diff --git a/modules/gui/chowdsp_gui/PluginComponents/chowdsp_ParametersView.cpp b/modules/gui/chowdsp_gui/PluginComponents/chowdsp_ParametersView.cpp index e6ff0f72f..dc2d4646c 100644 --- a/modules/gui/chowdsp_gui/PluginComponents/chowdsp_ParametersView.cpp +++ b/modules/gui/chowdsp_gui/PluginComponents/chowdsp_ParametersView.cpp @@ -10,6 +10,7 @@ namespace parameters_view_detail BooleanParameterComponent (BoolParameter& param, PluginState& pluginState) : attachment (param, pluginState, button) { + setComponentID (param.paramID); addAndMakeVisible (button); } @@ -33,6 +34,7 @@ namespace parameters_view_detail ChoiceParameterComponent (ChoiceParameter& param, PluginState& pluginState) : attachment (param, pluginState, box) { + setComponentID (param.paramID); addAndMakeVisible (box); } @@ -56,6 +58,7 @@ namespace parameters_view_detail SliderParameterComponent (FloatParameter& param, PluginState& pluginState) : attachment (param, pluginState, slider) { + setComponentID (param.paramID); slider.setScrollWheelEnabled (false); addAndMakeVisible (slider); } @@ -90,6 +93,7 @@ namespace parameters_view_detail addAndMakeVisible (parameterLabel); addAndMakeVisible (*(parameterComp = createParameterComp (pluginState))); + setComponentID (parameterComp->getComponentID()); setSize (400, 40); } @@ -198,6 +202,32 @@ struct ParametersView::Pimpl return maxInner; } + [[nodiscard]] juce::Component* getComponentForParameter (const juce::RangedAudioParameter& param) const + { + return getComponentForParameter (param, *view.getRootItem(), view); + } + + static juce::Component* getComponentForParameter (const juce::RangedAudioParameter& param, + const juce::TreeViewItem& item, + const juce::TreeView& tree) + { + for (int i = 0; i < item.getNumSubItems(); ++i) + { + if (const auto* subItem = item.getSubItem (i)) + { + if (auto* paramControlItem = dynamic_cast (subItem)) + { + if (¶mControlItem->param == ¶m) + return tree.getItemComponent (subItem); + } + + if (auto* comp = getComponentForParameter (param, *subItem, tree)) + return comp; + } + } + return nullptr; + } + parameters_view_detail::ParameterGroupItem groupItem; juce::TreeView view; }; @@ -226,4 +256,9 @@ void ParametersView::resized() { pimpl->view.setBounds (getLocalBounds()); } + +juce::Component* ParametersView::getComponentForParameter (const juce::RangedAudioParameter& param) +{ + return pimpl->getComponentForParameter (param); +} } // namespace chowdsp diff --git a/modules/gui/chowdsp_gui/PluginComponents/chowdsp_ParametersView.h b/modules/gui/chowdsp_gui/PluginComponents/chowdsp_ParametersView.h index a22b872f1..6e16ab873 100644 --- a/modules/gui/chowdsp_gui/PluginComponents/chowdsp_ParametersView.h +++ b/modules/gui/chowdsp_gui/PluginComponents/chowdsp_ParametersView.h @@ -14,6 +14,9 @@ class ParametersView : public juce::Component void paint (juce::Graphics&) override; void resized() override; + /** Returns nullptr if no component is found for the given parameter */ + [[nodiscard]] juce::Component* getComponentForParameter (const juce::RangedAudioParameter&); + private: struct Pimpl; std::unique_ptr pimpl; @@ -40,9 +43,9 @@ class ParametersViewEditor : public juce::AudioProcessorEditor view.setBounds (getLocalBounds()); } -private: ParametersView view; +private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ParametersViewEditor) }; } // namespace chowdsp diff --git a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_RhythmParameter.cpp b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_RhythmParameter.cpp index 67ea847b6..02704d7e8 100644 --- a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_RhythmParameter.cpp +++ b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_RhythmParameter.cpp @@ -5,10 +5,10 @@ namespace chowdsp RhythmParameter::RhythmParameter (const ParameterID& parameterID, const juce::String& paramName, const std::vector& rhythms, - const RhythmUtils::Rhythm& defaultRhythm) : juce::AudioParameterChoice (parameterID, - paramName, - makeParameterChoiceList (rhythms), - getDefaultParameterChoice (rhythms, defaultRhythm)), + const RhythmUtils::Rhythm& defaultRhythm) : chowdsp::ChoiceParameter (parameterID, + paramName, + makeParameterChoiceList (rhythms), + getDefaultParameterChoice (rhythms, defaultRhythm)), rhythmChoices (rhythms) { } diff --git a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_RhythmParameter.h b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_RhythmParameter.h index 43e98a037..359b77fc1 100644 --- a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_RhythmParameter.h +++ b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_RhythmParameter.h @@ -9,7 +9,7 @@ namespace chowdsp * a rhythm. This might be useful for making a delay time synced to * the tempo of a song. */ -class RhythmParameter : public juce::AudioParameterChoice +class RhythmParameter : public chowdsp::ChoiceParameter { public: RhythmParameter (const ParameterID& paramID, @@ -17,6 +17,8 @@ class RhythmParameter : public juce::AudioParameterChoice const std::vector& rhythms = RhythmUtils::getDefaultRhythms(), const RhythmUtils::Rhythm& defaultRhythm = RhythmUtils::QUARTER); + using Ptr = OptionalPointer; + /** Returns the length of time associated with the current rhythm for a given BPM in seconds */ double getRhythmTimeSeconds (double tempoBPM) const; diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h index 6fcf78dc7..557ac5e7d 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h @@ -6,6 +6,9 @@ namespace chowdsp class ParamHolder { public: + /** Convenient alias for a Parameter ID */ + using PID = juce::ParameterID; + /** * Creates a ParamHolder. The user might want to name the ParamHolder, * or make it "non-owning" so it doesn't take ownership of the parameter