OSDN Git Service

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