Skip to content

Commit

Permalink
optimize layout change messages, fix key gfx update issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed Jan 20, 2024
1 parent 230b13d commit 7996b40
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 58 deletions.
8 changes: 4 additions & 4 deletions Source/lumatone_editor_library/listeners/editor_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<MappedLumatoneKey> selection) {}

Expand All @@ -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) {}
Expand Down
35 changes: 9 additions & 26 deletions Source/lumatone_editor_library/ui/key_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<LumatoneKey*>(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;
Expand Down
9 changes: 2 additions & 7 deletions Source/lumatone_editor_library/ui/key_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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; }
Expand Down
28 changes: 12 additions & 16 deletions Source/lumatone_editor_library/ui/keyboard_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand All @@ -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();
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -292,7 +288,7 @@ void LumatoneKeyboardComponent::mappingUpdateCallback()
if (currentWidth == 0 || currentHeight == 0)
return;

resized();
// resized();
repaint(lumatoneBounds);
}

Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions Source/lumatone_editor_library/ui/keyboard_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<MappedLumatoneKey> 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);
Expand Down

0 comments on commit 7996b40

Please sign in to comment.