commit 5942e6c1d87d08c26eac77040c57b33266215e70
parent d702d4ebbbd70a88ca816f86bc136255d9c0a3f8
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Fri, 31 May 2024 11:40:24 +0200
begin to replace onValueChanged in parameter with new event system
Diffstat:
4 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/source/jucePluginEditorLib/focusedParameter.cpp b/source/jucePluginEditorLib/focusedParameter.cpp
@@ -7,8 +7,6 @@
namespace jucePluginEditorLib
{
- static constexpr uint32_t g_listenerId = 1;
-
FocusedParameter::FocusedParameter(const pluginLib::Controller& _controller, const pluginLib::ParameterBinding& _parameterBinding, const genericUI::Editor& _editor)
: m_parameterBinding(_parameterBinding)
, m_controller(_controller)
@@ -29,17 +27,14 @@ namespace jucePluginEditorLib
{
for (const auto& param : params.second)
{
- m_boundParameters.push_back(param);
-
- param->onValueChanged.emplace_back(g_listenerId, [this, param]()
+ m_boundParameters.insert({param, pluginLib::EventListener(param->evValueChanged, [this](const pluginLib::Parameter* _param)
{
- if (param->getChangeOrigin() == pluginLib::Parameter::ChangedBy::PresetChange ||
- param->getChangeOrigin() == pluginLib::Parameter::ChangedBy::Derived)
+ if (_param->getChangeOrigin() == pluginLib::Parameter::ChangedBy::PresetChange ||
+ _param->getChangeOrigin() == pluginLib::Parameter::ChangedBy::Derived)
return;
- auto* comp = m_parameterBinding.getBoundComponent(param);
- if(comp)
+ if(auto* comp = m_parameterBinding.getBoundComponent(_param))
updateControlLabel(comp);
- });
+ })});
}
}
}
@@ -48,8 +43,7 @@ namespace jucePluginEditorLib
{
m_tooltip.reset();
- for (auto* p : m_boundParameters)
- p->removeListener(g_listenerId);
+ m_boundParameters.clear();
}
void FocusedParameter::onMouseEnter(const juce::MouseEvent& _event)
@@ -116,7 +110,7 @@ namespace jucePluginEditorLib
const int part = props.contains("part") ? static_cast<int>(props["part"]) : static_cast<int>(m_controller.getCurrentPart());
- auto* p = m_controller.getParameter(v, static_cast<uint8_t>(part));
+ const auto* p = m_controller.getParameter(v, static_cast<uint8_t>(part));
// do not show soft knob parameter if the softknob is bound to another parameter
if(p && p->getDescription().isSoftKnob())
diff --git a/source/jucePluginEditorLib/focusedParameter.h b/source/jucePluginEditorLib/focusedParameter.h
@@ -4,6 +4,8 @@
#include "juce_events/juce_events.h"
+#include "../jucePluginLib/event.h"
+
namespace juce
{
class MouseEvent;
@@ -43,6 +45,6 @@ namespace jucePluginEditorLib
juce::Label* m_focusedParameterName = nullptr;
juce::Label* m_focusedParameterValue = nullptr;
std::unique_ptr<FocusedParameterTooltip> m_tooltip;
- std::vector<pluginLib::Parameter*> m_boundParameters;
+ std::map<pluginLib::Parameter*, pluginLib::EventListener<pluginLib::Parameter*>> m_boundParameters;
};
}
diff --git a/source/jucePluginLib/parameter.cpp b/source/jucePluginLib/parameter.cpp
@@ -20,6 +20,8 @@ namespace pluginLib
for (const auto& func : onValueChanged)
func.second();
+
+ evValueChanged(this);
}
void Parameter::setDerivedValue(const int _value, ChangedBy _origin, bool _notifyHost)
diff --git a/source/jucePluginLib/parameter.h b/source/jucePluginLib/parameter.h
@@ -79,6 +79,8 @@ namespace pluginLib
// eg. multi/single value change requires triggering more logic.
std::list<std::pair<uint32_t, std::function<void()>>> onValueChanged;
+ Event<Parameter*> evValueChanged;
+
void addDerivedParameter(Parameter* _param);
int getUniqueId() const { return m_uniqueId; }