OSDN Git Service

App と Program を除いて、SST名前空間をすべて復元。
[strokestylet/CsWin10Desktop3.git] / StrokeStyleT / 入力 / キーバインディング.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Diagnostics;
4 using System.IO;
5 using System.Linq;
6 using System.Runtime.Serialization;
7 using SharpDX.DirectInput;
8 using FDK;
9
10 namespace SST.入力
11 {
12         [DataContract( Name = "KeyBindings", Namespace = "" )]
13         class キーバインディング : IExtensibleDataObject
14         {
15                 /// <summary>
16                 ///             入力コードのマッピング用 Dictionary のキーとなる型。
17                 /// </summary>
18                 /// <remarks>
19                 ///             入力は、デバイスID(入力デバイスの内部識別用ID; FDKのIInputEvent.DeviceIDと同じ)と、
20                 ///             キー(キーコード、ノート番号などデバイスから得られる入力値)の組で定義される。
21                 /// </remarks>
22                 [DataContract( Name = "IDとキー", Namespace = "" )]
23                 public struct IdKey
24                 {
25                         [DataMember]
26                         public int deviceId;
27
28                         [DataMember]
29                         public int key;
30
31                         public IdKey( int deviceId, int key )
32                         {
33                                 this.deviceId = deviceId;
34                                 this.key = key;
35                         }
36                         public IdKey( FDK.入力.InputEvent ie )
37                         {
38                                 this.deviceId = ie.DeviceID;
39                                 this.key = ie.Key;
40                         }
41                 }
42
43
44                 /// <summary>
45                 ///             MIDI番号(0~7)とMIDIデバイス名のマッピング用 Dictionary。
46                 /// </summary>
47                 [DataMember]
48                 public Dictionary<int, string> MIDIデバイス番号toデバイス名 { get; protected set; }
49
50                 /// <summary>
51                 ///             キーボードの入力(DirectInputのKey値)からドラム入力へのマッピング用 Dictionary 。
52                 /// </summary>
53                 [DataMember]
54                 public Dictionary<IdKey, ドラム入力種別> キーボードtoドラム { get; protected set; }
55
56                 /// <summary>
57                 ///             MIDI入力の入力(MIDIノート番号)からドラム入力へのマッピング用 Dictionary 。
58                 /// </summary>
59                 [DataMember]
60                 public Dictionary<IdKey, ドラム入力種別> MIDItoドラム { get; protected set; }
61
62
63                 /// <summary>
64                 ///             コンストラクタ。
65                 /// </summary>
66                 public キーバインディング()
67                 {
68                         using( Log.Block( FDKUtilities.現在のメソッド名 ) )
69                         {
70                                 this._既定値で初期化する( new StreamingContext() );
71                         }
72                 }
73
74                 /// <summary>
75                 ///             ファイルに保存する。
76                 /// </summary>
77                 public void 保存する()
78                 {
79                         using( Log.Block( FDKUtilities.現在のメソッド名 ) )
80                         {
81                                 var path = SST.IO.Folder.絶対パスに含まれるフォルダ変数を展開して返す( _KeyBindingsファイルパス );
82                                 FDKUtilities.保存する( this, path, false ); // キーが struct なので、SimplayDictionary を使うとおかしくなる。
83                         }
84                 }
85
86                 /// <summary>
87                 ///             ファイルから復元する。
88                 /// </summary>
89                 public static キーバインディング 復元する()
90                 {
91                         using( Log.Block( FDKUtilities.現在のメソッド名 ) )
92                         {
93                                 var path = SST.IO.Folder.絶対パスに含まれるフォルダ変数を展開して返す( _KeyBindingsファイルパス );
94                                 return FDKUtilities.復元または新規作成する<キーバインディング>( path, false );      // キーが struct なので、SimplayDictionary を使うとおかしくなる。
95                         }
96                 }
97
98                 /// <summary>
99                 ///             キーバインディングを保存するファイルのパス。
100                 /// </summary>
101                 private static readonly string _KeyBindingsファイルパス = @"$(AppData)\KeyBindings.json";
102
103                 /// <summary>
104                 ///             コンストラクタ時または逆シリアル化時のメンバの既定値を設定する。
105                 /// </summary>
106                 /// <param name="sc">未使用。</param>
107                 /// <remarks>
108                 ///             .NET 既定の初期値だと支障のある(逆シリアル化対象の)メンバがあれば、ここで初期化しておくこと。
109                 /// </remarks>
110                 [OnDeserializing]
111                 private void _既定値で初期化する( StreamingContext context )
112                 {
113                         using( Log.Block( FDKUtilities.現在のメソッド名 ) )
114                         {
115                                 this.MIDIデバイス番号toデバイス名 = new Dictionary<int, string>();
116
117                                 this.キーボードtoドラム = new Dictionary<IdKey, ドラム入力種別>() {
118                                         { new IdKey( 0, (int) Key.Q ), ドラム入力種別.LeftCrash },
119                                         { new IdKey( 0, (int) Key.Return ), ドラム入力種別.LeftCrash },
120                                         { new IdKey( 0, (int) Key.A ), ドラム入力種別.HiHat_Open },
121                                         { new IdKey( 0, (int) Key.Z ), ドラム入力種別.HiHat_Close },
122                                         { new IdKey( 0, (int) Key.X ), ドラム入力種別.Snare },
123                                         { new IdKey( 0, (int) Key.C ), ドラム入力種別.Bass },
124                                         { new IdKey( 0, (int) Key.Space ), ドラム入力種別.Bass },
125                                         { new IdKey( 0, (int) Key.V ), ドラム入力種別.Tom1 },
126                                         { new IdKey( 0, (int) Key.B ), ドラム入力種別.Tom2 },
127                                         { new IdKey( 0, (int) Key.N ), ドラム入力種別.Tom3 },
128                                         { new IdKey( 0, (int) Key.M ), ドラム入力種別.RightCrash },
129                                         { new IdKey( 0, (int) Key.K ), ドラム入力種別.Ride },
130                                 };
131
132                                 this.MIDItoドラム = new Dictionary<IdKey, ドラム入力種別>() {
133                                         // とりあえず、DTXMania からベタ移植。
134                                         { new IdKey( 0, 42 ), ドラム入力種別.HiHat_Close },
135                                         { new IdKey( 0, 93 ), ドラム入力種別.HiHat_Close },
136                                         { new IdKey( 0, 46 ), ドラム入力種別.HiHat_Open },
137                                         { new IdKey( 0, 92 ), ドラム入力種別.HiHat_Open },
138                                         { new IdKey( 0, 255 ), ドラム入力種別.HiHat_Control },   // FDK の MidiIn クラスは、FootControl を ノート 255 として扱う。
139                                         { new IdKey( 0, 25 ), ドラム入力種別.Snare },
140                                         { new IdKey( 0, 26 ), ドラム入力種別.Snare },
141                                         { new IdKey( 0, 27 ), ドラム入力種別.Snare },
142                                         { new IdKey( 0, 28 ), ドラム入力種別.Snare },
143                                         { new IdKey( 0, 29 ), ドラム入力種別.Snare },
144                                         { new IdKey( 0, 31 ), ドラム入力種別.Snare },
145                                         { new IdKey( 0, 32 ), ドラム入力種別.Snare },
146                                         { new IdKey( 0, 34 ), ドラム入力種別.Snare },
147                                         { new IdKey( 0, 37 ), ドラム入力種別.Snare },
148                                         { new IdKey( 0, 38 ), ドラム入力種別.Snare },
149                                         { new IdKey( 0, 40 ), ドラム入力種別.Snare },
150                                         { new IdKey( 0, 113 ), ドラム入力種別.Snare },
151                                         { new IdKey( 0, 33 ), ドラム入力種別.Bass },
152                                         { new IdKey( 0, 35 ), ドラム入力種別.Bass },
153                                         { new IdKey( 0, 36 ), ドラム入力種別.Bass },
154                                         { new IdKey( 0, 112 ), ドラム入力種別.Bass },
155                                         { new IdKey( 0, 48 ), ドラム入力種別.Tom1 },
156                                         { new IdKey( 0, 50 ), ドラム入力種別.Tom1 },
157                                         { new IdKey( 0, 47 ), ドラム入力種別.Tom2 },
158                                         { new IdKey( 0, 41 ), ドラム入力種別.Tom3 },
159                                         { new IdKey( 0, 43 ), ドラム入力種別.Tom3 },
160                                         { new IdKey( 0, 45 ), ドラム入力種別.Tom3 },
161                                         { new IdKey( 0, 49 ), ドラム入力種別.RightCrash },
162                                         { new IdKey( 0, 52 ), ドラム入力種別.RightCrash },
163                                         { new IdKey( 0, 55 ), ドラム入力種別.RightCrash },
164                                         { new IdKey( 0, 57 ), ドラム入力種別.RightCrash },
165                                         { new IdKey( 0, 91 ), ドラム入力種別.RightCrash },
166                                         { new IdKey( 0, 51 ), ドラム入力種別.Ride },
167                                         { new IdKey( 0, 53 ), ドラム入力種別.Ride },
168                                         { new IdKey( 0, 59 ), ドラム入力種別.Ride },
169                                         { new IdKey( 0, 89 ), ドラム入力種別.Ride },
170                                 };
171                         }
172                 }
173
174
175                 #region " IExtensibleDataObject の実装 "
176                 //----------------
177                 private ExtensionDataObject _ExData;
178
179                 public virtual ExtensionDataObject ExtensionData
180                 {
181                         get
182                                 => this._ExData;
183
184                         set
185                                 => this._ExData = value;
186                 }
187                 //----------------
188                 #endregion
189         }
190 }