source: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/MM/MidiOut.ab@ 594

Last change on this file since 594 was 594, checked in by NoWest, 16 years ago

MIDI出力関連のMidiOutクラスを追加。
Joystick.abを改良。ListをIlistに変更。

File size: 6.7 KB
Line 
1
2'#require <api_mmsys.sbp>
3
4Namespace ActiveBasic
5Namespace Windows
6Namespace MM
7
8'MIDI出力デバイスの種類を表す列挙子
9Enum MidiOutDeviceType
10 'デバイスはポート
11 HardwarePort = 1
12 'デバイスはシンセサイザ
13 Synthesizer = 2
14 'デバイスは方形波シンセサイザ
15 SquareWaveSynthesizer = 3
16 'デバイスはFMシンセサイザ
17 FrequencyModulationSynthesizer = 4
18 'デバイスはマッパー
19 Mapper = 5
20 'デバイスはハードウェアのウェーブテーブルシンセサイザ
21 HardwareWavetableSynthesizer = 6
22 'デバイスはソフトウェアシンセサイザ
23 SoftwareSynthesizer = 7
24End Enum
25
26
27'MIDI出力デバイスの持つ機能を表す列挙子
28Enum MidiDeviceFunction
29 'デバイスはモノラルの音量調節が可能
30 VolumeControl = &H0001
31 'デバイスはステレオの音量調節が可能
32 LRVolumeControl = &H0002
33 'デバイスはキャッシングが可能
34 PatchCaching = &H0004
35 'デバイスはmidiSteamOut関数を直接サポート
36 DirectSupportedMidiStreamOut = &H0008
37End Enum
38
39Class MidiOutCaps
40 caps As MIDIOUTCAPS
41
42Protected
43 Sub _Initialize ( id As DWord )
44 midiOutGetDevCaps(id,caps,SizeOf(MIDIOUTCAPS))
45 End Sub
46
47Public 'Property
48 '製造業者IDの取得
49 Function ManufacturerID () As Word
50 Return This.caps.wMid
51 End Function
52
53 '製品IDの取得
54 Function ProductID () As Word
55 Return This.caps.wPid
56 End Function
57
58 'デバイスドライバのバージョンの取得
59 Function DriverVersion () As DWord
60 Return This.caps.vDriverVersion
61 End Function
62
63 'デバイス名の取得
64 Function DeviceName () As String
65 Return New System.String(This.caps.szPname As LPTSTR)
66 End Function
67
68 'MIDI出力デバイスの種類を取得
69 Function DeviceType () As MidiOutDeviceType
70 Return This.caps.wTechnology As MidiOutDeviceType
71 End Function
72
73 'MIDI出力デバイスがサポートするボイス数を取得
74 Function NumberOfVoices () As Word
75 Return This.caps.wVoices
76 End Function
77
78 'MIDI出力デバイスが同時に演奏することができるノート数
79 Function NumberOfNotes () As Word
80 Return This.caps.wNotes
81 End Function
82
83/* Function Channel() As Word
84 TODO
85 This.caps.wChannelMask
86 End Function*/
87
88 'デバイスが提供している機能を取得
89 Function SupportedFunctions () As MidiDeviceFunction
90 Return This.caps.dwSupport As MidiDeviceFunction
91 End Function
92
93End Class
94
95'MIDI出力デバイスを扱うためのクラス
96Class MidiOutDevice
97 id As DWord
98 handle As HMIDIOUT
99
100Protected
101 Sub _Initialize ( id As DWord )
102 This.id = id
103 End Sub
104 Function Handle () As HMIDIOUT
105 Return This.handle
106 End Function
107
108Public
109 Sub ~MidiOutDevice ()
110 This.Close()
111 End Sub
112
113Public 'Property
114 Function GetCapabilities () As MidiOutCaps
115 Return New Detail._System_MidiOutCaps(This.id)
116 End Function
117
118Public 'Method
119 'デバイスを閉じる
120 Sub Close ()
121 Dim ret = midiOutClose(InterlockedExchangePointer(ByVal VarPtr(This.handle) As VoidPtr, NULL))
122 End Sub
123
124 'デバイスのステレオ音量の左側の値を取得
125 Function GetLeftVolume() As Word
126 If This.handle=NULL Then Return 0
127 Dim volume As DWord
128 Dim ret = midiOutGetVolume(This.handle,volume)
129 Return LOWORD(volume)
130 End Function
131
132 'デバイスのステレオ音量の右側の値を取得
133 Function GetRightVolume() As Word
134 If This.handle=NULL Then Return 0
135 Dim volume As DWord
136 Dim ret = midiOutGetVolume(This.handle,volume)
137 Return HIWORD(volume)
138 End Function
139
140 'デバイスのモノラル音量を取得
141 Function GetVolume () As Word
142 If This.handle=NULL Then Return 0
143 Return This.GetLeftVolume()
144 End Function
145
146 'デバイスを開く
147 Sub Open ()
148 Dim ret = midiOutOpen(This.handle,This.id,0,0,CALLBACK_NULL)
149 End Sub
150
151 'コールバックにSystem.Threading.EventWaitHandleを使用してデバイスを開く
152 Sub Open ( callback As System.Threading.EventWaitHandle )
153 Dim ret = midiOutOpen(This.handle,This.id,callback.Handle() As DWORD_PTR,0,CALLBACK_FUNCTION)
154 End Sub
155
156 'コールバックに関数を指定してデバイスを開く
157 Sub Open ( callback As MIDICALLBACK )
158 Dim ret = midiOutOpen(This.handle,This.id,callback As DWORD_PTR,0,CALLBACK_FUNCTION)
159 End Sub
160
161 'コールバックにSystem.Threading.Threadを使用してデバイスを開く
162 Sub Open ( callback As System.Threading.Thread )
163 Dim ret = midiOutOpen(This.handle,This.id,callback.ThreadId() As DWORD_PTR,0,CALLBACK_THREAD)
164 End Sub
165
166 'コールバックにウィンドウハンドルを指定してデバイスを開く
167 Sub Open ( callback As HWND )
168 Dim ret = midiOutOpen(This.handle,This.id,callback As DWORD_PTR,0,CALLBACK_WINDOW)
169 End Sub
170
171 'デバイスの出力を全て停止
172 Sub Reset ()
173 Dim ret = midiOutReset(This.handle)
174 End Sub
175
176 'デバイスにショートメッセージを送信
177 Sub SendShortMsg ( msg As DWord )
178 If This.handle=NULL Then Exit Sub
179 Dim ret = midiOutShortMsg(This.handle,msg)
180 End Sub
181
182 'デバイスのステレオ音量の左側の値を設定
183 Sub SetLeftVolume ( volume As Word )
184 If This.handle=NULL Then Exit Sub
185 Dim ret = midiOutSetVolume(This.handle,MAKELONG(volume,This.GetRightVolume()))
186 End Sub
187
188 'デバイスのステレオ音量の右側の値を設定
189 Sub SetRightVolume ( volume As Word )
190 If This.handle=NULL Then Exit Sub
191 Dim ret = midiOutSetVolume(This.handle,MAKELONG(This.GetLeftVolume(),volume))
192 End Sub
193
194 'デバイスのモノラル音量を設定
195 Sub SetVolume ( volume As Word )
196 If This.handle=NULL Then Exit Sub
197 This.SetLeftVolume(volume)
198 End Sub
199
200End Class
201
202Class MidiOut
203Public
204 'MIDI出力デバイス数を取得
205 Static Function NumberOfDevices () As DWord
206 Return midiOutGetNumDevs()
207 End Function
208
209 'MIDIマッパーを取得
210 Static Function GetMIDIMapper () As MidiOutDevice
211 Return GetDeviceFromID(MIDI_MAPPER)
212 End Function
213
214 'MIDI出力デバイス名を全て取得
215 Static Function GetDeviceNames () As System.Collections.Generic.IList<String>
216 GetDeviceNames = New System.Collections.Generic.List<String>
217 Dim dev = GetDevices()
218 Dim d = Nothing As MidiOutDevice
219 Foreach d In dev
220 GetDeviceNames.Add(d.GetCapabilities().DeviceName())
221 Next
222 End Function
223
224 'MIDI出力デバイスを全て取得
225 Static Function GetDevices () As System.Collections.Generic.IList<MidiOutDevice>
226 GetDevices = New System.Collections.Generic.List<MidiOutDevice>
227 Dim num = NumberOfDevices
228 Dim cnt As DWord
229 For cnt=0 To num-1
230 GetDevices.Add(GetDeviceFromID(cnt))
231 Next
232 End Function
233
234 'IDを指定してMIDI出力デバイスを取得
235 Static Function GetDeviceFromID ( id As DWord ) As MidiOutDevice
236 Return New Detail._System_MidiOutDevice(id)
237 End Function
238End Class
239
240Namespace Detail
241Class _System_MidiOutCaps
242 Inherits MidiOutCaps
243Public
244 Sub _System_MidiOutCaps ( id As DWord )
245 This._Initialize(id)
246 End Sub
247
248 Override Function ToString () As String
249 Return "MidiOutCaps"
250 End Function
251End Class
252
253Class _System_MidiOutDevice
254 Inherits MidiOutDevice
255Public
256 Sub _System_MidiOutDevice ( id As DWord )
257 This._Initialize(id)
258 End Sub
259
260 Override Function ToString () As String
261 Return "MidiOutDevice"
262 End Function
263End Class
264End Namespace
265
266End Namespace
267End Namespace
268End Namespace
Note: See TracBrowser for help on using the repository browser.