MinGW – MIDIDevice

LastUpdate 2005.08.30 Yoshiaki Ueda
[目次へ戻る]

 MinGWでMIDIデバイスをコントロールするプログラムを開発する。


■MIDIデバイスをオープンする


 まずは、MIDIデバイスをオープンしないといけない・・、midiOutOpen( )を使えばいいらしい。
 これはWin32APIそのものである。Win32APIが直接呼び出せる。

bool CMidiOutDevice::Open(UINT uDeviceID, UINT* pResult /*=NULL*/)
{
    UINT result = midiOutOpen(
        &m_Handle,        //LPHMIDIOUT lphmo
        uDeviceID,        //UINT uDeviceID
        0,                //DWORD dwCallback
        0,                //DWORD dwCallbackInstance
        CALLBACK_NULL    //DWORD dwFlags   
    );
    if(pResult) *pResult = result;
    if(result==MMSYSERR_NOERROR){
        m_bOpened = true;
        return true;
    }else{
        return false;
    }
}


■メッセージボックスを出す


    //MIDIデバイス
    CMidiOutDevice mod;
    UINT result;
    //オープン
    mod.Open(2, &result);
    ::wxMessageBox( wxString::Format(wxT("Open %u"), result) );


■MIDIデバイスへメッセージを送出する(音を出す)


void CMidiOutDevice::OutShortMsg(DWORD dwMessage) throw(MMRESULT)
{
    if(!IsOpened()) throw MMSYSERR_INVALHANDLE;
    MMRESULT result = midiOutShortMsg(m_Handle, dwMessage);
    if(result!=MMSYSERR_NOERROR) throw result;
}