我在寫一個使用C++和Windows API的Windows程序,並且試圖在MIDI流中排列MIDI消息,但是當我嘗試這樣做時收到奇怪的錯誤。如果我使用midiOutShortMsg
將未排隊的MIDI消息發送到流,它將正常工作。但是,midiStreamOut
總是返回錯誤代碼68,即#define
d到MCIERR_WAVE_OUTPUTUNSPECIFIED
。 midiOutGetErrorText
給出了錯誤的如下描述:在Windows中使用MIDI流的問題
The current MIDI Mapper setup refers to a MIDI device that is not installed on the system. Use MIDI Mapper to edit the setup.
我使用Windows 7(64位),並嘗試打開與兩個MIDI_MAPPER的設備ID的MIDI流,我的系統上所有四個MIDI輸出設備和仍然收到完全相同的錯誤信息。
這裏是打開MIDI流代碼:
UINT device_id = MIDI_MAPPER; //Also tried 0, 1, 2 and 3
midiStreamOpen(&midi, &device_id, 1, (DWORD_PTR)hwnd, 0, CALLBACK_WINDOW);
這裏是發送MIDI消息代碼:
MIDIHDR header;
MIDIEVENT *event;
event = (MIDIEVENT *)malloc(sizeof(*event));
event->dwDeltaTime = delta_time;
event->dwStreamID = 0;
event->dwEvent = (MEVT_F_SHORT | MEVT_SHORTMSG) << 24 | (msg & 0x00FFFFFF);
header.lpData = (LPSTR)event;
header.dwBufferLength = sizeof(*event);
header.dwBytesRecorded = sizeof(*event);
header.dwUser = 0;
header.dwFlags = 0;
header.dwOffset = 0;
midiOutPrepareHeader((HMIDIOUT)midi, &header, sizeof(header));
midiStreamOut(midi, &header, sizeof(header));
我怎樣才能解決這個問題呢?