Selecting specific audio input and output channels for use?

The tutorials aren’t clear on this topic so I’ll ask this here:

I want to have a list of available audio input/output channels for the connected audio devices. Those will be shown in my application’s configuration screen. For example Ableton Live seems to handle this so that it first lists all the audio devices. Then you choose one of them. After that you have access to that devices input/output channel list from which you enable/disable the ones you want.

The above would work fine for me, but I can’t figure out what’s the proper way of querying the amount of channels for the selected device. Do I need to call AudioAppComponent::setAudioChannels (100, 100) with huge numbers as channel counts so they always exceed what the hardware will be capable of delivering and then see how many it gave me back using the following code:

auto* device = deviceManager.getCurrentAudioDevice();
auto activeInputChannels  = device->getActiveInputChannels();
auto activeOutputChannels = device->getActiveOutputChannels();

auto maxInputChannels  = activeInputChannels .getHighestBit() + 1;
auto maxOutputChannels = activeOutputChannels.getHighestBit() + 1;

That sounds like a waste of CPU as I would optimally want to activate only those exact audio inputs/outputs the user selects from the applications configuration menu.

Is there a better way to do this?

Here’s what I ended up doing:

As the AudioAppComponent::setAudioChannels() really seems to set the hard limit for how many audio inputs and outputs can be selected from, I ended up giving the value 128 for both requested input and output channels. This way I should always get all the inputs and outputs available from any possible audio interface imaginable.

Now I can call the following to get the actual available channel names, and thus the list also tells me the amount of audio channels:

auto output_channel_names = deviceManager.getCurrentAudioDevice()->getOutputChannelNames();
auto input_channel_names = deviceManager.getCurrentAudioDevice()->getInputChannelNames();

I would imagine the device->getActiveInputChannels() returns the same amount of bits turned on as the above methods return as input and output channels.

My only concern is that as I have to request all available inputs and outputs, will this eat up much more CPU?