sysex2smf.cpp
branchv_0
changeset 0 dcdd12e654da
child 1 b3c075114b95
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sysex2smf.cpp	Tue May 19 22:56:20 2020 +0200
     1.3 @@ -0,0 +1,42 @@
     1.4 +/**
     1.5 + * SysEx to SMF convertor
     1.6 + * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
     1.7 + *
     1.8 + * This program is free software: you can redistribute it and/or modify
     1.9 + * it under the terms of the GNU General Public License as published by
    1.10 + * the Free Software Foundation, version 3 of the License.
    1.11 + *
    1.12 + * This program is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.15 + * GNU General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU General Public License
    1.18 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.19 + */
    1.20 +#include <iostream>
    1.21 +#include <sstream>
    1.22 +#include <smf.h>
    1.23 +
    1.24 +int main(int argc, char**argv) {
    1.25 +	if (argc == 2) {
    1.26 +		smf_t* smf = smf_new();
    1.27 +		smf_track_t* track = smf_track_new();
    1.28 +		smf_add_track(smf, track);
    1.29 +
    1.30 +		std::stringstream data;
    1.31 +		for (char ch; std::cin.read(&ch, 1).good();) {
    1.32 +			data.put(ch);
    1.33 +		}
    1.34 +
    1.35 +		smf_event_t* event = smf_event_new_from_pointer((void*) data.str().c_str(), data.tellp());
    1.36 +		smf_track_add_event_pulses(track, event, 0);
    1.37 +
    1.38 +
    1.39 +		int res = smf_save(smf, argv[1]);
    1.40 +		if (res) std::cerr << "unable to save MIDI file: " << res << std::endl;
    1.41 +		smf_delete(smf);
    1.42 +	} else {
    1.43 +		std::cerr << "Usage: " << argv[0] << " 'output-file.mid'" << std::endl;
    1.44 +	}
    1.45 +}