forked from paulh002/sdrberry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMidiControle.cpp
63 lines (56 loc) · 1.21 KB
/
MidiControle.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
#include "MidiControle.h"
#include <alsa/asoundlib.h>
#include <vector>
#include "RtMidi.h"
MidiControle::MidiControle()
{
// RtMidiIn constructor
try {
midiin = new RtMidiIn();
}
catch(RtMidiError &error) {
error.printMessage();
exit(EXIT_FAILURE);
}
}
MidiControle::~MidiControle()
{
if (midiin)
delete midiin;
}
// Check inputs.
int MidiControle::check_midi_input()
{
if (midiin == nullptr)
return -1;
unsigned int nPorts = midiin->getPortCount();
std::cout << "\nThere are " << nPorts << " MIDI input sources available.\n";
std::string portName;
for (unsigned int i = 0; i < nPorts; i++) {
try {
portName = midiin->getPortName(i);
}
catch (RtMidiError &error) {
error.printMessage();
}
std::cout << " Input Port #" << i + 1 << ": " << portName << '\n';
}
return nPorts;
}
void MidiControle::openport(int port)
{
midiin->openPort(port);
//midiin->ignoreTypes(false, false, false);
}
int MidiControle::read_midi_input()
{
double stamp;
int nBytes, i;
stamp = midiin->getMessage(&message);
nBytes = message.size();
for (i = 0; i < nBytes; i++)
std::cout << "Byte " << i << " = " << (int)message[i] << ", ";
if (nBytes > 0)
std::cout << "stamp = " << stamp << std::endl;
return 0;
}