From 0fb62bd24048d618ee9b5ab2f08e43d4dd425d9f Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 5 Aug 2025 11:54:37 +0100 Subject: [PATCH] AU: Refactor getAUChannelInfo to reduce duplication --- .../format_types/juce_AU_Shared.h | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_AU_Shared.h b/modules/juce_audio_processors/format_types/juce_AU_Shared.h index 11ed907270..3cf11e3afe 100644 --- a/modules/juce_audio_processors/format_types/juce_AU_Shared.h +++ b/modules/juce_audio_processors/format_types/juce_AU_Shared.h @@ -440,31 +440,29 @@ struct AudioUnitHelpers } } - auto hasUnsupportedInput = ! hasMainInputBus, hasUnsupportedOutput = ! hasMainOutputBus; - - for (auto inChanNum = hasMainInputBus ? 1 : 0; inChanNum <= (hasMainInputBus ? maxNumChanToCheckFor : 0); ++inChanNum) + const auto computeHasUnsupportedLayout = [&] (bool isInput) { - Channels channelConfiguration { static_cast (inChanNum), - static_cast (hasInOutMismatch ? defaultOutputs : inChanNum) }; + const auto hasMainBus = isInput ? hasMainInputBus : hasMainOutputBus; + const auto begin = hasMainBus ? 1 : 0; + const auto end = hasMainBus ? maxNumChanToCheckFor : 0; - if (! supportedChannels.contains (channelConfiguration)) + for (auto chan = begin; chan <= end; ++chan) { - hasUnsupportedInput = true; - break; - } - } + const Channels channelConfig + { + static_cast (! isInput && hasInOutMismatch ? defaultInputs : chan), + static_cast ( isInput && hasInOutMismatch ? defaultOutputs : chan) + }; - for (auto outChanNum = hasMainOutputBus ? 1 : 0; outChanNum <= (hasMainOutputBus ? maxNumChanToCheckFor : 0); ++outChanNum) - { - Channels channelConfiguration { static_cast (hasInOutMismatch ? defaultInputs : outChanNum), - static_cast (outChanNum) }; - - if (! supportedChannels.contains (channelConfiguration)) - { - hasUnsupportedOutput = true; - break; + if (! supportedChannels.contains (channelConfig)) + return true; } - } + + return ! hasMainBus; + }; + + const auto hasUnsupportedInput = computeHasUnsupportedLayout (true); + const auto hasUnsupportedOutput = computeHasUnsupportedLayout (false); for (const auto& supported : supportedChannels) {