diff --git a/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp b/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp index 07ea37e570..c3867897f8 100644 --- a/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp @@ -210,7 +210,6 @@ public: type.scanForDevices(); setup.manager->addChangeListener (this); - updateAllControls(); } ~AudioDeviceSettingsPanel() @@ -220,83 +219,101 @@ public: void resized() override { - const int lx = proportionOfWidth (0.35f); - const int w = proportionOfWidth (0.4f); - const int h = 24; - const int space = 6; - const int dh = h + space; - int y = 0; - - if (outputDeviceDropDown != nullptr) + if (AudioDeviceSelectorComponent* parent = findParentComponentOfClass()) { - outputDeviceDropDown->setBounds (lx, y, w, h); - - if (testButton != nullptr) - testButton->setBounds (proportionOfWidth (0.77f), - outputDeviceDropDown->getY(), - proportionOfWidth (0.18f), - h); - y += dh; - } + Rectangle r (proportionOfWidth (0.35f), 0, proportionOfWidth (0.6f), 3000); - if (inputDeviceDropDown != nullptr) - { - inputDeviceDropDown->setBounds (lx, y, w, h); + const int maxListBoxHeight = 100; + const int h = parent->getItemHeight(); + const int space = h / 4; - inputLevelMeter->setBounds (proportionOfWidth (0.77f), - inputDeviceDropDown->getY(), - proportionOfWidth (0.18f), - h); - y += dh; - } + if (outputDeviceDropDown != nullptr) + { + Rectangle row (r.removeFromTop (h)); - const int maxBoxHeight = 100; + if (testButton != nullptr) + { + testButton->changeWidthToFitText (h); + testButton->setBounds (row.removeFromRight (testButton->getWidth())); + row.removeFromRight (space); + } - if (outputChanList != nullptr) - { - const int bh = outputChanList->getBestHeight (maxBoxHeight); - outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh); - y += bh + space; - } + outputDeviceDropDown->setBounds (row); + r.removeFromTop (space); + } - if (inputChanList != nullptr) - { - const int bh = inputChanList->getBestHeight (maxBoxHeight); - inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh); - y += bh + space; - } + if (inputDeviceDropDown != nullptr) + { + Rectangle row (r.removeFromTop (h)); - y += space * 2; + inputLevelMeter->setBounds (row.removeFromRight (testButton != nullptr ? testButton->getWidth() : row.getWidth() / 6)); + row.removeFromRight (space); + inputDeviceDropDown->setBounds (row); + r.removeFromTop (space); + } - if (showAdvancedSettingsButton != nullptr) - { - showAdvancedSettingsButton->changeWidthToFitText (h); - showAdvancedSettingsButton->setTopLeftPosition (lx, y); - } + if (outputChanList != nullptr) + { + outputChanList->setBounds (r.removeFromTop (outputChanList->getBestHeight (maxListBoxHeight))); + outputChanLabel->setBounds (0, outputChanList->getBounds().getCentreY() - h / 2, r.getX(), h); + r.removeFromTop (space); + } - if (sampleRateDropDown != nullptr) - { - sampleRateDropDown->setVisible (showAdvancedSettingsButton == nullptr - || ! showAdvancedSettingsButton->isVisible()); + if (inputChanList != nullptr) + { + inputChanList->setBounds (r.removeFromTop (inputChanList->getBestHeight (maxListBoxHeight))); + inputChanLabel->setBounds (0, inputChanList->getBounds().getCentreY() - h / 2, r.getX(), h); + r.removeFromTop (space); + } - sampleRateDropDown->setBounds (lx, y, w, h); - y += dh; - } + r.removeFromTop (space * 2); - if (bufferSizeDropDown != nullptr) - { - bufferSizeDropDown->setVisible (showAdvancedSettingsButton == nullptr - || ! showAdvancedSettingsButton->isVisible()); - bufferSizeDropDown->setBounds (lx, y, w, h); - y += dh; - } + if (showAdvancedSettingsButton != nullptr) + { + showAdvancedSettingsButton->setBounds (r.withHeight (h)); + showAdvancedSettingsButton->changeWidthToFitText(); + } + + const bool advancedSettingsVisible = showAdvancedSettingsButton == nullptr + || ! showAdvancedSettingsButton->isVisible(); + + if (sampleRateDropDown != nullptr) + { + sampleRateDropDown->setVisible (advancedSettingsVisible); + sampleRateDropDown->setBounds (r.removeFromTop (h)); + r.removeFromTop (space); + } + + if (bufferSizeDropDown != nullptr) + { + bufferSizeDropDown->setVisible (advancedSettingsVisible); + bufferSizeDropDown->setBounds (r.removeFromTop (h)); + r.removeFromTop (space); + } + + r.removeFromTop (space * 2); + Rectangle buttons (r.removeFromTop (h)); - if (showUIButton != nullptr) + if (showUIButton != nullptr) + { + showUIButton->setVisible (advancedSettingsVisible); + showUIButton->changeWidthToFitText (h); + showUIButton->setBounds (buttons.removeFromLeft (showUIButton->getWidth())); + buttons.removeFromLeft (space); + } + + if (resetDeviceButton != nullptr) + { + resetDeviceButton->setVisible (advancedSettingsVisible); + resetDeviceButton->changeWidthToFitText (h); + resetDeviceButton->setBounds (buttons.removeFromLeft (showUIButton->getWidth())); + } + + setSize (getWidth(), r.getHeight()); + } + else { - showUIButton->setVisible (showAdvancedSettingsButton == nullptr - || ! showAdvancedSettingsButton->isVisible()); - showUIButton->changeWidthToFitText (h); - showUIButton->setTopLeftPosition (lx, y); + jassertfalse; } } @@ -394,6 +411,10 @@ public: { setup.manager->playTestSound(); } + else if (button == resetDeviceButton) + { + resetDevice(); + } } void updateAllControls() @@ -402,6 +423,7 @@ public: updateInputsComboBox(); updateControlPanelButton(); + updateResetButton(); if (AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice()) { @@ -414,6 +436,7 @@ public: = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType, TRANS ("(no audio output channels found)"))); outputChanLabel = new Label (String::empty, TRANS("Active output channels:")); + outputChanLabel->setJustificationType (Justification::centredRight); outputChanLabel->attachToComponent (outputChanList, true); } @@ -434,6 +457,7 @@ public: = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType, TRANS("(no audio input channels found)"))); inputChanLabel = new Label (String::empty, TRANS("Active input channels:")); + inputChanLabel->setJustificationType (Justification::centredRight); inputChanLabel->attachToComponent (inputChanList, true); } @@ -473,6 +497,12 @@ public: updateAllControls(); } + void resetDevice() + { + setup.manager->closeAudioDevice(); + setup.manager->restartLastAudioDevice(); + } + private: AudioIODeviceType& type; const AudioDeviceSetupDetails setup; @@ -481,7 +511,7 @@ private: ScopedPointer