From: Ross Bencina Date: Sun, 18 Sep 2016 14:43:40 +0000 (+1000) Subject: hotplug: Update defaultHostApiIndex_ in Pa_RefreshDeviceList() to reflect the first... X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=5549bca961d25d46965f1e9bfa23ac06ab0181c9;p=portaudio hotplug: Update defaultHostApiIndex_ in Pa_RefreshDeviceList() to reflect the first host API with an input or output device (previously this was left unchanged, which could result in a default host API with zero devices, and therefore no global default devices.) --- diff --git a/src/common/pa_front.c b/src/common/pa_front.c index fd2c95a..7e6050a 100644 --- a/src/common/pa_front.c +++ b/src/common/pa_front.c @@ -814,6 +814,7 @@ PaError Pa_RefreshDeviceList( void ) /* Phase 2: Commit the scan changes to each back-end */ + defaultHostApiIndex_ = -1; /* indicates that we haven't determined the default host API yet */ baseDeviceIndex = 0; deviceCount_ = 0; for( i = 0 ; i < hostApisCount_ ; ++i ) @@ -840,6 +841,16 @@ PaError Pa_RefreshDeviceList( void ) assert( hostApi->info.defaultInputDevice < hostApi->info.deviceCount ); assert( hostApi->info.defaultOutputDevice < hostApi->info.deviceCount ); + /* the first successfully initialized host API with a default input *or* + output device is used as the default host API. + */ + if( (defaultHostApiIndex_ == -1) && + ( hostApi->info.defaultInputDevice != paNoDevice + || hostApi->info.defaultOutputDevice != paNoDevice ) ) + { + defaultHostApiIndex_ = i; + } + hostApi->privatePaFrontInfo.baseDeviceIndex = baseDeviceIndex; if( hostApi->info.defaultInputDevice != paNoDevice ) @@ -852,6 +863,10 @@ PaError Pa_RefreshDeviceList( void ) deviceCount_ += hostApi->info.deviceCount; } + /* if no host APIs have devices, the default host API is the first initialized host API */ + if( defaultHostApiIndex_ == -1 ) + defaultHostApiIndex_ = 0; + done: if( scanResults )