From c9c4d7a747b54ea5138eb526dd225dec0299176f Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 17 Jan 2022 13:23:47 +0000 Subject: [PATCH] AudioPluginHost: Allow Audio IO window to display different channel layouts with matching channel counts --- .../Source/Plugins/IOConfigurationWindow.cpp | 57 +++++++++---------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/extras/AudioPluginHost/Source/Plugins/IOConfigurationWindow.cpp b/extras/AudioPluginHost/Source/Plugins/IOConfigurationWindow.cpp index f0cfe3394f..db77d0cb86 100644 --- a/extras/AudioPluginHost/Source/Plugins/IOConfigurationWindow.cpp +++ b/extras/AudioPluginHost/Source/Plugins/IOConfigurationWindow.cpp @@ -171,7 +171,6 @@ private: //============================================================================== class IOConfigurationWindow::InputOutputConfig : public Component, - private ComboBox::Listener, private Button::Listener, private NumberedBoxes::Listener { @@ -187,7 +186,6 @@ public: layoutLabel.setFont (layoutLabel.getFont().withStyle (Font::bold)); enabledToggle.setClickingTogglesState (true); - layouts.addListener (this); enabledToggle.addListener (this); addAndMakeVisible (layoutLabel); @@ -262,26 +260,32 @@ private: { name.setText (bus->getName(), NotificationType::dontSendNotification); - int i; - for (i = 1; i < AudioChannelSet::maxChannelsOfNamedLayout; ++i) - if ((layouts.indexOfItemId(i) == -1) != bus->supportedLayoutWithChannels (i).isDisabled()) - break; - // supported layouts have changed - if (i < AudioChannelSet::maxChannelsOfNamedLayout) - { - layouts.clear(); + layouts.clear (dontSendNotification); + auto* menu = layouts.getRootMenu(); + + auto itemId = 1; + auto selectedId = -1; - for (i = 1; i < AudioChannelSet::maxChannelsOfNamedLayout; ++i) + for (auto i = 1; i < AudioChannelSet::maxChannelsOfNamedLayout; ++i) + { + for (const auto& set : AudioChannelSet::channelSetsWithNumberOfChannels (i)) { - auto set = bus->supportedLayoutWithChannels (i); + if (bus->isLayoutSupported (set)) + { + menu->addItem (PopupMenu::Item { set.getDescription() } + .setAction ([this, set] { applyBusLayout (set); }) + .setID (itemId)); + } - if (! set.isDisabled()) - layouts.addItem (set.getDescription(), i); + if (bus->getCurrentLayout() == set) + selectedId = itemId; + + ++itemId; } } - layouts.setSelectedId (bus->getLastEnabledLayout().size()); + layouts.setSelectedId (selectedId); const bool canBeDisabled = bus->isNumberOfChannelsSupported (0); @@ -294,27 +298,18 @@ private: } //============================================================================== - void comboBoxChanged (ComboBox* combo) override + void applyBusLayout (const AudioChannelSet& set) { - if (combo == &layouts) + if (auto* p = owner.getAudioProcessor()) { - if (auto* p = owner.getAudioProcessor()) + if (auto* bus = p->getBus (isInput, currentBus)) { - if (auto* bus = p->getBus (isInput, currentBus)) + if (bus->setCurrentLayoutWithoutEnabling (set)) { - auto selectedNumChannels = layouts.getSelectedId(); - - if (selectedNumChannels != bus->getLastEnabledLayout().size()) - { - if (isPositiveAndBelow (selectedNumChannels, AudioChannelSet::maxChannelsOfNamedLayout) - && bus->setCurrentLayoutWithoutEnabling (bus->supportedLayoutWithChannels (selectedNumChannels))) - { - if (auto* config = owner.getConfig (! isInput)) - config->updateBusLayout(); + if (auto* config = owner.getConfig (! isInput)) + config->updateBusLayout(); - owner.update(); - } - } + owner.update(); } } }