comparison data/midi/MIDIInput.cpp @ 1527:710e6250a401 zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:14 +0100
parents cee1be4fb8c1
children 70e172e6cc59
comparison
equal deleted inserted replaced
1324:d4a28d1479a8 1527:710e6250a401
18 #include "rtmidi/RtMidi.h" 18 #include "rtmidi/RtMidi.h"
19 19
20 #include "system/System.h" 20 #include "system/System.h"
21 21
22 MIDIInput::MIDIInput(QString name, FrameTimer *timer) : 22 MIDIInput::MIDIInput(QString name, FrameTimer *timer) :
23 m_rtmidi(), 23 m_rtmidi(0),
24 m_frameTimer(timer), 24 m_frameTimer(timer),
25 m_buffer(1023) 25 m_buffer(1023)
26 { 26 {
27 try { 27 try {
28 m_rtmidi = new RtMidiIn(name.toStdString()); 28 std::vector<RtMidi::Api> apis;
29 m_rtmidi->setCallback(staticCallback, this); 29 RtMidi::getCompiledApi(apis);
30 m_rtmidi->openPort(0, tr("Input").toStdString()); 30 RtMidi::Api preferredApi = RtMidi::UNSPECIFIED;
31 } catch (RtError e) { 31 for (auto a: apis) {
32 e.printMessage(); 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;
40 } else {
41
42 m_rtmidi = new RtMidiIn(preferredApi, name.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 }
65 }
66
67 } catch (const RtMidiError &e) {
68 SVCERR << "ERROR: RtMidi error: " << e.getMessage() << endl;
33 delete m_rtmidi; 69 delete m_rtmidi;
34 m_rtmidi = 0; 70 m_rtmidi = 0;
35 } 71 }
36 } 72 }
37 73
78 MIDIInput::postEvent(MIDIEvent e) 114 MIDIInput::postEvent(MIDIEvent e)
79 { 115 {
80 int count = 0, max = 5; 116 int count = 0, max = 5;
81 while (m_buffer.getWriteSpace() == 0) { 117 while (m_buffer.getWriteSpace() == 0) {
82 if (count == max) { 118 if (count == max) {
83 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;
84 return; 120 return;
85 } 121 }
86 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;
87 SVDEBUG << "Waiting for something to be processed" << endl; 123 SVDEBUG << "Waiting for something to be processed" << endl;
88 #ifdef _WIN32 124 #ifdef _WIN32
89 Sleep(1); 125 Sleep(1);
90 #else 126 #else
91 sleep(1); 127 sleep(1);