From ce465ca81983caa0ad26e4d448abdbcedefe3361 Mon Sep 17 00:00:00 2001 From: Vincenzo Sicurella Date: Sun, 21 Jan 2024 02:09:06 -0500 Subject: [PATCH] move state response handling to event manager, implement get macro colour callbacks --- Source/GlobalSettingsArea.cpp | 54 +++---- Source/GlobalSettingsArea.h | 14 +- Source/MainComponent.cpp | 2 +- Source/colour_view_component.cpp | 5 +- Source/colour_view_component.h | 2 +- .../device/lumatone_controller.cpp | 117 +------------- .../device/lumatone_controller.h | 12 +- .../device/lumatone_event_manager.cpp | 145 +++++++++++++++++- .../device/lumatone_event_manager.h | 44 +++--- .../listeners/editor_listener.h | 2 +- 10 files changed, 211 insertions(+), 186 deletions(-) diff --git a/Source/GlobalSettingsArea.cpp b/Source/GlobalSettingsArea.cpp index 3bb0a76b..601836d8 100644 --- a/Source/GlobalSettingsArea.cpp +++ b/Source/GlobalSettingsArea.cpp @@ -22,7 +22,6 @@ #include "./Settings/SettingsContainer.h" -#include "./lumatone_editor_library/device/lumatone_controller.h" //[/Headers] #include "GlobalSettingsArea.h" @@ -76,10 +75,12 @@ GlobalSettingsArea::GlobalSettingsArea (const LumatoneEditorState& stateIn) activeMacroButtonColourEdit.reset(new ColourViewComponent()); addAndMakeVisible(activeMacroButtonColourEdit.get()); activeMacroButtonColourEdit->addChangeListener(this); + activeMacroButtonColourEdit->setColour(getActiveMacroButtonColour().toString(), false); inactiveMacroButtonColourEdit.reset(new ColourViewComponent()); addAndMakeVisible(inactiveMacroButtonColourEdit.get()); inactiveMacroButtonColourEdit->addChangeListener(this); + inactiveMacroButtonColourEdit->setColour(getInactiveMacroButtonColour().toString(), false); lblDeveloperMode.reset(new juce::Label("DeveloperModeLabel", "Developer Mode")); addChildComponent(lblDeveloperMode.get()); @@ -90,9 +91,18 @@ GlobalSettingsArea::GlobalSettingsArea (const LumatoneEditorState& stateIn) lblPresetButtonColours->setFont(getAppFonts().getFont(LumatoneEditorFont::UniviaProBold)); addStatusListener(this); + addEditorListener(this); settingsButton->setEnabled(false); + lblPresetButtonColours->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::LabelPink)); + + lblColourActiveMacroButton->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::DescriptionText)); + lblColourInactiveMacroButton->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::DescriptionText)); + + settingsButton->setColour(TextButton::ColourIds::buttonColourId, Colour(0xff383b3d)); + settingsButton->setColour(TextButton::ColourIds::textColourOffId, Colour(0xffffffff)); + /* We don't want a resize here /* //[/UserPreSize] @@ -126,6 +136,16 @@ GlobalSettingsArea::~GlobalSettingsArea() //[/Destructor] } +void GlobalSettingsArea::macroButtonInactiveColourChanged(juce::Colour colour) +{ + inactiveMacroButtonColourEdit->setColour(colour.toString(), false); +} + +void GlobalSettingsArea::macroButtonActiveColourChanged(juce::Colour colour) +{ + activeMacroButtonColourEdit->setColour(colour.toString(), false); +} + //============================================================================== void GlobalSettingsArea::paint (juce::Graphics& g) { @@ -220,46 +240,18 @@ void GlobalSettingsArea::buttonClicked (juce::Button* buttonThatWasClicked) //[MiscUserCode] You can add your own definitions of your custom methods or any other code here... -void GlobalSettingsArea::lookAndFeelChanged() -{ - lblPresetButtonColours->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::LabelPink)); - - lblColourActiveMacroButton->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::DescriptionText)); - lblColourInactiveMacroButton->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::DescriptionText)); - - settingsButton->setColour(TextButton::ColourIds::buttonColourId, Colour(0xff383b3d)); - settingsButton->setColour(TextButton::ColourIds::textColourOffId, Colour(0xffffffff)); -} - void GlobalSettingsArea::changeListenerCallback(ChangeBroadcaster *source) { if (source == inactiveMacroButtonColourEdit.get()) { - String inactiveMacroButtonColour = inactiveMacroButtonColourEdit->getColourAsString(); - getLumatoneController()->sendMacroButtonInactiveColour(inactiveMacroButtonColour); + setInactiveMacroButtonColour(inactiveMacroButtonColourEdit->getColourAsObject()); } else if (source == activeMacroButtonColourEdit.get()) { - String activeMacroButtonColour = activeMacroButtonColourEdit->getColourAsString(); - getLumatoneController()->sendMacroButtonActiveColour(activeMacroButtonColour); + setActiveMacroButtonColour(activeMacroButtonColourEdit->getColourAsObject()); } } -void GlobalSettingsArea::restoreStateFromPropertiesFile() -{ - inactiveMacroButtonColourEdit->setColour(getProperty(LumatoneEditorProperty::InactiveMacroButtonColour, "000000")); - activeMacroButtonColourEdit->setColour(getProperty(LumatoneEditorProperty::ActiveMacroButtonColour, "FFFFFF")); -} - -void GlobalSettingsArea::saveStateToPropertiesFile(PropertiesFile* propertiesFile) -{ - String inactiveMacroButtonColour = inactiveMacroButtonColourEdit->getColourAsString(); - propertiesFile->setValue(LumatoneEditorProperty::InactiveMacroButtonColour, inactiveMacroButtonColour); - - String activeMacroButtonColour = activeMacroButtonColourEdit->getColourAsString(); - propertiesFile->setValue(LumatoneEditorProperty::ActiveMacroButtonColour, activeMacroButtonColour); -} - void GlobalSettingsArea::listenToColourEditButtons(Button::Listener* listenerIn) { inactiveMacroButtonColourEdit->addListener(listenerIn); diff --git a/Source/GlobalSettingsArea.h b/Source/GlobalSettingsArea.h index 15a97ad9..5109c486 100644 --- a/Source/GlobalSettingsArea.h +++ b/Source/GlobalSettingsArea.h @@ -25,6 +25,7 @@ #include "./LumatoneEditorState.h" #include "./lumatone_editor_library/listeners/status_listener.h" +#include "./lumatone_editor_library/listeners/editor_listener.h" #include "./colour_view_component.h" //[/Headers] @@ -43,6 +44,7 @@ class GlobalSettingsArea : public juce::Component, public LumatoneEditorState, public ChangeListener, public LumatoneEditor::StatusListener, + public LumatoneEditor::EditorListener, public juce::Button::Listener { public: @@ -54,18 +56,16 @@ class GlobalSettingsArea : public juce::Component, //[UserMethods] -- You can add your own custom methods in this section. void changeListenerCallback(ChangeBroadcaster *source) override; - void saveStateToPropertiesFile(PropertiesFile* propertiesFile); - void listenToColourEditButtons(Button::Listener* listenerIn); - void lookAndFeelChanged() override; - void setDeveloperMode(bool devModeOn); // LumatoneEditor::StatusListener implementation - // void connectionEstablished(int inputDevice, int outputDevice) override; void connectionStateChanged(ConnectionState newState) override; - // void connectionFailed() override; + + // LumatoneEditor::EditorListener implementation + void macroButtonInactiveColourChanged(juce::Colour colour) override; + void macroButtonActiveColourChanged(juce::Colour colour) override; //[/UserMethods] @@ -73,8 +73,6 @@ class GlobalSettingsArea : public juce::Component, void resized() override; void buttonClicked (juce::Button* buttonThatWasClicked) override; -private: - void restoreStateFromPropertiesFile(); private: //[UserVariables] -- You can add your own custom variables in this section. diff --git a/Source/MainComponent.cpp b/Source/MainComponent.cpp index 83791aae..fde8fb00 100644 --- a/Source/MainComponent.cpp +++ b/Source/MainComponent.cpp @@ -143,7 +143,7 @@ MainContentComponent::~MainContentComponent() void MainContentComponent::saveStateToPropertiesFile(PropertiesFile* propertiesFile) { noteEditArea->saveStateToPropertiesFile(propertiesFile); - globalSettingsArea->saveStateToPropertiesFile(propertiesFile); + // globalSettingsArea->saveStateToPropertiesFile(propertiesFile); } // Set the currentSectionKey mapping to be edited to the value passed in parameter diff --git a/Source/colour_view_component.cpp b/Source/colour_view_component.cpp index 37ac2973..ffa7eb2e 100644 --- a/Source/colour_view_component.cpp +++ b/Source/colour_view_component.cpp @@ -241,7 +241,7 @@ void ColourViewComponent::paintButton(juce::Graphics& g, bool shouldDrawButtonAs g.drawFittedText(getButtonText(), getLocalBounds(), juce::Justification::centred, 1); } -void ColourViewComponent::setColour(juce::String colourAsString) +void ColourViewComponent::setColour(juce::String colourAsString, bool sendChange) { //jassert(colourCombo != nullptr); @@ -254,7 +254,8 @@ void ColourViewComponent::setColour(juce::String colourAsString) repaint(); // Notify parent that value has changed and can be sent to MIDI controller - sendChangeMessage(); + if (sendChange) + sendChangeMessage(); } juce::String ColourViewComponent::getColourAsString() diff --git a/Source/colour_view_component.h b/Source/colour_view_component.h index 918eda5f..29ffde90 100644 --- a/Source/colour_view_component.h +++ b/Source/colour_view_component.h @@ -94,7 +94,7 @@ class ColourViewComponent : public juce::Button, //[UserMethods] -- You can add your own custom methods in this section. //void changeListenerCallback(juce::ChangeBroadcaster *source) override; - void setColour(juce::String colourAsString); + void setColour(juce::String colourAsString, bool sendChangeMessage = true); juce::String getColourAsString(); int getColourAsNumber(); juce::Colour getColourAsObject(); diff --git a/Source/lumatone_editor_library/device/lumatone_controller.cpp b/Source/lumatone_editor_library/device/lumatone_controller.cpp index e47b1fa2..b68d080f 100644 --- a/Source/lumatone_editor_library/device/lumatone_controller.cpp +++ b/Source/lumatone_editor_library/device/lumatone_controller.cpp @@ -556,6 +556,12 @@ void LumatoneController::requestExpressionPedalSensitivity() firmwareDriver.sendGetExpressionPedalSensitivity(); } +void LumatoneController::requestMacroButtonColours() +{ + if (firmwareSupport.versionAcknowledgesCommand(getLumatoneVersion(), GET_MACRO_LIGHT_INTENSITY)) + firmwareDriver.sendGetMacroLightIntensity(); +} + bool LumatoneController::connectionConfirmed() const { return firmwareDriver.hasDevicesDefined() && currentDevicePairConfirmed; @@ -637,114 +643,3 @@ void LumatoneController::pingResponseReceived(unsigned int pingValue) setConnectionState(ConnectionState::ONLINE); } } - -void LumatoneController::octaveColourConfigReceived(int boardId, juce::uint8 rgbFlag, const int* colourData) -{ - int boardIndex = boardId - 1; - - for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) - { - auto newValue = colourData[keyIndex]; - - juce::Colour colour = getKey(boardIndex, keyIndex).getColour(); - if (rgbFlag == 0) - { - colour = juce::Colour(newValue, colour.getGreen(), colour.getBlue()); - } - else if (rgbFlag == 1) - { - colour = juce::Colour(colour.getRed(), newValue, colour.getBlue()); - } - else if (rgbFlag == 2) - { - colour = juce::Colour(colour.getRed(), colour.getGreen(), newValue); - } - else - { - jassertfalse; - } - - LumatoneState::setKeyColour(colour, boardId, keyIndex); - } - - getEditorListeners()->call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex)); -} - -void LumatoneController::octaveChannelConfigReceived(int boardId, const int* channelData) -{ - int boardIndex = boardId - 1; - - for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) - { - juce::uint8 ch = channelData[keyIndex]; - if (ch == 0 || ch > 16) - ch = 1; - - auto key = getKey(boardIndex, keyIndex); - key.setChannelNumber(ch); - LumatoneState::setKeyConfig(key, boardId, keyIndex); - } - - getEditorListeners()->call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex)); -} - -void LumatoneController::octaveNoteConfigReceived(int boardId, const int* noteData) -{ - int boardIndex = boardId - 1; - - for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) - { - int note = noteData[keyIndex]; - if (note < 0 || note > 127) - note = 0; - - auto key = getKey(boardIndex, keyIndex); - key.setNoteOrCC(noteData[keyIndex]); - LumatoneState::setKeyConfig(key, boardId, keyIndex); - } - - getEditorListeners()->call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex)); -} - -void LumatoneController::keyTypeConfigReceived(int boardId, const int* keyTypeData) -{ - int boardIndex = boardId - 1; - - for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) - { - auto type = LumatoneKeyType(keyTypeData[keyIndex]); - - auto key = getKey(boardIndex, keyIndex); - key.setKeyType(type); - LumatoneState::setKeyConfig(key, boardId, keyIndex); - } - - getEditorListeners()->call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex)); -} - -void LumatoneController::macroButtonColoursReceived(juce::Colour inactiveColour, juce::Colour activeColour) -{ - -} - -//void LumatoneController::loadRandomMapping(int testTimeoutMs, int maxIterations, int i) -//{ -// auto dir = juce::File::getSpecialLocation(juce::File::SpecialLocationType::userDocumentsDirectory).getChildFile("Lumatone Editor").getChildFile("Mappings"); -// auto mappings = dir.findChildFiles(juce::File::TypesOfFileToFind::findFiles, true); -// auto numfiles = mappings.size(); -// auto r = juce::Random(); -// -// auto fileIndex = r.nextInt(numfiles-1); -// auto file = mappings[fileIndex]; -// -// if (file.exists() && file.hasFileExtension(".ltn")) -// { -// DBG("Found " + juce::String(numfiles) + " files, loading " + file.getFileName()); -// juce::MessageManager::callAsync([file]() { TerpstraSysExApplication::getApp().setCurrentFile(file); }); -// } -// -//// if (i < maxIterations) -//// Timer::callAfterDelay(testTimeoutMs, [&]() { loadRandomMapping(testTimeoutMs, maxIterations, i + 1); }); -//// else -//// DBG("Finished random mappings test."); -//} diff --git a/Source/lumatone_editor_library/device/lumatone_controller.h b/Source/lumatone_editor_library/device/lumatone_controller.h index 0009c966..42156ebe 100644 --- a/Source/lumatone_editor_library/device/lumatone_controller.h +++ b/Source/lumatone_editor_library/device/lumatone_controller.h @@ -201,6 +201,9 @@ class LumatoneController : private LumatoneApplicationState // Get sensitivity setting of expression pedal void requestExpressionPedalSensitivity(); + // Get preset button light colours + void requestMacroButtonColours(); + private: // juce::ValueTree::Listener implementation @@ -208,7 +211,7 @@ class LumatoneController : private LumatoneApplicationState protected: //============================================================================ - // LumatoneEditor::FirmwareListener implementation + // LumatoneEditor::FirmwareListener implementation - use to establish device connection void serialIdentityReceived(const int* serialBytes) override; @@ -216,13 +219,6 @@ class LumatoneController : private LumatoneApplicationState void pingResponseReceived(unsigned int pingValue) override; - void octaveColourConfigReceived(int boardId, juce::uint8 rgbFlag, const int* colourData) override; - void octaveChannelConfigReceived(int octaveIndex, const int* channelData) override; - void octaveNoteConfigReceived(int octaveIndex, const int* noteData) override; - void keyTypeConfigReceived(int boardId, const int* keyTypeData) override; - - void macroButtonColoursReceived(juce::Colour inactiveColour, juce::Colour activeColour) override; - //============================================================================ // Test functions diff --git a/Source/lumatone_editor_library/device/lumatone_event_manager.cpp b/Source/lumatone_editor_library/device/lumatone_event_manager.cpp index ea810e15..5b4c0769 100644 --- a/Source/lumatone_editor_library/device/lumatone_event_manager.cpp +++ b/Source/lumatone_editor_library/device/lumatone_event_manager.cpp @@ -13,11 +13,15 @@ #include "../lumatone_midi_driver/lumatone_midi_driver.h" #include "../lumatone_midi_driver/firmware_sysex.h" -LumatoneEventManager::LumatoneEventManager(LumatoneFirmwareDriver& midiDriverIn, const LumatoneState& stateIn) - : LumatoneState(stateIn) +#include "../listeners/editor_listener.h" + +LumatoneEventManager::LumatoneEventManager(LumatoneFirmwareDriver& midiDriverIn, const LumatoneApplicationState& stateIn) + : LumatoneApplicationState("LumatoneEventManager", stateIn) + , LumatoneApplicationState::Controller(static_cast(*this)) , midiDriver(midiDriverIn) { midiDriver.addDriverListener(this); + addFirmwareListener(this); juce::MidiMessageCollector::reset(bufferReadTimeoutMs); } @@ -299,6 +303,11 @@ FirmwareSupport::Error LumatoneEventManager::handleGetPresetFlagsResponse(const presetFlags.sustainPedalInverted ); + mappingData->setLightOnKeyStrokes(presetFlags.polyphonicAftertouch); + mappingData->setAftertouchEnabled(presetFlags.polyphonicAftertouch); + mappingData->setInvertExpression(presetFlags.expressionPedalInverted); + mappingData->setInvertSustain(presetFlags.sustainPedalInverted); + firmwareListeners.call(&LumatoneEditor::FirmwareListener::presetFlagsReceived, presetFlags); return errorCode; @@ -309,11 +318,31 @@ FirmwareSupport::Error LumatoneEventManager::handleGetExpressionPedalSensitivity int sensitivity = 127; auto errorCode = LumatoneSysEx::unpackGetExpressionPedalSensitivityResponse(midiMessage, sensitivity); + mappingData->setExpressionSensitivity(sensitivity); + firmwareListeners.call(&LumatoneEditor::FirmwareListener::expressionPedalSensitivityReceived, sensitivity); return errorCode; } +FirmwareSupport::Error LumatoneEventManager::handleGetMacroLightIntensityResponse(const juce::MidiMessage &midiMessage) +{ + juce::Colour activeColour; + juce::Colour inactiveColour; + + auto errorCode = LumatoneSysEx::unpackGetMacroLightIntensityResponse(midiMessage, activeColour, inactiveColour); + if (errorCode != FirmwareSupport::Error::noError) + return errorCode; + + LumatoneState::setActiveMacroButtonColour(activeColour); + getEditorListeners()->call(&LumatoneEditor::EditorListener::macroButtonActiveColourChanged, activeColour); + + LumatoneState::setInactiveMacroButtonColour(inactiveColour); + getEditorListeners()->call(&LumatoneEditor::EditorListener::macroButtonInactiveColourChanged, inactiveColour); + + return FirmwareSupport::Error::noError; +} + FirmwareSupport::Error LumatoneEventManager::handlePeripheralCalibrationData(const juce::MidiMessage& midiMessage) { int mode = -1; @@ -503,6 +532,9 @@ FirmwareSupport::Error LumatoneEventManager::handleBufferCommand(const juce::Mid // loadRandomMapping(1000, 1); // uncomment for test sequence return FirmwareSupport::Error::noError; + case GET_MACRO_LIGHT_INTENSITY: + return handleGetMacroLightIntensityResponse(midiMessage); + default: jassert(sysExData[MSG_STATUS] == LumatoneFirmware::ReturnCode::ACK); if (midiMessage.getRawDataSize() <= 8) @@ -565,3 +597,112 @@ void LumatoneEventManager::timerCallback() bufferReadRequested = false; } + +void LumatoneEventManager::octaveColourConfigReceived(int boardId, juce::uint8 rgbFlag, const int* colourData) +{ + int boardIndex = boardId - 1; + + for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) + { + auto newValue = colourData[keyIndex]; + + juce::Colour colour = getKey(boardIndex, keyIndex).getColour(); + if (rgbFlag == 0) + { + colour = juce::Colour(newValue, colour.getGreen(), colour.getBlue()); + } + else if (rgbFlag == 1) + { + colour = juce::Colour(colour.getRed(), newValue, colour.getBlue()); + } + else if (rgbFlag == 2) + { + colour = juce::Colour(colour.getRed(), colour.getGreen(), newValue); + } + else + { + jassertfalse; + } + + LumatoneState::setKeyColour(colour, boardId, keyIndex); + } + + getEditorListeners()->call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex)); +} + +void LumatoneEventManager::octaveChannelConfigReceived(int boardId, const int* channelData) +{ + int boardIndex = boardId - 1; + + for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) + { + juce::uint8 ch = channelData[keyIndex]; + if (ch == 0 || ch > 16) + ch = 1; + + auto key = getKey(boardIndex, keyIndex); + key.setChannelNumber(ch); + LumatoneState::setKeyConfig(key, boardId, keyIndex); + } + + getEditorListeners()->call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex)); +} + +void LumatoneEventManager::octaveNoteConfigReceived(int boardId, const int* noteData) +{ + int boardIndex = boardId - 1; + + for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) + { + int note = noteData[keyIndex]; + if (note < 0 || note > 127) + note = 0; + + auto key = getKey(boardIndex, keyIndex); + key.setNoteOrCC(noteData[keyIndex]); + LumatoneState::setKeyConfig(key, boardId, keyIndex); + } + + getEditorListeners()->call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex)); +} + +void LumatoneEventManager::keyTypeConfigReceived(int boardId, const int* keyTypeData) +{ + int boardIndex = boardId - 1; + + for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) + { + auto type = LumatoneKeyType(keyTypeData[keyIndex]); + + auto key = getKey(boardIndex, keyIndex); + key.setKeyType(type); + LumatoneState::setKeyConfig(key, boardId, keyIndex); + } + + getEditorListeners()->call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex)); +} + +void LumatoneEventManager::macroButtonColoursReceived(juce::Colour inactiveColour, juce::Colour activeColour) +{ + getEditorListeners()->call(&LumatoneEditor::EditorListener::macroButtonInactiveColourChanged, inactiveColour); + getEditorListeners()->call(&LumatoneEditor::EditorListener::macroButtonActiveColourChanged, activeColour); +} + +void LumatoneEventManager::presetFlagsReceived(LumatoneFirmware::PresetFlags presetFlags) +{ + LumatoneState::setLightOnKeyStrokes(presetFlags.lightsOnKeystroke); + setStateProperty(LumatoneStateProperty::LightsOnAfterKeystroke, presetFlags.lightsOnKeystroke); + getEditorListeners()->call(&LumatoneEditor::EditorListener::lightOnKeyStrokesChanged, presetFlags.lightsOnKeystroke); + + LumatoneState::setAftertouchEnabled(presetFlags.polyphonicAftertouch); + setStateProperty(LumatoneStateProperty::AftertouchEnabled, presetFlags.polyphonicAftertouch); + getEditorListeners()->call(&LumatoneEditor::EditorListener::aftertouchToggled, presetFlags.polyphonicAftertouch); + + LumatoneState::setInvertSustain(presetFlags.sustainPedalInverted); + setStateProperty(LumatoneStateProperty::InvertSustain, presetFlags.sustainPedalInverted); + getEditorListeners()->call(&LumatoneEditor::EditorListener::invertSustainToggled, presetFlags.sustainPedalInverted); + + LumatoneState::setInvertExpression(presetFlags.expressionPedalInverted); + setStateProperty(LumatoneStateProperty::InvertExpression, presetFlags.expressionPedalInverted); + getEditorListeners()->call(&LumatoneEditor::EditorListener::invertFootControllerChanged, presetFlags.expressionPedalInverted); +} diff --git a/Source/lumatone_editor_library/device/lumatone_event_manager.h b/Source/lumatone_editor_library/device/lumatone_event_manager.h index 1fd7f745..641a195e 100644 --- a/Source/lumatone_editor_library/device/lumatone_event_manager.h +++ b/Source/lumatone_editor_library/device/lumatone_event_manager.h @@ -10,23 +10,21 @@ #pragma once -#include "../listeners/status_listener.h" -#include "../listeners/firmware_listener.h" +#include "../data/application_state.h" #include "../midi/lumatone_midi_state.h" - #include "../lumatone_midi_driver/firmware_driver_listener.h" +#include "../listeners/firmware_listener.h" -class LumatoneFirmwareDriver; - -class LumatoneEventManager : private LumatoneFirmwareDriverListener, - public LumatoneMidiState, - public LumatoneState, - private juce::Timer +class LumatoneEventManager : public LumatoneApplicationState + , public LumatoneMidiState + , private LumatoneApplicationState::Controller + , private LumatoneFirmwareDriverListener + , private LumatoneEditor::FirmwareListener + , private juce::Timer { public: - - LumatoneEventManager(LumatoneFirmwareDriver& midiDriver, const LumatoneState& stateIn); + LumatoneEventManager(LumatoneFirmwareDriver& midiDriver, const LumatoneApplicationState& stateIn); ~LumatoneEventManager() override; private: @@ -43,6 +41,17 @@ class LumatoneEventManager : private LumatoneFirmwareDriverListener, //virtual void generalLogMessage(juce::String textMessage, HajuErrorVisualizer::ErrorLevel errorLevel) override; virtual void noAnswerToMessage(juce::MidiDeviceInfo expectedDevice, const juce::MidiMessage& midiMessage) override; + //============================================================================ + // Implementation of LumatoneEditor::FirmwareListener + void octaveColourConfigReceived(int boardId, juce::uint8 rgbFlag, const int* colourData) override; + void octaveChannelConfigReceived(int octaveIndex, const int* channelData) override; + void octaveNoteConfigReceived(int octaveIndex, const int* noteData) override; + void keyTypeConfigReceived(int boardId, const int* keyTypeData) override; + + void macroButtonColoursReceived(juce::Colour inactiveColour, juce::Colour activeColour) override; + + void presetFlagsReceived(LumatoneFirmware::PresetFlags presetFlags) override; + private: juce::ListenerList firmwareListeners; public: @@ -107,23 +116,17 @@ class LumatoneEventManager : private LumatoneFirmwareDriverListener, FirmwareSupport::Error handleGetExpressionPedalSensitivityResponse(const juce::MidiMessage& midiMessage); + FirmwareSupport::Error handleGetMacroLightIntensityResponse(const juce::MidiMessage& midiMessage); + void handleMidiDriverError(FirmwareSupport::Error errorToHandle, int commandReceived = -1); // Buffer read helpers FirmwareSupport::Error getBufferErrorCode(const juce::uint8* sysExData); FirmwareSupport::Error handleBufferCommand(const juce::MidiMessage& midiMessage); -private: - //void confirmAutoConnection(); - //void onConnectionConfirm(bool sendChangeSignal); - //void onDisconnection(); - //void onFirmwareUpdateReceived(); private: - LumatoneFirmwareDriver& midiDriver; - - FirmwareSupport firmwareSupport; - + LumatoneFirmwareDriver& midiDriver; const int bufferReadTimeoutMs = 30; const int bufferReadSize = 16; @@ -132,6 +135,5 @@ class LumatoneEventManager : private LumatoneFirmwareDriverListener, std::atomic readQueueSize; int sendQueueSize = 0; - int verbose = 0; }; diff --git a/Source/lumatone_editor_library/listeners/editor_listener.h b/Source/lumatone_editor_library/listeners/editor_listener.h index 6f5c857d..27a7df19 100644 --- a/Source/lumatone_editor_library/listeners/editor_listener.h +++ b/Source/lumatone_editor_library/listeners/editor_listener.h @@ -34,7 +34,7 @@ class EditorListener virtual void expressionPedalSensitivityChanged(unsigned char value) {} virtual void invertFootControllerChanged(bool inverted) {} - virtual void macroButtonActiveColourChagned(juce::Colour colour) {} + virtual void macroButtonActiveColourChanged(juce::Colour colour) {} virtual void macroButtonInactiveColourChanged(juce::Colour colour) {} virtual void lightOnKeyStrokesChanged(bool lightOn) {}