-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmidiparser.cpp
More file actions
executable file
·68 lines (62 loc) · 2.1 KB
/
midiparser.cpp
File metadata and controls
executable file
·68 lines (62 loc) · 2.1 KB
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
#include "midiparser.h"
#include "MIDIFile.hpp"
#include <QDebug>
#include <QJsonArray>
#include <QJsonValue>
#include <QJsonDocument>
#include <map>
using namespace std;
MidiParser::MidiParser()
{
}
void MidiParser::test(std::string fileName){
// MIDI::File mid(fileName.c_str());
//mid.open();
fstream tmp;
tmp.open(fileName.append(".txt"), std::ios::out);
/*
MIDI::Header* header=mid.header();
// tmp << "Header" <<'\n';
// tmp << "\tFormat Type: " << header->formatType() <<'\n';
// tmp << "\tNumber of Tracks: " << header->numTracks() <<'\n';
tmp << header->formatType() << ' ' << header->numTracks() << endl;
if(header->framesPerSecond())
{
tmp << "\tFrames Per Second: " << header->framesPerSecond() <<'\n';
tmp << "\tTicks Per Frame: " << header->ticksPerFrame() <<'\n';
}
else
tmp << "\tTicks Per Beat: " << header->ticksPerBeat() <<'\n';
QJsonArray cxq;
for(int i=0;i<mid.numTracks();i++)
{
map<int, int>g;
QJsonArray wyj;
MIDI::Track* track=mid.track(i);
tmp << "Track #" << i+1 <<'\n';
int tim = 0;
for(int j=0;j<track->numEvents();j++)
{
MIDI::ChannelEvent* event = (MIDI::ChannelEvent*)track->event(j);
tim += event->deltaTime();
if ((int)event->command() == 8 || (int)event->command() == 9) {
if ((int)event->command() == 8) {
if (g.count((int)event->param1())) {
QJsonArray wkn;
//wkn.append(g[(int)event->param1()]);
wkn.append(tim);
wkn.append((int)event->param1());
wyj.append(wkn);
g.erase((int)event->param1());
}
} else {
//g[(int)event->param1()] = tim;
}
}
tmp << (int)tim << ' ' << (int)event->type() << ' ' << (int)event->command() << ' ' << (int)event->param1() << ' ' << (int)event->param2() << endl;
}
cxq.append(wyj);
}
*/
tmp.close();
}