Skip to content

Commit

Permalink
Tweaks for ParamHolder and ParametersView (#550)
Browse files Browse the repository at this point in the history
* Allow ParamHolder to be used with const parameter pointers

* Fix assertion

* Fixes

* Apply clang-format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jatinchowdhury18 and github-actions[bot] authored Aug 27, 2024
1 parent ceb5df6 commit ee4722f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ struct PoolAllocator

~PoolAllocator()
{
aligned_free (backing_buffer.data());
if (backing_buffer.data() != nullptr)
aligned_free (backing_buffer.data());
}

/** Re-allocates the allocator's backing buffer to fit some number of chunks. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ namespace parameters_view_detail
parameterName.setInterceptsMouseClicks (false, false);
addAndMakeVisible (parameterName);

parameterLabel.setText (parameter.getLabel(), juce::dontSendNotification);
parameterLabel.setInterceptsMouseClicks (false, false);
addAndMakeVisible (parameterLabel);

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

Expand All @@ -102,14 +98,16 @@ namespace parameters_view_detail
{
auto area = getLocalBounds();

parameterName.setBounds (area.removeFromLeft (100));
parameterLabel.setBounds (area.removeFromRight (50));
parameterName.setBounds (area.removeFromLeft (parameterName
.getFont()
.getStringWidth (parameterName.getText())
* 11 / 10));
parameterComp->setBounds (area);
}

private:
juce::RangedAudioParameter& parameter;
juce::Label parameterName, parameterLabel;
juce::Label parameterName;
std::unique_ptr<juce::Component> parameterComp;

std::unique_ptr<juce::Component> createParameterComp (ParameterListeners& listeners) const
Expand Down Expand Up @@ -183,6 +181,7 @@ struct ParametersView::Pimpl
Pimpl (ParamHolder& params, ParameterListeners& listeners)
: groupItem (params, listeners)
{
view.setIndentSize (5);
const auto numIndents = getNumIndents (groupItem);
const auto width = 400 + view.getIndentSize() * numIndents;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,30 @@ std::enable_if_t<std::is_base_of_v<BoolParameter, ParamType>, void>
add (others...);
}

template <typename ParamType, typename... OtherParams>
std::enable_if_t<std::is_base_of_v<FloatParameter, ParamType>, void>
ParamHolder::add (const OptionalPointer<ParamType>& floatParam, OtherParams&... others)
{
jassert (! isOwning);
add (const_cast<OptionalPointer<ParamType>&> (floatParam), others...);
}

template <typename ParamType, typename... OtherParams>
std::enable_if_t<std::is_base_of_v<ChoiceParameter, ParamType>, void>
ParamHolder::add (const OptionalPointer<ParamType>& choiceParam, OtherParams&... others)
{
jassert (! isOwning);
add (const_cast<OptionalPointer<ParamType>&> (choiceParam), others...);
}

template <typename ParamType, typename... OtherParams>
std::enable_if_t<std::is_base_of_v<BoolParameter, ParamType>, void>
ParamHolder::add (const OptionalPointer<ParamType>& boolParam, OtherParams&... others)
{
jassert (! isOwning);
add (const_cast<OptionalPointer<ParamType>&> (boolParam), others...);
}

template <typename... OtherParams>
void ParamHolder::add (ParamHolder& paramHolder, OtherParams&... others)
{
Expand Down
15 changes: 15 additions & 0 deletions modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ class ParamHolder
std::enable_if_t<std::is_base_of_v<BoolParameter, ParamType>, void>
add (OptionalPointer<ParamType>& boolParam, OtherParams&... others);

/** Adds parameters to the ParamHolder. */
template <typename ParamType, typename... OtherParams>
std::enable_if_t<std::is_base_of_v<FloatParameter, ParamType>, void>
add (const OptionalPointer<ParamType>& floatParam, OtherParams&... others);

/** Adds parameters to the ParamHolder. */
template <typename ParamType, typename... OtherParams>
std::enable_if_t<std::is_base_of_v<ChoiceParameter, ParamType>, void>
add (const OptionalPointer<ParamType>& choiceParam, OtherParams&... others);

/** Adds parameters to the ParamHolder. */
template <typename ParamType, typename... OtherParams>
std::enable_if_t<std::is_base_of_v<BoolParameter, ParamType>, void>
add (const OptionalPointer<ParamType>& boolParam, OtherParams&... others);

/** Adds parameters to the ParamHolder. */
template <typename... OtherParams>
void add (ParamHolder& paramHolder, OtherParams&... others);
Expand Down

0 comments on commit ee4722f

Please sign in to comment.