documentation, exit code v_0 v0.1
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 19 May 2020 23:09:10 +0200
branchv_0
changeset 1b3c075114b95
parent 0 dcdd12e654da
child 2 f569e23f1b3f
documentation, exit code
sysex2smf.cpp
     1.1 --- a/sysex2smf.cpp	Tue May 19 22:56:20 2020 +0200
     1.2 +++ b/sysex2smf.cpp	Tue May 19 23:09:10 2020 +0200
     1.3 @@ -18,7 +18,22 @@
     1.4  #include <sstream>
     1.5  #include <smf.h>
     1.6  
     1.7 +/**
     1.8 + * Translates System Exclusive (SysEx) message (binary not HEX) from standard input to a Standard MIDI file (SMF).
     1.9 + * The file path must be passed as a CLI argument.
    1.10 + * 
    1.11 + * Usage examples:
    1.12 + *     cat test.syx | ./sysex2smf test.mid
    1.13 + * 
    1.14 + * Dependencies:
    1.15 + *     libsmf (in Debian-based distributions do: apt install libsmf-dev)
    1.16 + * 
    1.17 + * @param argc
    1.18 + * @param argv
    1.19 + * @return 
    1.20 + */
    1.21  int main(int argc, char**argv) {
    1.22 +	int exitCode = 0;
    1.23  	if (argc == 2) {
    1.24  		smf_t* smf = smf_new();
    1.25  		smf_track_t* track = smf_track_new();
    1.26 @@ -29,14 +44,20 @@
    1.27  			data.put(ch);
    1.28  		}
    1.29  
    1.30 +		// TODO: review the (void*) – it works but…
    1.31  		smf_event_t* event = smf_event_new_from_pointer((void*) data.str().c_str(), data.tellp());
    1.32  		smf_track_add_event_pulses(track, event, 0);
    1.33  
    1.34 -
    1.35 +		// TODO: check whether file exists?
    1.36  		int res = smf_save(smf, argv[1]);
    1.37 -		if (res) std::cerr << "unable to save MIDI file: " << res << std::endl;
    1.38 +		if (res) {
    1.39 +			std::cerr << "Error: Unable to save MIDI file: " << argv[1] << " Error code: " << res << std::endl;
    1.40 +			exitCode = 1;
    1.41 +		}
    1.42  		smf_delete(smf);
    1.43  	} else {
    1.44  		std::cerr << "Usage: " << argv[0] << " 'output-file.mid'" << std::endl;
    1.45 +		exitCode = 1;
    1.46  	}
    1.47 +	return exitCode;
    1.48  }