OSDN Git Service

#37961 PCとMIDI機器をつなぐケーブルとして「MIDI2.0-USB」を使用している場合に警告を表示する機能を追加。このケーブルを通すと、PCからのMIDI出力...
[dtxmania/dtxmania.git] / DTXMania / コード / ステージ / CDTXVmode.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Diagnostics;
5 using System.IO;
6 using System.Threading;
7 using FDK;
8
9
10 namespace DTXMania
11 {
12         public class CDTXVmode
13         {
14                 public enum ECommand
15                 {
16                         Stop,
17                         Play,
18                         Preview
19                 }
20
21                 /// <summary>
22                 /// DTXVモードかどうか
23                 /// </summary>
24                 public bool Enabled
25                 {
26                         get;
27                         set;
28                 }
29
30                 /// <summary>
31                 /// プレビューサウンドの再生が発生した
32                 /// </summary>
33                 public bool Preview
34                 {
35                         get;
36                         set;
37                 }
38
39                 /// <summary>
40                 /// 外部から再指示が発生したか
41                 /// </summary>
42                 public bool Refreshed
43                 {
44                         get;
45                         set;
46                 }
47
48                 /// <summary>
49                 /// 演奏開始小節番号
50                 /// </summary>
51                 public int nStartBar
52                 {
53                         get;
54                         set;
55                 }
56
57                 /// <summary>
58                 /// DTXファイルの再読み込みが必要かどうか
59                 /// </summary>
60                 public bool NeedReload
61                 {
62                         get;
63                         private set;
64                         //                      private set;    // 本来はprivate setにすべきだが、デバッグが簡単になるので、しばらくはprivateなしのままにする。
65                 }
66
67                 /// <summary>
68                 /// DTXCからのコマンド
69                 /// </summary>
70                 public ECommand Command
71                 {
72                         get;
73                         set;
74                 }
75
76                 public ESoundDeviceType soundDeviceType
77                 {
78                         get;
79                         set;
80                 }
81                 public int nASIOdevice
82                 {
83                         get;
84                         set;
85                 }
86                 /// <summary>
87                 /// 前回からサウンドデバイスが変更されたか
88                 /// </summary>
89                 public bool ChangedSoundDevice
90                 {
91                         get;
92                         set;
93                 }
94
95                 public string filename
96                 {
97                         get
98                         {
99                                 return last_path;
100                         }
101                 }
102
103                 public string previewFilename
104                 {
105                         get;
106                         set;
107                 }
108                 public int previewVolume
109                 {
110                         get;
111                         set;
112                 }
113                 public int previewPan
114                 {
115                         get;
116                         set;
117                 }
118                 public bool GRmode
119                 {
120                         get;
121                         set;
122                 }
123                 public bool lastGRmode
124                 {
125                         get;
126                         private set;
127                 }
128                 public bool TimeStretch
129                 {
130                         get;
131                         set;
132                 }
133                 public bool lastTimeStretch
134                 {
135                         get;
136                         private set;
137                 }
138                 public bool VSyncWait
139                 {
140                         get;
141                         set;
142                 }
143                 public bool lastVSyncWait
144                 {
145                         get;
146                         private set;
147                 }
148
149
150                 /// <summary>
151                 /// コンストラクタ
152                 /// </summary>
153                 public CDTXVmode()
154                 {
155                         this.last_path = "";
156                         this.last_timestamp = DateTime.MinValue;
157                         this.Enabled = false;
158                         this.nStartBar = 0;
159                         this.Refreshed = false;
160                         this.NeedReload = false;
161                         this.previewFilename = "";
162                         this.GRmode = false;
163                         this.lastGRmode = false;
164                         this.TimeStretch = false;
165                         this.lastTimeStretch = false;
166                         this.VSyncWait = true;
167                         this.lastVSyncWait = true;
168                 }
169
170                 /// <summary>
171                 /// DTXファイルのリロードが必要かどうか判定する
172                 /// </summary>
173                 /// <param name="filename">DTXファイル名</param>
174                 /// <returns>再読込が必要ならtrue</returns>
175                 /// <remarks>プロパティNeedReloadにも結果が入る</remarks>
176                 /// <remarks>これを呼び出すたびに、Refreshedをtrueにする</remarks>
177                 /// <exception cref="FileNotFoundException"></exception>
178                 public bool bIsNeedReloadDTX(string filename)
179                 {
180                         if (!File.Exists(filename))     // 指定したファイルが存在しないなら例外終了
181                         {
182                                 Trace.TraceError("ファイルが見つかりません。({0})", filename);
183                                 this.last_path = filename;
184                                 throw new FileNotFoundException();
185                                 //return false;
186                         }
187
188                         this.Refreshed = true;
189
190                         // 前回とファイル名が異なるか、タイムスタンプが更新されているか、
191                         // GRmode等の設定を変更したなら、DTX要更新
192                         DateTime current_timestamp = File.GetLastWriteTime(filename);
193                         if (last_path != filename || current_timestamp > last_timestamp ||
194                                 this.lastGRmode != this.GRmode || this.lastTimeStretch != this.TimeStretch || this.lastVSyncWait != this.VSyncWait)
195                         {
196                                 this.last_path = filename;
197                                 this.last_timestamp = current_timestamp;
198                                 this.lastGRmode = this.GRmode;
199                                 this.lastTimeStretch = this.TimeStretch;
200                                 this.lastVSyncWait = this.VSyncWait;
201
202                                 this.NeedReload = true;
203                                 return true;
204                         }
205                         this.NeedReload = false;
206                         return false;
207                 }
208
209
210                 /// <summary>
211                 /// Viewer関連の設定のみを更新して、Config.iniに書き出す
212                 /// </summary>
213                 public void tUpdateConfigIni()
214                 {
215                         /// Viewer関連の設定のみを更新するために、
216                         /// 1. 現在のconfig.ini相当の情報を、別変数にコピーしておく
217                         /// 2. config.iniを読み込みなおす
218                         /// 3. 別変数のコピーから、Viewer関連の設定を、configに入れ込む
219                         /// 4. Config.iniを保存する
220         
221                         CConfigXml ConfigIni_backup = (CConfigXml) CDTXMania.Instance.ConfigIni.Clone();                // #36612 2016.9.12 yyagi
222                         CDTXMania.Instance.LoadConfig();
223
224                         // CConfigIni cc = new CConfigIni();
225                         //string path = CDTXMania.Instance.strEXEのあるフォルダ + "Config.ini";
226                         //if (File.Exists(path))
227                         //{
228                         //      FileInfo fi = new FileInfo(path);
229                         //      if (fi.Length > 0)      // Config.iniが0byteだったなら、読み込まない
230                         //      {
231                         //              try
232                         //              {
233                         //                      CDTXMania..tファイルから読み込み(path);
234                         //              }
235                         //              catch
236                         //              {
237                         //                      //ConfigIni = new CConfigIni(); // 存在してなければ新規生成
238                         //              }
239                         //      }
240                         //      fi = null;
241                         //}
242
243                         for (EPart inst = EPart.Drums; inst <= EPart.Bass; ++inst)
244                         {
245                                 CDTXMania.Instance.ConfigIni.nViewerScrollSpeed[inst].Value = ConfigIni_backup.nScrollSpeed[inst];
246                         }
247                         CDTXMania.Instance.ConfigIni.bViewerShowDebugStatus.Value = ConfigIni_backup.bDebugInfo;
248                         CDTXMania.Instance.ConfigIni.bViewerVSyncWait.Value = ConfigIni_backup.bVSyncWait;
249                         CDTXMania.Instance.ConfigIni.bViewerTimeStretch.Value = ConfigIni_backup.bTimeStretch;
250                         CDTXMania.Instance.ConfigIni.bViewerDrumsActive.Value = ConfigIni_backup.bDrums有効;
251                         CDTXMania.Instance.ConfigIni.bViewerGuitarActive.Value = ConfigIni_backup.bGuitar有効;
252
253                         CDTXMania.Instance.ConfigIni.rcViewerWindow.W = ConfigIni_backup.rcWindow.W;
254                         CDTXMania.Instance.ConfigIni.rcViewerWindow.H = ConfigIni_backup.rcWindow.H;
255                         CDTXMania.Instance.ConfigIni.rcViewerWindow.X = ConfigIni_backup.rcWindow.X;
256                         CDTXMania.Instance.ConfigIni.rcViewerWindow.Y = ConfigIni_backup.rcWindow.Y;
257
258                         CDTXMania.Instance.SaveConfig();
259
260                         ConfigIni_backup = null;
261                 }
262
263                 private string last_path;
264                 private DateTime last_timestamp;
265
266         }
267 }