forked from craigsapp/midifile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmid2hex.cpp
66 lines (52 loc) · 1.37 KB
/
mid2hex.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
//
// Programmer: Craig Stuart Sapp <[email protected]>
// Creation Date: Sun Apr 15 12:11:36 PDT 2018
// Last Modified: Sun Apr 15 12:11:40 PDT 2018
// Filename: midifile/src-programs/readstatus.cpp
// Syntax: C++11
//
// Description: Convert a binary standard MIDI file (or binasc MIDI file,
// or hex-byte MIDI file) into a hex byte-code MIDI file.
//
#include "MidiFile.h"
#include "Options.h"
#include <iostream>
using namespace std;
using namespace smf;
int main(int argc, char** argv) {
Options options;
options.define("o|output=s", "output file name");
options.define("w|width=i:25", "hex bytes per text line");
options.process(argc, argv);
MidiFile midifile;
if (options.getArgCount() == 0) {
midifile.read(cin);
} else if (options.getArgCount() == 1) {
midifile.read(options.getArg(1));
} else {
cerr << "Only one file input allowed" << endl;
exit(1);
}
string filename = options.getString("output");
if (filename.empty()) {
midifile.writeHex(cout, options.getInteger("width"));
} else {
midifile.writeHex(filename, options.getInteger("width"));
}
return 0;
}
/* test data save to a file:
"MThd"
4'6
2'0
2'1
2'100
"MTRk"
4'13
v0 90 '60 '80
v200 90 '60 '80
v0 FF 2F 00
output data:
4d 54 68 64 00 00 00 06 00 00 00 01 00 78 4d 54 72 6b 00 00 00 04 00 ff 2f
00
*/