Set AudioDeviceManager input and output audio devices

Hi all, I’m stuck on this simple problem and looking for some guidance. When a certain usb device is connected, I would like to automatically reset my audio inputs and outputs to this device. The problem seems to be that I can’t update the device selector component because updateAllControls is private. Here’s where I am so far…

    String pioneerDJMS9 = "DJM-S9";
    auto& deviceTypes = audioDeviceManager.getAvailableDeviceTypes();
    
    for (auto type : deviceTypes)
    {
        auto deviceNames (type->getDeviceNames());
        
        for (auto device : deviceNames)
        {
            if (device == pioneerDJMS9)
            {
                type->createDevice (pioneerDJMS9, pioneerDJMS9);
                audioDeviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
                DBG("successful");
            }
        }
    }

Any help is much appreciated!

Did you try to let the AudioDeviceManager manage?

auto setup = manager.getAudioDeviceSetup();
setup.outputDeviceName = pioneerDJMS9;
setup.inputDeviceName = pioneerDJMS9;
manager.setAudioDeviceSetup (setup, true);

N.B. check, if the name is in the StringArray:

if( deviceNames.contains (pioneerDJMS9))
...

And to get notification, when a device becomes available, maybe listening to the manager being a ChangeBroadcaster could help… but I am not sure, if this would be sending a message…

I wasn’t aware inputDeviceName and outputDeviceName could be used to set the devices – only thought they returned the current device. Thanks I’ll try this out in the morning!