From 830d3538784d7dc7ecf3a2f60239d8ef0c01580b Mon Sep 17 00:00:00 2001 From: Vincenzo Sicurella Date: Wed, 14 Aug 2024 23:12:53 -0400 Subject: [PATCH 1/4] refactor num board & key macros, remove ValueTree from board & key structs --- .../data/lumatone_board.cpp | 50 ++++++++----- .../data/lumatone_board.h | 14 ++-- .../data/lumatone_key.cpp | 71 ++++++++++++------- .../data/lumatone_key.h | 17 ++--- .../data/lumatone_layout.h | 7 +- .../mapping/lumatone_hex_map.h | 4 +- .../mapping/lumatone_output_map.cpp | 2 +- archive/IsomorphicMassAssign.cpp | 4 +- archive/NoteEditArea.cpp | 8 +-- 9 files changed, 105 insertions(+), 72 deletions(-) diff --git a/Source/lumatone_editor_library/data/lumatone_board.cpp b/Source/lumatone_editor_library/data/lumatone_board.cpp index 4e3355e6..967eeb3d 100644 --- a/Source/lumatone_editor_library/data/lumatone_board.cpp +++ b/Source/lumatone_editor_library/data/lumatone_board.cpp @@ -24,13 +24,13 @@ LumatoneBoard::LumatoneBoard(LumatoneKeyType newKeyType, int numKeysIn, int boar theKeys[i] = LumatoneKey(newKeyType); //key_idx = 0; - state = juce::ValueTree(LumatoneBoardProperty::State); - updateState(); + // state = juce::ValueTree(LumatoneBoardProperty::State); + // updateState(); } LumatoneBoard::LumatoneBoard(const LumatoneBoard& copyBoard) { - state = juce::ValueTree(LumatoneBoardProperty::State); + // state = juce::ValueTree(LumatoneBoardProperty::State); board_idx = copyBoard.board_idx; operator=(copyBoard); } @@ -41,8 +41,8 @@ LumatoneBoard::LumatoneBoard(juce::ValueTree stateIn) if (stateIn.hasType(LumatoneBoardProperty::State)) stateToCopy = stateIn; - state = stateToCopy; - refreshFromState(); + // state = stateToCopy; + refreshFromState(stateToCopy); } void LumatoneBoard::operator=(const LumatoneBoard& copyBoard) @@ -54,7 +54,7 @@ void LumatoneBoard::operator=(const LumatoneBoard& copyBoard) theKeys[i] = copyBoard.getKey(i); } - updateState(); + // updateState(); } bool LumatoneBoard::isEmpty() const @@ -68,6 +68,19 @@ bool LumatoneBoard::isEmpty() const return true; } +juce::ValueTree LumatoneBoard::getState() const +{ + juce::ValueTree newState(LumatoneBoardProperty::State); + + newState.setProperty(LumatoneBoardProperty::Id, board_idx, nullptr); + for (int i = 0; i < numKeys; i++) + { + newState.addChild(theKeys[i].getState(), i, nullptr); + } + + return newState; +} + int LumatoneBoard::getNumKeys() const { return numKeys; @@ -165,22 +178,23 @@ juce::Array LumatoneBoard::getKeysWithColour(const juce::Colou return keyCoords; } -void LumatoneBoard::updateState() -{ - juce::ValueTree newState(LumatoneBoardProperty::State); +// void LumatoneBoard::updateState() +// { +// juce::ValueTree newState(LumatoneBoardProperty::State); - newState.setProperty(LumatoneBoardProperty::Id, board_idx, nullptr); - for (int i = 0; i < numKeys; i++) - { - newState.addChild(theKeys[i].getState(), i, nullptr); - } +// newState.setProperty(LumatoneBoardProperty::Id, board_idx, nullptr); +// for (int i = 0; i < numKeys; i++) +// { +// newState.addChild(theKeys[i].getState(), i, nullptr); +// } - state.copyPropertiesAndChildrenFrom(newState, nullptr); -} +// state.copyPropertiesAndChildrenFrom(newState, nullptr); +// } -void LumatoneBoard::refreshFromState() +void LumatoneBoard::refreshFromState(const juce::ValueTree& state) { - board_idx = (int)state[LumatoneBoardProperty::Id]; + juce::var defaultIndex = 0; + board_idx = (int)state.getProperty(LumatoneBoardProperty::Id, defaultIndex); for (int i = 0; i < numKeys; i++) { diff --git a/Source/lumatone_editor_library/data/lumatone_board.h b/Source/lumatone_editor_library/data/lumatone_board.h index 5838a49e..897c4c95 100644 --- a/Source/lumatone_editor_library/data/lumatone_board.h +++ b/Source/lumatone_editor_library/data/lumatone_board.h @@ -14,7 +14,7 @@ #include "../data/lumatone_editor_common.h" #include "lumatone_key.h" -#define MAXBOARDSIZE 56 +#define MAX_LUMATONE_BOARD_KEYS 56 namespace LumatoneBoardProperty { @@ -29,7 +29,7 @@ class LumatoneLayout; class LumatoneBoard { public: - LumatoneBoard(LumatoneKeyType newKeyType = LumatoneKeyType::disabled, int numKeysIn=MAXBOARDSIZE, int boardIndex = 0); + LumatoneBoard(LumatoneKeyType newKeyType = LumatoneKeyType::disabled, int numKeysIn=MAX_LUMATONE_BOARD_KEYS, int boardIndex = 0); LumatoneBoard(const LumatoneBoard& copyBoard); LumatoneBoard(juce::ValueTree stateIn); @@ -38,7 +38,7 @@ class LumatoneBoard int getBoardIndex() const { return board_idx; } bool isEmpty() const; - juce::ValueTree getState() const { return state; } + juce::ValueTree getState() const; int getNumKeys() const; const LumatoneKey& getKey(int index) const; @@ -54,16 +54,16 @@ class LumatoneBoard juce::Array getKeysWithColour(const juce::Colour& c) const; private: - void updateState(); - void refreshFromState(); + // void updateState(); + void refreshFromState(const juce::ValueTree& state); private: - LumatoneKey theKeys[MAXBOARDSIZE]; + LumatoneKey theKeys[MAX_LUMATONE_BOARD_KEYS]; int board_idx; int numKeys; - juce::ValueTree state; + // juce::ValueTree state; friend class LumatoneLayout; }; diff --git a/Source/lumatone_editor_library/data/lumatone_key.cpp b/Source/lumatone_editor_library/data/lumatone_key.cpp index aca11ed8..3fab68d7 100644 --- a/Source/lumatone_editor_library/data/lumatone_key.cpp +++ b/Source/lumatone_editor_library/data/lumatone_key.cpp @@ -18,8 +18,8 @@ LumatoneKey::LumatoneKey(LumatoneKeyType newKeyType) keyType = newKeyType; ccFaderDefault = true; - state = juce::ValueTree(LumatoneKeyProperty::State); - updateState(); + // state = juce::ValueTree(LumatoneKeyProperty::State); + // updateState(); } LumatoneKey::LumatoneKey(LumatoneKeyType newKeyType, int newChannelNumber, int newNoteNumber, juce::Colour newColour, bool invertCCFader) @@ -30,8 +30,8 @@ LumatoneKey::LumatoneKey(LumatoneKeyType newKeyType, int newChannelNumber, int n colour = newColour; ccFaderDefault = invertCCFader; - state = juce::ValueTree(LumatoneKeyProperty::State); - updateState(); + // state = juce::ValueTree(LumatoneKeyProperty::State); + // updateState(); } LumatoneKey::LumatoneKey(juce::ValueTree keyStateIn) @@ -42,9 +42,20 @@ LumatoneKey::LumatoneKey(juce::ValueTree keyStateIn) { stateToCopy = keyStateIn; } +// + // state = stateToCopy; + refreshFromState(stateToCopy); +} - state = stateToCopy; - refreshFromState(); +LumatoneKey::LumatoneKey(const LumatoneKey &keyToCopy) + : keyType(keyToCopy.keyType) + , noteNumber(keyToCopy.noteNumber) + , channelNumber(keyToCopy.channelNumber) + , colour(keyToCopy.colour) + , ccFaderDefault(keyToCopy.ccFaderDefault) +{ + // state = juce::ValueTree(LumatoneKeyProperty::State); + // updateState(); } bool LumatoneKey::configIsEqual(const LumatoneKey &compare) const @@ -70,37 +81,37 @@ void LumatoneKey::operator=(const LumatoneKey &keyToCopy) noteNumber = keyToCopy.noteNumber; colour = keyToCopy.colour; ccFaderDefault = keyToCopy.ccFaderDefault; - updateState(); + // updateState(); } void LumatoneKey::setKeyType(LumatoneKeyType typeIn) { keyType = typeIn; - state.setProperty(LumatoneKeyProperty::Type, keyType, nullptr); + // state.setProperty(LumatoneKeyProperty::Type, keyType, nullptr); } void LumatoneKey::setColour(juce::Colour colourIn) { colour = colourIn; - state.setProperty(LumatoneKeyProperty::Colour, colour.toString(), nullptr); + // state.setProperty(LumatoneKeyProperty::Colour, colour.toString(), nullptr); } void LumatoneKey::setNoteOrCC(int noteOrCC) { noteNumber = noteOrCC; - state.setProperty(LumatoneKeyProperty::MidiNote, noteNumber, nullptr); + // state.setProperty(LumatoneKeyProperty::MidiNote, noteNumber, nullptr); } void LumatoneKey::setChannelNumber(int channelIn) { channelNumber = channelIn; - state.setProperty(LumatoneKeyProperty::MidiChnl, channelNumber, nullptr); + // state.setProperty(LumatoneKeyProperty::MidiChnl, channelNumber, nullptr); } void LumatoneKey::setDefaultCCFader(bool defaultCCFader) { ccFaderDefault = defaultCCFader; - state.setProperty(LumatoneKeyProperty::DefaultCCFader, ccFaderDefault, nullptr); + // state.setProperty(LumatoneKeyProperty::DefaultCCFader, ccFaderDefault, nullptr); } void LumatoneKey::setConfig(const LumatoneKey& config) @@ -109,32 +120,38 @@ void LumatoneKey::setConfig(const LumatoneKey& config) channelNumber = config.channelNumber; ccFaderDefault = config.ccFaderDefault; keyType = config.keyType; - updateState(); + // updateState(); } juce::ValueTree LumatoneKey::getState() const { - return state; -} - -void LumatoneKey::updateState() -{ - // juce::ValueTree newState(LumatoneKeyProperty::State); + juce::ValueTree state = juce::ValueTree(LumatoneKeyProperty::State); state.setProperty(LumatoneKeyProperty::Type, keyType, nullptr); state.setProperty(LumatoneKeyProperty::Colour, colour.toString(), nullptr); state.setProperty(LumatoneKeyProperty::MidiNote, noteNumber, nullptr); state.setProperty(LumatoneKeyProperty::MidiChnl, channelNumber, nullptr); state.setProperty(LumatoneKeyProperty::DefaultCCFader, ccFaderDefault, nullptr); - // state.copyPropertiesFrom(newState, nullptr); + return state; } -void LumatoneKey::refreshFromState() -{ - keyType = (LumatoneKeyType)(int)state.getProperty(LumatoneKeyProperty::Type, (int)LumatoneKeyType::disabled); - colour = juce::Colour::fromString(state.getProperty(LumatoneKeyProperty::Colour, juce::Colours::transparentBlack.toString()).toString()); - noteNumber = (int)state.getProperty(LumatoneKeyProperty::MidiNote, 0); - channelNumber = (int)state.getProperty(LumatoneKeyProperty::MidiChnl, 1); - ccFaderDefault = (bool)state.getProperty(LumatoneKeyProperty::DefaultCCFader, false); +// void LumatoneKey::updateState() +// { +// // juce::ValueTree newState(LumatoneKeyProperty::State); +// state.setProperty(LumatoneKeyProperty::Type, keyType, nullptr); +// state.setProperty(LumatoneKeyProperty::Colour, colour.toString(), nullptr); +// state.setProperty(LumatoneKeyProperty::MidiNote, noteNumber, nullptr); +// state.setProperty(LumatoneKeyProperty::MidiChnl, channelNumber, nullptr); +// state.setProperty(LumatoneKeyProperty::DefaultCCFader, ccFaderDefault, nullptr); +// // state.copyPropertiesFrom(newState, nullptr); +// } + +void LumatoneKey::refreshFromState(const juce::ValueTree& stateIn) +{ + keyType = (LumatoneKeyType)(int)stateIn.getProperty(LumatoneKeyProperty::Type, (int)LumatoneKeyType::disabled); + colour = juce::Colour::fromString(stateIn.getProperty(LumatoneKeyProperty::Colour, juce::Colours::transparentBlack.toString()).toString()); + noteNumber = (int)stateIn.getProperty(LumatoneKeyProperty::MidiNote, 0); + channelNumber = (int)stateIn.getProperty(LumatoneKeyProperty::MidiChnl, 1); + ccFaderDefault = (bool)stateIn.getProperty(LumatoneKeyProperty::DefaultCCFader, false); } diff --git a/Source/lumatone_editor_library/data/lumatone_key.h b/Source/lumatone_editor_library/data/lumatone_key.h index f6b38309..5db9cb54 100644 --- a/Source/lumatone_editor_library/data/lumatone_key.h +++ b/Source/lumatone_editor_library/data/lumatone_key.h @@ -54,6 +54,7 @@ class LumatoneKey LumatoneKey(LumatoneKeyType newKeyType = LumatoneKeyType::disabled); LumatoneKey(LumatoneKeyType newKeyType, int newChannelNumber, int newNoteNumber, juce::Colour newColour, bool invertCCFader = false); LumatoneKey(juce::ValueTree keyStateIn); + LumatoneKey(const LumatoneKey& keyToCopy); bool isEmpty() const { return channelNumber == 0; } @@ -96,17 +97,17 @@ class LumatoneKey juce::ValueTree getState() const; private: - void updateState(); - void refreshFromState(); + // void updateState(); + void refreshFromState(const juce::ValueTree& stateIn); private: - LumatoneKeyType keyType; - int noteNumber; - int channelNumber; - juce::Colour colour; - bool ccFaderDefault; + LumatoneKeyType keyType; + int noteNumber; + int channelNumber; + juce::Colour colour; + bool ccFaderDefault; - juce::ValueTree state; + // juce::ValueTree state; }; diff --git a/Source/lumatone_editor_library/data/lumatone_layout.h b/Source/lumatone_editor_library/data/lumatone_layout.h index 6f4fd57b..b51ac189 100644 --- a/Source/lumatone_editor_library/data/lumatone_layout.h +++ b/Source/lumatone_editor_library/data/lumatone_layout.h @@ -74,7 +74,8 @@ class LumatoneConfigTable A complete key mapping ============================================================================== */ -#define MAXNUMBOARDS 5 +#define MAX_LUMATONE_BOARDS 5 +#define MAX_LUMATONE_KEYS MAX_LUMATONE_BOARDS * MAX_LUMATONE_BOARD_KEYS // Number of entries in the velocity interval table #define VELOCITYINTERVALTABLESIZE 127 @@ -82,7 +83,7 @@ A complete key mapping class LumatoneLayout { private: - LumatoneBoard boards[MAXNUMBOARDS]; + LumatoneBoard boards[MAX_LUMATONE_BOARDS]; public: LumatoneLayout(int numBoards=5, int octaveBoardSize=56, bool initializeWithNotes=false); @@ -156,7 +157,7 @@ class LumatoneLayout LumatoneKeyCoord keyNumToKeyCoord(int keyNum) const; public: - static LumatoneLayout IdentityMapping(int numBoards=MAXNUMBOARDS, int octaveBoardSize=56, LumatoneKeyType keyType=LumatoneKeyType::noteOnNoteOff); + static LumatoneLayout IdentityMapping(int numBoards=MAX_LUMATONE_BOARDS, int octaveBoardSize=56, LumatoneKeyType keyType=LumatoneKeyType::noteOnNoteOff); private: diff --git a/Source/lumatone_editor_library/mapping/lumatone_hex_map.h b/Source/lumatone_editor_library/mapping/lumatone_hex_map.h index 2d7b8ead..43ecba97 100644 --- a/Source/lumatone_editor_library/mapping/lumatone_hex_map.h +++ b/Source/lumatone_editor_library/mapping/lumatone_hex_map.h @@ -29,7 +29,7 @@ class LumatoneHexMap struct MapBoard { int size = 0; - MappedKey keys[MAXBOARDSIZE]; + MappedKey keys[MAX_LUMATONE_BOARD_KEYS]; MapBoard(int octaveBoardSize = 0) { @@ -74,7 +74,7 @@ class LumatoneHexMap LumatoneGeometry lumatoneGeometry; //juce::Array boards; - MapBoard boards[MAXNUMBOARDS]; + MapBoard boards[MAX_LUMATONE_BOARDS]; Hex::Point originPoint; int originBoardIndex = 0; diff --git a/Source/lumatone_editor_library/mapping/lumatone_output_map.cpp b/Source/lumatone_editor_library/mapping/lumatone_output_map.cpp index 155ef27a..88cfb1ef 100644 --- a/Source/lumatone_editor_library/mapping/lumatone_output_map.cpp +++ b/Source/lumatone_editor_library/mapping/lumatone_output_map.cpp @@ -33,7 +33,7 @@ void LumatoneOutputMap::render(const LumatoneLayout& layout, juce::HashMap= 0 && setSelection < MAXNUMBOARDS && keySelection >= 0 && keySelection < getOctaveBoardSize()); + jassert(setSelection >= 0 && setSelection < MAX_LUMATONE_BOARDS && keySelection >= 0 && keySelection < getOctaveBoardSize()); int startNoteIndex = this->startingPointBox->getSelectedItemIndex(); if (this->mappingLogic != nullptr && startNoteIndex >= 0) @@ -755,7 +755,7 @@ bool IsomorphicMassAssign::performMouseDown(int setSelection, int keySelection) PointstartPos = boardGeometry.coordinatesForKey(setSelection, keySelection); // Get the coordinates of the clicked key. - for (int boardIx = 0; boardIx < MAXNUMBOARDS; boardIx++) { // For each board + for (int boardIx = 0; boardIx < MAX_LUMATONE_BOARDS; boardIx++) { // For each board for (int keyIx = 0; keyIx < getOctaveBoardSize(); keyIx++) { // For each key on that board Point keyPos = boardGeometry.coordinatesForKey(boardIx, keyIx); // Get the coordinates of the key to assign. Point keyOffset = keyPos - startPos; // Get the offset of the key to assign, relative to where the user clicked. diff --git a/archive/NoteEditArea.cpp b/archive/NoteEditArea.cpp index 256d3c99..7d802eb5 100644 --- a/archive/NoteEditArea.cpp +++ b/archive/NoteEditArea.cpp @@ -75,7 +75,7 @@ NoteEditArea::NoteEditArea (const LumatoneEditorState& stateIn) octaveBoardSelectorTab.reset(new TabbedButtonBar(TabbedButtonBar::Orientation::TabsAtTop)); addAndMakeVisible(octaveBoardSelectorTab.get()); - for (int i = 0; i < MAXNUMBOARDS; i++) + for (int i = 0; i < MAX_LUMATONE_BOARDS; i++) { octaveBoardSelectorTab->addTab(translate("Section") + " " + String(i + 1), juce::Colours::lightgrey, i + 1); } @@ -247,7 +247,7 @@ void NoteEditArea::mouseDown (const juce::MouseEvent& e) { // Perform the edit, according to edit mode. Including sending to device auto setSelection = octaveBoardSelectorTab->getCurrentTabIndex(); - jassert(setSelection >= 0 && setSelection < MAXNUMBOARDS&& keyIndex >= 0 && keyIndex < getOctaveBoardSize()); + jassert(setSelection >= 0 && setSelection < MAX_LUMATONE_BOARDS&& keyIndex >= 0 && keyIndex < getOctaveBoardSize()); int editMode = editFunctionsTab->getCurrentTabIndex(); switch (editMode) @@ -314,7 +314,7 @@ void NoteEditArea::changeListenerCallback(ChangeBroadcaster *source) if (source == octaveBoardSelectorTab.get()) { auto setSelection = octaveBoardSelectorTab->getCurrentTabIndex(); - jassert(setSelection >= 0 && setSelection < MAXNUMBOARDS); + jassert(setSelection >= 0 && setSelection < MAX_LUMATONE_BOARDS); setKeyFieldValues(getBoard(setSelection)); } @@ -362,7 +362,7 @@ void NoteEditArea::changeSingleKeySelection(int newSelection) void NoteEditArea::refreshKeyFields() { auto setSelection = octaveBoardSelectorTab->getCurrentTabIndex(); - jassert(setSelection >= 0 && setSelection < MAXNUMBOARDS); + jassert(setSelection >= 0 && setSelection < MAX_LUMATONE_BOARDS); setKeyFieldValues(getBoard(setSelection)); } From b5cb4bced78ecf87b7da5c6899adff1b2804ba05 Mon Sep 17 00:00:00 2001 From: Vincenzo Sicurella Date: Wed, 14 Aug 2024 23:13:12 -0400 Subject: [PATCH 2/4] decouple midi driver debug flag from juce --- .../lumatone_midi_driver/lumatone_midi_driver.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/lumatone_editor_library/lumatone_midi_driver/lumatone_midi_driver.cpp b/Source/lumatone_editor_library/lumatone_midi_driver/lumatone_midi_driver.cpp index dee3a546..8baaa76e 100644 --- a/Source/lumatone_editor_library/lumatone_midi_driver/lumatone_midi_driver.cpp +++ b/Source/lumatone_editor_library/lumatone_midi_driver/lumatone_midi_driver.cpp @@ -22,6 +22,8 @@ #define MIDI_DRIVER_USE_LOCK JUCE_WINDOWS //|| JUCE_LINUX +#define MIDI_DRIVER_DEBUG 0 //JUCE_DEBUG + LumatoneFirmwareDriver::LumatoneFirmwareDriver(HostMode hostModeIn, int numBoardsIn) : hostMode(hostModeIn) , numBoards(numBoardsIn) @@ -866,7 +868,7 @@ void LumatoneFirmwareDriver::sendCurrentMessage() jassert(!isTimerRunning()); jassert(hasMsgWaitingForAck); -// #if JUCE_DEBUG +// #if MIDI_DRIVER_DEBUG // if (currentMsgWaitingForAck.isSysEx()) // { // auto sysExData = currentMsgWaitingForAck.getSysExData(); @@ -878,7 +880,7 @@ void LumatoneFirmwareDriver::sendCurrentMessage() sendMessageNow(currentMsgWaitingForAck); // send it // Notify listeners - #if JUCE_DEBUG + #if MIDI_DRIVER_DEBUG { juce::String msg = "SENT: " + FirmwareSupport::getCommandDescription(currentMsgWaitingForAck); // DBG("SENT: " + currentMsgWaitingForAck.getDescription()); @@ -895,7 +897,7 @@ void LumatoneFirmwareDriver::sendCurrentMessage() void LumatoneFirmwareDriver::handleIncomingMidiMessage(juce::MidiInput* source, const juce::MidiMessage& message) { -#if JUCE_DEBUG +#if MIDI_DRIVER_DEBUG if (message.isSysEx()) { auto msg = "RCVD: " + FirmwareSupport::getCommandDescription(message); From 6f612de2267fda005e9820412ac80a4d5d6eabc0 Mon Sep 17 00:00:00 2001 From: Vincenzo Sicurella Date: Wed, 14 Aug 2024 23:15:36 -0400 Subject: [PATCH 3/4] rework key update buffer --- .../device/key_update_buffer.cpp | 167 +++++++++++------- .../device/key_update_buffer.h | 13 +- 2 files changed, 108 insertions(+), 72 deletions(-) diff --git a/Source/lumatone_editor_library/device/key_update_buffer.cpp b/Source/lumatone_editor_library/device/key_update_buffer.cpp index 01aa1218..dbea9af4 100644 --- a/Source/lumatone_editor_library/device/key_update_buffer.cpp +++ b/Source/lumatone_editor_library/device/key_update_buffer.cpp @@ -5,7 +5,25 @@ LumatoneKeyUpdateBuffer::LumatoneKeyUpdateBuffer(LumatoneFirmwareDriver& driverI : firmwareDriver(driverIn) , LumatoneState("LumatoneKeyUpdateBuffer", state) { - keysToUpdate.remapTable(280); + // updatedLayout.remapTable(280); + + for (int b = 0; b < MAX_LUMATONE_BOARDS; b++) + { + if (b < getNumBoards()) + { + const LumatoneBoard& board = getBoard(b); + for (int k = 0; k < MAX_LUMATONE_BOARD_KEYS; k++) + { + if (k < board.getNumKeys()) + { + const LumatoneKey& key = board.getKey(k); + int index = b * MAX_LUMATONE_BOARD_KEYS + k; + keysToUpdate[index] = nullptr; + lastUpdatedKeys[index] = LumatoneKey(); + } + } + } + } } LumatoneKeyUpdateBuffer::~LumatoneKeyUpdateBuffer() @@ -35,101 +53,114 @@ void LumatoneKeyUpdateBuffer::sendKeyColourConfig(int boardId, int keyIndex, juc void LumatoneKeyUpdateBuffer::updateKeyConfig(int boardIndex, int keyIndex, const LumatoneKey& config) { - juce::ScopedLock l(lock); + // juce::ScopedLock l(lock); // while (!lock.tryEnter()) {} - auto keyNum = getKeyNum(boardIndex, keyIndex); - MappedLumatoneKey currentUpdateData = keysToUpdate[keyNum]; - const LumatoneKey& currentKey = getKey(boardIndex, keyIndex); - preUpdateLayout.setKey(currentKey, boardIndex, keyIndex); - if (currentKey == config) - { - keysToUpdate.set(keyNum, MappedLumatoneKey()); - } - else if (currentUpdateData.boardIndex < 0 || currentUpdateData.keyIndex < 0) - { - auto updateKey = MappedLumatoneKey(config, boardIndex, keyIndex); - updateKey.setColour(currentKey.getColour()); - keysToUpdate.set(keyNum, updateKey); - } - else if (!currentUpdateData.configIsEqual(config)) + int index = boardIndex * MAX_LUMATONE_BOARD_KEYS + keyIndex; + const LumatoneKey& lastUpdatedKey = lastUpdatedKeys[index]; + const LumatoneKey** keyPtr = &keysToUpdate[index]; + + // if (/*currentKey == config && */lastUpdatedKey == config) + // { + // *keyPtr = nullptr; + // } + // else + // { + *keyPtr = ¤tKey; + // } + + if (!isTimerRunning()) { - auto updateKey = MappedLumatoneKey(config, boardIndex, keyIndex); - updateKey.setColour(currentUpdateData.getColour()); - keysToUpdate.set(keyNum, updateKey); + // processUpdates(); + startTimer(updateMs); } - - startTimer(updateMs); } void LumatoneKeyUpdateBuffer::updateKeyColour(int boardIndex, int keyIndex, juce::Colour colour) { - juce::ScopedLock l(lock); + // juce::ScopedLock l(lock); // while (!lock.tryEnter()) {} - auto keyNum = getKeyNum(boardIndex, keyIndex); - MappedLumatoneKey currentUpdateData = keysToUpdate[keyNum]; const LumatoneKey& currentKey = getKey(boardIndex, keyIndex); - preUpdateLayout.setKey(currentKey, boardIndex, keyIndex); - if (currentKey.getColour() == colour && currentKey.configIsEqual(currentUpdateData)) - { - keysToUpdate.set(keyNum, MappedLumatoneKey()); - } - else if (currentUpdateData.boardIndex < 0 || currentUpdateData.keyIndex < 0) - { - auto updateKey = MappedLumatoneKey(currentKey, boardIndex, keyIndex); - updateKey.setColour(colour); - keysToUpdate.set(keyNum, updateKey); - } - else if (currentUpdateData.isColour(colour)) - { - auto updateKey = MappedLumatoneKey(currentUpdateData, boardIndex, keyIndex); - updateKey.setColour(colour); - keysToUpdate.set(keyNum, updateKey); - } + int index = boardIndex * MAX_LUMATONE_BOARD_KEYS + keyIndex; + const LumatoneKey& lastUpdatedKey = lastUpdatedKeys[index]; + const LumatoneKey** keyPtr = &keysToUpdate[boardIndex * MAX_LUMATONE_BOARD_KEYS + keyIndex]; + // if (/*currentKey.isColour(colour) &&*/ lastUpdatedKey.isColour(colour)) + // { + // *keyPtr = nullptr; + // } + // else + // { + *keyPtr = ¤tKey; + // } - startTimer(updateMs); + if (!isTimerRunning()) + { + // processUpdates(); + startTimer(updateMs); + } } -void LumatoneKeyUpdateBuffer::timerCallback() +void LumatoneKeyUpdateBuffer::processUpdates() { - stopTimer(); - - if (! lock.tryEnter()) - return; + // DBG("<<<< process updates >>>>"); - int keyNum = 0; - for (int board = 0; board < getNumBoards(); board++) + for (int board = 0; board < MAX_LUMATONE_BOARDS; board++) { int boardId = board + 1; - for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) + for (int keyIndex = 0; keyIndex < MAX_LUMATONE_BOARD_KEYS; keyIndex++) { - auto keyUpdate = keysToUpdate[keyNum]; - if (keyUpdate.boardIndex >= 0 && keyUpdate.keyIndex >= 0) - { - // auto currentKey = getKey(board, keyIndex); - auto currentKey = preUpdateLayout.getKey(board, keyIndex); - if (!currentKey.configIsEqual(keyUpdate)) - firmwareDriver.sendKeyFunctionParameters(boardId, keyIndex, keyUpdate.getMidiNumber(), keyUpdate.getMidiChannel(), keyUpdate.getType(), keyUpdate.isCCFaderDefault()); + int index = board * MAX_LUMATONE_BOARD_KEYS + keyIndex; + const LumatoneKey** key = &keysToUpdate[index]; + if (key == nullptr || *key == nullptr) + continue; - if (!currentKey.colourIsEqual(keyUpdate)) - { - auto colour = keyUpdate.getColour(); - if (getLumatoneVersion() >= LumatoneFirmware::ReleaseVersion::VERSION_1_0_11) - firmwareDriver.sendKeyLightParameters(boardId, keyIndex, colour.getRed(), colour.getGreen(), colour.getBlue()); - else - firmwareDriver.sendKeyLightParameters_Version_1_0_0(boardId, keyIndex, colour.getRed() * 0.5f, colour.getGreen() * 0.5f, colour.getBlue() * 0.5f); - } + const LumatoneKey& keyUpdate = **key; + + // const LumatoneKey& currentKey = getKey(board, keyIndex); + const LumatoneKey& lastUpdatedKey = lastUpdatedKeys[index]; + if (!lastUpdatedKey.configIsEqual(keyUpdate)) + firmwareDriver.sendKeyFunctionParameters(boardId, keyIndex, keyUpdate.getMidiNumber(), keyUpdate.getMidiChannel(), keyUpdate.getType(), keyUpdate.isCCFaderDefault()); + + if (!lastUpdatedKey.colourIsEqual(keyUpdate)) + { + auto colour = keyUpdate.getColour(); + if (getLumatoneVersion() >= LumatoneFirmware::ReleaseVersion::VERSION_1_0_11) + firmwareDriver.sendKeyLightParameters(boardId, keyIndex, colour.getRed(), colour.getGreen(), colour.getBlue()); + else + firmwareDriver.sendKeyLightParameters_Version_1_0_0(boardId, keyIndex, colour.getRed() * 0.5f, colour.getGreen() * 0.5f, colour.getBlue() * 0.5f); } - keysToUpdate.set(keyNum, MappedLumatoneKey()); - keyNum++; + *key = nullptr; + lastUpdatedKeys[index] = keyUpdate; } } +} + +void LumatoneKeyUpdateBuffer::handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier &property) +{ + LumatoneState::handleStatePropertyChange(stateIn, property); + + // juce::ValueTree lumatoneStateTree = state.getChildWithName(LumatoneConfigProperty::State); + // if (stateIn == lumatoneStateTree || stateIn.isAChildOf(lumatoneStateTree)) + // { + // // layout updated + + // DBG("key update buffer layout update"); + // } +} +void LumatoneKeyUpdateBuffer::timerCallback() +{ + stopTimer(); + + if (! lock.tryEnter()) + return; + // DBG(">>>> buffer timer callback <<<<"); + processUpdates(); } diff --git a/Source/lumatone_editor_library/device/key_update_buffer.h b/Source/lumatone_editor_library/device/key_update_buffer.h index 136e3546..cf207ef0 100644 --- a/Source/lumatone_editor_library/device/key_update_buffer.h +++ b/Source/lumatone_editor_library/device/key_update_buffer.h @@ -25,17 +25,22 @@ class LumatoneKeyUpdateBuffer : public LumatoneState, void updateKeyConfig(int boardIndex, int keyIndex, const LumatoneKey& config); void updateKeyColour(int boardIndex, int keyIndex, juce::Colour colour); + void processUpdates(); + +private: + + void handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property) override; + private: juce::CriticalSection lock; LumatoneFirmwareDriver& firmwareDriver; - juce::HashMap keysToUpdate; - - LumatoneLayout preUpdateLayout; + const LumatoneKey* keysToUpdate[MAX_LUMATONE_KEYS]; + LumatoneKey lastUpdatedKeys[MAX_LUMATONE_KEYS]; - int updateMs = 300; + int updateMs = 700; }; #endif LUMATONE_UPDATE_BUFFER_H From ac46a94dc37f5e70507627ef39e0cb1be0cdcc8b Mon Sep 17 00:00:00 2001 From: Vincenzo Sicurella Date: Wed, 14 Aug 2024 23:15:51 -0400 Subject: [PATCH 4/4] use key buffer for key set and batch update actions --- Source/actions/BatchColourActions.cpp | 67 +++++++++++++------------ Source/actions/EditorControlActions.cpp | 10 ++-- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/Source/actions/BatchColourActions.cpp b/Source/actions/BatchColourActions.cpp index 086dce9b..b91b1a7d 100644 --- a/Source/actions/BatchColourActions.cpp +++ b/Source/actions/BatchColourActions.cpp @@ -85,7 +85,7 @@ ApplyBatchColourAdjustments::ApplyBatchColourAdjustments(const LumatoneEditorSta newData = editData; previousData = getBatchColourEditData(); - if (keySelectionIn.size() > 0 && keySelection.size() < (MAXNUMBOARDS * MAXBOARDSIZE)) // todo get actual number from each board + if (keySelectionIn.size() > 0 && keySelection.size() < (MAX_LUMATONE_BOARDS * MAX_LUMATONE_BOARD_KEYS)) // todo get actual number from each board { for (const MappedLumatoneKey& key : keySelectionIn) { @@ -107,19 +107,19 @@ ApplyBatchColourAdjustments::~ApplyBatchColourAdjustments() bool ApplyBatchColourAdjustments::perform() { - if (fullLayout) - { - for (const MappedLumatoneKey& key : keySelection) - { - MappedLumatoneKey updatedKey = key; - applyColourAdjustmentToKey(updatedKey, newData); - updatedLayout.setKey(updatedKey, key.boardIndex, key.keyIndex); - } - - setLayout(updatedLayout); - } - else - { + // if (fullLayout) + // { + // for (const MappedLumatoneKey& key : keySelection) + // { + // MappedLumatoneKey updatedKey = key; + // applyColourAdjustmentToKey(updatedKey, newData); + // updatedLayout.setKey(updatedKey, key.boardIndex, key.keyIndex); + // } + + // setLayout(updatedLayout); + // } + // else + // { juce::Array updatedKeys; for (const MappedLumatoneKey& key : keySelection) { @@ -128,36 +128,39 @@ bool ApplyBatchColourAdjustments::perform() updatedKeys.add(updatedKey); } - sendSelectionColours(updatedKeys); - } + bool useBuffer = keySelection.size() > 48; + sendSelectionColours(updatedKeys, true, useBuffer); + // } return true; } bool ApplyBatchColourAdjustments::undo() { - if (fullLayout) - { - for (const MappedLumatoneKey& key : keySelection) - { - MappedLumatoneKey baseKey = baseLayout->getMappedKey(key.boardIndex, key.keyIndex); - applyColourAdjustmentToKey(baseKey, previousData); - updatedLayout.setKey(baseKey); - } - - setLayout(updatedLayout); - } - else - { + // if (fullLayout) + // { + // for (const MappedLumatoneKey& key : keySelection) + // { + // MappedLumatoneKey baseKey = baseLayout->getMappedKey(key.boardIndex, key.keyIndex); + // applyColourAdjustmentToKey(baseKey, previousData); + // updatedLayout.setKey(baseKey); + // } + + // setLayout(updatedLayout); + // } + // else + // { for (MappedLumatoneKey& key : keySelection) { juce::Colour baseColour = baseLayout->getKey(key.boardIndex, key.keyIndex) .getColour(); key.setColour(baseColour); - applyColourAdjustmentToKey(key, previousData); + // applyColourAdjustmentToKey(key, previousData); } - sendSelectionParam(keySelection, true); - } + + bool useBuffer = keySelection.size() > 48; + sendSelectionColours(keySelection, true, useBuffer); + // } return true; } diff --git a/Source/actions/EditorControlActions.cpp b/Source/actions/EditorControlActions.cpp index be9671bc..47cc6002 100644 --- a/Source/actions/EditorControlActions.cpp +++ b/Source/actions/EditorControlActions.cpp @@ -132,22 +132,24 @@ bool ApplyAssignmentsToSelectionAction::perform() if (newData.ccFaderDefault) keyUpdate.setDefaultCCFader(newData.ccFaderDefault); - setKey((const LumatoneKey&) keyUpdate, keyUpdate.boardIndex + 1, keyUpdate.keyIndex); + LumatoneState::setKey((const LumatoneKey&) keyUpdate, keyUpdate.boardIndex + 1, keyUpdate.keyIndex); updatedKeys.add(keyUpdate); } + bool useBuffer = updatedKeys.size() > 48; + if (!newData.useColour) { // todo param-only update (no colour) - sendSelectionParam(updatedKeys); + sendSelectionParam(updatedKeys, true, useBuffer); } else if (newData.useType || newData.useNote || newData.useChannel || newData.ccFaderDefault) { - sendSelectionParam(updatedKeys); + sendSelectionParam(updatedKeys, true, useBuffer); } else { - sendSelectionColours(updatedKeys); + sendSelectionColours(updatedKeys, true, useBuffer); } updatedSelectedKeys();