-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse_opts.cpp
More file actions
127 lines (108 loc) · 6.91 KB
/
parse_opts.cpp
File metadata and controls
127 lines (108 loc) · 6.91 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "parse_opts.h"
#include <cerrno>
#include <cstdio>
#include <chrono>
#include <iostream>
namespace po = boost::program_options;
po::variables_map parse_cmd_opts(int argc, char *argv[])
{
po::options_description options_info("Informational Options");
options_info.add_options()
/* Informational switches - print info then quit */
("help,h", "Prints this help message") //
("licence", "Prints the licence information for this software and libraries that it uses") //
("list-devices,l", "Lists the available input devices with their IDs") //
("version", "Prints the version number of Chronicle");
po::options_description options_filesystem("Filesystem Options");
options_filesystem.add_options()
/* Filesystem switches - to do with the directory name or filename */
("directory,d", po::value<std::string>()->default_value(boost::filesystem::current_path().string()), "Sets the directory to save the logged audio to. A trailing slash is not required, but may be added. On Windows, if using a trailing slash, use a trailing double-slash.\n"
"Defaults to current directory") //
("format,f", po::value<std::string>()->default_value("\%F \%H\%M\%S"), "strftime-compatible format to use when naming the audio files.\n"
"Defaults to %F %H%M%S") //
("no-delete", "If passed, Chronicle will not delete old audio files, so they can be manually managed.\n"
"Incompatible with --max-age") //
("max-age,a", po::value<std::string>()->default_value("1000h"), "Sets the maximum age before audio files will be automatically deleted.\n"
"Use the format <length><unit>, where unit is < s| m | h | d > for seconds, minutes, hours and days, respectively.\n"
"Defaults to 1000 hours (OfCom minimum required storage for radio stations");
po::options_description options_audio("Audio Options");
options_audio.add_options()
/* Audio switches - to do with the input device or audio format */
("audio-format,s", po::value<std::string>()->default_value("WAV"), "Sets the audio format to use for the recorded audio files. Acceptable parameters are:\n"
"OGG \tOgg Vorbis (.ogg)\n"
"WAV \t16-bit PCM WAV (.wav) (default)\n"
"MP3 \t 320kbps MP3 (.mp3)\n"
"FLAC \t Free Lossless Audio Codec (.flac)") //
("input-device,i", po::value<unsigned int>(), "The ID number of the input device to record from. A list of input devices and their ID numbers can be obtained with `chronicle -l`") //
("device-first-channel,t", po::value<unsigned int>()->default_value(0), "On multi-channel audio devices, select the first input channel to record from.\n"
"Defaults to 0") //
("device-channels,c", po::value<unsigned int>()->default_value(2), "On multi-channel audio devices, select how many channels to record.\n"
"Use with --device-first-channel to use effectively on devices with more audio channels available than you wish to record from") //
("sample-rate,r", po::value<unsigned int>()->default_value(44100), "The sample rate (in Hz) that you wish to use with the audio device specified, if supported")
("bitrate,b", po::value<unsigned int>()->default_value(320), "For MP3, the sample rate to use for ABR recordings, in kbps. Defaults to 320. Ignored for other formats.");
po::options_description options_extra("Extra Options");
options_extra.add_options()
/* Extra/maintenance switches */
("no-term", "If supplied, will not initialize a UI. Use when running chronicle in the background") //
("debug", "Enables verbose logging");
po::variables_map vm;
po::options_description options_all("All Options");
options_all.add(options_info).add(options_audio).add(options_filesystem).add(options_extra);
po::store(po::parse_command_line(argc, argv, options_all), vm);
po::notify(vm);
if (vm.count("help"))
{
std::cout << options_info << std::endl
<< options_audio << std::endl
<< options_filesystem << std::endl
<< options_extra << std::endl;
exit(0);
}
if (vm.count("licence"))
{
printLicence();
exit(0);
}
if (vm.count("version"))
{
printVersion();
exit(0);
}
return vm;
}
bool is_integer(char *value)
{
char *endptr = NULL;
unsigned int n = strtoul(value, &endptr, 10);
return endptr != value;
}
void printVersion()
{
printf("%s.%s.%s", SOFTWARE_VERSION_MAJOR, SOFTWARE_VERSION_MINOR, SOFTWARE_VERSION_PATCH);
}
void printLicence()
{
std::cout << "Chronicle is distributed under the MIT Licence." << std::endl;
std::cout << "See LICENCE for details of the licences used." << std::endl;
std::cout << "Chronicle uses the following libraries internally:" << std::endl;
std::cout << std::endl;
std::cout << "\tlibsndfile" << std::endl;
std::cout << "\t\tCopyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>" << std::endl;
std::cout << "\t\tLicenced under the LGPL as a dynamically linked library." << std::endl;
std::cout << "\t\tThe version of libsndfile that is distributed with this software has not" << std::endl;
std::cout << "\t\tbeen modified from the version available at" << std::endl;
std::cout << "\t\thttp://www.mega-nerd.com/libsndfile/" << std::endl;
std::cout << std::endl;
std::cout << "\tRtAudio" << std::endl;
std::cout << "\t\tCopyright (c) Gary P. Scavone, McGill University" << std::endl;
std::cout << "\t\tLicenced under the the RtAudio licence." << std::endl;
std::cout << "\t\thttps://www.music.mcgill.ca/~gary/rtaudio/" << std::endl;
std::cout << std::endl;
std::cout << "\tBoost" << std::endl;
std::cout << "\t\tLicenced under the Boost Software Licence." << std::endl;
std::cout << std::endl;
std::cout << "\tLAME" << std::endl;
std::cout << "\t\tLicenced under the LGPL v2.1. Courtesy of www.mp3dev.org" << std::endl;
std::cout << "\tspdlog" << std::endl;
std::cout << "\t\tLicenced under the MIT Licence. See LICENCE for details." << std::endl;
}