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.Windows.Forms;
6
7 namespace SST
8 {
9         class StrokeStyleT : FDK.ApplicationFormBase
10         {
11                 // グローバルリソース (static) 
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
18                 public static void すべての入力デバイスをポーリングする()
19                 {
20                         // hack: 追加の入力デバイスができたら、ここにポーリングコードを追加すること。
21                         StrokeStyleT.キーボード入力?.ポーリングする();
22                         StrokeStyleT.MIDI入力?.ポーリングする();
23                 }
24
25                 // get only static property の初期化。
26                 static StrokeStyleT()
27                 {
28                         // フォルダ変数を真っ先に登録する。(ほかのメンバのコンストラクタでフォルダ変数を利用できるようにするため。)
29                         StrokeStyleT.bs_フォルダ = new SST.フォルダ();
30                         SST.フォルダ.フォルダ変数を追加する( "Static", StrokeStyleT.フォルダ.StaticFolder );
31                         SST.フォルダ.フォルダ変数を追加する( "AppData", StrokeStyleT.フォルダ.AppDataFolder );
32                         SST.フォルダ.フォルダ変数を追加する( "User", null );
33                 }
34
35                 public override void 初期化する()
36                 {
37                         Debug.Assert( null == this.デバイスリソース );  // 作成される前である。
38                         FDK.Log.現在のスレッドに名前をつける( "GUI" );
39
40                         this.Text = $"StrokeStyle<T> {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()}";
41                         this.ClientSize = new System.Drawing.Size( 1920, 1080 );        // 物理画面サイズpx
42                         this.設計画面サイズdpx = new SharpDX.Size2F( 1920, 1080 );       // 設計画面サイズdpx
43
44                         #region " System.Stopwatch が高解像度タイマを使わないならエラー。"
45                         //-----------------
46                         if( false == System.Diagnostics.Stopwatch.IsHighResolution )
47                                 throw new SSTException( "このシステムは、高解像度タイマをサポートしていません。" );
48                         //-----------------
49                         #endregion
50                         #region " MediaFoundation を起動する。"
51                         //-----------------
52                         SharpDX.MediaFoundation.MediaManager.Startup();
53                         //-----------------
54                         #endregion
55                         #region " Sleep 精度を上げる。"
56                         //-----------------
57                         StrokeStyleT.timeBeginPeriod( 1 );
58                         //-----------------
59                         #endregion
60
61                         #region " WASAPI デバイスを初期化する。"
62                         //----------------
63                         StrokeStyleT.bs_Wasapiデバイス = new FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice();
64                         StrokeStyleT.bs_Wasapiデバイス.初期化する( 7.0f );
65                         //----------------
66                         #endregion
67                         #region " キーボード入力 を初期化する。"
68                         //-----------------
69                         FDK.Log.Info( "キーボード入力デバイスを初期化します。" );
70                         StrokeStyleT.bs_キーボード入力 = new FDK.入力.Keyboard( this.Handle );
71                         //-----------------
72                         #endregion
73                         #region " MIDI入力 を初期化する。"
74                         //-----------------
75                         FDK.Log.Info( "MIDI入力デバイスを初期化します。" );
76                         StrokeStyleT.bs_MIDI入力 = new FDK.入力.MidiIn();
77                         //-----------------
78                         #endregion
79
80                         this.現在のステージ = this.最初のダミーステージ;
81                 }
82                 public override void 終了する()
83                 {
84                         Debug.Assert( null == this.デバイスリソース );  // 解放された後である。
85
86                         #region " MIDI入力 を解放する。"
87                         //-----------------
88                         FDK.Log.Info( "MIDI入力デバイスを解放します。" );
89                         FDK.Utilities.解放する( ref StrokeStyleT.bs_MIDI入力 );
90                         //-----------------
91                         #endregion
92                         #region " キーボード入力 を解放する。"
93                         //-----------------
94                         FDK.Log.Info( "キーボード入力デバイスを解放します。" );
95                         FDK.Utilities.解放する( ref StrokeStyleT.bs_キーボード入力 );
96                         //-----------------
97                         #endregion
98                         #region " WASAPIデバイスを解放する。"
99                         //----------------
100                         FDK.Utilities.解放する( ref StrokeStyleT.bs_Wasapiデバイス );
101                         //----------------
102                         #endregion
103                         #region " MediaFoundation を終了する。"
104                         //-----------------
105                         SharpDX.MediaFoundation.MediaManager.Shutdown();
106                         //-----------------
107                         #endregion
108                 }
109                 public override void シーンを描画する()
110                 {
111                         var d3dDevice = (SharpDX.Direct3D11.Device) null;
112                         using( var d3dLock = new FDK.同期.AutoD3DDeviceLock( this.デバイスリソース.DXGIDeviceManager, out d3dDevice ) )
113                         {
114                                 // 既定のD3Dレンダーターゲットビューを黒でクリアする。
115                                 d3dDevice.ImmediateContext.ClearRenderTargetView(
116                                         this.デバイスリソース.D3DRenderTargetView, SharpDX.Color4.Black );
117
118                                 // 深度バッファを 1.0f でクリアする。
119                                 d3dDevice.ImmediateContext.ClearDepthStencilView(
120                                         this.デバイスリソース.D3DDepthStencilView,
121                                         SharpDX.Direct3D11.DepthStencilClearFlags.Depth,
122                                         depth: 1.0f,
123                                         stencil: 0 );
124                         }
125                         // 既定のD2DレンダーターゲットビットマップをD2Dターゲットに指定する。
126                         this.デバイスリソース.D2DContext1.Target = this.デバイスリソース.D2DRenderTargetBitmap;
127
128                         // 現在のステージを進行描画する。
129                         this.現在のステージ.進行描画する( this.デバイスリソース );
130                 }
131                 public override void シーンのPresent後の処理を行う()
132                 {
133                         switch( this.現在のステージ.GetType().Name )
134                         {
135                                 case nameof( ステージ.ステージ ):
136                                         #region " 最初のダミーステージ "
137                                         //----------------
138                                         // 起動ステージへ遷移する。
139                                         this.起動ステージ.活性化する( this.デバイスリソース );
140                                         this.現在のステージ = this.起動ステージ;
141                                         //----------------
142                                         #endregion
143                                         break;
144
145                                 case nameof( ステージ.起動.起動ステージ ):
146                                         #region " *** "
147                                         //----------------
148                                         //----------------
149                                         #endregion
150                                         break;
151                         }
152                 }
153
154                 // 各ステージの、唯一のインスタンス。
155                 protected SST.ステージ.ステージ 最初のダミーステージ = new ステージ.ステージ();
156                 protected SST.ステージ.起動.起動ステージ 起動ステージ = new ステージ.起動.起動ステージ();
157
158                 private SST.ステージ.ステージ 現在のステージ = null;
159
160                 #region " バックストア。"
161                 //----------------
162                 private static SST.フォルダ bs_フォルダ = null;
163                 private static FDK.入力.Keyboard bs_キーボード入力 = null;
164                 private static FDK.入力.MidiIn bs_MIDI入力 = null;
165                 private static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice bs_Wasapiデバイス = null;
166                 private static readonly Random bs_乱数 = new Random( DateTime.Now.Millisecond );
167                 //----------------
168                 #endregion
169
170                 #region " Win32 API "
171                 //-----------------
172                 [System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeBeginPeriod" )]
173                 private static extern uint timeBeginPeriod( uint uMilliseconds );
174
175                 [System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeEndPeriod" )]
176                 private static extern uint timeEndPeriod( uint uMilliseconds );
177                 //-----------------
178                 #endregion
179         }
180 }