Browse Source

Update requested input/output channels whenever AudioDeviceManager::setAudioDeviceSetup() is called

tags/2021-05-28
ed 6 years ago
parent
commit
e14a183886
2 changed files with 36 additions and 40 deletions
  1. +36
    -39
      modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp
  2. +0
    -1
      modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.h

+ 36
- 39
modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp View File

@@ -439,6 +439,25 @@ AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
return availableDeviceTypes.getFirst();
}
static void updateSetupChannels (AudioDeviceManager::AudioDeviceSetup& setup, int defaultNumIns, int defaultNumOuts)
{
auto updateChannels = [](const String& deviceName, BigInteger& channels, int defaultNumChannels)
{
if (deviceName.isEmpty())
{
channels.clear();
}
else if (defaultNumChannels != -1)
{
channels.clear();
channels.setRange (0, defaultNumChannels, true);
}
};
updateChannels (setup.inputDeviceName, setup.inputChannels, setup.useDefaultInputChannels ? defaultNumIns : -1);
updateChannels (setup.outputDeviceName, setup.outputChannels, setup.useDefaultOutputChannels ? defaultNumOuts : -1);
}
String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
bool treatAsChosenDevice)
{
@@ -447,20 +466,7 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
if (newSetup == currentSetup && currentAudioDevice != nullptr)
return {};
if (! (newSetup == currentSetup))
sendChangeMessage();
stopDevice();
if (! newSetup.useDefaultInputChannels)
numInputChansNeeded = newSetup.inputChannels.countNumberOfSetBits();
if (! newSetup.useDefaultOutputChannels)
numOutputChansNeeded = newSetup.outputChannels.countNumberOfSetBits();
auto* type = getCurrentDeviceTypeObject();
if (type == nullptr)
if (getCurrentDeviceTypeObject() == nullptr)
{
deleteCurrentDevice();
@@ -470,6 +476,11 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
return {};
}
stopDevice();
if (newSetup != currentSetup)
sendChangeMessage();
String error;
if (currentSetup.inputDeviceName != newSetup.inputDeviceName
@@ -479,6 +490,8 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
deleteCurrentDevice();
scanDevicesIfNeeded();
auto* type = getCurrentDeviceTypeObject();
if (newSetup.outputDeviceName.isNotEmpty() && ! deviceListContains (type, false, newSetup.outputDeviceName))
return "No such device: " + newSetup.outputDeviceName;
@@ -499,32 +512,16 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
deleteCurrentDevice();
return error;
}
if (newSetup.useDefaultInputChannels)
{
inputChannels.clear();
inputChannels.setRange (0, numInputChansNeeded, true);
}
if (newSetup.useDefaultOutputChannels)
{
outputChannels.clear();
outputChannels.setRange (0, numOutputChansNeeded, true);
}
if (newSetup.inputDeviceName.isEmpty()) inputChannels.clear();
if (newSetup.outputDeviceName.isEmpty()) outputChannels.clear();
}
if (! newSetup.useDefaultInputChannels)
inputChannels = newSetup.inputChannels;
currentSetup = newSetup;
if (! newSetup.useDefaultOutputChannels)
outputChannels = newSetup.outputChannels;
if (! currentSetup.useDefaultInputChannels) numInputChansNeeded = currentSetup.inputChannels.countNumberOfSetBits();
if (! currentSetup.useDefaultOutputChannels) numOutputChansNeeded = currentSetup.outputChannels.countNumberOfSetBits();
currentSetup = newSetup;
updateSetupChannels (currentSetup, numInputChansNeeded, numOutputChansNeeded);
if (inputChannels.isZero() && outputChannels.isZero())
if (currentSetup.inputChannels.isZero() && currentSetup.outputChannels.isZero())
{
if (treatAsChosenDevice)
updateXml();
@@ -532,11 +529,11 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
return {};
}
currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
currentSetup.bufferSize = chooseBestBufferSize (newSetup.bufferSize);
currentSetup.sampleRate = chooseBestSampleRate (currentSetup.sampleRate);
currentSetup.bufferSize = chooseBestBufferSize (currentSetup.bufferSize);
error = currentAudioDevice->open (inputChannels,
outputChannels,
error = currentAudioDevice->open (currentSetup.inputChannels,
currentSetup.outputChannels,
currentSetup.sampleRate,
currentSetup.bufferSize);


+ 0
- 1
modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.h View File

@@ -471,7 +471,6 @@ private:
Array<AudioIODeviceCallback*> callbacks;
int numInputChansNeeded = 0, numOutputChansNeeded = 2;
String preferredDeviceName, currentDeviceType;
BigInteger inputChannels, outputChannels;
std::unique_ptr<XmlElement> lastExplicitSettings;
mutable bool listNeedsScanning = true;
AudioBuffer<float> tempBuffer;


Loading…
Cancel
Save