Browse Source

Fixed a bug in the AudioDeviceSelectorComponent when selecting zero channels

tags/2021-05-28
Tom Poole 6 years ago
parent
commit
faf7fb1960
3 changed files with 31 additions and 31 deletions
  1. +22
    -18
      modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp
  2. +3
    -7
      modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp
  3. +6
    -6
      modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.h

+ 22
- 18
modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp View File

@@ -445,16 +445,15 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
stopDevice();
if (! newSetup.useDefaultInputChannels) numInputChansNeeded = newSetup.inputChannels.countNumberOfSetBits();
if (! newSetup.useDefaultOutputChannels) numOutputChansNeeded = newSetup.outputChannels.countNumberOfSetBits();
if (! newSetup.useDefaultInputChannels)
numInputChansNeeded = newSetup.inputChannels.countNumberOfSetBits();
auto newInputDeviceName (numInputChansNeeded == 0 ? String() : newSetup.inputDeviceName);
auto newOutputDeviceName (numOutputChansNeeded == 0 ? String() : newSetup.outputDeviceName);
if (! newSetup.useDefaultOutputChannels)
numOutputChansNeeded = newSetup.outputChannels.countNumberOfSetBits();
String error;
auto* type = getCurrentDeviceTypeObject();
if (type == nullptr || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
if (type == nullptr)
{
deleteCurrentDevice();
@@ -464,20 +463,22 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
return {};
}
if (currentSetup.inputDeviceName != newInputDeviceName
|| currentSetup.outputDeviceName != newOutputDeviceName
|| currentAudioDevice == nullptr)
String error;
if (currentSetup.inputDeviceName != newSetup.inputDeviceName
|| currentSetup.outputDeviceName != newSetup.outputDeviceName
|| currentAudioDevice == nullptr)
{
deleteCurrentDevice();
scanDevicesIfNeeded();
if (newOutputDeviceName.isNotEmpty() && ! deviceListContains (type, false, newOutputDeviceName))
return "No such device: " + newOutputDeviceName;
if (newSetup.outputDeviceName.isNotEmpty() && ! deviceListContains (type, false, newSetup.outputDeviceName))
return "No such device: " + newSetup.outputDeviceName;
if (newInputDeviceName.isNotEmpty() && ! deviceListContains (type, true, newInputDeviceName))
return "No such device: " + newInputDeviceName;
if (newSetup.inputDeviceName.isNotEmpty() && ! deviceListContains (type, true, newSetup.inputDeviceName))
return "No such device: " + newSetup.inputDeviceName;
currentAudioDevice.reset (type->createDevice (newOutputDeviceName, newInputDeviceName));
currentAudioDevice.reset (type->createDevice (newSetup.outputDeviceName, newSetup.inputDeviceName));
if (currentAudioDevice == nullptr)
error = "Can't open the audio device!\n\n"
@@ -504,12 +505,15 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup
outputChannels.setRange (0, numOutputChansNeeded, true);
}
if (newInputDeviceName.isEmpty()) inputChannels.clear();
if (newOutputDeviceName.isEmpty()) outputChannels.clear();
if (newSetup.inputDeviceName.isEmpty()) inputChannels.clear();
if (newSetup.outputDeviceName.isEmpty()) outputChannels.clear();
}
if (! newSetup.useDefaultInputChannels) inputChannels = newSetup.inputChannels;
if (! newSetup.useDefaultOutputChannels) outputChannels = newSetup.outputChannels;
if (! newSetup.useDefaultInputChannels)
inputChannels = newSetup.inputChannels;
if (! newSetup.useDefaultOutputChannels)
outputChannels = newSetup.outputChannels;
currentSetup = newSetup;


+ 3
- 7
modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp View File

@@ -60,8 +60,9 @@ struct SimpleDeviceManagerInputLevelMeter : public Component,
void paint (Graphics& g) override
{
// (add a bit of a skew to make the level more obvious)
getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
(float) std::exp (std::log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
(float) std::exp (std::log (level) / 3.0));
}
AudioDeviceManager& manager;
@@ -904,12 +905,7 @@ public:
}
}
auto error = setup.manager->setAudioDeviceSetup (config, true);
if (error.isNotEmpty())
{
//xxx
}
setup.manager->setAudioDeviceSetup (config, true);
}
}


+ 6
- 6
modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.h View File

@@ -95,6 +95,12 @@ public:
private:
//==============================================================================
void handleBluetoothButton();
void updateDeviceType();
void updateMidiOutput();
void changeListenerCallback (ChangeBroadcaster*) override;
void updateAllControls();
std::unique_ptr<ComboBox> deviceTypeDropDown;
std::unique_ptr<Label> deviceTypeDropDownLabel;
std::unique_ptr<Component> audioDeviceSettingsComp;
@@ -110,12 +116,6 @@ private:
std::unique_ptr<Label> midiInputsLabel, midiOutputLabel;
std::unique_ptr<TextButton> bluetoothButton;
void handleBluetoothButton();
void updateDeviceType();
void updateMidiOutput();
void changeListenerCallback (ChangeBroadcaster*) override;
void updateAllControls();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioDeviceSelectorComponent)
};


Loading…
Cancel
Save