Skip to content

Commit

Permalink
fixed and simplified some colour selection callback behavior, disable…
Browse files Browse the repository at this point in the history
… colour picker to prevent bug
  • Loading branch information
vsicurella committed Aug 15, 2024
1 parent d741074 commit f710bab
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Source/actions/KeyboardClickListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
73 changes: 40 additions & 33 deletions Source/components/mapping/KeyEditorControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn)
// addAndMakeVisible(colourSubwindow.get());

colourDropdown = std::make_unique<ColourDropdownSelector>("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([&]()
Expand Down Expand Up @@ -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);
Expand All @@ -248,7 +249,7 @@ void KeyEditorControls::selectionChanged()
else
{
// colourSubwindow->setColour("", false);
colourDropdown->deselectColour();
colourDropdown->clearColour(false);
// colourTextEditor->setText("", juce::NotificationType::dontSendNotification);
}

Expand All @@ -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<juce::Component*>(source);
if (src != nullptr && isParentOf(src))
{
performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys()), true, false);
}
}
31 changes: 22 additions & 9 deletions Source/controls/ColourDropdownSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<void()> callbackIn)
Expand Down Expand Up @@ -124,6 +131,12 @@ void ColourDropdownSelector::colourChangedCallback(ColourSelectionBroadcaster* s
pickerIsListening = false;

// callbackPickerChanged();
return;
}

if (source != this)
{
setSelectedColour(newColour, false, true);
}
}

Expand All @@ -134,7 +147,7 @@ juce::Colour ColourDropdownSelector::getSelectedColour()

void ColourDropdownSelector::deselectColour()
{
colourEditorBox->setSelectedId(0, juce::NotificationType::sendNotification);
clearColour();
}

juce::Colour ColourDropdownSelector::parseInput() const
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion Source/controls/ColourDropdownSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void()> callback);
void setColourPickerChangedCallback(std::function<void()> callback);
Expand Down

0 comments on commit f710bab

Please sign in to comment.