# HG changeset patch # User Chris Cannam # Date 1488792903 0 # Node ID d2ecf0acc3e29a7d81430fb728f1af5a9be52d9b # Parent 08bbbd2023c4bb8c06b8c6a0b97494556cce21e4 More useful diagnostics for MIDI startup diff -r 08bbbd2023c4 -r d2ecf0acc3e2 data/midi/MIDIInput.cpp --- 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 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);