OSDN Git Service

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