-
Notifications
You must be signed in to change notification settings - Fork 0
/
QRetroMidi.cpp
76 lines (63 loc) · 1.23 KB
/
QRetroMidi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <QDebug>
#if QRETRO_HAVE_MIDI
#include <QMidiIn.h>
#include <QMidiOut.h>
#endif
#include "QRetroMidi.h"
QRetroMidi::QRetroMidi()
{
#if QRETRO_HAVE_MIDI
auto vals = QMidiIn::devices();
if (vals.size() > 0)
{
m_In = new QMidiIn(this);
m_InEnabled = m_In->connect(vals.firstKey());
if (m_InEnabled)
{
qDebug() << "MIDI input connected to " << vals.first();
m_In->start();
}
}
vals = QMidiOut::devices();
if (vals.size() > 0)
{
m_Out = new QMidiOut();
m_OutEnabled = m_Out->connect(vals.firstKey());
if (m_OutEnabled)
qDebug() << "MIDI output connected to " << vals.first();
}
#endif
}
bool QRetroMidi::inputEnabled(void) { return m_InEnabled; }
bool QRetroMidi::outputEnabled(void) { return m_OutEnabled; }
bool QRetroMidi::read(uint8_t *byte)
{
#if QRETRO_HAVE_MIDI
if (m_OutEnabled)
{
m_Out->sendMsg(*byte);
return true;
}
#else
Q_UNUSED(byte)
#endif
return false;
}
bool QRetroMidi::write(uint8_t byte, uint32_t delta_time)
{
#if QRETRO_HAVE_MIDI
if (m_InEnabled)
{
emit m_In->midiEvent(byte, delta_time);
return true;
}
#else
Q_UNUSED(byte)
Q_UNUSED(delta_time)
#endif
return false;
}
bool QRetroMidi::flush(void)
{
return true;
}