From 6f3d01af86f850527827ffc02c9604c78e39c2cd Mon Sep 17 00:00:00 2001 From: Vincenzo Sicurella Date: Thu, 4 Jan 2024 22:07:04 -0500 Subject: [PATCH] refactor some editor listener calls and implement in controller options --- Source/GeneralOptionsDlg.cpp | 22 +++++-- Source/GeneralOptionsDlg.h | 10 +++- Source/PedalSensitivityDlg.cpp | 57 ++++++++++++++----- Source/PedalSensitivityDlg.h | 29 ++++++---- .../data/application_state.cpp | 11 +++- .../listeners/editor_listener.h | 16 +++--- 6 files changed, 104 insertions(+), 41 deletions(-) diff --git a/Source/GeneralOptionsDlg.cpp b/Source/GeneralOptionsDlg.cpp index acc47a40..221391c4 100644 --- a/Source/GeneralOptionsDlg.cpp +++ b/Source/GeneralOptionsDlg.cpp @@ -68,7 +68,7 @@ GeneralOptionsDlg::GeneralOptionsDlg (const LumatoneEditorState& stateIn) //[UserPreSize] labelGeneralSettingslTitle->setFont(getAppFonts().getFont(LumatoneEditorFont::UniviaProBold)); - // getLumatoneController()->addFirmwareListener(this); + addEditorListener(this); //[/UserPreSize] setSize (188, 96); @@ -81,7 +81,7 @@ GeneralOptionsDlg::GeneralOptionsDlg (const LumatoneEditorState& stateIn) GeneralOptionsDlg::~GeneralOptionsDlg() { //[Destructor_pre]. You can add your own custom destruction code here.. - // getLumatoneController()->removeFirmwareListener(this); + removeEditorListener(this); //[/Destructor_pre] labelGeneralSettingslTitle = nullptr; @@ -173,10 +173,22 @@ void GeneralOptionsDlg::loadFromMapping() buttonLightOnKeyStrokes->setToggleState(getLightOnKeyStrokes(), juce::NotificationType::dontSendNotification); } -void GeneralOptionsDlg::presetFlagsReceived(LumatoneFirmware::PresetFlags presetFlags) +//void GeneralOptionsDlg::presetFlagsReceived(LumatoneFirmware::PresetFlags presetFlags) +//{ +// buttonAfterTouchActive->setToggleState(presetFlags.polyphonicAftertouch, dontSendNotification); +// buttonLightOnKeyStrokes->setToggleState(presetFlags.lightsOnKeystroke, dontSendNotification); +//} + +void GeneralOptionsDlg::lightOnKeyStrokesChanged(bool lightOn) +{ + buttonLightOnKeyStrokes->setToggleState(getLightOnKeyStrokes(), dontSendNotification); + +} + +void GeneralOptionsDlg::aftertouchToggled(bool enabled) { - buttonAfterTouchActive->setToggleState(presetFlags.polyphonicAftertouch, dontSendNotification); - buttonLightOnKeyStrokes->setToggleState(presetFlags.lightsOnKeystroke, dontSendNotification); + buttonAfterTouchActive->setToggleState(getAftertouchOn(), dontSendNotification); + } //[/MiscUserCode] diff --git a/Source/GeneralOptionsDlg.h b/Source/GeneralOptionsDlg.h index 16e4b7e8..6c2842cf 100644 --- a/Source/GeneralOptionsDlg.h +++ b/Source/GeneralOptionsDlg.h @@ -22,7 +22,7 @@ //[Headers] -- You can add your own extra header files here -- #include -#include "./lumatone_editor_library/listeners/firmware_listener.h" +#include "./lumatone_editor_library/listeners/editor_listener.h" #include "LumatoneEditorState.h" //[/Headers] @@ -39,7 +39,7 @@ */ class GeneralOptionsDlg : public juce::Component, public LumatoneEditorState, - public LumatoneEditor::FirmwareListener, + public LumatoneEditor::EditorListener, public juce::Button::Listener { public: @@ -56,7 +56,11 @@ class GeneralOptionsDlg : public juce::Component, void lookAndFeelChanged() override; // LumatoneEditor::FirmwareListener Implementation - void presetFlagsReceived(LumatoneFirmware::PresetFlags presetFlags) override; + //void presetFlagsReceived(LumatoneFirmware::PresetFlags presetFlags) override; + + // LumatoneEditor::EditorListener Implementation + void lightOnKeyStrokesChanged(bool lightOn) override; + void aftertouchToggled(bool enabled) override; //[/UserMethods] diff --git a/Source/PedalSensitivityDlg.cpp b/Source/PedalSensitivityDlg.cpp index 1e4d2fb2..42fcd854 100644 --- a/Source/PedalSensitivityDlg.cpp +++ b/Source/PedalSensitivityDlg.cpp @@ -102,7 +102,7 @@ PedalSensitivityDlg::PedalSensitivityDlg (const LumatoneEditorState& stateIn) labelExprContrSensitivity->setFont(getAppFonts().getFont(LumatoneEditorFont::GothamNarrowMedium)); labelExprContrSensitivity->setJustificationType(Justification::centred); - // getLumatoneController()->addFirmwareListener(this); + addEditorListener(this); //[/UserPreSize] setSize (134, 96); @@ -115,6 +115,7 @@ PedalSensitivityDlg::PedalSensitivityDlg (const LumatoneEditorState& stateIn) PedalSensitivityDlg::~PedalSensitivityDlg() { //[Destructor_pre]. You can add your own custom destruction code here.. + removeEditorListener(this); //[/Destructor_pre] labelExprContrSensitivity = nullptr; @@ -263,9 +264,49 @@ void PedalSensitivityDlg::loadFromMapping() sldExprCtrlSensitivity->setValue(getExpressionSensitivity(), juce::NotificationType::dontSendNotification); } -void PedalSensitivityDlg::firmwareRevisionReceived(LumatoneFirmware::Version version) +//void PedalSensitivityDlg::firmwareRevisionReceived(LumatoneFirmware::Version version) +//{ +// if (getFirmwareSupport().versionAcknowledgesCommand(version, INVERT_SUSTAIN_PEDAL)) +// { +// btnInvertSustain->setEnabled(true); +// btnInvertSustain->setTooltip(""); +// } +// else +// { +// btnInvertSustain->setEnabled(false); +// btnInvertSustain->setTooltip("This feature is not supported by the firmware version of your Lumatone."); +// } +//} + +//void PedalSensitivityDlg::presetFlagsReceived(LumatoneFirmware::PresetFlags presetFlags) +//{ +// btnInvertExpression->setToggleState(presetFlags.expressionPedalInverted, dontSendNotification); +// btnInvertSustain->setToggleState(presetFlags.sustainPedalInverted, dontSendNotification); +//} + +//void PedalSensitivityDlg::expressionPedalSensitivityReceived(int sensitivity) +//{ +// sldExprCtrlSensitivity->setValue(sensitivity, dontSendNotification); +//} + +void PedalSensitivityDlg::expressionPedalSensitivityChanged(unsigned char value) { - if (getFirmwareSupport().versionAcknowledgesCommand(version, INVERT_SUSTAIN_PEDAL)) + sldExprCtrlSensitivity->setValue(getExpressionSensitivity(), dontSendNotification); +} + +void PedalSensitivityDlg::invertFootControllerChanged(bool inverted) +{ + btnInvertExpression->setToggleState(getInvertExpression(), dontSendNotification); +} + +void PedalSensitivityDlg::invertSustainToggled(bool inverted) +{ + btnInvertSustain->setToggleState(getInvertSustain(), dontSendNotification); +} + +void PedalSensitivityDlg::firmwareVersionChanged() +{ + if (getFirmwareSupport().versionAcknowledgesCommand(getLumatoneVersion(), INVERT_SUSTAIN_PEDAL)) { btnInvertSustain->setEnabled(true); btnInvertSustain->setTooltip(""); @@ -277,16 +318,6 @@ void PedalSensitivityDlg::firmwareRevisionReceived(LumatoneFirmware::Version ver } } -void PedalSensitivityDlg::presetFlagsReceived(LumatoneFirmware::PresetFlags presetFlags) -{ - btnInvertExpression->setToggleState(presetFlags.expressionPedalInverted, dontSendNotification); - btnInvertSustain->setToggleState(presetFlags.sustainPedalInverted, dontSendNotification); -} - -void PedalSensitivityDlg::expressionPedalSensitivityReceived(int sensitivity) -{ - sldExprCtrlSensitivity->setValue(sensitivity, dontSendNotification); -} //[/MiscUserCode] diff --git a/Source/PedalSensitivityDlg.h b/Source/PedalSensitivityDlg.h index d8302cab..b05dff87 100644 --- a/Source/PedalSensitivityDlg.h +++ b/Source/PedalSensitivityDlg.h @@ -24,7 +24,7 @@ #include "LumatoneEditorState.h" -#include "./lumatone_editor_library/listeners/firmware_listener.h" +#include "./lumatone_editor_library/listeners/editor_listener.h" //[/Headers] @@ -37,11 +37,12 @@ Describe your class and how it works here! //[/Comments] */ -class PedalSensitivityDlg : public juce::Component, - public LumatoneEditorState, - public LumatoneEditor::FirmwareListener, - public juce::Button::Listener, - public juce::Slider::Listener +class PedalSensitivityDlg : public juce::Component + , public LumatoneEditorState + //, private LumatoneEditor::FirmwareListener + , private LumatoneEditor::EditorListener + , private juce::Button::Listener + , private juce::Slider::Listener { public: //============================================================================== @@ -56,9 +57,17 @@ class PedalSensitivityDlg : public juce::Component, void lookAndFeelChanged() override; // LumatoneEditor::FirmwareListener implementation - void firmwareRevisionReceived(LumatoneFirmware::Version version) override; - void presetFlagsReceived(LumatoneFirmware::PresetFlags presetFlags) override; - void expressionPedalSensitivityReceived(int sensitivity) override; + //void firmwareRevisionReceived(LumatoneFirmware::Version version) override; + //void presetFlagsReceived(LumatoneFirmware::PresetFlags presetFlags) override; + //void expressionPedalSensitivityReceived(int sensitivity) override; + + // LumatoneEditor::Editor implementation + void expressionPedalSensitivityChanged(unsigned char value) override; + void invertFootControllerChanged(bool inverted) override; + + void invertSustainToggled(bool inverted) override; + + void firmwareVersionChanged() override; //[/UserMethods] @@ -67,8 +76,6 @@ class PedalSensitivityDlg : public juce::Component, void buttonClicked (juce::Button* buttonThatWasClicked) override; void sliderValueChanged (juce::Slider* sliderThatWasMoved) override; - - private: //[UserVariables] -- You can add your own custom variables in this section. int roundedCornerSize = 0; diff --git a/Source/lumatone_editor_library/data/application_state.cpp b/Source/lumatone_editor_library/data/application_state.cpp index 0b28d017..4d262c5f 100644 --- a/Source/lumatone_editor_library/data/application_state.cpp +++ b/Source/lumatone_editor_library/data/application_state.cpp @@ -175,6 +175,15 @@ void LumatoneApplicationState::setCompleteConfig(const LumatoneLayout &layoutIn) } editorListeners->call(&LumatoneEditor::EditorListener::completeMappingLoaded, *mappingData); + editorListeners->call(&LumatoneEditor::EditorListener::expressionPedalSensitivityChanged, getExpressionSensitivity()); + editorListeners->call(&LumatoneEditor::EditorListener::invertFootControllerChanged, getInvertExpression()); + editorListeners->call(&LumatoneEditor::EditorListener::lightOnKeyStrokesChanged, getLightOnKeyStrokes()); + editorListeners->call(&LumatoneEditor::EditorListener::aftertouchToggled, getAftertouchOn()); + + editorListeners->call(&LumatoneEditor::EditorListener::configTableChanged, LumatoneConfigTable::TableType::velocityInterval); + editorListeners->call(&LumatoneEditor::EditorListener::configTableChanged, LumatoneConfigTable::TableType::fader); + editorListeners->call(&LumatoneEditor::EditorListener::configTableChanged, LumatoneConfigTable::TableType::afterTouch); + editorListeners->call(&LumatoneEditor::EditorListener::configTableChanged, LumatoneConfigTable::TableType::lumaTouch); } void LumatoneApplicationState::setLayout(const LumatoneLayout &layoutIn) @@ -335,7 +344,7 @@ void LumatoneApplicationState::setConfigTable(LumatoneConfigTable::TableType typ controller->sendTableConfig(type, table.velocityValues); } - editorListeners->call(&LumatoneEditor::EditorListener::configTableChanged, type, *mappingData->getConfigTable(type)); + editorListeners->call(&LumatoneEditor::EditorListener::configTableChanged, type); } // //void LumatoneApplicationState::setVelocityIntervalTable(const LumatoneConfigTable& tableIn) diff --git a/Source/lumatone_editor_library/listeners/editor_listener.h b/Source/lumatone_editor_library/listeners/editor_listener.h index a29a0bd8..32b9183e 100644 --- a/Source/lumatone_editor_library/listeners/editor_listener.h +++ b/Source/lumatone_editor_library/listeners/editor_listener.h @@ -24,34 +24,34 @@ class EditorListener virtual void contextChanged(LumatoneContext* context) {} - virtual void configTableChanged(LumatoneConfigTable::TableType type, const LumatoneConfigTable& table) {} + virtual void configTableChanged(LumatoneConfigTable::TableType type) {} // Firmware Actions virtual void keyConfigChanged(int boardIndex, int keyIndex, LumatoneKey keyData) {} virtual void keyColourChanged(int boardIndex, int keyIndex, juce::Colour keyColour) {} + virtual void expressionPedalSensitivityChanged(unsigned char value) {} virtual void invertFootControllerChanged(bool inverted) {} + virtual void macroButtonActiveColourChagned(juce::Colour colour) {} virtual void macroButtonInactiveColourChanged(juce::Colour colour) {} + virtual void lightOnKeyStrokesChanged(bool lightOn) {} - - virtual void velocityConfigSaved() {} - virtual void velocityConfigReset() {} + virtual void velocityConfigChanged() {} virtual void aftertouchToggled(bool enabled) {} virtual void calibrateAftertouchToggled(bool active) {} - virtual void aftertouchConfigReset() {} + virtual void aftertouchConfigChanged() {} - virtual void serialIdentityRequested() {} virtual void calibrateKeysRequested() {} virtual void calibratePitchModWheelToggled(bool active) {} - virtual void lumatouchConfigReset() {} + virtual void lumatouchConfigChanged() {} - virtual void firmwareVersionRequested() {} + virtual void firmwareVersionChanged() {} virtual void pingSent(juce::uint8 pingId) {} virtual void peripheralChannelsChanged(int pitchWheelChannel, int modWheelChannel, int expressionChannel, int sustainChannel) {}