2 * SysEx to SMF convertor
3 * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
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.
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.
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/>.
22 * Translates System Exclusive (SysEx) message (binary not HEX) from standard input to a Standard MIDI file (SMF).
23 * The file path must be passed as a CLI argument.
26 * cat test.syx | ./sysex2smf test.mid
29 * libsmf (in Debian-based distributions do: apt install libsmf-dev)
35 int main(int argc, char**argv) {
38 smf_t* smf = smf_new();
39 smf_track_t* track = smf_track_new();
40 smf_add_track(smf, track);
42 std::stringstream data;
43 for (char ch; std::cin.read(&ch, 1).good();) {
47 // TODO: review the (void*) – it works but…
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);
51 // TODO: check whether file exists?
52 int res = smf_save(smf, argv[1]);
54 std::cerr << "Error: Unable to save MIDI file: " << argv[1] << " Error code: " << res << std::endl;
59 std::cerr << "Usage: " << argv[0] << " 'output-file.mid'" << std::endl;