franta-hg@0: /**
franta-hg@0: * SysEx to SMF convertor
franta-hg@0: * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
franta-hg@0: *
franta-hg@0: * This program is free software: you can redistribute it and/or modify
franta-hg@0: * it under the terms of the GNU General Public License as published by
franta-hg@0: * the Free Software Foundation, version 3 of the License.
franta-hg@0: *
franta-hg@0: * This program is distributed in the hope that it will be useful,
franta-hg@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@0: * GNU General Public License for more details.
franta-hg@0: *
franta-hg@0: * You should have received a copy of the GNU General Public License
franta-hg@0: * along with this program. If not, see .
franta-hg@0: */
franta-hg@0: #include
franta-hg@0: #include
franta-hg@0: #include
franta-hg@0:
franta-hg@1: /**
franta-hg@1: * Translates System Exclusive (SysEx) message (binary not HEX) from standard input to a Standard MIDI file (SMF).
franta-hg@1: * The file path must be passed as a CLI argument.
franta-hg@1: *
franta-hg@1: * Usage examples:
franta-hg@1: * cat test.syx | ./sysex2smf test.mid
franta-hg@1: *
franta-hg@1: * Dependencies:
franta-hg@1: * libsmf (in Debian-based distributions do: apt install libsmf-dev)
franta-hg@1: *
franta-hg@1: * @param argc
franta-hg@1: * @param argv
franta-hg@1: * @return
franta-hg@1: */
franta-hg@0: int main(int argc, char**argv) {
franta-hg@1: int exitCode = 0;
franta-hg@0: if (argc == 2) {
franta-hg@0: smf_t* smf = smf_new();
franta-hg@0: smf_track_t* track = smf_track_new();
franta-hg@0: smf_add_track(smf, track);
franta-hg@0:
franta-hg@0: std::stringstream data;
franta-hg@0: for (char ch; std::cin.read(&ch, 1).good();) {
franta-hg@0: data.put(ch);
franta-hg@0: }
franta-hg@0:
franta-hg@1: // TODO: review the (void*) – it works but…
franta-hg@0: smf_event_t* event = smf_event_new_from_pointer((void*) data.str().c_str(), data.tellp());
franta-hg@0: smf_track_add_event_pulses(track, event, 0);
franta-hg@0:
franta-hg@1: // TODO: check whether file exists?
franta-hg@0: int res = smf_save(smf, argv[1]);
franta-hg@1: if (res) {
franta-hg@1: std::cerr << "Error: Unable to save MIDI file: " << argv[1] << " Error code: " << res << std::endl;
franta-hg@1: exitCode = 1;
franta-hg@1: }
franta-hg@0: smf_delete(smf);
franta-hg@0: } else {
franta-hg@0: std::cerr << "Usage: " << argv[0] << " 'output-file.mid'" << std::endl;
franta-hg@1: exitCode = 1;
franta-hg@0: }
franta-hg@1: return exitCode;
franta-hg@0: }