Mercurial > hg > svcore
diff data/midi/MIDIInput.cpp @ 1400:d2ecf0acc3e2
More useful diagnostics for MIDI startup
author | Chris Cannam |
---|---|
date | Mon, 06 Mar 2017 09:35:03 +0000 |
parents | b0533d195c83 |
children | cee1be4fb8c1 |
line wrap: on
line diff
--- a/data/midi/MIDIInput.cpp Mon Mar 06 09:34:29 2017 +0000 +++ b/data/midi/MIDIInput.cpp Mon Mar 06 09:35:03 2017 +0000 @@ -27,15 +27,45 @@ try { std::vector<RtMidi::Api> apis; RtMidi::getCompiledApi(apis); - if (apis.empty()) { - SVDEBUG << "MIDIInput: No RtMidi APIs compiled in" << endl; + RtMidi::Api preferredApi = RtMidi::UNSPECIFIED; + for (auto a: apis) { + if (a == RtMidi::UNSPECIFIED || a == RtMidi::RTMIDI_DUMMY) { + continue; + } + preferredApi = a; + break; + } + if (preferredApi == RtMidi::UNSPECIFIED) { + SVCERR << "ERROR: MIDIInput: No RtMidi APIs compiled in" << endl; } else { - m_rtmidi = new RtMidiIn(apis[0], name.toStdString()); - m_rtmidi->setCallback(staticCallback, this); - m_rtmidi->openPort(0, tr("Input").toStdString()); + + m_rtmidi = new RtMidiIn(preferredApi, name.toStdString()); + + int n = m_rtmidi->getPortCount(); + + if (n == 0) { + + SVDEBUG << "NOTE: MIDIInput: No input ports available" << endl; + delete m_rtmidi; + m_rtmidi = 0; + + } else { + + m_rtmidi->setCallback(staticCallback, this); + + SVDEBUG << "MIDIInput: Available ports are:" << endl; + for (int i = 0; i < n; ++i) { + SVDEBUG << i << ". " << m_rtmidi->getPortName(i) << endl; + } + SVDEBUG << "MIDIInput: Using first port (\"" + << m_rtmidi->getPortName(0) << "\")" << endl; + + m_rtmidi->openPort(0, tr("Input").toStdString()); + } } + } catch (RtMidiError e) { - e.printMessage(); + SVCERR << "ERROR: RtMidi error: " << e.getMessage() << endl; delete m_rtmidi; m_rtmidi = 0; } @@ -86,10 +116,10 @@ int count = 0, max = 5; while (m_buffer.getWriteSpace() == 0) { if (count == max) { - cerr << "ERROR: MIDIInput::postEvent: MIDI event queue is full and not clearing -- abandoning incoming event" << endl; + SVCERR << "ERROR: MIDIInput::postEvent: MIDI event queue is full and not clearing -- abandoning incoming event" << endl; return; } - cerr << "WARNING: MIDIInput::postEvent: MIDI event queue (capacity " << m_buffer.getSize() << " is full!" << endl; + SVCERR << "WARNING: MIDIInput::postEvent: MIDI event queue (capacity " << m_buffer.getSize() << " is full!" << endl; SVDEBUG << "Waiting for something to be processed" << endl; #ifdef _WIN32 Sleep(1);