2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Diagnostics;
6 using System.Windows.Forms;
10 class StrokeStyleT : FDK.ApplicationFormBase
13 public static SST.フォルダ フォルダ => StrokeStyleT.bs_フォルダ;
14 public static FDK.入力.Keyboard キーボード入力 => StrokeStyleT.bs_キーボード入力;
15 public static FDK.入力.MidiIn MIDI入力 => StrokeStyleT.bs_MIDI入力;
16 public static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice Wasapiデバイス => StrokeStyleT.bs_Wasapiデバイス;
17 public static Random 乱数 => StrokeStyleT.bs_乱数;
18 public static SST.ユーザ.ユーザ管理 ユーザ管理 => StrokeStyleT.bs_ユーザ管理;
19 public static SST.曲.曲ツリー管理 曲ツリー管理 => StrokeStyleT.bs_曲ツリー管理;
20 public static SSTFormat.スコア 演奏スコア { get; set; } = null;
22 public static void すべての入力デバイスをポーリングする()
24 // hack: 追加の入力デバイスができたら、ここにポーリングコードを追加すること。
25 StrokeStyleT.キーボード入力?.ポーリングする();
26 StrokeStyleT.MIDI入力?.ポーリングする();
29 // get only static property の初期化。
32 // フォルダ変数を真っ先に登録する。(ほかのメンバのコンストラクタでフォルダ変数を利用できるようにするため。)
33 StrokeStyleT.bs_フォルダ = new SST.フォルダ();
34 SST.フォルダ.フォルダ変数を追加する( "Static", StrokeStyleT.フォルダ.StaticFolder );
35 SST.フォルダ.フォルダ変数を追加する( "AppData", StrokeStyleT.フォルダ.AppDataFolder );
36 SST.フォルダ.フォルダ変数を追加する( "User", null );
39 StrokeStyleT.bs_ユーザ管理 = new ユーザ.ユーザ管理();
40 StrokeStyleT.bs_曲ツリー管理 = new 曲.曲ツリー管理();
43 public override void 初期化する()
45 Debug.Assert( null == this.デバイスリソース ); // 作成される前である。
46 FDK.Log.現在のスレッドに名前をつける( "GUI" );
48 this.Text = $"StrokeStyle<T> {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()}";
49 this.ClientSize = new System.Drawing.Size( 1920, 1080 ); // 物理画面サイズpx
50 this.設計画面サイズdpx = new SharpDX.Size2F( 1920, 1080 ); // 設計画面サイズdpx
52 #region " System.Stopwatch が高解像度タイマを使わないならエラー。"
54 if( false == System.Diagnostics.Stopwatch.IsHighResolution )
55 throw new SSTException( "このシステムは、高解像度タイマをサポートしていません。" );
58 #region " MediaFoundation を起動する。"
60 SharpDX.MediaFoundation.MediaManager.Startup();
63 #region " Sleep 精度を上げる。"
65 StrokeStyleT.timeBeginPeriod( 1 );
71 FDK.Log.Info( "ユーザ情報を初期化します。" );
72 StrokeStyleT.ユーザ管理.UsersXmlを読み込む();
75 foreach( var ユーザ in StrokeStyleT.ユーザ管理.ユーザリスト )
76 ユーザ.SourcesXmlを読み込む();
79 #region " WASAPI デバイスを初期化する。"
81 StrokeStyleT.bs_Wasapiデバイス = new FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice();
82 StrokeStyleT.bs_Wasapiデバイス.初期化する( 7.0f );
85 #region " キーボード入力 を初期化する。"
87 FDK.Log.Info( "キーボード入力デバイスを初期化します。" );
88 StrokeStyleT.bs_キーボード入力 = new FDK.入力.Keyboard( this.Handle );
91 #region " MIDI入力 を初期化する。"
93 FDK.Log.Info( "MIDI入力デバイスを初期化します。" );
94 StrokeStyleT.bs_MIDI入力 = new FDK.入力.MidiIn();
98 this.現在のステージ = this.最初のダミーステージ;
100 public override void 終了する()
102 Debug.Assert( null == this.デバイスリソース ); // 解放された後である。
104 #region " ステージを終了し、解放する。"
106 //if( this.現在のステージ.活性化している )
107 // this.現在のステージ.非活性化する( this.デバイスリソース ); → デバイスリソース解放後なので、ここで非活性化してはならない。
108 this.最初のダミーステージ = null;
110 this.タイトルステージ = null;
111 this.ログインステージ = null;
118 #region " MIDI入力 を解放する。"
120 FDK.Log.Info( "MIDI入力デバイスを解放します。" );
121 FDK.Utilities.解放する( ref StrokeStyleT.bs_MIDI入力 );
124 #region " キーボード入力 を解放する。"
126 FDK.Log.Info( "キーボード入力デバイスを解放します。" );
127 FDK.Utilities.解放する( ref StrokeStyleT.bs_キーボード入力 );
130 #region " WASAPIデバイスを解放する。"
132 FDK.Utilities.解放する( ref StrokeStyleT.bs_Wasapiデバイス );
135 #region " MediaFoundation を終了する。"
137 SharpDX.MediaFoundation.MediaManager.Shutdown();
141 public override void シーンを描画する()
145 var d3dDevice = (SharpDX.Direct3D11.Device) null;
146 using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.デバイスリソース.DXGIDeviceManager, out d3dDevice ) )
148 using( var d3dContext = d3dDevice.ImmediateContext )
150 // 既定のD3Dレンダーターゲットビューを黒でクリアする。
151 d3dContext.ClearRenderTargetView(
152 this.デバイスリソース.D3DRenderTargetView, SharpDX.Color4.Black );
154 // 深度バッファを 1.0f でクリアする。
155 d3dContext.ClearDepthStencilView(
156 this.デバイスリソース.D3DDepthStencilView,
157 SharpDX.Direct3D11.DepthStencilClearFlags.Depth,
165 this.現在のステージ?.進行描画する( this.デバイスリソース );
168 this.デバイスリソース.SwapChain.Present( 1, SharpDX.DXGI.PresentFlags.None );
170 if( null != this.現在のステージ )
172 // ステージの状態チェックを行い、必要あれば遷移、またはアプリを終了する。
173 switch( this.現在のステージ.GetType().Name )
175 case nameof( ステージ.ステージ ):
176 #region " 最初のダミーステージ "
179 this.起動ステージ.活性化する( this.デバイスリソース );
180 this.現在のステージ = this.起動ステージ;
185 case nameof( ステージ.起動.起動ステージ ):
186 #region " 終了 → タイトルステージへ。"
188 if( this.起動ステージ.現在のフェーズ == ステージ.起動.起動ステージ.フェーズ.終了 )
190 this.現在のステージ.非活性化する( this.デバイスリソース );
191 this.現在のステージ = this.タイトルステージ;
192 this.現在のステージ.活性化する( this.デバイスリソース );
198 case nameof( ステージ.タイトル.タイトルステージ ):
199 #region " 確定 → ログインステージへ。"
201 if( this.タイトルステージ.現在のフェーズ == ステージ.タイトル.タイトルステージ.フェーズ.確定 )
203 this.現在のステージ.非活性化する( this.デバイスリソース );
204 this.現在のステージ = this.ログインステージ;
205 this.現在のステージ.活性化する( this.デバイスリソース );
209 #region " キャンセル → アプリを終了する。"
211 else if( this.タイトルステージ.現在のフェーズ == ステージ.タイトル.タイトルステージ.フェーズ.キャンセル )
213 this.現在のステージ.非活性化する( this.デバイスリソース );
215 this.アプリを終了せよ = true;
221 case nameof( ステージ.ログイン.ログインステージ ):
222 #region " 確定 → ログイン処理を行って、選曲ステージへ。"
224 if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.確定 )
226 // ログイン処理(1) ユーザリストに対してユーザを選択する。
227 StrokeStyleT.ユーザ管理.ユーザを選択する( this.ログインステージ.ユーザインデックス );
228 FDK.Log.Info( $"ユーザが選択されました。[{StrokeStyleT.ユーザ管理.現在選択されているユーザ.名前}]" );
230 // ログイン処理(2) 選択ユーザの曲ツリーを構築する。
231 StrokeStyleT.ユーザ管理.現在選択されているユーザ.曲を検索して曲ツリーを構築する();
233 // ログイン処理(3) 構築した曲ツリーを曲リスト管理に登録する。
234 StrokeStyleT.曲ツリー管理.現在の管理対象ツリー = StrokeStyleT.ユーザ管理.現在選択されているユーザ.曲ツリーのルートノード;
237 this.現在のステージ.非活性化する( this.デバイスリソース );
238 this.現在のステージ = this.選曲ステージ;
239 this.現在のステージ.活性化する( this.デバイスリソース );
243 #region " キャンセル → タイトルステージへ。"
245 else if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.キャンセル )
247 this.現在のステージ.非活性化する( this.デバイスリソース );
248 this.現在のステージ = this.タイトルステージ;
249 this.現在のステージ.活性化する( this.デバイスリソース );
255 case nameof( ステージ.選曲.選曲ステージ ):
256 #region " 曲確定 → 曲読込ステージへ。"
258 if( this.選曲ステージ.現在のフェーズ == ステージ.選曲.選曲ステージ.フェーズ.曲確定 )
260 // 曲ノードが選択されていることを確認。
261 Trace.Assert( null != StrokeStyleT.曲ツリー管理.現在選択されているノード, "[バグあり] 選択曲が null です。" );
262 this.現在のステージ.非活性化する( this.デバイスリソース );
263 this.現在のステージ = this.曲読込ステージ;
264 this.現在のステージ.活性化する( this.デバイスリソース );
268 #region " キャンセル → アプリを終了する。"
270 else if( this.選曲ステージ.現在のフェーズ == ステージ.選曲.選曲ステージ.フェーズ.キャンセル )
272 this.現在のステージ.非活性化する( this.デバイスリソース );
274 this.アプリを終了せよ = true;
280 case nameof( ステージ.曲読込.曲読込ステージ ):
281 #region " 終了 → 演奏ステージへ。"
282 //--------------------
283 if( this.曲読込ステージ.現在のフェーズ == ステージ.曲読込.曲読込ステージ.フェーズ.終了 )
285 // 演奏スコアインスタンスが作成されていることを確認。
286 Debug.Assert( null != StrokeStyleT.演奏スコア );
288 this.現在のステージ.非活性化する( this.デバイスリソース );
289 this.現在のステージ = this.演奏ステージ;
290 this.現在のステージ.活性化する( this.デバイスリソース );
292 //--------------------
296 case nameof( ステージ.演奏.演奏ステージ ):
297 #region " 演奏終了 → 結果ステージへ。"
298 //--------------------
299 if( this.演奏ステージ.現在のフェーズ == ステージ.演奏.演奏ステージ.フェーズ.クリアor失敗 )
301 this.現在のステージ.非活性化する( this.デバイスリソース );
302 this.現在のステージ = this.結果ステージ;
303 this.現在のステージ.活性化する( this.デバイスリソース );
305 //--------------------
307 #region " キャンセル → 選曲ステージへ。"
308 //--------------------
309 if( this.演奏ステージ.現在のフェーズ == ステージ.演奏.演奏ステージ.フェーズ.キャンセル )
311 this.現在のステージ.非活性化する( this.デバイスリソース );
312 this.現在のステージ = this.選曲ステージ;
313 this.現在のステージ.活性化する( this.デバイスリソース );
315 //--------------------
319 case nameof( ステージ.結果.結果ステージ ):
320 #region " 終了 → 選曲ステージへ。"
321 //--------------------
322 if( this.結果ステージ.現在のフェーズ == ステージ.結果.結果ステージ.フェーズ.終了 )
324 this.現在のステージ.非活性化する( this.デバイスリソース );
325 this.現在のステージ = this.選曲ステージ;
326 this.現在のステージ.活性化する( this.デバイスリソース );
328 //--------------------
334 protected override void OnClosing( CancelEventArgs e )
336 if( ( null != this.現在のステージ ) && ( this.現在のステージ.活性化している ) )
337 this.現在のステージ.非活性化する( this.デバイスリソース );
341 protected override void OnSizeChanged( EventArgs e )
343 // すべてのサイズ依存リソースを解放する。
344 this.現在のステージ?.非活性化する( this.デバイスリソース );
347 base.OnSizeChanged( e );
349 // すべてのサイズ依存リソースを作成し直す。
350 this.現在のステージ?.活性化する( this.デバイスリソース );
354 protected SST.ステージ.ステージ 最初のダミーステージ = new ステージ.ステージ();
355 protected SST.ステージ.起動.起動ステージ 起動ステージ = new ステージ.起動.起動ステージ();
356 protected SST.ステージ.タイトル.タイトルステージ タイトルステージ = new ステージ.タイトル.タイトルステージ();
357 protected SST.ステージ.ログイン.ログインステージ ログインステージ = new ステージ.ログイン.ログインステージ();
358 protected SST.ステージ.選曲.選曲ステージ 選曲ステージ = new ステージ.選曲.選曲ステージ();
359 protected SST.ステージ.曲読込.曲読込ステージ 曲読込ステージ = new ステージ.曲読込.曲読込ステージ();
360 protected SST.ステージ.演奏.演奏ステージ 演奏ステージ = new ステージ.演奏.演奏ステージ();
361 protected SST.ステージ.結果.結果ステージ 結果ステージ = new ステージ.結果.結果ステージ();
363 private SST.ステージ.ステージ 現在のステージ = null;
367 private static SST.フォルダ bs_フォルダ = null;
368 private static FDK.入力.Keyboard bs_キーボード入力 = null;
369 private static FDK.入力.MidiIn bs_MIDI入力 = null;
370 private static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice bs_Wasapiデバイス = null;
371 private static readonly Random bs_乱数 = new Random( DateTime.Now.Millisecond );
372 private static SST.ユーザ.ユーザ管理 bs_ユーザ管理 = null;
373 private static SST.曲.曲ツリー管理 bs_曲ツリー管理 = null;
377 #region " Win32 API "
379 [System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeBeginPeriod" )]
380 private static extern uint timeBeginPeriod( uint uMilliseconds );
382 [System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeEndPeriod" )]
383 private static extern uint timeEndPeriod( uint uMilliseconds );