2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Diagnostics;
6 using System.Windows.Forms;
10 class StrokeStyleT : FDK.ApplicationBase
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;
21 public static SST.設定.Config Config => StrokeStyleT.bs_Config;
23 public static void すべての入力デバイスをポーリングする()
25 // hack: 追加の入力デバイスができたら、ここにポーリングコードを追加すること。
26 StrokeStyleT.キーボード入力?.ポーリングする();
27 StrokeStyleT.MIDI入力?.ポーリングする();
30 // get only static property の初期化。
33 // フォルダ変数を真っ先に登録する。(ほかのメンバのコンストラクタでフォルダ変数を利用できるようにするため。)
34 StrokeStyleT.bs_フォルダ = new SST.フォルダ();
35 SST.フォルダ.フォルダ変数を追加する( "Static", StrokeStyleT.フォルダ.StaticFolder );
36 SST.フォルダ.フォルダ変数を追加する( "AppData", StrokeStyleT.フォルダ.AppDataFolder );
37 SST.フォルダ.フォルダ変数を追加する( "User", null );
40 StrokeStyleT.bs_ユーザ管理 = new ユーザ.ユーザ管理();
41 StrokeStyleT.bs_曲ツリー管理 = new 曲.曲ツリー管理();
44 protected override void 初期化する()
46 FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
48 Debug.Assert( null == this.スレッド排他領域.デバイスリソース, "デバイスリソースの作成前であること。" );
50 this.Window.Text = $"StrokeStyle<T> {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()}";
51 this.設計画面サイズdpx = new SharpDX.Size2F( 1920, 1080 ); // 設計画面サイズdpx
53 #region " コンフィグ を初期化する。"
55 FDK.Log.Info( "コンフィグを初期化します。" );
56 StrokeStyleT.bs_Config = new 設定.Config();
57 StrokeStyleT.bs_Config.ConfigXmlを読み込む();
61 this.Window.ClientSize = new System.Drawing.Size( StrokeStyleT.Config.物理画面サイズpx.Width, StrokeStyleT.Config.物理画面サイズpx.Height );
63 #region " System.Stopwatch が高解像度タイマを使わないならエラー。"
65 if( false == System.Diagnostics.Stopwatch.IsHighResolution )
66 throw new SSTException( "このシステムは、高解像度タイマをサポートしていません。" );
69 #region " MediaFoundation を起動する。"
71 SharpDX.MediaFoundation.MediaManager.Startup();
74 #region " Sleep 精度を上げる。"
76 StrokeStyleT.timeBeginPeriod( 1 );
82 FDK.Log.Info( "ユーザ情報を初期化します。" );
83 StrokeStyleT.ユーザ管理.UsersXmlを読み込む();
86 foreach( var ユーザ in StrokeStyleT.ユーザ管理.ユーザリスト )
87 ユーザ.SourcesXmlを読み込む();
90 #region " WASAPI デバイスを初期化する。"
92 StrokeStyleT.bs_Wasapiデバイス = new FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice();
93 StrokeStyleT.bs_Wasapiデバイス.初期化する( 15.0f );
96 #region " キーボード入力 を初期化する。"
98 FDK.Log.Info( "キーボード入力デバイスを初期化します。" );
99 StrokeStyleT.bs_キーボード入力 = new FDK.入力.Keyboard( this.Window.Handle );
102 #region " MIDI入力 を初期化する。"
104 FDK.Log.Info( "MIDI入力デバイスを初期化します。" );
105 StrokeStyleT.bs_MIDI入力 = new FDK.入力.MidiIn();
109 this.現在のステージ = this.最初のダミーステージ;
111 //#warning 全画面モード切替えを KeyDown で仮実装。
112 this.Window.KeyDown += ( target, arg ) => {
113 // Alt+Enter → 画面モードの切り替え
114 // if( ( arg.KeyCode == System.Windows.Forms.Keys.Return ) && ( arg.Modifiers == Keys.Alt ) )
115 // this.全画面モードとウィンドウモードを切り替える();
118 FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
120 protected override void 終了する()
122 FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
124 Debug.Assert( null != this.スレッド排他領域.デバイスリソース, "デバイスリソースが解放される前であること。" );
126 #region " ステージを終了し、解放する。"
128 if( ( null != this.現在のステージ ) && ( this.現在のステージ.活性化している ) )
129 this.現在のステージ.非活性化する( this.スレッド排他領域.デバイスリソース );
131 this.最初のダミーステージ = null;
133 this.タイトルステージ = null;
134 this.ログインステージ = null;
141 #region " MIDI入力 を解放する。"
143 FDK.Log.Info( "MIDI入力デバイスを解放します。" );
144 FDK.Utilities.解放する( ref StrokeStyleT.bs_MIDI入力 );
147 #region " キーボード入力 を解放する。"
149 FDK.Log.Info( "キーボード入力デバイスを解放します。" );
150 FDK.Utilities.解放する( ref StrokeStyleT.bs_キーボード入力 );
153 #region " WASAPIデバイスを解放する。"
155 FDK.Utilities.解放する( ref StrokeStyleT.bs_Wasapiデバイス );
158 #region " コンフィグを解放する。"
160 StrokeStyleT.bs_Config = null;
163 #region " MediaFoundation を終了する。"
165 SharpDX.MediaFoundation.MediaManager.Shutdown();
169 FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
171 protected override void シーンを描画する()
173 // このメソッドは、GUIスレッドではなく進行描画スレッドから呼び出されるので注意。
175 this.スレッド排他領域.WriteLock( () => {
179 var dr = this.スレッド排他領域.デバイスリソース;
180 var d3dDevice = (SharpDX.Direct3D11.Device) null;
181 using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( dr.DXGIDeviceManager, out d3dDevice ) )
183 using( var d3dContext = d3dDevice.ImmediateContext )
185 // 既定のD3Dレンダーターゲットビューを黒でクリアする。
186 d3dContext.ClearRenderTargetView( dr.D3DRenderTargetView, SharpDX.Color4.Black );
188 // 深度バッファを 1.0f でクリアする。
189 d3dContext.ClearDepthStencilView(
190 dr.D3DDepthStencilView,
191 SharpDX.Direct3D11.DepthStencilClearFlags.Depth,
199 this.現在のステージ?.進行描画する( this.スレッド排他領域.デバイスリソース );
203 // 表示する。垂直帰線待ちなどで時間がかかるのでロックしないこと。
204 if( false == this.スレッド排他領域.アプリを終了せよ )
206 this.スレッド排他領域.デバイスリソース.SwapChain.Present(
207 ( StrokeStyleT.Config.垂直帰線待ちを行う ) ? 1 : 0,
208 SharpDX.DXGI.PresentFlags.None );
211 this.スレッド排他領域.WriteLock( () => {
213 if( null != this.現在のステージ )
215 // ステージの状態チェックを行い、必要あれば遷移、またはアプリを終了する。
216 switch( this.現在のステージ.GetType().Name )
218 case nameof( ステージ.ステージ ):
219 #region " 最初のダミーステージ "
222 this.起動ステージ.活性化する( this.スレッド排他領域.デバイスリソース );
223 this.現在のステージ = this.起動ステージ;
228 case nameof( ステージ.起動.起動ステージ ):
229 #region " 終了 → タイトルステージへ。"
231 if( this.起動ステージ.現在のフェーズ == ステージ.起動.起動ステージ.フェーズ.終了 )
233 this.現在のステージ.非活性化する( this.スレッド排他領域.デバイスリソース );
234 this.現在のステージ = this.タイトルステージ;
235 this.現在のステージ.活性化する( this.スレッド排他領域.デバイスリソース );
241 case nameof( ステージ.タイトル.タイトルステージ ):
242 #region " 確定 → ログインステージへ。"
244 if( this.タイトルステージ.現在のフェーズ == ステージ.タイトル.タイトルステージ.フェーズ.確定 )
246 this.現在のステージ.非活性化する( this.スレッド排他領域.デバイスリソース );
247 this.現在のステージ = this.ログインステージ;
248 this.現在のステージ.活性化する( this.スレッド排他領域.デバイスリソース );
252 #region " キャンセル → アプリを終了する。"
254 else if( this.タイトルステージ.現在のフェーズ == ステージ.タイトル.タイトルステージ.フェーズ.キャンセル )
256 this.現在のステージ.非活性化する( this.スレッド排他領域.デバイスリソース );
258 this.スレッド排他領域.アプリを終了せよ = true;
264 case nameof( ステージ.ログイン.ログインステージ ):
265 #region " 確定 → ログイン処理を行って、選曲ステージへ。"
267 if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.確定 )
269 // ログイン処理(1) ユーザリストに対してユーザを選択する。
270 StrokeStyleT.ユーザ管理.ユーザを選択する( this.ログインステージ.ユーザインデックス );
271 FDK.Log.Info( $"ユーザが選択されました。[{StrokeStyleT.ユーザ管理.現在選択されているユーザ.名前}]" );
273 // ログイン処理(2) 選択ユーザの曲ツリーを構築する。
274 StrokeStyleT.ユーザ管理.現在選択されているユーザ.曲を検索して曲ツリーを構築する();
276 // ログイン処理(3) 構築した曲ツリーを曲リスト管理に登録する。
277 StrokeStyleT.曲ツリー管理.現在の管理対象ツリー = StrokeStyleT.ユーザ管理.現在選択されているユーザ.曲ツリーのルートノード;
280 this.現在のステージ.非活性化する( this.スレッド排他領域.デバイスリソース );
281 this.現在のステージ = this.選曲ステージ;
282 this.現在のステージ.活性化する( this.スレッド排他領域.デバイスリソース );
286 #region " キャンセル → タイトルステージへ。"
288 else if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.キャンセル )
290 this.現在のステージ.非活性化する( this.スレッド排他領域.デバイスリソース );
291 this.現在のステージ = this.タイトルステージ;
292 this.現在のステージ.活性化する( this.スレッド排他領域.デバイスリソース );
298 case nameof( ステージ.選曲.選曲ステージ ):
299 #region " 曲確定 → 曲読込ステージへ。"
301 if( this.選曲ステージ.現在のフェーズ == ステージ.選曲.選曲ステージ.フェーズ.曲確定 )
303 // 曲ノードが選択されていることを確認。
304 Trace.Assert( null != StrokeStyleT.曲ツリー管理.現在選択されているノード, "[バグあり] 選択曲が null です。" );
305 this.現在のステージ.非活性化する( this.スレッド排他領域.デバイスリソース );
306 this.現在のステージ = this.曲読込ステージ;
307 this.現在のステージ.活性化する( this.スレッド排他領域.デバイスリソース );
311 #region " キャンセル → アプリを終了する。"
313 else if( this.選曲ステージ.現在のフェーズ == ステージ.選曲.選曲ステージ.フェーズ.キャンセル )
315 this.現在のステージ.非活性化する( this.スレッド排他領域.デバイスリソース );
317 this.スレッド排他領域.アプリを終了せよ = true;
323 case nameof( ステージ.曲読込.曲読込ステージ ):
324 #region " 終了 → 演奏ステージへ。"
325 //--------------------
326 if( this.曲読込ステージ.現在のフェーズ == ステージ.曲読込.曲読込ステージ.フェーズ.終了 )
328 // 演奏スコアインスタンスが作成されていることを確認。
329 Debug.Assert( null != StrokeStyleT.演奏スコア );
331 this.現在のステージ.非活性化する( this.スレッド排他領域.デバイスリソース );
332 this.現在のステージ = this.演奏ステージ;
333 this.現在のステージ.活性化する( this.スレッド排他領域.デバイスリソース );
335 //--------------------
339 case nameof( ステージ.演奏.演奏ステージ ):
340 #region " 演奏終了 → 結果ステージへ。"
341 //--------------------
342 if( this.演奏ステージ.現在のフェーズ == ステージ.演奏.演奏ステージ.フェーズ.クリアor失敗 )
344 this.現在のステージ.非活性化する( this.スレッド排他領域.デバイスリソース );
345 this.現在のステージ = this.結果ステージ;
346 this.現在のステージ.活性化する( this.スレッド排他領域.デバイスリソース );
348 //--------------------
350 #region " キャンセル → 選曲ステージへ。"
351 //--------------------
352 if( this.演奏ステージ.現在のフェーズ == ステージ.演奏.演奏ステージ.フェーズ.キャンセル )
354 this.現在のステージ.非活性化する( this.スレッド排他領域.デバイスリソース );
355 this.現在のステージ = this.選曲ステージ;
356 this.現在のステージ.活性化する( this.スレッド排他領域.デバイスリソース );
358 //--------------------
362 case nameof( ステージ.結果.結果ステージ ):
363 #region " 終了 → 選曲ステージへ。"
364 //--------------------
365 if( this.結果ステージ.現在のフェーズ == ステージ.結果.結果ステージ.フェーズ.終了 )
367 this.現在のステージ.非活性化する( this.スレッド排他領域.デバイスリソース );
368 this.現在のステージ = this.選曲ステージ;
369 this.現在のステージ.活性化する( this.スレッド排他領域.デバイスリソース );
371 //--------------------
379 protected override void デバイス依存リソースを再構築する()
381 FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
383 this.現在のステージ?.デバイス依存リソースを作成する( this.スレッド排他領域.デバイスリソース );
385 FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
387 protected override void デバイス依存リソースを解放する()
389 FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
391 this.現在のステージ?.デバイス依存リソースを解放する( this.スレッド排他領域.デバイスリソース );
393 FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
397 protected SST.ステージ.ステージ 最初のダミーステージ = new ステージ.ステージ();
398 protected SST.ステージ.起動.起動ステージ 起動ステージ = new ステージ.起動.起動ステージ();
399 protected SST.ステージ.タイトル.タイトルステージ タイトルステージ = new ステージ.タイトル.タイトルステージ();
400 protected SST.ステージ.ログイン.ログインステージ ログインステージ = new ステージ.ログイン.ログインステージ();
401 protected SST.ステージ.選曲.選曲ステージ 選曲ステージ = new ステージ.選曲.選曲ステージ();
402 protected SST.ステージ.曲読込.曲読込ステージ 曲読込ステージ = new ステージ.曲読込.曲読込ステージ();
403 protected SST.ステージ.演奏.演奏ステージ 演奏ステージ = new ステージ.演奏.演奏ステージ();
404 protected SST.ステージ.結果.結果ステージ 結果ステージ = new ステージ.結果.結果ステージ();
406 private SST.ステージ.ステージ 現在のステージ = null;
410 private static SST.フォルダ bs_フォルダ = null;
411 private static FDK.入力.Keyboard bs_キーボード入力 = null;
412 private static FDK.入力.MidiIn bs_MIDI入力 = null;
413 private static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice bs_Wasapiデバイス = null;
414 private static readonly Random bs_乱数 = new Random( DateTime.Now.Millisecond );
415 private static SST.ユーザ.ユーザ管理 bs_ユーザ管理 = null;
416 private static SST.曲.曲ツリー管理 bs_曲ツリー管理 = null;
417 public static SST.設定.Config bs_Config = null;
421 #region " Win32 API "
423 [ System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeBeginPeriod" )]
424 private static extern uint timeBeginPeriod( uint uMilliseconds );
426 [System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeEndPeriod" )]
427 private static extern uint timeEndPeriod( uint uMilliseconds );