diff options
author | Chris Xiong <chirs241097@gmail.com> | 2016-04-07 23:39:02 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2016-04-07 23:39:02 +0800 |
commit | 8f8782f43bd838e825f3792b611d27fffa90399b (patch) | |
tree | 1fbd96dd7ce061010edacf67f72f0ffb07889edf /core/qmpmidimapperrtmidi.cpp | |
parent | 70fd2d85c1bd6fb8732e680e8fda9d36c317c732 (diff) | |
download | QMidiPlayer-8f8782f43bd838e825f3792b611d27fffa90399b.tar.xz |
Lunatic Princess.
Diffstat (limited to 'core/qmpmidimapperrtmidi.cpp')
-rw-r--r-- | core/qmpmidimapperrtmidi.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/core/qmpmidimapperrtmidi.cpp b/core/qmpmidimapperrtmidi.cpp new file mode 100644 index 0000000..adba267 --- /dev/null +++ b/core/qmpmidimapperrtmidi.cpp @@ -0,0 +1,88 @@ +#include <cstdio> +#include <cstring> +#include <vector> +#include "RtMidi.h" +#include "qmpmidimappers.hpp" +RtMidiOut* qmpMidiMapperRtMidi::dummy=NULL; +qmpMidiMapperRtMidi::qmpMidiMapperRtMidi() +{ + dummy=new RtMidiOut(); + memset(ports,0,sizeof(ports)); +} +qmpMidiMapperRtMidi::~qmpMidiMapperRtMidi() +{ + delete dummy;for(int i=0;i<16;++i)if(ports[i])delete ports[i]; +} +int qmpMidiMapperRtMidi::enumDevices() +{ + return dummy->getPortCount(); +} +std::string qmpMidiMapperRtMidi::deviceName(int id) +{ + fprintf(stderr,"port #%d: %s\n",id,dummy->getPortName(id).c_str()); + return dummy->getPortName(id); +} +int qmpMidiMapperRtMidi::deviceInit(int id) +{ + int i=0;for(;ports[i]&&i<16;++i); + if(i==16)return -1; + try + { + ports[i]=new RtMidiOut(); + ports[i]->openPort(id); + } + catch(RtMidiError e) + { + printf("Device initialization failure: %s\n",e.what()); + ports[i]=NULL; + return -1; + } + return i; +} +void qmpMidiMapperRtMidi::deviceDeinit(int iid) +{ + if(ports[iid]){ports[iid]->closePort();delete ports[iid];ports[iid]=NULL;} +} +void qmpMidiMapperRtMidi::noteOn(int iid,int ch,int key,int vel) +{ + if(!ports[iid])return;ch&=0x0F; + std::vector<unsigned char>message; + message.push_back(0x90|ch); + message.push_back(key); + message.push_back(vel); + ports[iid]->sendMessage(&message); +} +void qmpMidiMapperRtMidi::noteOff(int iid,int ch,int key) +{ + if(!ports[iid])return;ch&=0x0F; + std::vector<unsigned char>message; + message.push_back(0x80|ch);message.push_back(key);message.push_back(0); + ports[iid]->sendMessage(&message); +} +void qmpMidiMapperRtMidi::ctrlChange(int iid,int ch,int cc,int val) +{ + if(!ports[iid])return;ch&=0x0F; + std::vector<unsigned char>message; + message.push_back(0xB0|ch);message.push_back(cc);message.push_back(val); + ports[iid]->sendMessage(&message); +} +void qmpMidiMapperRtMidi::progChange(int iid,int ch,int val) +{ + if(!ports[iid])return;ch&=0x0F; + std::vector<unsigned char>message; + message.push_back(0xC0|ch);message.push_back(val); + ports[iid]->sendMessage(&message); +} +void qmpMidiMapperRtMidi::pitchBend(int iid,int ch,int val) +{ + if(!ports[iid])return;ch&=0x0F; + std::vector<unsigned char>message; + message.push_back(0xE0|ch);message.push_back(val&0xFF); + message.push_back(val>>8);ports[iid]->sendMessage(&message); +} +void qmpMidiMapperRtMidi::sysEx(int iid,int length,const char *data) +{ + if(!ports[iid])return; + std::vector<unsigned char>message(data,data+length); + ports[iid]->sendMessage(&message); +} |