diff --git a/libs/backends/portaudio/portaudio_io.cc b/libs/backends/portaudio/portaudio_io.cc index 164ac91cd8..77ea0536fb 100644 --- a/libs/backends/portaudio/portaudio_io.cc +++ b/libs/backends/portaudio/portaudio_io.cc @@ -211,29 +211,36 @@ PortAudioIO::get_default_output_device () } void -PortAudioIO::discover() +PortAudioIO::clear_device_list () { - if (!initialize_pa()) return; - for (std::map::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 (-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 (-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 (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 () { diff --git a/libs/backends/portaudio/portaudio_io.h b/libs/backends/portaudio/portaudio_io.h index 9871850ec4..fccda4f05e 100644 --- a/libs/backends/portaudio/portaudio_io.h +++ b/libs/backends/portaudio/portaudio_io.h @@ -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;