-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
84 lines (65 loc) · 2.36 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
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
#include "Midi.h"
#include <iostream>
using namespace std;
char PATH[] = "./res/reference.mid";
int main() {
Midi f {PATH};
auto& header = f.getHeader();
auto& tracks = f.getTracks();
cout << "File read" << endl;
cout << "File contents:" << endl;
cout << " Header:" << endl;
cout << " File format: " << (int)header.getFormat() <<
"\n Number of tracks: " << header.getNTracks() <<
"\n Time division: " << header.getDivision() << endl;
for (const auto& track : tracks) {
cout << " Track events:" << endl;
auto& events = track.getEvents();
for (const auto& trackEvent : events) {
auto* event = trackEvent.getEvent();
uint8_t* data;
if (event->getType() == MidiType::EventType::MidiEvent) {
auto* midiEvent = (MidiEvent*)event;
cout << " Midi event:" << endl;
auto status = midiEvent->getStatus();
if (status == MidiType::MidiMessageStatus::NoteOn) {
cout << "\t\t\t" << "Note " << (midiEvent->getVelocity()? "on " : "off ")
<< (int)midiEvent->getNote()
<< " on channel " << (int)midiEvent->getChannel() << endl;
} else if (status == MidiType::MidiMessageStatus::NoteOff) {
cout << "\t\t\t" << "Note off "
<< (int)midiEvent->getNote()
<< " on channel " << (int)midiEvent->getChannel() << endl;
} else {
cout << "\t\t\tStatus: 0x" << hex << (int)midiEvent->getStatus() << endl
<< "\t\t\tData: 0x" << midiEvent->getData() << dec << endl;
}
} else if (event->getType() == MidiType::EventType::SysExEvent) {
cout << "\t\tSystem exclusive event:" << endl
<< "\t\t\tStatus: 0x" << hex
<< ((MetaEvent*)event)->getStatus() << endl
<< "\t\t\tData: 0x";
data = ((MetaEvent*)event)->getData();
for (int i {0}; i < ((MetaEvent*)event)->getLength(); ++i) {
cout << (int)data[i];
}
cout << dec << endl;
} else { // event->getType() == MidiType::EventType::MetaEvent
cout << "\t\tMeta event:" << endl
<< "\t\t\tStatus: 0x" << hex
<< ((MetaEvent*)event)->getStatus() << endl
<< "\t\t\tData: 0x";
data = ((MetaEvent*)event)->getData();
for (int i {0}; i < ((MetaEvent*)event)->getLength(); ++i) {
cout << (int)data[i];
}
if (!((MetaEvent*)event)->getLength()) {
cout << "0";
}
cout << dec << endl;
}
cout << "\t\t\tLength: " << trackEvent.getDeltaTime().getData() << endl;
}
}
return 0;
}