OSDN Git Service

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