-
Notifications
You must be signed in to change notification settings - Fork 0
/
changevolume.cpp
73 lines (62 loc) · 2.6 KB
/
changevolume.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
#include "changevolume.h"
#include <QString>
#include "MidiFile.h"
#include <string>
#include <iostream>
ChangeVolume::ChangeVolume(QString filename, int selectedNote, int highChange, int lowChange, int selectedTrack,
int lowRange,int highRange, int sigA, int sigB, bool note, bool randb)
{
cout << "Changing note " << selectedNote << " by " <<
highChange << endl;
string file = filename.toStdString().c_str();
MidiFile midifile;
midifile.read(file);
cout << midifile.status() << endl;
int tracks = midifile.getTrackCount();
int tpq = midifile.getTicksPerQuarterNote();
lowRange = tpq*lowRange*sigA;
highRange = tpq*highRange*sigA + (tpq*sigA);
cout << "Tracks: " << tracks << endl;
cout << "TPQ: " << tpq << endl;
int track = selectedTrack;
int randChange;
for (int event=0; event < midifile[track].size(); event++) {
//cout << "low " << lowRange << endl;
//cout << "Real " << midifile[track][event].tick << endl;
//cout << "high " << highRange << endl;
if (midifile[track][event].isNoteOn()) {
if (randb) {
cout << "Rand" << endl;
if (midifile[track][event].tick >= lowRange && midifile[track][event].tick < highRange){
if (note) {
cout << "note" << endl;
if (midifile[track][event][1] == selectedNote){
randChange = rand() % (highChange - lowChange) + (lowChange);
cout << randChange << endl;
midifile[track][event][2] += randChange; ///random here
}
}
else {
cout << "no note" << endl;
randChange = rand() % (highChange - lowChange) + (lowChange);
cout << randChange << endl;
midifile[track][event][2] += randChange; ///random here
}
}
} else {
if (midifile[track][event].tick >= lowRange && midifile[track][event].tick < highRange){
if (note) {
if (midifile[track][event][1] == selectedNote){
midifile[track][event][2] += highChange;
}
}
else {
midifile[track][event][2] += highChange;
}
}
}
}
}
//midifile.sortTrack(midifile[track]);
midifile.write("output.mid");
}