Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "rtmidi_controller.h" | ||
2 | |||
3 | 8 | RtMidiController::RtMidiController(QObject *parent) | |
4 | : Controller{parent} | ||
5 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
|
8 | , m_midiOut() |
6 |
2/4✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
|
8 | , m_midiIn() |
7 | 8 | , m_inputMidi() | |
8 | 16 | , m_outputMidi() | |
9 | { | ||
10 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | load_input_port(); |
11 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | load_output_port(); |
12 | 8 | } | |
13 | |||
14 | 32 | RtMidiController::~RtMidiController() noexcept | |
15 | { | ||
16 | 16 | qDebug() << "Destroy MIDI controller"; | |
17 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 5 times.
|
16 | if (m_midiIn.isPortOpen()) { |
18 | 6 | qInfo() << "Input port is open, close it"; | |
19 | 6 | m_midiIn.cancelCallback(); | |
20 | 6 | m_midiIn.closePort(); | |
21 | } | ||
22 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 6 times.
|
16 | if (m_midiOut.isPortOpen()) { |
23 | 4 | qInfo() << "Output port is open, close it"; | |
24 | 4 | m_midiOut.closePort(); | |
25 | } | ||
26 | 32 | } | |
27 | |||
28 | 2 | const QList<QString> &RtMidiController::getInputMidiPort() const | |
29 | { | ||
30 | 2 | return m_inputMidi; | |
31 | } | ||
32 | |||
33 | 2 | const QList<QString> &RtMidiController::getOutputMidiPort() const | |
34 | { | ||
35 | 2 | return m_outputMidi; | |
36 | } | ||
37 | |||
38 | 7 | void RtMidiController::activateInputMidiPort(int index) | |
39 | { | ||
40 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 4 times.
|
7 | if (index >= m_inputMidi.size()) { |
41 |
4/8✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
|
3 | qCritical() << "Cannot activate port #" << index << ": out of limit"; |
42 | 3 | return; | |
43 | } | ||
44 | |||
45 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
|
4 | if (m_midiIn.isPortOpen()) { |
46 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | qInfo() << "Input port already open, close it"; |
47 | 1 | m_midiIn.cancelCallback(); | |
48 | 1 | m_midiIn.closePort(); | |
49 | } | ||
50 |
3/6✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 4 times.
✗ Branch 10 not taken.
|
4 | qDebug() << "Activate MIDI In port " << m_inputMidi.at(index); |
51 |
2/4✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
|
4 | m_midiIn.openPort(index); |
52 | 4 | m_midiIn.setCallback(emitSignalOnNewMessageStatic, this); | |
53 | } | ||
54 | |||
55 | 2 | void RtMidiController::activateInputMidiPort(QString port_name) | |
56 | { | ||
57 | 2 | int index = 0; | |
58 |
4/6✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 1 times.
|
4 | for (auto &it : m_inputMidi) { |
59 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
|
3 | if (it == port_name) |
60 | 1 | break; | |
61 | 2 | index++; | |
62 | } | ||
63 | 2 | activateInputMidiPort(index); | |
64 | 2 | } | |
65 | |||
66 | 6 | void RtMidiController::activateOutputMidiPort(int index) | |
67 | { | ||
68 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
|
6 | if (index >= m_outputMidi.size()) { |
69 |
4/8✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
|
3 | qCritical() << "Cannot activate port #" << index << ": out of limit"; |
70 | 3 | return; | |
71 | } | ||
72 | |||
73 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
|
3 | if (m_midiOut.isPortOpen()) { |
74 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | qInfo() << "Output port already open, close it"; |
75 | 1 | m_midiOut.closePort(); | |
76 | } | ||
77 |
3/6✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
|
3 | qDebug() << "Activate MIDI Out port " << m_outputMidi.at(index); |
78 |
2/4✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
|
3 | m_midiOut.openPort(index); |
79 | } | ||
80 | |||
81 | 2 | void RtMidiController::activateOutputMidiPort(QString port_name) | |
82 | { | ||
83 | 2 | int index = 0; | |
84 |
4/6✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 1 times.
|
3 | for (auto &it : m_outputMidi) { |
85 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
2 | if (it == port_name) |
86 | 1 | break; | |
87 | 1 | index++; | |
88 | } | ||
89 | 2 | activateOutputMidiPort(index); | |
90 | 2 | } | |
91 | |||
92 | 8 | void RtMidiController::load_input_port() | |
93 | { | ||
94 | 8 | size_t in_ports_count = m_midiIn.getPortCount(); | |
95 |
4/8✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 8 times.
✗ Branch 12 not taken.
|
8 | qDebug() << "There are " << in_ports_count << " MIDI input sources available"; |
96 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 8 times.
|
23 | for (size_t i = 0; i < in_ports_count; ++i) { |
97 |
2/4✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
|
15 | QString port_name = QString::fromStdString(m_midiIn.getPortName(i)); |
98 |
5/10✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 15 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 15 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 15 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 15 times.
✗ Branch 15 not taken.
|
15 | qDebug() << "\t - add #" << i << ": " << port_name; |
99 |
1/2✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
|
15 | m_inputMidi.push_back(port_name); |
100 | 15 | } | |
101 | 8 | } | |
102 | |||
103 | 8 | void RtMidiController::load_output_port() | |
104 | { | ||
105 | 8 | size_t out_ports_count = m_midiOut.getPortCount(); | |
106 |
4/8✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 8 times.
✗ Branch 12 not taken.
|
8 | qDebug() << "There are " << out_ports_count << " MIDI output ports available"; |
107 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8 times.
|
18 | for (size_t i = 0; i < out_ports_count; ++i) { |
108 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | QString port_name = QString::fromStdString(m_midiOut.getPortName(i)); |
109 |
5/10✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 10 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 10 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 10 times.
✗ Branch 15 not taken.
|
10 | qDebug() << "\t - add #" << i << ": " << port_name; |
110 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | m_outputMidi.push_back(port_name); |
111 | 10 | } | |
112 | 8 | } | |
113 | |||
114 | 1 | void RtMidiController::emitSignalOnNewMessage(double timestamp, std::vector<unsigned char> *message) | |
115 | { | ||
116 | (void) timestamp; | ||
117 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | QByteArray translatedMessage(reinterpret_cast<const char *>(message->data()), message->size()); |
118 | |||
119 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | emit newMidiMessage(translatedMessage); |
120 | 1 | } | |
121 |