1 #ifndef HULA_CLI_COMMON_H 2 #define HULA_CLI_COMMON_H 6 #define STR_HELPER(x) #x 7 #define STR(x) STR_HELPER(x) 17 #include <QCoreApplication> 18 #include <QTextStream> 20 #include <HulaVersion.h> 24 #define HL_CLI_NAME "hulaloop-cli" 25 #define HL_CLI_ASCII_HEADER "\n" \ 27 " | | | | | | | |\n" \ 28 " | |__| |_ _| | __ _| | ___ ___ _ __\n" \ 29 " | __ | | | | |/ _` | | / _ \\ / _ \\| '_ \\\n" \ 30 " | | | | |_| | | (_| | |___| (_) | (_) | |_) |\n" \ 31 " |_| |_|\\__,_|_|\\__,_|______\\___/ \\___/| .__/\n" \ 34 "----------------------------------------------------\n\n" \ 39 #define QCOL(stream, width, text) \ 40 stream.setFieldWidth(width); \ 42 stream.setFieldWidth(0); 50 Q_DECLARE_TR_FUNCTIONS(
CLI)
61 bool startRecord =
false;
74 std::string delay =
"0";
85 std::string duration = STR(HL_INFINITE_RECORD);
122 QTextStream cout(stdout);
123 cout.setAutoDetectUnicode(
true);
124 cout.setRealNumberNotation(QTextStream::FixedNotation);
125 cout.setRealNumberPrecision(2);
126 cout.setPadChar(
'.');
127 cout.setFieldAlignment(QTextStream::AlignLeft);
131 std::vector<Device *> devices;
142 fprintf(stderr,
"%s%s\n",
HL_ERROR_PREFIX, ce.getErrorMessage().c_str());
156 fprintf(stderr,
"%s%s\n",
HL_ERROR_PREFIX, ce.getErrorMessage().c_str());
162 for (
size_t i = 0; i < devices.size(); i++)
164 QCOL(cout, colW, CLI::tr(
"Device #%1").arg(i).append(
" "));
165 cout <<
" " << devices[i]->getName().c_str() << endl;
167 QCOL(cout, colW, CLI::tr(
"Record",
"device capability").append(
" "));
168 cout <<
" " << ((devices[i]->getType() & DeviceType::RECORD) ? CLI::tr(
"Yes") : CLI::tr(
"No")) << endl;
170 QCOL(cout, colW, CLI::tr(
"Loopback",
"device capability").append(
" "));
171 cout <<
" " << ((devices[i]->getType() & DeviceType::LOOPBACK) ? CLI::tr(
"Yes") : CLI::tr(
"No")) << endl;
173 QCOL(cout, colW, CLI::tr(
"Output",
"device capability").append(
" "));
174 cout <<
" " << ((devices[i]->getType() & DeviceType::PLAYBACK) ? CLI::tr(
"Yes") : CLI::tr(
"No")) << endl;
198 std::vector<Device *> devices;
210 fprintf(stderr,
"%s%s\n",
HL_ERROR_PREFIX, ce.getErrorMessage().c_str());
221 id = std::stoi(name,
nullptr);
223 catch (std::invalid_argument &e)
229 for (
size_t i = 0; i < devices.size(); i++)
232 if (i ==
id || devices[i]->getName() == name)
240 if (device !=
nullptr)
242 device =
new Device(*device);
247 if (device ==
nullptr)
250 fprintf(stderr,
"\n%s\n", qPrintable(CLI::tr(
"Could not find device matching: %1").arg(name.c_str())));
263 QTextStream cout(stdout);
264 cout.setAutoDetectUnicode(
true);
265 cout.setRealNumberNotation(QTextStream::FixedNotation);
266 cout.setRealNumberPrecision(2);
267 cout.setFieldAlignment(QTextStream::AlignLeft);
273 QCOL(cout, colW, CLI::tr(
"Output file:",
"setting"));
278 QCOL(cout, colW, CLI::tr(
"Delay:"));
279 cout << stod(args.
delay) <<
" " << CLI::tr(
"s",
"abbreviation for seconds") << endl;
281 QCOL(cout, colW, CLI::tr(
"Duration:"));
282 cout << stod(args.
duration) <<
" " << CLI::tr(
"s",
"abbreviation for seconds") << endl;
284 QCOL(cout, colW, CLI::tr(
"Sample rate:"));
285 cout << settings->
getSampleRate() <<
" " << CLI::tr(
"Hz",
"unit") << endl;
288 QCOL(cout, colW, CLI::tr(
"Encoding:"));
289 cout <<
"WAV" << endl;
291 QCOL(cout, colW, CLI::tr(
"Input device:"));
292 cout << QString::fromStdString(args.
inputDevice) << endl;
294 QCOL(cout, colW, CLI::tr(
"Output device:"));
295 cout << QString::fromStdString(args.
outputDevice) << endl;
299 #endif // END HULA_CLI_COMMON_H
Device * findDevice(Transport *t, const std::string &name, DeviceType type)
Utility function for searching the list of devices.
Definition: CLICommon.h:195
Extra class for managing the state of the application and all audio related processes.
Definition: Transport.h:33
#define HL_ERROR_PREFIX
Prefix printed before every console message to stderr.
Definition: HulaAudioError.h:39
std::vector< Device * > getDevices(DeviceType type) const
Fetch a list of devices for the given DeviceType.
Definition: Controller.cpp:131
Definition: CLICommon.h:49
static void deleteDevices(std::vector< Device *> devices)
Delete all the device pointers inside the vector.
Definition: Device.cpp:54
static HulaSettings * getInstance()
Retreive the singular instance of HulaSettings or construct a new one if none exists.
Definition: HulaSettings.cpp:31
Controller * getController() const
Get the controller instance.
Definition: Transport.cpp:221
void printDeviceList(Transport *t)
Utility CLI function to print the device list to the console.
Definition: CLICommon.h:117
void printSettings(const HulaImmediateArgs &args)
Utility function for printing the current application settings.
Definition: CLICommon.h:259
int getSampleRate()
Get the number of channels for the current global device configuration.
Definition: HulaAudioSettings.cpp:71
Exception class for the control module and higher.
Definition: HulaAudioError.h:131
Wrapper for OS specific device information.
Definition: Device.h:55
Wrapper around translation functions for Qt.
Definition: Controller.h:10
Singleton class containing all settings for the application.
Definition: HulaSettings.h:23
bool getShowRecordDevices()
Getters.
Definition: HulaAudioSettings.cpp:45
DeviceType
Denotes type of Device.
Definition: Device.h:18
int getErrorCode() const
This method returns the error code.
Definition: HulaAudioError.h:162
Exception class for the control module and higher.
Definition: HulaControlError.h:40
struct hula::HulaImmediateArgs HulaImmediateArgs
Args parsed from CLI flags.