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();
|
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,
|
String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
|
||||||
bool treatAsChosenDevice)
|
bool treatAsChosenDevice)
|
||||||
{
|
{
|
||||||
|
|
@ -447,20 +466,7 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
|
||||||
if (newSetup == currentSetup && currentAudioDevice != nullptr)
|
if (newSetup == currentSetup && currentAudioDevice != nullptr)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (! (newSetup == currentSetup))
|
if (getCurrentDeviceTypeObject() == nullptr)
|
||||||
sendChangeMessage();
|
|
||||||
|
|
||||||
stopDevice();
|
|
||||||
|
|
||||||
if (! newSetup.useDefaultInputChannels)
|
|
||||||
numInputChansNeeded = newSetup.inputChannels.countNumberOfSetBits();
|
|
||||||
|
|
||||||
if (! newSetup.useDefaultOutputChannels)
|
|
||||||
numOutputChansNeeded = newSetup.outputChannels.countNumberOfSetBits();
|
|
||||||
|
|
||||||
auto* type = getCurrentDeviceTypeObject();
|
|
||||||
|
|
||||||
if (type == nullptr)
|
|
||||||
{
|
{
|
||||||
deleteCurrentDevice();
|
deleteCurrentDevice();
|
||||||
|
|
||||||
|
|
@ -470,6 +476,11 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stopDevice();
|
||||||
|
|
||||||
|
if (newSetup != currentSetup)
|
||||||
|
sendChangeMessage();
|
||||||
|
|
||||||
String error;
|
String error;
|
||||||
|
|
||||||
if (currentSetup.inputDeviceName != newSetup.inputDeviceName
|
if (currentSetup.inputDeviceName != newSetup.inputDeviceName
|
||||||
|
|
@ -479,6 +490,8 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
|
||||||
deleteCurrentDevice();
|
deleteCurrentDevice();
|
||||||
scanDevicesIfNeeded();
|
scanDevicesIfNeeded();
|
||||||
|
|
||||||
|
auto* type = getCurrentDeviceTypeObject();
|
||||||
|
|
||||||
if (newSetup.outputDeviceName.isNotEmpty() && ! deviceListContains (type, false, newSetup.outputDeviceName))
|
if (newSetup.outputDeviceName.isNotEmpty() && ! deviceListContains (type, false, newSetup.outputDeviceName))
|
||||||
return "No such device: " + newSetup.outputDeviceName;
|
return "No such device: " + newSetup.outputDeviceName;
|
||||||
|
|
||||||
|
|
@ -499,32 +512,16 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
|
||||||
deleteCurrentDevice();
|
deleteCurrentDevice();
|
||||||
return error;
|
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;
|
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)
|
if (treatAsChosenDevice)
|
||||||
updateXml();
|
updateXml();
|
||||||
|
|
@ -532,11 +529,11 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
|
currentSetup.sampleRate = chooseBestSampleRate (currentSetup.sampleRate);
|
||||||
currentSetup.bufferSize = chooseBestBufferSize (newSetup.bufferSize);
|
currentSetup.bufferSize = chooseBestBufferSize (currentSetup.bufferSize);
|
||||||
|
|
||||||
error = currentAudioDevice->open (inputChannels,
|
error = currentAudioDevice->open (currentSetup.inputChannels,
|
||||||
outputChannels,
|
currentSetup.outputChannels,
|
||||||
currentSetup.sampleRate,
|
currentSetup.sampleRate,
|
||||||
currentSetup.bufferSize);
|
currentSetup.bufferSize);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -471,7 +471,6 @@ private:
|
||||||
Array<AudioIODeviceCallback*> callbacks;
|
Array<AudioIODeviceCallback*> callbacks;
|
||||||
int numInputChansNeeded = 0, numOutputChansNeeded = 2;
|
int numInputChansNeeded = 0, numOutputChansNeeded = 2;
|
||||||
String preferredDeviceName, currentDeviceType;
|
String preferredDeviceName, currentDeviceType;
|
||||||
BigInteger inputChannels, outputChannels;
|
|
||||||
std::unique_ptr<XmlElement> lastExplicitSettings;
|
std::unique_ptr<XmlElement> lastExplicitSettings;
|
||||||
mutable bool listNeedsScanning = true;
|
mutable bool listNeedsScanning = true;
|
||||||
AudioBuffer<float> tempBuffer;
|
AudioBuffer<float> tempBuffer;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue