diff --git a/Source/lumatone_editor_library/palettes/colour_palette_window.cpp b/Source/ColourPaletteWindow.cpp similarity index 69% rename from Source/lumatone_editor_library/palettes/colour_palette_window.cpp rename to Source/ColourPaletteWindow.cpp index 569aa2bf..c1c59a44 100644 --- a/Source/lumatone_editor_library/palettes/colour_palette_window.cpp +++ b/Source/ColourPaletteWindow.cpp @@ -8,28 +8,29 @@ ============================================================================== */ -#include "colour_palette_window.h" +#include "ColourPaletteWindow.h" -#include "./colour_palette_component.h" +#include "./lumatone_editor_library/palettes/colour_selection_group.h" +#include "./lumatone_editor_library/palettes/colour_picker_panel.h" -#include "./palette_selection_panel.h" -#include "./colour_picker_panel.h" +#include "./colour_palette_component.h" #include "./palette_edit_panel.h" +#include "./LumatoneEditorLookAndFeel.h" + + //============================================================================== // ColourPaletteWindow Definitions -ColourPaletteWindow::ColourPaletteWindow(juce::Array& colourPalettesIn) - // : lookAndFeel(TerpstraSysExApplication::getApp().getLookAndFeel()), - : colourPalettes(colourPalettesIn) +ColourPaletteWindow::ColourPaletteWindow(const LumatoneEditorState& stateIn) + : LumatoneEditorStateController("ColourPaletteWindow", stateIn) { - // setLookAndFeel(&lookAndFeel); - setName("ColourPaletteWindow"); + setLookAndFeel(&getEditorLookAndFeel()); colourSelectorGroup.reset(new ColourSelectionGroup()); - - palettePanel.reset(new ColourPalettesPanel(colourPalettes, colourSelectorGroup.get())); + + palettePanel.reset(new ColourPalettesPanel(getColourPalettes(), colourSelectorGroup.get())); palettePanel->addListener(this); palettePanelViewport.reset(new juce::Viewport("PalettePanelViewport")); @@ -46,26 +47,26 @@ ColourPaletteWindow::ColourPaletteWindow(juce::ArrayaddTab(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.9f); addAndMakeVisible(*colourToolTabs); - - const int firstTabIndex = 0;//; TerpstraSysExApplication::getApp().getPropertiesFile()->getIntValue("LastColourPopupTabIndex"); + + const int firstTabIndex = getProperty(LumatoneEditorProperty::LastColourWindowTab, "0").getIntValue(); colourToolTabs->setCurrentTabIndex(firstTabIndex); colourToolTabs->getTabbedButtonBar().addChangeListener(this); } ColourPaletteWindow::~ColourPaletteWindow() -{ +{ paletteEditPanel = nullptr; colourToolTabs = nullptr; - + colourSelectorGroup->removeSelector(customPickerPanel.get()); customPickerPanel = nullptr; - + palettePanelViewport = nullptr; palettePanel = nullptr; colourSelectorGroup = nullptr; - + setLookAndFeel(nullptr); } @@ -77,13 +78,13 @@ void ColourPaletteWindow::resized() if (paletteEditPanel.get()) paletteEditPanel->setBounds(getLocalBounds()); - palettePanel->rebuildPanel(colourPalettes, palettePanelViewport->getMaximumVisibleWidth()); + palettePanel->rebuildPanel(getColourPalettes(), palettePanelViewport->getMaximumVisibleWidth()); } void ColourPaletteWindow::startEditingPalette(int paletteIndexIn, int selectedSwatchIndex) { paletteIndexEditing = paletteIndexIn; - paletteEditPanel.reset(new PaletteEditPanel(colourPalettes[paletteIndexIn])); + paletteEditPanel.reset(new PaletteEditPanel(*this, LumatoneEditorState::getColourPalettes()[paletteIndexIn])); paletteEditPanel->setBounds(getLocalBounds()); paletteEditPanel->setLookAndFeel(&getLookAndFeel()); addAndMakeVisible(*paletteEditPanel); @@ -96,36 +97,47 @@ void ColourPaletteWindow::startEditingPalette(int paletteIndexIn, int selectedSw void ColourPaletteWindow::duplicatePalette(int paletteIndexIn) { - auto copiedPalette = colourPalettes[paletteIndexIn].clone(); + auto colourPalettes = getColourPalettes(); + auto copiedPalette = getColourPalettes()[paletteIndexIn].clone(); + + if (! copiedPalette.saveToFile()) + return; // TODO + colourPalettes.insert(paletteIndexIn + 1, copiedPalette); - // TerpstraSysExApplication::getApp().saveColourPalette(copiedPalette); + setColourPalettes(colourPalettes); + palettePanel->rebuildPanel(colourPalettes); } void ColourPaletteWindow::removePalette(int paletteIndexToRemove) { // Remove loaded colour palette - juce::String deletedPalette = colourPalettes[paletteIndexToRemove].getPathToFile(); + auto colourPalettes = getColourPalettes(); + auto deletedPalette = colourPalettes[paletteIndexToRemove]; + + if (!deletedPalette.deleteFile()) + return; // TODO + colourPalettes.remove(paletteIndexToRemove); - // TerpstraSysExApplication::getApp().deletePaletteFile(deletedPalette); + setColourPalettes(colourPalettes); palettePanel->rebuildPanel(colourPalettes); } void ColourPaletteWindow::editPaletteRequested(int paletteIndex, int selectedSwatchIndex) { - if (paletteIndex >= 0 && paletteIndex < colourPalettes.size()) + if (paletteIndex >= 0 && paletteIndex < getColourPalettes().size()) { startEditingPalette(paletteIndex, selectedSwatchIndex); } else - jassert(true); // Something bad happened! + jassert(true); // Something bad happened! } void ColourPaletteWindow::clonePaletteRequested(int paletteIndex) { - if (paletteIndex >= 0 && paletteIndex < colourPalettes.size()) + if (paletteIndex >= 0 && paletteIndex < getColourPalettes().size()) { duplicatePalette(paletteIndex); } @@ -135,7 +147,7 @@ void ColourPaletteWindow::clonePaletteRequested(int paletteIndex) void ColourPaletteWindow::deletePaletteRequested(int paletteIndex) { - if (paletteIndex >= 0 && paletteIndex < colourPalettes.size()) + if (paletteIndex >= 0 && paletteIndex < getColourPalettes().size()) { removePalette(paletteIndex); } @@ -146,7 +158,13 @@ void ColourPaletteWindow::deletePaletteRequested(int paletteIndex) void ColourPaletteWindow::newPaletteRequested() { paletteEditingIsNew = true; - colourPalettes.insert(0, LumatoneEditorColourPalette()); + + auto colourPalettes = getColourPalettes(); + auto newPalette = LumatoneEditorColourPalette(); + newPalette.saveToFile(); + colourPalettes.insert(0, newPalette); + + setColourPalettes(colourPalettes); startEditingPalette(0, 0); } @@ -157,21 +175,23 @@ void ColourPaletteWindow::changeListenerCallback(juce::ChangeBroadcaster* source { if (paletteEditPanel->wasSaveRequested()) { - if (paletteIndexEditing >= 0 && paletteIndexEditing < colourPalettes.size()) + if (paletteIndexEditing >= 0 && paletteIndexEditing < getColourPalettes().size()) { + auto colourPalettes = getColourPalettes(); auto palette = colourPalettes.getReference(paletteIndexEditing); palette.setColours(paletteEditPanel->getCurrentPalette()); juce::String newName = paletteEditPanel->getPaletteName(); palette.setName(newName); - // TerpstraSysExApplication::getApp().saveColourPalette(palette); + palette.saveToFile(); + setColourPalettes(colourPalettes); } else jassert(true); // Something bad happened! - palettePanel->rebuildPanel(colourPalettes); + palettePanel->rebuildPanel(getColourPalettes()); } else if (paletteEditingIsNew) removePalette(paletteIndexEditing); @@ -180,10 +200,10 @@ void ColourPaletteWindow::changeListenerCallback(juce::ChangeBroadcaster* source paletteEditingIsNew = false; paletteEditPanel = nullptr; } - + else if (source == &colourToolTabs->getTabbedButtonBar()) { const int newTab = colourToolTabs->getCurrentTabIndex(); - // TerpstraSysExApplication::getApp().getPropertiesFile()->setValue("LastColourPopupTabIndex", newTab); + getPropertiesFile()->setValue(LumatoneEditorProperty::LastColourWindowTab, juce::String(newTab)); } } diff --git a/Source/lumatone_editor_library/palettes/colour_palette_window.h b/Source/ColourPaletteWindow.h similarity index 83% rename from Source/lumatone_editor_library/palettes/colour_palette_window.h rename to Source/ColourPaletteWindow.h index 08dac39c..2b24bd11 100644 --- a/Source/lumatone_editor_library/palettes/colour_palette_window.h +++ b/Source/ColourPaletteWindow.h @@ -10,14 +10,14 @@ #pragma once -#include -// #include "LumatoneEditorStyleCommon.h" - -#include "./colour_selection_group.h" -#include "./colour_palette_file.h" +#include "./lumatone_editor_library/palettes/colour_selection_group.h" +#include "./lumatone_editor_library/palettes/colour_palette_file.h" #include "./palette_selection_panel.h" +#include "./LumatoneEditorState.h" + +class ColourSelectionGroup; class ColourPaletteComponent; class CustomPickerPanel; @@ -26,12 +26,13 @@ class PaletteEditPanel; //============================================================================== /* */ -class ColourPaletteWindow : public juce::Component, - public juce::ChangeListener, - public ColourPalettesPanel::Listener +class ColourPaletteWindow : public juce::Component + , private LumatoneEditorStateController + , public juce::ChangeListener + , public ColourPalettesPanel::Listener { public: - ColourPaletteWindow(juce::Array& colourPalettesIn); + ColourPaletteWindow(const LumatoneEditorState& stateIn); ~ColourPaletteWindow() override; void resized() override; @@ -56,13 +57,13 @@ class ColourPaletteWindow : public juce::Component, /// Force a colour selector (added to the group) to be selected /// /// - void setCurrentColourSelector(ColourSelectionBroadcaster* newSelector) - { + void setCurrentColourSelector(ColourSelectionBroadcaster* newSelector) + { // This statement is kind of a kludge - vsicurella if (colourSelectorGroup->getIndexOfSelector(newSelector) < 0) colourSelectorGroup->addSelector(newSelector); - colourSelectorGroup->setCurrentSelector(newSelector); + colourSelectorGroup->setCurrentSelector(newSelector); } private: @@ -96,10 +97,10 @@ class ColourPaletteWindow : public juce::Component, void newPaletteRequested() override; private: - + // LumatoneEditorLookAndFeel lookAndFeel; - juce::Array& colourPalettes; + //juce::Array& colourPalettes; std::unique_ptr colourToolTabs; std::unique_ptr palettePanel; diff --git a/Source/GlobalSettingsArea.h b/Source/GlobalSettingsArea.h index fbbd918d..15a97ad9 100644 --- a/Source/GlobalSettingsArea.h +++ b/Source/GlobalSettingsArea.h @@ -25,7 +25,7 @@ #include "./LumatoneEditorState.h" #include "./lumatone_editor_library/listeners/status_listener.h" -#include "./lumatone_editor_library/palettes/colour_view_component.h" +#include "./colour_view_component.h" //[/Headers] diff --git a/Source/IsomorphicMassAssign.cpp b/Source/IsomorphicMassAssign.cpp index f38db156..1be0451b 100644 --- a/Source/IsomorphicMassAssign.cpp +++ b/Source/IsomorphicMassAssign.cpp @@ -22,7 +22,7 @@ #include "./lumatone_editor_library/graphics/view_constants.h" #include "./lumatone_editor_library/device/lumatone_controller.h" -#include "./lumatone_editor_library/palettes/colour_palette_component.h" +#include "./colour_palette_component.h" //[/Headers] @@ -733,7 +733,8 @@ void IsomorphicMassAssign::colourChangedCallback(ColourSelectionBroadcaster* sou colourTable = newColours; } - mappingLogic->setColourTable(colourTable); + if (mappingLogic) + mappingLogic->setColourTable(colourTable); } } diff --git a/Source/NoteEditArea.cpp b/Source/NoteEditArea.cpp index 087fbf58..6481f0ee 100644 --- a/Source/NoteEditArea.cpp +++ b/Source/NoteEditArea.cpp @@ -27,7 +27,7 @@ #include "./lumatone_editor_library/graphics/view_constants.h" #include "MainComponent.h" -#include "./lumatone_editor_library/palettes/colour_view_component.h" +#include "./colour_view_component.h" //[/Headers] #include "NoteEditArea.h" diff --git a/Source/SingleNoteAssign.cpp b/Source/SingleNoteAssign.cpp index 29474449..f803ad49 100644 --- a/Source/SingleNoteAssign.cpp +++ b/Source/SingleNoteAssign.cpp @@ -19,8 +19,8 @@ //[Headers] You can add your own extra header files here... #include "./lumatone_editor_library/actions/edit_actions.h" -#include "./lumatone_editor_library/palettes/colour_view_component.h" #include "./lumatone_editor_library/palettes/colour_edit_textbox.h" +#include "./colour_view_component.h" #include "LumatoneEditorLookAndFeel.h" //[/Headers] diff --git a/Source/lumatone_editor_library/palettes/colour_palette_component.cpp b/Source/colour_palette_component.cpp similarity index 98% rename from Source/lumatone_editor_library/palettes/colour_palette_component.cpp rename to Source/colour_palette_component.cpp index 207a9865..59b80298 100644 --- a/Source/lumatone_editor_library/palettes/colour_palette_component.cpp +++ b/Source/colour_palette_component.cpp @@ -10,7 +10,7 @@ #include #include "colour_palette_component.h" -#include "../graphics/lumatone_assets.h" +#include "lumatone_editor_library/graphics/lumatone_assets.h" //============================================================================== // ColourPaletteComponent Definitions diff --git a/Source/lumatone_editor_library/palettes/colour_palette_component.h b/Source/colour_palette_component.h similarity index 91% rename from Source/lumatone_editor_library/palettes/colour_palette_component.h rename to Source/colour_palette_component.h index 831fe6fd..22815545 100644 --- a/Source/lumatone_editor_library/palettes/colour_palette_component.h +++ b/Source/colour_palette_component.h @@ -12,10 +12,10 @@ #include -#include "./hex_group_palette.h" -#include "./colour_selection_broadcaster.h" +#include "./lumatone_editor_library/palettes/hex_group_palette.h" +#include "./lumatone_editor_library/palettes/colour_selection_broadcaster.h" -#include "./colour_palette_file.h" +#include "./lumatone_editor_library/palettes/colour_palette_file.h" // #include "LumatoneEditorStyleCommon.h" diff --git a/Source/lumatone_editor_library/palettes/colour_view_component.cpp b/Source/colour_view_component.cpp similarity index 99% rename from Source/lumatone_editor_library/palettes/colour_view_component.cpp rename to Source/colour_view_component.cpp index e9151fc0..37ac2973 100644 --- a/Source/lumatone_editor_library/palettes/colour_view_component.cpp +++ b/Source/colour_view_component.cpp @@ -18,7 +18,7 @@ */ //[Headers] You can add your own extra header files here... -#include "../graphics/view_constants.h" +#include "./lumatone_editor_library/graphics/view_constants.h" //[/Headers] #include "colour_view_component.h" @@ -311,4 +311,3 @@ END_JUCER_METADATA //[EndFile] You can add extra defines here... //[/EndFile] - diff --git a/Source/lumatone_editor_library/palettes/colour_view_component.h b/Source/colour_view_component.h similarity index 98% rename from Source/lumatone_editor_library/palettes/colour_view_component.h rename to Source/colour_view_component.h index a6ee105d..918eda5f 100644 --- a/Source/lumatone_editor_library/palettes/colour_view_component.h +++ b/Source/colour_view_component.h @@ -20,8 +20,7 @@ #pragma once //[Headers] -- You can add your own extra header files here -- -#include -#include "colour_selection_group.h" +#include "./lumatone_editor_library/palettes/colour_selection_group.h" /* ============================================================================== @@ -137,4 +136,3 @@ class ColourViewComponent : public juce::Button, //[EndFile] You can add extra defines here... //[/EndFile] - diff --git a/Source/lumatone_editor_library/palettes/palette_edit_panel.h b/Source/palette_edit_panel.h similarity index 83% rename from Source/lumatone_editor_library/palettes/palette_edit_panel.h rename to Source/palette_edit_panel.h index 9b3bf1d6..8e156cce 100644 --- a/Source/lumatone_editor_library/palettes/palette_edit_panel.h +++ b/Source/palette_edit_panel.h @@ -11,21 +11,26 @@ #ifndef LUMATONE_PALETTE_EDIT_PANEL_H #define LUMATONE_PALETTE_EDIT_PANEL_H + #include "./colour_palette_component.h" +#include "LumatoneEditorLookAndFeel.h" +#include "LumatoneEditorState.h" //============================================================================== /* * Colour palette edtior panel */ class PaletteEditPanel : public juce::Component + , private LumatoneEditorState , public juce::Button::Listener , public juce::Label::Listener , public juce::ChangeBroadcaster { public: - PaletteEditPanel(const LumatoneEditorColourPalette& paletteIn) - : colourPalette(paletteIn) + PaletteEditPanel(const LumatoneEditorState& stateIn, const LumatoneEditorColourPalette& paletteIn) + : LumatoneEditorState("PaletteEditPanel", stateIn) + , colourPalette(paletteIn) { colourPicker.reset(new juce::ColourSelector( juce::ColourSelector::ColourSelectorOptions::editableColour @@ -49,7 +54,7 @@ class PaletteEditPanel : public juce::Component paletteNameEditor->addListener(this); paletteNameEditor->setColour(juce::Label::ColourIds::backgroundColourId, juce::Colour()); paletteNameEditor->setText(colourPalette.getName(), juce::dontSendNotification); - // paletteNameEditor->getProperties().set(LumatoneEditorStyleIDs::labelMaximumLineCount, 3); + paletteNameEditor->getProperties().set(LumatoneEditorStyleIDs::labelMaximumLineCount, 3); addAndMakeVisible(*paletteNameEditor); labelTextChanged(paletteNameEditor.get()); // force update @@ -82,7 +87,7 @@ class PaletteEditPanel : public juce::Component auto labelText = editPaletteLabel->getText() + " "; int labelWidth = editPaletteLabel->getFont().getStringWidth(labelText); - // resizeLabelWithHeight(editPaletteLabel.get(), proportionOfHeight(editPaletteHeight)); + resizeLabelWithHeight(editPaletteLabel.get(), proportionOfHeight(editPaletteHeight)); editPaletteLabel->setSize(labelWidth, proportionOfHeight(editPaletteHeight)); editPaletteLabel->setCentrePosition(leftCenter, juce::roundToInt(editPaletteLabel->getHeight() * 0.5f + proportionOfHeight(editPaletteLabelY))); @@ -103,27 +108,14 @@ class PaletteEditPanel : public juce::Component juce::Point(juce::roundToInt(leftMargin), paletteControl->getBottom()), juce::Point(colourPicker->getX() - leftMargin, saveButton->getY()) )); - // paletteNameEditor->getProperties().set(LumatoneEditorStyleIDs::fontHeightScalar, editPaletteLabel->getHeight() / (float)paletteNameEditor->getHeight()); - - //if (lookAndFeel) - //{ - // Font labelFont = (paletteUnnamed) - // ? lookAndFeel->getAppFont(LumatoneEditorFont::UniviaProBold) - // : lookAndFeel->getAppFont(LumatoneEditorFont::GothamNarrowMedium); - - // paletteNameEditor->setFont(labelFont); - //} + paletteNameEditor->getProperties().set(LumatoneEditorStyleIDs::fontHeightScalar, editPaletteLabel->getHeight() / (float)paletteNameEditor->getHeight()); + juce::Font labelFont = (paletteUnnamed) + ? getAppFonts().getFont(LumatoneEditorFont::UniviaProBold) + : getAppFonts().getFont(LumatoneEditorFont::GothamNarrowMedium); + paletteNameEditor->setFont(labelFont); } - // void lookAndFeelChanged() override - // { - // lookAndFeel = dynamic_cast(&getLookAndFeel()); - // if (lookAndFeel) - // { - // } - // } - //============================================================================== void buttonClicked(juce::Button* btn) override @@ -149,8 +141,8 @@ class PaletteEditPanel : public juce::Component { paletteUnnamed = false; colourPalette.setName(paletteNameEditor->getText()); - // paletteNameEditor->getProperties().remove(LumatoneEditorStyleIDs::fontOverrideTypefaceStyle); - // paletteNameEditor->getProperties().set(LumatoneEditorStyleIDs::fontOverride, LumatoneEditorFont::GothamNarrowMedium); + paletteNameEditor->getProperties().remove(LumatoneEditorStyleIDs::fontOverrideTypefaceStyle); + paletteNameEditor->getProperties().set(LumatoneEditorStyleIDs::fontOverride, LumatoneEditorFont::GothamNarrowMedium); } else if (nameIsEmpty && !paletteUnnamed) @@ -161,8 +153,8 @@ class PaletteEditPanel : public juce::Component if (paletteUnnamed) { paletteNameEditor->setText("unnamed", juce::NotificationType::dontSendNotification); - // paletteNameEditor->getProperties().set(LumatoneEditorStyleIDs::fontOverrideTypefaceStyle, "Italic"); - // paletteNameEditor->getProperties().remove(LumatoneEditorStyleIDs::fontOverride); + paletteNameEditor->getProperties().set(LumatoneEditorStyleIDs::fontOverrideTypefaceStyle, "Italic"); + paletteNameEditor->getProperties().remove(LumatoneEditorStyleIDs::fontOverride); } //resized(); @@ -211,8 +203,6 @@ class PaletteEditPanel : public juce::Component std::unique_ptr saveButton; std::unique_ptr cancelButton; - // LumatoneEditorLookAndFeel* lookAndFeel = nullptr; - bool saveRequested = false; bool paletteUnnamed = false; diff --git a/Source/lumatone_editor_library/palettes/palette_selection_panel.h b/Source/palette_selection_panel.h similarity index 98% rename from Source/lumatone_editor_library/palettes/palette_selection_panel.h rename to Source/palette_selection_panel.h index 054511d7..4fbb86f7 100644 --- a/Source/lumatone_editor_library/palettes/palette_selection_panel.h +++ b/Source/palette_selection_panel.h @@ -32,7 +32,7 @@ class ColourPalettesPanel : public juce::Component newPaletteBtn->setButtonText(juce::translate("NewPalette")); // newPaletteBtn->getProperties().set(LumatoneEditorStyleIDs::textButtonHyperlinkFlag, 1); newPaletteBtn->onClick = [&] { listeners.call(&ColourPalettesPanel::Listener::newPaletteRequested); }; - + }; ~ColourPalettesPanel() @@ -62,9 +62,9 @@ class ColourPalettesPanel : public juce::Component return height; } - void paint(juce::Graphics& g) override + void paint(juce::Graphics& g) override { - //Draws rectangles around items and margins + //Draws rectangles around items and margins //for (auto item : dbgItems) //{ // g.setColour(Colours::red); @@ -101,7 +101,7 @@ class ColourPalettesPanel : public juce::Component } flexBox.performLayout(viewportBounds); - + float bottomMarginControlHeight = juce::roundToInt(viewportBounds.proportionOfWidth(btmMarginCtrlScalar)); float bottomMarginControlSpace = (bottomMargin - bottomMarginControlHeight) * 0.5f; @@ -185,7 +185,7 @@ class ColourPalettesPanel : public juce::Component controlGroups.clear(); paletteLabels.clear(); - + allPalettes = juce::Array(newPalette.get()); // Palettes with colour diff --git a/TerpstraSysEx.jucer b/TerpstraSysEx.jucer index 721ca126..15af6920 100644 --- a/TerpstraSysEx.jucer +++ b/TerpstraSysEx.jucer @@ -278,35 +278,19 @@ file="Source/lumatone_editor_library/palettes/colour_edit_textbox.cpp"/> - - - - - - - - @@ -389,6 +373,22 @@ + + + + + + + +