comparison 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
comparison
equal deleted inserted replaced
1399:08bbbd2023c4 1400:d2ecf0acc3e2
25 m_buffer(1023) 25 m_buffer(1023)
26 { 26 {
27 try { 27 try {
28 std::vector<RtMidi::Api> apis; 28 std::vector<RtMidi::Api> apis;
29 RtMidi::getCompiledApi(apis); 29 RtMidi::getCompiledApi(apis);
30 if (apis.empty()) { 30 RtMidi::Api preferredApi = RtMidi::UNSPECIFIED;
31 SVDEBUG << "MIDIInput: No RtMidi APIs compiled in" << endl; 31 for (auto a: apis) {
32 if (a == RtMidi::UNSPECIFIED || a == RtMidi::RTMIDI_DUMMY) {
33 continue;
34 }
35 preferredApi = a;
36 break;
37 }
38 if (preferredApi == RtMidi::UNSPECIFIED) {
39 SVCERR << "ERROR: MIDIInput: No RtMidi APIs compiled in" << endl;
32 } else { 40 } else {
33 m_rtmidi = new RtMidiIn(apis[0], name.toStdString()); 41
34 m_rtmidi->setCallback(staticCallback, this); 42 m_rtmidi = new RtMidiIn(preferredApi, name.toStdString());
35 m_rtmidi->openPort(0, tr("Input").toStdString()); 43
44 int n = m_rtmidi->getPortCount();
45
46 if (n == 0) {
47
48 SVDEBUG << "NOTE: MIDIInput: No input ports available" << endl;
49 delete m_rtmidi;
50 m_rtmidi = 0;
51
52 } else {
53
54 m_rtmidi->setCallback(staticCallback, this);
55
56 SVDEBUG << "MIDIInput: Available ports are:" << endl;
57 for (int i = 0; i < n; ++i) {
58 SVDEBUG << i << ". " << m_rtmidi->getPortName(i) << endl;
59 }
60 SVDEBUG << "MIDIInput: Using first port (\""
61 << m_rtmidi->getPortName(0) << "\")" << endl;
62
63 m_rtmidi->openPort(0, tr("Input").toStdString());
64 }
36 } 65 }
66
37 } catch (RtMidiError e) { 67 } catch (RtMidiError e) {
38 e.printMessage(); 68 SVCERR << "ERROR: RtMidi error: " << e.getMessage() << endl;
39 delete m_rtmidi; 69 delete m_rtmidi;
40 m_rtmidi = 0; 70 m_rtmidi = 0;
41 } 71 }
42 } 72 }
43 73
84 MIDIInput::postEvent(MIDIEvent e) 114 MIDIInput::postEvent(MIDIEvent e)
85 { 115 {
86 int count = 0, max = 5; 116 int count = 0, max = 5;
87 while (m_buffer.getWriteSpace() == 0) { 117 while (m_buffer.getWriteSpace() == 0) {
88 if (count == max) { 118 if (count == max) {
89 cerr << "ERROR: MIDIInput::postEvent: MIDI event queue is full and not clearing -- abandoning incoming event" << endl; 119 SVCERR << "ERROR: MIDIInput::postEvent: MIDI event queue is full and not clearing -- abandoning incoming event" << endl;
90 return; 120 return;
91 } 121 }
92 cerr << "WARNING: MIDIInput::postEvent: MIDI event queue (capacity " << m_buffer.getSize() << " is full!" << endl; 122 SVCERR << "WARNING: MIDIInput::postEvent: MIDI event queue (capacity " << m_buffer.getSize() << " is full!" << endl;
93 SVDEBUG << "Waiting for something to be processed" << endl; 123 SVDEBUG << "Waiting for something to be processed" << endl;
94 #ifdef _WIN32 124 #ifdef _WIN32
95 Sleep(1); 125 Sleep(1);
96 #else 126 #else
97 sleep(1); 127 sleep(1);