]> Repos - portaudio/commitdiff
hotplug: Update defaultHostApiIndex_ in Pa_RefreshDeviceList() to reflect the first...
authorRoss Bencina <rossb@audiomulch.com>
Sun, 18 Sep 2016 14:43:40 +0000 (00:43 +1000)
committerRoss Bencina <rossb@audiomulch.com>
Sun, 18 Sep 2016 14:43:40 +0000 (00:43 +1000)
src/common/pa_front.c

index fd2c95ae726a620215eeb0da614b7744551a6465..7e6050ab9f1db3171411649945f2998d20fc8703 100644 (file)
@@ -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 )