From 4f6cc3fc8fceaca84056ccf3b254b63314b7ce59 Mon Sep 17 00:00:00 2001 From: Vincenzo Sicurella Date: Sat, 13 Jan 2024 17:50:26 -0500 Subject: [PATCH] implement status listener calls in controller and monitor --- .../data/application_state.h | 4 + .../device/activity_monitor.cpp | 12 ++- .../device/activity_monitor.h | 4 +- .../device/lumatone_controller.cpp | 75 ++++++++++++------- .../device/lumatone_controller.h | 2 + 5 files changed, 62 insertions(+), 35 deletions(-) diff --git a/Source/lumatone_editor_library/data/application_state.h b/Source/lumatone_editor_library/data/application_state.h index 05ed301d..fdaed05f 100644 --- a/Source/lumatone_editor_library/data/application_state.h +++ b/Source/lumatone_editor_library/data/application_state.h @@ -48,6 +48,7 @@ class LumatoneFirmwareDriver; class LumatoneController; class LumatoneColourModel; class LumatoneAction; +class DeviceActivityMonitor; class LumatoneApplicationState : public LumatoneState { @@ -142,6 +143,9 @@ class LumatoneApplicationState : public LumatoneState void addFirmwareListener(LumatoneEditor::FirmwareListener* listenerIn); void removeFirmwareListener(LumatoneEditor::FirmwareListener* listenerIn); + // Allow these to edit state and signal listeners + friend class LumatoneController; + friend class DeviceActivityMonitor; }; #endif LUMATONE_APPLICATION_STATE_H diff --git a/Source/lumatone_editor_library/device/activity_monitor.cpp b/Source/lumatone_editor_library/device/activity_monitor.cpp index ea77fa22..ef1b66df 100644 --- a/Source/lumatone_editor_library/device/activity_monitor.cpp +++ b/Source/lumatone_editor_library/device/activity_monitor.cpp @@ -12,6 +12,8 @@ #include "../lumatone_midi_driver/lumatone_midi_driver.h" #include "../lumatone_midi_driver/firmware_sysex.h" +#include "../listeners/status_listener.h" + DeviceActivityMonitor::DeviceActivityMonitor(LumatoneFirmwareDriver* midiDriverIn, LumatoneApplicationState stateIn) : LumatoneApplicationState("DeviceActivityMonitor", stateIn) @@ -263,7 +265,7 @@ void DeviceActivityMonitor::checkDetectionStatus() if (isConnectionEstablished()) { deviceDetectInProgress = false; - //statusListeners->call(&LumatoneEditor::StatusListener::connectionStateChanged, ConnectionState::ONLINE); + statusListeners->call(&LumatoneEditor::StatusListener::connectionStateChanged, ConnectionState::ONLINE); outputPingIds.clear(); @@ -284,7 +286,7 @@ void DeviceActivityMonitor::checkDetectionStatus() waitingForResponse = false; startTimer(detectRoutineTimeoutMs); - //statusListeners.call(&LumatoneEditor::StatusListener::connectionFailed); + statusListeners->call(&LumatoneEditor::StatusListener::connectionFailed); } else { @@ -338,7 +340,7 @@ void DeviceActivityMonitor::checkDetectionStatus() waitingForResponse = false; startTimer(detectRoutineTimeoutMs); - //statusListeners.call(&LumatoneEditor::StatusListener::connectionFailed); + statusListeners->call(&LumatoneEditor::StatusListener::connectionFailed); } } @@ -419,6 +421,7 @@ void DeviceActivityMonitor::handleResponse(int inputDeviceIndex, const juce::Mid if (cmd == PERIPHERAL_CALBRATION_DATA && !isConnectionEstablished()) { + DBG("DAM: Unexpected calibration data received"); sendCalibratePitchModOff = true; // startTimer(100); return; @@ -451,6 +454,7 @@ void DeviceActivityMonitor::handleResponse(int inputDeviceIndex, const juce::Mid if (!isConnectionEstablished()) { sendCalibratePitchModOff = true; + jassertfalse; } } break; @@ -566,7 +570,7 @@ void DeviceActivityMonitor::onDisconnection() waitingForResponse = false; - //juce::MessageManager::callAsync([&]() { statusListeners.call(&LumatoneEditor::StatusListener::connectionStateChanged, ConnectionState::DISCONNECTED); }); + statusListeners->call(&LumatoneEditor::StatusListener::connectionStateChanged, ConnectionState::DISCONNECTED); if (detectDevicesIfDisconnected) { diff --git a/Source/lumatone_editor_library/device/activity_monitor.h b/Source/lumatone_editor_library/device/activity_monitor.h index c24d3d0d..80056f36 100644 --- a/Source/lumatone_editor_library/device/activity_monitor.h +++ b/Source/lumatone_editor_library/device/activity_monitor.h @@ -21,13 +21,11 @@ #include "../lumatone_midi_driver/firmware_driver_listener.h" #include "../data/application_state.h" -#include "../listeners/status_listener.h" class LumatoneFirmwareDriver; class DeviceActivityMonitor : protected LumatoneApplicationState, - public juce::Timer, - public LumatoneEditor::StatusEmitter, + public juce::Timer, protected LumatoneFirmwareDriverListener { diff --git a/Source/lumatone_editor_library/device/lumatone_controller.cpp b/Source/lumatone_editor_library/device/lumatone_controller.cpp index 0965df36..b2e67be2 100644 --- a/Source/lumatone_editor_library/device/lumatone_controller.cpp +++ b/Source/lumatone_editor_library/device/lumatone_controller.cpp @@ -13,6 +13,7 @@ #include "lumatone_event_manager.h" #include "../actions/lumatone_action.h" #include "../lumatone_midi_driver/lumatone_midi_driver.h" +#include "../listeners/editor_listener.h" LumatoneController::LumatoneController(const LumatoneApplicationState& stateIn, LumatoneFirmwareDriver& firmwareDriverIn, juce::UndoManager* undoManager) : LumatoneApplicationState("LumatoneController", stateIn, undoManager) @@ -641,7 +642,7 @@ void LumatoneController::onConnectionConfirmed() sendGetFirmwareRevisionRequest(); } - //statusListeners.call(&LumatoneEditor::StatusListener::connectionStateChanged, ConnectionState::ONLINE); + statusListeners->call(&LumatoneEditor::StatusListener::connectionStateChanged, ConnectionState::ONLINE); } // bool LumatoneController::loadLayoutFromFile(const juce::File& file) @@ -700,78 +701,96 @@ void LumatoneController::pingResponseReceived(unsigned int pingValue) void LumatoneController::octaveColourConfigReceived(int boardId, juce::uint8 rgbFlag, const int* colourData) { - auto octaveSize = getOctaveBoardSize(); - auto numBoards = getNumBoards(); + LumatoneBoard editedBoard = getBoard(boardId - 1); - int boardIndex = boardId - 1; - - for (int keyIndex = 0; keyIndex < octaveSize; keyIndex++) + for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) { - LumatoneKey keyData = getKey(boardIndex, keyIndex); auto newValue = colourData[keyIndex]; + juce::Colour colour = editedBoard.getKey(keyIndex).getColour(); if (rgbFlag == 0) { - keyData.setColour(juce::Colour(newValue, keyData.getColour().getGreen(), keyData.getColour().getBlue())); + colour = juce::Colour(newValue, colour.getGreen(), colour.getBlue()); } else if (rgbFlag == 1) { - keyData.setColour(juce::Colour(keyData.getColour().getRed(), newValue, keyData.getColour().getBlue())); + colour = juce::Colour(colour.getRed(), newValue, colour.getBlue()); } else if (rgbFlag == 2) { - keyData.setColour(juce::Colour(keyData.getColour().getRed(), keyData.getColour().getGreen(), newValue)); + colour = juce::Colour(colour.getRed(), colour.getGreen(), newValue); } else { jassertfalse; } + + editedBoard.setKeyColour(colour, keyIndex); } - //editorListeners.call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex)); + LumatoneState::setBoard(editedBoard, boardId); + editorListeners->call(&LumatoneEditor::EditorListener::boardChanged, editedBoard); }; void LumatoneController::octaveChannelConfigReceived(int boardId, const int* channelData) { + LumatoneBoard editedBoard = getBoard(boardId - 1); + for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) { - // Check channel values? - auto key = getKey(boardId-1, keyIndex); - key.setChannelNumber(channelData[keyIndex]); - LumatoneState::setKey(key, boardId, keyIndex); - // getEditKey(boardId-1, keyIndex)->channelNumber = channelData[keyIndex]; + juce::uint8 ch = channelData[keyIndex]; + if (ch == 0 || ch > 16) + ch = 1; + + auto key = editedBoard.getKey(keyIndex); + key.setChannelNumber(ch); + editedBoard.setKeyConfig(key, keyIndex); } - //editorListeners.call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardId - 1)); + LumatoneState::setBoard(editedBoard, boardId); + editorListeners->call(&LumatoneEditor::EditorListener::boardChanged, editedBoard); } void LumatoneController::octaveNoteConfigReceived(int boardId, const int* noteData) { + LumatoneBoard editedBoard = getBoard(boardId - 1); + for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) { - auto key = getKey(boardId-1, keyIndex); + int note = noteData[keyIndex]; + if (note < 0 || note > 127) + note = 0; + + auto key = editedBoard.getKey(keyIndex); key.setNoteOrCC(noteData[keyIndex]); - LumatoneState::setKey(key, boardId, keyIndex); - // Check note values? - // getEditKey(boardId - 1, keyIndex)->noteNumber = noteData[keyIndex]; + editedBoard.setKeyConfig(key, keyIndex); } - //editorListeners.call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardId - 1)); + LumatoneState::setBoard(editedBoard, boardId); + editorListeners->call(&LumatoneEditor::EditorListener::boardChanged, editedBoard); } void LumatoneController::keyTypeConfigReceived(int boardId, const int* keyTypeData) { + LumatoneBoard editedBoard = getBoard(boardId - 1); + for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) { - auto key = getKey(boardId-1, keyIndex); - key.setKeyType((LumatoneKeyType)keyTypeData[keyIndex]); - LumatoneState::setKey(key, boardId, keyIndex); - // Check note values? - // getEditKey(boardId - 1, keyIndex)->keyType = LumatoneKeyType(keyTypeData[keyIndex]); + auto type = LumatoneKeyType(keyTypeData[keyIndex]); + + auto key = editedBoard.getKey(keyIndex); + key.setKeyType(type); + editedBoard.setKeyConfig(key, keyIndex); } - //editorListeners.call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardId - 1)); + LumatoneState::setBoard(editedBoard, boardId); + editorListeners->call(&LumatoneEditor::EditorListener::boardChanged, editedBoard); +} + +void LumatoneController::macroButtonColoursReceived(juce::Colour inactiveColour, juce::Colour activeColour) +{ + } //void LumatoneController::loadRandomMapping(int testTimeoutMs, int maxIterations, int i) diff --git a/Source/lumatone_editor_library/device/lumatone_controller.h b/Source/lumatone_editor_library/device/lumatone_controller.h index d94e9d6f..a3025e78 100644 --- a/Source/lumatone_editor_library/device/lumatone_controller.h +++ b/Source/lumatone_editor_library/device/lumatone_controller.h @@ -237,6 +237,8 @@ class LumatoneController : private LumatoneApplicationState 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