author | František Kučera <franta-hg@frantovo.cz> |
Tue, 19 May 2020 23:09:10 +0200 | |
branch | v_0 |
changeset 1 | b3c075114b95 |
parent 0 | dcdd12e654da |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* SysEx to SMF convertor |
|
3 |
* Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, version 3 of the License. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
#include <iostream> |
|
18 |
#include <sstream> |
|
19 |
#include <smf.h> |
|
20 |
||
1
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
21 |
/** |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
22 |
* Translates System Exclusive (SysEx) message (binary not HEX) from standard input to a Standard MIDI file (SMF). |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
23 |
* The file path must be passed as a CLI argument. |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
24 |
* |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
25 |
* Usage examples: |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
26 |
* cat test.syx | ./sysex2smf test.mid |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
27 |
* |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
28 |
* Dependencies: |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
29 |
* libsmf (in Debian-based distributions do: apt install libsmf-dev) |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
30 |
* |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
31 |
* @param argc |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
32 |
* @param argv |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
33 |
* @return |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
34 |
*/ |
0 | 35 |
int main(int argc, char**argv) { |
1
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
36 |
int exitCode = 0; |
0 | 37 |
if (argc == 2) { |
38 |
smf_t* smf = smf_new(); |
|
39 |
smf_track_t* track = smf_track_new(); |
|
40 |
smf_add_track(smf, track); |
|
41 |
||
42 |
std::stringstream data; |
|
43 |
for (char ch; std::cin.read(&ch, 1).good();) { |
|
44 |
data.put(ch); |
|
45 |
} |
|
46 |
||
1
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
47 |
// TODO: review the (void*) – it works but… |
0 | 48 |
smf_event_t* event = smf_event_new_from_pointer((void*) data.str().c_str(), data.tellp()); |
49 |
smf_track_add_event_pulses(track, event, 0); |
|
50 |
||
1
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
51 |
// TODO: check whether file exists? |
0 | 52 |
int res = smf_save(smf, argv[1]); |
1
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
53 |
if (res) { |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
54 |
std::cerr << "Error: Unable to save MIDI file: " << argv[1] << " Error code: " << res << std::endl; |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
55 |
exitCode = 1; |
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
56 |
} |
0 | 57 |
smf_delete(smf); |
58 |
} else { |
|
59 |
std::cerr << "Usage: " << argv[0] << " 'output-file.mid'" << std::endl; |
|
1
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
60 |
exitCode = 1; |
0 | 61 |
} |
1
b3c075114b95
documentation, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
62 |
return exitCode; |
0 | 63 |
} |