-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.cpp
More file actions
105 lines (87 loc) · 2.24 KB
/
Copy pathoptions.cpp
File metadata and controls
105 lines (87 loc) · 2.24 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
95
96
97
98
99
100
101
102
103
104
105
#include <primo/avblocks/avb.h>
#include <primo/platform/error_facility.h>
#include "program_options.h"
#include "util.h"
#include "options.h"
#include <string>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <filesystem>
namespace fs = std::filesystem;
using namespace std;
using namespace primo::program_options;
void setDefaultOptions(Options& opt)
{
opt.inputFile = getExeDir() + "/../../assets/aud/Hydrate-Kenny_Beltrey.mp3";
fs::path output(getExeDir() + "/../../output/audio_upsample");
fs::create_directories(output);
ostringstream s;
s << output.c_str() << "/Hydrate-Kenny_Beltrey-48khz.mp3";
opt.outputFile = s.str();
}
void help(OptionsConfig<char>& optcfg)
{
cout << "enc_mp3_file --input <wav file> --output <mp3 file>" << endl;
doHelp(cout, optcfg);
}
bool validateOptions(Options& opt)
{
if(opt.inputFile.empty())
{
cout << "Input file needed" << endl;
return false;
}
else
{
cout << "Input file: " << opt.inputFile << endl;
}
if(opt.outputFile.empty())
{
cout << "Output file needed" << endl;
return false;
}
else
{
cout << "Output file: " << opt.outputFile << endl;
}
return true;
}
ErrorCodes prepareOptions(Options &opt, int argc, char* argv[])
{
if (argc < 2)
{
setDefaultOptions(opt);
cout << "Using defaults:\n";
cout << " --input " << opt.inputFile;
cout << " --output " << opt.outputFile;
cout << endl;
return Parsed;
}
primo::program_options::OptionsConfig<char> optcfg;
optcfg.addOptions()
(("help,h"), opt.help, (""))
(("input,i"), opt.inputFile, string(), ("input WAV file"))
(("output,o"), opt.outputFile, string(), ("output MP3 file"));
try
{
primo::program_options::scanArgv(optcfg, argc, argv);
}
catch (primo::program_options::ParseFailure<char> &ex)
{
cout << ex.message() << endl;
help(optcfg);
return Error;
}
if (opt.help)
{
help(optcfg);
return Command;
}
if (!validateOptions(opt))
{
help(optcfg);
return Error;
}
return Parsed;
}