condition.cpp (1503B)
1 #include "condition.h" 2 3 #include "editor.h" 4 5 namespace genericUI 6 { 7 void Condition::setEnabled(const bool _enable) 8 { 9 m_enabled = _enable; 10 Editor::setEnabled(m_target, _enable); 11 } 12 13 ConditionByParameterValues::ConditionByParameterValues(juce::Component& _target, juce::Value* _value, int32_t _parameterIndex, std::set<uint8_t> _values) 14 : Condition(_target) 15 , m_parameterIndex(_parameterIndex) 16 , m_values(std::move(_values)) 17 { 18 bind(_value); 19 } 20 21 ConditionByParameterValues::~ConditionByParameterValues() 22 { 23 unbind(); 24 } 25 26 void ConditionByParameterValues::valueChanged(juce::Value& _value) 27 { 28 const auto v = roundToInt(_value.getValueSource().getValue()); 29 setEnabled(m_values.find(static_cast<uint8_t>(v)) != m_values.end()); 30 } 31 32 void ConditionByParameterValues::bind(juce::Value* _value) 33 { 34 unbind(); 35 36 m_value = _value; 37 38 if(!m_value) 39 return; 40 41 m_value->addListener(this); 42 valueChanged(*m_value); 43 } 44 45 void ConditionByParameterValues::unbind() 46 { 47 if(!m_value) 48 return; 49 50 m_value->removeListener(this); 51 m_value = nullptr; 52 } 53 54 void ConditionByParameterValues::refresh() 55 { 56 if(m_value) 57 valueChanged(*m_value); 58 } 59 60 void ConditionByParameterValues::setCurrentPart(const Editor& _editor, const uint8_t _part) 61 { 62 unbind(); 63 64 const auto v = _editor.getInterface().getParameterValue(getParameterIndex(), _part); 65 if(v) 66 bind(v); 67 } 68 69 void ConditionByKeyValue::setValue(const std::string& _value) 70 { 71 setEnabled(m_values.find(_value) != m_values.end()); 72 } 73 }