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 bool 垂直帰線待ちを行う { get; set; } = true;
45 public override void 初期化する()
47 Debug.Assert( null == this.デバイスリソース ); // 作成される前である。
48 FDK.Log.現在のスレッドに名前をつける( "GUI" );
50 this.Text = $"StrokeStyle<T> {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()}";
51 this.ClientSize = new System.Drawing.Size( 1920, 1080 ); // 物理画面サイズpx
52 this.設計画面サイズdpx = new SharpDX.Size2F( 1920, 1080 ); // 設計画面サイズdpx
54 #region " System.Stopwatch が高解像度タイマを使わないならエラー。"
56 if( false == System.Diagnostics.Stopwatch.IsHighResolution )
57 throw new SSTException( "このシステムは、高解像度タイマをサポートしていません。" );
60 #region " MediaFoundation を起動する。"
62 SharpDX.MediaFoundation.MediaManager.Startup();
65 #region " Sleep 精度を上げる。"
67 StrokeStyleT.timeBeginPeriod( 1 );
73 FDK.Log.Info( "ユーザ情報を初期化します。" );
74 StrokeStyleT.ユーザ管理.UsersXmlを読み込む();
77 foreach( var ユーザ in StrokeStyleT.ユーザ管理.ユーザリスト )
78 ユーザ.SourcesXmlを読み込む();
81 #region " WASAPI デバイスを初期化する。"
83 StrokeStyleT.bs_Wasapiデバイス = new FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice();
84 StrokeStyleT.bs_Wasapiデバイス.初期化する( 15.0f );
87 #region " キーボード入力 を初期化する。"
89 FDK.Log.Info( "キーボード入力デバイスを初期化します。" );
90 StrokeStyleT.bs_キーボード入力 = new FDK.入力.Keyboard( this.Handle );
93 #region " MIDI入力 を初期化する。"
95 FDK.Log.Info( "MIDI入力デバイスを初期化します。" );
96 StrokeStyleT.bs_MIDI入力 = new FDK.入力.MidiIn();
100 this.現在のステージ = this.最初のダミーステージ;
103 this.KeyDown += ( target, arg ) => {
104 // Alt+Enter → 画面モードの切り替え
105 if( ( arg.KeyCode == System.Windows.Forms.Keys.Return ) && ( arg.Modifiers == Keys.Alt ) )
106 this.全画面モードとウィンドウモードを切り替える();
109 public override void 終了する()
111 Debug.Assert( null == this.デバイスリソース ); // 解放された後である。
113 #region " ステージを終了し、解放する。"
115 //if( this.現在のステージ.活性化している )
116 // this.現在のステージ.非活性化する( this.デバイスリソース ); → デバイスリソース解放後なので、ここで非活性化してはならない。
117 this.最初のダミーステージ = null;
119 this.タイトルステージ = null;
120 this.ログインステージ = null;
127 #region " MIDI入力 を解放する。"
129 FDK.Log.Info( "MIDI入力デバイスを解放します。" );
130 FDK.Utilities.解放する( ref StrokeStyleT.bs_MIDI入力 );
133 #region " キーボード入力 を解放する。"
135 FDK.Log.Info( "キーボード入力デバイスを解放します。" );
136 FDK.Utilities.解放する( ref StrokeStyleT.bs_キーボード入力 );
139 #region " WASAPIデバイスを解放する。"
141 FDK.Utilities.解放する( ref StrokeStyleT.bs_Wasapiデバイス );
144 #region " MediaFoundation を終了する。"
146 SharpDX.MediaFoundation.MediaManager.Shutdown();
150 public override void シーンを描画する()
154 var d3dDevice = (SharpDX.Direct3D11.Device) null;
155 using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.デバイスリソース.DXGIDeviceManager, out d3dDevice ) )
157 using( var d3dContext = d3dDevice.ImmediateContext )
159 // 既定のD3Dレンダーターゲットビューを黒でクリアする。
160 d3dContext.ClearRenderTargetView(
161 this.デバイスリソース.D3DRenderTargetView, SharpDX.Color4.Black );
163 // 深度バッファを 1.0f でクリアする。
164 d3dContext.ClearDepthStencilView(
165 this.デバイスリソース.D3DDepthStencilView,
166 SharpDX.Direct3D11.DepthStencilClearFlags.Depth,
174 this.現在のステージ?.進行描画する( this.デバイスリソース );
177 this.デバイスリソース.SwapChain.Present(
178 (this.垂直帰線待ちを行う) ? 1 : 0,
179 SharpDX.DXGI.PresentFlags.None );
181 if( null != this.現在のステージ )
183 // ステージの状態チェックを行い、必要あれば遷移、またはアプリを終了する。
184 switch( this.現在のステージ.GetType().Name )
186 case nameof( ステージ.ステージ ):
187 #region " 最初のダミーステージ "
190 this.起動ステージ.活性化する( this.デバイスリソース );
191 this.現在のステージ = this.起動ステージ;
196 case nameof( ステージ.起動.起動ステージ ):
197 #region " 終了 → タイトルステージへ。"
199 if( this.起動ステージ.現在のフェーズ == ステージ.起動.起動ステージ.フェーズ.終了 )
201 this.現在のステージ.非活性化する( this.デバイスリソース );
202 this.現在のステージ = this.タイトルステージ;
203 this.現在のステージ.活性化する( this.デバイスリソース );
209 case nameof( ステージ.タイトル.タイトルステージ ):
210 #region " 確定 → ログインステージへ。"
212 if( this.タイトルステージ.現在のフェーズ == ステージ.タイトル.タイトルステージ.フェーズ.確定 )
214 this.現在のステージ.非活性化する( this.デバイスリソース );
215 this.現在のステージ = this.ログインステージ;
216 this.現在のステージ.活性化する( this.デバイスリソース );
220 #region " キャンセル → アプリを終了する。"
222 else if( this.タイトルステージ.現在のフェーズ == ステージ.タイトル.タイトルステージ.フェーズ.キャンセル )
224 this.現在のステージ.非活性化する( this.デバイスリソース );
226 this.アプリを終了せよ = true;
232 case nameof( ステージ.ログイン.ログインステージ ):
233 #region " 確定 → ログイン処理を行って、選曲ステージへ。"
235 if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.確定 )
237 // ログイン処理(1) ユーザリストに対してユーザを選択する。
238 StrokeStyleT.ユーザ管理.ユーザを選択する( this.ログインステージ.ユーザインデックス );
239 FDK.Log.Info( $"ユーザが選択されました。[{StrokeStyleT.ユーザ管理.現在選択されているユーザ.名前}]" );
241 // ログイン処理(2) 選択ユーザの曲ツリーを構築する。
242 StrokeStyleT.ユーザ管理.現在選択されているユーザ.曲を検索して曲ツリーを構築する();
244 // ログイン処理(3) 構築した曲ツリーを曲リスト管理に登録する。
245 StrokeStyleT.曲ツリー管理.現在の管理対象ツリー = StrokeStyleT.ユーザ管理.現在選択されているユーザ.曲ツリーのルートノード;
248 this.現在のステージ.非活性化する( this.デバイスリソース );
249 this.現在のステージ = this.選曲ステージ;
250 this.現在のステージ.活性化する( this.デバイスリソース );
254 #region " キャンセル → タイトルステージへ。"
256 else if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.キャンセル )
258 this.現在のステージ.非活性化する( this.デバイスリソース );
259 this.現在のステージ = this.タイトルステージ;
260 this.現在のステージ.活性化する( this.デバイスリソース );
266 case nameof( ステージ.選曲.選曲ステージ ):
267 #region " 曲確定 → 曲読込ステージへ。"
269 if( this.選曲ステージ.現在のフェーズ == ステージ.選曲.選曲ステージ.フェーズ.曲確定 )
271 // 曲ノードが選択されていることを確認。
272 Trace.Assert( null != StrokeStyleT.曲ツリー管理.現在選択されているノード, "[バグあり] 選択曲が null です。" );
273 this.現在のステージ.非活性化する( this.デバイスリソース );
274 this.現在のステージ = this.曲読込ステージ;
275 this.現在のステージ.活性化する( this.デバイスリソース );
279 #region " キャンセル → アプリを終了する。"
281 else if( this.選曲ステージ.現在のフェーズ == ステージ.選曲.選曲ステージ.フェーズ.キャンセル )
283 this.現在のステージ.非活性化する( this.デバイスリソース );
285 this.アプリを終了せよ = true;
291 case nameof( ステージ.曲読込.曲読込ステージ ):
292 #region " 終了 → 演奏ステージへ。"
293 //--------------------
294 if( this.曲読込ステージ.現在のフェーズ == ステージ.曲読込.曲読込ステージ.フェーズ.終了 )
296 // 演奏スコアインスタンスが作成されていることを確認。
297 Debug.Assert( null != StrokeStyleT.演奏スコア );
299 this.現在のステージ.非活性化する( this.デバイスリソース );
300 this.現在のステージ = this.演奏ステージ;
301 this.現在のステージ.活性化する( this.デバイスリソース );
303 //--------------------
307 case nameof( ステージ.演奏.演奏ステージ ):
308 #region " 演奏終了 → 結果ステージへ。"
309 //--------------------
310 if( this.演奏ステージ.現在のフェーズ == ステージ.演奏.演奏ステージ.フェーズ.クリアor失敗 )
312 this.現在のステージ.非活性化する( this.デバイスリソース );
313 this.現在のステージ = this.結果ステージ;
314 this.現在のステージ.活性化する( this.デバイスリソース );
316 //--------------------
318 #region " キャンセル → 選曲ステージへ。"
319 //--------------------
320 if( this.演奏ステージ.現在のフェーズ == ステージ.演奏.演奏ステージ.フェーズ.キャンセル )
322 this.現在のステージ.非活性化する( this.デバイスリソース );
323 this.現在のステージ = this.選曲ステージ;
324 this.現在のステージ.活性化する( this.デバイスリソース );
326 //--------------------
330 case nameof( ステージ.結果.結果ステージ ):
331 #region " 終了 → 選曲ステージへ。"
332 //--------------------
333 if( this.結果ステージ.現在のフェーズ == ステージ.結果.結果ステージ.フェーズ.終了 )
335 this.現在のステージ.非活性化する( this.デバイスリソース );
336 this.現在のステージ = this.選曲ステージ;
337 this.現在のステージ.活性化する( this.デバイスリソース );
339 //--------------------
345 protected override void OnClosing( CancelEventArgs e )
347 if( ( null != this.現在のステージ ) && ( this.現在のステージ.活性化している ) )
348 this.現在のステージ.非活性化する( this.デバイスリソース );
352 protected override void OnSizeChanged( EventArgs e )
354 // すべてのサイズ依存リソースを解放する。
355 this.現在のステージ?.デバイス依存リソースを解放する( this.デバイスリソース );
358 base.OnSizeChanged( e );
360 // すべてのサイズ依存リソースを作成し直す。
361 this.現在のステージ?.デバイス依存リソースを作成する( this.デバイスリソース );
365 protected SST.ステージ.ステージ 最初のダミーステージ = new ステージ.ステージ();
366 protected SST.ステージ.起動.起動ステージ 起動ステージ = new ステージ.起動.起動ステージ();
367 protected SST.ステージ.タイトル.タイトルステージ タイトルステージ = new ステージ.タイトル.タイトルステージ();
368 protected SST.ステージ.ログイン.ログインステージ ログインステージ = new ステージ.ログイン.ログインステージ();
369 protected SST.ステージ.選曲.選曲ステージ 選曲ステージ = new ステージ.選曲.選曲ステージ();
370 protected SST.ステージ.曲読込.曲読込ステージ 曲読込ステージ = new ステージ.曲読込.曲読込ステージ();
371 protected SST.ステージ.演奏.演奏ステージ 演奏ステージ = new ステージ.演奏.演奏ステージ();
372 protected SST.ステージ.結果.結果ステージ 結果ステージ = new ステージ.結果.結果ステージ();
374 private SST.ステージ.ステージ 現在のステージ = null;
378 private static SST.フォルダ bs_フォルダ = null;
379 private static FDK.入力.Keyboard bs_キーボード入力 = null;
380 private static FDK.入力.MidiIn bs_MIDI入力 = null;
381 private static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice bs_Wasapiデバイス = null;
382 private static readonly Random bs_乱数 = new Random( DateTime.Now.Millisecond );
383 private static SST.ユーザ.ユーザ管理 bs_ユーザ管理 = null;
384 private static SST.曲.曲ツリー管理 bs_曲ツリー管理 = null;
388 #region " Win32 API "
390 [System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeBeginPeriod" )]
391 private static extern uint timeBeginPeriod( uint uMilliseconds );
393 [System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeEndPeriod" )]
394 private static extern uint timeEndPeriod( uint uMilliseconds );