by NoWest » 2005年12月10日(土) 16:32
> 返信ありがとうございます。
>
> あと音の高さも分かると嬉しいカモ...
> いや、贅沢な事は言っちゃいけないですね。
> NoWestさんの返信を元に自分でも
> いろいろと試してみようと思います
サンプルを作ってみたんですが、
先にも書きましたとおり、当方にはテストする環境が無いので、
そちらでぶっつけ本番となります。
あと作成したのはAB4.12ですので、
もし、別のバージョンで作成されているようでしたら
連絡してください。
サンプルはMIDI入力から読み込んだデータを
オウム返しにパソコンのMIDI出力から出すものです。
サンプル中ではデバイスのオープンにMIDI_MAPPERを指定していますが、
実際にはそのようにしないでください。
出力デバイスと入力デバイスが被ってしまうとどうなるか私には分かりません。
[ここをクリックすると内容が表示されます] [ここをクリックすると非表示にします]コード: 全て選択
'-----------------------------------------------------------------------------
' イベント プロシージャ
'-----------------------------------------------------------------------------
' このファイルには、ウィンドウ [MainWnd] に関するイベントをコーディングします。
' ウィンドウ ハンドル: hMainWnd
' TODO: この位置にグローバルな変数、構造体、定数、関数を定義します。
Const CALLBACK_WINDOW = &H00010000l
Const MM_MIM_OPEN = &H3C1
Const MM_MIM_CLOSE = &H3C2
Const MM_MIM_DATA = &H3C3
Const MM_MIM_LONGDATA = &H3C4
Const MM_MIM_ERROR = &H3C5
Const MM_MIM_LONGERROR = &H3C6
Const MM_MOM_OPEN = &H3C7
Const MM_MOM_CLOSE = &H3C8
Const MM_MOM_DONE = &H3C9
Const MIDIERR_BASE = 64
Const MIDIERR_UNPREPARED = (MIDIERR_BASE + 0)
Const MIDIERR_STILLPLAYING = (MIDIERR_BASE + 1)
Const MIDIERR_NOMAP = (MIDIERR_BASE + 2)
Const MIDIERR_NOTREADY = (MIDIERR_BASE + 3)
Const MIDIERR_NODEVICE = (MIDIERR_BASE + 4)
Const MIDIERR_INVALIDSETUP = (MIDIERR_BASE + 5)
Const MIDIERR_BADOPENMODE = (MIDIERR_BASE + 6)
Const MIDIERR_DONT_CONTINUE = (MIDIERR_BASE + 7)
Const MIDIERR_LASTERROR = (MIDIERR_BASE + 7)
TypeDef HMIDI = VoidPtr
TypeDef HMIDIIN = VoidPtr
TypeDef HMIDIOUT = VoidPtr
TypeDef HMIDISTRM = VoidPtr
TypeDef LPHMIDI = *HMIDI
TypeDef LPHMIDIIN = *HMIDIIN
TypeDef LPHMIDIOUT = *HMIDIOUT
TypeDef LPHMIDISTRM = *HMIDISTRM
TypeDef LPMIDICALLBACK = PDRVCALLBACK
Const MIDIPATCHSIZE = 128
Const MIM_OPEN = MM_MIM_OPEN
Const MIM_CLOSE = MM_MIM_CLOSE
Const MIM_DATA = MM_MIM_DATA
Const MIM_LONGDATA = MM_MIM_LONGDATA
Const MIM_ERROR = MM_MIM_ERROR
Const MIM_LONGERROR = MM_MIM_LONGERROR
Const MOM_OPEN = MM_MOM_OPEN
Const MOM_CLOSE = MM_MOM_CLOSE
Const MOM_DONE = MM_MOM_DONE
Const MIM_MOREDATA = MM_MIM_MOREDATA
Const MOM_POSITIONCB = MM_MOM_POSITIONCB
Const MIDIMAPPER = (-1)
Const MIDI_MAPPER = (-1)
Const MIDI_IO_STATUS = &H00000020L
Const MIDI_CACHE_ALL = 1
Const MIDI_CACHE_BESTFIT = 2
Const MIDI_CACHE_QUERY = 3
Const MIDI_UNCACHE = 4
Type MIDIOUTCAPS
wMid As Word
wPid As Word
vDriverVersion As DWord
szPname[ELM(MAXPNAMELEN)] As Char
wTechnology As Word
wVoices As Word
wNotes As Word
wChannelMask As Word
dwSupport As DWord
End Type
Const MOD_MIDIPORT = 1
Const MOD_SYNTH = 2
Const MOD_SQSYNTH = 3
Const MOD_FMSYNTH = 4
Const MOD_MAPPER = 5
Const MIDICAPS_VOLUME = &H0001
Const MIDICAPS_LRVOLUME = &H0002
Const MIDICAPS_CACHE = &H0004
Const MIDICAPS_STREAM = &H0008
Type MIDIINCAPS
wMid As Word
wPid As Word
vDriverVersion As DWord
szPname[ELM(MAXPNAMELEN)] As Char
dwSupport As DWord
End Type
Type MIDIHDR
lpData As LPSTR
dwBufferLength As DWord
dwBytesRecorded As DWord
dwUser As DWord
dwFlags As DWord
lpNext As *MIDIHDR
reserved As DWord
dwOffset As DWord
dwReserved[ELM(8)] As DWord
End Type
Type MIDIEVENT
dwDeltaTime As DWord
dwStreamID As DWord
dwEvent As DWord
dwParms[ELM(1)] As DWord
End Type
Type MIDISTRMBUFFVER
dwVersion As DWord
dwMid As DWord
dwOEMVersion As DWord
End Type
Const MHDR_DONE = &H00000001
Const MHDR_PREPARED = &H00000002
Const MHDR_INQUEUE = &H00000004
Const MHDR_ISSTRM = &H00000008
Const MEVT_F_SHORT = &H00000000L
Const MEVT_F_LONG = &H80000000L
Const MEVT_F_CALLBACK = &H40000000L
Const MEVT_EVENTTYPE(x) = ((x>>24) AND &HFF)
Const MEVT_EVENTPARM(x) = (x AND &H00FFFFFFL)
Const MEVT_SHORTMSG = (&H00)
Const MEVT_TEMPO = (&H01)
Const MEVT_NOP = (&H02)
Const MEVT_LONGMSG = (&H80)
Const MEVT_COMMENT = (&H82)
Const MEVT_VERSION = (&H84)
Const MIDISTRM_ERROR = (-2)
Const MIDIPROP_SET = &H80000000L
Const MIDIPROP_GET = &H40000000L
Const MIDIPROP_TIMEDIV = &H00000001L
Const MIDIPROP_TEMPO = &H00000002L
Type MIDIPROPTIMEDIV
cbStruct As DWord
dwTimeDiv As DWord
End Type
Type MIDIPROPTEMPO
cbStruct As DWord
dwTempo As DWord
End Type
Declare Function midiOutGetNumDevs Lib "winmm" () As DWord
Declare Function midiConnect Lib "winmm" (hmi As HMIDI, hmo As HMIDIOUT, pReserved As VoidPtr) As Long
Declare Function midiDisconnect Lib "winmm" (hmi As HMIDI, hmo As HMIDIOUT, pReserved As VoidPtr) As Long
Declare Function midiOutGetDevCaps Lib "winmm" Alias "midiOutGetDevCapsA" (uDeviceID As DWord, pmoc As *MIDIOUTCAPS, cbmoc As DWord) As Long
Declare Function midiOutGetVolume Lib "winmm" (hmo As HMIDIOUT, pdwVolume As *DWord) As Long
Declare Function midiOutSetVolume Lib "winmm" (hmo As HMIDIOUT, dwVolume As DWord) As Long
Declare Function midiOutGetErrorText Lib "winmm" Alias "midiOutGetErrorTextA" (mmrError As Long, pszText As LPSTR, cchText As DWord) As Long
Declare Function midiOutOpen Lib "winmm" (phmo As *HMIDIOUT, uDeviceID As DWord, dwCallback As DWord, dwInstance As DWord, fdwOpen As DWord) As Long
Declare Function midiOutClose Lib "winmm" (hmo As HMIDIOUT) As Long
Declare Function midiOutPrepareHeader Lib "winmm" (hmo As HMIDIOUT, pmh As *MIDIHDR, cbmh As DWord) As Long
Declare Function midiOutUnprepareHeader Lib "winmm" (hmo As HMIDIOUT, pmh As *MIDIHDR, cbmh As DWord) As Long
Declare Function midiOutShortMsg Lib "winmm" (hmo As HMIDIOUT, dwMsg As DWord) As Long
Declare Function midiOutLongMsg Lib "winmm" (hmo As HMIDIOUT, pmh As *MIDIHDR, cbmh As DWord) As Long
Declare Function midiOutReset Lib "winmm" (hmo As HMIDIOUT) As Long
Declare Function midiOutCachePatches Lib "winmm" (hmo As HMIDIOUT, uBank As DWord, pwpa As *Word, fuCache As DWord) As Long
Declare Function midiOutCacheDrumPatches Lib "winmm" (hmo As HMIDIOUT, uPatch As DWord, pwkya As *Word, fuCache As DWord) As Long
Declare Function midiOutGetID Lib "winmm" (hmo As HMIDIOUT, puDeviceID As *DWord) As Long
Declare Function midiOutMessage Lib "winmm" (hmo As HMIDIOUT, uMsg As DWord, dw1 As DWord, dw2 As DWord) As Long
Declare Function midiInGetNumDevs Lib "winmm" () As DWord
Declare Function midiInGetDevCaps Lib "winmm" Alias "midiInGetDevCapsA" (uDeviceID As DWord, pmic As *MIDIINCAPS, cbmic As DWord) As Long
Declare Function midiInGetErrorText Lib "winmm" Alias "midiInGetErrorTextA" (mmrError As Long, pszText As LPSTR, cchText As DWord) As Long
Declare Function midiInOpen Lib "winmm" (phmi As *HMIDIIN, uDeviceID As DWord, dwCallback As DWord, dwInstance As DWord, fdwOpen As DWord) As Long
Declare Function midiInClose Lib "winmm" (hmi As HMIDIIN) As Long
Declare Function midiInPrepareHeader Lib "winmm" (hmi As HMIDIIN, pmh As *MIDIHDR, cbmh As DWord) As Long
Declare Function midiInUnprepareHeader Lib "winmm" (hmi As HMIDIIN, pmh As *MIDIHDR, cbmh As DWord) As Long
Declare Function midiInAddBuffer Lib "winmm" (hmi As HMIDIIN, pmh As *MIDIHDR, cbmh As DWord) As Long
Declare Function midiInStart Lib "winmm" (hmi As HMIDIIN) As Long
Declare Function midiInStop Lib "winmm" (hmi As HMIDIIN) As Long
Declare Function midiInReset Lib "winmm" (hmi As HMIDIIN) As Long
Declare Function midiInGetID Lib "winmm" (hmi As HMIDIIN, puDeviceID As *DWord) As Long
Declare Function midiInMessage Lib "winmm" (hmi As HMIDIIN, uMsg As DWord, dw1 As DWord, dw2 As DWord) As Long
/***************************************************************************************/
Dim Buf[255] As Char
Dim NumDevs As DWord
Dim MidiInCaps As MIDIINCAPS
NumDevs=midiInGetNumDevs()
wsprintf(Buf,Ex"Number Of Devices = %d\n",NumDevs)
OutputDebugString(Buf)
Dim i As Long
For i=0 To NumDevs-1
midiInGetDevCaps(NumDevs-1,VarPtr(MidiInCaps),SizeOf(MIDIINCAPS))
wsprintf(Buf,Ex"Name Of MIDI IN Device = \q%s\q ",MidiInCaps.szPname)
OutputDebugString(Buf)
wsprintf(Buf,Ex"Device ID = %d\n",i)
OutputDebugString(Buf)
Next
Dim hMidiIn As HMIDIIN
Dim MidiData[ELM(128)] As Char
Dim MidiHdr As MIDIHDR
MidiHdr.lpData=MidiData
Dim hMidiOut As HMIDIOUT
'-----------------------------------------------------------------------------
' ウィンドウメッセージを処理するためのコールバック関数
Function MainWndProc(hWnd As HWND, dwMsg As DWord, wParam As WPARAM, lParam As LPARAM) As DWord
' TODO: この位置にウィンドウメッセージを処理するためのコードを記述します。
Select Case dwMsg
Case MM_MIM_OPEN
OutputDebugString(Ex"MIDI IN Device Opened\n")
Case MM_MIM_CLOSE
OutputDebugString(Ex"MIDI IN Device Closed\n")
Case MM_MIM_DATA
If wParam<> hMidiIn Then Exit Function
midiOutShortMsg(hMidiOut,lParam)
wsprintf(Buf,":Channel %d\n",lParam And &H0F)
OutputDebugString(Buf)
Select Case (lParam And &HF0)
Case &H80 'ノートオフ
OutputDebugString(Ex"::Note Off\n")
Case &H90 'ノートオン
If (lParam And &HFF0000)=0 Then
'ノートオフ
OutputDebugString(Ex"::Note Off (Ex.)\n")
Else
'ノートオン
OutputDebugString(Ex"::Note On\n")
End If
Case &HC0 'プログラムチェンジ
OutputDebugString(Ex"::Program Change\n")
End Select
Case MM_MIM_LONGDATA
If wParam<> hMidiIn Then Exit Function
midiOutLongMsg(hMidiOut,lParam,SizeOf(MIDIHDR))
midiInAddBuffer(wParam,lParam,SizeOf(MIDIHDR))
Case MM_MOM_OPEN
OutputDebugString(Ex"MIDI OUT Device Opened\n")
Case MM_MOM_CLOSE
OutputDebugString(Ex"MIDI OUT Device Closed\n")
End Select
' イベントプロシージャの呼び出しを行います。
MainWndProc=EventCall_MainWnd(hWnd,dwMsg,wParam,lParam)
End Function
'-----------------------------------------------------------------------------
' ここから下は、イベントプロシージャを記述するための領域になります。
Sub MainWnd_Destroy()
midiin_DestroyObjects()
PostQuitMessage(0)
End Sub
Sub MainWnd_Create(ByRef CreateStruct As CREATESTRUCT)
EnableWindow(GetDlgItem(hMainWnd,CommandButton2),FALSE)
End Sub
Sub MainWnd_CommandButton1_Click()
If hMidiIn=0 Then midiInOpen(VarPtr(hMidiIn), MIDI_MAPPER, hMainWnd, 0, CALLBACK_WINDOW)
If hMidiIn=0 Then OutputDebugString(Ex"Can't Open MIDI IN Devices\n")
If hMidiIn Then midiInPrepareHeader(hMidiIn,VarPtr(MidiHdr),SizeOf(MIDIHDR))
If hMidiIn Then midiInAddBuffer(hMidiIn,VarPtr(MidiHdr),SizeOf(MIDIHDR))
If hMidiOut=0 Then midiOutOpen(VarPtr(hMidiOut), MIDI_MAPPER, hMainWnd, 0, CALLBACK_WINDOW)
If hMidiOut=0 Then OutputDebugString(Ex"Can't Open MIDI OUT Devices\n")
EnableWindow(GetDlgItem(hMainWnd,CommandButton1),FALSE)
EnableWindow(GetDlgItem(hMainWnd,CommandButton2),TRUE)
End Sub
Sub MainWnd_CommandButton2_Click()
If hMidiIn Then midiInUnprepareHeader(hMidiIn,VarPtr(MidiHdr),SizeOf(MIDIHDR))
If hMidiIn Then midiInClose(hMidiIn)
hMidiIn=0
If hMidiOut Then midiOutClose(hMidiOut)
hMidiOut=0
EnableWindow(GetDlgItem(hMainWnd,CommandButton1),TRUE)
EnableWindow(GetDlgItem(hMainWnd,CommandButton2),FALSE)
End Sub
サンプルの実行には
ウィンドウモードでプロジェクトを作成(名前はmidiin)して
コマンドボタンを2つ貼り付けるだけで動くようにしています。
CommandButton1が入力開始でCommandButton2が停止です。
分からないことがあればまた質問してください。
[quote]> 返信ありがとうございます。
>
> あと音の高さも分かると嬉しいカモ...
> いや、贅沢な事は言っちゃいけないですね。
> NoWestさんの返信を元に自分でも
> いろいろと試してみようと思います[/quote]
サンプルを作ってみたんですが、
先にも書きましたとおり、当方にはテストする環境が無いので、
そちらでぶっつけ本番となります。
あと作成したのはAB4.12ですので、
もし、別のバージョンで作成されているようでしたら
連絡してください。
サンプルはMIDI入力から読み込んだデータを
オウム返しにパソコンのMIDI出力から出すものです。
サンプル中ではデバイスのオープンにMIDI_MAPPERを指定していますが、
実際にはそのようにしないでください。
出力デバイスと入力デバイスが被ってしまうとどうなるか私には分かりません。
[hide][code]'-----------------------------------------------------------------------------
' イベント プロシージャ
'-----------------------------------------------------------------------------
' このファイルには、ウィンドウ [MainWnd] に関するイベントをコーディングします。
' ウィンドウ ハンドル: hMainWnd
' TODO: この位置にグローバルな変数、構造体、定数、関数を定義します。
Const CALLBACK_WINDOW = &H00010000l
Const MM_MIM_OPEN = &H3C1
Const MM_MIM_CLOSE = &H3C2
Const MM_MIM_DATA = &H3C3
Const MM_MIM_LONGDATA = &H3C4
Const MM_MIM_ERROR = &H3C5
Const MM_MIM_LONGERROR = &H3C6
Const MM_MOM_OPEN = &H3C7
Const MM_MOM_CLOSE = &H3C8
Const MM_MOM_DONE = &H3C9
Const MIDIERR_BASE = 64
Const MIDIERR_UNPREPARED = (MIDIERR_BASE + 0)
Const MIDIERR_STILLPLAYING = (MIDIERR_BASE + 1)
Const MIDIERR_NOMAP = (MIDIERR_BASE + 2)
Const MIDIERR_NOTREADY = (MIDIERR_BASE + 3)
Const MIDIERR_NODEVICE = (MIDIERR_BASE + 4)
Const MIDIERR_INVALIDSETUP = (MIDIERR_BASE + 5)
Const MIDIERR_BADOPENMODE = (MIDIERR_BASE + 6)
Const MIDIERR_DONT_CONTINUE = (MIDIERR_BASE + 7)
Const MIDIERR_LASTERROR = (MIDIERR_BASE + 7)
TypeDef HMIDI = VoidPtr
TypeDef HMIDIIN = VoidPtr
TypeDef HMIDIOUT = VoidPtr
TypeDef HMIDISTRM = VoidPtr
TypeDef LPHMIDI = *HMIDI
TypeDef LPHMIDIIN = *HMIDIIN
TypeDef LPHMIDIOUT = *HMIDIOUT
TypeDef LPHMIDISTRM = *HMIDISTRM
TypeDef LPMIDICALLBACK = PDRVCALLBACK
Const MIDIPATCHSIZE = 128
Const MIM_OPEN = MM_MIM_OPEN
Const MIM_CLOSE = MM_MIM_CLOSE
Const MIM_DATA = MM_MIM_DATA
Const MIM_LONGDATA = MM_MIM_LONGDATA
Const MIM_ERROR = MM_MIM_ERROR
Const MIM_LONGERROR = MM_MIM_LONGERROR
Const MOM_OPEN = MM_MOM_OPEN
Const MOM_CLOSE = MM_MOM_CLOSE
Const MOM_DONE = MM_MOM_DONE
Const MIM_MOREDATA = MM_MIM_MOREDATA
Const MOM_POSITIONCB = MM_MOM_POSITIONCB
Const MIDIMAPPER = (-1)
Const MIDI_MAPPER = (-1)
Const MIDI_IO_STATUS = &H00000020L
Const MIDI_CACHE_ALL = 1
Const MIDI_CACHE_BESTFIT = 2
Const MIDI_CACHE_QUERY = 3
Const MIDI_UNCACHE = 4
Type MIDIOUTCAPS
wMid As Word
wPid As Word
vDriverVersion As DWord
szPname[ELM(MAXPNAMELEN)] As Char
wTechnology As Word
wVoices As Word
wNotes As Word
wChannelMask As Word
dwSupport As DWord
End Type
Const MOD_MIDIPORT = 1
Const MOD_SYNTH = 2
Const MOD_SQSYNTH = 3
Const MOD_FMSYNTH = 4
Const MOD_MAPPER = 5
Const MIDICAPS_VOLUME = &H0001
Const MIDICAPS_LRVOLUME = &H0002
Const MIDICAPS_CACHE = &H0004
Const MIDICAPS_STREAM = &H0008
Type MIDIINCAPS
wMid As Word
wPid As Word
vDriverVersion As DWord
szPname[ELM(MAXPNAMELEN)] As Char
dwSupport As DWord
End Type
Type MIDIHDR
lpData As LPSTR
dwBufferLength As DWord
dwBytesRecorded As DWord
dwUser As DWord
dwFlags As DWord
lpNext As *MIDIHDR
reserved As DWord
dwOffset As DWord
dwReserved[ELM(8)] As DWord
End Type
Type MIDIEVENT
dwDeltaTime As DWord
dwStreamID As DWord
dwEvent As DWord
dwParms[ELM(1)] As DWord
End Type
Type MIDISTRMBUFFVER
dwVersion As DWord
dwMid As DWord
dwOEMVersion As DWord
End Type
Const MHDR_DONE = &H00000001
Const MHDR_PREPARED = &H00000002
Const MHDR_INQUEUE = &H00000004
Const MHDR_ISSTRM = &H00000008
Const MEVT_F_SHORT = &H00000000L
Const MEVT_F_LONG = &H80000000L
Const MEVT_F_CALLBACK = &H40000000L
Const MEVT_EVENTTYPE(x) = ((x>>24) AND &HFF)
Const MEVT_EVENTPARM(x) = (x AND &H00FFFFFFL)
Const MEVT_SHORTMSG = (&H00)
Const MEVT_TEMPO = (&H01)
Const MEVT_NOP = (&H02)
Const MEVT_LONGMSG = (&H80)
Const MEVT_COMMENT = (&H82)
Const MEVT_VERSION = (&H84)
Const MIDISTRM_ERROR = (-2)
Const MIDIPROP_SET = &H80000000L
Const MIDIPROP_GET = &H40000000L
Const MIDIPROP_TIMEDIV = &H00000001L
Const MIDIPROP_TEMPO = &H00000002L
Type MIDIPROPTIMEDIV
cbStruct As DWord
dwTimeDiv As DWord
End Type
Type MIDIPROPTEMPO
cbStruct As DWord
dwTempo As DWord
End Type
Declare Function midiOutGetNumDevs Lib "winmm" () As DWord
Declare Function midiConnect Lib "winmm" (hmi As HMIDI, hmo As HMIDIOUT, pReserved As VoidPtr) As Long
Declare Function midiDisconnect Lib "winmm" (hmi As HMIDI, hmo As HMIDIOUT, pReserved As VoidPtr) As Long
Declare Function midiOutGetDevCaps Lib "winmm" Alias "midiOutGetDevCapsA" (uDeviceID As DWord, pmoc As *MIDIOUTCAPS, cbmoc As DWord) As Long
Declare Function midiOutGetVolume Lib "winmm" (hmo As HMIDIOUT, pdwVolume As *DWord) As Long
Declare Function midiOutSetVolume Lib "winmm" (hmo As HMIDIOUT, dwVolume As DWord) As Long
Declare Function midiOutGetErrorText Lib "winmm" Alias "midiOutGetErrorTextA" (mmrError As Long, pszText As LPSTR, cchText As DWord) As Long
Declare Function midiOutOpen Lib "winmm" (phmo As *HMIDIOUT, uDeviceID As DWord, dwCallback As DWord, dwInstance As DWord, fdwOpen As DWord) As Long
Declare Function midiOutClose Lib "winmm" (hmo As HMIDIOUT) As Long
Declare Function midiOutPrepareHeader Lib "winmm" (hmo As HMIDIOUT, pmh As *MIDIHDR, cbmh As DWord) As Long
Declare Function midiOutUnprepareHeader Lib "winmm" (hmo As HMIDIOUT, pmh As *MIDIHDR, cbmh As DWord) As Long
Declare Function midiOutShortMsg Lib "winmm" (hmo As HMIDIOUT, dwMsg As DWord) As Long
Declare Function midiOutLongMsg Lib "winmm" (hmo As HMIDIOUT, pmh As *MIDIHDR, cbmh As DWord) As Long
Declare Function midiOutReset Lib "winmm" (hmo As HMIDIOUT) As Long
Declare Function midiOutCachePatches Lib "winmm" (hmo As HMIDIOUT, uBank As DWord, pwpa As *Word, fuCache As DWord) As Long
Declare Function midiOutCacheDrumPatches Lib "winmm" (hmo As HMIDIOUT, uPatch As DWord, pwkya As *Word, fuCache As DWord) As Long
Declare Function midiOutGetID Lib "winmm" (hmo As HMIDIOUT, puDeviceID As *DWord) As Long
Declare Function midiOutMessage Lib "winmm" (hmo As HMIDIOUT, uMsg As DWord, dw1 As DWord, dw2 As DWord) As Long
Declare Function midiInGetNumDevs Lib "winmm" () As DWord
Declare Function midiInGetDevCaps Lib "winmm" Alias "midiInGetDevCapsA" (uDeviceID As DWord, pmic As *MIDIINCAPS, cbmic As DWord) As Long
Declare Function midiInGetErrorText Lib "winmm" Alias "midiInGetErrorTextA" (mmrError As Long, pszText As LPSTR, cchText As DWord) As Long
Declare Function midiInOpen Lib "winmm" (phmi As *HMIDIIN, uDeviceID As DWord, dwCallback As DWord, dwInstance As DWord, fdwOpen As DWord) As Long
Declare Function midiInClose Lib "winmm" (hmi As HMIDIIN) As Long
Declare Function midiInPrepareHeader Lib "winmm" (hmi As HMIDIIN, pmh As *MIDIHDR, cbmh As DWord) As Long
Declare Function midiInUnprepareHeader Lib "winmm" (hmi As HMIDIIN, pmh As *MIDIHDR, cbmh As DWord) As Long
Declare Function midiInAddBuffer Lib "winmm" (hmi As HMIDIIN, pmh As *MIDIHDR, cbmh As DWord) As Long
Declare Function midiInStart Lib "winmm" (hmi As HMIDIIN) As Long
Declare Function midiInStop Lib "winmm" (hmi As HMIDIIN) As Long
Declare Function midiInReset Lib "winmm" (hmi As HMIDIIN) As Long
Declare Function midiInGetID Lib "winmm" (hmi As HMIDIIN, puDeviceID As *DWord) As Long
Declare Function midiInMessage Lib "winmm" (hmi As HMIDIIN, uMsg As DWord, dw1 As DWord, dw2 As DWord) As Long
/***************************************************************************************/
Dim Buf[255] As Char
Dim NumDevs As DWord
Dim MidiInCaps As MIDIINCAPS
NumDevs=midiInGetNumDevs()
wsprintf(Buf,Ex"Number Of Devices = %d\n",NumDevs)
OutputDebugString(Buf)
Dim i As Long
For i=0 To NumDevs-1
midiInGetDevCaps(NumDevs-1,VarPtr(MidiInCaps),SizeOf(MIDIINCAPS))
wsprintf(Buf,Ex"Name Of MIDI IN Device = \q%s\q ",MidiInCaps.szPname)
OutputDebugString(Buf)
wsprintf(Buf,Ex"Device ID = %d\n",i)
OutputDebugString(Buf)
Next
Dim hMidiIn As HMIDIIN
Dim MidiData[ELM(128)] As Char
Dim MidiHdr As MIDIHDR
MidiHdr.lpData=MidiData
Dim hMidiOut As HMIDIOUT
'-----------------------------------------------------------------------------
' ウィンドウメッセージを処理するためのコールバック関数
Function MainWndProc(hWnd As HWND, dwMsg As DWord, wParam As WPARAM, lParam As LPARAM) As DWord
' TODO: この位置にウィンドウメッセージを処理するためのコードを記述します。
Select Case dwMsg
Case MM_MIM_OPEN
OutputDebugString(Ex"MIDI IN Device Opened\n")
Case MM_MIM_CLOSE
OutputDebugString(Ex"MIDI IN Device Closed\n")
Case MM_MIM_DATA
If wParam<> hMidiIn Then Exit Function
midiOutShortMsg(hMidiOut,lParam)
wsprintf(Buf,":Channel %d\n",lParam And &H0F)
OutputDebugString(Buf)
Select Case (lParam And &HF0)
Case &H80 'ノートオフ
OutputDebugString(Ex"::Note Off\n")
Case &H90 'ノートオン
If (lParam And &HFF0000)=0 Then
'ノートオフ
OutputDebugString(Ex"::Note Off (Ex.)\n")
Else
'ノートオン
OutputDebugString(Ex"::Note On\n")
End If
Case &HC0 'プログラムチェンジ
OutputDebugString(Ex"::Program Change\n")
End Select
Case MM_MIM_LONGDATA
If wParam<> hMidiIn Then Exit Function
midiOutLongMsg(hMidiOut,lParam,SizeOf(MIDIHDR))
midiInAddBuffer(wParam,lParam,SizeOf(MIDIHDR))
Case MM_MOM_OPEN
OutputDebugString(Ex"MIDI OUT Device Opened\n")
Case MM_MOM_CLOSE
OutputDebugString(Ex"MIDI OUT Device Closed\n")
End Select
' イベントプロシージャの呼び出しを行います。
MainWndProc=EventCall_MainWnd(hWnd,dwMsg,wParam,lParam)
End Function
'-----------------------------------------------------------------------------
' ここから下は、イベントプロシージャを記述するための領域になります。
Sub MainWnd_Destroy()
midiin_DestroyObjects()
PostQuitMessage(0)
End Sub
Sub MainWnd_Create(ByRef CreateStruct As CREATESTRUCT)
EnableWindow(GetDlgItem(hMainWnd,CommandButton2),FALSE)
End Sub
Sub MainWnd_CommandButton1_Click()
If hMidiIn=0 Then midiInOpen(VarPtr(hMidiIn), MIDI_MAPPER, hMainWnd, 0, CALLBACK_WINDOW)
If hMidiIn=0 Then OutputDebugString(Ex"Can't Open MIDI IN Devices\n")
If hMidiIn Then midiInPrepareHeader(hMidiIn,VarPtr(MidiHdr),SizeOf(MIDIHDR))
If hMidiIn Then midiInAddBuffer(hMidiIn,VarPtr(MidiHdr),SizeOf(MIDIHDR))
If hMidiOut=0 Then midiOutOpen(VarPtr(hMidiOut), MIDI_MAPPER, hMainWnd, 0, CALLBACK_WINDOW)
If hMidiOut=0 Then OutputDebugString(Ex"Can't Open MIDI OUT Devices\n")
EnableWindow(GetDlgItem(hMainWnd,CommandButton1),FALSE)
EnableWindow(GetDlgItem(hMainWnd,CommandButton2),TRUE)
End Sub
Sub MainWnd_CommandButton2_Click()
If hMidiIn Then midiInUnprepareHeader(hMidiIn,VarPtr(MidiHdr),SizeOf(MIDIHDR))
If hMidiIn Then midiInClose(hMidiIn)
hMidiIn=0
If hMidiOut Then midiOutClose(hMidiOut)
hMidiOut=0
EnableWindow(GetDlgItem(hMainWnd,CommandButton1),TRUE)
EnableWindow(GetDlgItem(hMainWnd,CommandButton2),FALSE)
End Sub
[/code][/hide]
サンプルの実行には
ウィンドウモードでプロジェクトを作成(名前はmidiin)して
コマンドボタンを2つ貼り付けるだけで動くようにしています。
CommandButton1が入力開始でCommandButton2が停止です。
分からないことがあればまた質問してください。