-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
94 lines (80 loc) · 2.79 KB
/
Copy pathmain.cpp
File metadata and controls
94 lines (80 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* BMSSTV - Build Music SSTV
* This project MUST be built with or with above C++ 20 standard
*/
#include "langs.hpp"
#include "sstvprocessor.hpp"
#include "constvalue.hpp"
#include <iostream>
#include <filesystem>
#include <string>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include "include/CLI/CLI.hpp"
#define VERSION_C "ver build20260531"
#define VERSION std::string(VERSION_C)
const std::set<std::string> sstv_formats = {
"martin1","mt1",
"martin2", "mt2",
"scottie1", "sct1",
"scottie2", "sct2",
"scottiedx", "sctdx"
};
const std::set<std::string> output_image_formats = { "png", "bmp" ,"jpg", "jpeg" };
enum output_image_formatse {png, bmp, jpg};
int main(int argc, char** argv)
{
CLI::App app{ (std::string("BMSSTV - Build Music SSTV ") + VERSION + " by BH6BMJ") };
argv = app.ensure_utf8(argv);
std::string
midi_file_path,
output_image_file_path,
sstv_format_argc;
unsigned char track_number;
app.add_option("-m,-i,--midiinput", midi_file_path, midiinput_bmj)->check(
[](const std::string& filename) -> std::string {
if (!std::filesystem::exists(filename)) return midifile404_bmj + filename;
smf::MidiFile midifile;
if (!midifile.read(filename)) return cannotreadmidifile_bmj + filename;
if (midifile.getTrackCount() == 0) return emptytrack_bmj + filename;
return "";
}
);
app.add_option("-o,--outputfile", output_image_file_path, outputfile_bmj)->check(
[](const std::string& imagefileext)->std::string
{
auto ext = std::filesystem::path(imagefileext).extension().string();
if (!ext.empty()) {
std::string ext = ext.substr(1);
if (output_image_formats.find(ext) == output_image_formats.end()) return invaildimageformat_bmj + ext;
return "";
}
else return invaildimageformat_bmj + ext;
}
);
app.add_option("-f,--sstvformat", sstv_format_argc, sstvformat_bmj)->check(CLI::IsMember(sstv_formats));
app.add_option("-t,--track", track_number, tracknumber_bmj)
->default_val(0)
->check(CLI::Range(0, 255));
try {
app.parse(argc, argv);
}
catch (const CLI::ParseError& e) {
return app.exit(e);
}
MidiNoteToImage noteslist(
midi_file_path,
track_number,
[&]() -> auto {
if (sstv_format_argc == "martin1" || sstv_format_argc == "mt1") return MidiNoteToImage::sstvformats_::martin1;
if (sstv_format_argc == "martin2" || sstv_format_argc == "mt2") return MidiNoteToImage::sstvformats_::martin2;
if (sstv_format_argc == "scottie1" || sstv_format_argc == "sct1") return MidiNoteToImage::sstvformats_::scottie1;
if (sstv_format_argc == "scottie2" || sstv_format_argc == "sct2") return MidiNoteToImage::sstvformats_::scottie2;
if (sstv_format_argc == "scottiedx" || sstv_format_argc == "sctdx") return MidiNoteToImage::sstvformats_::scottiedx;
return MidiNoteToImage::sstvformats_::martin1;
}()
);
return 0;
}