Skip to content

Commit

Permalink
Fixing plugin state test
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Nov 22, 2024
1 parent ce9d5f2 commit 320b68f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*build*/
cmake-build*/
.raddbg_project
.vscode/
docs/
.idea/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ inline ParamHolder::ParamHolder (ParamHolder* parent, std::string_view phName, b
return OptionalPointer<ChainedArenaAllocator> { static_cast<size_t> (1024) };
}(),
},
allParamsMap { MapAllocator { arena } },
name { arena::alloc_string (*arena, phName) },
isOwning { phIsOwning }
{
}

inline ParamHolder::ParamHolder (ChainedArenaAllocator& alloc, std::string_view phName, bool phIsOwning)
: arena { &alloc, false }, name { arena::alloc_string (*arena, phName) }, isOwning { phIsOwning }
: arena { &alloc, false },
allParamsMap { MapAllocator { arena } },
name { arena::alloc_string (*arena, phName) },
isOwning { phIsOwning }
{
}

Expand Down Expand Up @@ -110,6 +114,10 @@ std::enable_if_t<std::is_base_of_v<BoolParameter, ParamType>, void>
template <typename... OtherParams>
void ParamHolder::add (ParamHolder& paramHolder, OtherParams&... others)
{
// This should be the parent of the holder being added.
// Maybe we can relax this restriction if we no longer need the allParamsMap.
jassert (arena == paramHolder.arena);

allParamsMap.merge (paramHolder.allParamsMap);
jassert (paramHolder.allParamsMap.empty()); // assuming no duplicate parameter IDs, all the parameters should be moved in the merge!
things.insert (ThingPtr { reinterpret_cast<PackedVoid*> (&paramHolder), Holder });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class ParamHolder
using MapKey = std::string_view;
using MapValue = ThingPtr;
using MapAllocator = STLArenaAllocator<std::pair<const MapKey, MapValue>, ChainedArenaAllocator>;
std::unordered_map<MapKey, MapValue, std::hash<MapKey>, std::equal_to<>, MapAllocator> allParamsMap { MapAllocator { arena } };
using AllParamsMap = std::unordered_map<MapKey, MapValue, std::hash<MapKey>, std::equal_to<>, MapAllocator>;
AllParamsMap allParamsMap;

std::string_view name;
bool isOwning;
Expand Down
11 changes: 6 additions & 5 deletions tests/plugin_tests/chowdsp_plugin_state_test/ParamHolderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ TEST_CASE ("ParamHolder Test", "[plugin][state]")
{
SECTION ("add()")
{
chowdsp::BoolParameter::Ptr boolNested { "param1", "Param", false };
chowdsp::ChoiceParameter::Ptr choiceNested { "param2", "Param", juce::StringArray { "One", "Two" }, 0 };
chowdsp::ParamHolder nestedParams;
nestedParams.add (boolNested, choiceNested);

chowdsp::ParamHolder params;
std::array<chowdsp::PercentParameter::Ptr, 2> floatParams {
chowdsp::PercentParameter::Ptr { "param3", "Param", 0.5f },
chowdsp::PercentParameter::Ptr { "param4", "Param", 0.5f },
};

chowdsp::BoolParameter::Ptr boolNested { "param1", "Param", false };
chowdsp::ChoiceParameter::Ptr choiceNested { "param2", "Param", juce::StringArray { "One", "Two" }, 0 };
chowdsp::ParamHolder nestedParams { &params };
nestedParams.add (boolNested, choiceNested);

params.add (nestedParams, floatParams);

auto allParamIDs = [&params]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ using StateWithTripleOfSameType = chowdsp::PluginStateImpl<PluginParameterStateT

struct NewGroup : chowdsp::ParamHolder
{
NewGroup()
explicit NewGroup(ParamHolder* parent)
: ParamHolder { parent }
{
add (newParam);
}
Expand All @@ -135,7 +136,7 @@ struct PluginParameterStateNewGroup : chowdsp::ParamHolder
LevelParams levelParams { this };
chowdsp::ChoiceParameter::Ptr mode { "mode", "Mode", juce::StringArray { "Percent", "Gain", "Percent / Gain", "Gain / Percent" }, 2 };
chowdsp::BoolParameter::Ptr onOff { "on_off", "On/Off", true };
NewGroup newGroup;
NewGroup newGroup { this };
};

using StateWithNewGroup = chowdsp::PluginStateImpl<PluginParameterStateNewGroup>;
Expand Down

0 comments on commit 320b68f

Please sign in to comment.