franta-hg@0
|
1 |
/**
|
franta-hg@0
|
2 |
* SysEx to SMF convertor
|
franta-hg@0
|
3 |
* Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
|
franta-hg@0
|
4 |
*
|
franta-hg@0
|
5 |
* This program is free software: you can redistribute it and/or modify
|
franta-hg@0
|
6 |
* it under the terms of the GNU General Public License as published by
|
franta-hg@0
|
7 |
* the Free Software Foundation, version 3 of the License.
|
franta-hg@0
|
8 |
*
|
franta-hg@0
|
9 |
* This program is distributed in the hope that it will be useful,
|
franta-hg@0
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
franta-hg@0
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
franta-hg@0
|
12 |
* GNU General Public License for more details.
|
franta-hg@0
|
13 |
*
|
franta-hg@0
|
14 |
* You should have received a copy of the GNU General Public License
|
franta-hg@0
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
franta-hg@0
|
16 |
*/
|
franta-hg@0
|
17 |
#include <iostream>
|
franta-hg@0
|
18 |
#include <sstream>
|
franta-hg@0
|
19 |
#include <smf.h>
|
franta-hg@0
|
20 |
|
franta-hg@0
|
21 |
int main(int argc, char**argv) {
|
franta-hg@0
|
22 |
if (argc == 2) {
|
franta-hg@0
|
23 |
smf_t* smf = smf_new();
|
franta-hg@0
|
24 |
smf_track_t* track = smf_track_new();
|
franta-hg@0
|
25 |
smf_add_track(smf, track);
|
franta-hg@0
|
26 |
|
franta-hg@0
|
27 |
std::stringstream data;
|
franta-hg@0
|
28 |
for (char ch; std::cin.read(&ch, 1).good();) {
|
franta-hg@0
|
29 |
data.put(ch);
|
franta-hg@0
|
30 |
}
|
franta-hg@0
|
31 |
|
franta-hg@0
|
32 |
smf_event_t* event = smf_event_new_from_pointer((void*) data.str().c_str(), data.tellp());
|
franta-hg@0
|
33 |
smf_track_add_event_pulses(track, event, 0);
|
franta-hg@0
|
34 |
|
franta-hg@0
|
35 |
|
franta-hg@0
|
36 |
int res = smf_save(smf, argv[1]);
|
franta-hg@0
|
37 |
if (res) std::cerr << "unable to save MIDI file: " << res << std::endl;
|
franta-hg@0
|
38 |
smf_delete(smf);
|
franta-hg@0
|
39 |
} else {
|
franta-hg@0
|
40 |
std::cerr << "Usage: " << argv[0] << " 'output-file.mid'" << std::endl;
|
franta-hg@0
|
41 |
}
|
franta-hg@0
|
42 |
}
|