OSDN Git Service

ebb6346ca0b928cbf9ad06f9e131eb0c15681f47
[dtxmania/dtxmania.git] / FDK / コード / 02.入力 / CInputMIDI.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Diagnostics;
5
6 namespace FDK
7 {
8         public class CInputMIDI : IInputDevice, IDisposable
9         {
10                 // プロパティ
11
12                 public uint hMidiIn;
13                 public List<STInputEvent> listEventBuffer;
14
15                 // コンストラクタ
16
17                 public CInputMIDI( uint nID )
18                 {
19                         this.hMidiIn = 0;
20                         this.listEventBuffer = new List<STInputEvent>( 32 );
21                         this.list入力イベント = new List<STInputEvent>( 32 );
22                         this.e入力デバイス種別 = E入力デバイス種別.MidiIn;
23                         this.GUID = "";
24                         this.ID = (int) nID;
25                         this.strDeviceName = "";        // CInput管理で初期化する
26                 }
27
28
29                 // メソッド
30
31                 public void tメッセージからMIDI信号のみ受信( uint wMsg, int dwInstance, int dwParam1, int dwParam2, long n受信システム時刻 )
32                 {
33                         if( wMsg == CWin32.MIM_DATA )
34                         {
35                                 int nMIDIevent = dwParam1 & 0xF0;
36                                 int nPara1 = ( dwParam1 >> 8 ) & 0xFF;
37                                 int nPara2 = ( dwParam1 >> 16 ) & 0xFF;
38
39 // Trace.TraceInformation( "MIDIevent={0:X2} para1={1:X2} para2={2:X2}", nMIDIevent, nPara1, nPara2 );
40                         
41                                 if( ( nMIDIevent == 0x90 ) && ( nPara2 != 0 ) )         // Note ON
42                                 {
43                                         STInputEvent item = new STInputEvent();
44                                         item.nKey = nPara1;
45                                         item.b押された = true;
46                                         item.nTimeStamp = n受信システム時刻;
47                                         item.nVelocity = nPara2;
48                                         this.listEventBuffer.Add( item );
49                                 }
50                                 //else if ( ( nMIDIevent == 0xB0 ) && ( nPara1 == 4 ) ) // Ctrl Chg #04: Foot Controller
51                                 //{
52                                 //      STInputEvent item = new STInputEvent();
53                                 //      item.nKey = nPara1;
54                                 //      item.b押された = true;
55                                 //      item.nTimeStamp = n受信システム時刻;
56                                 //      item.nVelocity = nPara2;
57                                 //      this.listEventBuffer.Add( item );
58                                 //}
59                         }
60                 }
61
62                 #region [ IInputDevice 実装 ]
63                 //-----------------
64                 public E入力デバイス種別 e入力デバイス種別 { get; private set; }
65                 public string GUID { get; private set; }
66                 public int ID { get; private set; }
67                 public List<STInputEvent> list入力イベント { get; private set; }
68                 public string strDeviceName { get; set; }
69
70                 public void tポーリング( bool bWindowがアクティブ中, bool bバッファ入力を使用する )
71                 {
72                         // this.list入力イベント = new List<STInputEvent>( 32 );
73                         this.list入力イベント.Clear();                                                            // #xxxxx 2012.6.11 yyagi; To optimize, I removed new();
74
75                         for( int i = 0; i < this.listEventBuffer.Count; i++ )
76                                 this.list入力イベント.Add( this.listEventBuffer[ i ] );
77
78                         this.listEventBuffer.Clear();
79                 }
80                 public bool bキーが押された( int nKey )
81                 {
82                         foreach( STInputEvent event2 in this.list入力イベント )
83                         {
84                                 if( ( event2.nKey == nKey ) && event2.b押された )
85                                 {
86                                         return true;
87                                 }
88                         }
89                         return false;
90                 }
91                 public bool bキーが押されている( int nKey )
92                 {
93                         return false;
94                 }
95                 public bool bキーが離された( int nKey )
96                 {
97                         return false;
98                 }
99                 public bool bキーが離されている( int nKey )
100                 {
101                         return false;
102                 }
103                 //-----------------
104                 #endregion
105
106                 #region [ IDisposable 実装 ]
107                 //-----------------
108                 public void Dispose()
109                 {
110                         if ( this.listEventBuffer != null )
111                         {
112                                 this.listEventBuffer = null;
113                         }
114                         if ( this.list入力イベント != null )
115                         {
116                                 this.list入力イベント = null;
117                         }
118                 }
119                 //-----------------
120                 #endregion
121         }
122 }