13
0

Refactor PortAudioIO::discover into three private methods

This commit is contained in:
Tim Mayberry 2015-05-04 13:28:41 +10:00
parent 4e370feeb1
commit ff1d4d5c67
2 changed files with 38 additions and 15 deletions

View File

@ -211,29 +211,36 @@ PortAudioIO::get_default_output_device ()
}
void
PortAudioIO::discover()
PortAudioIO::clear_device_list ()
{
if (!initialize_pa()) return;
for (std::map<int, paDevice*>::const_iterator i = _devices.begin (); i != _devices.end(); ++i) {
delete i->second;
}
_devices.clear();
}
void
PortAudioIO::add_default_device ()
{
const PaHostApiInfo* info = Pa_GetHostApiInfo (_host_api_index);
if (info == NULL) return;
{
const PaDeviceInfo* nfo_i = Pa_GetDeviceInfo(get_default_input_device());
const PaDeviceInfo* nfo_o = Pa_GetDeviceInfo(get_default_output_device());
if (nfo_i && nfo_o) {
_devices.insert (std::pair<int, paDevice*> (-1,
new paDevice("Default",
nfo_i->maxInputChannels,
nfo_o->maxOutputChannels
)));
}
const PaDeviceInfo* nfo_i = Pa_GetDeviceInfo(get_default_input_device());
const PaDeviceInfo* nfo_o = Pa_GetDeviceInfo(get_default_output_device());
if (nfo_i && nfo_o) {
_devices.insert (std::pair<int, paDevice*> (-1,
new paDevice("Default",
nfo_i->maxInputChannels,
nfo_o->maxOutputChannels
)));
}
}
void
PortAudioIO::add_devices ()
{
const PaHostApiInfo* info = Pa_GetHostApiInfo (_host_api_index);
if (info == NULL) return;
int n_devices = Pa_GetDeviceCount();
#ifndef NDEBUG
@ -259,6 +266,7 @@ PortAudioIO::discover()
if ( nfo->maxInputChannels == 0 && nfo->maxOutputChannels == 0) {
continue;
}
_devices.insert (std::pair<int, paDevice*> (i, new paDevice(
nfo->name,
nfo->maxInputChannels,
@ -267,6 +275,16 @@ PortAudioIO::discover()
}
}
void
PortAudioIO::discover()
{
if (!initialize_pa()) return;
clear_device_list ();
add_default_device ();
add_devices ();
}
void
PortAudioIO::pcm_stop ()
{

View File

@ -75,7 +75,13 @@ public:
int get_capture_channel (uint32_t chn, float *input, uint32_t n_samples);
int set_playback_channel (uint32_t chn, const float *input, uint32_t n_samples);
private:
private: // Methods
void clear_device_list ();
void add_default_device ();
void add_devices ();
private: // Data
int _state;
bool _initialized;
@ -91,7 +97,6 @@ private:
uint32_t _cur_input_latency;
uint32_t _cur_output_latency;
struct paDevice {
std::string name;
uint32_t n_inputs;