mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Update requested input/output channels whenever AudioDeviceManager::setAudioDeviceSetup() is called
This commit is contained in:
parent
92350e421d
commit
e14a183886
2 changed files with 37 additions and 41 deletions
|
|
@ -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;
|
||||
|
||||
if (! newSetup.useDefaultOutputChannels)
|
||||
outputChannels = newSetup.outputChannels;
|
||||
|
||||
currentSetup = newSetup;
|
||||
|
||||
if (inputChannels.isZero() && outputChannels.isZero())
|
||||
if (! currentSetup.useDefaultInputChannels) numInputChansNeeded = currentSetup.inputChannels.countNumberOfSetBits();
|
||||
if (! currentSetup.useDefaultOutputChannels) numOutputChansNeeded = currentSetup.outputChannels.countNumberOfSetBits();
|
||||
|
||||
updateSetupChannels (currentSetup, numInputChansNeeded, numOutputChansNeeded);
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue