diff --git a/Source/actions/KeyboardClickListener.cpp b/Source/actions/KeyboardClickListener.cpp index 99d749a..d7ee828 100644 --- a/Source/actions/KeyboardClickListener.cpp +++ b/Source/actions/KeyboardClickListener.cpp @@ -32,7 +32,7 @@ void KeyboardClickListener::handleKeyDown(int keyNum) const LumatoneKey& key = getMappingData()->getKey(keyCoord.boardIndex, keyCoord.keyIndex); lastKeyColour = key.getColour(); - selectorListeners.call(&ColourSelectionListener::colourChangedCallback, this, lastKeyColour); + // selectorListeners.call(&ColourSelectionListener::colourChangedCallback, this, lastKeyColour); } void KeyboardClickListener::handleKeyHold(int key, float xDistance, float yDistance) diff --git a/Source/components/mapping/KeyEditorControls.cpp b/Source/components/mapping/KeyEditorControls.cpp index 5281513..ca1b257 100644 --- a/Source/components/mapping/KeyEditorControls.cpp +++ b/Source/components/mapping/KeyEditorControls.cpp @@ -45,12 +45,12 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn) // addAndMakeVisible(colourSubwindow.get()); colourDropdown = std::make_unique("AssignColourDropdown"); - colourDropdown->setOnValueChangeCallback([&]() - { - performAction(SetKeySettingsAction::NewSetAssignColourAction(*this, colourDropdown->getSelectedColour())); - if (colourDropdown->getSelectedColour() != juce::Colours::transparentBlack) - performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys())); - }); + // colourDropdown->setOnValueChangeCallback([&]() + // { + // performAction(SetKeySettingsAction::NewSetAssignColourAction(*this, colourDropdown->getSelectedColour())); + // if (colourDropdown->getSelectedColour() != juce::Colours::transparentBlack) + // performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys())); + // }); // addColourSelectionListener(colourDropdown.get()); // colourDropdown->setColourPickerChangedCallback([&]() @@ -236,9 +236,10 @@ void KeyEditorControls::selectionChanged() if (newData.useColour) { setAssignKeyColour(newData.useColour, newData.colour); - // performAction(SetKeySettingsAction::NewSetAssignColourAction(*this, newData.colour), true, false); + colourSelectionGroup->setSelectedColour(newData.colour, nullptr); // colourSubwindow->setColour(newData.colour.toString(), false); - colourDropdown->setSelectedColour(newData.colour); + // colourDropdown->setSelectedColour(newData.colour, false, false); + // performAction(SetKeySettingsAction::NewSetAssignColourAction(*this, newData.colour), true, false); // if (newData.colour.isTransparent()) // colourTextEditor->setText("", juce::NotificationType::dontSendNotification); @@ -248,7 +249,7 @@ void KeyEditorControls::selectionChanged() else { // colourSubwindow->setColour("", false); - colourDropdown->deselectColour(); + colourDropdown->clearColour(false); // colourTextEditor->setText("", juce::NotificationType::dontSendNotification); } @@ -272,35 +273,41 @@ void KeyEditorControls::handleStatePropertyChange(juce::ValueTree stateIn, const { LumatoneEditorState::handleStatePropertyChange(stateIn, property); - juce::var value = stateIn.getProperty(property); + // juce::var value = stateIn.getProperty(property); - if (property == LumatoneEditSelectionProperty::AssignKeyColour) - { - auto colourString = stateIn[property].toString(); - // colourTextEditor->setText(colourString, juce::NotificationType::dontSendNotification); - // colourSubwindow->setColour(colourString, false); - colourDropdown->setSelectedColour(juce::Colour::fromString(colourString)); - } - else if (property == LumatoneEditSelectionProperty::AssignKeyType) - { - keyTypeCombo->setSelectedId(((int)value) + 1, juce::NotificationType::dontSendNotification); - } - else if (property == LumatoneEditSelectionProperty::AssignKeyNote) - { - noteInput->setValue((int)value, juce::NotificationType::dontSendNotification); - } - else if (property == LumatoneEditSelectionProperty::AssignKeyChannel) - { - channelInput->setValue((int)value, juce::NotificationType::dontSendNotification); - } - else if (property == LumatoneEditSelectionProperty::AssignKeyCCFader) - { + // if (property == LumatoneEditSelectionProperty::AssignKeyColour) + // { + // auto colourString = stateIn[property].toString(); + // // colourTextEditor->setText(colourString, juce::NotificationType::dontSendNotification); + // // colourSubwindow->setColour(colourString, false); + // colourDropdown->setSelectedColour(juce::Colour::fromString(colourString), true, false); + // } + // else if (property == LumatoneEditSelectionProperty::AssignKeyType) + // { + // keyTypeCombo->setSelectedId(((int)value) + 1, juce::NotificationType::dontSendNotification); + // } + // else if (property == LumatoneEditSelectionProperty::AssignKeyNote) + // { + // noteInput->setValue((int)value, juce::NotificationType::dontSendNotification); + // } + // else if (property == LumatoneEditSelectionProperty::AssignKeyChannel) + // { + // channelInput->setValue((int)value, juce::NotificationType::dontSendNotification); + // } + // else if (property == LumatoneEditSelectionProperty::AssignKeyCCFader) + // { - } + // } } void KeyEditorControls::colourChangedCallback(ColourSelectionBroadcaster *source, juce::Colour newColour) { performAction(SetKeySettingsAction::NewSetAssignColourAction(*this, newColour)); - performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys()), true, false); + + // A bit kludgey maybe + juce::Component* src = dynamic_cast(source); + if (src != nullptr && isParentOf(src)) + { + performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys()), true, false); + } } diff --git a/Source/controls/ColourDropdownSelector.cpp b/Source/controls/ColourDropdownSelector.cpp index 9ab9493..a0a689e 100644 --- a/Source/controls/ColourDropdownSelector.cpp +++ b/Source/controls/ColourDropdownSelector.cpp @@ -69,7 +69,7 @@ void ColourDropdownSelector::setShowPicker(bool show) colourPickerButton->setVisible(show); } -void ColourDropdownSelector::setSelectedColour(juce::Colour newColour, bool setText) +void ColourDropdownSelector::setSelectedColour(juce::Colour newColour, bool sendNotification, bool doCallback) { if (!newColour.isOpaque()) return; // Don't allow transparency @@ -81,15 +81,22 @@ void ColourDropdownSelector::setSelectedColour(juce::Colour newColour, bool setT colourPickerButton->setColour(juce::TextButton::ColourIds::buttonColourId, newColour); colourPickerButton->setColour(juce::TextButton::ColourIds::buttonOnColourId, newColour); - selectorListeners.call(&ColourSelectionListener::colourChangedCallback, this, lastSetColour); + if (sendNotification) + selectorListeners.call(&ColourSelectionListener::colourChangedCallback, this, lastSetColour); } - if (setText) - { - colourEditorBox->setText(lastSetColour.toDisplayString(false), juce::NotificationType::dontSendNotification); - } + // if (setText) + // { + colourEditorBox->setText(lastSetColour.toDisplayString(false), juce::NotificationType::dontSendNotification); + // } - callbackColourChanged(); + if (doCallback) + callbackColourChanged(); +} + +void ColourDropdownSelector::clearColour(bool sendNotification) +{ + colourEditorBox->setSelectedId(0, sendNotification ? juce::NotificationType::sendNotification : juce::NotificationType::dontSendNotification); } void ColourDropdownSelector::setOnValueChangeCallback(std::function callbackIn) @@ -124,6 +131,12 @@ void ColourDropdownSelector::colourChangedCallback(ColourSelectionBroadcaster* s pickerIsListening = false; // callbackPickerChanged(); + return; + } + + if (source != this) + { + setSelectedColour(newColour, false, true); } } @@ -134,7 +147,7 @@ juce::Colour ColourDropdownSelector::getSelectedColour() void ColourDropdownSelector::deselectColour() { - colourEditorBox->setSelectedId(0, juce::NotificationType::sendNotification); + clearColour(); } juce::Colour ColourDropdownSelector::parseInput() const @@ -182,7 +195,7 @@ void ColourDropdownSelector::valueChangedCallback() selectedColour = juce::Colour::fromString("ff" + colourEditorBox->getText()); } - setSelectedColour(selectedColour, false); + setSelectedColour(selectedColour, true, true); } void ColourDropdownSelector::togglePickerListenForColour(bool listening) diff --git a/Source/controls/ColourDropdownSelector.h b/Source/controls/ColourDropdownSelector.h index d2e563b..0448fd5 100644 --- a/Source/controls/ColourDropdownSelector.h +++ b/Source/controls/ColourDropdownSelector.h @@ -31,7 +31,8 @@ class ColourDropdownSelector : public juce::Component void setShowDropdown(bool show); void setShowPicker(bool show); - void setSelectedColour(juce::Colour newColour, bool setText=true); + void setSelectedColour(juce::Colour newColour, bool sendNotification = true, bool doCallback = true); + void clearColour(bool sendNotification = true); void setOnValueChangeCallback(std::function callback); void setColourPickerChangedCallback(std::function callback);