5 #include <QCommandLineParser> 10 #include "CLICommon.h" 19 #define HL_OUT_FILE_SO "f" 20 #define HL_OUT_FILE_LO "out-file" 21 #define HL_DELAY_TIME_SO "d" 22 #define HL_DELAY_TIME_LO "delay" 23 #define HL_RECORD_TIME_SO "t" 24 #define HL_RECORD_TIME_LO "time" 25 #define HL_TRIGGER_RECORD_SO "r" 26 #define HL_TRIGGER_RECORD_LO "record" 27 #define HL_SAMPLE_RATE_SO "s" 28 #define HL_SAMPLE_RATE_LO "sample-rate" 29 #define HL_ENCODING_SO "e" 30 #define HL_ENCODING_LO "encoding" 31 #define HL_INPUT_DEVICE_SO "i" 32 #define HL_INPUT_DEVICE_LO "input-device" 33 #define HL_OUTPUT_DEVICE_SO "o" 34 #define HL_OUTPUT_DEVICE_LO "output-device" 35 #define HL_LIST_DEVICES_SO "l" 36 #define HL_LIST_DEVICES_LO "list" 37 #define HL_LANG_SO "g" 38 #define HL_LANG_LO "lang" 45 void invalidArg(QString name, QString arg, QString message =
"")
47 fprintf(stderr,
"%s\n", qPrintable(CLI::tr(
"Invalid argument '%1' provided to option '%2'.").arg(arg, name)));
48 if (!message.isEmpty())
50 fprintf(stderr,
"%s\n", qPrintable(message));
63 QCommandLineParser parser;
64 parser.setApplicationDescription(CLI::tr(
"Simple cross-platform audio loopback and recording."));
66 parser.addHelpOption();
67 parser.addVersionOption();
71 {{HL_OUT_FILE_SO, HL_OUT_FILE_LO}, CLI::tr(
"Path to audio output file."), CLI::tr(
"output filepath")},
72 {{HL_DELAY_TIME_SO, HL_DELAY_TIME_LO}, CLI::tr(
"Duration, in seconds, of the countdown timer before record."), CLI::tr(
"delay")},
73 {{HL_RECORD_TIME_SO, HL_RECORD_TIME_LO}, CLI::tr(
"Duration, in seconds, of the record."), CLI::tr(
"record duration")},
74 {{HL_TRIGGER_RECORD_SO, HL_TRIGGER_RECORD_LO}, CLI::tr(
"Start the countdown/record immediately.")},
75 {{HL_SAMPLE_RATE_SO, HL_SAMPLE_RATE_LO}, CLI::tr(
"Desired sample rate of the output file."), CLI::tr(
"sample rate")},
76 {{HL_ENCODING_SO, HL_ENCODING_LO}, CLI::tr(
"Encoding format for the output file. Valid options are WAV and MP3. This will default to WAV."), CLI::tr(
"encoding")},
77 {{HL_INPUT_DEVICE_SO, HL_INPUT_DEVICE_LO}, CLI::tr(
"System name of the input device. This will default if not provided."), CLI::tr(
"input device name")},
78 {{HL_OUTPUT_DEVICE_SO, HL_OUTPUT_DEVICE_LO}, CLI::tr(
"System name of the output device. This will default if not provided."), CLI::tr(
"output device name")},
79 {{HL_LIST_DEVICES_SO, HL_LIST_DEVICES_LO}, CLI::tr(
"List available input and output devices.")},
80 {{HL_LANG_SO, HL_LANG_LO}, CLI::tr(
"Set the language of the application."), CLI::tr(
"target language")}
89 if (parser.isSet(HL_LANG_LO))
91 bool success = settings->
loadLanguage(&app, parser.value(HL_LANG_LO).toStdString());
94 printf(
"%s\n", qPrintable(CLI::tr(
"Translation file successfully loaded.")));
98 fprintf(stderr,
"%s\n", qPrintable(CLI::tr(
"Could not find translation file for %1.").arg(parser.value(HL_LANG_LO))));
102 if (parser.isSet(HL_OUT_FILE_LO))
104 extraArgs.
outputFilePath = parser.value(HL_OUT_FILE_LO).toStdString();
107 if (parser.isSet(HL_DELAY_TIME_LO))
109 extraArgs.
delay = parser.value(HL_DELAY_TIME_LO).toStdString();
112 if (parser.isSet(HL_RECORD_TIME_LO))
114 extraArgs.
duration = parser.value(HL_RECORD_TIME_LO).toStdString();
117 if (parser.isSet(HL_TRIGGER_RECORD_LO))
122 if (parser.isSet(HL_SAMPLE_RATE_LO))
125 int rate = parser.value(HL_SAMPLE_RATE_LO).toInt(&ok);
128 invalidArg(HL_SAMPLE_RATE_LO, parser.value(HL_SAMPLE_RATE_LO));
134 if (parser.isSet(HL_ENCODING_LO))
136 std::string encoding = parser.value(HL_ENCODING_LO).toStdString();
137 if (encoding ==
"WAV")
143 invalidArg(HL_ENCODING_LO, parser.value(HL_ENCODING_LO), CLI::tr(
"Only WAV format is supported at this time."));
148 if (parser.isSet(HL_INPUT_DEVICE_LO))
150 extraArgs.
inputDevice = parser.value(HL_INPUT_DEVICE_LO).toStdString();
153 if (parser.isSet(HL_OUTPUT_DEVICE_LO))
155 extraArgs.
outputDevice = parser.value(HL_OUTPUT_DEVICE_LO).toStdString();
158 if (parser.isSet(HL_LIST_DEVICES_LO))
162 printf(
"\n-------- %s --------\n", qPrintable(CLI::tr(
"Device List")));
165 extraArgs.
exit =
true;
171 #endif // END HL_CLI_ARGS_H
Extra class for managing the state of the application and all audio related processes.
Definition: Transport.h:33
bool loadLanguage(QCoreApplication *app, const std::string &id)
Remove and delete the current translator, replacing it with a new translator of the specified languag...
Definition: HulaSettings.cpp:88
void setSampleRate(int)
Set the number of channels for the current global device configuration.
Definition: HulaAudioSettings.cpp:121
static HulaSettings * getInstance()
Retreive the singular instance of HulaSettings or construct a new one if none exists.
Definition: HulaSettings.cpp:31
void printDeviceList(Transport *t)
Utility CLI function to print the device list to the console.
Definition: CLICommon.h:117
Wrapper around translation functions for Qt.
Definition: Controller.h:10
Singleton class containing all settings for the application.
Definition: HulaSettings.h:23