From 95c90dbca1aab96768ac3924a0f585cfc1da3893 Mon Sep 17 00:00:00 2001 From: Vincenzo Sicurella Date: Sun, 28 Jul 2024 16:14:27 -0400 Subject: [PATCH] allow key click listener to broadcast colours --- Source/mapping_editors/KeyboardClickListener.cpp | 12 ++++++++++++ Source/mapping_editors/KeyboardClickListener.h | 11 ++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Source/mapping_editors/KeyboardClickListener.cpp b/Source/mapping_editors/KeyboardClickListener.cpp index b834f04..c464cfa 100644 --- a/Source/mapping_editors/KeyboardClickListener.cpp +++ b/Source/mapping_editors/KeyboardClickListener.cpp @@ -8,6 +8,7 @@ KeyboardClickListener::KeyboardClickListener(const LumatoneEditorState &stateIn, , keyboardComponent(keyboardComponentIn) { keyboardComponent->addListener(this); + addColourSelectionBroadcaster(this); } KeyboardClickListener::~KeyboardClickListener() @@ -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) @@ -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; diff --git a/Source/mapping_editors/KeyboardClickListener.h b/Source/mapping_editors/KeyboardClickListener.h index 2f24073..d073330 100644 --- a/Source/mapping_editors/KeyboardClickListener.h +++ b/Source/mapping_editors/KeyboardClickListener.h @@ -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: @@ -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); @@ -40,6 +46,9 @@ class KeyboardClickListener : public LumatoneEditorState LumatoneKeyboardComponent* keyboardComponent; int lastKeyDown = -1; + + juce::Colour lastKeyColour; + }; #endif // LUMATONE_KEY_SELECTION_CONTROLLER_H