forked from Riateche/piano-keyboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
37 lines (34 loc) · 1 KB
/
main.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
#include <QtCore/QCoreApplication>
#include "portmidi.h"
#include <iostream>
#include <QString>
#include <QDebug>
#include "Midi_reader.h"
#define MIDI_DEVICE_NAME "YAMAHA"
using namespace std;
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
qDebug() << "started!";
int good_id = -1;
int count = Pm_CountDevices();
for(int i = 0; i < count; i++) {
const PmDeviceInfo* info = Pm_GetDeviceInfo(i);
if ( info->input == 1 && QString(info->name).contains(MIDI_DEVICE_NAME)) {
good_id = i;
}
qDebug() << i << (good_id == i? "(*)":"") << ": " << info->name << " input: " << info->input << " output: " << info->output;
}
if (good_id < 0) {
qDebug() << "Device not found";
return 1;
}
PortMidiStream* s = 0;
PmError e = Pm_OpenInput(&s, good_id, 0, 100, 0, 0);
if (e != pmNoError) {
qDebug() << "Can't open input, error: " << e << endl;
return 2;
}
qDebug() << "Open successful: " << s << endl;
Midi_reader mini_reader(s);
return a.exec();
}