diff options
author | Chris Xiong <chirs241097@gmail.com> | 2019-12-04 23:02:40 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2019-12-04 23:02:40 +0800 |
commit | 06496661120f7858f26a29f76631e6f0a0ebae7f (patch) | |
tree | 569d912a4d10a9439e2def8d71e5d9dcafe2cb95 /core/qmpmidioutrtmidi.cpp | |
parent | 96a17cb0283647b7a5b7afa9c35a5d1d2b8d6fc7 (diff) | |
download | QMidiPlayer-06496661120f7858f26a29f76631e6f0a0ebae7f.tar.xz |
Do not crash if midi device is disconnected during the playback.
Linux build no longer searches working directory for plugins. Instead
it should search the plugin folder in the executable directory.
Documentation update.
Diffstat (limited to 'core/qmpmidioutrtmidi.cpp')
-rw-r--r-- | core/qmpmidioutrtmidi.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/core/qmpmidioutrtmidi.cpp b/core/qmpmidioutrtmidi.cpp index 76b12e6..3ed8a4a 100644 --- a/core/qmpmidioutrtmidi.cpp +++ b/core/qmpmidioutrtmidi.cpp @@ -197,7 +197,7 @@ void qmpMidiOutRtMidi::deviceInit() } catch(RtMidiError &e) { - printf("Cannot create RtMidi Output instance: %s\n",e.what()); + fprintf(stderr,"Cannot create RtMidi Output instance: %s\n",e.what()); outport=nullptr; } } @@ -214,13 +214,27 @@ void qmpMidiOutRtMidi::basicMessage(uint8_t type,uint8_t p1,uint8_t p2) msg.push_back(p1); if(((type&0xF0)!=0xC0)&&((type&0xF0)!=0xD0)) msg.push_back(p2); - outport->sendMessage(&msg); + try + { + outport->sendMessage(&msg); + } + catch(RtMidiError &e) + { + fprintf(stderr,"Failed to send midi message: %s\n",e.what()); + } } void qmpMidiOutRtMidi::extendedMessage(uint32_t length,const char *data) { if(!outport||!outport->isPortOpen())return; std::vector<unsigned char>msg(data,data+length); - outport->sendMessage(&msg); + try + { + outport->sendMessage(&msg); + } + catch(RtMidiError &e) + { + fprintf(stderr,"Failed to send midi message: %s\n",e.what()); + } } void qmpMidiOutRtMidi::rpnMessage(uint8_t ch,uint16_t type,uint16_t val) { @@ -271,7 +285,7 @@ void qmpMidiOutRtMidi::onMapped(uint8_t,int) } catch(RtMidiError &e) { - printf("Device initialization failure: %s\n",e.what()); + fprintf(stderr,"Device initialization failure: %s\n",e.what()); } } @@ -333,7 +347,7 @@ std::vector<std::pair<qmpMidiOutRtMidi*,std::string>> qmpRtMidiManager::getDevic try{dummy=new RtMidiOut();} catch(RtMidiError &e) { - printf("Failed to initialize the dummy device: %s\n",e.what()); + fprintf(stderr,"Failed to initialize the dummy device: %s\n",e.what()); return{}; } for(unsigned i=0;i<dummy->getPortCount();++i) |