OSDN Git Service

Merge branch 'develop' of git.osdn.net:/gitroot/strokestylet/CsWin10Desktop3 into...
[strokestylet/CsWin10Desktop3.git] / StrokeStyleT / StrokeStyleT.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Diagnostics;
4 using System.Linq;
5 using System.ServiceModel;
6 using System.Windows.Forms;
7 using FDK;
8
9 namespace SST
10 {
11         [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]     // サービスインターフェースをシングルスレッドで呼び出す。
12         class StrokeStyleT : SST.IStrokeStyleTService
13         {
14                 // グローバルリソース (static) 
15
16                 public static SST.フォルダ フォルダ
17                 {
18                         get { return StrokeStyleT.bs_フォルダ; }
19                 }
20                 public static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice Wasapiデバイス
21                 {
22                         get { return StrokeStyleT.bs_Wasapiデバイス; }
23                 }
24                 public static System.Random 乱数
25                 {
26                         get { return StrokeStyleT.bs_乱数; }
27                 }
28                 public static SST.ユーザ.ユーザ管理 ユーザ管理
29                 {
30                         get { return StrokeStyleT.bs_ユーザ管理; }
31                 }
32                 public static SST.曲.曲ツリー管理 曲ツリー管理
33                 {
34                         get { return StrokeStyleT.bs_曲ツリー管理; }
35                 }
36                 public static SSTFormat.スコア 演奏スコア
37                 {
38                         get;
39                         set;
40                 } = null;
41                 public static SST.設定.Config Config
42                 {
43                         get { return StrokeStyleT.bs_Config; }
44                 }
45                 public static bool ビュアーモードである
46                 {
47                         get;
48                         set;
49                 } = false;
50                 public static bool ビュアーモードではない
51                 {
52                         get { return !StrokeStyleT.ビュアーモードである; }
53                         set { StrokeStyleT.ビュアーモードである = !value; }
54                 }
55                 public static FDK.入力.Keyboard キーボード入力
56                 {
57                         get { return StrokeStyleT.bs_キーボード入力; }
58                 }
59                 public static FDK.入力.MidiIn MIDI入力
60                 {
61                         get { return StrokeStyleT.bs_MIDI入力; }
62                 }
63
64                 public static void すべての入力デバイスをポーリングする()
65                 {
66                         // hack: 追加の入力デバイスができたら、ここにポーリングコードを追加すること。
67                         StrokeStyleT.キーボード入力?.ポーリングする();
68                         StrokeStyleT.MIDI入力?.ポーリングする();
69                 }
70
71                 static StrokeStyleT()
72                 {
73                         // フォルダ変数を真っ先に登録する。(ほかのメンバのコンストラクタでフォルダ変数を利用できるようにするため。)
74                         StrokeStyleT.bs_フォルダ = new SST.フォルダ();
75                         SST.フォルダ.フォルダ変数を追加する( "Static", StrokeStyleT.フォルダ.StaticFolder );
76                         SST.フォルダ.フォルダ変数を追加する( "AppData", StrokeStyleT.フォルダ.AppDataFolder );
77                         SST.フォルダ.フォルダ変数を追加する( "User", null );
78                 }
79                 public StrokeStyleT()
80                 {
81                         #region " ビュアーモードかどうかを確認する。"
82                         //----------------
83                         foreach( var arg in Environment.GetCommandLineArgs() )
84                         {
85                                 if( ( "-v" == arg.ToLower() ) || ( "-viewer" == arg.ToLower() ) )
86                                 {
87                                         StrokeStyleT.ビュアーモードである = true;
88                                         break;
89                                 }
90                         }
91                         //----------------
92                         #endregion
93
94                         this.State = ApplicationState.起動;
95
96                         this.MainForm = new SharpDX.Windows.RenderForm();
97                         this.MainForm.AllowUserResizing = false;        // ユーザはフォームサイズを変更できない。
98                         this.MainForm.UserResized += フォームサイズが変更された;
99                 }
100                 public void Run()
101                 {
102                         Debug.Assert( null != this.MainForm );
103
104                         SharpDX.Windows.RenderLoop.Run( this.MainForm, () => {
105
106                                 // アプリケーションの状態に応じて処理分岐。
107                                 switch( this.State )
108                                 {
109                                         case ApplicationState.起動:
110                                                 this.初期化する();
111                                                 this.State = ApplicationState.進行描画;
112                                                 break;
113
114                                         case ApplicationState.進行描画:
115                                                 this.進行描画する();
116                                                 if( this.State == ApplicationState.終了 )
117                                                         this.終了する();
118                                                 break;
119
120                                         case ApplicationState.終了:
121                                                 // 何もしない
122                                                 break;
123                                 }
124
125                         } );
126                 }
127
128                 #region " WCF サービスインターフェースの実装 "
129                 //----------------
130                 // ・このサービスインターフェースは、シングルスレッド(GUIスレッド)で同期実行される。(StrokeStyleT クラスの ServiceBehavior属性を参照。)
131                 // ・このサービスホストはシングルトンであり、すべてのクライアントセッションは同一(単一)のサービスインスタンスへ接続される。(Program.Main() を参照。)
132
133                 public void ViewerPlay( string path, int startPart = 0, bool drumsSound = true )
134                 {
135                         if( StrokeStyleT.ビュアーモードではない )
136                                 return;
137
138                         // todo: 演奏を開始する。
139                 }
140                 public void ViewerStop()
141                 {
142                         if( StrokeStyleT.ビュアーモードではない )
143                                 return;
144
145                         // todo: 演奏を停止する。
146                 }
147                 public float GetSoundDelay()
148                 {
149                         if( StrokeStyleT.ビュアーモードではない )
150                                 return 0f;
151
152                         // todo: 発声遅延[ms]を返す。
153                         return 0f;
154                 }
155                 //----------------
156                 #endregion
157
158                 protected enum ApplicationState { 起動, 進行描画, 終了 }
159                 protected ApplicationState State;
160                 protected SharpDX.Windows.RenderForm MainForm = null;
161                 protected SharpDX.Size2F 設計画面サイズdpx = SharpDX.Size2F.Empty;
162
163                 protected FDK.メディア.デバイスリソース デバイスリソース = null;
164                 protected SST.ステージ.ステージ 最初のダミーステージ = null;
165                 protected SST.ステージ.起動.起動ステージ 起動ステージ = null;
166                 protected SST.ステージ.タイトル.タイトルステージ タイトルステージ = null;
167                 protected SST.ステージ.ログイン.ログインステージ ログインステージ = null;
168                 protected SST.ステージ.選曲.選曲ステージ 選曲ステージ = null;
169                 protected SST.ステージ.曲読込.曲読込ステージ 曲読込ステージ = null;
170                 protected SST.ステージ.演奏.演奏ステージ 演奏ステージ = null;
171                 protected SST.ステージ.結果.結果ステージ 結果ステージ = null;
172                 protected SST.ステージ.ステージ 現在のステージ = null;
173
174                 protected void 初期化する()
175                 {
176                         FDK.Log.現在のスレッドに名前をつける( "Render" );
177                         FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
178                         Debug.Assert( null == this.デバイスリソース, "デバイスリソースの作成前であること。" );
179
180                         StrokeStyleT.bs_ユーザ管理 = new ユーザ.ユーザ管理();
181                         StrokeStyleT.bs_曲ツリー管理 = new 曲.曲ツリー管理();
182
183                         #region " 高解像度タイマを使えないならエラー。"
184                         //-----------------
185                         if( false == System.Diagnostics.Stopwatch.IsHighResolution )
186                                 throw new SSTException( "このシステムは、高解像度タイマをサポートしていません。" );
187                         //-----------------
188                         #endregion
189                         #region " MediaFoundation を起動する。"
190                         //-----------------
191                         SharpDX.MediaFoundation.MediaManager.Startup();
192                         //-----------------
193                         #endregion
194                         #region " Sleep 精度を上げる。"
195                         //-----------------
196                         Win32.timeBeginPeriod( 1 );
197                         //-----------------
198                         #endregion
199
200                         #region " コンフィグ を初期化する。"
201                         //----------------
202                         FDK.Log.Info( "コンフィグを初期化します。" );
203                         StrokeStyleT.bs_Config = new 設定.Config();
204                         StrokeStyleT.bs_Config.ConfigXmlを読み込む();
205                         //----------------
206                         #endregion
207
208                         #region " コンフィグで指定されたウィンドウサイズに変更する。"
209                         //----------------
210                         this.MainForm.ClientSize = new System.Drawing.Size( StrokeStyleT.Config.物理画面サイズpx.Width, StrokeStyleT.Config.物理画面サイズpx.Height );
211                         //----------------
212                         #endregion
213                         #region " フォームタイトルと設計画面サイズを設定する。"
214                         //----------------
215                         this.MainForm.Text = $"StrokeStyle<T> {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()}";
216                         if( StrokeStyleT.ビュアーモードである )
217                                 this.MainForm.Text += " (Viewer)";
218
219                         this.設計画面サイズdpx = new SharpDX.Size2F( 1920f, 1080f );
220                         //----------------
221                         #endregion
222
223                         #region " デバイスリソースを作成する。"
224                         //----------------
225                         FDK.Log.BeginInfo( "デバイスリソースを作成します。" );
226                         FDK.Log.Info( $"設計画面サイズ: {this.設計画面サイズdpx}" );
227                         FDK.Log.Info( $"物理画面サイズ: {this.MainForm.ClientSize}" );
228                         this.デバイスリソース = new FDK.メディア.デバイスリソース( this.設計画面サイズdpx );
229                         this.デバイスリソース.すべてのリソースを作成する( this.MainForm.ClientSize, this.MainForm.Handle );
230                         //----------------
231                         #endregion
232
233                         #region " ステージを生成する。"
234                         //----------------
235                         this.最初のダミーステージ = new ステージ.ステージ();
236                         this.起動ステージ = new ステージ.起動.起動ステージ();
237                         this.タイトルステージ = new ステージ.タイトル.タイトルステージ();
238                         this.ログインステージ = new ステージ.ログイン.ログインステージ();
239                         this.選曲ステージ = new ステージ.選曲.選曲ステージ();
240                         this.曲読込ステージ = new ステージ.曲読込.曲読込ステージ();
241                         this.演奏ステージ = new ステージ.演奏.演奏ステージ();
242                         this.結果ステージ = new ステージ.結果.結果ステージ();
243
244                         // 外部依存アクションを接続する。
245                         this.曲読込ステージ.読込曲のファイルパスを取得する = () => ( ( StrokeStyleT.曲ツリー管理.現在選択されているノード as SST.曲.MusicNode )?.sstfファイルパス );
246                         this.結果ステージ.演奏ステージインスタンスを取得する = () => ( this.演奏ステージ );
247                         this.結果ステージ.BGMを終了する = () => { this.演奏ステージ.BGMを解放する(); };
248                         //----------------
249                         #endregion
250                         #region " ユーザを初期化する。"
251                         //-----------------
252                         FDK.Log.Info( "ユーザ情報を初期化します。" );
253                         StrokeStyleT.ユーザ管理.UsersXmlを読み込む();
254
255                         // ユーザ別の初期化。
256                         foreach( var ユーザ in StrokeStyleT.ユーザ管理.ユーザリスト )
257                                 ユーザ.SourcesXmlを読み込む();
258                         //-----------------
259                         #endregion
260                         #region " WASAPI デバイスを初期化する。"
261                         //----------------
262                         StrokeStyleT.bs_Wasapiデバイス = new FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice();
263                         StrokeStyleT.bs_Wasapiデバイス.初期化する( 15.0f );
264                         //----------------
265                         #endregion
266                         #region " キーボード入力 を初期化する。"
267                         //-----------------
268                         FDK.Log.Info( "キーボード入力デバイスを初期化します。" );
269                         StrokeStyleT.bs_キーボード入力 = new FDK.入力.Keyboard( this.MainForm.Handle );
270                         //-----------------
271                         #endregion
272                         #region " MIDI入力 を初期化する。"
273                         //-----------------
274                         FDK.Log.Info( "MIDI入力デバイスを初期化します。" );
275                         StrokeStyleT.bs_MIDI入力 = new FDK.入力.MidiIn();
276                         //-----------------
277                         #endregion
278
279                         FDK.Log.Info( "最初のダミーステージを開始します。" );
280                         this.現在のステージ = this.最初のダミーステージ;
281
282                         //#warning 全画面モード切替えを KeyDown で仮実装。
283                         this.MainForm.KeyDown += ( target, arg ) => {
284
285                                 // F11 → 画面モードの切り替え
286                                 if( arg.KeyCode == System.Windows.Forms.Keys.F11 )
287                                 {
288                                         this.全画面モードとウィンドウモードを切り替える();
289                                         arg.Handled = true;
290                                 }
291                         };
292
293                         Debug.Assert( SharpDX.Size2F.Empty != this.設計画面サイズdpx, "初期化メソッド内で設計画面サイズを設定してあること。" );
294                         FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
295                 }
296                 protected void 終了する()
297                 {
298                         FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
299                         Debug.Assert( null != this.デバイスリソース, "デバイスリソースが解放される前であること。" );
300
301                         #region " ステージを終了し、解放する。"
302                         //----------------
303                         if( ( null != this.現在のステージ ) && ( this.現在のステージ.活性化している ) )      // 念のため
304                                 this.現在のステージ.非活性化する( this.デバイスリソース );
305
306                         this.最初のダミーステージ = null;
307                         this.起動ステージ = null;
308                         this.タイトルステージ = null;
309                         this.ログインステージ = null;
310                         this.選曲ステージ = null;
311                         this.曲読込ステージ = null;
312                         this.演奏ステージ = null;
313                         this.結果ステージ = null;
314                         //----------------
315                         #endregion
316
317                         #region " デバイスリソースを解放する。"
318                         //----------------
319                         FDK.Utilities.解放する( ref this.デバイスリソース );
320                         //----------------
321                         #endregion
322
323                         #region " MIDI入力デバイスを解放する。"
324                         //-----------------
325                         FDK.Log.Info( "MIDI入力デバイスを解放します。" );
326                         FDK.Utilities.解放する( ref StrokeStyleT.bs_MIDI入力 );
327                         //-----------------
328                         #endregion
329                         #region " キーボード入力デバイスを解放する。"
330                         //-----------------
331                         FDK.Log.Info( "キーボード入力デバイスを解放します。" );
332                         FDK.Utilities.解放する( ref StrokeStyleT.bs_キーボード入力 );
333                         //-----------------
334                         #endregion
335                         #region " WASAPIデバイスを解放する。"
336                         //----------------
337                         FDK.Log.Info( "WASAPIデバイスを解放します。" );
338                         FDK.Utilities.解放する( ref StrokeStyleT.bs_Wasapiデバイス );
339                         //----------------
340                         #endregion
341                         
342                         #region " コンフィグを保存し、解放する。"
343                         //----------------
344                         FDK.Log.Info( "コンフィグを解放します。" );
345                         StrokeStyleT.bs_Config.ConfigXmlを保存する();
346                         StrokeStyleT.bs_Config = null;
347                         //----------------
348                         #endregion
349                         #region " フォームを閉じる。"
350                         //----------------
351                         FDK.Utilities.解放する( ref this.MainForm );
352                         //----------------
353                         #endregion
354
355                         #region " MediaFoundation を終了する。"
356                         //-----------------
357                         SharpDX.MediaFoundation.MediaManager.Shutdown();
358                         //-----------------
359                         #endregion
360
361                         FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
362                 }
363                 protected void 進行描画する()
364                 {
365                         #region " D3Dデバイスが消失していれば再構築する。"
366                         //----------------
367                         bool 異常発生 = false;
368                         this.デバイスリソース.D3Dデバイスが消失していれば再構築する( out 異常発生 );
369
370                         // 再構築不可能な異常の場合は、即終了する。
371                         if( 異常発生 )
372                         {
373                                 this.State = ApplicationState.終了;
374                                 return;
375                         }
376                         //----------------
377                         #endregion
378                         #region " 描画の前処理を行う。"
379                         //----------------
380                         {
381                                 var d3dDevice = (SharpDX.Direct3D11.Device) null;
382                                 using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.デバイスリソース.DXGIDeviceManager, out d3dDevice ) )
383                                 using( d3dDevice )
384                                 using( var d3dContext = d3dDevice.ImmediateContext )
385                                 {
386                                         // 既定のD3Dレンダーターゲットビューを黒でクリアする。
387                                         d3dContext.ClearRenderTargetView( this.デバイスリソース.D3DRenderTargetView, SharpDX.Color4.Black );
388
389                                         // 深度バッファを 1.0f でクリアする。
390                                         d3dContext.ClearDepthStencilView(
391                                                 this.デバイスリソース.D3DDepthStencilView,
392                                                 SharpDX.Direct3D11.DepthStencilClearFlags.Depth,
393                                                 depth: 1.0f,
394                                                 stencil: 0 );
395                                 }
396                         }
397                         //----------------
398                         #endregion
399                         #region " 現在のステージを進行描画する。"
400                         //----------------
401                         this.現在のステージ?.進行描画する( this.デバイスリソース );
402                         //----------------
403                         #endregion
404                         #region " スワップチェーンを表示する。"
405                         //----------------
406                         if( StrokeStyleT.Config.垂直帰線待ちを行う )
407                         {
408                                 // We recommend that you use Flush when the CPU waits for an arbitrary amount of time
409                                 // (such as when you call the Sleep function). 
410                                 // → https://msdn.microsoft.com/ja-jp/library/windows/desktop/ff476425(v=vs.85).aspx
411
412                                 var d3dDevice = (SharpDX.Direct3D11.Device) null;
413                                 using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.デバイスリソース.DXGIDeviceManager, out d3dDevice ) )
414                                 using( d3dDevice )
415                                 using( var d3dContext = d3dDevice.ImmediateContext )
416                                 {
417                                         d3dContext.Flush();
418                                 }
419                         }
420
421                         this.デバイスリソース.SwapChain1.Present(
422                                 ( StrokeStyleT.Config.垂直帰線待ちを行う ) ? 1 : 0,
423                                 SharpDX.DXGI.PresentFlags.None );
424                         //----------------
425                         #endregion
426                         #region " ステージの状態をチェックし、必要あれば遷移またはアプリを終了する。"
427                         //----------------
428                         if( null != this.現在のステージ )
429                         {
430                                 switch( this.現在のステージ.GetType().Name )
431                                 {
432                                         case nameof( ステージ.ステージ ):
433                                                 #region " ビュアーモード → AutoPlayerでログインして曲読込ステージへ。"
434                                                 //----------------
435                                                 if( StrokeStyleT.ビュアーモードである )
436                                                 {
437                                                         FDK.Log.Info( "ビュアーモード: AutoPlayer ユーザでログインします。" );
438                                                         this.ログインする( Properties.Resources.AUTOPLAYER );
439
440                                                         this.曲読込ステージ.読込曲のファイルパスを取得する = () => ( null );  // 今は null 。あとでメッセージキューを見る。
441                                                         this.曲読込ステージ.活性化する( this.デバイスリソース );
442                                                         this.現在のステージ = this.曲読込ステージ;
443                                                 }
444                                                 //----------------
445                                                 #endregion
446                                                 #region " 通常モード → 起動ステージへ。"
447                                                 //----------------
448                                                 else
449                                                 {
450                                                         this.起動ステージ.活性化する( this.デバイスリソース );
451                                                         this.現在のステージ = this.起動ステージ;
452                                                 }
453                                                 //----------------
454                                                 #endregion
455                                                 break;
456
457                                         case nameof( ステージ.起動.起動ステージ ):
458                                                 #region " 終了 → タイトルステージへ。"
459                                                 //---------------
460                                                 if( this.起動ステージ.現在のフェーズ == ステージ.起動.起動ステージ.フェーズ.終了 )
461                                                 {
462                                                         this.現在のステージ.非活性化する( this.デバイスリソース );
463                                                         this.現在のステージ = this.タイトルステージ;
464                                                         this.現在のステージ.活性化する( this.デバイスリソース );
465                                                 }
466                                                 //---------------
467                                                 #endregion
468                                                 break;
469
470                                         case nameof( ステージ.タイトル.タイトルステージ ):
471                                                 #region " 確定 → ログインステージへ。"
472                                                 //---------------
473                                                 if( this.タイトルステージ.現在のフェーズ == ステージ.タイトル.タイトルステージ.フェーズ.確定 )
474                                                 {
475                                                         this.現在のステージ.非活性化する( this.デバイスリソース );
476                                                         this.現在のステージ = this.ログインステージ;
477                                                         this.現在のステージ.活性化する( this.デバイスリソース );
478                                                 }
479                                                 //---------------
480                                                 #endregion
481                                                 #region " キャンセル → アプリを終了する。"
482                                                 //---------------
483                                                 else if( this.タイトルステージ.現在のフェーズ == ステージ.タイトル.タイトルステージ.フェーズ.キャンセル )
484                                                 {
485                                                         this.現在のステージ.非活性化する( this.デバイスリソース );
486                                                         this.現在のステージ = null;
487                                                         this.State = ApplicationState.終了;
488                                                 }
489                                                 //---------------
490                                                 #endregion
491                                                 break;
492
493                                         case nameof( ステージ.ログイン.ログインステージ ):
494                                                 #region " 確定 → ログイン処理を行って、選曲ステージへ。"
495                                                 //---------------
496                                                 if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.確定 )
497                                                 {
498                                                         var user = StrokeStyleT.ユーザ管理.現在選択されているユーザ;
499
500                                                         if( null != user )
501                                                         {
502                                                                 foreach( var path in user.曲の検索元フォルダパスのリスト )
503                                                                         SST.曲.曲ツリー管理.フォルダから曲を再帰的に検索して子ノードリストに追加する( user.曲ツリーのルートノード, path );
504
505                                                                 StrokeStyleT.曲ツリー管理.現在の管理対象ツリー = StrokeStyleT.ユーザ管理.現在選択されているユーザ.曲ツリーのルートノード;
506                                                         }
507
508                                                         this.現在のステージ.非活性化する( this.デバイスリソース );
509                                                         this.現在のステージ = this.選曲ステージ;
510                                                         this.現在のステージ.活性化する( this.デバイスリソース );
511                                                 }
512                                                 //---------------
513                                                 #endregion
514                                                 #region " キャンセル → タイトルステージへ。"
515                                                 //---------------
516                                                 else if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.キャンセル )
517                                                 {
518                                                         this.現在のステージ.非活性化する( this.デバイスリソース );
519                                                         this.現在のステージ = this.タイトルステージ;
520                                                         this.現在のステージ.活性化する( this.デバイスリソース );
521                                                 }
522                                                 //---------------
523                                                 #endregion
524                                                 break;
525
526                                         case nameof( ステージ.選曲.選曲ステージ ):
527                                                 #region " 曲確定 → 曲読込ステージへ。"
528                                                 //---------------
529                                                 if( this.選曲ステージ.現在のフェーズ == ステージ.選曲.選曲ステージ.フェーズ.曲確定 )
530                                                 {
531                                                         // 曲ノードが選択されていることを確認。
532                                                         Trace.Assert( null != StrokeStyleT.曲ツリー管理.現在選択されているノード, "[バグあり] 選択曲が null です。" );
533                                                         this.現在のステージ.非活性化する( this.デバイスリソース );
534                                                         this.現在のステージ = this.曲読込ステージ;
535                                                         this.現在のステージ.活性化する( this.デバイスリソース );
536                                                 }
537                                                 //---------------
538                                                 #endregion
539                                                 #region " キャンセル → アプリを終了する。"
540                                                 //---------------
541                                                 else if( this.選曲ステージ.現在のフェーズ == ステージ.選曲.選曲ステージ.フェーズ.キャンセル )
542                                                 {
543                                                         this.現在のステージ.非活性化する( this.デバイスリソース );
544                                                         this.現在のステージ = null;
545                                                         this.State = ApplicationState.終了;
546                                                 }
547                                                 //---------------
548                                                 #endregion
549                                                 break;
550
551                                         case nameof( ステージ.曲読込.曲読込ステージ ):
552                                                 #region " 終了 → 演奏ステージへ。"
553                                                 //--------------------
554                                                 if( this.曲読込ステージ.現在のフェーズ == ステージ.曲読込.曲読込ステージ.フェーズ.終了 )
555                                                 {
556                                                         this.現在のステージ.非活性化する( this.デバイスリソース );
557                                                         this.現在のステージ = this.演奏ステージ;
558                                                         this.現在のステージ.活性化する( this.デバイスリソース );
559                                                 }
560                                                 //--------------------
561                                                 #endregion
562                                                 break;
563
564                                         case nameof( ステージ.演奏.演奏ステージ ):
565                                                 #region " 演奏終了 → 結果ステージへ。"
566                                                 //--------------------
567                                                 if( this.演奏ステージ.現在のフェーズ.Value == ステージ.演奏.演奏ステージ.フェーズ.クリアor失敗 )
568                                                 {
569                                                         this.現在のステージ.非活性化する( this.デバイスリソース );
570                                                         this.現在のステージ = this.結果ステージ;
571                                                         this.現在のステージ.活性化する( this.デバイスリソース );
572                                                 }
573                                                 //--------------------
574                                                 #endregion
575                                                 #region " キャンセル → 選曲ステージへ。"
576                                                 //--------------------
577                                                 if( this.演奏ステージ.現在のフェーズ.Value == ステージ.演奏.演奏ステージ.フェーズ.キャンセル )
578                                                 {
579                                                         this.現在のステージ.非活性化する( this.デバイスリソース );
580                                                         this.現在のステージ = this.選曲ステージ;
581                                                         this.現在のステージ.活性化する( this.デバイスリソース );
582                                                 }
583                                                 //--------------------
584                                                 #endregion
585                                                 break;
586
587                                         case nameof( ステージ.結果.結果ステージ ):
588                                                 #region " 終了 → 選曲ステージへ。"
589                                                 //--------------------
590                                                 if( this.結果ステージ.現在のフェーズ == ステージ.結果.結果ステージ.フェーズ.終了 )
591                                                 {
592                                                         this.現在のステージ.非活性化する( this.デバイスリソース );
593                                                         this.現在のステージ = this.選曲ステージ;
594                                                         this.現在のステージ.活性化する( this.デバイスリソース );
595                                                 }
596                                                 //--------------------
597                                                 #endregion
598                                                 break;
599                                 }
600                         }
601                         //----------------
602                         #endregion
603                 }
604                 protected void デバイス依存リソースを解放する()
605                 {
606                         FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
607                         Debug.Assert( null != this.デバイスリソース );  // 解放前であること。
608
609                         this.現在のステージ?.デバイス依存リソースを解放する( this.デバイスリソース );
610
611                         FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
612                 }
613                 protected void デバイス依存リソースを再構築する()
614                 {
615                         FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
616                         Debug.Assert( null != this.デバイスリソース );  // 再生成済みであること。
617
618                         this.現在のステージ?.デバイス依存リソースを作成する( this.デバイスリソース );
619
620                         FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
621                 }
622
623                 private void フォームサイズが変更された( object sender, EventArgs e )
624                 {
625                         FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
626                         FDK.Log.Info( $"新しいクライアントサイズ = {this.MainForm.ClientSize}" );
627
628                         #region " 実行条件チェック。"
629                         //----------------
630                         if( null == this.デバイスリソース )
631                         {
632                                 FDK.Log.Info( " まだ初期化されてないので、何もしません。" );
633                                 FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
634                                 return;
635                         }
636                         if( this.MainForm.WindowState == FormWindowState.Minimized )
637                         {
638                                 FDK.Log.Info( "最小化されました。" );
639                                 FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
640                                 return; // 何もしない
641                         }
642                         if( this.State != ApplicationState.進行描画 )
643                         {
644                                 FDK.Log.Info( " アプリケーションの状態が進行描画じゃないので、何もしません。" );
645                                 FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
646                                 return;
647                         }
648                         //----------------
649                         #endregion
650
651                         Debug.Assert( null != this.デバイスリソース, "デバイスリソースが作成済みであること。" );
652
653                         // 現在の画面モードを取得しておく。(Alt+TABなど、勝手に全画面を解除されることもあるので。)
654                         SharpDX.Mathematics.Interop.RawBool fullscreen;
655                         SharpDX.DXGI.Output outputTarget;
656                         this.デバイスリソース.SwapChain1.GetFullscreenState( out fullscreen, out outputTarget );
657                         this.MainForm.IsFullscreen = fullscreen;
658                         outputTarget?.Dispose();
659                         FDK.Log.Info( $"現在、全画面モードである = {this.MainForm.IsFullscreen}" );
660
661                         // (1) リソースを解放して、
662                         this.デバイス依存リソースを解放する();
663                         this.デバイスリソース.サイズに依存するリソースを解放する();
664
665                         // (2) 物理画面サイズを変更して、
666                         this.デバイスリソース.物理画面サイズpx = new SharpDX.Size2F( this.MainForm.ClientSize.Width, this.MainForm.ClientSize.Height );
667
668                         // (3) リソースを再構築する。
669                         this.デバイスリソース.サイズに依存するリソースを作成する();
670                         this.デバイス依存リソースを再構築する();
671
672                         FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
673                 }
674                 private void 全画面モードとウィンドウモードを切り替える()
675                 {
676                         FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
677
678                         this.MainForm.IsFullscreen = !this.MainForm.IsFullscreen;   // 切り替え
679                         this.デバイスリソース.SwapChain1.SetFullscreenState( this.MainForm.IsFullscreen, null );
680
681                         FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
682                 }
683                 private void ログインする( string ユーザ名 )
684                 {
685                         StrokeStyleT.ユーザ管理.ユーザを選択する( ユーザ名 );
686                         FDK.Log.Info( $"ユーザが選択されました。[{StrokeStyleT.ユーザ管理.現在選択されているユーザ.名前}]" );
687                 }
688
689                 #region " バックストア。"
690                 //----------------
691                 private static SST.フォルダ bs_フォルダ = null;
692                 private static FDK.入力.Keyboard bs_キーボード入力 = null;
693                 private static FDK.入力.MidiIn bs_MIDI入力 = null;
694                 private static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice bs_Wasapiデバイス = null;
695                 private static readonly System.Random bs_乱数 = new Random( DateTime.Now.Millisecond );
696                 private static SST.ユーザ.ユーザ管理 bs_ユーザ管理 = null;
697                 private static SST.曲.曲ツリー管理 bs_曲ツリー管理 = null;
698                 private static SST.設定.Config bs_Config = null;
699                 //----------------
700                 #endregion
701         }
702 }