File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -245,14 +245,29 @@ int
245245portaudio_select_device_by_name (const char * name ,
246246 enum portaudio_device_direction dir )
247247{
248+ int prefix_idx = -1 ; // dev idx starting with name
249+ int substr_idx = -1 ; // dev idx with name as substr
248250 for (int i = 0 ; i < Pa_GetDeviceCount (); i ++ ) {
249251 const PaDeviceInfo * device_info = Pa_GetDeviceInfo (i );
250252 if (!has_channels (device_info , dir )) {
251253 continue ;
252254 }
253- if (strstr (device_info -> name , name )) {
255+ if (strcmp (device_info -> name , name ) == 0 ) { // exact match
254256 return i ;
255257 }
258+ if (strstr (device_info -> name , name )) {
259+ substr_idx = i ;
260+ if (strstr (device_info -> name , name ) ==
261+ device_info -> name ) {
262+ prefix_idx = i ;
263+ }
264+ }
265+ }
266+ if (prefix_idx != -1 ) {
267+ return prefix_idx ;
268+ }
269+ if (substr_idx != -1 ) {
270+ return substr_idx ;
256271 }
257272 log_msg (LOG_LEVEL_ERROR , MOD_NAME "No device named \"%s\" was found!\n" , name );
258273 return -2 ;
You can’t perform that action at this time.
0 commit comments