Skip to content

Commit

Permalink
CoreAudio: Return the correct index when the list of devices change
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony-Nicholls committed Sep 20, 2023
1 parent 27fad0f commit 3540152
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
17 changes: 7 additions & 10 deletions modules/juce_audio_devices/native/juce_CoreAudio_mac.cpp
Expand Up @@ -1207,12 +1207,10 @@ class CoreAudioIODevice : public AudioIODevice,
public:
CoreAudioIODevice (CoreAudioIODeviceType* dt,
const String& deviceName,
AudioDeviceID inputDeviceId, int inputIndex_,
AudioDeviceID outputDeviceId, int outputIndex_)
AudioDeviceID inputDeviceId,
AudioDeviceID outputDeviceId)
: AudioIODevice (deviceName, "CoreAudio"),
deviceType (dt),
inputIndex (inputIndex_),
outputIndex (outputIndex_)
deviceType (dt)
{
internal = [this, &inputDeviceId, &outputDeviceId]
{
Expand Down Expand Up @@ -1260,7 +1258,7 @@ class CoreAudioIODevice : public AudioIODevice,
int getCurrentBufferSizeSamples() override { return internal->getBufferSize(); }
int getXRunCount() const noexcept override { return internal->xruns; }

int getIndexOfDevice (bool asInput) const { return asInput ? inputIndex : outputIndex; }
int getIndexOfDevice (bool asInput) const { return deviceType->getDeviceNames (asInput).indexOf (getName()); }

int getDefaultBufferSize() override
{
Expand Down Expand Up @@ -1389,7 +1387,6 @@ class CoreAudioIODevice : public AudioIODevice,
bool shouldRestartDevice() const noexcept { return restartDevice; }

WeakReference<CoreAudioIODeviceType> deviceType;
int inputIndex, outputIndex;
bool hadDiscontinuity;

private:
Expand Down Expand Up @@ -2265,12 +2262,12 @@ class CoreAudioIODeviceType : public AudioIODeviceType,
: outputDeviceName;

if (inputDeviceID == outputDeviceID)
return std::make_unique<CoreAudioIODevice> (this, combinedName, inputDeviceID, inputIndex, outputDeviceID, outputIndex).release();
return std::make_unique<CoreAudioIODevice> (this, combinedName, inputDeviceID, outputDeviceID).release();

auto in = inputDeviceID != 0 ? std::make_unique<CoreAudioIODevice> (this, inputDeviceName, inputDeviceID, inputIndex, 0, -1)
auto in = inputDeviceID != 0 ? std::make_unique<CoreAudioIODevice> (this, inputDeviceName, inputDeviceID, 0)
: nullptr;

auto out = outputDeviceID != 0 ? std::make_unique<CoreAudioIODevice> (this, outputDeviceName, 0, -1, outputDeviceID, outputIndex)
auto out = outputDeviceID != 0 ? std::make_unique<CoreAudioIODevice> (this, outputDeviceName, 0, outputDeviceID)
: nullptr;

if (in == nullptr) return out.release();
Expand Down
Expand Up @@ -227,6 +227,8 @@ class AudioDeviceSettingsPanel : public Component,
type.scanForDevices();

setup.manager->addChangeListener (this);

updateAllControls();
}

~AudioDeviceSettingsPanel() override
Expand Down Expand Up @@ -1154,10 +1156,8 @@ void AudioDeviceSelectorComponent::updateAllControls()
details.maxNumOutputChannels = maxOutputChannels;
details.useStereoPairs = showChannelsAsStereoPairs;

auto sp = std::make_unique<AudioDeviceSettingsPanel> (*type, details, hideAdvancedOptionsWithButton);
addAndMakeVisible (*sp);
sp->updateAllControls();
audioDeviceSettingsComp = std::move (sp);
audioDeviceSettingsComp = std::make_unique<AudioDeviceSettingsPanel> (*type, details, hideAdvancedOptionsWithButton);
addAndMakeVisible (audioDeviceSettingsComp.get());
}
}

Expand Down

0 comments on commit 3540152

Please sign in to comment.