OSDN Git Service

6d374b6e1f991551df67b764defbd23d62fc72bf
[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                                         // うちの環境(2017.6.11)
134                                         { new IdKey( 1, 36 ), ドラム入力種別.Bass },
135                                         { new IdKey( 1, 30 ), ドラム入力種別.RightCrash },
136                                         { new IdKey( 1, 29 ), ドラム入力種別.RightCrash },
137                                         { new IdKey( 0, 51 ), ドラム入力種別.RightCrash },
138                                         { new IdKey( 0, 52 ), ドラム入力種別.RightCrash },
139                                         { new IdKey( 0, 57 ), ドラム入力種別.RightCrash },
140                                         { new IdKey( 1, 52 ), ドラム入力種別.RightCrash },
141                                         { new IdKey( 1, 43 ), ドラム入力種別.Tom3 },
142                                         { new IdKey( 1, 58 ), ドラム入力種別.Tom3 },
143                                         { new IdKey( 1, 42 ), ドラム入力種別.HiHat_Close },
144                                         { new IdKey( 1, 22 ), ドラム入力種別.HiHat_Close },
145                                         { new IdKey( 1, 26 ), ドラム入力種別.HiHat_Open },
146                                         { new IdKey( 1, 46 ), ドラム入力種別.HiHat_Open },
147                                         { new IdKey( 1, 255 ), ドラム入力種別.HiHat_Control },   // FDK の MidiIn クラスは、FootControl を ノート 255 として扱う。
148                                         { new IdKey( 1, 48 ), ドラム入力種別.Tom3 },
149                                         { new IdKey( 1, 50 ), ドラム入力種別.Tom3 },
150                                         { new IdKey( 1, 49 ), ドラム入力種別.LeftCrash },
151                                         { new IdKey( 1, 55 ), ドラム入力種別.LeftCrash },
152                                         { new IdKey( 0, 48 ), ドラム入力種別.LeftCrash },
153                                         { new IdKey( 0, 49 ), ドラム入力種別.LeftCrash },
154                                         { new IdKey( 0, 59 ), ドラム入力種別.LeftCrash },
155                                         { new IdKey( 1, 45 ), ドラム入力種別.Tom2 },
156                                         { new IdKey( 1, 47 ), ドラム入力種別.Tom2 },
157                                         { new IdKey( 1, 51 ), ドラム入力種別.Ride },
158                                         { new IdKey( 1, 59 ), ドラム入力種別.Ride },
159                                         { new IdKey( 1, 38 ), ドラム入力種別.Snare },
160                                         { new IdKey( 1, 40 ), ドラム入力種別.Snare },
161                                         { new IdKey( 1, 37 ), ドラム入力種別.Snare },
162
163                                         // とりあえず、DTXMania からベタ移植。
164                                         //{ new IdKey( 0, 42 ), ドラム入力種別.HiHat_Close },
165                                         //{ new IdKey( 0, 93 ), ドラム入力種別.HiHat_Close },
166                                         //{ new IdKey( 0, 46 ), ドラム入力種別.HiHat_Open },
167                                         //{ new IdKey( 0, 92 ), ドラム入力種別.HiHat_Open },
168                                         //{ new IdKey( 0, 255 ), ドラム入力種別.HiHat_Control }, // FDK の MidiIn クラスは、FootControl を ノート 255 として扱う。
169                                         //{ new IdKey( 0, 25 ), ドラム入力種別.Snare },
170                                         //{ new IdKey( 0, 26 ), ドラム入力種別.Snare },
171                                         //{ new IdKey( 0, 27 ), ドラム入力種別.Snare },
172                                         //{ new IdKey( 0, 28 ), ドラム入力種別.Snare },
173                                         //{ new IdKey( 0, 29 ), ドラム入力種別.Snare },
174                                         //{ new IdKey( 0, 31 ), ドラム入力種別.Snare },
175                                         //{ new IdKey( 0, 32 ), ドラム入力種別.Snare },
176                                         //{ new IdKey( 0, 34 ), ドラム入力種別.Snare },
177                                         //{ new IdKey( 0, 37 ), ドラム入力種別.Snare },
178                                         //{ new IdKey( 0, 38 ), ドラム入力種別.Snare },
179                                         //{ new IdKey( 0, 40 ), ドラム入力種別.Snare },
180                                         //{ new IdKey( 0, 113 ), ドラム入力種別.Snare },
181                                         //{ new IdKey( 0, 33 ), ドラム入力種別.Bass },
182                                         //{ new IdKey( 0, 35 ), ドラム入力種別.Bass },
183                                         //{ new IdKey( 0, 36 ), ドラム入力種別.Bass },
184                                         //{ new IdKey( 0, 112 ), ドラム入力種別.Bass },
185                                         //{ new IdKey( 0, 48 ), ドラム入力種別.Tom1 },
186                                         //{ new IdKey( 0, 50 ), ドラム入力種別.Tom1 },
187                                         //{ new IdKey( 0, 47 ), ドラム入力種別.Tom2 },
188                                         //{ new IdKey( 0, 41 ), ドラム入力種別.Tom3 },
189                                         //{ new IdKey( 0, 43 ), ドラム入力種別.Tom3 },
190                                         //{ new IdKey( 0, 45 ), ドラム入力種別.Tom3 },
191                                         //{ new IdKey( 0, 49 ), ドラム入力種別.RightCrash },
192                                         //{ new IdKey( 0, 52 ), ドラム入力種別.RightCrash },
193                                         //{ new IdKey( 0, 55 ), ドラム入力種別.RightCrash },
194                                         //{ new IdKey( 0, 57 ), ドラム入力種別.RightCrash },
195                                         //{ new IdKey( 0, 91 ), ドラム入力種別.RightCrash },
196                                         //{ new IdKey( 0, 51 ), ドラム入力種別.Ride },
197                                         //{ new IdKey( 0, 53 ), ドラム入力種別.Ride },
198                                         //{ new IdKey( 0, 59 ), ドラム入力種別.Ride },
199                                         //{ new IdKey( 0, 89 ), ドラム入力種別.Ride },
200                                 };
201                         }
202                 }
203
204
205                 #region " IExtensibleDataObject の実装 "
206                 //----------------
207                 private ExtensionDataObject _ExData;
208
209                 public virtual ExtensionDataObject ExtensionData
210                 {
211                         get
212                                 => this._ExData;
213
214                         set
215                                 => this._ExData = value;
216                 }
217                 //----------------
218                 #endregion
219         }
220 }