OSDN Git Service

曲読込ステージから 曲ツリー管理 の依存を排除。
[strokestylet/CsWin10Desktop3.git] / StrokeStyleT / StrokeStyleT.cs
1 using System;
2 using System.Collections.Concurrent;
3 using System.Collections.Generic;
4 using System.Diagnostics;
5 using System.IO;
6 using System.Linq;
7 using System.Windows.Forms;
8 using Microsoft.VisualBasic.ApplicationServices;
9 using FDK;      // for string 拡張
10
11 namespace SST
12 {
13         class StrokeStyleT : FDK.ApplicationBase
14         {
15                 // グローバルリソース (static) 
16                 public static SST.フォルダ フォルダ => ( StrokeStyleT.bs_フォルダ );
17                 public static FDK.入力.Keyboard キーボード入力 => ( StrokeStyleT.bs_キーボード入力 );
18                 public static FDK.入力.MidiIn MIDI入力 => ( StrokeStyleT.bs_MIDI入力 );
19                 public static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice Wasapiデバイス => ( StrokeStyleT.bs_Wasapiデバイス );
20                 public static Random 乱数 => ( StrokeStyleT.bs_乱数 );
21                 public static SST.ユーザ.ユーザ管理 ユーザ管理 => ( StrokeStyleT.bs_ユーザ管理 );
22                 public static SST.曲.曲ツリー管理 曲ツリー管理 => ( StrokeStyleT.bs_曲ツリー管理 );
23                 public static SSTFormat.スコア 演奏スコア { get; set; } = null;
24                 public static SST.設定.Config Config => ( StrokeStyleT.bs_Config );
25                 public static bool ビュアーモードである { get; set; } = false;
26                 public static ConcurrentQueue<SST.ステージ.演奏.ビュアーメッセージ> ビュアーメッセージキュー => ( StrokeStyleT.bs_ビュアーメッセージキュー );
27
28                 public static void すべての入力デバイスをポーリングする()
29                 {
30                         // hack: 追加の入力デバイスができたら、ここにポーリングコードを追加すること。
31                         StrokeStyleT.キーボード入力?.ポーリングする();
32                         StrokeStyleT.MIDI入力?.ポーリングする();
33                 }
34
35                 // get only static property の初期化。
36                 static StrokeStyleT()
37                 {
38                         // フォルダ変数を真っ先に登録する。(ほかのメンバのコンストラクタでフォルダ変数を利用できるようにするため。)
39                         StrokeStyleT.bs_フォルダ = new SST.フォルダ();
40                         SST.フォルダ.フォルダ変数を追加する( "Static", StrokeStyleT.フォルダ.StaticFolder );
41                         SST.フォルダ.フォルダ変数を追加する( "AppData", StrokeStyleT.フォルダ.AppDataFolder );
42                         SST.フォルダ.フォルダ変数を追加する( "User", null );
43
44                         // その他の static の生成。
45                         StrokeStyleT.bs_ユーザ管理 = new ユーザ.ユーザ管理();
46                         StrokeStyleT.bs_曲ツリー管理 = new 曲.曲ツリー管理();
47                 }
48
49                 protected override void 初期化する()
50                 {
51                         FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
52
53                         lock( this.スレッド間同期 )
54                         {
55                                 Debug.Assert( null == this.デバイスリソース, "デバイスリソースの作成前であること。" );
56
57                                 this.コマンドライン引数を解析する( Environment.GetCommandLineArgs().Skip( 1 ) );   // 最初の要素は exe ファイル名なのでスキップする。
58
59                                 this.MainForm.Text = $"StrokeStyle<T> {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()}";
60                                 this.設計画面サイズdpx = new SharpDX.Size2F( 1920, 1080 );     // 設計画面サイズdpx(固定)
61
62                                 #region " コンフィグ を初期化する。"
63                                 //----------------
64                                 FDK.Log.Info( "コンフィグを初期化します。" );
65                                 StrokeStyleT.bs_Config = new 設定.Config();
66                                 StrokeStyleT.bs_Config.ConfigXmlを読み込む();
67                                 //----------------
68                                 #endregion
69                                 #region " コンフィグで指定されたウィンドウサイズに変更する。"
70                                 //----------------
71                                 this.MainForm.ClientSize = new System.Drawing.Size( StrokeStyleT.Config.物理画面サイズpx.Width, StrokeStyleT.Config.物理画面サイズpx.Height );
72                                 //----------------
73                                 #endregion
74
75                                 #region " System.Stopwatch が高解像度タイマを使わないならエラー。"
76                                 //-----------------
77                                 if( false == System.Diagnostics.Stopwatch.IsHighResolution )
78                                         throw new SSTException( "このシステムは、高解像度タイマをサポートしていません。" );
79                                 //-----------------
80                                 #endregion
81                                 #region " MediaFoundation を起動する。"
82                                 //-----------------
83                                 SharpDX.MediaFoundation.MediaManager.Startup();
84                                 //-----------------
85                                 #endregion
86                                 #region " Sleep 精度を上げる。"
87                                 //-----------------
88                                 StrokeStyleT.timeBeginPeriod( 1 );
89                                 //-----------------
90                                 #endregion
91
92                                 #region " ステージのActionを接続する。"
93                                 //----------------
94                                 this.曲読込ステージ.読込曲のファイルパスを取得する = () => ( ( StrokeStyleT.曲ツリー管理.現在選択されているノード as SST.曲.MusicNode )?.sstfファイルパス );
95
96                                 this.結果ステージ.演奏ステージインスタンスを取得する = () => ( this.演奏ステージ );
97                                 this.結果ステージ.BGMを終了する = () => { this.演奏ステージ.BGMを解放する(); };
98                                 //----------------
99                                 #endregion
100                                 #region " ユーザを初期化する。"
101                                 //-----------------
102                                 FDK.Log.Info( "ユーザ情報を初期化します。" );
103                                 StrokeStyleT.ユーザ管理.UsersXmlを読み込む();
104
105                                 // ユーザ別の初期化。
106                                 foreach( var ユーザ in StrokeStyleT.ユーザ管理.ユーザリスト )
107                                         ユーザ.SourcesXmlを読み込む();
108                                 //-----------------
109                                 #endregion
110                                 #region " WASAPI デバイスを初期化する。"
111                                 //----------------
112                                 StrokeStyleT.bs_Wasapiデバイス = new FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice();
113                                 StrokeStyleT.bs_Wasapiデバイス.初期化する( 15.0f );
114                                 //----------------
115                                 #endregion
116                                 #region " キーボード入力 を初期化する。"
117                                 //-----------------
118                                 FDK.Log.Info( "キーボード入力デバイスを初期化します。" );
119                                 StrokeStyleT.bs_キーボード入力 = new FDK.入力.Keyboard( this.MainForm.Handle );
120                                 //-----------------
121                                 #endregion
122                                 #region " MIDI入力 を初期化する。"
123                                 //-----------------
124                                 FDK.Log.Info( "MIDI入力デバイスを初期化します。" );
125                                 StrokeStyleT.bs_MIDI入力 = new FDK.入力.MidiIn();
126                                 //-----------------
127                                 #endregion
128
129                                 this.現在のステージ = this.最初のダミーステージ;
130
131                                 //#warning 全画面モード切替えを KeyDown で仮実装。
132                                 this.MainForm.KeyDown += ( target, arg ) => {
133
134                                         // Alt+Enter → 画面モードの切り替え
135                                         //if( ( arg.KeyCode == System.Windows.Forms.Keys.Return ) && ( arg.Modifiers == Keys.Alt ) )
136                                         //{
137                                         //      this.全画面モードとウィンドウモードを切り替える();
138                                         //      arg.Handled = true;
139                                         //}
140                                 };
141                         }
142
143                         FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
144                 }
145                 protected override void 終了する()
146                 {
147                         FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
148
149                         lock( this.スレッド間同期 )
150                         {
151                                 Debug.Assert( null != this.デバイスリソース, "デバイスリソースが解放される前であること。" );
152
153                                 #region " ステージを終了し、解放する。"
154                                 //----------------
155                                 if( ( null != this.現在のステージ ) && ( this.現在のステージ.活性化している ) )            // 念のため
156                                         this.現在のステージ.非活性化する( this.デバイスリソース );
157
158                                 this.最初のダミーステージ = null;
159                                 this.起動ステージ = null;
160                                 this.タイトルステージ = null;
161                                 this.ログインステージ = null;
162                                 this.選曲ステージ = null;
163                                 this.曲読込ステージ = null;
164                                 this.演奏ステージ = null;
165                                 this.結果ステージ = null;
166                                 //----------------
167                                 #endregion
168                                 #region " MIDI入力 を解放する。"
169                                 //-----------------
170                                 FDK.Log.Info( "MIDI入力デバイスを解放します。" );
171                                 FDK.Utilities.解放する( ref StrokeStyleT.bs_MIDI入力 );
172                                 //-----------------
173                                 #endregion
174                                 #region " キーボード入力 を解放する。"
175                                 //-----------------
176                                 FDK.Log.Info( "キーボード入力デバイスを解放します。" );
177                                 FDK.Utilities.解放する( ref StrokeStyleT.bs_キーボード入力 );
178                                 //-----------------
179                                 #endregion
180                                 #region " WASAPIデバイスを解放する。"
181                                 //----------------
182                                 FDK.Log.Info( "WASAPIデバイスを解放します。" );
183                                 FDK.Utilities.解放する( ref StrokeStyleT.bs_Wasapiデバイス );
184                                 //----------------
185                                 #endregion
186                                 #region " コンフィグを解放する。"
187                                 //----------------
188                                 FDK.Log.Info( "コンフィグを解放します。" );
189                                 StrokeStyleT.bs_Config = null;
190                                 //----------------
191                                 #endregion
192                                 #region " MediaFoundation を終了する。"
193                                 //-----------------
194                                 SharpDX.MediaFoundation.MediaManager.Shutdown();
195                                 //-----------------
196                                 #endregion
197                         }
198
199                         FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
200                 }
201                 protected override void シーンを描画する()
202                 {
203                         // このメソッドは、GUIスレッドではなく進行描画スレッドから呼び出されるので注意。(FDK.ApplicationBase.進行描画スレッド処理() を参照。)
204
205                         // 現在のステージを進行描画する。
206                         lock( this.スレッド間同期 )
207                         {
208                                 #region " 描画の準備を行う。"
209                                 //----------------
210                                 var d3dDevice = (SharpDX.Direct3D11.Device) null;
211                                 using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.デバイスリソース.DXGIDeviceManager, out d3dDevice ) )
212                                 using( d3dDevice )
213                                 using( var d3dContext = d3dDevice.ImmediateContext )
214                                 {
215                                         // 既定のD3Dレンダーターゲットビューを黒でクリアする。
216                                         d3dContext.ClearRenderTargetView( this.デバイスリソース.D3DRenderTargetView, SharpDX.Color4.Black );
217
218                                         // 深度バッファを 1.0f でクリアする。
219                                         d3dContext.ClearDepthStencilView(
220                                                 this.デバイスリソース.D3DDepthStencilView,
221                                                 SharpDX.Direct3D11.DepthStencilClearFlags.Depth,
222                                                 depth: 1.0f,
223                                                 stencil: 0 );
224                                 }
225                                 //----------------
226                                 #endregion
227
228                                 this.現在のステージ?.進行描画する( this.デバイスリソース );
229                         }
230
231                         // スワップチェーンを表示する。垂直帰線待ちなどで時間がかかるので、この部分はスレッド排他領域の外に配置すること。
232                         this.デバイスリソース.SwapChain.Present(
233                                 ( StrokeStyleT.Config.垂直帰線待ちを行う ) ? 1 : 0,
234                                 SharpDX.DXGI.PresentFlags.None );
235
236                         // ステージの状態をチェックし、必要あれば遷移またはアプリを終了する。
237                         bool アプリを終了せよ = false;
238                         lock( this.スレッド間同期)
239                         {
240                                 if( null != this.現在のステージ )
241                                 {
242                                         switch( this.現在のステージ.GetType().Name )
243                                         {
244                                                 case nameof( ステージ.ステージ ):
245                                                         #region " ビュアーモード → AutoPlayerでログインして演奏ステージ(ビュアーモード)へ。"
246                                                         //----------------
247                                                         if( StrokeStyleT.ビュアーモードである )
248                                                         {
249                                                                 this.ログインする( Properties.Resources.AUTOPLAYER );
250                                                                 this.演奏ステージ.活性化する( this.デバイスリソース );
251                                                                 this.現在のステージ = this.演奏ステージ;
252                                                         }
253                                                         //----------------
254                                                         #endregion
255                                                         #region " 通常モード → 起動ステージへ。"
256                                                         //----------------
257                                                         else
258                                                         {
259                                                                 this.起動ステージ.活性化する( this.デバイスリソース );
260                                                                 this.現在のステージ = this.起動ステージ;
261                                                         }
262                                                         //----------------
263                                                         #endregion
264                                                         break;
265
266                                                 case nameof( ステージ.起動.起動ステージ ):
267                                                         #region " 終了 → タイトルステージへ。"
268                                                         //---------------
269                                                         if( this.起動ステージ.現在のフェーズ == ステージ.起動.起動ステージ.フェーズ.終了 )
270                                                         {
271                                                                 this.現在のステージ.非活性化する( this.デバイスリソース );
272                                                                 this.現在のステージ = this.タイトルステージ;
273                                                                 this.現在のステージ.活性化する( this.デバイスリソース );
274                                                         }
275                                                         //---------------
276                                                         #endregion
277                                                         break;
278
279                                                 case nameof( ステージ.タイトル.タイトルステージ ):
280                                                         #region " 確定 → ログインステージへ。"
281                                                         //---------------
282                                                         if( this.タイトルステージ.現在のフェーズ == ステージ.タイトル.タイトルステージ.フェーズ.確定 )
283                                                         {
284                                                                 this.現在のステージ.非活性化する( this.デバイスリソース );
285                                                                 this.現在のステージ = this.ログインステージ;
286                                                                 this.現在のステージ.活性化する( this.デバイスリソース );
287                                                         }
288                                                         //---------------
289                                                         #endregion
290                                                         #region " キャンセル → アプリを終了する。"
291                                                         //---------------
292                                                         else if( this.タイトルステージ.現在のフェーズ == ステージ.タイトル.タイトルステージ.フェーズ.キャンセル )
293                                                         {
294                                                                 this.現在のステージ.非活性化する( this.デバイスリソース );
295                                                                 this.現在のステージ = null;
296                                                                 アプリを終了せよ = true;
297                                                         }
298                                                         //---------------
299                                                         #endregion
300                                                         break;
301
302                                                 case nameof( ステージ.ログイン.ログインステージ ):
303                                                         #region " 確定 → ログイン処理を行って、選曲ステージへ。"
304                                                         //---------------
305                                                         if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.確定 )
306                                                         {
307                                                                 this.ログインする( this.ログインステージ.ユーザインデックス );
308
309                                                                 var user = StrokeStyleT.ユーザ管理.現在選択されているユーザ;
310
311                                                                 foreach( var path in user.曲の検索元フォルダパスのリスト )
312                                                                         SST.曲.曲ツリー管理.フォルダから曲を再帰的に検索して子ノードリストに追加する( user.曲ツリーのルートノード, path );
313
314                                                                 StrokeStyleT.曲ツリー管理.現在の管理対象ツリー = StrokeStyleT.ユーザ管理.現在選択されているユーザ.曲ツリーのルートノード;
315
316                                                                 this.現在のステージ.非活性化する( this.デバイスリソース );
317                                                                 this.現在のステージ = this.選曲ステージ;
318                                                                 this.現在のステージ.活性化する( this.デバイスリソース );
319                                                         }
320                                                         //---------------
321                                                         #endregion
322                                                         #region " キャンセル → タイトルステージへ。"
323                                                         //---------------
324                                                         else if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.キャンセル )
325                                                         {
326                                                                 this.現在のステージ.非活性化する( this.デバイスリソース );
327                                                                 this.現在のステージ = this.タイトルステージ;
328                                                                 this.現在のステージ.活性化する( this.デバイスリソース );
329                                                         }
330                                                         //---------------
331                                                         #endregion
332                                                         break;
333
334                                                 case nameof( ステージ.選曲.選曲ステージ ):
335                                                         #region " 曲確定 → 曲読込ステージへ。"
336                                                         //---------------
337                                                         if( this.選曲ステージ.現在のフェーズ == ステージ.選曲.選曲ステージ.フェーズ.曲確定 )
338                                                         {
339                                                                 // 曲ノードが選択されていることを確認。
340                                                                 Trace.Assert( null != StrokeStyleT.曲ツリー管理.現在選択されているノード, "[バグあり] 選択曲が null です。" );
341                                                                 this.現在のステージ.非活性化する( this.デバイスリソース );
342                                                                 this.現在のステージ = this.曲読込ステージ;
343                                                                 this.現在のステージ.活性化する( this.デバイスリソース );
344                                                         }
345                                                         //---------------
346                                                         #endregion
347                                                         #region " キャンセル → アプリを終了する。"
348                                                         //---------------
349                                                         else if( this.選曲ステージ.現在のフェーズ == ステージ.選曲.選曲ステージ.フェーズ.キャンセル )
350                                                         {
351                                                                 this.現在のステージ.非活性化する( this.デバイスリソース );
352                                                                 this.現在のステージ = null;
353                                                                 アプリを終了せよ = true;
354                                                         }
355                                                         //---------------
356                                                         #endregion
357                                                         break;
358
359                                                 case nameof( ステージ.曲読込.曲読込ステージ ):
360                                                         #region " 終了 → 演奏ステージへ。"
361                                                         //--------------------
362                                                         if( this.曲読込ステージ.現在のフェーズ == ステージ.曲読込.曲読込ステージ.フェーズ.終了 )
363                                                         {
364                                                                 this.現在のステージ.非活性化する( this.デバイスリソース );
365                                                                 this.現在のステージ = this.演奏ステージ;
366                                                                 this.現在のステージ.活性化する( this.デバイスリソース );
367                                                         }
368                                                         //--------------------
369                                                         #endregion
370                                                         break;
371
372                                                 case nameof( ステージ.演奏.演奏ステージ ):
373                                                         #region " 演奏終了 → 結果ステージへ。"
374                                                         //--------------------
375                                                         if( this.演奏ステージ.現在のフェーズ == ステージ.演奏.演奏ステージ.フェーズ.クリアor失敗 )
376                                                         {
377                                                                 this.現在のステージ.非活性化する( this.デバイスリソース );
378                                                                 this.現在のステージ = this.結果ステージ;
379                                                                 this.現在のステージ.活性化する( this.デバイスリソース );
380                                                         }
381                                                         //--------------------
382                                                         #endregion
383                                                         #region " キャンセル → 選曲ステージへ。"
384                                                         //--------------------
385                                                         if( this.演奏ステージ.現在のフェーズ == ステージ.演奏.演奏ステージ.フェーズ.キャンセル )
386                                                         {
387                                                                 this.現在のステージ.非活性化する( this.デバイスリソース );
388                                                                 this.現在のステージ = this.選曲ステージ;
389                                                                 this.現在のステージ.活性化する( this.デバイスリソース );
390                                                         }
391                                                         //--------------------
392                                                         #endregion
393                                                         break;
394
395                                                 case nameof( ステージ.結果.結果ステージ ):
396                                                         #region " 終了 → 選曲ステージへ。"
397                                                         //--------------------
398                                                         if( this.結果ステージ.現在のフェーズ == ステージ.結果.結果ステージ.フェーズ.終了 )
399                                                         {
400                                                                 this.現在のステージ.非活性化する( this.デバイスリソース );
401                                                                 this.現在のステージ = this.選曲ステージ;
402                                                                 this.現在のステージ.活性化する( this.デバイスリソース );
403                                                         }
404                                                         //--------------------
405                                                         #endregion
406                                                         break;
407                                         }
408                                 }
409                         }
410
411                         if( アプリを終了せよ )
412                         {
413                                 // GUIスレッド上で、ウィンドウを閉じる。
414                                 this.MainForm.BeginInvoke( new Action( () => { this.MainForm.Close(); } ) );
415                         }
416                 }
417                 protected override void デバイス依存リソースを解放する()
418                 {
419                         FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
420
421                         lock( this.スレッド間同期 )
422                         {
423                                 Debug.Assert( null != this.デバイスリソース );  // 解放前であること。
424                                 this.現在のステージ?.デバイス依存リソースを解放する( this.デバイスリソース );
425                         }
426
427                         FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
428                 }
429                 protected override void デバイス依存リソースを再構築する()
430                 {
431                         FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
432
433                         lock( this.スレッド間同期 )
434                         {
435                                 Debug.Assert( null != this.デバイスリソース );  // 再生成済みであること。
436                                 this.現在のステージ?.デバイス依存リソースを作成する( this.デバイスリソース );
437                         }
438
439                         FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
440                 }
441                 /// <summary>
442                 /// アプリが二重起動されたときに発生するイベント。
443                 /// </summary>
444                 /// <remarks>
445                 /// 後続のインスタンスは起動せず、既存のインスタンスに対してこのイベントが発生する。
446                 /// eventArg.CommandLine で、後続のインスタンスのコマンドライン引数を確認することができる。
447                 /// </remarks>
448                 protected override void OnStartupNextInstance( StartupNextInstanceEventArgs eventArgs )
449                 {
450                         FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
451
452                         lock( this.スレッド間同期 )
453                         {
454                                 if( StrokeStyleT.ビュアーモードである )
455                                 {
456                                         this.コマンドライン引数を解析する( eventArgs.CommandLine );
457                                 }
458                                 else
459                                 {
460                                         FDK.Log.ERROR( "現在、ビュアーモードではありません。" );
461                                 }
462                         }
463
464                         FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
465                 }
466
467                 // 各ステージの、唯一のインスタンス。最終的に null を代入するので、readonlyにはしない。
468                 protected SST.ステージ.ステージ 最初のダミーステージ = new ステージ.ステージ();
469                 protected SST.ステージ.起動.起動ステージ 起動ステージ = new ステージ.起動.起動ステージ();
470                 protected SST.ステージ.タイトル.タイトルステージ タイトルステージ = new ステージ.タイトル.タイトルステージ();
471                 protected SST.ステージ.ログイン.ログインステージ ログインステージ = new ステージ.ログイン.ログインステージ();
472                 protected SST.ステージ.選曲.選曲ステージ 選曲ステージ = new ステージ.選曲.選曲ステージ();
473                 protected SST.ステージ.曲読込.曲読込ステージ 曲読込ステージ = new ステージ.曲読込.曲読込ステージ();
474                 protected SST.ステージ.演奏.演奏ステージ 演奏ステージ = new ステージ.演奏.演奏ステージ();
475                 protected SST.ステージ.結果.結果ステージ 結果ステージ = new ステージ.結果.結果ステージ();
476
477                 private SST.ステージ.ステージ 現在のステージ = null;
478
479                 #region " バックストア。"
480                 //----------------
481                 private static SST.フォルダ bs_フォルダ = null;
482                 private static FDK.入力.Keyboard bs_キーボード入力 = null;
483                 private static FDK.入力.MidiIn bs_MIDI入力 = null;
484                 private static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice bs_Wasapiデバイス = null;
485                 private static readonly Random bs_乱数 = new Random( DateTime.Now.Millisecond );
486                 private static SST.ユーザ.ユーザ管理 bs_ユーザ管理 = null;
487                 private static SST.曲.曲ツリー管理 bs_曲ツリー管理 = null;
488                 private static SST.設定.Config bs_Config = null;
489                 private static readonly ConcurrentQueue<SST.ステージ.演奏.ビュアーメッセージ> bs_ビュアーメッセージキュー = new ConcurrentQueue<ステージ.演奏.ビュアーメッセージ>();
490                 //----------------
491                 #endregion
492
493                 /// <summary>
494                 /// コマンドライン引数を解析して、ビュアーモードの設定があればそれを返す。
495                 /// </summary>
496                 /// <param name="args">コマンドライン引数の列挙。exeファイル名は含まない。</param>
497                 /// <return>引数を反映したビュアーモード変数。</return>
498                 private void コマンドライン引数を解析する( IEnumerable<string> args )
499                 {
500                         FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
501
502                         try
503                         {
504                                 if( 0 == args.Count() )
505                                 {
506                                         FDK.Log.Info( "引数は指定されていません。" );    // ビュアーモードではない。
507                                         return;
508                                 }
509
510                                 StrokeStyleT.ビュアーモードである = true;
511
512                                 try
513                                 {
514                                         // 新しいメッセージを生成する。
515                                         var msg = new ステージ.演奏.ビュアーメッセージ() {
516                                                 種別 = ステージ.演奏.ビュアーメッセージ.E種別.演奏開始,          // 規定値は「演奏開始」
517                                                 曲ファイルパス = null,
518                                                 演奏開始小節番号 = 0,
519                                                 ドラム音を発声する = false,    // 規定値は false
520                                         };
521
522                                         // オプションを定義する。
523                                         var optionSet = new Mono.Options.OptionSet() {
524                                                 "Usage: StrokeStyleT [File] [OPTIONS]+",
525                                                 "  File\t\t\t\tビュアーモードで表示する曲ファイル名です。",
526                                                 { "p=|part=", "ビュアーモードで起動し、指定された小節番号から演奏を開始します。小節番号を省略すると、先頭から再生します。", (int v) => { msg.演奏開始小節番号 = v; }  },
527                                                 { "s|stop", "ビュアーモードで演奏中であれば、演奏を停止します。", v => { if ( v != null ) { msg.種別 = ステージ.演奏.ビュアーメッセージ.E種別.演奏停止; } } },
528                                                 { "d|drums", "ビュアーモードで、チップヒット時に内蔵のドラム音を再生します。", v => { if( v != null ) { msg.ドラム音を発声する = true; } } },
529                                         };
530
531                                         // オプションを解析する。
532                                         List<string> ファイルパスs = optionSet.Parse( args );
533
534                                         // 解析結果。
535                                         if( msg.種別 == ステージ.演奏.ビュアーメッセージ.E種別.演奏停止 )
536                                         {
537                                                 // (A) 演奏停止(曲ファイルパスは省略可。)
538                                                 FDK.Log.Info( "ビュアーメッセージ: 演奏停止" );
539                                         }
540                                         else
541                                         {
542                                                 // (B) 演奏開始(曲ファイルパスは必須。)
543                                                 if( 0 < ファイルパスs.Count )
544                                                 {
545                                                         if( File.Exists( ファイルパスs[ 0 ] ) )
546                                                         {
547                                                                 msg.曲ファイルパス = ファイルパスs[ 0 ];
548                                                         }
549                                                         else
550                                                         {
551                                                                 msg.曲ファイルパス = null;    // ファイルが存在しなかったら null 。
552                                                                 throw new Mono.Options.OptionException( $"ファイルが存在しません。[{FDK.フォルダ.絶対パスをフォルダ変数付き絶対パスに変換して返す( ファイルパスs[ 0 ] )}]", "File" );
553                                                         }
554                                                 }
555                                                 else
556                                                 {
557                                                         throw new Mono.Options.OptionException( "ファイルの指定がありません。", "File" );
558                                                 }
559
560                                                 FDK.Log.Info( "ビュアーメッセージ: 演奏開始" );
561                                                 FDK.Log.Info( $"曲ファイルパス: {msg.曲ファイルパス}" );
562                                                 FDK.Log.Info( $"開始小節番号: {msg.演奏開始小節番号}" );
563                                                 FDK.Log.Info( $"ドラム音: {msg.ドラム音を発声する}" );
564                                         }
565
566                                         // キューへ格納。
567                                         StrokeStyleT.ビュアーメッセージキュー.Enqueue( msg );
568                                         FDK.Log.Info( "ビュアーメッセージを送信しました。" );
569                                 }
570                                 catch( Mono.Options.OptionException e )
571                                 {
572                                         FDK.Log.ERROR( $"{e.Message}" );
573                                 }
574                         }
575                         finally
576                         {
577                                 FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
578                         }
579                 }
580
581                 private void ログインする( SST.ユーザ.ユーザ ユーザ )
582                 {
583                         StrokeStyleT.ユーザ管理.ユーザを選択する( ユーザ );
584                         FDK.Log.Info( $"ユーザが選択されました。[{StrokeStyleT.ユーザ管理.現在選択されているユーザ.名前}]" );
585                 }
586                 private void ログインする( string ユーザ名 )
587                 {
588                         StrokeStyleT.ユーザ管理.ユーザを選択する( ユーザ名 );
589                         FDK.Log.Info( $"ユーザが選択されました。[{StrokeStyleT.ユーザ管理.現在選択されているユーザ.名前}]" );
590                 }
591                 private void ログインする( int ユーザリストのインデックス番号 )
592                 {
593                         StrokeStyleT.ユーザ管理.ユーザを選択する( ユーザリストのインデックス番号 );
594                         FDK.Log.Info( $"ユーザが選択されました。[{StrokeStyleT.ユーザ管理.現在選択されているユーザ.名前}]" );
595                 }
596
597                 #region " Win32 API "
598                 //-----------------
599                 [ System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeBeginPeriod" )]
600                 private static extern uint timeBeginPeriod( uint uMilliseconds );
601
602                 [System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeEndPeriod" )]
603                 private static extern uint timeEndPeriod( uint uMilliseconds );
604                 //-----------------
605                 #endregion
606         }
607 }