#include #include MIDIOutputDevice::MIDIOutputDevice(void) : mHasDevice(FALSE), mMIDIDeviceID(MIDIMAPPER) { openDevice(); } WORD MIDIOutputDevice::openDevice(void) { closeDevice(); if(!::midiOutGetNumDevs())return FALSE; if(::midiOutOpen(&mhMIDIOutput,mMIDIDeviceID,0,0,0))return FALSE; hasDevice(TRUE); getDeviceCapabilities(); return TRUE; } void MIDIOutputDevice::closeDevice(void) { if(!hasDevice())return; ::midiOutReset(mhMIDIOutput); ::midiOutClose(mhMIDIOutput); hasDevice(FALSE); } WORD MIDIOutputDevice::getDeviceCapabilities(void) { if(!hasDevice())return FALSE; ::memset(&mMIDIOutDevCaps,0,sizeof(MIDIOutCaps)); if(::midiOutGetDevCaps(mMIDIDeviceID,mMIDIOutDevCaps,sizeof(MIDIOutCaps)))return FALSE; return TRUE; } WORD MIDIOutputDevice::midiEvent(const PureEvent &somePureEvent) { union{DWORD dwData;BYTE bData[4];}unionData; // String str=(String)((PureEvent&)somePureEvent)+String("\n");; // ::OutputDebugString(str.str()); if(!hasDevice())return FALSE; unionData.bData[0]=somePureEvent.eventType(); unionData.bData[1]=somePureEvent.firstData(); unionData.bData[2]=somePureEvent.secondData(); unionData.bData[3]=0; if(::midiOutShortMsg(mhMIDIOutput,unionData.dwData))return FALSE; return TRUE; } WORD MIDIOutputDevice::getLeftVolume(void)const { DWORD volumeLevel; if(!hasDevice())return FALSE; if(!mMIDIOutDevCaps.hasVolume())return FALSE; #if WINVER>=0x0400 if(::midiOutGetVolume(mhMIDIOutput,&volumeLevel))return FALSE; #else if(::midiOutGetVolume(mMIDIDeviceID,&volumeLevel))return FALSE; #endif return LOWORD(volumeLevel); } WORD MIDIOutputDevice::getRightVolume(void)const { DWORD volumeLevel; if(!hasDevice())return FALSE; if(!mMIDIOutDevCaps.hasVolume())return FALSE; #if WINVER>=0x0400 if(::midiOutGetVolume(mhMIDIOutput,&volumeLevel))return FALSE; #else if(::midiOutGetVolume(mMIDIDeviceID,&volumeLevel))return FALSE; #endif if(!mMIDIOutDevCaps.hasLeftRightVolume())return LOWORD(volumeLevel); return HIWORD(volumeLevel); } WORD MIDIOutputDevice::setRightVolume(WORD volumeRight) { DWORD volumeLevel; if(!hasDevice())return FALSE; if(!mMIDIOutDevCaps.hasVolume())return FALSE; volumeLevel=volumeRight; if(mMIDIOutDevCaps.hasLeftRightVolume()) { volumeLevel<<=8; volumeLevel+=getLeftVolume(); } #if WINVER>=0x0400 if(::midiOutSetVolume(mhMIDIOutput,volumeLevel))return FALSE; #else if(::midiOutSetVolume(mMIDIDeviceID,volumeLevel))return FALSE; #endif return TRUE; } WORD MIDIOutputDevice::setLeftVolume(WORD volumeLeft) { DWORD volumeLevel(0L); if(!hasDevice())return FALSE; if(!mMIDIOutDevCaps.hasVolume())return FALSE; if(mMIDIOutDevCaps.hasLeftRightVolume()) { volumeLevel=getRightVolume(); volumeLevel<<=8; } volumeLevel+=volumeLeft; #if WINVER>=0x0400 if(::midiOutSetVolume(mhMIDIOutput,volumeLevel))return FALSE; #else if(::midiOutSetVolume(mMIDIDeviceID,volumeLevel))return FALSE; #endif return TRUE; }