commit a6336fe60305c539670b520a7b973135715595b6
parent 3dc8951055124a7b700541fb662f7c7367f204ef
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Sat, 1 Jun 2024 15:53:38 +0200
cleanup parameter unnormalized/normalized value getters/setters
Diffstat:
12 files changed, 51 insertions(+), 61 deletions(-)
diff --git a/source/jucePluginLib/controller.cpp b/source/jucePluginLib/controller.cpp
@@ -10,9 +10,9 @@
namespace pluginLib
{
- uint8_t getParameterValue(Parameter* _p)
+ uint8_t getParameterValue(const Parameter* _p)
{
- return static_cast<uint8_t>(roundToInt(_p->getValueObject().getValue()));
+ return static_cast<uint8_t>(_p->getUnnormalizedValue());
}
Controller::Controller(Processor& _processor, const std::string& _parameterDescJson)
diff --git a/source/jucePluginLib/parameter.cpp b/source/jucePluginLib/parameter.cpp
@@ -36,18 +36,18 @@ namespace pluginLib
if(_notifyHost && getDescription().isPublic)
{
- const float v = convertTo0to1(static_cast<float>(newValue));
-
switch (_origin)
{
case Origin::Midi:
case Origin::HostAutomation:
case Origin::Derived:
- setValue(v, Origin::Derived);
+ case Origin::PresetChange:
+ setUnnormalizedValue(newValue, Origin::Derived);
break;
- default:
+ case Origin::Unknown:
+ case Origin::Ui:
beginChangeGesture();
- setValueNotifyingHost(v, Origin::Derived);
+ setUnnormalizedValueNotifyingHost(newValue, Origin::Derived);
endChangeGesture();
break;
}
@@ -121,10 +121,22 @@ namespace pluginLib
void Parameter::setValueNotifyingHost(const float _value, const Origin _origin)
{
- setValue(_value, _origin);
+ setUnnormalizedValue(juce::roundToInt(convertFrom0to1(_value)), _origin);
sendValueChangedMessageToListeners(_value);
}
+ void Parameter::setUnnormalizedValueNotifyingHost(const float _value, const Origin _origin)
+ {
+ setUnnormalizedValue(juce::roundToInt(_value), _origin);
+ sendValueChangedMessageToListeners(convertTo0to1(_value));
+ }
+
+ void Parameter::setUnnormalizedValueNotifyingHost(const int _value, const Origin _origin)
+ {
+ setUnnormalizedValue(_value, _origin);
+ sendValueChangedMessageToListeners(convertTo0to1(static_cast<float>(_value)));
+ }
+
void Parameter::setRateLimitMilliseconds(const uint32_t _ms)
{
m_rateLimit = _ms;
@@ -153,27 +165,19 @@ namespace pluginLib
void Parameter::setValue(const float _newValue)
{
- setValue(_newValue, Origin::HostAutomation);
+ setUnnormalizedValue(juce::roundToInt(convertFrom0to1(_newValue)), Origin::HostAutomation);
}
- void Parameter::setValue(const float _newValue, const Origin _origin)
+ void Parameter::setUnnormalizedValue(const int _newValue, const Origin _origin)
{
if (m_changingDerivedValues)
return;
- const auto floatValue = convertFrom0to1(_newValue);
m_lastValueOrigin = _origin;
- m_value.setValue(floatValue);
-
+ m_value.setValue(clampValue(_newValue));
sendToSynth();
- forwardToDerived(m_value.getValue(), _origin, true);
- }
-
- void Parameter::setUnnormalizedValue(const int _newValue, const Origin _origin)
- {
- const auto v = convertTo0to1(static_cast<float>(_newValue));
- setValue(v, _origin);
+ forwardToDerived(_newValue, _origin, true);
}
void Parameter::setValueFromSynth(const int _newValue, const Origin _origin)
@@ -193,8 +197,7 @@ namespace pluginLib
if (notifyHost && getDescription().isPublic)
{
beginChangeGesture();
- const auto v = convertTo0to1(static_cast<float>(clampedValue));
- setValueNotifyingHost(v, _origin);
+ setUnnormalizedValueNotifyingHost(clampedValue, _origin);
endChangeGesture();
}
else
@@ -206,7 +209,7 @@ namespace pluginLib
forwardToDerived(_newValue, _origin, notifyHost);
}
- void Parameter::forwardToDerived(const int _newValue, Origin _origin, const bool _notifyHost)
+ void Parameter::forwardToDerived(const int _newValue, const Origin _origin, const bool _notifyHost)
{
if (m_changingDerivedValues)
return;
diff --git a/source/jucePluginLib/parameter.h b/source/jucePluginLib/parameter.h
@@ -32,8 +32,7 @@ namespace pluginLib
Parameter(Controller& _controller, const Description& _desc, uint8_t _partNum, int _uniqueId);
- juce::Value &getValueObject() { return m_value; }
- const juce::Value &getValueObject() const { return m_value; }
+ juce::Value& getValueObject() { return m_value; }
const Description& getDescription() const { return m_desc; }
@@ -43,10 +42,11 @@ namespace pluginLib
bool isMetaParameter() const override;
- float getValue() const override { return convertTo0to1(m_value.getValue()); }
int getUnnormalizedValue() const { return juce::roundToInt(m_value.getValue()); }
+ float getValue() const override { return convertTo0to1(m_value.getValue()); }
+
void setValue(float _newValue) override;
- void setValue(float _newValue, Origin _origin);
+
void setUnnormalizedValue(int _newValue, Origin _origin);
void setValueFromSynth(int _newValue, Origin _origin);
@@ -85,6 +85,8 @@ namespace pluginLib
Origin getChangeOrigin() const { return m_lastValueOrigin; }
void setValueNotifyingHost(float _value, Origin _origin);
+ void setUnnormalizedValueNotifyingHost(float _value, Origin _origin);
+ void setUnnormalizedValueNotifyingHost(int _value, Origin _origin);
void setRateLimitMilliseconds(uint32_t _ms);
diff --git a/source/jucePluginLib/parameterbinding.cpp b/source/jucePluginLib/parameterbinding.cpp
@@ -24,12 +24,12 @@ namespace pluginLib
void ParameterBinding::MouseListener::mouseDrag(const juce::MouseEvent& event)
{
- m_param->setValueNotifyingHost(m_param->convertTo0to1(static_cast<float>(m_slider->getValue())), Parameter::Origin::Ui);
+ m_param->setUnnormalizedValueNotifyingHost(static_cast<float>(m_slider->getValue()), Parameter::Origin::Ui);
}
void ParameterBinding::MouseListener::mouseWheelMove(const juce::MouseEvent& event, const juce::MouseWheelDetails& wheel)
{
- m_param->setValueNotifyingHost(m_param->convertTo0to1(static_cast<float>(m_slider->getValue())), Parameter::Origin::Ui);
+ m_param->setUnnormalizedValueNotifyingHost(static_cast<float>(m_slider->getValue()), Parameter::Origin::Ui);
}
void ParameterBinding::MouseListener::mouseDoubleClick(const juce::MouseEvent& event)
@@ -165,7 +165,7 @@ namespace pluginLib
if(v->getDescription().isPublic)
{
v->beginChangeGesture();
- v->setValueNotifyingHost(v->convertTo0to1(static_cast<float>(id - 1)), Parameter::Origin::Ui);
+ v->setUnnormalizedValueNotifyingHost(id - 1, Parameter::Origin::Ui);
v->endChangeGesture();
}
v->getValueObject().setValue(id - 1);
@@ -173,7 +173,7 @@ namespace pluginLib
const auto listenerId = v->onValueChanged.addListener([this, &_combo](pluginLib::Parameter* v)
{
- const auto value = static_cast<int>(v->getValueObject().getValueSource().getValue());
+ const auto value = v->getUnnormalizedValue();
_combo.setSelectedId(value + 1, juce::dontSendNotification);
});
diff --git a/source/jucePluginLib/softknob.cpp b/source/jucePluginLib/softknob.cpp
@@ -49,20 +49,20 @@ namespace pluginLib
bind();
}
- void SoftKnob::onSourceValueChanged()
+ void SoftKnob::onSourceValueChanged() const
{
if(!m_targetParam)
return;
- const auto v = m_sourceParam->getValue();
- m_targetParam->setValue(v, Parameter::Origin::Derived);
+ const auto v = m_sourceParam->getUnnormalizedValue();
+ m_targetParam->setUnnormalizedValue(v, Parameter::Origin::Derived);
}
- void SoftKnob::onTargetValueChanged()
+ void SoftKnob::onTargetValueChanged() const
{
assert(m_targetParam);
- const auto v = m_targetParam->getValue();
- m_sourceParam->setValue(v, Parameter::Origin::Derived);
+ const auto v = m_targetParam->getUnnormalizedValue();
+ m_sourceParam->setUnnormalizedValue(v, Parameter::Origin::Derived);
}
void SoftKnob::bind()
diff --git a/source/jucePluginLib/softknob.h b/source/jucePluginLib/softknob.h
@@ -27,8 +27,8 @@ namespace pluginLib
private:
void onTargetChanged();
- void onSourceValueChanged();
- void onTargetValueChanged();
+ void onSourceValueChanged() const;
+ void onTargetValueChanged() const;
void bind();
void unbind();
diff --git a/source/virusJucePlugin/Parts.cpp b/source/virusJucePlugin/Parts.cpp
@@ -116,7 +116,7 @@ namespace genericVirusUI
{
menu.addItem(name + ' ' + std::to_string(i + 1), true, v->getUnnormalizedValue() == i, [v, i]
{
- v->setValue(v->convertTo0to1(i), pluginLib::Parameter::Origin::Ui);
+ v->setUnnormalizedValue(i, pluginLib::Parameter::Origin::Ui);
});
}
diff --git a/source/virusJucePlugin/VirusController.cpp b/source/virusJucePlugin/VirusController.cpp
@@ -128,17 +128,6 @@ namespace Virus
return parseControllerDump(e);
}
- juce::Value* Controller::getParamValue(uint8_t ch, uint8_t bank, uint8_t paramIndex)
- {
- const auto& params = findSynthParam(ch, static_cast<uint8_t>(virusLib::PAGE_A + bank), paramIndex);
- if (params.empty())
- {
- // unregistered param?
- return nullptr;
- }
- return ¶ms.front()->getValueObject();
- }
-
void Controller::parseParamChange(const pluginLib::MidiPacket::Data& _data)
{
const auto page = _data.find(pluginLib::MidiDataType::Page)->second;
@@ -290,9 +279,7 @@ namespace Virus
bool Controller::isMultiMode() const
{
- const auto paramIdx = getParameterIndexByName(g_paramPlayMode);
- const auto& value = getParameter(paramIdx)->getValueObject();
- return value.getValue();
+ return getParameter(g_paramPlayMode, 0)->getUnnormalizedValue();
}
juce::String Controller::getCurrentPartPresetName(const uint8_t _part) const
@@ -308,7 +295,7 @@ namespace Virus
auto* param = getParameter(idx, _part);
if(!param)
break;
- const int v = param->getValueObject().getValue();
+ const auto v = param->getUnnormalizedValue();
name += static_cast<char>(v);
}
return name;
diff --git a/source/virusJucePlugin/VirusController.h b/source/virusJucePlugin/VirusController.h
@@ -82,8 +82,6 @@ namespace Virus
static void printMessage(const pluginLib::SysEx &);
- juce::Value* getParamValue(uint8_t ch, uint8_t bank, uint8_t paramIndex);
-
juce::StringArray getSinglePresetNames(virusLib::BankNumber bank) const;
std::string getSinglePresetName(const pluginLib::MidiPacket::ParamValues& _values) const;
std::string getSinglePresetName(const pluginLib::MidiPacket::AnyPartParamValues& _values) const;
diff --git a/source/virusJucePlugin/VirusEditor.cpp b/source/virusJucePlugin/VirusEditor.cpp
@@ -396,7 +396,7 @@ namespace genericVirusUI
const auto playMode = getController().getParameterIndexByName(Virus::g_paramPlayMode);
auto* param = getController().getParameter(playMode);
- param->setValue(param->convertTo0to1(_playMode), pluginLib::Parameter::Origin::Ui);
+ param->setUnnormalizedValue(_playMode, pluginLib::Parameter::Origin::Ui);
// we send this directly here as we request a new arrangement below, we don't want to wait on juce to inform the knob to have changed
getController().sendParameterChange(*param, _playMode);
diff --git a/source/virusJucePlugin/VirusProcessor.cpp b/source/virusJucePlugin/VirusProcessor.cpp
@@ -30,10 +30,10 @@ void VirusProcessor::processBpm(const float _bpm)
const auto bpmValue = juce::jmin(127, juce::jmax(0, static_cast<int>(_bpm)-63));
const auto clockParam = getController().getParameter(m_clockTempoParam, 0);
- if (clockParam == nullptr || static_cast<int>(clockParam->getValueObject().getValue()) == bpmValue)
+ if (clockParam == nullptr || clockParam->getUnnormalizedValue() == bpmValue)
return;
- clockParam->getValueObject().setValue(bpmValue);
+ clockParam->setUnnormalizedValue(bpmValue, pluginLib::Parameter::Origin::HostAutomation);
}
bool VirusProcessor::setSelectedRom(const uint32_t _index)
diff --git a/source/xtJucePlugin/xtEditor.cpp b/source/xtJucePlugin/xtEditor.cpp
@@ -199,7 +199,7 @@ namespace xtJucePlugin
if(newText.empty())
continue;
- p->setValue(p->convertTo0to1(static_cast<float>(v)), pluginLib::Parameter::Origin::Ui);
+ p->setUnnormalizedValue(v, pluginLib::Parameter::Origin::Ui);
break;
}
}