diff --git a/Source/lumatone_editor_library/listeners/editor_listener.h b/Source/lumatone_editor_library/listeners/editor_listener.h index 32b9183e..6f5c857d 100644 --- a/Source/lumatone_editor_library/listeners/editor_listener.h +++ b/Source/lumatone_editor_library/listeners/editor_listener.h @@ -14,9 +14,9 @@ class EditorListener virtual ~EditorListener() {} // App Actions - virtual void completeMappingLoaded(LumatoneLayout mappingData) {} - virtual void boardChanged(LumatoneBoard boardData) {} - virtual void keyChanged(int boardIndex, int keyIndex, LumatoneKey lumatoneKey) {} + virtual void completeMappingLoaded(const LumatoneLayout& mappingData) {} + virtual void boardChanged(const LumatoneBoard& boardData) {} + virtual void keyChanged(int boardIndex, int keyIndex, const LumatoneKey& lumatoneKey) {} virtual void selectionChanged(juce::Array selection) {} @@ -28,7 +28,7 @@ class EditorListener // Firmware Actions - virtual void keyConfigChanged(int boardIndex, int keyIndex, LumatoneKey keyData) {} + virtual void keyConfigChanged(int boardIndex, int keyIndex, const LumatoneKey& keyData) {} virtual void keyColourChanged(int boardIndex, int keyIndex, juce::Colour keyColour) {} virtual void expressionPedalSensitivityChanged(unsigned char value) {} diff --git a/Source/lumatone_editor_library/ui/key_component.cpp b/Source/lumatone_editor_library/ui/key_component.cpp index 7bc40e61..5056cc2d 100644 --- a/Source/lumatone_editor_library/ui/key_component.cpp +++ b/Source/lumatone_editor_library/ui/key_component.cpp @@ -16,6 +16,9 @@ LumatoneKeyDisplay::LumatoneKeyDisplay(int newBoardIndex, int newKeyIndex, const : LumatoneKeyContext(keyDataIn, newBoardIndex, newKeyIndex) , Component("LumatoneKeyDisplay_" + LumatoneKeyCoord::toString(newBoardIndex, newKeyIndex)) { + boardIndex = newBoardIndex; + keyIndex = newKeyIndex; + renderMode = LumatoneComponentRenderMode::GraphicInteractive; clearUiState(); } @@ -218,38 +221,18 @@ void LumatoneKeyDisplay::endDrag() } } -// const LumatoneKey* LumatoneKeyDisplay::getKeyData() const -// { -// return &keyData; -// } - -// juce::Colour LumatoneKeyDisplay::getKeyColour() const -// { - -// } - -void LumatoneKeyDisplay::setLumatoneKey(const LumatoneKey& lumatoneKey, int boardIdx, int keyIdx) -{ - auto thisKey = static_cast(this); - *thisKey = lumatoneKey; - - boardIndex = boardIdx; - keyIndex = keyIdx; - // repaint(); -} - -void LumatoneKeyDisplay::setDisplayColour(const juce::Colour& colourIn) -{ - LumatoneKey::setColour(colourIn); - // redrawRender(); -} - void LumatoneKeyDisplay::setKeyGraphics(juce::Image& colourGraphicIn, juce::Image& shadowGraphicIn) { colourGraphic = colourGraphicIn; shadowGraphic = shadowGraphicIn; } +void LumatoneKeyDisplay::setLumatoneKey(const LumatoneKey &lumatoneKey, juce::Colour displayColour) +{ + LumatoneKey::operator=(lumatoneKey); + LumatoneKey::setColour(displayColour); +} + void LumatoneKeyDisplay::setSelected(bool selected) { isSelected = selected; diff --git a/Source/lumatone_editor_library/ui/key_component.h b/Source/lumatone_editor_library/ui/key_component.h index 08040147..acbb49ec 100644 --- a/Source/lumatone_editor_library/ui/key_component.h +++ b/Source/lumatone_editor_library/ui/key_component.h @@ -43,7 +43,7 @@ class LumatoneKeyDisplay : public LumatoneKeyContext, public: LumatoneKeyDisplay(int newBoardIndex, int newKeyIndex, const LumatoneKey& keyData=LumatoneKey()); - ~LumatoneKeyDisplay(); + ~LumatoneKeyDisplay() override; LumatoneComponentRenderMode getRenderMode() const { return renderMode; } void setRenderMode(LumatoneComponentRenderMode uiModeIn); @@ -53,12 +53,7 @@ class LumatoneKeyDisplay : public LumatoneKeyContext, void setKeyGraphics(juce::Image& colourGraphicIn, juce::Image& shadowGraphicIn); - void setLumatoneKey(const LumatoneKey& lumatoneKey, int boardIdx, int keyIdx); - - void setDisplayColour(const juce::Colour& colour); - - // const LumatoneKey* getKeyData() const; - // juce::Colour getKeyColour() const; + void setLumatoneKey(const LumatoneKey& lumatoneKey, juce::Colour displayColour); int getBoardIndex() const { return boardIndex; } int getKeyIndex() const { return keyIndex; } diff --git a/Source/lumatone_editor_library/ui/keyboard_component.cpp b/Source/lumatone_editor_library/ui/keyboard_component.cpp index c8b92c06..9a654ef5 100644 --- a/Source/lumatone_editor_library/ui/keyboard_component.cpp +++ b/Source/lumatone_editor_library/ui/keyboard_component.cpp @@ -189,7 +189,7 @@ void LumatoneKeyboardComponent::setUiMode(LumatoneKeyboardComponent::UiMode mode uiMode = modeIn; } -void LumatoneKeyboardComponent::completeMappingLoaded(LumatoneLayout mappingData) +void LumatoneKeyboardComponent::completeMappingLoaded(const LumatoneLayout& mappingData) { for (int boardIndex = 0; boardIndex < octaveBoards.size(); boardIndex++) { @@ -199,23 +199,20 @@ void LumatoneKeyboardComponent::completeMappingLoaded(LumatoneLayout mappingData { const LumatoneKey& keyData = mappingData.getKey(boardIndex, keyIndex); keyUpdateCallback(boardIndex, keyIndex, keyData, false); - } } resetLayoutState(&mappingData); } -void LumatoneKeyboardComponent::boardChanged(LumatoneBoard boardData) +void LumatoneKeyboardComponent::boardChanged(const LumatoneBoard& boardData) { - auto board = octaveBoards[boardData.getBoardIndex()]; + int boardIndex = boardData.getBoardIndex(); - for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++) + for (int keyIndex = 0; keyIndex < octaveBoards[boardIndex]->keyMiniDisplay.size(); keyIndex++) { - auto key = board->keyMiniDisplay[keyIndex]; - const LumatoneKey& keyData = boardData.getKey(keyIndex); - keyUpdateCallback(boardData.getBoardIndex(), keyIndex, keyData, false); + keyUpdateCallback(boardIndex, keyIndex, keyData, false); } resetLayoutState(); @@ -230,12 +227,12 @@ void LumatoneKeyboardComponent::contextChanged(LumatoneContext *newOrEmptyContex // completeMappingLoaded(layout); } -void LumatoneKeyboardComponent::keyChanged(int boardIndex, int keyIndex, LumatoneKey lumatoneKey) +void LumatoneKeyboardComponent::keyChanged(int boardIndex, int keyIndex, const LumatoneKey& lumatoneKey) { keyUpdateCallback(boardIndex, keyIndex, lumatoneKey); } -void LumatoneKeyboardComponent::keyConfigChanged(int boardIndex, int keyIndex, LumatoneKey keyData) +void LumatoneKeyboardComponent::keyConfigChanged(int boardIndex, int keyIndex, const LumatoneKey& keyData) { keyUpdateCallback(boardIndex, keyIndex, keyData); } @@ -261,8 +258,7 @@ void LumatoneKeyboardComponent::keyUpdateCallback(int boardIndex, int keyIndex, { auto key = octaveBoards[boardIndex]->keyMiniDisplay[keyIndex]; - key->setLumatoneKey(newKey, boardIndex, keyIndex); - updateKeyColour(boardIndex, keyIndex, newKey.getColour()); + applyKeyUpdates(boardIndex, keyIndex, newKey); if (!doRepaint) return; @@ -292,7 +288,7 @@ void LumatoneKeyboardComponent::mappingUpdateCallback() if (currentWidth == 0 || currentHeight == 0) return; - resized(); + // resized(); repaint(lumatoneBounds); } @@ -303,11 +299,11 @@ void LumatoneKeyboardComponent::rerender() repaint(lumatoneBounds); } -void LumatoneKeyboardComponent::updateKeyColour(int boardIndex, int keyIndex, const juce::Colour& colour) +void LumatoneKeyboardComponent::applyKeyUpdates(int boardIndex, int keyIndex, const LumatoneKey& keyData) { - auto modelColour = getColourModel()->getModelColour(colour); + auto modelColour = getColourModel()->getModelColour(keyData.getColour()); auto key = octaveBoards[boardIndex]->keyMiniDisplay[keyIndex]; - key->setDisplayColour(modelColour); + key->setLumatoneKey(keyData, modelColour); } void LumatoneKeyboardComponent::resetLayoutState(const LumatoneLayout* optionalLayout) diff --git a/Source/lumatone_editor_library/ui/keyboard_component.h b/Source/lumatone_editor_library/ui/keyboard_component.h index 8d54351f..c9a41fc2 100644 --- a/Source/lumatone_editor_library/ui/keyboard_component.h +++ b/Source/lumatone_editor_library/ui/keyboard_component.h @@ -80,16 +80,16 @@ class LumatoneKeyboardComponent : public juce::Component, public: // LumatoneEditor::EditorListener Implementation - void completeMappingLoaded(LumatoneLayout mappingData) override; - void boardChanged(LumatoneBoard boardData) override; + void completeMappingLoaded(const LumatoneLayout& mappingData) override; + void boardChanged(const LumatoneBoard& boardData) override; void contextChanged(LumatoneContext* newOrEmptyContext) override; - void keyChanged(int boardIndex, int keyIndex, LumatoneKey lumatoneKey) override; - void keyConfigChanged(int boardIndex, int keyIndex, LumatoneKey keyData) override; + void keyChanged(int boardIndex, int keyIndex, const LumatoneKey& lumatoneKey) override; + void keyConfigChanged(int boardIndex, int keyIndex, const LumatoneKey& keyData) override; void keyColourChanged(int octaveNumber, int keyNumber, juce::Colour keyColour) override; void selectionChanged(juce::Array selection) override; private: - void updateKeyColour(int boardIndex, int keyIndex, const juce::Colour& colour); + void applyKeyUpdates(int boardIndex, int keyIndex, const LumatoneKey& keyData); void resetLayoutState(const LumatoneLayout* optionalLayout=nullptr); void keyUpdateCallback(int boardIndex, int keyIndex, const LumatoneKey& keyData, bool doRepaint=true);