From 20d25423952b4bb2f54b695cefce509d895d89b2 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sun, 19 Apr 2020 23:59:07 +0800 Subject: Fix unintended control values sent to external midi devices. --- core/qmpmidioutrtmidi.cpp | 2 ++ core/qmpmidiplay.cpp | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/core/qmpmidioutrtmidi.cpp b/core/qmpmidioutrtmidi.cpp index 3ed8a4a..2f7125e 100644 --- a/core/qmpmidioutrtmidi.cpp +++ b/core/qmpmidioutrtmidi.cpp @@ -194,6 +194,7 @@ void qmpMidiOutRtMidi::deviceInit() try { outport=new RtMidiOut(); + reset(0xFF); } catch(RtMidiError &e) { @@ -337,6 +338,7 @@ void qmpMidiOutRtMidi::setInitializerFile(const char* path) { if(devinit)delete devinit; devinit=qmpDeviceInitializer::parse(path); + reset(0xFF); } std::vector> qmpRtMidiManager::devices; diff --git a/core/qmpmidiplay.cpp b/core/qmpmidiplay.cpp index 2fed6a8..cb9e726 100644 --- a/core/qmpmidiplay.cpp +++ b/core/qmpmidiplay.cpp @@ -297,6 +297,8 @@ CMidiPlayer::CMidiPlayer() memset(mappedoutput,0,sizeof(mappedoutput)); mididev[0].refcnt=16; memset(chstatus,0,sizeof(chstatus)); + for(int i=0;i<16;++i) + memset(chstatus[i],0xff,128*sizeof(uint8_t)); #ifdef _WIN32 QueryPerformanceFrequency((LARGE_INTEGER*)&pf); #endif @@ -359,9 +361,7 @@ void CMidiPlayer::playerInit() sendSysEx=true;memset(rpnid,0xFF,sizeof(rpnid));memset(rpnval,0xFF,sizeof(rpnval)); memset(chstatus,0,sizeof(chstatus)); for(int i=0;i<16;++i) - { memset(chstatus[i],0xff,128*sizeof(uint8_t)); - } } void CMidiPlayer::playerDeinit() { @@ -424,6 +424,11 @@ uint32_t CMidiPlayer::isFinished(){return finished;} void CMidiPlayer::setResumed(){resumed=true;} void CMidiPlayer::setWaitVoice(bool wv){waitvoice=wv;} +void CMidiPlayer::registerFluidOptions(qmpPluginAPI *coreapi) +{ + internalFluid->registerOptions(coreapi); +} + void CMidiPlayer::setChannelPreset(int ch,int b,int p) { chstatus[ch][128]=p; @@ -506,9 +511,16 @@ void CMidiPlayer::setChannelOutput(int ch,int outid) SMidiDev& dnew=mididev[outid]; dnew.dev->onMapped(ch,++dnew.refcnt); for(int i=0;i<124;++i) - if(i!=6&&i!=38&&i!=100&&i!=101)//avoid sending RPN/NRPN - dnew.dev->basicMessage(0xB0|ch,i,chstatus[ch][i]); - dnew.dev->basicMessage(0xC0|ch,chstatus[ch][128],0); + { + if(i!=6&&i!=38&&i!=100&&i!=101)//avoid sending RPN/NRPN + { + unsigned st=chstatus[ch][i]; + if(!~st) + st=dnew.dev->getInitialCCValue(i,ch); + dnew.dev->basicMessage(0xB0|ch,i,chstatus[ch][i]); + } + } + dnew.dev->basicMessage(0xC0|ch,~chstatus[ch][128]?chstatus[ch][128]:dnew.dev->getInitialCCValue(128,ch),0); mappedoutput[ch]=outid; if(~origoutput) { -- cgit v1.2.3