OSDN Git Service

#40813 キーリピートありのUp/Downを、Sysytem/Input Optionからキーアサインできるようにした。電子ドラム使用時の選曲が楽になるはず...
[dtxmania/dtxmania.git] / DTXMania / コード / 全体 / CDTXMania.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Globalization;
4 using System.Text;
5 using System.Windows.Forms;
6 using System.Drawing;
7 using System.Diagnostics;
8 using System.IO;
9 using System.Threading;
10 using System.Management;
11 using SharpDX;
12 using SharpDX.Direct3D9;
13 using FDK;
14 using SampleFramework;
15 using System.Runtime.Serialization;
16 using System.Runtime;
17 using System.Xml;
18
19 using Point = System.Drawing.Point;
20 using Color = System.Drawing.Color;
21
22 namespace DTXMania
23 {
24         internal class CDTXMania : Game
25         {
26                 // プロパティ
27                 #region [ properties ]
28                 public static readonly string VERSION = "118(200510)";
29                 //public static readonly string SLIMDXDLL = "c_net20x86_Jun2010";
30                 public static readonly string D3DXDLL = "d3dx9_43.dll";     // June 2010
31                 //public static readonly string D3DXDLL = "d3dx9_42.dll";       // February 2010
32                 //public static readonly string D3DXDLL = "d3dx9_41.dll";       // March 2009
33                 private static CDTXMania instance = new CDTXMania();
34
35                 public static CDTXMania Instance
36                 {
37                         get
38                         {
39                                 return instance;
40                         }
41                 }
42                 public C文字コンソール act文字コンソール { get; private set; }
43                 public bool bコンパクトモード { get; private set; }
44                 public CConfigXml ConfigIni;
45                 public CResources Resources;
46
47                 public CDTX DTX
48                 {
49                         get
50                         {
51                                 return dtx;
52                         }
53                         set
54                         {
55                                 if ((dtx != null) && (Instance != null))
56                                 {
57                                         dtx.On非活性化();
58                                         Instance.listトップレベルActivities.Remove(dtx);
59                                 }
60                                 dtx = value;
61                                 if ((dtx != null) && (Instance != null))
62                                 {
63                                         Instance.listトップレベルActivities.Add(dtx);
64                                 }
65                         }
66                 }
67                 public CFPS FPS { get; private set; }
68                 public CInput管理 Input管理 { get; private set; }
69                 #region [ 入力範囲ms ]
70                 public int nPerfect範囲ms
71                 {
72                         get
73                         {
74                                 if (stage選曲.r確定された曲 != null)
75                                 {
76                                         C曲リストノード c曲リストノード = stage選曲.r確定された曲.r親ノード;
77                                         if (((c曲リストノード != null) && (c曲リストノード.eノード種別 == C曲リストノード.Eノード種別.BOX)) && (c曲リストノード.nPerfect範囲ms >= 0))
78                                         {
79                                                 return c曲リストノード.nPerfect範囲ms;
80                                         }
81                                 }
82                                 return ConfigIni.nHitRange.Perfect;
83                         }
84                 }
85                 public int nGreat範囲ms
86                 {
87                         get
88                         {
89                                 if (stage選曲.r確定された曲 != null)
90                                 {
91                                         C曲リストノード c曲リストノード = stage選曲.r確定された曲.r親ノード;
92                                         if (((c曲リストノード != null) && (c曲リストノード.eノード種別 == C曲リストノード.Eノード種別.BOX)) && (c曲リストノード.nGreat範囲ms >= 0))
93                                         {
94                                                 return c曲リストノード.nGreat範囲ms;
95                                         }
96                                 }
97                                 return ConfigIni.nHitRange.Great;
98                         }
99                 }
100                 public int nGood範囲ms
101                 {
102                         get
103                         {
104                                 if (stage選曲.r確定された曲 != null)
105                                 {
106                                         C曲リストノード c曲リストノード = stage選曲.r確定された曲.r親ノード;
107                                         if (((c曲リストノード != null) && (c曲リストノード.eノード種別 == C曲リストノード.Eノード種別.BOX)) && (c曲リストノード.nGood範囲ms >= 0))
108                                         {
109                                                 return c曲リストノード.nGood範囲ms;
110                                         }
111                                 }
112                                 return ConfigIni.nHitRange.Good;
113                         }
114                 }
115                 public int nPoor範囲ms
116                 {
117                         get
118                         {
119                                 if (stage選曲.r確定された曲 != null)
120                                 {
121                                         C曲リストノード c曲リストノード = stage選曲.r確定された曲.r親ノード;
122                                         if (((c曲リストノード != null) && (c曲リストノード.eノード種別 == C曲リストノード.Eノード種別.BOX)) && (c曲リストノード.nPoor範囲ms >= 0))
123                                         {
124                                                 return c曲リストノード.nPoor範囲ms;
125                                         }
126                                 }
127                                 return ConfigIni.nHitRange.Poor;
128                         }
129                 }
130                 #endregion
131                 public CPad Pad { get; private set; }
132                 public Random Random { get; private set; }
133                 public CSkin Skin { get; private set; }
134                 public CSongs管理 Songs管理 { get; set; }// 2012.1.26 yyagi private解除 CStage起動でのdesirialize読み込みのため
135                 public CEnumSongs EnumSongs { get; private set; }
136                 public CActEnumSongs actEnumSongs { get; private set; }
137                 public CActFlushGPU actFlushGPU { get; private set; }
138
139                 public CSound管理 Sound管理 { get; private set; }
140                 public CStage起動 stage起動 { get; private set; }
141                 public CStageタイトル stageタイトル { get; private set; }
142                 public CStageコンフィグ stageコンフィグ { get; private set; }
143                 public CStage選曲 stage選曲 { get; private set; }
144                 public CStage曲読み込み stage曲読み込み { get; private set; }
145                 public CStage演奏画面共通 stage演奏画面 { get; private set; }
146                 public CStage結果 stage結果 { get; private set; }
147                 public CStageChangeSkin stageChangeSkin { get; private set; }
148                 public CStage終了 stage終了 { get; private set; }
149                 public CStage r現在のステージ = null;
150                 public CStage r直前のステージ = null;
151                 public CStage r1フレーム前のステージ = null;
152                 public string strEXEのあるフォルダ { get; private set; }
153                 public string strコンパクトモードファイル { get; private set; }
154                 public CTimer Timer { get; private set; }
155                 public Format TextureFormat = Format.A8R8G8B8;
156                 internal IPluginActivity act現在入力を占有中のプラグイン = null;
157                 public bool bApplicationActive { get; private set; }
158                 public bool b次のタイミングで垂直帰線同期切り替えを行う { get; set; }
159                 public bool b次のタイミングで全画面_ウィンドウ切り替えを行う { get; set; }
160                 public Coordinates.CCoordinates Coordinates;
161                 public Device Device
162                 {
163                         get
164                         {
165                                 return base.GraphicsDeviceManager.Direct3D9.Device;
166                         }
167                 }
168                 public CPluginHost PluginHost { get; private set; }
169                 public List<STPlugin> listプラグイン = new List<STPlugin>();
170
171                 private Size currentClientSize { get; set; }    // #23510 2010.10.27 add yyagi to keep current window size
172                                                                                                                                                                                                                 //              public static CTimer ct;
173                 public IntPtr WindowHandle                  // 2012.10.24 yyagi; to add ASIO support
174                 {
175                         get
176                         {
177                                 return base.Window.Handle;
178                         }
179                 }
180         public CDTXVmode DTXVmode;                       // #28821 2014.1.23 yyagi
181         public CDTX2WAVmode DTX2WAVmode;
182         public CCommandParse CommandParse;
183         #endregion
184
185         // コンストラクタ
186
187         private CDTXMania()
188                 {
189                 }
190
191                 public void InitializeInstance()
192                 {
193                         #region [ strEXEのあるフォルダを決定する ]
194                         // BEGIN #23629 2010.11.13 from: デバッグ時は Application.ExecutablePath が ($SolutionDir)/bin/x86/Debug/ などになり System/ の読み込みに失敗するので、カレントディレクトリを採用する。(プロジェクトのプロパティ→デバッグ→作業ディレクトリが有効になる)
195 #if DEBUG
196                         strEXEのあるフォルダ = Environment.CurrentDirectory + @"\";
197                         //strEXEのあるフォルダ = Path.GetDirectoryName( Environment.GetCommandLineArgs()[ 0 ] ) + @"\";
198 #else
199                         strEXEのあるフォルダ = Path.GetDirectoryName(Application.ExecutablePath) + @"\"; // #23629 2010.11.9 yyagi: set correct pathname where DTXManiaGR.exe is.
200 #endif
201                         // END #23629 2010.11.13 from
202                         #endregion
203
204                         #region [ 言語リソースの初期化 ]
205                         Trace.TraceInformation("言語リソースの初期化を行います。");
206                         Trace.Indent();
207                         try
208                         {
209                                 Resources = new CResources();
210                                 Resources.LoadResources("");
211                                 Trace.TraceInformation("言語リソースの初期化を完了しました。");
212                         }
213                         finally
214                         {
215                                 Trace.Unindent();
216                         }
217                         #endregion
218
219                         #region [ Config.ini の読込み ]
220                         ConfigIni = new CConfigXml();
221                         CDTXMania.Instance.LoadConfig();
222                         // #28200 2011.5.1 yyagi
223                         this.Window.EnableSystemMenu = CDTXMania.Instance.ConfigIni.bIsEnabledSystemMenu;
224                         // 2012.8.22 Config.iniが無いときに初期値が適用されるよう、この設定行をifブロック外に移動
225                         #endregion
226
227
228                         #region[座標値読み込み]
229                         Coordinates = new Coordinates.CCoordinates();
230                         UpdateCoordinates();
231                         //Coordinates = (DTXMania.Coordinates.CCoordinates) CDTXMania.DeserializeXML( strEXEのあるフォルダ + "Coordinates.xml", typeof( DTXMania.Coordinates.CCoordinates ) );
232                         //if ( Coordinates == null )
233                         //{
234                         //      if ( File.Exists( strEXEのあるフォルダ + "Coordinates.xml" ) )
235                         //      {
236                         //              Trace.TraceInformation( "Coordinates.xmlファイルは存在します。" );
237                         //      }
238                         //      Trace.TraceInformation( "Coordiantes.xmlファイルの読み込みができませんでした。無視して進めます。" );
239                         //      Coordinates = new Coordinates.CCoordinates();
240                         //}
241                         #endregion
242
243                         #region [ ログ出力開始 ]
244                         Trace.AutoFlush = true;
245                         if (ConfigIni.bLog)
246                         {
247                                 try
248                                 {
249                                         Trace.Listeners.Add(new CTraceLogListener(new StreamWriter(System.IO.Path.Combine(strEXEのあるフォルダ, "DTXManiaLog.txt"), false, Encoding.GetEncoding("utf-16"))));
250                                 }
251                                 catch (System.UnauthorizedAccessException)          // #24481 2011.2.20 yyagi
252                                 {
253                                         Resources.Language = instance.ConfigIni.strLanguage;
254                                         string mes = CDTXMania.Instance.Resources.Explanation("strErrorLogWrite");
255                                         MessageBox.Show(mes, "DTXMania boot error", MessageBoxButtons.OK, MessageBoxIcon.Error);
256                                         Environment.Exit(1);
257                                 }
258                         }
259                         Trace.WriteLine("");
260                         Trace.WriteLine("DTXMania powered by YAMAHA Silent Session Drums");
261                         Trace.WriteLine(string.Format("Release: {0} {1} mode.", VERSION, (Environment.Is64BitProcess)? "x64":"x86" ));
262                         Trace.WriteLine("");
263                         Trace.TraceInformation("----------------------");
264                         Trace.TraceInformation("■ アプリケーションの初期化");
265
266                         CPutSystemLog.PutSystemLog();
267                         #endregion
268
269                         #region [ 言語の設定 ]
270                         Trace.TraceInformation("言語情報の読み込みを開始します。");
271                         //Debug.WriteLine( "language=" + Resources.Language );
272                         //Debug.WriteLine( "settings=" + instance.ConfigIni.strLanguage );
273                         Resources.Language = instance.ConfigIni.strLanguage;
274                         Trace.TraceInformation("言語を{0}に設定しました。", Resources.Language);
275
276                         #endregion
277
278                         #region [ DTXVmodeクラス, DTX2WAVmodeクラス, CommandParseクラス の初期化 ]
279                         //Trace.TraceInformation( "DTXVモードの初期化を行います。" );
280                         //Trace.Indent();
281                         try
282                         {
283                                 DTXVmode = new CDTXVmode();
284                                 DTXVmode.Enabled = false;
285                 //Trace.TraceInformation( "DTXVモードの初期化を完了しました。" );
286
287                 DTX2WAVmode = new CDTX2WAVmode();
288                 //Trace.TraceInformation( "DTX2WAVモードの初期化を完了しました。" );
289
290                 CommandParse = new CCommandParse();
291                 //Trace.TraceInformation( "CommandParseの初期化を完了しました。" );
292             }
293             finally
294                         {
295                                 //Trace.Unindent();
296                         }
297                         #endregion
298                         #region [ コンパクトモードスイッチの有無、もしくは、DTXViewer/DTX2WAVとしての起動 ]
299                         bコンパクトモード = false;
300                         strコンパクトモードファイル = "";
301                         string[] commandLineArgs = Environment.GetCommandLineArgs();
302                         if ((commandLineArgs != null) && (commandLineArgs.Length > 1))
303                         {
304                                 bコンパクトモード = true;
305                                 string arg = "";
306
307                                 for (int i = 1; i < commandLineArgs.Length; i++)
308                                 {
309                                         if (i != 1)
310                                         {
311                                                 arg += " " + "\"" + commandLineArgs[i] + "\"";
312                                         }
313                                         else
314                                         {
315                                                 arg += commandLineArgs[i];
316                                         }
317                                 }
318                                 CommandParse.ParseArguments(arg, ref DTXVmode, ref DTX2WAVmode);
319                                 if (DTXVmode.Enabled)
320                                 {
321                                         DTXVmode.Refreshed = false;                             // 初回起動時は再読み込みに走らせない
322                                         strコンパクトモードファイル = DTXVmode.filename;
323                                         switch (DTXVmode.soundDeviceType)                       // サウンド再生方式の設定
324                                         {
325                                                 case ESoundDeviceType.DirectSound:
326                                                         ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.DSound;
327                                                         break;
328                                                 case ESoundDeviceType.ExclusiveWASAPI:
329                                                         ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.WASAPI_Exclusive;
330                                                         break;
331                                                 case ESoundDeviceType.SharedWASAPI:
332                                                         ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.WASAPI_Shared;
333                                                         break;
334                                                 case ESoundDeviceType.ASIO:
335                                                         ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.ASIO;
336                                                         ConfigIni.strASIODevice.Index = DTXVmode.nASIOdevice;
337                                                         break;
338                                         }
339
340                                         CDTXMania.Instance.ConfigIni.bVSyncWait.Value = DTXVmode.VSyncWait;
341                                         CDTXMania.Instance.ConfigIni.bTimeStretch.Value = DTXVmode.TimeStretch;
342                                         if (DTXVmode.GRmode)
343                                         {
344                                                 CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.GBOnly;
345                                         }
346                                         else
347                                         {
348                                                 CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.Both;
349                                         }
350
351                                         CDTXMania.Instance.ConfigIni.bFullScreen.Value = false;
352                                         CDTXMania.Instance.ConfigIni.rcWindow_backup = CDTXMania.Instance.ConfigIni.rcWindow;       // #36612 2016.9.12 yyagi
353                                         CDTXMania.Instance.ConfigIni.rcWindow.W = CDTXMania.Instance.ConfigIni.rcViewerWindow.W;
354                                         CDTXMania.Instance.ConfigIni.rcWindow.H = CDTXMania.Instance.ConfigIni.rcViewerWindow.H;
355                                         CDTXMania.Instance.ConfigIni.rcWindow.X = CDTXMania.Instance.ConfigIni.rcViewerWindow.X;
356                                         CDTXMania.Instance.ConfigIni.rcWindow.Y = CDTXMania.Instance.ConfigIni.rcViewerWindow.Y;
357                                 }
358                                 else if (DTX2WAVmode.Enabled)
359                                 {
360                                         strコンパクトモードファイル = DTX2WAVmode.dtxfilename;
361                                         #region [ FDKへの録音設定 ]
362                                         FDK.CSound管理.strRecordInputDTXfilename = DTX2WAVmode.dtxfilename;
363                                         FDK.CSound管理.strRecordOutFilename = DTX2WAVmode.outfilename;
364                                         FDK.CSound管理.strRecordFileType = DTX2WAVmode.Format.ToString();
365                                         FDK.CSound管理.nBitrate = DTX2WAVmode.bitrate;
366                                         for (int i = 0; i < (int)FDK.CSound.EInstType.Unknown; i++)
367                                         {
368                                                 FDK.CSound管理.nMixerVolume[ i ] = DTX2WAVmode.nMixerVolume[ i ];
369                                         }
370                                         ConfigIni.nMasterVolume.Value = DTX2WAVmode.nMixerVolume[(int)FDK.CSound.EInstType.Unknown];    // [5](Unknown)のところにMasterVolumeが入ってくるので注意
371                                                                                                                                                                                                                                         // CSound管理.nMixerVolume[5]は、結局ここからは変更しないため、
372                                                                                                                                                                                                                                         // 事実上初期値=100で固定。
373                                         #endregion
374                                         #region [ 録音用の本体設定 ]
375
376                                         // 本体プロセスの優先度を少し上げる (最小化状態で動作させると、処理性能が落ちるようなので
377                                         // → ほとんど効果がなかったので止めます
378                                         //Process thisProcess = System.Diagnostics.Process.GetCurrentProcess();
379                                         //thisProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
380
381                                         // エンコーダーのパス設定 (=DLLフォルダ)
382                                         FDK.CSound管理.strEncoderPath = Path.Combine(strEXEのあるフォルダ, "DLL");
383
384                                         CDTXMania.instance.ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.WASAPI_Exclusive;
385                                         CDTXMania.instance.ConfigIni.bEventDrivenWASAPI.Value = false;
386
387                                         CDTXMania.instance.ConfigIni.bVSyncWait.Value = false;
388                                         CDTXMania.instance.ConfigIni.bTimeStretch.Value = false;
389                                         CDTXMania.instance.ConfigIni.eActiveInst.Value = EActiveInstrument.Both;
390
391                                         CDTXMania.instance.ConfigIni.bFullScreen.Value = false;
392                                         CDTXMania.instance.ConfigIni.rcWindow_backup = CDTXMania.Instance.ConfigIni.rcWindow;
393                                         CDTXMania.instance.ConfigIni.rcWindow.W = CDTXMania.Instance.ConfigIni.rcViewerWindow.W;
394                                         CDTXMania.instance.ConfigIni.rcWindow.H = CDTXMania.Instance.ConfigIni.rcViewerWindow.H;
395                                         CDTXMania.instance.ConfigIni.rcWindow.X = CDTXMania.Instance.ConfigIni.rcViewerWindow.X;
396                                         CDTXMania.instance.ConfigIni.rcWindow.Y = CDTXMania.Instance.ConfigIni.rcViewerWindow.Y;
397
398                                         //全オート
399                                         CDTXMania.instance.ConfigIni.bAutoPlay.LC.Value = true;
400                                         CDTXMania.instance.ConfigIni.bAutoPlay.HH.Value = true;
401                                         CDTXMania.instance.ConfigIni.bAutoPlay.HHO.Value = true;
402                                         CDTXMania.instance.ConfigIni.bAutoPlay.SD.Value = true;
403                                         CDTXMania.instance.ConfigIni.bAutoPlay.BD.Value = true;
404                                         CDTXMania.instance.ConfigIni.bAutoPlay.HT.Value = true;
405                                         CDTXMania.instance.ConfigIni.bAutoPlay.LT.Value = true;
406                                         CDTXMania.instance.ConfigIni.bAutoPlay.FT.Value = true;
407                                         CDTXMania.instance.ConfigIni.bAutoPlay.CY.Value = true;
408                                         CDTXMania.instance.ConfigIni.bAutoPlay.RD.Value = true;
409
410                                         CDTXMania.instance.ConfigIni.bAutoPlay.GtR.Value = true;
411                                         CDTXMania.instance.ConfigIni.bAutoPlay.GtG.Value = true;
412                                         CDTXMania.instance.ConfigIni.bAutoPlay.GtB.Value = true;
413                                         CDTXMania.instance.ConfigIni.bAutoPlay.GtPick.Value = true;
414                                         //CDTXMania.instance.ConfigIni.bAutoPlay.GtWail.Value = true;  // 無くてもよい 処理不可削減のため、敢えてWailはAutoにしない
415                                         CDTXMania.instance.ConfigIni.bAutoPlay.BsR.Value = true;
416                                         CDTXMania.instance.ConfigIni.bAutoPlay.BsG.Value = true;
417                                         CDTXMania.instance.ConfigIni.bAutoPlay.BsB.Value = true;
418                                         CDTXMania.instance.ConfigIni.bAutoPlay.BsPick.Value = true;
419                                         //CDTXMania.instance.ConfigIni.bAutoPlay.BsWail.Value = true;
420
421                                         //FillInオフ, 歓声オフ
422                                         CDTXMania.instance.ConfigIni.bFillin.Value = false;
423                                         CDTXMania.instance.ConfigIni.bAudience.Value = false;
424                                         //ストイックモード
425                                         CDTXMania.instance.ConfigIni.bStoicMode.Value = false;
426                                         //チップ非表示
427                                         CDTXMania.instance.ConfigIni.eSudHidInv.Drums.Value = ESudHidInv.FullInv;
428                                         CDTXMania.instance.ConfigIni.eSudHidInv.Guitar.Value = ESudHidInv.FullInv;
429                                         CDTXMania.instance.ConfigIni.eSudHidInv.Bass.Value = ESudHidInv.FullInv;
430
431                                         // Dark=Full
432                                         CDTXMania.instance.ConfigIni.eDark.Value = EDark.Full;
433
434                                         //多重再生数=4
435                                         CDTXMania.instance.ConfigIni.nPolyphonicSounds.Value = 4;
436
437                                         //再生速度x1
438                                         CDTXMania.instance.ConfigIni.nPlaySpeed.Value = 20;
439
440                                         //メトロノーム音量0
441                                         CDTXMania.instance.ConfigIni.eClickType.Value = EClickType.Off;
442                                         CDTXMania.instance.ConfigIni.nClickHighVolume.Value = 0;
443                                         CDTXMania.instance.ConfigIni.nClickLowVolume.Value = 0;
444
445                                         //自動再生音量=100
446                                         CDTXMania.instance.ConfigIni.nAutoVolume.Value = 100;
447                                         CDTXMania.instance.ConfigIni.nChipVolume.Value = 100;
448
449                                         //マスターボリューム100
450                                         //CDTXMania.instance.ConfigIni.nMasterVolume.Value = 100;       // DTX2WAV側から設定するので、ここでは触らない
451
452                                         //StageFailedオフ
453                                         CDTXMania.instance.ConfigIni.bStageFailed.Value = false;
454
455                                         //グラフ無効
456                                         CDTXMania.instance.ConfigIni.bGraph.Drums.Value = false;
457                                         CDTXMania.instance.ConfigIni.bGraph.Guitar.Value = false;
458                                         CDTXMania.instance.ConfigIni.bGraph.Bass.Value = false;
459
460                                         //コンボ非表示,判定非表示
461                                         CDTXMania.instance.ConfigIni.bDisplayCombo.Drums.Value = false;
462                                         CDTXMania.instance.ConfigIni.bDisplayCombo.Guitar.Value = false;
463                                         CDTXMania.instance.ConfigIni.bDisplayCombo.Bass.Value = false;
464                                         CDTXMania.instance.ConfigIni.bDisplayJudge.Drums.Value = false;
465                                         CDTXMania.instance.ConfigIni.bDisplayJudge.Guitar.Value = false;
466                                         CDTXMania.instance.ConfigIni.bDisplayJudge.Bass.Value = false;
467
468
469                                         //デバッグ表示オフ
470                                         //CDTXMania.instance.ConfigIni.b演奏情報を表示する = false;
471                                         CDTXMania.instance.ConfigIni.bDebugInfo.Value = false;
472
473                                         //BGAオフ, AVIオフ
474                                         CDTXMania.instance.ConfigIni.bBGA.Value = false;
475                                         CDTXMania.instance.ConfigIni.bAVI.Value = false;
476
477                                         //BGMオン、チップ音オン
478                                         CDTXMania.instance.ConfigIni.bBGMPlay.Value = true;
479                                         CDTXMania.instance.ConfigIni.bDrumsHitSound.Value = true;
480
481                                         //パート強調オフ
482                                         CDTXMania.instance.ConfigIni.bEmphasizePlaySound.Drums.Value = false;
483                                         CDTXMania.instance.ConfigIni.bEmphasizePlaySound.Guitar.Value = false;
484                                         CDTXMania.instance.ConfigIni.bEmphasizePlaySound.Bass.Value = false;
485
486                                         // パッド入力等、基本操作の無効化 (ESCを除く)
487                                         //CDTXMania.Instance.ConfigIni.KeyAssign[][];
488                                         
489                                         #endregion
490                                 }
491                                 else                                                        // 通常のコンパクトモード
492                                 {
493                                         strコンパクトモードファイル = commandLineArgs[1];
494                                 }
495
496                                 if (!File.Exists(strコンパクトモードファイル))      // #32985 2014.1.23 yyagi 
497                                 {
498                                         Trace.TraceError("コンパクトモードで指定されたファイルが見つかりません。DTXManiaを終了します。[{0}]", strコンパクトモードファイル);
499 #if DEBUG
500                                         Environment.Exit(-1);
501 #else
502                                         if (strコンパクトモードファイル == "")      // DTXMania未起動状態で、DTXCで再生停止ボタンを押した場合は、何もせず終了
503                                         {
504                                                 Environment.Exit(-1);
505                                         }
506                                         else
507                                         {
508                                                 throw new FileNotFoundException("コンパクトモードで指定されたファイルが見つかりません。DTXManiaを終了します。", strコンパクトモードファイル);
509                                         }
510 #endif
511                                 }
512                                 if (DTXVmode.Enabled)
513                                 {
514                                         Trace.TraceInformation("DTXVモードで起動します。[{0}]", strコンパクトモードファイル);
515                                 }
516                                 else if (DTX2WAVmode.Enabled)
517                                 {
518                                         Trace.TraceInformation("DTX2WAVモードで起動します。[{0}]", strコンパクトモードファイル);
519                                         DTX2WAVmode.SendMessage2DTX2WAV("BOOT");
520                                 }
521                                 else
522                                 {
523                                         Trace.TraceInformation("コンパクトモードで起動します。[{0}]", strコンパクトモードファイル);
524                                 }
525                         }
526                         else
527                         {
528                                 Trace.TraceInformation("通常モードで起動します。");
529                         }
530                         #endregion
531
532                         #region [ 現在の電源プランをバックアップし、CONFIGのHighPower=ONの場合は HighPerformanceに変更 ]
533                         CPowerPlan.BackupCurrentPowerPlan();
534                         if (CDTXMania.Instance.ConfigIni.bForceHighPowerPlan)
535                         {
536                                 CPowerPlan.ChangeHighPerformance();
537                         }
538                         #endregion
539
540                         #region [ Input管理 の初期化 ]
541                         Trace.TraceInformation("DirectInput, MIDI入力の初期化を行います。");
542                         Trace.Indent();
543                         try
544                         {
545                                 bool bUseMIDIIn = !DTXVmode.Enabled;
546                                 Input管理 = new CInput管理(base.Window.Handle, bUseMIDIIn);
547
548                                 // If the users uses MIDI2.0-USB cable, then warn it
549                                 if (bUseMIDIIn && CDTXMania.Instance.ConfigIni.bWarnMIDI20USB.Value)
550                                 {
551                                         foreach (IInputDevice device in Input管理.list入力デバイス)
552                                         {
553                                                 if ((device.e入力デバイス種別 == E入力デバイス種別.MidiIn) && (device.strDeviceName == "USB2.0-MIDI"))
554                                                 {
555                                                         string strWarnMes = CDTXMania.Instance.Resources.Explanation("strWarnMIDI20USB");
556                                                         var ret = MessageBox.Show(strWarnMes, "DTXMania Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
557                                                         if (ret == DialogResult.OK)
558                                                         {
559                                                                 CDTXMania.Instance.ConfigIni.bWarnMIDI20USB.Value = false;
560                                                         }
561                                                 }
562                                         }
563                                 }
564
565
566
567                                 foreach (IInputDevice device in Input管理.list入力デバイス)
568                                 {
569                                         if ((device.e入力デバイス種別 == E入力デバイス種別.Joystick) && !ConfigIni.dicJoystick.Value.ContainsValue(device.GUID))
570                                         {
571                                                 int key = 0;
572                                                 while (ConfigIni.dicJoystick.Value.ContainsKey(key))
573                                                 {
574                                                         key++;
575                                                 }
576                                                 ConfigIni.dicJoystick.Value.Add(key, device.GUID);
577                                         }
578                                 }
579                                 foreach (IInputDevice device2 in Input管理.list入力デバイス)
580                                 {
581                                         if (device2.e入力デバイス種別 == E入力デバイス種別.Joystick)
582                                         {
583                                                 foreach (KeyValuePair<int, string> pair in ConfigIni.dicJoystick.Value)
584                                                 {
585                                                         if (device2.GUID.Equals(pair.Value))
586                                                         {
587                                                                 ((CInputJoystick)device2).SetID(pair.Key);
588                                                                 break;
589                                                         }
590                                                 }
591                                                 continue;
592                                         }
593                                 }
594                                 Trace.TraceInformation("DirectInput の初期化を完了しました。");
595                         }
596                         catch (Exception exception2)
597                         {
598                                 Trace.TraceError(exception2.Message);
599                                 Trace.TraceError("DirectInput, MIDI入力の初期化に失敗しました。");
600
601                                 string mes = CDTXMania.Instance.Resources.Explanation("strErrorLogWrite");
602                                 MessageBox.Show(mes, "DTXMania boot error", MessageBoxButtons.OK, MessageBoxIcon.Error);
603                                 Environment.Exit(1);
604                         }
605                         finally
606                         {
607                                 Trace.Unindent();
608                         }
609                         #endregion
610
611                         #region [ ウィンドウ初期化 ]
612                         // #30675 2013.02.04 ikanick add
613                         base.Window.StartPosition = FormStartPosition.Manual;
614                         base.Window.Location = new Point(ConfigIni.rcWindow.X, ConfigIni.rcWindow.Y);
615                         // 事前にDTXVmodeの実体を作っておくこと
616                         base.Window.Text = this.strWindowTitle;
617                         //base.Window.StartPosition = FormStartPosition.Manual;
618                         //base.Window.Location = new Point(ConfigIni.rcWindow.X, ConfigIni.rcWindow.Y);
619
620                         // #34510 yyagi 2010.10.31 to change window size got from Config.ini
621                         base.Window.ClientSize = new Size(ConfigIni.rcWindow.W, ConfigIni.rcWindow.H);
622 #if !WindowedFullscreen
623                         if (!ConfigIni.bウィンドウモード)                                               // #23510 2010.11.02 yyagi: add; to recover window size in case bootup with fullscreen mode
624                         {                                                                                                               // #30666 2013.02.02 yyagi: currentClientSize should be always made
625 #endif
626                         currentClientSize = new Size(ConfigIni.rcWindow.W, ConfigIni.rcWindow.H);
627 #if !WindowedFullscreen
628                         }
629 #endif
630                         // #23510 2010.11.04 yyagi: to support maximizing window
631                         base.Window.MaximizeBox = true;
632                         // #23510 2010.10.27 yyagi: changed from FixedDialog to Sizable, to support window resize
633                         base.Window.FormBorderStyle = FormBorderStyle.Sizable;
634                         // #30666 2013.02.02 yyagi: moved the code to t全画面・ウインドウモード切り替え()
635                         base.Window.ShowIcon = true;
636                         base.Window.Icon = Properties.Resources.dtx;
637                         base.Window.KeyDown += new KeyEventHandler(this.Window_KeyDown);
638                         base.Window.MouseUp += new MouseEventHandler(this.Window_MouseUp);
639                         base.Window.MouseDown += new MouseEventHandler(this.Window_MouseDown);
640                         // #23510 2010.11.13 yyagi: to go fullscreen mode
641                         base.Window.MouseDoubleClick += new MouseEventHandler(this.Window_MouseDoubleClick);
642                         // #23510 2010.11.20 yyagi: to set resized window size in Config.ini
643                         base.Window.ResizeEnd += new EventHandler(this.Window_ResizeEnd);
644                         base.Window.ApplicationActivated += new EventHandler(this.Window_ApplicationActivated);
645                         base.Window.ApplicationDeactivated += new EventHandler(this.Window_ApplicationDeactivated);
646                         base.Window.MouseMove += new MouseEventHandler(this.Window_MouseMove);
647                         #endregion
648
649                         #region [ Direct3D9Exを使うかどうか判定 ]
650                         #endregion
651
652                         #region [ Direct3D9 デバイスの生成 ]
653                         DeviceSettings settings = new DeviceSettings();
654 #if WindowedFullscreen
655                         // #30666 2013.2.2 yyagi: Fullscreenmode is "Maximized window" mode
656                         settings.Windowed = true;
657 #else
658                         settings.Windowed = ConfigIni.bウィンドウモード;
659 #endif
660                         settings.BackBufferWidth = SampleFramework.GameWindowSize.Width;
661                         settings.BackBufferHeight = SampleFramework.GameWindowSize.Height;
662                         settings.EnableVSync = ConfigIni.bVSyncWait;
663                         //settings.MultisampleType = MultisampleType.FourSamples;
664                         //settings.MultisampleQuality = 3;
665                         //settings.MultisampleType = MultisampleType.NonMaskable;
666                         //settings.Multithreaded = true;
667
668
669                         try
670                         {
671                                 base.GraphicsDeviceManager.ChangeDevice(settings);
672                         }
673                         catch (DeviceCreationException e)
674                         {
675                                 Trace.TraceError(e.ToString());
676                                 MessageBox.Show(e.Message + e.ToString(), "DTXMania failed to boot: DirectX9 Initialize Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
677                                 Environment.Exit(-1);
678                         }
679                         Trace.TraceInformation("DeviceCaps       = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.DeviceCaps.ToString());
680                         Trace.TraceInformation("DeviceCaps2      = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.DeviceCaps2.ToString());
681                         Trace.TraceInformation("MaxTextureWidth  = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.MaxTextureWidth);
682                         Trace.TraceInformation("MaxTextureHeight = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.MaxTextureHeight);
683                         Trace.TraceInformation("TextureCaps      = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.TextureCaps.ToString());
684                         Trace.TraceInformation("DeviceInformation= " + base.GraphicsDeviceManager.DeviceInformation.ToString());
685                         Trace.TraceInformation("DeviceStatics    = " + base.GraphicsDeviceManager.DeviceStatistics.ToString());
686
687                         base.IsFixedTimeStep = false;
688                         //                      base.TargetElapsedTime = TimeSpan.FromTicks( 10000000 / 75 );
689                         // #23510 2010.10.31 yyagi: to recover window size. width and height are able to get from Config.ini.
690                         base.Window.ClientSize = new Size(ConfigIni.rcWindow.W, ConfigIni.rcWindow.H);
691                         // #23568 2010.11.3 yyagi: to support valiable sleep value when !IsActive
692                         base.InactiveSleepTime = TimeSpan.FromMilliseconds((float)(ConfigIni.nSleepUnfocusMs));
693                         // #23568 2010.11.4 ikanick changed ( 1 -> ConfigIni )
694 #if WindowedFullscreen
695                         // #30666 2013.2.2 yyagi: finalize settings for "Maximized window mode"
696                         this.t全画面_ウィンドウモード切り替え();
697 #endif
698                         actFlushGPU = new CActFlushGPU();
699                         #endregion
700
701                         if (DTX2WAVmode.Enabled)
702                         {
703                                 this.Window.WindowState = FormWindowState.Minimized;            //DTX2WAVモード時は自動的に最小化
704                         }
705
706                         DTX = null;
707
708                         #region [ Skin の初期化 ]
709                         Trace.TraceInformation("スキンの初期化を行います。");
710                         Trace.Indent();
711                         try
712                         {
713                                 Skin = new CSkin(
714                                         CDTXMania.Instance.ConfigIni.strSystemSkinSubfolderPath,
715                                         CDTXMania.Instance.ConfigIni.bUseBoxDefSkin);
716                                 // 旧指定のSkinフォルダが消滅していた場合に備える
717                                 CDTXMania.Instance.ConfigIni.strSystemSkinSubfolderPath.Value = CDTXMania.Instance.Skin.GetCurrentSkinSubfolderFullName(true);
718                                 Trace.TraceInformation("スキンの初期化を完了しました。");
719                         }
720                         catch
721                         {
722                                 Trace.TraceInformation("スキンの初期化に失敗しました。");
723                                 throw;
724                         }
725                         finally
726                         {
727                                 Trace.Unindent();
728                         }
729
730                         #region [ Skin配下にある言語リソースの確認と初期化 ]
731                         Trace.TraceInformation("スキンフォルダに言語リソースがないか確認します。");
732                         Trace.Indent();
733                         try
734                         {
735                                 Resources.csvCurrentPath = CDTXMania.Instance.ConfigIni.strSystemSkinSubfolderPath.Value;
736                                 Trace.TraceInformation("Skin Path:" + Resources.csvCurrentPath);
737
738                                 bool ret = Resources.LoadResources(instance.ConfigIni.strLanguage);
739                                 if (ret)
740                                 {
741                                         Trace.TraceInformation("スキンフォルダ内に言語リソースが見つかりました。この言語リソースを使用します。");
742                                 }
743                                 else
744                                 {
745                                         Trace.TraceInformation("スキンフォルダ内の言語リソースを使用できません。既定の言語リソースを使用します。");
746
747                                 }
748                         }
749                         finally
750                         {
751                                 Trace.Unindent();
752                         }
753                         #endregion
754
755                         #endregion
756
757                         #region [ Timer の初期化 ]
758                         Trace.TraceInformation("タイマの初期化を行います。");
759                         Trace.Indent();
760                         try
761                         {
762                                 Timer = new CTimer(CTimer.E種別.MultiMedia);
763                                 Trace.TraceInformation("タイマの初期化を完了しました。");
764                         }
765                         finally
766                         {
767                                 Trace.Unindent();
768                         }
769                         #endregion
770
771                         #region [ マウス消去用のクラスを初期化 ]
772                         cMouseHideControl = new CMouseHideControl();
773                         #endregion
774
775                         #region [ FPS カウンタの初期化 ]
776                         Trace.TraceInformation("FPSカウンタの初期化を行います。");
777                         Trace.Indent();
778                         try
779                         {
780                                 FPS = new CFPS();
781                                 Trace.TraceInformation("FPSカウンタを生成しました。");
782                         }
783                         finally
784                         {
785                                 Trace.Unindent();
786                         }
787                         #endregion
788
789                         #region [ act文字コンソールの初期化 ]
790                         Trace.TraceInformation("文字コンソールの初期化を行います。");
791                         Trace.Indent();
792                         try
793                         {
794                                 act文字コンソール = new C文字コンソール();
795                                 Trace.TraceInformation("文字コンソールを生成しました。");
796                                 act文字コンソール.On活性化();
797                                 Trace.TraceInformation("文字コンソールを活性化しました。");
798                                 Trace.TraceInformation("文字コンソールの初期化を完了しました。");
799                         }
800                         catch (Exception exception)
801                         {
802                                 Trace.TraceError(exception.Message);
803                                 Trace.TraceError("文字コンソールの初期化に失敗しました。");
804                         }
805                         finally
806                         {
807                                 Trace.Unindent();
808                         }
809                         #endregion
810
811                         #region [ Pad の初期化 ]
812                         Trace.TraceInformation("パッドの初期化を行います。");
813                         Trace.Indent();
814                         try
815                         {
816                                 Pad = new CPad();
817                                 Trace.TraceInformation("パッドの初期化を完了しました。");
818                         }
819                         catch (Exception exception3)
820                         {
821                                 Trace.TraceError(exception3.Message);
822                                 Trace.TraceError("パッドの初期化に失敗しました。");
823                         }
824                         finally
825                         {
826                                 Trace.Unindent();
827                         }
828                         #endregion
829
830                         #region [ Sound管理 の初期化 ]
831                         Trace.TraceInformation("サウンドデバイスの初期化を行います。");
832                         Trace.Indent();
833                         try
834                         {
835                                 ESoundDeviceType soundDeviceType;
836                                 switch (CDTXMania.Instance.ConfigIni.nSoundDeviceType.Value)
837                                 {
838                                         case ESoundDeviceTypeForConfig.DSound:
839                                                 soundDeviceType = ESoundDeviceType.DirectSound;
840                                                 break;
841                                         case ESoundDeviceTypeForConfig.ASIO:
842                                                 soundDeviceType = ESoundDeviceType.ASIO;
843                                                 break;
844                                         case ESoundDeviceTypeForConfig.WASAPI_Exclusive:
845                                                 soundDeviceType = ESoundDeviceType.ExclusiveWASAPI;
846                                                 break;
847                                         case ESoundDeviceTypeForConfig.WASAPI_Shared:
848                                                 soundDeviceType = ESoundDeviceType.SharedWASAPI;
849                                                 break;
850                                         default:
851                                                 soundDeviceType = ESoundDeviceType.Unknown;
852                                                 break;
853                                 }
854                                 Sound管理 = new CSound管理(base.Window.Handle,
855                                                                                         soundDeviceType,
856                                                                                         CDTXMania.Instance.ConfigIni.nWASAPIBufferSizeMs,
857                                                                                         CDTXMania.instance.ConfigIni.bEventDrivenWASAPI,
858                                                                                         0,
859                                                                                         CDTXMania.Instance.ConfigIni.strASIODevice.Index,
860                                                                                         CDTXMania.Instance.ConfigIni.bUseOSTimer
861                                 );
862                                 //Sound管理 = FDK.CSound管理.Instance;
863                                 //Sound管理.t初期化( soundDeviceType, 0, 0, CDTXMania.Instance.ConfigIni.nASIODevice, base.Window.Handle );
864
865                                 ShowWindowTitleWithSoundType();
866                                 FDK.CSound管理.bIsTimeStretch = CDTXMania.Instance.ConfigIni.bTimeStretch;
867                                 Sound管理.nMasterVolume = CDTXMania.Instance.ConfigIni.nMasterVolume;
868                                 //FDK.CSound管理.bIsMP3DecodeByWindowsCodec = CDTXMania.Instance.ConfigIni.bNoMP3Streaming;
869
870
871                                 string strDefaultSoundDeviceBusType = CSound管理.strDefaultDeviceBusType;
872                                 Trace.TraceInformation($"Bus type of the default sound device = {strDefaultSoundDeviceBusType}");
873
874                                 if (strDefaultSoundDeviceBusType.ToUpper().Equals("USB"))
875                                 {
876                                         if (CDTXMania.Instance.ConfigIni.bWarnSoundDeviceOnUSB.Value)
877                                         {
878                                                 string strWarnMes = CDTXMania.Instance.Resources.Explanation("strWarnSoundDeviceOnUSB");
879                                                 var ret = MessageBox.Show(strWarnMes, "DTXMania Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
880                                                 if (ret == DialogResult.OK)
881                                                 {
882                                                         CDTXMania.Instance.ConfigIni.bWarnSoundDeviceOnUSB.Value = false;
883                                                 }
884                                         }
885                                 }
886
887                                 Trace.TraceInformation("サウンドデバイスの初期化を完了しました。");
888                         }
889                         catch (NullReferenceException)  // No audio output found
890                         {
891                                 Trace.TraceError("Error: No sound output devices are ready.");
892                                 string strWarnMes = CDTXMania.Instance.Resources.Explanation("strErrorNoActiveSoundDevice");
893                                 MessageBox.Show(strWarnMes, "DTXMania Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
894                                 Environment.Exit(-1);
895                         }
896                         catch (Exception e)
897                         {
898                                 Trace.TraceError(e.Message);
899                                 throw;
900                         }
901                         finally
902                         {
903                                 Trace.Unindent();
904                         }
905                         #endregion
906
907                         #region [ Songs管理 の初期化 ]
908                         //---------------------
909                         Trace.TraceInformation("曲リストの初期化を行います。");
910                         Trace.Indent();
911                         try
912                         {
913                                 Songs管理 = new CSongs管理();
914                                 //                              Songs管理_裏読 = new CSongs管理();
915                                 EnumSongs = new CEnumSongs();
916                                 actEnumSongs = new CActEnumSongs();
917                                 Trace.TraceInformation("曲リストの初期化を完了しました。");
918                         }
919                         catch (Exception e)
920                         {
921                                 Trace.TraceError(e.Message);
922                                 Trace.TraceError("曲リストの初期化に失敗しました。");
923                         }
924                         finally
925                         {
926                                 Trace.Unindent();
927                         }
928                         //---------------------
929                         #endregion
930
931                         #region [ CAvi の初期化 ]
932                         CAvi.t初期化();
933                         #endregion
934
935                         #region [ Random の初期化 ]
936                         Random = new Random((int)Timer.nシステム時刻);
937                         #endregion
938
939                         #region [ ステージの初期化 ]
940                         r現在のステージ = null;
941                         r直前のステージ = null;
942                         stage起動 = new CStage起動();
943                         stageタイトル = new CStageタイトル();
944                         stageコンフィグ = new CStageコンフィグ();
945                         stage選曲 = new CStage選曲();
946                         stage曲読み込み = new CStage曲読み込み();
947                         stage演奏画面 = new CStage演奏画面共通();
948                         stage結果 = new CStage結果();
949                         stageChangeSkin = new CStageChangeSkin();
950                         stage終了 = new CStage終了();
951
952                         this.listトップレベルActivities = new List<CActivity>();
953                         this.listトップレベルActivities.Add(actEnumSongs);
954                         this.listトップレベルActivities.Add(act文字コンソール);
955                         this.listトップレベルActivities.Add(stage起動);
956                         this.listトップレベルActivities.Add(stageタイトル);
957                         this.listトップレベルActivities.Add(stageコンフィグ);
958                         this.listトップレベルActivities.Add(stage選曲);
959                         this.listトップレベルActivities.Add(stage曲読み込み);
960                         this.listトップレベルActivities.Add(stage演奏画面);
961                         this.listトップレベルActivities.Add(stage結果);
962                         this.listトップレベルActivities.Add(stageChangeSkin);
963                         this.listトップレベルActivities.Add(stage終了);
964                         this.listトップレベルActivities.Add(actFlushGPU);
965                         #endregion
966
967                         #region [ プラグインの検索と生成 ]
968                         PluginHost = new CPluginHost();
969
970                         Trace.TraceInformation("プラグインの検索と生成を行います。");
971                         Trace.Indent();
972                         try
973                         {
974                                 this.tプラグイン検索と生成();
975                                 Trace.TraceInformation("プラグインの検索と生成を完了しました。");
976                         }
977                         finally
978                         {
979                                 Trace.Unindent();
980                         }
981                         #endregion
982
983                         #region [ プラグインの初期化 ]
984                         if (this.listプラグイン != null && this.listプラグイン.Count > 0)
985                         {
986                                 Trace.TraceInformation("プラグインの初期化を行います。");
987                                 Trace.Indent();
988                                 try
989                                 {
990                                         foreach (STPlugin st in this.listプラグイン)
991                                         {
992                                                 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
993                                                 st.plugin.On初期化(this.PluginHost);
994                                                 st.plugin.OnManagedリソースの作成();
995                                                 st.plugin.OnUnmanagedリソースの作成();
996                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
997                                         }
998                                         Trace.TraceInformation("すべてのプラグインの初期化を完了しました。");
999                                 }
1000                                 catch
1001                                 {
1002                                         Trace.TraceError("プラグインのどれかの初期化に失敗しました。");
1003                                         throw;
1004                                 }
1005                                 finally
1006                                 {
1007                                         Trace.Unindent();
1008                                 }
1009                         }
1010                         #endregion
1011
1012
1013                         Trace.TraceInformation("アプリケーションの初期化を完了しました。");
1014
1015                         #region [ 最初のステージの起動 ]
1016                         Trace.TraceInformation("----------------------");
1017                         Trace.TraceInformation("■ 起動");
1018
1019                         if (CDTXMania.Instance.bコンパクトモード)
1020                         {
1021                                 r現在のステージ = stage曲読み込み;
1022                         }
1023                         else
1024                         {
1025                                 r現在のステージ = stage起動;
1026                         }
1027                         r現在のステージ.On活性化();
1028                         #endregion
1029                 }
1030
1031
1032                 public void t全画面_ウィンドウモード切り替え()
1033                 {
1034 #if WindowedFullscreen
1035                         if (ConfigIni != null)
1036 #else
1037                         DeviceSettings settings = base.GraphicsDeviceManager.CurrentSettings.Clone();
1038                         if ( ( ConfigIni != null ) && ( ConfigIni.bウィンドウモード != settings.Windowed ) )
1039 #endif
1040                         {
1041 #if !WindowedFullscreen
1042                                 settings.Windowed = ConfigIni.bウィンドウモード;
1043 #endif
1044                                 if (ConfigIni.bウィンドウモード == false)   // #23510 2010.10.27 yyagi: backup current window size before going fullscreen mode
1045                                 {
1046                                         currentClientSize = this.Window.ClientSize;
1047                                         ConfigIni.rcWindow.W = this.Window.ClientSize.Width;
1048                                         ConfigIni.rcWindow.H = this.Window.ClientSize.Height;
1049                                         //                                      FDK.CTaskBar.ShowTaskBar( false );
1050                                 }
1051 #if !WindowedFullscreen
1052                                 base.GraphicsDeviceManager.ChangeDevice( settings );
1053 #endif
1054                                 if (ConfigIni.bウィンドウモード == true)    // #23510 2010.10.27 yyagi: to resume window size from backuped value
1055                                 {
1056 #if WindowedFullscreen
1057                                         // #30666 2013.2.2 yyagi Don't use Fullscreen mode becasue NVIDIA GeForce is
1058                                         // tend to delay drawing on Fullscreen mode. So DTXMania uses Maximized window
1059                                         // in spite of using fullscreen mode.
1060                                         Instance.Window.WindowState = FormWindowState.Normal;
1061                                         Instance.Window.FormBorderStyle = FormBorderStyle.Sizable;
1062                                         Instance.Window.WindowState = FormWindowState.Normal;
1063 #endif
1064                                         base.Window.ClientSize =
1065                                                         new Size(currentClientSize.Width, currentClientSize.Height);
1066                                         //                                      FDK.CTaskBar.ShowTaskBar( true );
1067                                 }
1068 #if WindowedFullscreen
1069                                 else
1070                                 {
1071                                         Instance.Window.WindowState = FormWindowState.Normal;
1072                                         Instance.Window.FormBorderStyle = FormBorderStyle.None;
1073                                         Instance.Window.WindowState = FormWindowState.Maximized;
1074                                 }
1075                                 if (cMouseHideControl != null)
1076                                 {
1077                                         if (ConfigIni.bウィンドウモード)
1078                                         {
1079                                                 cMouseHideControl.Show();
1080                                         }
1081                                         else
1082                                         {
1083                                                 cMouseHideControl.Hide();
1084                                         }
1085                                 }
1086 #endif
1087                         }
1088                 }
1089
1090                 #region [ #24609 リザルト画像をpngで保存する ]              // #24609 2011.3.14 yyagi; to save result screen in case BestRank or HiSkill.
1091                 /// <summary>
1092                 /// リザルト画像のキャプチャと保存。
1093                 /// </summary>
1094                 /// <param name="strFilename">保存するファイル名(フルパス)</param>
1095                 public bool SaveResultScreen(string strFullPath)
1096                 {
1097                         string strSavePath = Path.GetDirectoryName(strFullPath);
1098                         if (!Directory.Exists(strSavePath))
1099                         {
1100                                 try
1101                                 {
1102                                         Directory.CreateDirectory(strSavePath);
1103                                 }
1104                                 catch
1105                                 {
1106                                         return false;
1107                                 }
1108                         }
1109
1110                         // http://www.gamedev.net/topic/594369-dx9slimdxati-incorrect-saving-surface-to-file/
1111                         using (Surface pSurface = CDTXMania.Instance.Device.GetRenderTarget(0))
1112                         {
1113                                 Surface.ToFile(pSurface, strFullPath, ImageFileFormat.Png);
1114                         }
1115                         return true;
1116                 }
1117                 #endregion
1118
1119                 // Game 実装
1120
1121                 protected override void Initialize()
1122                 {
1123                         //                      new GCBeep();
1124                         //sw.Start();
1125                         //swlist1 = new List<int>( 8192 );
1126                         //swlist2 = new List<int>( 8192 );
1127                         //swlist3 = new List<int>( 8192 );
1128                         //swlist4 = new List<int>( 8192 );
1129                         //swlist5 = new List<int>( 8192 );
1130                         if (this.listトップレベルActivities != null)
1131                         {
1132                                 foreach (CActivity activity in this.listトップレベルActivities)
1133                                         activity.OnManagedリソースの作成();
1134                         }
1135
1136                         foreach (STPlugin st in this.listプラグイン)
1137                         {
1138                                 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
1139                                 st.plugin.OnManagedリソースの作成();
1140                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1141                         }
1142 #if GPUFlushAfterPresent
1143                         FrameEnd += dtxmania_FrameEnd;
1144 #endif
1145                 }
1146 #if GPUFlushAfterPresent
1147                 void dtxmania_FrameEnd( object sender, EventArgs e )    // GraphicsDeviceManager.game_FrameEnd()後に実行される
1148                 {                                                                                                               // → Present()直後にGPUをFlushする
1149                                                                                                                                 // → 画面のカクツキが頻発したため、ここでのFlushは行わない
1150                         actFlushGPU.On進行描画();           // Flush GPU
1151                 }
1152 #endif
1153                 protected override void LoadContent()
1154                 {
1155                         if (cMouseHideControl != null)
1156                         {
1157                                 if (ConfigIni.bウィンドウモード)
1158                                 {
1159                                         cMouseHideControl.Show();
1160                                 }
1161                                 else
1162                                 {
1163                                         cMouseHideControl.Hide();
1164                                 }
1165                         }
1166                         this.Device.SetTransform(TransformState.View, Matrix.LookAtLH(new Vector3(0f, 0f, (float)(-SampleFramework.GameWindowSize.Height / 2 * Math.Sqrt(3.0))), new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f)));
1167                         this.Device.SetTransform(TransformState.Projection, Matrix.PerspectiveFovLH(C変換.DegreeToRadian((float)60f), ((float)this.Device.Viewport.Width) / ((float)this.Device.Viewport.Height), -100f, 100f));
1168                         this.Device.SetRenderState(RenderState.Lighting, false);
1169                         this.Device.SetRenderState(RenderState.ZEnable, false);                                         // trueにすると、一部システムで画面表示できなくなる
1170                         this.Device.SetRenderState(RenderState.AntialiasedLineEnable, false);       // trueにすると、一部システムで画面表示できなくなる 
1171                         this.Device.SetRenderState(RenderState.AlphaTestEnable, true);
1172                         this.Device.SetRenderState(RenderState.AlphaRef, 10);
1173
1174                         this.Device.SetRenderState(RenderState.MultisampleAntialias, true);
1175                         this.Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
1176                         this.Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
1177
1178                         this.Device.SetRenderState<Compare>(RenderState.AlphaFunc, Compare.Greater);
1179                         this.Device.SetRenderState(RenderState.AlphaBlendEnable, true);
1180                         this.Device.SetRenderState<Blend>(RenderState.SourceBlend, Blend.SourceAlpha);
1181                         this.Device.SetRenderState<Blend>(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
1182                         this.Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate);
1183                         this.Device.SetTextureStageState(0, TextureStage.AlphaArg1, 2);
1184                         this.Device.SetTextureStageState(0, TextureStage.AlphaArg2, 1);
1185
1186                         if (this.listトップレベルActivities != null)
1187                         {
1188                                 foreach (CActivity activity in this.listトップレベルActivities)
1189                                         activity.OnUnmanagedリソースの作成();
1190                         }
1191
1192                         foreach (STPlugin st in this.listプラグイン)
1193                         {
1194                                 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
1195                                 st.plugin.OnUnmanagedリソースの作成();
1196                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1197                         }
1198                 }
1199                 protected override void UnloadContent()
1200                 {
1201                         if (this.listトップレベルActivities != null)
1202                         {
1203                                 foreach (CActivity activity in this.listトップレベルActivities)
1204                                         activity.OnUnmanagedリソースの解放();
1205                         }
1206
1207                         foreach (STPlugin st in this.listプラグイン)
1208                         {
1209                                 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
1210                                 st.plugin.OnUnmanagedリソースの解放();
1211                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1212                         }
1213                 }
1214                 protected override void OnExiting(EventArgs e)
1215                 {
1216                         CPowerManagement.tEnableMonitorSuspend();       // スリープ抑止状態を解除
1217                         this.t終了処理();
1218                         base.OnExiting(e);
1219                 }
1220                 protected override void Update(GameTime gameTime)
1221                 {
1222                 }
1223                 protected override void Draw(GameTime gameTime)
1224                 {
1225                         if (Sound管理 == null)
1226                         {
1227                                 return;
1228                         }
1229                         //Sound管理.t再生中の処理をする();
1230
1231                         if (Timer != null)
1232                                 Timer.t更新();
1233                         if (CSound管理.rc演奏用タイマ != null)
1234                                 CSound管理.rc演奏用タイマ.t更新();
1235
1236                         if (Input管理 != null)
1237                                 Input管理.tポーリング(this.bApplicationActive, CDTXMania.Instance.ConfigIni.bBufferedInput);
1238
1239                         if (FPS != null)
1240                                 FPS.tカウンタ更新();
1241
1242                         //if( Pad != null )                                     ポーリング時にクリアしたらダメ!曲の開始時に1回だけクリアする。(2010.9.11)
1243                         //      Pad.st検知したデバイス.Clear();
1244
1245                         if (this.Device == null)
1246                                 return;
1247
1248                         if (this.bApplicationActive)    // DTXMania本体起動中の本体/モニタの省電力モード移行を抑止
1249                                 CPowerManagement.tDisableMonitorSuspend();
1250
1251                         // #xxxxx 2013.4.8 yyagi; sleepの挿入位置を、EndScnene~Present間から、BeginScene前に移動。描画遅延を小さくするため。
1252                         #region [ スリープ ]
1253                         if (ConfigIni.nSleepPerFrameMs >= 0)            // #xxxxx 2011.11.27 yyagi
1254                         {
1255                                 Thread.Sleep(ConfigIni.nSleepPerFrameMs);
1256                         }
1257                         #endregion
1258
1259                         #region [ DTXCreator/DTX2WAVからの指示 ]
1260                         if (this.Window.IsReceivedMessage)  // ウインドウメッセージで、
1261                         {
1262                                 string strMes = this.Window.strMessage;
1263                                 this.Window.IsReceivedMessage = false;
1264                                 if (strMes != null)
1265                                 {
1266                                         CommandParse.ParseArguments(strMes, ref DTXVmode, ref DTX2WAVmode);
1267
1268                                         if (DTXVmode.Enabled)
1269                                         {
1270                                                 bコンパクトモード = true;
1271                                                 strコンパクトモードファイル = DTXVmode.filename;
1272                                                 if (DTXVmode.Command == CDTXVmode.ECommand.Preview)
1273                                                 {
1274                                                         // preview soundの再生
1275                                                         string strPreviewFilename = DTXVmode.previewFilename;
1276                                                         //Trace.TraceInformation( "Preview Filename=" + DTXVmode.previewFilename );
1277                                                         try
1278                                                         {
1279                                                                 if (this.previewSound != null)
1280                                                                 {
1281                                                                         this.previewSound.tサウンドを停止する();
1282                                                                         this.previewSound.Dispose();
1283                                                                         this.previewSound = null;
1284                                                                 }
1285                                                                 this.previewSound = CDTXMania.Instance.Sound管理.tサウンドを生成する(strPreviewFilename);
1286                                                                 this.previewSound.n音量 = DTXVmode.previewVolume;
1287                                                                 this.previewSound.n位置 = DTXVmode.previewPan;
1288                                                                 this.previewSound.t再生を開始する();
1289                                                                 Trace.TraceInformation("DTXCからの指示で、サウンドを生成しました。({0})", strPreviewFilename);
1290                                                         }
1291                                                         catch
1292                                                         {
1293                                                                 Trace.TraceError("DTXCからの指示での、サウンドの生成に失敗しました。({0})", strPreviewFilename);
1294                                                                 if (this.previewSound != null)
1295                                                                 {
1296                                                                         this.previewSound.Dispose();
1297                                                                 }
1298                                                                 this.previewSound = null;
1299                                                         }
1300                                                 }
1301                                         }
1302                                         if (DTX2WAVmode.Enabled)
1303                                         {
1304                                                 if (DTX2WAVmode.Command == CDTX2WAVmode.ECommand.Cancel)
1305                                                 {
1306                                                         Trace.TraceInformation("録音のCancelコマンドをDTXMania本体が受信しました。");
1307                                                         //Microsoft.VisualBasic.Interaction.AppActivate("メモ帳");
1308                                                         //SendKeys.Send("{ESC}");
1309                                                         //SendKeys.SendWait("%{F4}");
1310                                                         //Application.Exit();
1311                                                         if (DTX != null)        // 曲読み込みの前に録音Cancelされると、DTXがnullのままここにきてでGPFとなる→nullチェック追加
1312                                                         {
1313                                                                 DTX.t全チップの再生停止();
1314                                                                 DTX.On非活性化();
1315                                                         }
1316                                                         r現在のステージ.On非活性化();
1317
1318                                                         //Environment.ExitCode = 10010;         // この組み合わせではダメ、返り値が反映されない
1319                                                         //base.Window.Close();
1320                                                         Environment.Exit(10010);                        // このやり方ならばOK
1321                                                 }
1322                                         }
1323                                 }
1324                         }
1325                         #endregion
1326
1327                         this.Device.BeginScene();
1328                         this.Device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, SharpDX.Color.Black, 1f, 0);
1329
1330                         if (r現在のステージ != null)
1331                         {
1332                                 this.n進行描画の戻り値 = (r現在のステージ != null) ? r現在のステージ.On進行描画() : 0;
1333
1334                                 #region [ プラグインの進行描画 ]
1335                                 //---------------------
1336                                 foreach (STPlugin sp in this.listプラグイン)
1337                                 {
1338                                         Directory.SetCurrentDirectory(sp.strプラグインフォルダ);
1339
1340                                         if (CDTXMania.Instance.act現在入力を占有中のプラグイン == null || CDTXMania.Instance.act現在入力を占有中のプラグイン == sp.plugin)
1341                                                 sp.plugin.On進行描画(CDTXMania.Instance.Pad, CDTXMania.Instance.Input管理.Keyboard);
1342                                         else
1343                                                 sp.plugin.On進行描画(null, null);
1344
1345                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1346                                 }
1347                                 //---------------------
1348                                 #endregion
1349
1350                                 #region [ DTX2WAVモード時、ステージが変わるたびに、そのことをDTX2WAVアプリ側に通知する ]
1351                                 if (DTX2WAVmode.Enabled && r現在のステージ != r1フレーム前のステージ)
1352                                 {
1353                                         r1フレーム前のステージ = r現在のステージ;
1354                                         //Trace.TraceInformation("Stage変更 to : " + r現在のステージ.eステージID.ToString());
1355                                         switch (r現在のステージ.eステージID)
1356                                         {
1357                                                 case CStage.Eステージ.曲読み込み:
1358                                                         DTX2WAVmode.SendMessage2DTX2WAV("LOAD");
1359                                                         break;
1360                                                 case CStage.Eステージ.演奏:
1361                                                         DTX2WAVmode.SendMessage2DTX2WAV("PLAY");
1362                                                         break;
1363                                                 default:
1364                                                         break;
1365                                         }
1366                                 }
1367                                 #endregion
1368
1369                                 CScoreIni scoreIni = null;
1370
1371                                 if (Control.IsKeyLocked(Keys.CapsLock))             // #30925 2013.3.11 yyagi; capslock=ON時は、EnumSongsしないようにして、起動負荷とASIOの音切れの関係を確認する
1372                                 {
1373                                         // → songs.db等の書き込み時だと音切れするっぽい
1374                                         actEnumSongs.On非活性化();
1375                                         EnumSongs.SongListEnumCompletelyDone();
1376                                         CDTXMania.Instance.stage選曲.bIsEnumeratingSongs = false;
1377                                 }
1378                                 #region [ 曲検索スレッドの起動/終了 ここに"Enumerating Songs..."表示を集約 ]
1379                                 if (!CDTXMania.Instance.bコンパクトモード)
1380                                 {
1381                                         actEnumSongs.On進行描画();                          // "Enumerating Songs..."アイコンの描画
1382                                 }
1383                                 switch (r現在のステージ.eステージID)
1384                                 {
1385                                         case CStage.Eステージ.タイトル:
1386                                         case CStage.Eステージ.コンフィグ:
1387                                         case CStage.Eステージ.選曲:
1388                                         case CStage.Eステージ.曲読み込み:
1389                                                 if (EnumSongs != null)
1390                                                 {
1391                             #region [ (特定条件時) 曲検索スレッドの起動・開始 ]
1392                                                         if (r現在のステージ.eステージID == CStage.Eステージ.タイトル &&
1393                                                                          r直前のステージ.eステージID == CStage.Eステージ.起動 &&
1394                                                                          this.n進行描画の戻り値 == (int)CStageタイトル.E戻り値.継続 &&
1395                                                                          !EnumSongs.IsSongListEnumStarted)
1396                                                         {
1397                                                                 actEnumSongs.On活性化();
1398                                                                 CDTXMania.Instance.stage選曲.bIsEnumeratingSongs = true;
1399                                                                 EnumSongs.Init(CDTXMania.Instance.Songs管理.listSongsDB, CDTXMania.Instance.Songs管理.nSongsDBから取得できたスコア数); // songs.db情報と、取得した曲数を、新インスタンスにも与える
1400                                                                 EnumSongs.StartEnumFromDisk();      // 曲検索スレッドの起動・開始
1401                                                                 if (CDTXMania.Instance.Songs管理.nSongsDBから取得できたスコア数 == 0)    // もし初回起動なら、検索スレッドのプライオリティをLowestでなくNormalにする
1402                                                                 {
1403                                                                         EnumSongs.ChangeEnumeratePriority(ThreadPriority.Normal);
1404                                                                 }
1405                                                         }
1406                                                         #endregion
1407
1408                                                         #region [ 曲検索の中断と再開 ]
1409                                                         if (r現在のステージ.eステージID == CStage.Eステージ.選曲 && !EnumSongs.IsSongListEnumCompletelyDone)
1410                                                         {
1411                                                                 switch (this.n進行描画の戻り値)
1412                                                                 {
1413                                                                         case 0:     // 何もない
1414                                                                                                                         //if ( CDTXMania.Instance.stage選曲.bIsEnumeratingSongs )
1415                                                                                 if (!CDTXMania.Instance.stage選曲.bIsPlayingPremovie)
1416                                                                                 {
1417                                                                                         EnumSongs.Resume();                     // #27060 2012.2.6 yyagi 中止していたバックグランド曲検索を再開
1418                                                                                         EnumSongs.IsSlowdown = false;
1419                                                                                 }
1420                                                                                 else
1421                                                                                 {
1422                                                                                         // EnumSongs.Suspend();                                 // #27060 2012.3.2 yyagi #PREMOVIE再生中は曲検索を低速化
1423                                                                                         EnumSongs.IsSlowdown = true;
1424                                                                                 }
1425                                                                                 actEnumSongs.On活性化();
1426                                                                                 break;
1427
1428                                                                         case 2:     // 曲決定
1429                                                                                 EnumSongs.Suspend();                        // #27060 バックグラウンドの曲検索を一時停止
1430                                                                                 actEnumSongs.On非活性化();
1431                                                                                 break;
1432                                                                 }
1433                                                         }
1434                                                         #endregion
1435
1436                                                         #region [ 曲探索中断待ち待機 ]
1437                                                         if (r現在のステージ.eステージID == CStage.Eステージ.曲読み込み && !EnumSongs.IsSongListEnumCompletelyDone &&
1438                                                                         EnumSongs.thDTXFileEnumerate != null)                           // #28700 2012.6.12 yyagi; at Compact mode, enumerating thread does not exist.
1439                                                         {
1440                                                                 EnumSongs.WaitUntilSuspended();                                 // 念のため、曲検索が一時中断されるまで待機
1441                                                         }
1442                                                         #endregion
1443
1444                                                         #region [ 曲検索が完了したら、実際の曲リストに反映する ]
1445                                                         // CStage選曲.On活性化() に回した方がいいかな?
1446                                                         if (EnumSongs.IsSongListEnumerated)
1447                                                         {
1448                                                                 actEnumSongs.On非活性化();
1449                                                                 CDTXMania.Instance.stage選曲.bIsEnumeratingSongs = false;
1450
1451                                                                 bool bRemakeSongTitleBar = (r現在のステージ.eステージID == CStage.Eステージ.選曲) ? true : false;
1452                                                                 CDTXMania.Instance.stage選曲.Refresh(EnumSongs.Songs管理, bRemakeSongTitleBar);
1453                                                                 EnumSongs.SongListEnumCompletelyDone();
1454                                                         }
1455                                                         #endregion
1456                                                 }
1457                                                 break;
1458                                 }
1459                                 #endregion
1460
1461                                 switch (r現在のステージ.eステージID)
1462                                 {
1463                                         case CStage.Eステージ.何もしない:
1464                                                 break;
1465
1466                                         case CStage.Eステージ.起動:
1467                                                 #region [ *** ]
1468                                                 //-----------------------------
1469                                                 if (this.n進行描画の戻り値 != 0)
1470                                                 {
1471                                                         if (!bコンパクトモード)
1472                                                         {
1473                                                                 r現在のステージ.On非活性化();
1474                                                                 Trace.TraceInformation("----------------------");
1475                                                                 Trace.TraceInformation("■ タイトル");
1476                                                                 stageタイトル.On活性化();
1477                                                                 r直前のステージ = r現在のステージ;
1478                                                                 r現在のステージ = stageタイトル;
1479                                                         }
1480                                                         else
1481                                                         {
1482                                                                 r現在のステージ.On非活性化();
1483                                                                 Trace.TraceInformation("----------------------");
1484                                                                 Trace.TraceInformation("■ 曲読み込み");
1485                                                                 stage曲読み込み.On活性化();
1486                                                                 r直前のステージ = r現在のステージ;
1487                                                                 r現在のステージ = stage曲読み込み;
1488
1489                                                         }
1490                                                         foreach (STPlugin pg in this.listプラグイン)
1491                                                         {
1492                                                                 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1493                                                                 pg.plugin.Onステージ変更();
1494                                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1495                                                         }
1496
1497                                                         this.tガベージコレクションを実行する();
1498                                                 }
1499                                                 //-----------------------------
1500                                                 #endregion
1501                                                 break;
1502
1503                                         case CStage.Eステージ.タイトル:
1504                         #region [ *** ]
1505                         //-----------------------------
1506                         switch (this.n進行描画の戻り値)
1507                                                 {
1508                                                         case (int)CStageタイトル.E戻り値.GAMESTART:
1509                                                                 #region [ 選曲処理へ ]
1510                                                                 //-----------------------------
1511                                                                 r現在のステージ.On非活性化();
1512                                                                 Trace.TraceInformation("----------------------");
1513                                                                 Trace.TraceInformation("■ 選曲");
1514                                                                 stage選曲.On活性化();
1515                                                                 r直前のステージ = r現在のステージ;
1516                                                                 r現在のステージ = stage選曲;
1517                                                                 //-----------------------------
1518                                                                 #endregion
1519                                                                 break;
1520
1521                                                         #region [ OPTION: 廃止済 ]
1522                                                         //                                                      case 2:                                                                 // #24525 OPTIONとCONFIGの統合に伴い、OPTIONは廃止
1523                                                         //                                                              #region [ *** ]
1524                                                         //                                                              //-----------------------------
1525                                                         //                                                              r現在のステージ.On非活性化();
1526                                                         //                                                              Trace.TraceInformation( "----------------------" );
1527                                                         //                                                              Trace.TraceInformation( "■ オプション" );
1528                                                         //                                                              stageオプション.On活性化();
1529                                                         //                                                              r直前のステージ = r現在のステージ;
1530                                                         //                                                              r現在のステージ = stageオプション;
1531                                                         //                                                              //-----------------------------
1532                                                         //                                                              #endregion
1533                                                         //                                                              break;
1534                                                         #endregion
1535
1536                                                         case (int)CStageタイトル.E戻り値.CONFIG:
1537                                                                 #region [ *** ]
1538                                                                 //-----------------------------
1539                                                                 r現在のステージ.On非活性化();
1540                                                                 Trace.TraceInformation("----------------------");
1541                                                                 Trace.TraceInformation("■ コンフィグ");
1542                                                                 stageコンフィグ.On活性化();
1543                                                                 r直前のステージ = r現在のステージ;
1544                                                                 r現在のステージ = stageコンフィグ;
1545                                                                 //-----------------------------
1546                                                                 #endregion
1547                                                                 break;
1548
1549                                                         case (int)CStageタイトル.E戻り値.EXIT:
1550                                                                 #region [ *** ]
1551                                                                 //-----------------------------
1552                                                                 r現在のステージ.On非活性化();
1553                                                                 Trace.TraceInformation("----------------------");
1554                                                                 Trace.TraceInformation("■ 終了");
1555                                                                 stage終了.On活性化();
1556                                                                 r直前のステージ = r現在のステージ;
1557                                                                 r現在のステージ = stage終了;
1558                                                                 //-----------------------------
1559                                                                 #endregion
1560                                                                 break;
1561                                                 }
1562
1563                                                 foreach (STPlugin pg in this.listプラグイン)
1564                                                 {
1565                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1566                                                         pg.plugin.Onステージ変更();
1567                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1568                                                 }
1569
1570                                                 //this.tガベージコレクションを実行する();                // #31980 2013.9.3 yyagi タイトル画面でだけ、毎フレームGCを実行して重くなっていた問題の修正
1571                                                 //-----------------------------
1572                                                 #endregion
1573                                                 break;
1574
1575                                         case CStage.Eステージ.コンフィグ:
1576                                                 #region [ *** ]
1577                                                 //-----------------------------
1578                                                 if (this.n進行描画の戻り値 != 0)
1579                                                 {
1580                                                         switch (r直前のステージ.eステージID)
1581                                                         {
1582                                                                 case CStage.Eステージ.タイトル:
1583                                                                         #region [ *** ]
1584                                                                         //-----------------------------
1585                                                                         r現在のステージ.On非活性化();
1586                                                                         Trace.TraceInformation("----------------------");
1587                                                                         Trace.TraceInformation("■ タイトル");
1588                                                                         stageタイトル.On活性化();
1589                                                                         r直前のステージ = r現在のステージ;
1590                                                                         r現在のステージ = stageタイトル;
1591
1592                                                                         foreach (STPlugin pg in this.listプラグイン)
1593                                                                         {
1594                                                                                 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1595                                                                                 pg.plugin.Onステージ変更();
1596                                                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1597                                                                         }
1598
1599                                                                         this.tガベージコレクションを実行する();
1600                                                                         break;
1601                                                                 //-----------------------------
1602                                                                 #endregion
1603
1604                                                                 case CStage.Eステージ.選曲:
1605                                                                         #region [ *** ]
1606                                                                         //-----------------------------
1607                                                                         r現在のステージ.On非活性化();
1608                                                                         Trace.TraceInformation("----------------------");
1609                                                                         Trace.TraceInformation("■ 選曲");
1610                                                                         stage選曲.On活性化();
1611                                                                         r直前のステージ = r現在のステージ;
1612                                                                         r現在のステージ = stage選曲;
1613
1614                                                                         foreach (STPlugin pg in this.listプラグイン)
1615                                                                         {
1616                                                                                 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1617                                                                                 pg.plugin.Onステージ変更();
1618                                                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1619                                                                         }
1620
1621                                                                         this.tガベージコレクションを実行する();
1622                                                                         break;
1623                                                                         //-----------------------------
1624                                                                         #endregion
1625                                                         }
1626                                                 }
1627                                                 //-----------------------------
1628                                                 #endregion
1629                                                 break;
1630
1631                                         case CStage.Eステージ.選曲:
1632                                                 #region [ *** ]
1633                                                 //-----------------------------
1634                                                 switch (this.n進行描画の戻り値)
1635                                                 {
1636                                                         case (int)CStage選曲.E戻り値.タイトルに戻る:
1637                                                                 #region [ *** ]
1638                                                                 //-----------------------------
1639                                                                 r現在のステージ.On非活性化();
1640                                                                 Trace.TraceInformation("----------------------");
1641                                                                 Trace.TraceInformation("■ タイトル");
1642                                                                 stageタイトル.On活性化();
1643                                                                 r直前のステージ = r現在のステージ;
1644                                                                 r現在のステージ = stageタイトル;
1645
1646                                                                 foreach (STPlugin pg in this.listプラグイン)
1647                                                                 {
1648                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1649                                                                         pg.plugin.Onステージ変更();
1650                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1651                                                                 }
1652
1653                                                                 this.tガベージコレクションを実行する();
1654                                                                 break;
1655                                                         //-----------------------------
1656                                                         #endregion
1657
1658                                                         case (int)CStage選曲.E戻り値.選曲した:
1659                                                                 #region [ *** ]
1660                                                                 //-----------------------------
1661                                                                 r現在のステージ.On非活性化();
1662                                                                 Trace.TraceInformation("----------------------");
1663                                                                 Trace.TraceInformation("■ 曲読み込み");
1664                                                                 stage曲読み込み.On活性化();
1665                                                                 r直前のステージ = r現在のステージ;
1666                                                                 r現在のステージ = stage曲読み込み;
1667
1668                                                                 foreach (STPlugin pg in this.listプラグイン)
1669                                                                 {
1670                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1671                                                                         pg.plugin.Onステージ変更();
1672                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1673                                                                 }
1674
1675                                                                 this.tガベージコレクションを実行する();
1676                                                                 break;
1677                                                         //-----------------------------
1678                                                         #endregion
1679
1680                                                         case (int)CStage選曲.E戻り値.コンフィグ呼び出し:
1681                                                                 #region [ *** ]
1682                                                                 //-----------------------------
1683                                                                 r現在のステージ.On非活性化();
1684                                                                 Trace.TraceInformation("----------------------");
1685                                                                 Trace.TraceInformation("■ コンフィグ");
1686                                                                 stageコンフィグ.On活性化();
1687                                                                 r直前のステージ = r現在のステージ;
1688                                                                 r現在のステージ = stageコンフィグ;
1689
1690                                                                 foreach (STPlugin pg in this.listプラグイン)
1691                                                                 {
1692                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1693                                                                         pg.plugin.Onステージ変更();
1694                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1695                                                                 }
1696
1697                                                                 this.tガベージコレクションを実行する();
1698                                                                 break;
1699                                                         //-----------------------------
1700                                                         #endregion
1701
1702                                                         case (int)CStage選曲.E戻り値.スキン変更:
1703
1704                                                                 #region [ *** ]
1705                                                                 //-----------------------------
1706                                                                 r現在のステージ.On非活性化();
1707                                                                 Trace.TraceInformation("----------------------");
1708                                                                 Trace.TraceInformation("■ スキン切り替え");
1709                                                                 stageChangeSkin.On活性化();
1710                                                                 r直前のステージ = r現在のステージ;
1711                                                                 r現在のステージ = stageChangeSkin;
1712                                                                 break;
1713                                                                 //-----------------------------
1714                                                                 #endregion
1715                                                 }
1716                                                 //-----------------------------
1717                                                 #endregion
1718                                                 break;
1719
1720                                         case CStage.Eステージ.曲読み込み:
1721                                                 #region [ *** ]
1722                                                 //-----------------------------
1723                                                 DTXVmode.Refreshed = false;     // 曲のリロード中に発生した再リロードは、無視する。
1724                                                 if (this.n進行描画の戻り値 != 0)
1725                                                 {
1726                                                         CDTXMania.Instance.Pad.st検知したデバイス.Clear();  // 入力デバイスフラグクリア(2010.9.11)
1727                                                         r現在のステージ.On非活性化();
1728                                                         #region [ ESC押下時は、曲の読み込みを中止して選曲画面に戻る ]
1729                                                         if (this.n進行描画の戻り値 == (int)E曲読込画面の戻り値.読込中止)
1730                                                         {
1731                                                                 //DTX.t全チップの再生停止();
1732                                                                 DTX.On非活性化();
1733                                                                 Trace.TraceInformation("曲の読み込みを中止しました。");
1734                                                                 this.tガベージコレクションを実行する();
1735                                                                 Trace.TraceInformation("----------------------");
1736                                                                 Trace.TraceInformation("■ 選曲");
1737                                                                 stage選曲.On活性化();
1738                                                                 r直前のステージ = r現在のステージ;
1739                                                                 r現在のステージ = stage選曲;
1740                                                                 foreach (STPlugin pg in this.listプラグイン)
1741                                                                 {
1742                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1743                                                                         pg.plugin.Onステージ変更();
1744                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1745                                                                 }
1746                                                                 break;
1747                                                         }
1748                                                         #endregion
1749
1750                                                         Trace.TraceInformation("----------------------");
1751                                                         Trace.TraceInformation("■ 演奏(ドラム画面)");
1752                                                         r直前のステージ = r現在のステージ;
1753                                                         r現在のステージ = stage演奏画面;
1754
1755                                                         foreach (STPlugin pg in this.listプラグイン)
1756                                                         {
1757                                                                 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1758                                                                 pg.plugin.Onステージ変更();
1759                                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1760                                                         }
1761
1762                                                         this.tガベージコレクションを実行する();
1763                                                 }
1764                                                 //-----------------------------
1765                                                 #endregion
1766                                                 break;
1767
1768                                         case CStage.Eステージ.演奏:
1769                                                 #region [ *** ]
1770                                                 //-----------------------------
1771                                                 //long n1 = FDK.CSound管理.rc演奏用タイマ.nシステム時刻ms;
1772                                                 //long n2 = FDK.CSound管理.SoundDevice.n経過時間ms;
1773                                                 //long n3 = FDK.CSound管理.SoundDevice.tmシステムタイマ.nシステム時刻ms;
1774                                                 //long n4 = FDK.CSound管理.rc演奏用タイマ.n現在時刻;
1775                                                 //long n5 = FDK.CSound管理.SoundDevice.n経過時間を更新したシステム時刻ms;
1776
1777                                                 //swlist1.Add( Convert.ToInt32(n1) );
1778                                                 //swlist2.Add( Convert.ToInt32(n2) );
1779                                                 //swlist3.Add( Convert.ToInt32( n3 ) );
1780                                                 //swlist4.Add( Convert.ToInt32( n4 ) );
1781                                                 //swlist5.Add( Convert.ToInt32( n5 ) );
1782
1783                                                 #region [ DTXVモード中にDTXCreatorから指示を受けた場合の処理 ]
1784                                                 if (DTXVmode.Enabled && DTXVmode.Refreshed)
1785                                                 {
1786                                                         DTXVmode.Refreshed = false;
1787
1788                                                         if (DTXVmode.Command == CDTXVmode.ECommand.Stop)
1789                                                         {
1790                                                                 CDTXMania.Instance.stage演奏画面.t停止();
1791
1792                                                                 if (previewSound != null)
1793                                                                 {
1794                                                                         this.previewSound.tサウンドを停止する();
1795                                                                         this.previewSound.Dispose();
1796                                                                         this.previewSound = null;
1797                                                                 }
1798                                                                 //{
1799                                                                 //    int lastd = 0;
1800                                                                 //    int f = 0;
1801                                                                 //    for ( int i = 0; i < swlist1.Count; i++ )
1802                                                                 //    {
1803                                                                 //        int d1 = swlist1[ i ];
1804                                                                 //        int d2 = swlist2[ i ];
1805                                                                 //        int d3 = swlist3[ i ];
1806                                                                 //        int d4 = swlist4[ i ];
1807                                                                 //        int d5 = swlist5[ i ];
1808
1809                                                                 //        int dif = d1 - lastd;
1810                                                                 //        string s = "";
1811                                                                 //        if ( 16 <= dif && dif <= 17 )
1812                                                                 //        {
1813                                                                 //        }
1814                                                                 //        else
1815                                                                 //        {
1816                                                                 //            s = "★";
1817                                                                 //        }
1818                                                                 //        Trace.TraceInformation( "frame {0:D4}: {1:D3} ( {2:D3}, {3:D3} - {7:D3}, {4:D3} ) {5}, n現在時刻={6}", f, dif, d1, d2, d3, s, d4, d5 );
1819                                                                 //        lastd = d1;
1820                                                                 //        f++;
1821                                                                 //    }
1822                                                                 //    swlist1.Clear();
1823                                                                 //    swlist2.Clear();
1824                                                                 //    swlist3.Clear();
1825                                                                 //    swlist4.Clear();
1826                                                                 //    swlist5.Clear();
1827
1828                                                                 //}
1829                                                         }
1830                                                         else if (DTXVmode.Command == CDTXVmode.ECommand.Play)
1831                                                         {
1832                                                                 if (DTXVmode.NeedReload)
1833                                                                 {
1834                                                                         CDTXMania.Instance.stage演奏画面.t再読込();
1835                                                                         if (DTXVmode.GRmode)
1836                                                                         {
1837                                                                                 CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.GBOnly;
1838                                                                         }
1839                                                                         else
1840                                                                         {
1841                                                                                 CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.Both;
1842                                                                         }
1843                                                                         CDTXMania.Instance.ConfigIni.bTimeStretch.Value = DTXVmode.TimeStretch;
1844                                                                         CSound管理.bIsTimeStretch = DTXVmode.TimeStretch;
1845                                                                         if (CDTXMania.Instance.ConfigIni.bVSyncWait != DTXVmode.VSyncWait)
1846                                                                         {
1847                                                                                 CDTXMania.Instance.ConfigIni.bVSyncWait.Value = DTXVmode.VSyncWait;
1848                                                                                 CDTXMania.Instance.b次のタイミングで垂直帰線同期切り替えを行う = true;
1849                                                                         }
1850                                                                 }
1851                                                                 else
1852                                                                 {
1853                                                                         CDTXMania.Instance.stage演奏画面.t演奏位置の変更(CDTXMania.Instance.DTXVmode.nStartBar);
1854                                                                 }
1855                                                         }
1856                                                 }
1857                                                 #endregion
1858
1859                                                 switch (this.n進行描画の戻り値)
1860                                                 {
1861                                                         case (int)E演奏画面の戻り値.再読込_再演奏:
1862                                                                 #region [ DTXファイルを再読み込みして、再演奏 ]
1863                                                                 DTX.t全チップの再生停止();
1864                                                                 DTX.On非活性化();
1865                                                                 r現在のステージ.On非活性化();
1866                                                                 stage曲読み込み.On活性化();
1867                                                                 r直前のステージ = r現在のステージ;
1868                                                                 r現在のステージ = stage曲読み込み;
1869                                                                 this.tガベージコレクションを実行する();
1870                                                                 break;
1871                                                         #endregion
1872
1873                                                         //case (int) E演奏画面の戻り値.再演奏:
1874                                                         #region [ 再読み込み無しで、再演奏 ]
1875                                                         #endregion
1876                                                         //      break;
1877
1878                                                         case (int)E演奏画面の戻り値.継続:
1879                                                                 break;
1880
1881                                                         case (int)E演奏画面の戻り値.演奏中断:
1882                                                                 #region [ 演奏キャンセル ]
1883                                                                 //-----------------------------
1884                                                                 scoreIni = this.tScoreIniへBGMAdjustとHistoryとPlayCountを更新("Play canceled");
1885                                                                 if (CDTXMania.Instance.ConfigIni.bIsSwappedGuitarBass)      // #35417 2015.8.18 yyagi Gt/Bsを入れ替えていたなら、演奏設定を元に戻す
1886                                                                 {
1887                                                                         //CDTXMania.Instance.DTX.SwapGuitarBassInfos();                                         // 譜面情報も元に戻す (現在は再演奏機能なしのため、元に戻す必要はない)
1888                                                                 }
1889
1890                                                                 //int lastd = 0;
1891                                                                 //int f = 0;
1892                                                                 //for (int i = 0; i < swlist1.Count; i++)
1893                                                                 //{
1894                                                                 //    int d1 = swlist1[ i ];
1895                                                                 //    int d2 = swlist2[ i ];
1896                                                                 //    int d3 = swlist3[ i ];
1897                                                                 //    int d4 = swlist4[ i ];
1898
1899                                                                 //    int dif = d1 - lastd;
1900                                                                 //    string s = "";
1901                                                                 //    if ( 16 <= dif && dif <= 17 )
1902                                                                 //    {
1903                                                                 //    }
1904                                                                 //    else
1905                                                                 //    {
1906                                                                 //        s = "★";
1907                                                                 //    }
1908                                                                 //    Trace.TraceInformation( "frame {0:D4}: {1:D3} ( {2:D3}, {3:D3}, {4:D3} ) {5}, n現在時刻={6}", f, dif, d1, d2, d3, s, d4 );
1909                                                                 //    lastd = d1;
1910                                                                 //    f++;
1911                                                                 //}
1912                                                                 //swlist1.Clear();
1913                                                                 //swlist2.Clear();
1914                                                                 //swlist3.Clear();
1915                                                                 //swlist4.Clear();
1916
1917                                                                 #region [ プラグイン On演奏キャンセル() の呼び出し ]
1918                                                                 //---------------------
1919                                                                 foreach (STPlugin pg in this.listプラグイン)
1920                                                                 {
1921                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1922                                                                         pg.plugin.On演奏キャンセル(scoreIni);
1923                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1924                                                                 }
1925                                                                 //---------------------
1926                                                                 #endregion
1927
1928                                                                 DTX.t全チップの再生停止();
1929                                                                 DTX.On非活性化();
1930                                                                 r現在のステージ.On非活性化();
1931                                                                 if (DTX2WAVmode.Enabled)
1932                                                                 {
1933                                                                         Environment.Exit(0);
1934                                                                 }
1935                                                                 if (bコンパクトモード)
1936                                                                 {
1937                                                                         base.Window.Close();
1938                                                                 }
1939                                                                 else
1940                                                                 {
1941                                                                         Trace.TraceInformation("----------------------");
1942                                                                         Trace.TraceInformation("■ 選曲");
1943                                                                         stage選曲.On活性化();
1944                                                                         r直前のステージ = r現在のステージ;
1945                                                                         r現在のステージ = stage選曲;
1946
1947                                                                         #region [ プラグイン Onステージ変更() の呼び出し ]
1948                                                                         //---------------------
1949                                                                         foreach (STPlugin pg in this.listプラグイン)
1950                                                                         {
1951                                                                                 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1952                                                                                 pg.plugin.Onステージ変更();
1953                                                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1954                                                                         }
1955                                                                         //---------------------
1956                                                                         #endregion
1957
1958                                                                         this.tガベージコレクションを実行する();
1959                                                                 }
1960                                                                 break;
1961                                                         //-----------------------------
1962                                                         #endregion
1963
1964                                                         case (int)E演奏画面の戻り値.ステージ失敗:
1965                                                                 #region [ 演奏失敗(StageFailed) ]
1966                                                                 //-----------------------------
1967                                                                 scoreIni = this.tScoreIniへBGMAdjustとHistoryとPlayCountを更新("Stage failed");
1968
1969                                                                 #region [ プラグイン On演奏失敗() の呼び出し ]
1970                                                                 //---------------------
1971                                                                 foreach (STPlugin pg in this.listプラグイン)
1972                                                                 {
1973                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1974                                                                         pg.plugin.On演奏失敗(scoreIni);
1975                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1976                                                                 }
1977                                                                 //---------------------
1978                                                                 #endregion
1979
1980                                                                 DTX.t全チップの再生停止();
1981                                                                 DTX.On非活性化();
1982                                                                 r現在のステージ.On非活性化();
1983                                                                 if (bコンパクトモード)
1984                                                                 {
1985                                                                         base.Window.Close();
1986                                                                 }
1987                                                                 else
1988                                                                 {
1989                                                                         Trace.TraceInformation("----------------------");
1990                                                                         Trace.TraceInformation("■ 選曲");
1991                                                                         stage選曲.On活性化();
1992                                                                         r直前のステージ = r現在のステージ;
1993                                                                         r現在のステージ = stage選曲;
1994
1995                                                                         #region [ プラグイン Onステージ変更() の呼び出し ]
1996                                                                         //---------------------
1997                                                                         foreach (STPlugin pg in this.listプラグイン)
1998                                                                         {
1999                                                                                 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
2000                                                                                 pg.plugin.Onステージ変更();
2001                                                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
2002                                                                         }
2003                                                                         //---------------------
2004                                                                         #endregion
2005
2006                                                                         this.tガベージコレクションを実行する();
2007                                                                 }
2008                                                                 break;
2009                                                         //-----------------------------
2010                                                         #endregion
2011
2012                                                         case (int)E演奏画面の戻り値.ステージクリア:
2013                                                                 #region [ 演奏クリア ]
2014                                                                 //-----------------------------
2015                                                                 STDGBSValue<CScoreIni.C演奏記録> record;
2016                                                                 record = stage演奏画面.Record;
2017
2018                                                                 double playskill = 0.0;
2019
2020                                                                 for (EPart inst = EPart.Drums; inst <= EPart.Bass; ++inst)
2021                                                                 {
2022                                                                         if (!record[inst].b全AUTOである && record[inst].n全チップ数 > 0)
2023                                                                         {
2024                                                                                 playskill = record[inst].db演奏型スキル値;
2025                                                                         }
2026                                                                 }
2027
2028                                                                 string str = "Cleared";
2029                                                                 switch (CScoreIni.t総合ランク値を計算して返す(record))
2030                                                                 {
2031                                                                         case CScoreIni.ERANK.SS:
2032                                                                                 str = string.Format("Cleared (SS: {0:F2})", playskill);
2033                                                                                 break;
2034
2035                                                                         case CScoreIni.ERANK.S:
2036                                                                                 str = string.Format("Cleared (S: {0:F2})", playskill);
2037                                                                                 break;
2038
2039                                                                         case CScoreIni.ERANK.A:
2040                                                                                 str = string.Format("Cleared (A: {0:F2})", playskill);
2041                                                                                 break;
2042
2043                                                                         case CScoreIni.ERANK.B:
2044                                                                                 str = string.Format("Cleared (B: {0:F2})", playskill);
2045                                                                                 break;
2046
2047                                                                         case CScoreIni.ERANK.C:
2048                                                                                 str = string.Format("Cleared (C: {0:F2})", playskill);
2049                                                                                 break;
2050
2051                                                                         case CScoreIni.ERANK.D:
2052                                                                                 str = string.Format("Cleared (D: {0:F2})", playskill);
2053                                                                                 break;
2054
2055                                                                         case CScoreIni.ERANK.E:
2056                                                                                 str = string.Format("Cleared (E: {0:F2})", playskill);
2057                                                                                 break;
2058
2059                                                                         case CScoreIni.ERANK.UNKNOWN:   // #23534 2010.10.28 yyagi add: 演奏チップが0個のとき
2060                                                                                 str = "Cleared (No chips)";
2061                                                                                 break;
2062                                                                 }
2063
2064                                                                 scoreIni = this.tScoreIniへBGMAdjustとHistoryとPlayCountを更新(str);
2065
2066                                                                 #region [ プラグイン On演奏クリア() の呼び出し ]
2067                                                                 //---------------------
2068                                                                 foreach (STPlugin pg in this.listプラグイン)
2069                                                                 {
2070                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
2071                                                                         pg.plugin.On演奏クリア(scoreIni);
2072                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
2073                                                                 }
2074                                                                 //---------------------
2075                                                                 #endregion
2076
2077                                                                 r現在のステージ.On非活性化();
2078                                                                 Trace.TraceInformation("----------------------");
2079                                                                 Trace.TraceInformation("■ 結果");
2080                                                                 stage結果.st演奏記録 = record;
2081                                                                 stage結果.r空うちドラムチップ = stage演奏画面.GetNoChipDrums();
2082                                                                 stage結果.On活性化();
2083                                                                 r直前のステージ = r現在のステージ;
2084                                                                 r現在のステージ = stage結果;
2085
2086                                                                 #region [ プラグイン Onステージ変更() の呼び出し ]
2087                                                                 //---------------------
2088                                                                 foreach (STPlugin pg in this.listプラグイン)
2089                                                                 {
2090                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
2091                                                                         pg.plugin.Onステージ変更();
2092                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
2093                                                                 }
2094                                                                 //---------------------
2095                                                                 #endregion
2096
2097                                                                 break;
2098                                                                 //-----------------------------
2099                                                                 #endregion
2100                                                 }
2101                                                 //-----------------------------
2102                                                 #endregion
2103                                                 break;
2104
2105                                         case CStage.Eステージ.結果:
2106                                                 #region [ *** ]
2107                                                 //-----------------------------
2108                                                 if (this.n進行描画の戻り値 != 0)
2109                                                 {
2110                                                         // #35417 2015.08.30 chnmr0 changed : ステージクリア処理で入れ替えるため元に戻した
2111                                                         // #35417 2015.8.18 yyagi: AUTO系のフラグ入れ替えは削除可能!?。以後AUTOフラグに全くアクセスしておらず、意味がないため。
2112                                                         if (CDTXMania.Instance.ConfigIni.bIsSwappedGuitarBass)      // #24415 2011.2.27 yyagi Gt/Bsを入れ替えていたなら、Auto状態をリザルト画面終了後に元に戻す
2113                                                         {
2114                                                                 CDTXMania.Instance.ConfigIni.SwapGuitarBassInfos_AutoFlags();   // Auto入れ替え
2115                                                         }
2116
2117                                                         DTX.t全チップの再生一時停止();
2118                                                         DTX.On非活性化();
2119                                                         r現在のステージ.On非活性化();
2120                                                         if (!bコンパクトモード)
2121                                                         {
2122                                                                 Trace.TraceInformation("----------------------");
2123                                                                 Trace.TraceInformation("■ 選曲");
2124                                                                 stage選曲.On活性化();
2125                                                                 r直前のステージ = r現在のステージ;
2126                                                                 r現在のステージ = stage選曲;
2127
2128                                                                 foreach (STPlugin pg in this.listプラグイン)
2129                                                                 {
2130                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
2131                                                                         pg.plugin.Onステージ変更();
2132                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
2133                                                                 }
2134
2135                                                                 this.tガベージコレクションを実行する();
2136                                                         }
2137                                                         else
2138                                                         {
2139                                                                 base.Window.Close();
2140                                                         }
2141                                                 }
2142                                                 //-----------------------------
2143                                                 #endregion
2144                                                 break;
2145
2146                                         case CStage.Eステージ.ChangeSkin:
2147                                                 #region [ *** ]
2148                                                 //-----------------------------
2149                                                 if (this.n進行描画の戻り値 != 0)
2150                                                 {
2151                                                         r現在のステージ.On非活性化();
2152                                                         Trace.TraceInformation("----------------------");
2153                                                         Trace.TraceInformation("■ 選曲");
2154                                                         stage選曲.On活性化();
2155                                                         r直前のステージ = r現在のステージ;
2156                                                         r現在のステージ = stage選曲;
2157                                                         this.tガベージコレクションを実行する();
2158                                                 }
2159                                                 //-----------------------------
2160                                                 #endregion
2161                                                 break;
2162
2163                                         case CStage.Eステージ.終了:
2164                                                 #region [ *** ]
2165                                                 //-----------------------------
2166                                                 if (this.n進行描画の戻り値 != 0)
2167                                                 {
2168                                                         base.Exit();
2169                                                 }
2170                                                 //-----------------------------
2171                                                 #endregion
2172                                                 break;
2173                                 }
2174                         }
2175                         this.Device.EndScene();
2176                         // Present()は game.csのOnFrameEnd()に登録された、GraphicsDeviceManager.game_FrameEnd() 内で実行されるので不要
2177                         // (つまり、Present()は、Draw()完了後に実行される)
2178 #if !GPUFlushAfterPresent
2179                         actFlushGPU.On進行描画();       // Flush GPU        // EndScene()~Present()間 (つまりVSync前) でFlush実行
2180 #endif
2181                         if (Sound管理.CurrentSoundDeviceType != ESoundDeviceType.DirectSound)
2182                         {
2183                                 Sound管理.t再生中の処理をする();   // サウンドバッファの更新; 画面描画と同期させることで、スクロールをスムーズにする
2184                         }
2185
2186                         #region [ マウスカーソル消去制御 ]
2187                         if (cMouseHideControl != null) cMouseHideControl.tHideCursorIfNeed();
2188                         #endregion
2189                         #region [ 全画面・ウインドウ切り替え ]
2190                         if (this.b次のタイミングで全画面_ウィンドウ切り替えを行う)
2191                         {
2192                                 // ConfigIni.bFullScreen.Value = !ConfigIni.bFullScreen;
2193                                 Instance.t全画面_ウィンドウモード切り替え();
2194                                 this.b次のタイミングで全画面_ウィンドウ切り替えを行う = false;
2195                         }
2196                         #endregion
2197                         #region [ 垂直基線同期切り替え ]
2198                         if (this.b次のタイミングで垂直帰線同期切り替えを行う)
2199                         {
2200                                 bool bIsMaximized = this.Window.IsMaximized;                                            // #23510 2010.11.3 yyagi: to backup current window mode before changing VSyncWait
2201                                 currentClientSize = this.Window.ClientSize;                                             // #23510 2010.11.3 yyagi: to backup current window size before changing VSyncWait
2202                                 DeviceSettings currentSettings = Instance.GraphicsDeviceManager.CurrentSettings;
2203                                 currentSettings.EnableVSync = ConfigIni.bVSyncWait;
2204                                 Instance.GraphicsDeviceManager.ChangeDevice(currentSettings);
2205                                 this.b次のタイミングで垂直帰線同期切り替えを行う = false;
2206                                 base.Window.ClientSize = new Size(currentClientSize.Width, currentClientSize.Height);   // #23510 2010.11.3 yyagi: to resume window size after changing VSyncWait
2207                                 if (bIsMaximized)
2208                                 {
2209                                         this.Window.WindowState = FormWindowState.Maximized;                                // #23510 2010.11.3 yyagi: to resume window mode after changing VSyncWait
2210                                 }
2211                         }
2212                         #endregion
2213
2214                         GC.Collect( 0, GCCollectionMode.Optimized, false );             // Rel105で処理が重くなっていることに対する、暫定処置。
2215                                                                                                                                         // 重くなっている原因に対する適切な処置をして、処理が104程度に軽くなったら、
2216                                                                                                                                         // この暫定処置は削除します。
2217                 }
2218
2219                 /// <summary>
2220                 /// XML ファイルからオブジェクトを生成します。
2221                 /// </summary>
2222                 /// <param name="xmlfile">オブジェクトが記述される XML のパス。これは DataContract によってシリアライズされていなければなりません。</param>
2223                 /// <returns>生成したオブジェクト。正しく生成できなかった場合 null 。</returns>
2224                 public static object DeserializeXML(string xmlpath, Type t)
2225                 {
2226                         object ret = null;
2227                         try
2228                         {
2229                                 if (File.Exists(xmlpath))
2230                                 {
2231                                         using (StreamReader reader = new StreamReader(xmlpath, Encoding.GetEncoding("shift_jis")))
2232                                         using (XmlReader xr = XmlReader.Create(reader))
2233                                         {
2234                                                 DataContractSerializer serializer = new DataContractSerializer(t);
2235                                                 ret = serializer.ReadObject(xr);
2236                                         }
2237                                 }
2238                         }
2239                         catch (Exception e)
2240                         {
2241                                 Trace.TraceWarning( e.Message );
2242                                 ret = null;
2243                         }
2244                         return ret;
2245                 }
2246
2247                 /// <summary>
2248                 /// オブジェクトから XML ファイルを生成します。
2249                 /// </summary>
2250                 /// <param name="xmlfile">XML ファイルのパス。</param>
2251                 /// <param name="obj">XML としてシリアライズするオブジェクト。DataContract 属性を持つクラスからインスタンス化されたオブジェクトです。</param>
2252                 public static void SerializeXML(string xmlpath, object obj)
2253                 {
2254                         XmlWriterSettings settings = new XmlWriterSettings();
2255                         settings.IndentChars = "  ";
2256                         settings.Indent = true;
2257                         settings.NewLineChars = Environment.NewLine;
2258                         settings.Encoding = new System.Text.UTF8Encoding(false);
2259             using (FileStreamSSD fsssd = new FileStreamSSD(xmlpath))
2260             {
2261                 using (XmlWriter xw = XmlWriter.Create(fsssd, settings))
2262                 {
2263                     DataContractSerializer serializer = new DataContractSerializer(obj.GetType());
2264                     serializer.WriteObject(xw, obj);
2265                 }
2266             }
2267                 }
2268
2269                 public void SaveConfig()
2270                 {
2271                         #region [ Skinパスの絶対パス→相対パス変換 ]
2272                         string _strSystemSkinSubfolderPath = ConfigIni.strSystemSkinSubfolderPath.Value;
2273                         Uri uriRoot = new Uri( System.IO.Path.Combine( this.strEXEのあるフォルダ, "System" + System.IO.Path.DirectorySeparatorChar ) );
2274                         if ( ConfigIni.strSystemSkinSubfolderPath.Value != null && ConfigIni.strSystemSkinSubfolderPath.Value.Length == 0 )
2275                         {
2276                                 // Config.iniが空の状態でDTXManiaをViewerとして起動・終了すると、strSystemSkinSubfolderFullName が空の状態でここに来る。
2277                                 // → 初期値として Default/ を設定する。
2278                                 ConfigIni.strSystemSkinSubfolderPath.Value = System.IO.Path.Combine( this.strEXEのあるフォルダ, "System" + System.IO.Path.DirectorySeparatorChar + "Default" + System.IO.Path.DirectorySeparatorChar );
2279                         }
2280
2281                         // 起動直後は(Loadの前にSaveを通るため)Skinパスには初期値の相対パスが入っている場合がある。
2282                         // そのため、以下の処理を通すために、いったん絶対パスに変換
2283                         if ( !System.IO.Path.IsPathRooted( ConfigIni.strSystemSkinSubfolderPath.Value ) )
2284                         {
2285                                 ConfigIni.strSystemSkinSubfolderPath.Value =
2286                                         Path.Combine( Path.Combine( this.strEXEのあるフォルダ, "System" ), ConfigIni.strSystemSkinSubfolderPath );
2287                         }
2288
2289                         Uri uriPath = new Uri( System.IO.Path.Combine( ConfigIni.strSystemSkinSubfolderPath.Value, "." + System.IO.Path.DirectorySeparatorChar ) );
2290                         string relPath = uriRoot.MakeRelativeUri( uriPath ).ToString();                         // 相対パスを取得
2291                         relPath = System.Web.HttpUtility.UrlDecode( relPath );                                          // デコードする
2292                         relPath = relPath.Replace( '/', System.IO.Path.DirectorySeparatorChar );        // 区切り文字が\ではなく/なので置換する
2293                         ConfigIni.strSystemSkinSubfolderPath.Value = relPath;
2294                         #endregion
2295                         ConfigIni.strDTXManiaVersion.Value = CDTXMania.VERSION;
2296
2297                         CDTXMania.SerializeXML( strEXEのあるフォルダ + "Config.xml", ConfigIni );
2298
2299                         // 元の絶対パスに戻す
2300                         ConfigIni.strSystemSkinSubfolderPath.Value = _strSystemSkinSubfolderPath;
2301                 }
2302
2303                 public void LoadConfig()
2304                 {
2305                         string path = strEXEのあるフォルダ + "Config.xml";
2306
2307                         if (!File.Exists(path))
2308                         {
2309                                 SaveConfig();
2310                         }
2311                         if (File.Exists(path))
2312                         {
2313                                 ConfigIni = (CConfigXml)CDTXMania.DeserializeXML(path, typeof(CConfigXml));
2314                                 if (ConfigIni == null)
2315                                 {
2316                                         ConfigIni = new CConfigXml();
2317                                         SaveConfig();
2318                                 }
2319                                 // Skinパスの相対パスを、絶対パスに変換
2320                                 if ( !System.IO.Path.IsPathRooted( ConfigIni.strSystemSkinSubfolderPath.Value ) )
2321                                 {
2322                                         ConfigIni.strSystemSkinSubfolderPath.Value =
2323                                                 Path.Combine( Path.Combine( this.strEXEのあるフォルダ, "System" ), ConfigIni.strSystemSkinSubfolderPath );
2324                                 }
2325                         }
2326
2327                         ConfigIni.UpgradeConfig();      // 本体version upに伴ってConfig.xmlの定義が更新される場合の、最低限のフォローアップ
2328                 }
2329                 /// <summary>
2330                 /// 座標値を読み込む。Coordinates メンバ初期化後いつ呼び出しても構わない。
2331                 /// </summary>
2332                 public void UpdateCoordinates()
2333                 {
2334                         string coordXml = strEXEのあるフォルダ + "Coordinates.xml";
2335  
2336                         // デシリアライズ
2337                         if (File.Exists(coordXml))
2338                         {
2339                                 using (XmlReader xr = XmlReader.Create(coordXml))
2340                                 {
2341                                         DataContractSerializer serializer = new DataContractSerializer(typeof(Coordinates.CCoordinates));
2342                                         try
2343                                         {
2344                                                 Coordinates = (Coordinates.CCoordinates) serializer.ReadObject( xr );
2345                                         }
2346                                         catch (SerializationException e)
2347                                         {
2348                                                 Trace.TraceWarning( "Rel107以前の古いフォーマットのCoordinates.xmlが読み込まれました。無視します。\n" + e.Message );
2349                                         }
2350                                 }
2351                         }
2352                         // シリアライズ
2353                         XmlWriterSettings settings = new XmlWriterSettings();
2354                         settings.IndentChars = "  ";
2355                         settings.Indent = true;
2356                         settings.NewLineChars = Environment.NewLine;
2357                         settings.Encoding = new System.Text.UTF8Encoding( false );
2358                         using ( XmlWriter xw = XmlTextWriter.Create( coordXml, settings ) )
2359                         {
2360                                 //XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
2361                                 //ns.Add( String.Empty, String.Empty );
2362
2363                                 //StreamWriter sw = new StreamWriter( "test2.xml", false, Encoding.UTF8 );
2364                                 //serializer.Serialize( sw, item, ns );
2365                                 //sw.Close
2366
2367                                 DataContractSerializer serializer = new DataContractSerializer( typeof( Coordinates.CCoordinates ) );
2368                                 serializer.WriteObject( xw, Coordinates );
2369                                 //serializer.WriteStartObject( xw, Coordinates );
2370                                 //xw.WriteAttributeString( "xmlns", "d1p1", "http://www.w3.org/2000/xmlns/",
2371                                 //      "http://schemas.microsoft.com/2003/10/Serialization/" );
2372                                 //serializer.WriteObjectContent( xw, Coordinates );
2373                                 //serializer.WriteEndObject( xw );
2374                         }
2375
2376                         // もう一度デシリアライズ
2377                         if (File.Exists(coordXml))
2378                         {
2379                                 using (XmlReader xr = XmlReader.Create(coordXml))
2380                                 {
2381                                         DataContractSerializer serializer = new DataContractSerializer(typeof(Coordinates.CCoordinates));
2382                                         Coordinates = (Coordinates.CCoordinates)serializer.ReadObject(xr);
2383                                 }
2384                         }
2385                 }
2386
2387
2388                 /// <summary>
2389                 /// 保存するxmlからnamespaceを削除するためのXmlTextWriter
2390                 /// </summary>
2391                 //public class MyXmlTextWriter : XmlTextWriter
2392                 //{
2393                 //      private bool _ignoreAttr = false;
2394
2395                 //      public MyXmlTextWriter( TextWriter w  )
2396                 //              : base( w )
2397                 //      {
2398                 //              Debug.WriteLine( "create" );
2399                 //      }
2400
2401                 //      public override string LookupPrefix( string ns )
2402                 //      {
2403                 //              Debug.WriteLine( "luprefix" );
2404                 //              return string.Empty;
2405                 //      }
2406
2407                 //      public override void WriteStartAttribute( string prefix, string localName, string ns )
2408                 //      {
2409                 //              Debug.WriteLine( "writestartattribute" );
2410                 //              if ( String.Compare( prefix, "xmlns", true ) == 0 )
2411                 //              {
2412                 //                      Debug.WriteLine( "[!]" );
2413                 //                      this._ignoreAttr = true;
2414                 //                      return;
2415                 //              }
2416                 //      }
2417
2418                 //      public override void WriteEndAttribute()
2419                 //      {
2420                 //              if ( this._ignoreAttr )
2421                 //              {
2422                 //                      this._ignoreAttr = false;
2423                 //                      return;
2424                 //              }
2425                 //              base.WriteEndAttribute();
2426                 //      }
2427
2428                 //      public override void WriteString( string text )
2429                 //      {
2430                 //              Debug.WriteLine( "ws" );
2431                 //              if ( String.Compare( text, "http://www.w3.org/2001/XMLSchema-instance", true ) == 0 )
2432                 //              {
2433                 //                      return;
2434                 //              }
2435                 //              base.WriteString( text );
2436                 //      }
2437
2438                 //      public override void WriteStartElement( string prefix, string localName, string ns )
2439                 //      {
2440                 //              Debug.WriteLine( "wse" );
2441                 //              base.WriteStartElement( null, localName, null );
2442                 //      }
2443                 //}
2444
2445                 public void ShowWindowTitleWithSoundType()
2446                 {
2447                         string delay = "";
2448                         if (Sound管理.CurrentSoundDeviceType != ESoundDeviceType.DirectSound)
2449                         {
2450                                 delay = "(" + Sound管理.GetSoundDelay() + "ms)";
2451                         }
2452                         base.Window.Text = strWindowTitle;
2453                         if (!this.DTX2WAVmode.Enabled)
2454                         {
2455                                 base.Window.Text += " (" + Sound管理.GetCurrentSoundDeviceType() + delay + ")";
2456                         }
2457                 }
2458
2459                 #region [ private ]
2460                 //-----------------
2461                 private bool b終了処理完了済み;
2462                 private static CDTX dtx;
2463                 private List<CActivity> listトップレベルActivities;
2464                 private int n進行描画の戻り値;
2465                 private MouseButtons mb = System.Windows.Forms.MouseButtons.Left;
2466                 private string strWindowTitle
2467                 {
2468                         get
2469                         {
2470                                 string strCPUmode = (Environment.Is64BitProcess) ? " [x64]" : " [x86]";
2471
2472                                         if (DTXVmode.Enabled)
2473                                 {
2474                                         return "DTXMViewer release " + VERSION + strCPUmode;
2475                                 }
2476                                 else if (DTX2WAVmode.Enabled)
2477                                 {
2478                                         return "DTX2WAV (" + VERSION + "): " + Path.GetFileName(this.DTX2WAVmode.dtxfilename) + strCPUmode;
2479                                 }
2480                                 else
2481                                 {
2482                                         return "DTXMania .NET style release " + VERSION + strCPUmode;
2483                                 }
2484                         }
2485                 }
2486                 private CSound previewSound;
2487                 private CMouseHideControl cMouseHideControl = null;
2488
2489                 private void t終了処理()
2490                 {
2491                         if (!this.b終了処理完了済み)
2492                         {
2493                                 Trace.TraceInformation("----------------------");
2494                                 Trace.TraceInformation("■ アプリケーションの終了");
2495                                 #region[ 電源プランの復元 ]
2496                                 CPowerPlan.RestoreCurrentPowerPlan();           // 電源プランを元のものに戻す
2497                                 #endregion
2498                                 #region [ 曲検索の終了処理 ]
2499                                 //---------------------
2500                                 if (actEnumSongs != null)
2501                                 {
2502                                         Trace.TraceInformation("曲検索actの終了処理を行います。");
2503                                         Trace.Indent();
2504                                         try
2505                                         {
2506                                                 actEnumSongs.On非活性化();
2507                                                 actEnumSongs = null;
2508                                                 Trace.TraceInformation("曲検索actの終了処理を完了しました。");
2509                                         }
2510                                         catch (Exception e)
2511                                         {
2512                                                 Trace.TraceError(e.Message);
2513                                                 Trace.TraceError("曲検索actの終了処理に失敗しました。");
2514                                         }
2515                                         finally
2516                                         {
2517                                                 Trace.Unindent();
2518                                         }
2519                                 }
2520                                 //---------------------
2521                                 #endregion
2522                                 #region [ 現在のステージの終了処理 ]
2523                                 //---------------------
2524                                 if (CDTXMania.Instance.r現在のステージ != null && CDTXMania.Instance.r現在のステージ.b活性化してる)     // #25398 2011.06.07 MODIFY FROM
2525                                 {
2526                                         Trace.TraceInformation("現在のステージを終了します。");
2527                                         Trace.Indent();
2528                                         try
2529                                         {
2530                                                 r現在のステージ.On非活性化();
2531                                                 Trace.TraceInformation("現在のステージの終了処理を完了しました。");
2532                                         }
2533                                         finally
2534                                         {
2535                                                 Trace.Unindent();
2536                                         }
2537                                 }
2538                                 //---------------------
2539                                 #endregion
2540
2541                                 #region [ 選曲ステージの終了処理 ]
2542                                 stage選曲.On非活性化();
2543                                 #endregion
2544
2545                                 #region [ プラグインの終了処理 ]
2546                                 //---------------------
2547                                 if (this.listプラグイン != null && this.listプラグイン.Count > 0)
2548                                 {
2549                                         Trace.TraceInformation("すべてのプラグインを終了します。");
2550                                         Trace.Indent();
2551                                         try
2552                                         {
2553                                                 foreach (STPlugin st in this.listプラグイン)
2554                                                 {
2555                                                         Directory.SetCurrentDirectory(st.strプラグインフォルダ);
2556                                                         st.plugin.OnUnmanagedリソースの解放();
2557                                                         st.plugin.OnManagedリソースの解放();
2558                                                         st.plugin.On終了();
2559                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
2560                                                 }
2561                                                 PluginHost = null;
2562                                                 Trace.TraceInformation("すべてのプラグインの終了処理を完了しました。");
2563                                         }
2564                                         finally
2565                                         {
2566                                                 Trace.Unindent();
2567                                         }
2568                                 }
2569                                 //---------------------
2570                                 #endregion
2571                                 #region [ 曲リストの終了処理 ]
2572                                 //---------------------
2573                                 if (Songs管理 != null)
2574                                 {
2575                                         Trace.TraceInformation("曲リストの終了処理を行います。");
2576                                         Trace.Indent();
2577                                         try
2578                                         {
2579                                                 Songs管理 = null;
2580                                                 Trace.TraceInformation("曲リストの終了処理を完了しました。");
2581                                         }
2582                                         catch (Exception exception)
2583                                         {
2584                                                 Trace.TraceError(exception.Message);
2585                                                 Trace.TraceError("曲リストの終了処理に失敗しました。");
2586                                         }
2587                                         finally
2588                                         {
2589                                                 Trace.Unindent();
2590                                         }
2591                                 }
2592                                 CAvi.t終了();
2593                                 //---------------------
2594                                 #endregion
2595                                 #region [ スキンの終了処理 ]
2596                                 //---------------------
2597                                 if (Skin != null)
2598                                 {
2599                                         Trace.TraceInformation("スキンの終了処理を行います。");
2600                                         Trace.Indent();
2601                                         try
2602                                         {
2603                                                 Skin.Dispose();
2604                                                 Skin = null;
2605                                                 Trace.TraceInformation("スキンの終了処理を完了しました。");
2606                                         }
2607                                         catch (Exception exception2)
2608                                         {
2609                                                 Trace.TraceError(exception2.Message);
2610                                                 Trace.TraceError("スキンの終了処理に失敗しました。");
2611                                         }
2612                                         finally
2613                                         {
2614                                                 Trace.Unindent();
2615                                         }
2616                                 }
2617                                 //---------------------
2618                                 #endregion
2619                                 #region [ DirectSoundの終了処理 ]
2620                                 //---------------------
2621                                 if (Sound管理 != null)
2622                                 {
2623                                         Trace.TraceInformation("DirectSound の終了処理を行います。");
2624                                         Trace.Indent();
2625                                         try
2626                                         {
2627                                                 Sound管理.Dispose();
2628                                                 Sound管理 = null;
2629                                                 Trace.TraceInformation("DirectSound の終了処理を完了しました。");
2630                                         }
2631                                         catch (Exception exception3)
2632                                         {
2633                                                 Trace.TraceError(exception3.Message);
2634                                                 Trace.TraceError("DirectSound の終了処理に失敗しました。");
2635                                         }
2636                                         finally
2637                                         {
2638                                                 Trace.Unindent();
2639                                         }
2640                                 }
2641                                 //---------------------
2642                                 #endregion
2643                                 #region [ パッドの終了処理 ]
2644                                 //---------------------
2645                                 if (Pad != null)
2646                                 {
2647                                         Trace.TraceInformation("パッドの終了処理を行います。");
2648                                         Trace.Indent();
2649                                         try
2650                                         {
2651                                                 Pad = null;
2652                                                 Trace.TraceInformation("パッドの終了処理を完了しました。");
2653                                         }
2654                                         catch (Exception exception4)
2655                                         {
2656                                                 Trace.TraceError(exception4.Message);
2657                                                 Trace.TraceError("パッドの終了処理に失敗しました。");
2658                                         }
2659                                         finally
2660                                         {
2661                                                 Trace.Unindent();
2662                                         }
2663                                 }
2664                                 //---------------------
2665                                 #endregion
2666                                 #region [ DirectInput, MIDI入力の終了処理 ]
2667                                 //---------------------
2668                                 if (Input管理 != null)
2669                                 {
2670                                         Trace.TraceInformation("DirectInput, MIDI入力の終了処理を行います。");
2671                                         Trace.Indent();
2672                                         try
2673                                         {
2674                                                 Input管理.Dispose();
2675                                                 Input管理 = null;
2676                                                 Trace.TraceInformation("DirectInput, MIDI入力の終了処理を完了しました。");
2677                                         }
2678                                         catch (Exception exception5)
2679                                         {
2680                                                 Trace.TraceError(exception5.Message);
2681                                                 Trace.TraceError("DirectInput, MIDI入力の終了処理に失敗しました。");
2682                                         }
2683                                         finally
2684                                         {
2685                                                 Trace.Unindent();
2686                                         }
2687                                 }
2688                                 //---------------------
2689                                 #endregion
2690                                 #region [ 文字コンソールの終了処理 ]
2691                                 //---------------------
2692                                 if (act文字コンソール != null)
2693                                 {
2694                                         Trace.TraceInformation("文字コンソールの終了処理を行います。");
2695                                         Trace.Indent();
2696                                         try
2697                                         {
2698                                                 act文字コンソール.On非活性化();
2699                                                 act文字コンソール = null;
2700                                                 Trace.TraceInformation("文字コンソールの終了処理を完了しました。");
2701                                         }
2702                                         catch (Exception exception6)
2703                                         {
2704                                                 Trace.TraceError(exception6.Message);
2705                                                 Trace.TraceError("文字コンソールの終了処理に失敗しました。");
2706                                         }
2707                                         finally
2708                                         {
2709                                                 Trace.Unindent();
2710                                         }
2711                                 }
2712                                 //---------------------
2713                                 #endregion
2714                                 #region [ FPSカウンタの終了処理 ]
2715                                 //---------------------
2716                                 Trace.TraceInformation("FPSカウンタの終了処理を行います。");
2717                                 Trace.Indent();
2718                                 try
2719                                 {
2720                                         if (FPS != null)
2721                                         {
2722                                                 FPS = null;
2723                                         }
2724                                         Trace.TraceInformation("FPSカウンタの終了処理を完了しました。");
2725                                 }
2726                                 finally
2727                                 {
2728                                         Trace.Unindent();
2729                                 }
2730                                 //---------------------
2731                                 #endregion
2732                                 #region [ タイマの終了処理 ]
2733                                 //---------------------
2734                                 Trace.TraceInformation("タイマの終了処理を行います。");
2735                                 Trace.Indent();
2736                                 try
2737                                 {
2738                                         if (Timer != null)
2739                                         {
2740                                                 Timer.Dispose();
2741                                                 Timer = null;
2742                                                 Trace.TraceInformation("タイマの終了処理を完了しました。");
2743                                         }
2744                                         else
2745                                         {
2746                                                 Trace.TraceInformation("タイマは使用されていません。");
2747                                         }
2748                                 }
2749                                 finally
2750                                 {
2751                                         Trace.Unindent();
2752                                 }
2753                                 //---------------------
2754                                 #endregion
2755                                 #region [ Config.iniの出力 ]
2756                                 //---------------------
2757                                 Trace.TraceInformation("Config.xml を出力します。");
2758                                 //                              if ( ConfigIni.bIsSwappedGuitarBass )                   // #24063 2011.1.16 yyagi ギターベースがスワップしているときは元に戻す
2759                                 if (ConfigIni.bIsSwappedGuitarBass_AutoFlagsAreSwapped) // #24415 2011.2.21 yyagi FLIP中かつ演奏中にalt-f4で終了したときは、AUTOのフラグをswapして戻す
2760                                 {
2761                                         ConfigIni.SwapGuitarBassInfos_AutoFlags();
2762                                 }
2763                                 /*
2764                                         if (ConfigIni.bIsSwappedGuitarBass_PlaySettingsAreSwapped)  // #35417 2015/8/18 yyagi FLIP中かつ演奏中にalt-f4で終了したときは、演奏設定のフラグをswapして戻す
2765                                         {
2766                                                         ConfigIni.SwapGuitarBassInfos_PlaySettings();
2767                                         }
2768                                  */
2769                                 string str = strEXEのあるフォルダ + "Config.xml";
2770                                 Trace.Indent();
2771                                 try
2772                                 {
2773                                         if (DTXVmode.Enabled)
2774                                         {
2775                                                 DTXVmode.tUpdateConfigIni();
2776                                                 Trace.TraceInformation("DTXVモードの設定情報を、Config.xmlに保存しました。");
2777                                         }
2778                                         else if (DTX2WAVmode.Enabled)
2779                                         {
2780                                                 DTX2WAVmode.tUpdateConfigIni();
2781                                                 Trace.TraceInformation("DTX2WAVモードの設定情報を、Config.xmlに保存しました。");
2782                                                 DTX2WAVmode.SendMessage2DTX2WAV("TERM");
2783                                         }
2784                                         else
2785                                         {
2786                                                 CDTXMania.Instance.SaveConfig();
2787                                                 Trace.TraceInformation("保存しました。({0})", str);
2788                                         }
2789                                 }
2790                                 catch (Exception e)
2791                                 {
2792                                         Trace.TraceError(e.Message);
2793                                         Trace.TraceError("Config.xml の出力に失敗しました。({0})", str);
2794                                 }
2795                                 finally
2796                                 {
2797                                         Trace.Unindent();
2798                                 }
2799                                 //---------------------
2800                                 #endregion
2801                                 #region [ DTXVmodeの終了処理 ]
2802                                 //---------------------
2803                                 //Trace.TraceInformation( "DTXVモードの終了処理を行います。" );
2804                                 //Trace.Indent();
2805                                 try
2806                                 {
2807                                         if (DTXVmode != null)
2808                                         {
2809                                                 DTXVmode = null;
2810                                                 //Trace.TraceInformation( "DTXVモードの終了処理を完了しました。" );
2811                                         }
2812                                         else
2813                                         {
2814                                                 //Trace.TraceInformation( "DTXVモードは使用されていません。" );
2815                                         }
2816                                 }
2817                                 finally
2818                                 {
2819                                         //Trace.Unindent();
2820                                 }
2821                                 //---------------------
2822                                 #endregion
2823                                 #region [ DirectXの終了処理 ]
2824                                 //---------------------
2825                                 base.GraphicsDeviceManager.Dispose();
2826                                 //---------------------
2827                                 #endregion
2828                                 Trace.TraceInformation( "アプリケーションの終了処理を完了しました。" );
2829
2830
2831                                 this.b終了処理完了済み = true;
2832                         }
2833                 }
2834                 private CScoreIni tScoreIniへBGMAdjustとHistoryとPlayCountを更新(string str新ヒストリ行)
2835                 {
2836                         STDGBSValue<bool> isUpdated = new STDGBSValue<bool>();
2837                         string strFilename = DTX.strファイル名の絶対パス + ".score.ini";
2838                         CScoreIni ini = new CScoreIni(strFilename);
2839                         if (!File.Exists(strFilename))
2840                         {
2841                                 ini.stファイル.Title = DTX.TITLE;
2842                                 ini.stファイル.Name = DTX.strファイル名;
2843                                 ini.stファイル.Hash = CScoreIni.tファイルのMD5を求めて返す(DTX.strファイル名の絶対パス);
2844                                 for (EPart i = EPart.Drums; i <= EPart.Bass; ++i)
2845                                 {
2846                                         ini.stセクション.HiScore[i].nPerfectになる範囲ms = nPerfect範囲ms;
2847                                         ini.stセクション.HiScore[i].nGreatになる範囲ms = nGreat範囲ms;
2848                                         ini.stセクション.HiScore[i].nGoodになる範囲ms = nGood範囲ms;
2849                                         ini.stセクション.HiScore[i].nPoorになる範囲ms = nPoor範囲ms;
2850
2851                                         ini.stセクション.HiSkill[i].nPerfectになる範囲ms = nPerfect範囲ms;
2852                                         ini.stセクション.HiSkill[i].nGreatになる範囲ms = nGreat範囲ms;
2853                                         ini.stセクション.HiSkill[i].nGoodになる範囲ms = nGood範囲ms;
2854                                         ini.stセクション.HiSkill[i].nPoorになる範囲ms = nPoor範囲ms;
2855
2856                                         ini.stセクション.LastPlay[i].nPerfectになる範囲ms = nPerfect範囲ms;
2857                                         ini.stセクション.LastPlay[i].nGreatになる範囲ms = nGreat範囲ms;
2858                                         ini.stセクション.LastPlay[i].nGoodになる範囲ms = nGood範囲ms;
2859                                         ini.stセクション.LastPlay[i].nPoorになる範囲ms = nPoor範囲ms;
2860                                 }
2861                         }
2862                         ini.stファイル.BGMAdjust = DTX.nBGMAdjust;
2863                         isUpdated = CScoreIni.t更新条件を取得する();
2864                         if (isUpdated.Drums || isUpdated.Guitar || isUpdated.Bass)
2865                         {
2866                                 if (isUpdated.Drums)
2867                                 {
2868                                         ini.stファイル.PlayCountDrums++;
2869                                 }
2870                                 if (isUpdated.Guitar)
2871                                 {
2872                                         ini.stファイル.PlayCountGuitar++;
2873                                 }
2874                                 if (isUpdated.Bass)
2875                                 {
2876                                         ini.stファイル.PlayCountBass++;
2877                                 }
2878                                 ini.tヒストリを追加する(str新ヒストリ行);
2879                                 if (!bコンパクトモード)
2880                                 {
2881                                         stage選曲.r現在選択中のスコア.譜面情報.演奏回数.Drums = ini.stファイル.PlayCountDrums;
2882                                         stage選曲.r現在選択中のスコア.譜面情報.演奏回数.Guitar = ini.stファイル.PlayCountGuitar;
2883                                         stage選曲.r現在選択中のスコア.譜面情報.演奏回数.Bass = ini.stファイル.PlayCountBass;
2884                                         for (int j = 0; j < ini.stファイル.History.Length; j++)
2885                                         {
2886                                                 stage選曲.r現在選択中のスコア.譜面情報.演奏履歴[j] = ini.stファイル.History[j];
2887                                         }
2888                                 }
2889                         }
2890                         if (ConfigIni.bScoreIni)
2891                         {
2892                                 ini.t書き出し(strFilename);
2893                         }
2894
2895                         return ini;
2896                 }
2897                 private void tガベージコレクションを実行する()
2898                 {
2899                         // LOHに対するコンパクションを要求
2900                         GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
2901
2902                         GC.Collect(0, GCCollectionMode.Optimized, true );
2903                         GC.WaitForPendingFinalizers();
2904                         GC.Collect(0, GCCollectionMode.Forced, true );
2905                         GC.WaitForPendingFinalizers();
2906
2907                         // 通常通り、LOHへのGCを抑制
2908                         GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.Default;
2909                 }
2910                 private void tプラグイン検索と生成()
2911                 {
2912                         this.listプラグイン = new List<STPlugin>();
2913
2914                         string strIPluginActivityの名前 = typeof(IPluginActivity).FullName;
2915                         string strプラグインフォルダパス = strEXEのあるフォルダ + "Plugins\\";
2916
2917                         this.t指定フォルダ内でのプラグイン検索と生成(strプラグインフォルダパス, strIPluginActivityの名前);
2918
2919                         if (this.listプラグイン.Count > 0)
2920                                 Trace.TraceInformation(this.listプラグイン.Count + " 個のプラグインを読み込みました。");
2921                 }
2922
2923                 private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
2924                 {
2925                         var domain = (AppDomain)sender;
2926
2927                         foreach (var assembly in domain.GetAssemblies())
2928                         {
2929                                 if (assembly.FullName == args.Name)
2930                                         return assembly;
2931                         }
2932                         return null;
2933                 }
2934                 private void t指定フォルダ内でのプラグイン検索と生成(string strプラグインフォルダパス, string strプラグイン型名)
2935                 {
2936                         // 指定されたパスが存在しないとエラー
2937                         if (!Directory.Exists(strプラグインフォルダパス))
2938                         {
2939                                 Trace.TraceWarning("プラグインフォルダが存在しません。(" + strプラグインフォルダパス + ")");
2940                                 return;
2941                         }
2942
2943                         AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
2944
2945
2946                         // (1) すべての *.dll について…
2947                         string[] strDLLs = System.IO.Directory.GetFiles(strプラグインフォルダパス, "*.dll");
2948                         foreach (string dllName in strDLLs)
2949                         {
2950                                 if (Path.GetExtension(dllName).ToLower() != ".dll")
2951                                 {
2952                                         continue;
2953                                 }
2954                                 try
2955                                 {
2956                                         // (1-1) dll をアセンブリとして読み込む。
2957                                         System.Reflection.Assembly asm = System.Reflection.Assembly.LoadFrom(dllName);
2958
2959                                         // (1-2) アセンブリ内のすべての型について、プラグインとして有効か調べる
2960                                         foreach (Type t in asm.GetTypes())
2961                                         {
2962                                                 //  (1-3) ↓クラスであり↓Publicであり↓抽象クラスでなく↓IPlugin型のインスタンスが作れる 型を持っていれば有効
2963                                                 if (t.IsClass && t.IsPublic && !t.IsAbstract && t.GetInterface(strプラグイン型名) != null)
2964                                                 {
2965                                                         // (1-4) クラス名からインスタンスを作成する
2966                                                         var st = new STPlugin()
2967                                                         {
2968                                                                 plugin = (IPluginActivity)asm.CreateInstance(t.FullName),
2969                                                                 strプラグインフォルダ = Path.GetDirectoryName(dllName),
2970                                                                 strアセンブリ簡易名 = asm.GetName().Name,
2971                                                                 Version = asm.GetName().Version,
2972                                                         };
2973
2974                                                         // (1-5) プラグインリストへ登録
2975                                                         this.listプラグイン.Add(st);
2976                                                         Trace.TraceInformation("プラグイン {0} ({1}, {2}, {3}) を読み込みました。", t.FullName, Path.GetFileName(dllName), st.strアセンブリ簡易名, st.Version.ToString());
2977                                                 }
2978                                         }
2979                                 }
2980                                 catch (System.Reflection.ReflectionTypeLoadException e)
2981                                 {
2982                                         Trace.TraceInformation(dllName + " からプラグインを生成することに失敗しました。スキップします。");
2983                                         Trace.TraceInformation(e.ToString());
2984                                         Trace.TraceInformation(e.Message);
2985                                         {
2986                                                 StringBuilder sb = new StringBuilder();
2987                                                 foreach (Exception exSub in e.LoaderExceptions)
2988                                                 {
2989                                                         sb.AppendLine(exSub.Message);
2990                                                         FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
2991                                                         if (exFileNotFound != null)
2992                                                         {
2993                                                                 if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
2994                                                                 {
2995                                                                         sb.AppendLine("Fusion Log:");
2996                                                                         sb.AppendLine(exFileNotFound.FusionLog);
2997                                                                 }
2998                                                         }
2999                                                         sb.AppendLine();
3000                                                 }
3001                                                 string errorMessage = sb.ToString();
3002                                                 //Display or log the error based on your application.
3003                                                 Trace.TraceInformation(errorMessage);
3004                                         }
3005                                 }
3006                                 catch (Exception e)
3007                                 {
3008                                         Trace.TraceInformation(dllName + " からプラグインを生成することに失敗しました。スキップします。");
3009                                         Trace.TraceInformation(e.ToString());
3010                                         Trace.TraceInformation(e.Message);
3011                                 }
3012                         }
3013
3014                         // (2) サブフォルダがあれば再帰する
3015                         string[] strDirs = Directory.GetDirectories(strプラグインフォルダパス, "*");
3016                         foreach (string dir in strDirs)
3017                                 this.t指定フォルダ内でのプラグイン検索と生成(dir + "\\", strプラグイン型名);
3018                 }
3019                 //-----------------
3020                 #region [ Windowイベント処理 ]
3021                 private void Window_ApplicationActivated( object sender, EventArgs e )
3022                 {
3023                         this.bApplicationActive = true;
3024                 }
3025                 private void Window_ApplicationDeactivated(object sender, EventArgs e)
3026                 {
3027                         this.bApplicationActive = false;
3028                         if (cMouseHideControl != null) cMouseHideControl.Show();
3029                 }
3030                 private void Window_KeyDown(object sender, KeyEventArgs e)
3031                 {
3032                         if (e.KeyCode == Keys.Menu)
3033                         {
3034                                 e.Handled = true;
3035                                 e.SuppressKeyPress = true;
3036                         }
3037                         else if ((e.KeyCode == Keys.Return) && e.Alt)
3038                         {
3039                                 if (ConfigIni != null)
3040                                 {
3041                                         ConfigIni.bウィンドウモード = !ConfigIni.bウィンドウモード;
3042                                         this.t全画面_ウィンドウモード切り替え();
3043                                 }
3044                                 e.Handled = true;
3045                                 e.SuppressKeyPress = true;
3046                         }
3047                         else
3048                         {
3049                                 for (int i = 0; i < CConfigXml.AssignableCodes; i++)
3050                                 {
3051                                         var captureCode = (SlimDX.DirectInput.Key) ConfigIni.KeyAssign[ EPad.Capture ][ i ].コード;
3052
3053                                         if( (int) captureCode > 0 &&
3054                                                 e.KeyCode == DeviceConstantConverter.KeyToKeys( captureCode ) )
3055                                         {
3056                                                 // Debug.WriteLine( "capture: " + string.Format( "{0:2x}", (int) e.KeyCode ) + " " + (int) e.KeyCode );
3057                                                 string strFullPath =
3058                                                                  Path.Combine( CDTXMania.Instance.strEXEのあるフォルダ, "Capture_img" );
3059                                                 strFullPath = Path.Combine( strFullPath, DateTime.Now.ToString( "yyyyMMddHHmmss" ) + ".png" );
3060                                                 SaveResultScreen( strFullPath );
3061                                         }
3062                                 }
3063                         }
3064                 }
3065                 private void Window_MouseUp(object sender, MouseEventArgs e)
3066                 {
3067                         mb = e.Button;
3068                 }
3069                 private void Window_MouseDown(object sender, MouseEventArgs e)
3070                 {
3071                         currentMousePosition.X = Control.MousePosition.X;
3072                         currentMousePosition.Y = Control.MousePosition.Y;
3073                 }
3074
3075                 private void Window_MouseDoubleClick(object sender, MouseEventArgs e)   // #23510 2010.11.13 yyagi: to go full screen mode
3076                 {
3077                         if (mb.Equals(MouseButtons.Left) && ConfigIni.bIsAllowedDoubleClickFullscreen)  // #26752 2011.11.27 yyagi
3078                         {
3079                                 ConfigIni.bウィンドウモード = !ConfigIni.bウィンドウモード;
3080                                 this.t全画面_ウィンドウモード切り替え();
3081                         }
3082                 }
3083                 private Point currentMousePosition = new Point(-1,-1);
3084                 private void Window_MouseMove(object sender, MouseEventArgs e)
3085                 {
3086                         if (cMouseHideControl != null) cMouseHideControl.tResetCursorState(ConfigIni.bウィンドウモード, this.bApplicationActive);
3087                         if (Control.MouseButtons.HasFlag(MouseButtons.Left))
3088                         {
3089                                 int X = base.Window.Location.X;
3090                                 X += (Control.MousePosition.X - currentMousePosition.X);
3091                                 int Y = base.Window.Location.Y;
3092                                 Y += (Control.MousePosition.Y - currentMousePosition.Y);
3093
3094                                 base.Window.Location = new Point(X, Y);
3095
3096                                 currentMousePosition.X = Control.MousePosition.X;
3097                                 currentMousePosition.Y = Control.MousePosition.Y;
3098                         }
3099                 }
3100                 private void Window_ResizeEnd(object sender, EventArgs e)               // #23510 2010.11.20 yyagi: to get resized window size
3101                 {
3102                         if (ConfigIni.bウィンドウモード)
3103                         {
3104                                 ConfigIni.rcWindow.X = base.Window.Location.X; // #30675 2013.02.04 ikanick add
3105                                 ConfigIni.rcWindow.Y = base.Window.Location.Y; //
3106                         }
3107
3108                         ConfigIni.rcWindow.W = (ConfigIni.bウィンドウモード) ? base.Window.ClientSize.Width : currentClientSize.Width;   // #23510 2010.10.31 yyagi add
3109                         ConfigIni.rcWindow.H = (ConfigIni.bウィンドウモード) ? base.Window.ClientSize.Height : currentClientSize.Height;
3110                 }
3111                 #endregion
3112
3113                 //Stopwatch sw = new Stopwatch();
3114                 //List<int> swlist1, swlist2, swlist3, swlist4, swlist5;
3115
3116                 #endregion
3117
3118                 private class CMouseHideControl
3119                 {
3120                         private Point lastPosition;
3121                         private CCounter ccMouseShow;
3122                         private bool bマウスカーソル表示中;
3123
3124                         /// <summary>
3125                         /// コンストラクタ
3126                         /// </summary>
3127                         public CMouseHideControl()
3128                         {
3129                                 ccMouseShow = new CCounter();
3130                                 lastPosition = Cursor.Position;
3131                                 bマウスカーソル表示中 = true;
3132                                 t開始();
3133                         }
3134
3135                         public void t開始()
3136                         {
3137                                 ccMouseShow.t開始(0, 20, 100, CDTXMania.instance.Timer);
3138                         }
3139
3140                         public void tHideCursorIfNeed()
3141                         {
3142                                 ccMouseShow.t進行();
3143 //Trace.TraceInformation("n現在の経過時間ms" + ccMouseShow.n現在の経過時間ms + ", n現在の値=" + ccMouseShow.n現在の値 + ", b終了値に達した=" + ccMouseShow.b終了値に達した);
3144                                 if (bマウスカーソル表示中 && ccMouseShow.b終了値に達した)
3145                                 {
3146                                         Point client_point = CDTXMania.Instance.Window.PointToClient(Cursor.Position);
3147                                         if (client_point.Y >= 0)        // タイトルバー上にマウスカーソルがある場合は、隠さない
3148                                         {
3149                                                 Hide();
3150                                         }
3151                                 }
3152
3153                         }
3154
3155                         public void tResetCursorState(bool bWindowed, bool bApplicationActive)
3156                         {
3157 //Trace.TraceInformation("マウス移動: " + Cursor.Position.X + "," + Cursor.Position.Y);
3158                                 if ((bWindowed == true && bマウスカーソル表示中 == false) || bApplicationActive == false)   // #36168 2016.3.19 yyagi: do not to show mouse cursor in full screen mode
3159                                 {
3160                                         Point currentPosition = Cursor.Position;
3161 //Trace.TraceInformation("current=" + currentPosition.ToString() + ", last=" + lastPosition.ToString());
3162                                         if (lastPosition != currentPosition)
3163                                         {
3164 //Trace.TraceInformation("移動発生");
3165                                                 lastPosition = currentPosition;
3166                                                 Show();
3167                                                 t開始();
3168                                         }
3169                                 }
3170                         }
3171
3172                         public void Show()
3173                         {
3174                                 Cursor.Show();
3175                                 bマウスカーソル表示中 = true;
3176                         }
3177                         public void Hide()
3178                         {
3179                                 Cursor.Hide();
3180                                 bマウスカーソル表示中 = false;
3181                         }
3182                 }
3183         }
3184 }