From e8d221ccb363fd7ae26fe47c141f768cef6b3ddb Mon Sep 17 00:00:00 2001 From: Anthony Nicholls Date: Thu, 9 Nov 2023 15:21:57 +0000 Subject: [PATCH] CoreAudio: Fix a bug when retrieving the index of a device nested inside an AudioIODeviceCombiner --- .../native/juce_CoreAudio_mac.cpp | 62 ++++--------------- 1 file changed, 13 insertions(+), 49 deletions(-) diff --git a/modules/juce_audio_devices/native/juce_CoreAudio_mac.cpp b/modules/juce_audio_devices/native/juce_CoreAudio_mac.cpp index 87aec679e7..7124e408dc 100644 --- a/modules/juce_audio_devices/native/juce_CoreAudio_mac.cpp +++ b/modules/juce_audio_devices/native/juce_CoreAudio_mac.cpp @@ -1462,6 +1462,12 @@ public: auto getDeviceWrappers() { return std::array< DeviceWrapper*, 2> { { &inputWrapper, &outputWrapper } }; } auto getDeviceWrappers() const { return std::array { { &inputWrapper, &outputWrapper } }; } + int getIndexOfDevice (bool asInput) const + { + return asInput ? inputWrapper.getIndexOfDevice (true) + : outputWrapper.getIndexOfDevice (false); + } + StringArray getOutputChannelNames() override { return outputWrapper.getChannelNames(); } StringArray getInputChannelNames() override { return inputWrapper .getChannelNames(); } BigInteger getActiveOutputChannels() const override { return outputWrapper.getActiveChannels(); } @@ -1469,46 +1475,16 @@ public: Array getAvailableSampleRates() override { - Array commonRates; - bool first = true; - - for (auto& d : getDeviceWrappers()) - { - auto rates = d->getAvailableSampleRates(); - - if (first) - { - first = false; - commonRates = rates; - } - else - { - commonRates.removeValuesNotIn (rates); - } - } + auto commonRates = inputWrapper.getAvailableSampleRates(); + commonRates.removeValuesNotIn (outputWrapper.getAvailableSampleRates()); return commonRates; } Array getAvailableBufferSizes() override { - Array commonSizes; - bool first = true; - - for (auto& d : getDeviceWrappers()) - { - auto sizes = d->getAvailableBufferSizes(); - - if (first) - { - first = false; - commonSizes = sizes; - } - else - { - commonSizes.removeValuesNotIn (sizes); - } - } + auto commonSizes = inputWrapper.getAvailableBufferSizes(); + commonSizes.removeValuesNotIn (outputWrapper.getAvailableBufferSizes()); return commonSizes; } @@ -1520,22 +1496,12 @@ public: int getCurrentBitDepth() override { - int depth = 32; - - for (auto& d : getDeviceWrappers()) - depth = jmin (depth, d->getCurrentBitDepth()); - - return depth; + return jmin (32, inputWrapper.getCurrentBitDepth(), outputWrapper.getCurrentBitDepth()); } int getDefaultBufferSize() override { - int size = 0; - - for (auto& d : getDeviceWrappers()) - size = jmax (size, d->getDefaultBufferSize()); - - return size; + return jmax (0, inputWrapper.getDefaultBufferSize(), outputWrapper.getDefaultBufferSize()); } AudioWorkgroup getWorkgroup() const override @@ -2238,9 +2204,7 @@ public: return d->getIndexOfDevice (asInput); if (auto* d = dynamic_cast (device)) - for (auto* dev : d->getDeviceWrappers()) - if (const auto index = dev->getIndexOfDevice (asInput); index >= 0) - return index; + return d->getIndexOfDevice (asInput); return -1; }