This repository has been archived by the owner on Feb 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMidiIO.cpp
189 lines (158 loc) · 3.69 KB
/
MidiIO.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include <QDebug>
#include "MidiIO.h"
#include "RtMidi.h"
MidiIO::MidiIO()
{
mmcNames[0x01] = "Stop";
mmcNames[0x02] = "Play";
mmcNames[0x03] = "Deferred Play";
mmcNames[0x04] = "Fast Forward";
mmcNames[0x05] = "Rewind";
mmcNames[0x06] = "Record Strobe (Punch In)";
mmcNames[0x07] = "Record Exit (Punch out)";
mmcNames[0x08] = "Record Ready";
mmcNames[0x09] = "Pause";
mmcNames[0x0A] = "Eject";
mmcNames[0x0B] = "Chase";
mmcNames[0x0C] = "Error Reset";
mmcNames[0x0D] = "MMC Reset";
mmcNames[0x20] = "Jog Start";
mmcNames[0x21] = "Jog Stop";
mmcNames[0x40] = "Write";
mmcNames[0x41] = "Masked Write";
mmcNames[0x42] = "Read";
mmcNames[0x43] = "Update";
mmcNames[0x44] = "Locate/Go to";
mmcNames[0x45] = "Variable Play";
mmcNames[0x46] = "Search";
mmcNames[0x47] = "Shuttle";
mmcNames[0x48] = "Step";
mmcNames[0x49] = "Assign system master";
mmcNames[0x4A] = "Generator Command";
mmcNames[0x4B] = "MTC Command";
mmcNames[0x4C] = "Move";
mmcNames[0x4D] = "Add";
mmcNames[0x4E] = "Subtract";
mmcNames[0x4F] = "Drop frame adjust";
mmcNames[0x50] = "Procedure";
mmcNames[0x51] = "Event";
mmcNames[0x52] = "Group";
mmcNames[0x53] = "Command Segment";
mmcNames[0x54] = "Deferred variable play";
mmcNames[0x55] = "Record strobe variable";
mmcNames[0x7C] = "Wait";
mmcNames[0x7F] = "Resume";
m_stop = 0;
try {
midiin = new RtMidiIn();
#ifndef __WINDOWS_MM__
if (midiin != NULL)
midiin->openVirtualPort("nanonoise");
#endif
midiout = new RtMidiOut();
#ifndef __WINDOWS_MM__
if (midiout != NULL)
midiout->openVirtualPort("nanonoise (filtered)");
#endif
}
catch ( RtError &error ) {
error.printMessage();
exit( EXIT_FAILURE );
}
lastOpenPort = -1;
}
MidiIO::~MidiIO()
{
// if (midiin != NULL)
// delete midiin;
// if (midiout != NULL)
// delete midiout;
}
void MidiIO::sig_handler(int)
{
m_stop = 1;
}
void MidiIO::stop()
{
m_stop = 1;
}
void MidiIO::openPort(int nr)
{
if (lastOpenPort != -1 && midiin != NULL) {
midiin->closePort();
}
if (nr != -1 && midiin != NULL) {
midiin->openPort(nr);
}
lastOpenPort = nr;
}
void MidiIO::openInputPortByName(QString portName)
{
openPort(getInputPorts().indexOf(portName));
}
QStringList MidiIO::getInputPorts()
{
QStringList ports;
if (midiin != NULL) {
for ( unsigned int i=0; i<midiin->getPortCount(); ++i ) {
try {
ports.append(QString(midiin->getPortName(i).c_str()));
}
catch ( RtError &error ) {
error.printMessage();
break;
}
}
}
return ports;
}
QStringList MidiIO::getOutputPorts()
{
QStringList ports;
if (midiout != NULL) {
for ( unsigned int i=0; i<midiout->getPortCount(); ++i ) {
try {
ports.append(QString(midiout->getPortName(i).c_str()));
}
catch ( RtError &error ) {
error.printMessage();
break;
}
}
}
return ports;
}
void midiRecivedCallback( double, std::vector< unsigned char > *message, void *userData)
{
QString m;
std::vector< unsigned char >::const_iterator i;
for(i=message->begin(); i!=message->end(); ++i){
m.append(*i);
}
((MidiIO *) userData)->sendMidiRecived(new MidiEvent(m));
}
void MidiIO::send(QString message)
{
std::vector< unsigned char > msg;
for(int i=0; i<message.size(); ++i){
msg.push_back(message.at(i).toLatin1());
}
if (midiout != NULL)
midiout->sendMessage(&msg);
}
void MidiIO::sendMidiRecived(MidiEvent *e)
{
QString m = QString(e->message);
emit midiRecived(e);
}
void MidiIO::run()
{
if (midiin != NULL) {
midiin->setCallback(&midiRecivedCallback, this);
midiin->ignoreTypes( false, false, false );
}
}
QString MidiIO::getMMCName(int cmd) const
{
return mmcNames.value(cmd);
}