--- a/sysex2smf.cpp Tue May 19 22:56:20 2020 +0200
+++ b/sysex2smf.cpp Tue May 19 23:09:10 2020 +0200
@@ -18,7 +18,22 @@
#include <sstream>
#include <smf.h>
+/**
+ * Translates System Exclusive (SysEx) message (binary not HEX) from standard input to a Standard MIDI file (SMF).
+ * The file path must be passed as a CLI argument.
+ *
+ * Usage examples:
+ * cat test.syx | ./sysex2smf test.mid
+ *
+ * Dependencies:
+ * libsmf (in Debian-based distributions do: apt install libsmf-dev)
+ *
+ * @param argc
+ * @param argv
+ * @return
+ */
int main(int argc, char**argv) {
+ int exitCode = 0;
if (argc == 2) {
smf_t* smf = smf_new();
smf_track_t* track = smf_track_new();
@@ -29,14 +44,20 @@
data.put(ch);
}
+ // TODO: review the (void*) – it works but…
smf_event_t* event = smf_event_new_from_pointer((void*) data.str().c_str(), data.tellp());
smf_track_add_event_pulses(track, event, 0);
-
+ // TODO: check whether file exists?
int res = smf_save(smf, argv[1]);
- if (res) std::cerr << "unable to save MIDI file: " << res << std::endl;
+ if (res) {
+ std::cerr << "Error: Unable to save MIDI file: " << argv[1] << " Error code: " << res << std::endl;
+ exitCode = 1;
+ }
smf_delete(smf);
} else {
std::cerr << "Usage: " << argv[0] << " 'output-file.mid'" << std::endl;
+ exitCode = 1;
}
+ return exitCode;
}