Skip to content

Commit

Permalink
Parameter tweaks and adding a component getter to parameters view (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 authored Nov 8, 2023
1 parent 63af51d commit 7e7179e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace parameters_view_detail
BooleanParameterComponent (BoolParameter& param, PluginState& pluginState)
: attachment (param, pluginState, button)
{
setComponentID (param.paramID);
addAndMakeVisible (button);
}

Expand All @@ -33,6 +34,7 @@ namespace parameters_view_detail
ChoiceParameterComponent (ChoiceParameter& param, PluginState& pluginState)
: attachment (param, pluginState, box)
{
setComponentID (param.paramID);
addAndMakeVisible (box);
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -90,6 +93,7 @@ namespace parameters_view_detail
addAndMakeVisible (parameterLabel);

addAndMakeVisible (*(parameterComp = createParameterComp (pluginState)));
setComponentID (parameterComp->getComponentID());

setSize (400, 40);
}
Expand Down Expand Up @@ -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<const parameters_view_detail::ParamControlItem*> (subItem))
{
if (&paramControlItem->param == &param)
return tree.getItemComponent (subItem);
}

if (auto* comp = getComponentForParameter (param, *subItem, tree))
return comp;
}
}
return nullptr;
}

parameters_view_detail::ParameterGroupItem groupItem;
juce::TreeView view;
};
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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> pimpl;
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace chowdsp
RhythmParameter::RhythmParameter (const ParameterID& parameterID,
const juce::String& paramName,
const std::vector<RhythmUtils::Rhythm>& 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)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ 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,
const juce::String& paramName,
const std::vector<RhythmUtils::Rhythm>& rhythms = RhythmUtils::getDefaultRhythms(),
const RhythmUtils::Rhythm& defaultRhythm = RhythmUtils::QUARTER);

using Ptr = OptionalPointer<RhythmParameter>;

/** Returns the length of time associated with the current rhythm for a given BPM in seconds */
double getRhythmTimeSeconds (double tempoBPM) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e7179e

Please sign in to comment.