From a48a564f9e094eeb490f05fe9f13413e85f3fcfd Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 22 Feb 2021 12:32:15 +0000 Subject: [PATCH] AU: Use slightly more readable channel type --- .../AU/juce_AU_Wrapper.mm | 8 ++-- .../format_types/juce_AU_Shared.h | 45 +++++++++++-------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm index 6048cc8cea..1a6879078e 100644 --- a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm +++ b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm @@ -2051,10 +2051,12 @@ private: addSupportedLayoutTags(); for (int i = 0; i < enabledInputs; ++i) - if ((err = syncAudioUnitWithChannelSet (true, i, juceFilter->getChannelLayoutOfBus (true, i))) != noErr) return err; + if ((err = syncAudioUnitWithChannelSet (true, i, juceFilter->getChannelLayoutOfBus (true, i))) != noErr) + return err; for (int i = 0; i < enabledOutputs; ++i) - if ((err = syncAudioUnitWithChannelSet (false, i, juceFilter->getChannelLayoutOfBus (false, i))) != noErr) return err; + if ((err = syncAudioUnitWithChannelSet (false, i, juceFilter->getChannelLayoutOfBus (false, i))) != noErr) + return err; return noErr; } @@ -2177,7 +2179,7 @@ private: #endif // add discrete layout tags - int n = bus->getMaxSupportedChannels(maxChannelsToProbeFor()); + int n = bus->getMaxSupportedChannels (maxChannelsToProbeFor()); for (int ch = 0; ch < n; ++ch) { 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 2dcbf39f4f..c311fdc0cb 100644 --- a/modules/juce_audio_processors/format_types/juce_AU_Shared.h +++ b/modules/juce_audio_processors/format_types/juce_AU_Shared.h @@ -353,11 +353,22 @@ struct AudioUnitHelpers auto defaultInputs = processor.getChannelCountOfBus (true, 0); auto defaultOutputs = processor.getChannelCountOfBus (false, 0); - SortedSet supportedChannels; + struct Channels + { + SInt16 ins, outs; + + std::pair makePair() const noexcept { return std::make_pair (ins, outs); } + + bool operator< (const Channels& other) const noexcept { return makePair() < other.makePair(); } + bool operator== (const Channels& other) const noexcept { return makePair() == other.makePair(); } + }; + + SortedSet supportedChannels; // add the current configuration if (defaultInputs != 0 || defaultOutputs != 0) - supportedChannels.add ((defaultInputs << 16) | defaultOutputs); + supportedChannels.add ({ static_cast (defaultInputs), + static_cast (defaultOutputs) }); for (auto inChanNum = hasMainInputBus ? 1 : 0; inChanNum <= (hasMainInputBus ? maxNumChanToCheckFor : 0); ++inChanNum) { @@ -375,19 +386,16 @@ struct AudioUnitHelpers if (! isNumberOfChannelsSupported (outBus, outChanNum, outLayout)) continue; - supportedChannels.add (((hasMainInputBus ? outLayout.getMainInputChannels() : 0) << 16) - | (hasMainOutputBus ? outLayout.getMainOutputChannels() : 0)); + supportedChannels.add ({ static_cast (hasMainInputBus ? outLayout.getMainInputChannels() : 0), + static_cast (hasMainOutputBus ? outLayout.getMainOutputChannels() : 0) }); } } auto hasInOutMismatch = false; - for (auto supported : supportedChannels) + for (const auto& supported : supportedChannels) { - auto numInputs = (supported >> 16) & 0xffff; - auto numOutputs = (supported >> 0) & 0xffff; - - if (numInputs != numOutputs) + if (supported.ins != supported.outs) { hasInOutMismatch = true; break; @@ -398,9 +406,10 @@ struct AudioUnitHelpers for (auto inChanNum = hasMainInputBus ? 1 : 0; inChanNum <= (hasMainInputBus ? maxNumChanToCheckFor : 0); ++inChanNum) { - auto channelConfiguration = (inChanNum << 16) | (hasInOutMismatch ? defaultOutputs : inChanNum); + Channels channelConfiguration { static_cast (inChanNum), + static_cast (hasInOutMismatch ? defaultOutputs : inChanNum) }; - if (! supportedChannels.contains (channelConfiguration)) + if (supportedChannels.contains (channelConfiguration)) { hasUnsupportedInput = true; break; @@ -409,25 +418,23 @@ struct AudioUnitHelpers for (auto outChanNum = hasMainOutputBus ? 1 : 0; outChanNum <= (hasMainOutputBus ? maxNumChanToCheckFor : 0); ++outChanNum) { - auto channelConfiguration = ((hasInOutMismatch ? defaultInputs : outChanNum) << 16) | outChanNum; + Channels channelConfiguration { static_cast (hasInOutMismatch ? defaultInputs : outChanNum), + static_cast (outChanNum) }; - if (! supportedChannels.contains (channelConfiguration)) + if (supportedChannels.contains (channelConfiguration)) { hasUnsupportedOutput = true; break; } } - for (auto supported : supportedChannels) + for (const auto& supported : supportedChannels) { - auto numInputs = (supported >> 16) & 0xffff; - auto numOutputs = (supported >> 0) & 0xffff; - AUChannelInfo info; // see here: https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/AudioUnitProgrammingGuide/TheAudioUnit/TheAudioUnit.html - info.inChannels = static_cast (hasMainInputBus ? (hasUnsupportedInput ? numInputs : (hasInOutMismatch && (! hasUnsupportedOutput) ? -2 : -1)) : 0); - info.outChannels = static_cast (hasMainOutputBus ? (hasUnsupportedOutput ? numOutputs : (hasInOutMismatch && (! hasUnsupportedInput) ? -2 : -1)) : 0); + info.inChannels = static_cast (hasMainInputBus ? (hasUnsupportedInput ? supported.ins : (hasInOutMismatch && (! hasUnsupportedOutput) ? -2 : -1)) : 0); + info.outChannels = static_cast (hasMainOutputBus ? (hasUnsupportedOutput ? supported.outs : (hasInOutMismatch && (! hasUnsupportedInput) ? -2 : -1)) : 0); if (info.inChannels == -2 && info.outChannels == -2) info.inChannels = -1;