Skip to content

Commit

Permalink
allow key click listener to broadcast colours
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed Jul 28, 2024
1 parent 19ffa46 commit 95c90db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Source/mapping_editors/KeyboardClickListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ KeyboardClickListener::KeyboardClickListener(const LumatoneEditorState &stateIn,
, keyboardComponent(keyboardComponentIn)
{
keyboardComponent->addListener(this);
addColourSelectionBroadcaster(this);
}

KeyboardClickListener::~KeyboardClickListener()
Expand All @@ -25,6 +26,12 @@ void KeyboardClickListener::handleKeyDown(int keyNum)
lastKeyDown = keyNum;
// make quicker?
toggleKeySelection(keyNum);

auto keyCoord = getMappingData()->keyNumToKeyCoord(keyNum);
const LumatoneKey& key = getMappingData()->getKey(keyCoord.boardIndex, keyCoord.keyIndex);
lastKeyColour = key.getColour();

selectorListeners.call(&ColourSelectionListener::colourChangedCallback, this, lastKeyColour);
}

void KeyboardClickListener::handleKeyHold(int key, float xDistance, float yDistance)
Expand All @@ -36,6 +43,11 @@ void KeyboardClickListener::handleKeyHold(int key, float xDistance, float yDista
}
}

juce::Colour KeyboardClickListener::getSelectedColour()
{
return lastKeyColour;
}

void KeyboardClickListener::toggleKeySelection(int keyNum)
{
bool isSelected = false;
Expand Down
11 changes: 10 additions & 1 deletion Source/mapping_editors/KeyboardClickListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@

#include "../LumatoneEditorState.h"
#include "../lumatone_editor_library/ui/keyboard_component.h"

#include "../lumatone_editor_library/palettes/colour_selection_broadcaster.h"
// Maybe KeyboardComponentSelectionController
class KeyboardClickListener : public LumatoneEditorState
, private LumatoneEditorState::Controller
, public LumatoneKeyboardComponent::Listener
, public ColourSelectionBroadcaster
{
public:

Expand All @@ -31,6 +32,11 @@ class KeyboardClickListener : public LumatoneEditorState
void handleKeyDown(int keyNum) override;
void handleKeyHold(int key, float xDistance, float yDistance) override;

private:

juce::Colour getSelectedColour() override;
void deselectColour() override {}

private:

void toggleKeySelection(int keyNum);
Expand All @@ -40,6 +46,9 @@ class KeyboardClickListener : public LumatoneEditorState
LumatoneKeyboardComponent* keyboardComponent;

int lastKeyDown = -1;

juce::Colour lastKeyColour;

};

#endif // LUMATONE_KEY_SELECTION_CONTROLLER_H

0 comments on commit 95c90db

Please sign in to comment.