2 using System.Collections.Generic;
3 using System.Diagnostics;
5 using System.Windows.Forms;
9 class StrokeStyleT : FDK.ApplicationFormBase
12 public static SST.フォルダ フォルダ => StrokeStyleT.bs_フォルダ;
13 public static FDK.入力.Keyboard キーボード入力 => StrokeStyleT.bs_キーボード入力;
14 public static FDK.入力.MidiIn MIDI入力 => StrokeStyleT.bs_MIDI入力;
15 public static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice Wasapiデバイス => StrokeStyleT.bs_Wasapiデバイス;
16 public static Random 乱数 => StrokeStyleT.bs_乱数;
17 public static SST.ユーザ.ユーザ管理 ユーザ管理 => StrokeStyleT.bs_ユーザ管理;
18 public static SST.曲.曲ツリー管理 曲ツリー管理 => StrokeStyleT.bs_曲ツリー管理;
19 public static SSTFormat.スコア 演奏スコア { get; set; } = null;
21 public static void すべての入力デバイスをポーリングする()
23 // hack: 追加の入力デバイスができたら、ここにポーリングコードを追加すること。
24 StrokeStyleT.キーボード入力?.ポーリングする();
25 StrokeStyleT.MIDI入力?.ポーリングする();
28 // get only static property の初期化。
31 // フォルダ変数を真っ先に登録する。(ほかのメンバのコンストラクタでフォルダ変数を利用できるようにするため。)
32 StrokeStyleT.bs_フォルダ = new SST.フォルダ();
33 SST.フォルダ.フォルダ変数を追加する( "Static", StrokeStyleT.フォルダ.StaticFolder );
34 SST.フォルダ.フォルダ変数を追加する( "AppData", StrokeStyleT.フォルダ.AppDataFolder );
35 SST.フォルダ.フォルダ変数を追加する( "User", null );
38 StrokeStyleT.bs_ユーザ管理 = new ユーザ.ユーザ管理();
39 StrokeStyleT.bs_曲ツリー管理 = new 曲.曲ツリー管理();
42 public override void 初期化する()
44 Debug.Assert( null == this.デバイスリソース ); // 作成される前である。
45 FDK.Log.現在のスレッドに名前をつける( "GUI" );
47 this.Text = $"StrokeStyle<T> {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()}";
48 this.ClientSize = new System.Drawing.Size( 1920, 1080 ); // 物理画面サイズpx
49 this.設計画面サイズdpx = new SharpDX.Size2F( 1920, 1080 ); // 設計画面サイズdpx
51 #region " System.Stopwatch が高解像度タイマを使わないならエラー。"
53 if( false == System.Diagnostics.Stopwatch.IsHighResolution )
54 throw new SSTException( "このシステムは、高解像度タイマをサポートしていません。" );
57 #region " MediaFoundation を起動する。"
59 SharpDX.MediaFoundation.MediaManager.Startup();
62 #region " Sleep 精度を上げる。"
64 StrokeStyleT.timeBeginPeriod( 1 );
70 FDK.Log.Info( "ユーザ情報を初期化します。" );
71 StrokeStyleT.ユーザ管理.UsersXmlを読み込む();
74 foreach( var ユーザ in StrokeStyleT.ユーザ管理.ユーザリスト )
75 ユーザ.SourcesXmlを読み込む();
78 #region " WASAPI デバイスを初期化する。"
80 StrokeStyleT.bs_Wasapiデバイス = new FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice();
81 StrokeStyleT.bs_Wasapiデバイス.初期化する( 7.0f );
84 #region " キーボード入力 を初期化する。"
86 FDK.Log.Info( "キーボード入力デバイスを初期化します。" );
87 StrokeStyleT.bs_キーボード入力 = new FDK.入力.Keyboard( this.Handle );
90 #region " MIDI入力 を初期化する。"
92 FDK.Log.Info( "MIDI入力デバイスを初期化します。" );
93 StrokeStyleT.bs_MIDI入力 = new FDK.入力.MidiIn();
97 this.現在のステージ = this.最初のダミーステージ;
99 public override void 終了する()
101 Debug.Assert( null == this.デバイスリソース ); // 解放された後である。
103 #region " ステージを終了し、解放する。"
105 //if( this.現在のステージ.活性化している )
106 // this.現在のステージ.非活性化する( this.デバイスリソース ); → デバイスリソース解放後なので、ここで非活性化してはならない。
107 this.最初のダミーステージ = null;
109 this.タイトルステージ = null;
110 this.ログインステージ = null;
117 #region " MIDI入力 を解放する。"
119 FDK.Log.Info( "MIDI入力デバイスを解放します。" );
120 FDK.Utilities.解放する( ref StrokeStyleT.bs_MIDI入力 );
123 #region " キーボード入力 を解放する。"
125 FDK.Log.Info( "キーボード入力デバイスを解放します。" );
126 FDK.Utilities.解放する( ref StrokeStyleT.bs_キーボード入力 );
129 #region " WASAPIデバイスを解放する。"
131 FDK.Utilities.解放する( ref StrokeStyleT.bs_Wasapiデバイス );
134 #region " MediaFoundation を終了する。"
136 SharpDX.MediaFoundation.MediaManager.Shutdown();
140 public override void シーンを描画する()
144 var d3dDevice = (SharpDX.Direct3D11.Device) null;
145 using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.デバイスリソース.DXGIDeviceManager, out d3dDevice ) )
147 // 既定のD3Dレンダーターゲットビューを黒でクリアする。
148 d3dDevice.ImmediateContext.ClearRenderTargetView(
149 this.デバイスリソース.D3DRenderTargetView, SharpDX.Color4.Black );
151 // 深度バッファを 1.0f でクリアする。
152 d3dDevice.ImmediateContext.ClearDepthStencilView(
153 this.デバイスリソース.D3DDepthStencilView,
154 SharpDX.Direct3D11.DepthStencilClearFlags.Depth,
162 this.現在のステージ?.進行描画する( this.デバイスリソース );
165 this.デバイスリソース.SwapChain.Present( 1, SharpDX.DXGI.PresentFlags.None );
167 if( null != this.現在のステージ )
169 // ステージの状態チェックを行い、必要あれば遷移、またはアプリを終了する。
170 switch( this.現在のステージ.GetType().Name )
172 case nameof( ステージ.ステージ ):
173 #region " 最初のダミーステージ "
176 this.起動ステージ.活性化する( this.デバイスリソース );
177 this.現在のステージ = this.起動ステージ;
182 case nameof( ステージ.起動.起動ステージ ):
183 #region " 終了 → タイトルステージへ。"
185 if( this.起動ステージ.現在のフェーズ == ステージ.起動.起動ステージ.フェーズ.終了 )
187 this.現在のステージ.非活性化する( this.デバイスリソース );
188 this.現在のステージ = this.タイトルステージ;
189 this.現在のステージ.活性化する( this.デバイスリソース );
195 case nameof( ステージ.タイトル.タイトルステージ ):
196 #region " 確定 → ログインステージへ。"
198 if( this.タイトルステージ.現在のフェーズ == ステージ.タイトル.タイトルステージ.フェーズ.確定 )
200 this.現在のステージ.非活性化する( this.デバイスリソース );
201 this.現在のステージ = this.ログインステージ;
202 this.現在のステージ.活性化する( this.デバイスリソース );
206 #region " キャンセル → アプリを終了する。"
208 else if( this.タイトルステージ.現在のフェーズ == ステージ.タイトル.タイトルステージ.フェーズ.キャンセル )
210 this.現在のステージ.非活性化する( this.デバイスリソース );
212 this.アプリを終了せよ = true;
218 case nameof( ステージ.ログイン.ログインステージ ):
219 #region " 確定 → ログイン処理を行って、選曲ステージへ。"
221 if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.確定 )
223 // ログイン処理(1) ユーザリストに対してユーザを選択する。
224 StrokeStyleT.ユーザ管理.ユーザを選択する( this.ログインステージ.ユーザインデックス );
225 FDK.Log.Info( $"ユーザが選択されました。[{StrokeStyleT.ユーザ管理.現在選択されているユーザ.名前}]" );
227 // ログイン処理(2) 選択ユーザの曲ツリーを構築する。
228 StrokeStyleT.ユーザ管理.現在選択されているユーザ.曲を検索して曲ツリーを構築する();
230 // ログイン処理(3) 構築した曲ツリーを曲リスト管理に登録する。
231 StrokeStyleT.曲ツリー管理.現在の管理対象ツリー = StrokeStyleT.ユーザ管理.現在選択されているユーザ.曲ツリーのルートノード;
234 this.現在のステージ.非活性化する( this.デバイスリソース );
235 this.現在のステージ = this.選曲ステージ;
236 this.現在のステージ.活性化する( this.デバイスリソース );
240 #region " キャンセル → タイトルステージへ。"
242 else if( this.ログインステージ.現在のフェーズ == ステージ.ログイン.ログインステージ.フェーズ.キャンセル )
244 this.現在のステージ.非活性化する( this.デバイスリソース );
245 this.現在のステージ = this.タイトルステージ;
246 this.現在のステージ.活性化する( this.デバイスリソース );
252 case nameof( ステージ.選曲.選曲ステージ ):
253 #region " 曲確定 → 曲読込ステージへ。"
255 if( this.選曲ステージ.現在のフェーズ == ステージ.選曲.選曲ステージ.フェーズ.曲確定 )
257 // 曲ノードが選択されていることを確認。
258 Trace.Assert( null != StrokeStyleT.曲ツリー管理.現在選択されているノード, "[バグあり] 選択曲が null です。" );
259 this.現在のステージ.非活性化する( this.デバイスリソース );
260 this.現在のステージ = this.曲読込ステージ;
261 this.現在のステージ.活性化する( this.デバイスリソース );
265 #region " キャンセル → アプリを終了する。"
267 else if( this.選曲ステージ.現在のフェーズ == ステージ.選曲.選曲ステージ.フェーズ.キャンセル )
269 this.現在のステージ.非活性化する( this.デバイスリソース );
271 this.アプリを終了せよ = true;
277 case nameof( ステージ.曲読込.曲読込ステージ ):
278 #region " 終了 → 演奏ステージへ。"
279 //--------------------
280 if( this.曲読込ステージ.現在のフェーズ == ステージ.曲読込.曲読込ステージ.フェーズ.終了 )
282 // 演奏スコアインスタンスが作成されていることを確認。
283 Debug.Assert( null != StrokeStyleT.演奏スコア );
285 this.現在のステージ.非活性化する( this.デバイスリソース );
286 this.現在のステージ = this.演奏ステージ;
287 this.現在のステージ.活性化する( this.デバイスリソース );
289 //--------------------
293 case nameof( ステージ.演奏.演奏ステージ ):
294 #region " 演奏終了 → 結果ステージへ。"
295 //--------------------
296 if( this.演奏ステージ.現在のフェーズ == ステージ.演奏.演奏ステージ.フェーズ.クリアor失敗 )
298 this.現在のステージ.非活性化する( this.デバイスリソース );
299 this.現在のステージ = this.結果ステージ;
300 this.現在のステージ.活性化する( this.デバイスリソース );
302 //--------------------
304 #region " キャンセル → 選曲ステージへ。"
305 //--------------------
306 if( this.演奏ステージ.現在のフェーズ == ステージ.演奏.演奏ステージ.フェーズ.キャンセル )
308 this.現在のステージ.非活性化する( this.デバイスリソース );
309 this.現在のステージ = this.選曲ステージ;
310 this.現在のステージ.活性化する( this.デバイスリソース );
312 //--------------------
316 case nameof( ステージ.結果.結果ステージ ):
317 #region " 終了 → 選曲ステージへ。"
318 //--------------------
319 if( this.結果ステージ.現在のフェーズ == ステージ.結果.結果ステージ.フェーズ.終了 )
321 this.現在のステージ.非活性化する( this.デバイスリソース );
322 this.現在のステージ = this.選曲ステージ;
323 this.現在のステージ.活性化する( this.デバイスリソース );
325 //--------------------
331 protected override void OnSizeChanged( EventArgs e )
333 // すべてのサイズ依存リソースを解放する。
334 this.現在のステージ?.非活性化する( this.デバイスリソース );
337 base.OnSizeChanged( e );
339 // すべてのサイズ依存リソースを作成し直す。
340 this.現在のステージ?.活性化する( this.デバイスリソース );
344 protected SST.ステージ.ステージ 最初のダミーステージ = new ステージ.ステージ();
345 protected SST.ステージ.起動.起動ステージ 起動ステージ = new ステージ.起動.起動ステージ();
346 protected SST.ステージ.タイトル.タイトルステージ タイトルステージ = new ステージ.タイトル.タイトルステージ();
347 protected SST.ステージ.ログイン.ログインステージ ログインステージ = new ステージ.ログイン.ログインステージ();
348 protected SST.ステージ.選曲.選曲ステージ 選曲ステージ = new ステージ.選曲.選曲ステージ();
349 protected SST.ステージ.曲読込.曲読込ステージ 曲読込ステージ = new ステージ.曲読込.曲読込ステージ();
350 protected SST.ステージ.演奏.演奏ステージ 演奏ステージ = new ステージ.演奏.演奏ステージ();
351 protected SST.ステージ.結果.結果ステージ 結果ステージ = new ステージ.結果.結果ステージ();
353 private SST.ステージ.ステージ 現在のステージ = null;
357 private static SST.フォルダ bs_フォルダ = null;
358 private static FDK.入力.Keyboard bs_キーボード入力 = null;
359 private static FDK.入力.MidiIn bs_MIDI入力 = null;
360 private static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice bs_Wasapiデバイス = null;
361 private static readonly Random bs_乱数 = new Random( DateTime.Now.Millisecond );
362 private static SST.ユーザ.ユーザ管理 bs_ユーザ管理 = null;
363 private static SST.曲.曲ツリー管理 bs_曲ツリー管理 = null;
367 #region " Win32 API "
369 [System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeBeginPeriod" )]
370 private static extern uint timeBeginPeriod( uint uMilliseconds );
372 [System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeEndPeriod" )]
373 private static extern uint timeEndPeriod( uint uMilliseconds );