gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit f8c6974f197436644ac01442c60927933ac9bfa7
parent fb4244cd2604c51d596f2b36d4050d7bc8137379
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Sat,  1 Jun 2024 12:48:41 +0200

parameter class code cleanup

Diffstat:
Msource/jucePluginLib/parameter.cpp | 64+++++++++++++++++++++++++++++++++++-----------------------------
Msource/jucePluginLib/parameter.h | 13+++++++++----
2 files changed, 44 insertions(+), 33 deletions(-)

diff --git a/source/jucePluginLib/parameter.cpp b/source/jucePluginLib/parameter.cpp @@ -4,25 +4,29 @@ namespace pluginLib { - Parameter::Parameter(Controller& _controller, const Description& _desc, const uint8_t _partNum, const int _uniqueId) : - juce::RangedAudioParameter(genId(_desc, _partNum, _uniqueId), "Ch " + juce::String(_partNum + 1) + " " + _desc.displayName), m_ctrl(_controller), - m_desc(_desc), m_partNum(_partNum), m_uniqueId(_uniqueId) + Parameter::Parameter(Controller& _controller, const Description& _desc, const uint8_t _partNum, const int _uniqueId) + : juce::RangedAudioParameter(genId(_desc, _partNum, _uniqueId), "Ch " + juce::String(_partNum + 1) + " " + _desc.displayName) + , m_controller(_controller) + , m_desc(_desc) + , m_part(_partNum) + , m_uniqueId(_uniqueId) { m_range.start = static_cast<float>(m_desc.range.getStart()); m_range.end = static_cast<float>(m_desc.range.getEnd()); m_range.interval = m_desc.step ? static_cast<float>(m_desc.step) : (m_desc.isDiscrete || m_desc.isBool ? 1.0f : 0.0f); + m_value.addListener(this); } - void Parameter::valueChanged(juce::Value &) + void Parameter::valueChanged(juce::Value&) { sendToSynth(); onValueChanged(this); } - void Parameter::setDerivedValue(const int _value, ChangedBy _origin, bool _notifyHost) + void Parameter::setDerivedValue(const int _value, const ChangedBy _origin, const bool _notifyHost) { - const int newValue = juce::roundToInt(m_range.getRange().clipValue(static_cast<float>(_value))); + const int newValue = clampValue(_value); if (newValue == m_lastValue) return; @@ -75,7 +79,7 @@ namespace pluginLib else { m_lastSendTime = milliseconds(); - m_ctrl.sendParameterChange(*this, static_cast<uint8_t>(value)); + m_controller.sendParameterChange(*this, static_cast<uint8_t>(value)); } } @@ -99,7 +103,7 @@ namespace pluginLib if(elapsed >= m_rateLimit) { m_lastSendTime = ms; - m_ctrl.sendParameterChange(*this, _value); + m_controller.sendParameterChange(*this, _value); } else { @@ -110,6 +114,11 @@ namespace pluginLib } } + int Parameter::clampValue(const int _value) const + { + return juce::roundToInt(m_range.getRange().clipValue(static_cast<float>(_value))); + } + void Parameter::setValueNotifyingHost(const float _value, const ChangedBy _origin) { setValue(_value, _origin); @@ -158,15 +167,7 @@ namespace pluginLib sendToSynth(); - m_changingDerivedValues = true; - - for (const auto& parameter : m_derivedParameters) - { - if(!parameter->m_changingDerivedValues) - parameter->setDerivedValue(m_value.getValue(), _origin, true); - } - - m_changingDerivedValues = false; + forwardToDerived(m_value.getValue(), _origin, true); } void Parameter::setUnnormalizedValue(const int _newValue, const ChangedBy _origin) @@ -175,16 +176,29 @@ namespace pluginLib setValue(v, _origin); } - void Parameter::setValueFromSynth(int newValue, const bool notifyHost, ChangedBy _origin) + void Parameter::forwardToDerived(const int _newValue, ChangedBy _origin, const bool _notifyHost) + { + if (m_changingDerivedValues) + return; + + m_changingDerivedValues = true; + + for (const auto& p : m_derivedParameters) + p->setDerivedValue(_newValue, _origin, _notifyHost); + + m_changingDerivedValues = false; + } + + void Parameter::setValueFromSynth(const int _newValue, const bool _notifyHost, const ChangedBy _origin) { - const auto clampedValue = juce::roundToInt(m_range.getRange().clipValue(static_cast<float>(newValue))); + const auto clampedValue = clampValue(_newValue); if (clampedValue != m_lastValue) { m_lastValue = clampedValue; m_lastValueOrigin = _origin; - if (notifyHost && getDescription().isPublic) + if (_notifyHost && getDescription().isPublic) { beginChangeGesture(); const auto v = convertTo0to1(static_cast<float>(clampedValue)); @@ -197,15 +211,7 @@ namespace pluginLib } } - if (m_changingDerivedValues) - return; - - m_changingDerivedValues = true; - - for (const auto& p : m_derivedParameters) - p->setDerivedValue(newValue, _origin, notifyHost); - - m_changingDerivedValues = false; + forwardToDerived(_newValue, _origin, _notifyHost); } juce::String Parameter::genId(const Description& d, const int part, const int uniqueId) diff --git a/source/jucePluginLib/parameter.h b/source/jucePluginLib/parameter.h @@ -37,7 +37,7 @@ namespace pluginLib const Description& getDescription() const { return m_desc; } - uint8_t getPart() const { return m_partNum; } + uint8_t getPart() const { return m_part; } const juce::NormalisableRange<float> &getNormalisableRange() const override { return m_range; } @@ -48,7 +48,7 @@ namespace pluginLib void setValue(float _newValue) override; void setValue(float _newValue, ChangedBy _origin); void setUnnormalizedValue(int _newValue, ChangedBy _origin); - void setValueFromSynth(int newValue, bool notifyHost, ChangedBy _origin); + void setValueFromSynth(int _newValue, bool _notifyHost, ChangedBy _origin); bool isDiscrete() const override { return m_desc.isDiscrete; } bool isBoolean() const override { return m_desc.isBool; } @@ -100,12 +100,16 @@ namespace pluginLib void sendToSynth(); static uint64_t milliseconds(); void sendParameterChangeDelayed(uint8_t, uint32_t _uniqueId); + void forwardToDerived(int _newValue, ChangedBy _origin, bool _notifyHost); - Controller& m_ctrl; + int clampValue(int _value) const; + + Controller& m_controller; const Description m_desc; juce::NormalisableRange<float> m_range; - const uint8_t m_partNum; + const uint8_t m_part; const int m_uniqueId; // 0 for all unique parameters, > 0 if multiple Parameter instances reference a single synth parameter + int m_lastValue{-1}; ChangedBy m_lastValueOrigin = ChangedBy::Unknown; juce::Value m_value; @@ -115,6 +119,7 @@ namespace pluginLib uint32_t m_rateLimit = 0; // milliseconds uint64_t m_lastSendTime = 0; uint32_t m_uniqueDelayCallbackId = 0; + bool m_isLocked = false; ParameterLinkType m_linkType = None; };