From e5b3a73e495c0987eb1439f8c97cdbaa65714714 Mon Sep 17 00:00:00 2001 From: Vincenzo Sicurella Date: Thu, 13 Jun 2024 18:49:05 -0400 Subject: [PATCH] implemenent set key settings action --- Source/actions/EditorControlActions.cpp | 50 ++++++++++++----- Source/actions/EditorControlActions.h | 18 ++---- Source/mapping_editors/KeyEditorControls.cpp | 58 +++++++++++++++----- Source/mapping_editors/KeyEditorControls.h | 9 ++- 4 files changed, 93 insertions(+), 42 deletions(-) diff --git a/Source/actions/EditorControlActions.cpp b/Source/actions/EditorControlActions.cpp index 86f16aa..9cf77ee 100644 --- a/Source/actions/EditorControlActions.cpp +++ b/Source/actions/EditorControlActions.cpp @@ -15,26 +15,30 @@ SetKeySettingsAction::SetKeySettingsAction(const LumatoneEditorState & stateIn, : LumatoneEditorState("SetKeySettingsAction", stateIn) , LumatoneEditorState::Controller(static_cast(*this)) , LumatoneAction(this, "SetKeySettingsAction") - , newEditData("SetKeySettingsActionData") + // , newEditData("SetKeySettingsActionData") { previousData = stateIn.getEditSelectionData(); - newEditData.setKeyColour(setKeyColourIn, colourIn); - newEditData.setKeyType(setKeyTypeIn, typeIn); - newEditData.setKeyNote(setKeyNoteIn, noteIn); - newEditData.setKeyChannel(setKeyChannelIn, channelIn); - newEditData.setCCFader(setCCFaderDefaultIn, ccFaderDefaultIn); + newEditData.setColour = setKeyColourIn; + newEditData.colour = colourIn; + + newEditData.setType = setKeyTypeIn; + newEditData.type = typeIn; + + newEditData.setNote = setKeyNoteIn; + newEditData.note = noteIn; + + newEditData.setChannel = setKeyChannelIn; + newEditData.channel = channelIn; + + newEditData.setCCFaderDefault = setCCFaderDefaultIn; + newEditData.ccFaderDefault = ccFaderDefaultIn; } bool SetKeySettingsAction::perform() { - LumatoneEditSelectionState::Data data = newEditData.getData(); - setAssignKeyColour(data.setColour, data.colour); - setAssignKeyType(data.setType, data.type); - setAssignKeyNote(data.setNote, data.note); - setAssignKeyChannel(data.setChannel, data.channel); - setAssignCCFader(data.setCCFaderDefault, data.ccFaderDefault); - return false; + addToEditAassignment(); + return true; } bool SetKeySettingsAction::undo() @@ -44,7 +48,25 @@ bool SetKeySettingsAction::undo() setAssignKeyNote(previousData.setNote, previousData.note); setAssignKeyChannel(previousData.setChannel, previousData.channel); setAssignCCFader(previousData.setCCFaderDefault, previousData.ccFaderDefault); - return false; + return true; +} + +// void SetKeySettingsAction::assignToSelectedKeys() +// { +// } + +void SetKeySettingsAction::addToEditAassignment() +{ + if (newEditData.setColour) + setAssignKeyColour(newEditData.setColour, newEditData.colour); + if (newEditData.setType) + setAssignKeyType(newEditData.setType, newEditData.type); + if (newEditData.setNote) + setAssignKeyNote(newEditData.setNote, newEditData.note); + if (newEditData.setChannel) + setAssignKeyChannel(newEditData.setChannel, newEditData.channel); + if (newEditData.setCCFaderDefault) + setAssignCCFader(newEditData.setCCFaderDefault, newEditData.ccFaderDefault); } SetKeySettingsAction *SetKeySettingsAction::NewSetAssignColourAction(LumatoneEditorState &stateIn, juce::Colour colourIn) diff --git a/Source/actions/EditorControlActions.h b/Source/actions/EditorControlActions.h index 608f9c1..d73161c 100644 --- a/Source/actions/EditorControlActions.h +++ b/Source/actions/EditorControlActions.h @@ -39,6 +39,9 @@ class SetKeySettingsAction : public LumatoneEditorState int getSizeInUnits() override { return sizeof(SetKeySettingsAction); } + // void assignToSelectedKeys(); + void addToEditAassignment(); + public: static SetKeySettingsAction* NewSetAssignColourAction(LumatoneEditorState& stateIn, juce::Colour colourIn); @@ -50,19 +53,8 @@ class SetKeySettingsAction : public LumatoneEditorState private: LumatoneEditSelectionState::Data previousData; - LumatoneEditSelectionState newEditData; - - // bool setKeyColour = false; - // bool setKeyType = false; - // bool setKeyNote = false; - // bool setKeyChannel = false; - // bool setCCFaderDefault = false; - - // juce::Colour colour; - // LumatoneKeyType type; - // int note; - // int channel; - // bool ccFaderDefault; + LumatoneEditSelectionState::Data newEditData; + }; diff --git a/Source/mapping_editors/KeyEditorControls.cpp b/Source/mapping_editors/KeyEditorControls.cpp index 5e84e50..0ce06d4 100644 --- a/Source/mapping_editors/KeyEditorControls.cpp +++ b/Source/mapping_editors/KeyEditorControls.cpp @@ -18,9 +18,12 @@ // #include "../lumatone_editor_library/palettes/palette_selection_panel.h" #include "../lumatone_editor_library/palettes/colour_picker_panel.h" +#include "../actions/EditorControlActions.h" + KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn) - : LumatoneEditorState(stateIn) - , juce::Component("KeyEditorControls") + : juce::Component("KeyEditorControls") + , LumatoneEditorState("KeyEditorControls", stateIn) + , LumatoneEditorState::Controller(static_cast(*this)) { lblKeySettings = std::make_unique("lblKeySettings", "Key Settings"); lblKeySettings->setColour(juce::Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::LabelBlue)); @@ -34,9 +37,6 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn) colourSubwindow->setColourButtonMode(ColourViewComponent::ColourButtonMode::Dropper); addAndMakeVisible(colourSubwindow.get()); - // colourPickerToggle = std::make_unique("Pick"); - // addAndMakeVisible(colourPickerToggle.get()); - keyTypeCombo = std::make_unique("keyTypeCombo"); keyTypeCombo->setEditableText (false); keyTypeCombo->setJustificationType (juce::Justification::centredLeft); @@ -46,6 +46,10 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn) keyTypeCombo->addItem (juce::translate("Continuous controller"), 2); keyTypeCombo->addItem (juce::translate("Lumatouch"), 3); keyTypeCombo->addItem (juce::translate("Disabled"), 4); + keyTypeCombo->onChange = [&]() + { + performAction(SetKeySettingsAction::NewSetAssignKeyTypeAction(*this, LumatoneKeyType(keyTypeCombo->getSelectedId() - 1))); + }; addAndMakeVisible(keyTypeCombo.get()); noteInput = std::make_unique("noteInput"); @@ -53,6 +57,10 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn) noteInput->setRange (0, 127, 1); noteInput->setSliderStyle (juce::Slider::IncDecButtons); noteInput->setTextBoxStyle (juce::Slider::TextBoxLeft, false, 56, 20); + noteInput->onValueChange = [&]() + { + performAction(SetKeySettingsAction::NewSetAssignKeyNoteAction(*this, (int)noteInput->getValue())); + }; // noteInput->addListener (this); addAndMakeVisible(noteInput.get()); @@ -60,6 +68,10 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn) channelInput->setRange (1, 16, 1); channelInput->setSliderStyle (juce::Slider::IncDecButtons); channelInput->setTextBoxStyle (juce::Slider::TextBoxLeft, false, 56, 20); + channelInput->onValueChange = [&]() + { + performAction(SetKeySettingsAction::NewSetAssignKeyChannelAction(*this, (int)channelInput->getValue())); + }; addAndMakeVisible(channelInput.get()); lblColour = std::make_unique("lblColour", "Key Colour:"); @@ -88,14 +100,6 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn) colourPalettePanel = std::make_unique(stateIn); addAndMakeVisible(colourPalettePanel.get()); - // colourPickerPanel = std::make_unique(); - - // juce::Colour colourControlBackground = getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::ColourPaletteBackground); - // colourControlTabs = std::make_unique(juce::TabbedButtonBar::Orientation::TabsAtTop); - // colourControlTabs->addTab("Colour Palettes", colourControlBackground, colourPalettePanel.get(), false); - // colourControlTabs->addTab("Custom Picker", colourControlBackground, colourPickerPanel.get(), false); - // addAndMakeVisible(colourControlTabs.get()); - } KeyEditorControls::~KeyEditorControls() @@ -174,3 +178,31 @@ void KeyEditorControls::resized() colourPalettePanel->setBounds(colourColumnX, 0, colourColumnWidth, h - contentMarginHeight); } + +void KeyEditorControls::handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier &property) +{ + LumatoneEditorState::handleStatePropertyChange(stateIn, property); + + juce::var value = stateIn.getProperty(property); + + if (property == LumatoneEditSelectionProperty::AssignKeyColour) + { + + } + 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) + { + + } +} diff --git a/Source/mapping_editors/KeyEditorControls.h b/Source/mapping_editors/KeyEditorControls.h index 5e13fc4..1f089ea 100644 --- a/Source/mapping_editors/KeyEditorControls.h +++ b/Source/mapping_editors/KeyEditorControls.h @@ -19,8 +19,9 @@ class ColourPaletteWindow; class CustomPickerPanel; class ColourPalettesPanel; -class KeyEditorControls : public LumatoneEditorState - , public juce::Component +class KeyEditorControls : public juce::Component + , public LumatoneEditorState + , private LumatoneEditorState::Controller { public: KeyEditorControls(const LumatoneEditorState& stateIn); @@ -32,6 +33,10 @@ class KeyEditorControls : public LumatoneEditorState void resized() override; +private: + + void handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property) override; + private: std::unique_ptr lblKeySettings;