diff --git a/Source/ColourPaletteWindow.cpp b/Source/ColourPaletteWindow.cpp index f7866ff..7ab9b53 100644 --- a/Source/ColourPaletteWindow.cpp +++ b/Source/ColourPaletteWindow.cpp @@ -29,10 +29,10 @@ ColourPaletteWindow::ColourPaletteWindow(const LumatoneEditorState& stateIn) setName("ColourPaletteWindow"); setLookAndFeel(&getEditorLookAndFeel()); - colourSelectorGroup.reset(new ColourSelectionGroup()); - loadColourPalettesFromFile(); + colourSelectorGroup.reset(new ColourSelectionGroup()); + palettePanel.reset(new ColourPalettesPanel(getColourPalettes(), colourSelectorGroup.get())); palettePanel->addListener(this); @@ -50,7 +50,7 @@ ColourPaletteWindow::ColourPaletteWindow(const LumatoneEditorState& stateIn) colourToolTabs->addTab(juce::translate("ColourPalettes"), juce::Colour(), palettePanelViewport.get(), false); colourToolTabs->addTab(juce::translate("CustomPicker"), juce::Colour(), customPickerPanel.get(), false); colourToolTabs->setColour(juce::TabbedComponent::ColourIds::outlineColourId, juce::Colour()); - colourToolTabs->getTabbedButtonBar().getProperties().set(LumatoneEditorStyleIDs::fontHeightScalar, 0.9f); + colourToolTabs->getTabbedButtonBar().getProperties().set(LumatoneEditorStyleIDs::fontHeightScalar, 0.75f); addAndMakeVisible(*colourToolTabs); const int firstTabIndex = getProperty(LumatoneEditorProperty::LastColourWindowTab, "0").getIntValue(); @@ -60,7 +60,10 @@ ColourPaletteWindow::ColourPaletteWindow(const LumatoneEditorState& stateIn) ColourPaletteWindow::~ColourPaletteWindow() { + setLookAndFeel(nullptr); + paletteEditPanel = nullptr; + colourToolTabs = nullptr; colourSelectorGroup->removeSelector(customPickerPanel.get()); @@ -68,16 +71,33 @@ ColourPaletteWindow::~ColourPaletteWindow() palettePanelViewport = nullptr; palettePanel = nullptr; + colourSelectorGroup = nullptr; +} - setLookAndFeel(nullptr); +void ColourPaletteWindow::paint(juce::Graphics &g) +{ + g.setColour(backgroundColour); + + auto controlBounds = getLocalBounds().toFloat() + .withTop(colourToolTabs->getTabbedButtonBar().getHeight()) + .withTrimmedTop(indent) + .withTrimmedBottom(indent); + + g.fillRoundedRectangle(controlBounds, getRoundedRectCornerSize()); } void ColourPaletteWindow::resized() { palettePanelViewport->setScrollBarThickness(proportionOfWidth(viewportScrollbarWidthScalar)); + + colourToolTabs->setIndent(indent); + colourToolTabs->setTabBarDepth(tabBarDepth); colourToolTabs->setBounds(getLocalBounds()); + + // colourToolTabs->setIndent(indent); + if (paletteEditPanel.get()) paletteEditPanel->setBounds(getLocalBounds()); @@ -102,7 +122,7 @@ void ColourPaletteWindow::duplicatePalette(int paletteIndexIn) { auto colourPalettes = getColourPalettes(); auto copiedPalette = getColourPalettes()[paletteIndexIn].clone(); - + if (! copiedPalette.saveToFile()) return; // TODO @@ -117,7 +137,7 @@ void ColourPaletteWindow::removePalette(int paletteIndexToRemove) // Remove loaded colour palette auto colourPalettes = getColourPalettes(); auto deletedPalette = colourPalettes[paletteIndexToRemove]; - + if (!deletedPalette.deleteFile()) return; // TODO @@ -166,7 +186,7 @@ void ColourPaletteWindow::newPaletteRequested() auto newPalette = LumatoneEditorColourPalette(); newPalette.saveToFile(); colourPalettes.insert(0, newPalette); - + setColourPalettes(colourPalettes); startEditingPalette(0, 0); } @@ -210,3 +230,23 @@ void ColourPaletteWindow::changeListenerCallback(juce::ChangeBroadcaster* source getPropertiesFile()->setValue(LumatoneEditorProperty::LastColourWindowTab, juce::String(newTab)); } } + +void ColourPaletteWindow::setIndentSize(int size, bool resize) +{ + indent = size; + if (resize) + resized(); +} + +void ColourPaletteWindow::setTabBarDepth(int height, bool resize) +{ + tabBarDepth = height; + if (resize) + resized(); +} + +void ColourPaletteWindow::setBackgroundColour(juce::Colour backgroundIn) +{ + backgroundColour = backgroundIn; + repaint(); +} diff --git a/Source/ColourPaletteWindow.h b/Source/ColourPaletteWindow.h index 31554fc..d864b39 100644 --- a/Source/ColourPaletteWindow.h +++ b/Source/ColourPaletteWindow.h @@ -36,10 +36,17 @@ class ColourPaletteWindow : public juce::Component ColourPaletteWindow(const LumatoneEditorState& stateIn); ~ColourPaletteWindow() override; + void paint(juce::Graphics& g) override; + void resized() override; void changeListenerCallback(juce::ChangeBroadcaster* source) override; + void setIndentSize(int size, bool resize=true); + void setTabBarDepth(int height, bool resize=true); + + void setBackgroundColour(juce::Colour backgroundIn); + //==================================================================== /// @@ -67,6 +74,8 @@ class ColourPaletteWindow : public juce::Component colourSelectorGroup->setCurrentSelector(newSelector); } + ColourSelectionGroup* getColourSelectionGroup() { return colourSelectorGroup.get(); } + private: /// @@ -99,23 +108,26 @@ class ColourPaletteWindow : public juce::Component private: - // LumatoneEditorLookAndFeel lookAndFeel; - - //juce::Array& colourPalettes; + std::unique_ptr colourSelectorGroup; - std::unique_ptr colourToolTabs; std::unique_ptr palettePanel; + std::unique_ptr palettePanelViewport; + std::unique_ptr customPickerPanel; - std::unique_ptr paletteEditPanel; - std::unique_ptr palettePanelViewport; + std::unique_ptr colourToolTabs; - std::unique_ptr colourSelectorGroup; + std::unique_ptr paletteEditPanel; int paletteIndexEditing = -1; bool paletteEditingIsNew = false; + int indent = 48; + int tabBarDepth = 48; + const float viewportScrollbarWidthScalar = 0.020833f; + juce::Colour backgroundColour; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ColourPaletteWindow) }; diff --git a/Source/Main.cpp b/Source/Main.cpp index ecb040d..aae092f 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -93,6 +93,8 @@ void TerpstraSysExApplication::initialise(const String& commandLine) void TerpstraSysExApplication::shutdown() { + undoManager.clearUndoHistory(); + LocalisedStrings::setCurrentMappings(nullptr); // Save state of main window diff --git a/Source/lumatone_editor_library/palettes/colour_selection_group.h b/Source/lumatone_editor_library/palettes/colour_selection_group.h index 4f773e1..38984ab 100644 --- a/Source/lumatone_editor_library/palettes/colour_selection_group.h +++ b/Source/lumatone_editor_library/palettes/colour_selection_group.h @@ -25,6 +25,8 @@ class ColourSelectionGroup : public ColourSelectionBroadcaster, ~ColourSelectionGroup() { + selectorListeners.clear(); + for (auto selector : colourSelectors) selector->removeColourSelectionListener(this); } diff --git a/Source/mapping_editors/KeyEditorControls.cpp b/Source/mapping_editors/KeyEditorControls.cpp index 1debabb..dc18c35 100644 --- a/Source/mapping_editors/KeyEditorControls.cpp +++ b/Source/mapping_editors/KeyEditorControls.cpp @@ -17,11 +17,15 @@ #include "../ColourPaletteWindow.h" // #include "../lumatone_editor_library/palettes/palette_selection_panel.h" #include "../lumatone_editor_library/palettes/colour_picker_panel.h" +#include "../lumatone_editor_library/palettes/colour_selection_group.h" #include "../actions/EditorControlActions.h" #include "../components/RangedControl.h" +#include "../actions/EditorControlActions.h" + + KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn) : juce::Component("KeyEditorControls") , LumatoneEditorState("KeyEditorControls", stateIn) @@ -50,7 +54,8 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn) keyTypeCombo->addItem (juce::translate("Disabled"), (int)LumatoneKeyType::disabled); keyTypeCombo->onChange = [&]() { - performAction(SetKeySettingsAction::NewSetAssignKeyTypeAction(*this, LumatoneKeyType(keyTypeCombo->getSelectedId() - 1))); + performAction(SetKeySettingsAction::NewSetAssignKeyTypeAction(*this, LumatoneKeyType(keyTypeCombo->getSelectedId()))); + performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys())); }; addAndMakeVisible(keyTypeCombo.get()); @@ -59,6 +64,7 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn) noteInput->setValueChangedCallback([&]() { performAction(SetKeySettingsAction::NewSetAssignKeyNoteAction(*this, (int)noteInput->getValue())); + performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys())); }); addAndMakeVisible(noteInput.get()); @@ -66,6 +72,7 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn) channelInput->setValueChangedCallback([&]() { performAction(SetKeySettingsAction::NewSetAssignKeyChannelAction(*this, (int)channelInput->getValue())); + performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys())); }); addAndMakeVisible(channelInput.get()); @@ -94,23 +101,42 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn) addAndMakeVisible(lblChannel.get()); colourPalettePanel = std::make_unique(stateIn); + colourPalettePanel->setBackgroundColour(getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::ColourPaletteBackground)); + // colourPalettePanel->setColourSelectionGroup(group); addAndMakeVisible(colourPalettePanel.get()); + // colourPalettePanel->addColourSelectorToGroup(colourSelectionGroup.get()); + + // ColourSelectionGroup* group = new ColourSelectionGroup("KeyEditorControlColour"); + colourSelectionGroup = colourPalettePanel->getColourSelectionGroup(); + // colourSelectionGroup = std::make_unique("KeyEditorControlColour"); + colourSelectionGroup->addSelector(colourTextEditor.get()); + colourSelectionGroup->addColourSelectionListener(colourSubwindow.get()); + colourSelectionGroup->addColourSelectionListener(colourTextEditor.get()); + colourSelectionGroup->addColourSelectionListener(this); + // group->addSelector(colourTextEditor.get()); + // group->addColourSelectionListener(colourSubwindow.get()); + // group->addColourSelectionListener(colourTextEditor.get()); addEditorListener(this); } KeyEditorControls::~KeyEditorControls() { - colourControlTabs = nullptr; - colourPickerPanel = nullptr; + colourSelectionGroup = nullptr; colourPalettePanel = nullptr; + lblChannel = nullptr; + lblNote = nullptr; + lblKeyType = nullptr; + lblColour = nullptr; + channelInput = nullptr; noteInput = nullptr; keyTypeCombo = nullptr; - // colourPickerToggle = nullptr; + colourSubwindow = nullptr; colourTextEditor = nullptr; + lblKeySettings = nullptr; } @@ -173,7 +199,9 @@ void KeyEditorControls::resized() colourColumnWidth = w - colourColumnX - contentMarginWidth; colourColumnHeight = roundToInt(h * colourColumnH); - colourPalettePanel->setBounds(colourColumnX, 0, colourColumnWidth, h - contentMarginHeight); + colourPalettePanel->setBounds(colourColumnX, 0, colourColumnWidth, h); + colourPalettePanel->setIndentSize(contentMarginHeight, false); + colourPalettePanel->setTabBarDepth(headerHeight, false); } void KeyEditorControls::selectionChanged() @@ -182,9 +210,20 @@ void KeyEditorControls::selectionChanged() auto newData = LumatoneEditSelectionState::findSharedSelectionProperties(*getSelectedKeys()); if (newData.setColour) - colourTextEditor->setText(newData.colour.toDisplayString(false)); + { + setAssignKeyColour(newData.setColour, newData.colour); + // performAction(SetKeySettingsAction::NewSetAssignColourAction(*this, newData.colour), true, false); + colourSubwindow->setColour(newData.colour.toString(), false); + if (newData.colour.isTransparent()) + colourTextEditor->setText("", juce::NotificationType::dontSendNotification); + else + colourTextEditor->setText(newData.colour.toDisplayString(false), juce::NotificationType::dontSendNotification); + } else - colourTextEditor->clear(); + { + colourSubwindow->setColour("", false); + colourTextEditor->setText("", juce::NotificationType::dontSendNotification); + } if (newData.setType) keyTypeCombo->setSelectedId((int)newData.type, juce::NotificationType::dontSendNotification); @@ -192,16 +231,14 @@ void KeyEditorControls::selectionChanged() keyTypeCombo->setSelectedId(0, juce::NotificationType::dontSendNotification); if (newData.setNote) - noteInput->setValue(newData.note); + noteInput->setValue(newData.note, juce::NotificationType::dontSendNotification); else noteInput->setValue(-1, juce::NotificationType::dontSendNotification); if (newData.setChannel) - channelInput->setValue(newData.channel); + channelInput->setValue(newData.channel, juce::NotificationType::dontSendNotification); else channelInput->setValue(-1, juce::NotificationType::dontSendNotification); - - } void KeyEditorControls::handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier &property) @@ -212,7 +249,9 @@ void KeyEditorControls::handleStatePropertyChange(juce::ValueTree stateIn, const if (property == LumatoneEditSelectionProperty::AssignKeyColour) { - + auto colourString = stateIn[property].toString(); + colourTextEditor->setText(colourString, juce::NotificationType::dontSendNotification); + colourSubwindow->setColour(colourString, false); } else if (property == LumatoneEditSelectionProperty::AssignKeyType) { @@ -231,3 +270,9 @@ void KeyEditorControls::handleStatePropertyChange(juce::ValueTree stateIn, const } } + +void KeyEditorControls::colourChangedCallback(ColourSelectionBroadcaster *source, juce::Colour newColour) +{ + performAction(SetKeySettingsAction::NewSetAssignColourAction(*this, newColour)); + performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys()), true, false); +} diff --git a/Source/mapping_editors/KeyEditorControls.h b/Source/mapping_editors/KeyEditorControls.h index e4797fa..3900537 100644 --- a/Source/mapping_editors/KeyEditorControls.h +++ b/Source/mapping_editors/KeyEditorControls.h @@ -14,53 +14,44 @@ #include "../LumatoneEditorState.h" #include "../lumatone_editor_library/listeners/editor_listener.h" -class ColourViewComponent; +#include "../lumatone_editor_library/palettes/colour_selection_broadcaster.h" + +class ColourSelectionGroup; class ColourTextEditor; +class ColourViewComponent; +class RangedControl; class ColourPaletteWindow; -class CustomPickerPanel; -class ColourPalettesPanel; -class RangedControl; class KeyEditorControls : public juce::Component , public LumatoneEditorState , private LumatoneEditorState::Controller , public LumatoneEditor::EditorListener + , public ColourSelectionListener { public: KeyEditorControls(const LumatoneEditorState& stateIn); virtual ~KeyEditorControls() override; - void paint(juce::Graphics&) override; void resized() override; - - void selectionChanged() override; -private: - - - private: void handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property) override; -private: + void colourChangedCallback(ColourSelectionBroadcaster* source, juce::Colour newColour) override; +private: std::unique_ptr lblKeySettings; - std::unique_ptr colourControlTabs; - std::unique_ptr colourTextEditor; std::unique_ptr colourSubwindow; - // std::unique_ptr colourPickerToggle; std::unique_ptr keyTypeCombo; - // std::unique_ptr noteInput; std::unique_ptr noteInput; - // std::unique_ptr channelInput; std::unique_ptr channelInput; std::unique_ptr lblColour; @@ -69,9 +60,8 @@ class KeyEditorControls : public juce::Component std::unique_ptr lblChannel; std::unique_ptr colourPalettePanel; - // std::unique_ptr<> colourPalettePanel; - std::unique_ptr colourPickerPanel; - + // std::unique_ptr colourSelectionGroup; + ColourSelectionGroup* colourSelectionGroup; const float headerH = 0.19f; int headerHeight; @@ -79,7 +69,7 @@ class KeyEditorControls : public juce::Component juce::Path controlPath; int contentMarginWidth; - const float contentMarginParentW = 0.024f; + const float contentMarginParentW = 0.02f; int contentMarginHeight; const float controlMarginH = 0.08f; @@ -87,7 +77,7 @@ class KeyEditorControls : public juce::Component int labelHeight; // int labelMarginWidth; const float labelToHeaderH = 0.5f; - const float controlLabelFontScalar = 0.67f; + const float controlLabelFontScalar = 0.6f; int keyControlColumnWidth; int keyControlColumnRight; diff --git a/Source/mapping_editors/MultiSelectControls.h b/Source/mapping_editors/MultiSelectControls.h index 971cb0b..9fe51e5 100644 --- a/Source/mapping_editors/MultiSelectControls.h +++ b/Source/mapping_editors/MultiSelectControls.h @@ -50,7 +50,7 @@ class MultiSelectControls : public LumatoneEditorState juce::Path controlPath; int contentMarginWidth; - const float contentMarginParentW = 0.022f; + const float contentMarginParentW = 0.02f; int contentMarginHeight; const float controlMarginH = 0.08f;