-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpmDJ.cpp
77 lines (71 loc) · 1.74 KB
/
pmDJ.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
#include "instMap.hpp"
#include "midiFile.hpp"
#include "smdFile.hpp"
#include "smdMidi.hpp"
#include <cstdio>
#include <exception>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
using namespace std;
typedef struct {
std::string filename;
int loopCount;
int trimAmount;
} InFile;
int main(int argc, char *argv[]) {
if(argc<3) {
cout << "Usage: " << argv[0] << " <.smd file> [parameters] [<.smd file> [parameters] ...] <.mid file>\n";
cout << "Parameters can be:\n"
<< " -l# - Loop # times\n"
<< " -t#:#.# - Trim #:#.# time off end of final loop\n";
return 0;
}
vector< InFile > inFiles;
// Parse command line
{
for(int i=1;i<argc-1;i++)
if(argv[i][0]=='-')
// Probably an option
switch(argv[i][1]) {
case 'l':
case 'L':
{
unsigned count;
sscanf(argv[i]+2,"%u",&count);
inFiles[inFiles.size()-1].loopCount = count;
} break;
case 't':
case 'T':
{
unsigned measure,beat,tick;
sscanf(argv[i]+2,"%u:%1u.%02u",&measure,&beat,&tick);
inFiles[inFiles.size()-1].trimAmount = 192*measure + 48*beat + tick;
}
break;
default:
throw runtime_error((string)"Unknown parameter: "+argv[i]);
}
else {
InFile myFile;
myFile.filename = argv[i];
myFile.loopCount=0;
myFile.trimAmount=0;
inFiles.push_back(myFile);
}
}
// Make MIDI file
smdMidi myMidi;
for(vector< InFile >::const_iterator it=inFiles.begin();it!=inFiles.end();++it) {
ifstream myHandle(it->filename.c_str());
smdSong mySmd(myHandle);
myHandle.close();
myMidi.AddToFile(mySmd,it->loopCount,it->trimAmount);
}
// Write MIDI file
ofstream myHandle(argv[argc-1]);
myMidi.Save(myHandle);
myHandle.close();
return 0;
}