From 7cf812a9bdb0e3c1a6115faae7209889bbe43775 Mon Sep 17 00:00:00 2001 From: George Reales Date: Tue, 21 Jul 2020 09:34:28 +0200 Subject: [PATCH] Update juce_StandaloneFilterWindow.h JUCE 5.4.7 compatibility update --- .../Standalone/juce_StandaloneFilterWindow.h | 140 ++++++++++-------- 1 file changed, 77 insertions(+), 63 deletions(-) mode change 100755 => 100644 Modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h diff --git a/Modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h b/Modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h old mode 100755 new mode 100644 index c91f2e0..b2bb4d0 --- a/Modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h +++ b/Modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h @@ -42,7 +42,8 @@ namespace juce @tags{Audio} */ class StandalonePluginHolder : private AudioIODeviceCallback, - private Timer + private Timer, + private Value::Listener { public: //============================================================================== @@ -72,15 +73,17 @@ public: #if JUCE_ANDROID || JUCE_IOS bool shouldAutoOpenMidiDevices = true #else - bool shouldAutoOpenMidiDevices = false + bool shouldAutoOpenMidiDevices = true #endif ) : settings (settingsToUse, takeOwnershipOfSettings), channelConfiguration (channels), - shouldMuteInput (! isInterAppAudioConnected()), autoOpenMidiDevices (shouldAutoOpenMidiDevices) { + shouldMuteInput.addListener (this); + shouldMuteInput = ! isInterAppAudioConnected(); + createPlugin(); auto inChannels = (channelConfiguration.size() > 0 ? channelConfiguration[0].numIns @@ -109,7 +112,7 @@ public: startTimer (500); } - virtual ~StandalonePluginHolder() + virtual ~StandalonePluginHolder() override { stopTimer(); @@ -158,6 +161,7 @@ public: //============================================================================== Value& getMuteInputValue() { return shouldMuteInput; } bool getProcessorHasPotentialFeedbackLoop() const { return processorHasPotentialFeedbackLoop; } + void valueChanged (Value& value) override { muteInput = (bool) value.getValue(); } //============================================================================== File getLastFile() const @@ -251,38 +255,29 @@ public: { DialogWindow::LaunchOptions o; - int minNumInputs = std::numeric_limits::max(), maxNumInputs = 0, - minNumOutputs = std::numeric_limits::max(), maxNumOutputs = 0; - - auto updateMinAndMax = [] (int newValue, int& minValue, int& maxValue) - { - minValue = jmin (minValue, newValue); - maxValue = jmax (maxValue, newValue); - }; + int maxNumInputs = 0, maxNumOutputs = 0; if (channelConfiguration.size() > 0) { - auto defaultConfig = channelConfiguration.getReference (0); - updateMinAndMax ((int) defaultConfig.numIns, minNumInputs, maxNumInputs); - updateMinAndMax ((int) defaultConfig.numOuts, minNumOutputs, maxNumOutputs); + auto& defaultConfig = channelConfiguration.getReference (0); + + maxNumInputs = jmax (0, (int) defaultConfig.numIns); + maxNumOutputs = jmax (0, (int) defaultConfig.numOuts); } if (auto* bus = processor->getBus (true, 0)) - updateMinAndMax (bus->getDefaultLayout().size(), minNumInputs, maxNumInputs); + maxNumInputs = jmax (0, bus->getDefaultLayout().size()); if (auto* bus = processor->getBus (false, 0)) - updateMinAndMax (bus->getDefaultLayout().size(), minNumOutputs, maxNumOutputs); + maxNumOutputs = jmax (0, bus->getDefaultLayout().size()); - minNumInputs = jmin (minNumInputs, maxNumInputs); - minNumOutputs = jmin (minNumOutputs, maxNumOutputs); - - o.content.setOwned (new SettingsComponent (*this, deviceManager, - minNumInputs, - maxNumInputs, - minNumOutputs, - maxNumOutputs)); + o.content.setOwned (new SettingsComponent (*this, deviceManager, maxNumInputs, maxNumOutputs)); +#if JUCE_MAC o.content->setSize (500, 240); - +#endif +#if ! JUCE_MAC + o.content->setSize (500, 340); +#endif o.dialogTitle = TRANS("Audio/MIDI Settings"); o.dialogBackgroundColour = o.content->getLookAndFeel().findColour (ResizableWindow::backgroundColourId); o.escapeKeyTriggersCloseButton = true; @@ -296,7 +291,7 @@ public: { if (settings != nullptr) { - std::unique_ptr xml (deviceManager.createStateXml()); + auto xml = deviceManager.createStateXml(); settings->setValue ("audioSetup", xml.get()); @@ -314,7 +309,7 @@ public: if (settings != nullptr) { - savedState.reset (settings->getXmlValue ("audioSetup")); + savedState = settings->getXmlValue ("audioSetup"); #if ! (JUCE_IOS || JUCE_ANDROID) shouldMuteInput.setValue (settings->getBoolValue ("shouldMuteInput", true)); @@ -406,12 +401,13 @@ public: // avoid feedback loop by default bool processorHasPotentialFeedbackLoop = true; + std::atomic muteInput { true }; Value shouldMuteInput; AudioBuffer emptyBuffer; bool autoOpenMidiDevices; std::unique_ptr options; - StringArray lastMidiDevices; + Array lastMidiDevices; private: //============================================================================== @@ -420,16 +416,14 @@ private: public: SettingsComponent (StandalonePluginHolder& pluginHolder, AudioDeviceManager& deviceManagerToUse, - int minAudioInputChannels, int maxAudioInputChannels, - int minAudioOutputChannels, int maxAudioOutputChannels) : owner (pluginHolder), deviceSelector (deviceManagerToUse, - minAudioInputChannels, maxAudioInputChannels, - minAudioOutputChannels, maxAudioOutputChannels, + 0, maxAudioInputChannels, + 0, maxAudioOutputChannels, true, - (pluginHolder.processor.get() != nullptr && pluginHolder.processor->producesMidi()), + false, // disables MIDI Out // (pluginHolder.processor.get() != nullptr && pluginHolder.processor->producesMidi()), true, false), shouldMuteLabel ("Feedback Loop:", "Feedback Loop:"), shouldMuteButton ("Mute audio input") @@ -492,9 +486,7 @@ private: int numOutputChannels, int numSamples) override { - const bool inputMuted = shouldMuteInput.getValue(); - - if (inputMuted) + if (muteInput) { emptyBuffer.clear(); inputChannelData = emptyBuffer.getArrayOfReadPointers(); @@ -526,7 +518,7 @@ private: const AudioDeviceManager::AudioDeviceSetup* preferredSetupOptions) { deviceManager.addAudioCallback (this); - deviceManager.addMidiInputCallback ({}, &player); + deviceManager.addMidiInputDeviceCallback ({}, &player); reloadAudioDeviceState (enableAudioInput, preferredDefaultDeviceName, preferredSetupOptions); } @@ -535,23 +527,25 @@ private: { saveAudioDeviceState(); - deviceManager.removeMidiInputCallback ({}, &player); + deviceManager.removeMidiInputDeviceCallback ({}, &player); deviceManager.removeAudioCallback (this); } void timerCallback() override { - auto newMidiDevices = MidiInput::getDevices(); + auto newMidiDevices = MidiInput::getAvailableDevices(); if (newMidiDevices != lastMidiDevices) { for (auto& oldDevice : lastMidiDevices) if (! newMidiDevices.contains (oldDevice)) - deviceManager.setMidiInputEnabled (oldDevice, false); + deviceManager.setMidiInputDeviceEnabled (oldDevice.identifier, false); for (auto& newDevice : newMidiDevices) if (! lastMidiDevices.contains (newDevice)) - deviceManager.setMidiInputEnabled (newDevice, true); + deviceManager.setMidiInputDeviceEnabled (newDevice.identifier, true); + + lastMidiDevices = newMidiDevices; } } @@ -595,7 +589,7 @@ public: bool autoOpenMidiDevices = true #endif ) - : DocumentWindow (title, Colour::fromHSV (0.0f, 0.0f, 0.1f, 1.0f), DocumentWindow::minimiseButton | DocumentWindow::closeButton) + : DocumentWindow ("", Colour::fromHSV (0.0f, 0.0f, 0.1f, 1.0f), DocumentWindow::minimiseButton | DocumentWindow::closeButton) , menuBar(this) #if ! JUCE_MAC , optionsButton ("Settings") @@ -644,7 +638,7 @@ public: #endif } - ~StandaloneFilterWindow() + ~StandaloneFilterWindow() override { #if JUCE_MAC setMacMainMenu(nullptr); @@ -717,16 +711,17 @@ public: void buttonClicked (Button*) override { - PopupMenu m; - m.addItem (1, TRANS("Audio/MIDI Settings...")); - m.addSeparator(); - m.addItem (2, TRANS("Save current state...")); - m.addItem (3, TRANS("Load a saved state...")); - m.addSeparator(); - m.addItem (4, TRANS("Reset to default state")); + pluginHolder->showAudioSettingsDialog(); - m.showMenuAsync (PopupMenu::Options(), - ModalCallbackFunction::forComponent (menuCallback, this)); + // PopupMenu m; + // m.addItem (1, TRANS("Audio/MIDI Settings...")); + // m.addSeparator(); + // m.addItem (2, TRANS("Save current state...")); + // m.addItem (3, TRANS("Load a saved state...")); + // m.addSeparator(); + // m.addItem (4, TRANS("Reset to default state")); + + // m.showMenuAsync (PopupMenu::Options(),ModalCallbackFunction::forComponent (menuCallback, this)); } void handleMenuResult (int result) @@ -771,7 +766,8 @@ private: public: MainContentComponent (StandaloneFilterWindow& filterWindow) : owner (filterWindow), notification (this), - editor (owner.getAudioProcessor()->createEditorIfNeeded()) + editor (owner.getAudioProcessor()->hasEditor() ? owner.getAudioProcessor()->createEditorIfNeeded() + : new GenericAudioProcessorEditor (*owner.getAudioProcessor())) { Value& inputMutedValue = owner.pluginHolder->getMuteInputValue(); @@ -794,7 +790,7 @@ private: inputMutedChanged (shouldShowNotification); } - ~MainContentComponent() + ~MainContentComponent() override { if (editor != nullptr) { @@ -811,7 +807,9 @@ private: if (shouldShowNotification) notification.setBounds (r.removeFromTop (NotificationArea::height)); - editor->setBounds (r); + if (editor != nullptr) + editor->setBounds (editor->getLocalArea (this, r) + .withPosition (r.getTopLeft().transformedBy (editor->getTransform().inverted()))); } private: @@ -871,9 +869,13 @@ private: #if JUCE_IOS || JUCE_ANDROID resized(); #else - setSize (editor->getWidth(), - editor->getHeight() - + (shouldShowNotification ? NotificationArea::height : 0)); + if (editor != nullptr) + { + auto rect = getSizeToContainEditor(); + + setSize (rect.getWidth(), + rect.getHeight() + (shouldShowNotification ? NotificationArea::height : 0)); + } #endif } @@ -888,11 +890,23 @@ private: } //============================================================================== - void componentMovedOrResized (Component&, bool, bool wasResized) override + void componentMovedOrResized (Component&, bool, bool) override { - if (wasResized && editor != nullptr) - setSize (editor->getWidth(), - editor->getHeight() + (shouldShowNotification ? NotificationArea::height : 0)); + if (editor != nullptr) + { + auto rect = getSizeToContainEditor(); + + setSize (rect.getWidth(), + rect.getHeight() + (shouldShowNotification ? NotificationArea::height : 0)); + } + } + + Rectangle getSizeToContainEditor() const + { + if (editor != nullptr) + return getLocalArea (editor.get(), editor->getLocalBounds()); + + return {}; } //==============================================================================