|
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 |
|
21 int main(int argc, char**argv) { |
|
22 if (argc == 2) { |
|
23 smf_t* smf = smf_new(); |
|
24 smf_track_t* track = smf_track_new(); |
|
25 smf_add_track(smf, track); |
|
26 |
|
27 std::stringstream data; |
|
28 for (char ch; std::cin.read(&ch, 1).good();) { |
|
29 data.put(ch); |
|
30 } |
|
31 |
|
32 smf_event_t* event = smf_event_new_from_pointer((void*) data.str().c_str(), data.tellp()); |
|
33 smf_track_add_event_pulses(track, event, 0); |
|
34 |
|
35 |
|
36 int res = smf_save(smf, argv[1]); |
|
37 if (res) std::cerr << "unable to save MIDI file: " << res << std::endl; |
|
38 smf_delete(smf); |
|
39 } else { |
|
40 std::cerr << "Usage: " << argv[0] << " 'output-file.mid'" << std::endl; |
|
41 } |
|
42 } |