HulaLoop
Simple cross-platform audio loopback and recording.
CLICommon.h
1 #ifndef HULA_CLI_COMMON_H
2 #define HULA_CLI_COMMON_H
3 
4 #include <string>
5 #include <vector>
6 
7 #include <hlaudio/hlaudio.h>
8 #include <hlcontrol/hlcontrol.h>
9 
10 #include <HulaVersion.h>
11 
12 using namespace hula;
13 
14 #define HL_CLI_NAME "hulaloop-cli"
15 #define HL_CLI_ASCII_HEADER "\n" \
16  " _ _ _ _\n" \
17  " | | | | | | | |\n" \
18  " | |__| |_ _| | __ _| | ___ ___ _ __\n" \
19  " | __ | | | | |/ _` | | / _ \\ / _ \\| '_ \\\n" \
20  " | | | | |_| | | (_| | |___| (_) | (_) | |_) |\n" \
21  " |_| |_|\\__,_|_|\\__,_|______\\___/ \\___/| .__/\n" \
22  " | |\n" \
23  " |_|\n" \
24  "----------------------------------------------------\n\n" \
25 
26 
31 inline void printDeviceList(Transport *t)
32 {
34 
35  std::vector<Device *> devices;
36  if (settings->getShowRecordDevices())
37  {
38  devices = t->getController()->getDevices((DeviceType)(PLAYBACK | LOOPBACK | RECORD));
39  }
40  else
41  {
42  devices = t->getController()->getDevices((DeviceType)(PLAYBACK | LOOPBACK));
43  }
44 
45  printf("\n");
46  for (size_t i = 0; i < devices.size(); i++)
47  {
48  printf("Device #%lu: %s\n", i, devices[i]->getName().c_str());
49  printf("Record: %s\n", (devices[i]->getType() & DeviceType::RECORD) ? "true" : "false");
50  printf("Loopback: %s\n", (devices[i]->getType() & DeviceType::LOOPBACK) ? "true" : "false");
51  printf("Output: %s\n", (devices[i]->getType() & DeviceType::PLAYBACK) ? "true" : "false");
52  printf("\n");
53  }
54 
55  Device::deleteDevices(devices);
56 }
57 
69 inline Device *findDevice(Transport *t, const std::string &name, DeviceType type)
70 {
71  Device *device = NULL;
72  std::vector<Device *> devices;
73  devices = t->getController()->getDevices(type);
74 
75  // Check if we got a numeric id
76  // Since we all do this differently,
77  // we'll just use the relative ordering to pick
78  // ids
79  int id = -1;
80  try
81  {
82  id = std::stoi(name, nullptr);
83  }
84  catch (std::invalid_argument &e)
85  {
86  // Wasn't an id
87  (void)e;
88  }
89 
90  for (size_t i = 0; i < devices.size(); i++)
91  {
92  // Check id and name
93  if (i == id || devices[i]->getName() == name)
94  {
95  device = devices[i];
96  break;
97  }
98  }
99 
100  // Make a copy so that we can delete
101  if (device != NULL)
102  {
103  device = new Device(*device);
104  }
105 
106  Device::deleteDevices(devices);
107 
108  if (device == NULL)
109  {
110  fprintf(stderr, "\nCould not find input device matching: %s\n", name.c_str());
111  }
112 
113  return device;
114 }
115 
119 inline void printSettings()
120 {
122 
123  printf("\n");
124  printf("Output file: '%s'\n", settings->getOutputFilePath().c_str());
125  printf("Delay: %.2f s\n", settings->getDelayTimer());
126  printf("Length: %.2f s\n", settings->getRecordDuration());
127  printf("Sample rate: %d Hz\n", settings->getSampleRate());
128  printf("Encoding: %s\n", "WAV");
129  printf("Input device: '%s'\n", settings->getDefaultInputDeviceName().c_str());
130  printf("Output device: '%s'\n", settings->getDefaultOutputDeviceName().c_str());
131  printf("\n");
132 }
133 
134 #endif // END HULA_CLI_COMMON_H
<hlcontrol/hlcontrol.h>
Extra class for managing the state of the application and all audio related processes.
Definition: Transport.h:29
Controller * getController() const
Get the controller instance.
Definition: Transport.cpp:193
<hlaudio/hlaudio.h>
static void deleteDevices(std::vector< Device * > devices)
Delete all the device pointers inside the vector.
Definition: Device.cpp:54
std::vector< Device * > getDevices(DeviceType type) const
Fetch a list of devices for the given DeviceType.
Definition: Controller.cpp:129
static HulaSettings * getInstance()
Retreive the singular instance of HulaSettings or construct a new one if none exists.
Definition: HulaSettings.cpp:24
std::string getOutputFilePath()
Get the path of the output file specified at startup or during the file save routine.
Definition: HulaAudioSettings.cpp:129
double getRecordDuration()
Get the length of the record in seconds.
Definition: HulaAudioSettings.cpp:163
std::string getDefaultInputDeviceName()
Get the name of the device that should be initially selected for record.
Definition: HulaAudioSettings.cpp:107
int getSampleRate()
Get the number of channels for the current global device configuration.
Definition: HulaAudioSettings.cpp:83
Wrapper for OS specific device information.
Definition: Device.h:34
Definition: Controller.h:11
Singleton class containing all settings for the application.
Definition: HulaSettings.h:12
std::string getDefaultOutputDeviceName()
Get the name of the device that should be initially selected for playback.
Definition: HulaAudioSettings.cpp:118
bool getShowRecordDevices()
Getters.
Definition: HulaAudioSettings.cpp:57
double getDelayTimer()
Get the length of the delay timer in seconds.
Definition: HulaAudioSettings.cpp:152