-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmidi-raw.cpp
47 lines (40 loc) · 1.14 KB
/
midi-raw.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
#include "MidiFile.h"
#include "Options.h"
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;
using namespace smf;
int main(int argc, char** argv){
if(argc!=3)
return 1;
const char * inf =argv[1]
const char * outf=argv[2];
MidiFile midifile;
auto out=fopen(outf,"w");
if(out==NULL)
return 1;
midifile.read(inf);
midifile.doTimeAnalysis();
midifile.linkNotePairs();
int tracks = midifile.getTrackCount();
for (int id=0; id<tracks; id++) {
if(id!=0)
fprintf(out,"\n");
fprintf(out,"channel:%d\n",id);
int notenum=midifile[id].size();
for(int nn=0;nn<notenum;nn++){
int lastTick=-1;
if (midifile[id][nn].isNoteOn() && midifile[id][nn].size()>=3){
int begin =midifile[id][nn].tick;
int note =midifile[id][nn][1];
if(lastTick!=begin && lastTick!=-1)
fprintf(out,"\n");
lastTick=begin;
fprintf(out,"%d ",note);
}
}
}
fclose(out);
return 0;
}