0

我正在尝试制作我模拟的win32应用程序,我按下C钢琴上的键,键盘No 60,并使用以下调用:midiOutShortMsg (hMidiOut, DWORD (0x090 | 0 | (60 << 8) | (64 << 16)));

并在释放 60 号键时执行以下调用:midiOutShortMsg (hMidiOut, DWORD (0x080 | 0 | (60 << 8) | (0 << 16)));

问题是当我按下按钮时,我只听到一次声音。当我运行程序时,只有一个案例有效。

我怎样才能做到只要我按,声音就会重复。以及如何才能使长旋律播放。

case WM_KEYDOWN:
{
    switch (wParam) {

    case VK_LEFT:
        midiOutOpen(&hMidiOut, -1, 0, 0, 0);
        // Set instrument to 0 = Acoustic Grand Piano
        midiOutShortMsg(hMidiOut, DWORD(0x0C0 | 0 | (0 << 8) | (0 << 16)));
        midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (65<<8 ) | (64 << 16)));
        break;

    case 'S':
        midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (62<<8 ) | (64 << 16)));   
        break;

    case 'D':
        midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (64<<8 ) | (64 << 16)));
        break;

    case 'F':
        midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (65<<8 ) | (64 << 16)));
        break;

    case 'G':
        midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (67<<8 ) | (64 << 16)));
        break;

    case 'H':
        midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (69<<8 ) | (64 << 16)));
        break;

    case 'J':
        midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (71<<8 ) | (64 << 16)));
        break;

    case 'K':
        midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (72<<8 ) | (64 << 16)));
        break;
4

1 回答 1

0

我想您可以存储键状态(也许使用 bool 数组)并在消息处理循环中进行播放。

于 2012-11-21T01:09:04.467 回答