1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

AU Client: Refactor scopeToDirection

This commit is contained in:
reuk 2024-10-17 15:38:12 +01:00
parent 1f56562652
commit 103ac55b92
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -264,19 +264,22 @@ public:
#ifdef JucePlugin_PreferredChannelConfigurations
return false;
#else
bool isInput;
const auto optIsInput = scopeToDirection (scope);
if (scopeToDirection (scope, isInput) != noErr)
if (! optIsInput.has_value())
return false;
#if JucePlugin_IsMidiEffect
return false;
#else
#if JucePlugin_IsSynth
if (isInput) return false;
const auto isInput = *optIsInput;
#if JucePlugin_IsSynth
if (isInput)
return false;
#endif
const int busCount = AudioUnitHelpers::getBusCount (*juceFilter, isInput);
const auto busCount = AudioUnitHelpers::getBusCount (*juceFilter, isInput);
return (juceFilter->canAddBus (isInput) || (busCount > 0 && juceFilter->canRemoveBus (isInput)));
#endif
#endif
@ -284,11 +287,12 @@ public:
OSStatus SetBusCount (AudioUnitScope scope, UInt32 count) override
{
OSStatus err = noErr;
bool isInput;
const auto optIsInput = scopeToDirection (scope);
if ((err = scopeToDirection (scope, isInput)) != noErr)
return err;
if (! optIsInput.has_value())
return kAudioUnitErr_InvalidScope;
const auto isInput = *optIsInput;
if (count != (UInt32) AudioUnitHelpers::getBusCount (*juceFilter, isInput))
{
@ -301,7 +305,7 @@ public:
return kAudioUnitErr_PropertyNotWritable;
// we need to already create the underlying elements so that we can change their formats
err = MusicDeviceBase::SetBusCount (scope, count);
auto err = MusicDeviceBase::SetBusCount (scope, count);
if (err != noErr)
return err;
@ -2271,13 +2275,12 @@ private:
}
//==============================================================================
static OSStatus scopeToDirection (AudioUnitScope scope, bool& isInput) noexcept
static std::optional<bool> scopeToDirection (AudioUnitScope scope) noexcept
{
isInput = (scope == kAudioUnitScope_Input);
if (scope != kAudioUnitScope_Input && scope != kAudioUnitScope_Output)
return {};
return (scope != kAudioUnitScope_Input
&& scope != kAudioUnitScope_Output)
? (OSStatus) kAudioUnitErr_InvalidScope : (OSStatus) noErr;
return scope == kAudioUnitScope_Input;
}
enum class BusKind
@ -2296,12 +2299,12 @@ private:
ElementInfo getElementInfo (AudioUnitScope scope, AudioUnitElement element) noexcept
{
bool isInput = false;
OSStatus err;
const auto optIsInput = scopeToDirection (scope);
if ((err = scopeToDirection (scope, isInput)) != noErr)
return { {}, {}, {}, err };
if (! optIsInput.has_value())
return { {}, {}, {}, kAudioUnitErr_InvalidScope };
const auto isInput = *optIsInput;
const auto busIdx = static_cast<int> (element);
if (isPositiveAndBelow (busIdx, AudioUnitHelpers::getBusCount (*juceFilter, isInput)))