OSDN Git Service

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