OSDN Git Service

#36612 DTXManiaでのViwerを実行にて、二回目以降の実行でウィンドウサイズが保持されない問題の修正。
[dtxmania/dtxmania.git] / DTXManiaプロジェクト / コード / ステージ / CDTXVmode.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using System.Diagnostics;\r
5 using System.IO;\r
6 using System.Threading;\r
7 using FDK;\r
8 \r
9 \r
10 namespace DTXMania\r
11 {\r
12         public class CDTXVmode\r
13         {\r
14                 public enum ECommand\r
15                 {\r
16                         Stop,\r
17                         Play,\r
18                         Preview\r
19                 }\r
20 \r
21                 /// <summary>\r
22                 /// DTXVモードかどうか\r
23                 /// </summary>\r
24                 public bool Enabled\r
25                 {\r
26                         get;\r
27                         set;\r
28                 }\r
29 \r
30                 /// <summary>\r
31                 /// プレビューサウンドの再生が発生した\r
32                 /// </summary>\r
33                 public bool Preview\r
34                 {\r
35                         get;\r
36                         set;\r
37                 }\r
38 \r
39                 /// <summary>\r
40                 /// 外部から再指示が発生したか\r
41                 /// </summary>\r
42                 public bool Refreshed\r
43                 {\r
44                         get;\r
45                         set;\r
46                 }\r
47 \r
48                 /// <summary>\r
49                 /// 演奏開始小節番号\r
50                 /// </summary>\r
51                 public int nStartBar\r
52                 {\r
53                         get;\r
54                         set;\r
55                 }\r
56 \r
57                 /// <summary>\r
58                 /// DTXファイルの再読み込みが必要かどうか\r
59                 /// </summary>\r
60                 public bool NeedReload\r
61                 {\r
62                         get;\r
63                         private set;\r
64                         //                      private set;    // 本来はprivate setにすべきだが、デバッグが簡単になるので、しばらくはprivateなしのままにする。\r
65                 }\r
66 \r
67                 /// <summary>\r
68                 /// DTXCからのコマンド\r
69                 /// </summary>\r
70                 public ECommand Command\r
71                 {\r
72                         get;\r
73                         private set;\r
74                 }\r
75 \r
76                 public ESoundDeviceType soundDeviceType\r
77                 {\r
78                         get;\r
79                         private set;\r
80                 }\r
81                 public int nASIOdevice\r
82                 {\r
83                         get;\r
84                         private set;\r
85                 }\r
86                 /// <summary>\r
87                 /// 前回からサウンドデバイスが変更されたか\r
88                 /// </summary>\r
89                 public bool ChangedSoundDevice\r
90                 {\r
91                         get;\r
92                         private set;\r
93                 }\r
94 \r
95                 public string filename\r
96                 {\r
97                         get\r
98                         {\r
99                                 return last_path;\r
100                         }\r
101                 }\r
102 \r
103                 public string previewFilename\r
104                 {\r
105                         get;\r
106                         private set;\r
107                 }\r
108                 public int previewVolume\r
109                 {\r
110                         get;\r
111                         private set;\r
112                 }\r
113                 public int previewPan\r
114                 {\r
115                         get;\r
116                         private set;\r
117                 }\r
118                 public bool GRmode\r
119                 {\r
120                         get;\r
121                         private set;\r
122                 }\r
123                 public bool lastGRmode\r
124                 {\r
125                         get;\r
126                         private set;\r
127                 }\r
128                 public bool TimeStretch\r
129                 {\r
130                         get;\r
131                         private set;\r
132                 }\r
133                 public bool lastTimeStretch\r
134                 {\r
135                         get;\r
136                         private set;\r
137                 }\r
138                 public bool VSyncWait\r
139                 {\r
140                         get;\r
141                         private set;\r
142                 }\r
143                 public bool lastVSyncWait\r
144                 {\r
145                         get;\r
146                         private set;\r
147                 }\r
148 \r
149 \r
150                 /// <summary>\r
151                 /// コンストラクタ\r
152                 /// </summary>\r
153                 public CDTXVmode()\r
154                 {\r
155                         this.last_path = "";\r
156                         this.last_timestamp = DateTime.MinValue;\r
157                         this.Enabled = false;\r
158                         this.nStartBar = 0;\r
159                         this.Refreshed = false;\r
160                         this.NeedReload = false;\r
161                         this.previewFilename = "";\r
162                         this.GRmode = false;\r
163                         this.lastGRmode = false;\r
164                         this.TimeStretch = false;\r
165                         this.lastTimeStretch = false;\r
166                         this.VSyncWait = true;\r
167                         this.lastVSyncWait = true;\r
168                 }\r
169 \r
170                 /// <summary>\r
171                 /// DTXファイルのリロードが必要かどうか判定する\r
172                 /// </summary>\r
173                 /// <param name="filename">DTXファイル名</param>\r
174                 /// <returns>再読込が必要ならtrue</returns>\r
175                 /// <remarks>プロパティNeedReloadにも結果が入る</remarks>\r
176                 /// <remarks>これを呼び出すたびに、Refreshedをtrueにする</remarks>\r
177                 /// <exception cref="FileNotFoundException"></exception>\r
178                 public bool bIsNeedReloadDTX(string filename)\r
179                 {\r
180                         if (!File.Exists(filename))     // 指定したファイルが存在しないなら例外終了\r
181                         {\r
182                                 Trace.TraceError("ファイルが見つかりません。({0})", filename);\r
183                                 throw new FileNotFoundException();\r
184                                 //return false;\r
185                         }\r
186 \r
187                         this.Refreshed = true;\r
188 \r
189                         // 前回とファイル名が異なるか、タイムスタンプが更新されているか、\r
190                         // GRmode等の設定を変更したなら、DTX要更新\r
191                         DateTime current_timestamp = File.GetLastWriteTime(filename);\r
192                         if (last_path != filename || current_timestamp > last_timestamp ||\r
193                                 this.lastGRmode != this.GRmode || this.lastTimeStretch != this.TimeStretch || this.lastVSyncWait != this.VSyncWait)\r
194                         {\r
195                                 this.last_path = filename;\r
196                                 this.last_timestamp = current_timestamp;\r
197                                 this.lastGRmode = this.GRmode;\r
198                                 this.lastTimeStretch = this.TimeStretch;\r
199                                 this.lastVSyncWait = this.VSyncWait;\r
200 \r
201                                 this.NeedReload = true;\r
202                                 return true;\r
203                         }\r
204                         this.NeedReload = false;\r
205                         return false;\r
206                 }\r
207 \r
208                 /// <summary>\r
209                 /// \r
210                 /// </summary>\r
211                 /// <param name="arg"></param>\r
212                 /// <param name="nStartBar"></param>\r
213                 /// <param name="command"></param>\r
214                 /// <returns>DTXV用の引数であればtrue</returns>\r
215                 /// <remarks>内部でEnabled, nStartBar, Command, NeedReload, filename, last_path, last_timestampを設定する</remarks>\r
216                 public bool ParseArguments(string arg)\r
217                 {\r
218                         bool ret = false, analyzing = true;\r
219                         this.nStartBar = 0;\r
220 \r
221                         if (arg != null)\r
222                         {\r
223                                 while (analyzing)\r
224                                 {\r
225                                         if (arg == "")\r
226                                         {\r
227                                                 analyzing = false;\r
228                                         }\r
229                                         else if (arg.StartsWith("-V", StringComparison.OrdinalIgnoreCase))    // サウンド再生\r
230                                         {\r
231                                                 // -Vvvv,ppp,"filename"の形式。 vvv=volume, ppp=pan.\r
232                                                 this.Enabled = true;\r
233                                                 this.Command = ECommand.Preview;\r
234                                                 this.Refreshed = true;\r
235                                                 ret = true;\r
236                                                 arg = arg.Substring(2);\r
237 \r
238                                                 int pVol = arg.IndexOf(',');                  //Trace.TraceInformation( "pVol=" + pVol );\r
239                                                 string strVol = arg.Substring(0, pVol);           //Trace.TraceInformation( "strVol=" + strVol );\r
240                                                 this.previewVolume = Convert.ToInt32(strVol);         //Trace.TraceInformation( "previewVolume=" + previewVolume );\r
241                                                 int pPan = arg.IndexOf(',', pVol + 1);            //Trace.TraceInformation( "pPan=" + pPan );\r
242                                                 string strPan = arg.Substring(pVol + 1, pPan - pVol - 1);   //Trace.TraceInformation( "strPan=" + strPan );\r
243                                                 this.previewPan = Convert.ToInt32(strPan);          //Trace.TraceInformation( "previewPan=" + previewPan );\r
244 \r
245                                                 arg = arg.Substring(pPan + 1);\r
246                                                 arg = arg.Trim(new char[] { '\"' });\r
247                                                 this.previewFilename = arg;\r
248                                                 analyzing = false;\r
249                                         }\r
250                                         // -S  -Nxxx  filename\r
251                                         else if (arg.StartsWith("-S", StringComparison.OrdinalIgnoreCase))    // DTXV再生停止\r
252                                         {\r
253                                                 this.Enabled = true;\r
254                                                 this.Command = ECommand.Stop;\r
255                                                 this.Refreshed = true;\r
256                                                 ret = true;\r
257                                                 arg = arg.Substring(2);\r
258                                         }\r
259                                         else if (arg.StartsWith("-D", StringComparison.OrdinalIgnoreCase))\r
260                                         {\r
261                                                 // -DW, -DA1など\r
262                                                 arg = arg.Substring(2); // -D を削除\r
263                                                 switch (arg[0])\r
264                                                 {\r
265                                                         #region [ DirectSound ]\r
266                                                         case 'D':\r
267                                                                 if (this.soundDeviceType != ESoundDeviceType.DirectSound)\r
268                                                                 {\r
269                                                                         this.ChangedSoundDevice = true;\r
270                                                                         this.soundDeviceType = ESoundDeviceType.DirectSound;\r
271                                                                 }\r
272                                                                 else\r
273                                                                 {\r
274                                                                         this.ChangedSoundDevice = false;\r
275                                                                 }\r
276                                                                 arg = arg.Substring(1);\r
277                                                                 break;\r
278                                                         #endregion\r
279                                                         #region [ WASAPI ]\r
280                                                         case 'W':\r
281                                                                 if (this.soundDeviceType != ESoundDeviceType.ExclusiveWASAPI)\r
282                                                                 {\r
283                                                                         this.ChangedSoundDevice = true;\r
284                                                                         this.soundDeviceType = ESoundDeviceType.ExclusiveWASAPI;\r
285                                                                 }\r
286                                                                 else\r
287                                                                 {\r
288                                                                         this.ChangedSoundDevice = false;\r
289                                                                 }\r
290                                                                 arg = arg.Substring(1);\r
291                                                                 break;\r
292                                                         #endregion\r
293                                                         #region [ ASIO ]\r
294                                                         case 'A':\r
295                                                                 if (this.soundDeviceType != ESoundDeviceType.ASIO)\r
296                                                                 {\r
297                                                                         this.ChangedSoundDevice = true;\r
298                                                                         this.soundDeviceType = ESoundDeviceType.ASIO;\r
299                                                                 }\r
300                                                                 else\r
301                                                                 {\r
302                                                                         this.ChangedSoundDevice = false;\r
303                                                                 }\r
304                                                                 arg = arg.Substring(1);\r
305 \r
306                                                                 int nAsioDev = 0, p = 0;\r
307                                                                 while (true)\r
308                                                                 {\r
309                                                                         char c = arg[0];\r
310                                                                         if ('0' <= c && c <= '9')\r
311                                                                         {\r
312                                                                                 nAsioDev *= 10;\r
313                                                                                 nAsioDev += c - '0';\r
314                                                                                 p++;\r
315                                                                                 arg = arg.Substring(1);\r
316                                                                                 continue;\r
317                                                                         }\r
318                                                                         else\r
319                                                                         {\r
320                                                                                 break;\r
321                                                                         }\r
322                                                                 }\r
323                                                                 if (this.nASIOdevice != nAsioDev)\r
324                                                                 {\r
325                                                                         this.ChangedSoundDevice = true;\r
326                                                                         this.nASIOdevice = nAsioDev;\r
327                                                                 }\r
328                                                                 break;\r
329                                                                 #endregion\r
330                                                 }\r
331                                                 #region [ GRmode, TimeStretch, VSyncWait ]\r
332                                                 {\r
333                                                         // Reload判定は、-Nのところで行う\r
334                                                         this.GRmode = (arg[0] == 'Y');\r
335                                                         this.TimeStretch = (arg[1] == 'Y');\r
336                                                         this.VSyncWait = (arg[2] == 'Y');\r
337 \r
338                                                         arg = arg.Substring(3);\r
339                                                 }\r
340                                                 #endregion\r
341                                         }\r
342                                         else if (arg.StartsWith("-N", StringComparison.OrdinalIgnoreCase))\r
343                                         {\r
344                                                 this.Enabled = true;\r
345                                                 this.Command = ECommand.Play;\r
346                                                 ret = true;\r
347 \r
348                                                 arg = arg.Substring(2);         // "-N"を除去\r
349                                                 string[] p = arg.Split(new char[] { ' ' });\r
350                                                 this.nStartBar = int.Parse(p[0]);     // 再生開始小節\r
351                                                 if (this.nStartBar < 0)\r
352                                                 {\r
353                                                         this.nStartBar = -1;\r
354                                                 }\r
355 \r
356                                                 int startIndex = arg.IndexOf(' ');\r
357                                                 string filename = arg.Substring(startIndex + 1);  // 再生ファイル名(フルパス) これで引数が終わっていることを想定\r
358                                                 try\r
359                                                 {\r
360                                                         filename = filename.Trim(new char[] { '\"' });\r
361                                                         bIsNeedReloadDTX(filename);\r
362                                                 }\r
363                                                 catch // 指定ファイルが存在しない\r
364                                                 {\r
365                                                 }\r
366                                                 arg = "";\r
367                                                 analyzing = false;\r
368                                         }\r
369                                         else\r
370                                         {\r
371                                                 analyzing = false;\r
372                                         }\r
373                                 }\r
374                         }\r
375                         //string[] s = { "Stop", "Play", "Preview" };\r
376                         //Trace.TraceInformation( "Command: " + s[ (int) this.Command ] );\r
377                         return ret;\r
378                 }\r
379 \r
380                 /// <summary>\r
381                 /// Viewer関連の設定のみを更新して、Config.iniに書き出す\r
382                 /// </summary>\r
383                 public void tUpdateConfigIni()\r
384                 {\r
385                         CConfigXml ConfigIni_backup = (CConfigXml) CDTXMania.Instance.ConfigIni.Clone();                // #36612 2016.9.12 yyagi\r
386                         CDTXMania.Instance.LoadConfig();\r
387 \r
388                         // CConfigIni cc = new CConfigIni();\r
389                         //string path = CDTXMania.Instance.strEXEのあるフォルダ + "Config.ini";\r
390                         //if (File.Exists(path))\r
391                         //{\r
392                         //      FileInfo fi = new FileInfo(path);\r
393                         //      if (fi.Length > 0)      // Config.iniが0byteだったなら、読み込まない\r
394                         //      {\r
395                         //              try\r
396                         //              {\r
397                         //                      CDTXMania..tファイルから読み込み(path);\r
398                         //              }\r
399                         //              catch\r
400                         //              {\r
401                         //                      //ConfigIni = new CConfigIni(); // 存在してなければ新規生成\r
402                         //              }\r
403                         //      }\r
404                         //      fi = null;\r
405                         //}\r
406 \r
407                         for (EPart inst = EPart.Drums; inst <= EPart.Bass; ++inst)\r
408                         {\r
409                                 CDTXMania.Instance.ConfigIni.nViewerScrollSpeed[inst].Value = ConfigIni_backup.nScrollSpeed[inst];\r
410                         }\r
411                         CDTXMania.Instance.ConfigIni.bViewerShowDebugStatus.Value = ConfigIni_backup.bDebugInfo;\r
412                         CDTXMania.Instance.ConfigIni.bViewerVSyncWait.Value = ConfigIni_backup.bVSyncWait;\r
413                         CDTXMania.Instance.ConfigIni.bViewerTimeStretch.Value = ConfigIni_backup.bTimeStretch;\r
414                         CDTXMania.Instance.ConfigIni.bViewerDrumsActive.Value = ConfigIni_backup.bDrums有効;\r
415                         CDTXMania.Instance.ConfigIni.bViewerGuitarActive.Value = ConfigIni_backup.bGuitar有効;\r
416 \r
417                         CDTXMania.Instance.ConfigIni.rcViewerWindow.W = ConfigIni_backup.rcWindow.W;\r
418                         CDTXMania.Instance.ConfigIni.rcViewerWindow.H = ConfigIni_backup.rcWindow.H;\r
419                         CDTXMania.Instance.ConfigIni.rcViewerWindow.X = ConfigIni_backup.rcWindow.X;\r
420                         CDTXMania.Instance.ConfigIni.rcViewerWindow.Y = ConfigIni_backup.rcWindow.Y;\r
421 \r
422                         CDTXMania.Instance.ConfigIni.rcWindow = ConfigIni_backup.rcWindow_backup;               // #36612 2016.9.12 yyagi\r
423 \r
424                         CDTXMania.Instance.SaveConfig();\r
425 \r
426                         ConfigIni_backup = null;\r
427                 }\r
428 \r
429                 private string last_path;\r
430                 private DateTime last_timestamp;\r
431 \r
432         }\r
433 }\r