commit 832082f7254639072b44023f61dd9769a02a6f66
parent d27e0b8b8a82b83e5b83d16e702d13b3372947aa
Author: jatinchowdhury18 <jatinchowdhury18@gmail.com>
Date: Sun, 26 Jun 2022 15:25:21 +0100
Added host context menus for slider controls (#275)
Diffstat:
4 files changed, 80 insertions(+), 27 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -7,6 +7,7 @@ this file.
- Added stereo/mid-side "balance" controls.
- Added CLAP plugin format support (with Parameter modulation).
- Added option to enable/disable OpenGL on Windows/Linux systems with sufficient OpenGL support.
+- Added host context menus for slider controls.
- Improved presets system, and added new built-in presets from Carter and Cool WAV.
- Fixed V1 mode creating high-pitched tone with linear phase oversampling.
- Fixed compatibility issue related to `xsimd::isnan`.
diff --git a/Plugin/Source/GUI/ModulatableSlider.cpp b/Plugin/Source/GUI/ModulatableSlider.cpp
@@ -1,5 +1,70 @@
#include "ModulatableSlider.h"
+void ModulatableSlider::attachToParameter (juce::RangedAudioParameter* param)
+{
+ if (param == nullptr)
+ {
+ attachment.reset();
+ modParameter = nullptr;
+ stopTimer();
+ return;
+ }
+
+ attachment = std::make_unique<juce::SliderParameterAttachment> (*param, *this, nullptr);
+ modParameter = dynamic_cast<chowdsp::FloatParameter*> (param);
+ startTimerHz (24);
+}
+
+double ModulatableSlider::getModulatedPosition()
+{
+ if (modParameter == nullptr)
+ return valueToProportionOfLength (getValue());
+
+ return jlimit (0.0, 1.0, valueToProportionOfLength ((double) modParameter->getCurrentValue()));
+}
+
+void ModulatableSlider::mouseDown (const MouseEvent& e)
+{
+ if (e.mods.isPopupMenu())
+ {
+ auto popupMenu = getContextMenu();
+ if (popupMenu.containsAnyActiveItems())
+ popupMenu.showMenuAsync (juce::PopupMenu::Options());
+
+ return;
+ }
+
+ foleys::AutoOrientationSlider::mouseDown (e);
+}
+
+void ModulatableSlider::setPluginEditorCallback (PluginEditorCallback&& newCallback)
+{
+ pluginEditorCallback = std::move (newCallback);
+}
+
+juce::PopupMenu ModulatableSlider::getContextMenu()
+{
+ if (pluginEditorCallback != nullptr)
+ {
+ if (auto* pluginEditor = pluginEditorCallback())
+ {
+ if (auto* hostContext = pluginEditor->getHostContext())
+ {
+ if (auto menu = hostContext->getContextMenuForParameter (modParameter))
+ return menu->getEquivalentPopupMenu();
+ }
+ }
+ }
+
+ return {};
+}
+
+void ModulatableSlider::timerCallback()
+{
+ repaint();
+}
+
+//====================================================================
ModSliderItem::ModSliderItem (foleys::MagicGUIBuilder& builder, const juce::ValueTree& node) : GuiItem (builder, node)
{
setColourTranslation (
@@ -18,6 +83,8 @@ ModSliderItem::ModSliderItem (foleys::MagicGUIBuilder& builder, const juce::Valu
void ModSliderItem::update()
{
+ slider.setPluginEditorCallback ([this] { return magicBuilder.getMagicState().getProcessor()->getActiveEditor(); });
+
slider.setTitle (magicBuilder.getStyleProperty (foleys::IDs::name, configNode));
auto type = getProperty (pSliderType).toString();
diff --git a/Plugin/Source/GUI/ModulatableSlider.h b/Plugin/Source/GUI/ModulatableSlider.h
@@ -8,41 +8,26 @@ class ModulatableSlider : public foleys::AutoOrientationSlider,
public:
ModulatableSlider() = default;
- void attachToParameter (juce::RangedAudioParameter* param)
- {
- if (param == nullptr)
- {
- attachment.reset();
- modParameter = nullptr;
- stopTimer();
- return;
- }
-
- attachment = std::make_unique<juce::SliderParameterAttachment> (*param, *this, nullptr);
- modParameter = dynamic_cast<chowdsp::FloatParameter*> (param);
- startTimerHz (24);
- }
-
- double getModulatedPosition()
- {
- if (modParameter == nullptr)
- return valueToProportionOfLength (getValue());
-
- return jlimit (0.0, 1.0, valueToProportionOfLength ((double) modParameter->getCurrentValue()));
- }
+ void attachToParameter (juce::RangedAudioParameter* param);
+ double getModulatedPosition();
+
+ void mouseDown (const MouseEvent& e) override;
+ virtual juce::PopupMenu getContextMenu();
+
+ using PluginEditorCallback = std::function<juce::AudioProcessorEditor*()>;
+ void setPluginEditorCallback (PluginEditorCallback&& newCallback);
private:
- void timerCallback() override
- {
- repaint();
- }
+ void timerCallback() override;
std::unique_ptr<juce::SliderParameterAttachment> attachment;
chowdsp::FloatParameter* modParameter = nullptr;
+ PluginEditorCallback pluginEditorCallback = nullptr;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ModulatableSlider)
};
+//====================================================================
class ModSliderItem : public foleys::GuiItem
{
public:
diff --git a/Plugin/Source/PluginProcessor.cpp b/Plugin/Source/PluginProcessor.cpp
@@ -151,7 +151,7 @@ void ChowtapeModelAudioProcessor::processBlockBypassed (AudioBuffer<float>& buff
void ChowtapeModelAudioProcessor::processAudioBlock (AudioBuffer<float>& buffer)
{
- if (auto playhead = getPlayHead())
+ if (auto* playhead = getPlayHead())
playhead->getCurrentPosition (positionInfo);
inGain.setGain (Decibels::decibelsToGain (inGainDBParam->getCurrentValue()));