From fd3fc10798fb4c8d63f6f3e538018774741f2b15 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Wed, 21 Jun 2017 16:28:03 +0800 Subject: Fixed a bunch of bugs and crashes in the RtMidi output device. --- core/qmpmidioutrtmidi.cpp | 8 +++++--- core/qmpmidiplay.cpp | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/qmpmidioutrtmidi.cpp b/core/qmpmidioutrtmidi.cpp index 776eb6b..295e87b 100644 --- a/core/qmpmidioutrtmidi.cpp +++ b/core/qmpmidioutrtmidi.cpp @@ -37,6 +37,7 @@ void qmpMidiOutRtMidi::basicMessage(uint8_t type,uint8_t p1,uint8_t p2) std::vectormsg; msg.push_back(type); msg.push_back(p1); + if(((type&0xF0)!=0xC0)&&((type&0xF0)!=0xD0)) msg.push_back(p2); outport->sendMessage(&msg); } @@ -71,9 +72,10 @@ void qmpMidiOutRtMidi::reset(uint8_t ch) basicMessage(0xB0|ch,120,0); basicMessage(0xB0|ch,121,0); } -void qmpMidiOutRtMidi::onMapped(uint8_t,int refcnt) +void qmpMidiOutRtMidi::onMapped(uint8_t,int) { - if(!outport||outport->isPortOpen()||refcnt)return; + if(!outport)deviceInit(); + if(outport->isPortOpen())return; try { outport->openPort(portid); @@ -87,7 +89,7 @@ void qmpMidiOutRtMidi::onMapped(uint8_t,int refcnt) void qmpMidiOutRtMidi::onUnmapped(uint8_t ch,int refcnt) { panic(ch); - if(!refcnt)outport->closePort(); + if(!refcnt&&outport)outport->closePort(); } RtMidiOut* qmpRtMidiManager::dummy=NULL; diff --git a/core/qmpmidiplay.cpp b/core/qmpmidiplay.cpp index cca77d0..e758457 100644 --- a/core/qmpmidiplay.cpp +++ b/core/qmpmidiplay.cpp @@ -256,7 +256,8 @@ CMidiPlayer::CMidiPlayer() memset(eventReaderCBuserdata,0,sizeof(eventReaderCBuserdata)); memset(fileReadFinishCB,0,sizeof(fileReadFinishCB)); memset(fileReadFinishCBuserdata,0,sizeof(fileReadFinishCBuserdata)); - memset(mappedoutput,0xFF,sizeof(mappedoutput)); + memset(mappedoutput,0,sizeof(mappedoutput)); + mididev[0].refcnt=16; memset(chstatus,0,sizeof(chstatus)); for(int i=0;i<16;++i) chstatus[i][7]=100,chstatus[i][11]=127, @@ -484,7 +485,6 @@ void CMidiPlayer::setChannelOutput(int ch,int outid) { SMidiDev& dold=mididev[origoutput]; dold.dev->onUnmapped(ch,--dold.refcnt); - } } uint8_t* CMidiPlayer::getChstates(){return chstate;} -- cgit v1.2.3