From d7719d9f5eecfa534551bafb893a77e5eea92a02 Mon Sep 17 00:00:00 2001 From: Vincenzo Sicurella Date: Sun, 7 Jan 2024 14:34:40 -0500 Subject: [PATCH] fix developer mode callback and settings window --- Source/GlobalSettingsArea.cpp | 10 +--- Source/LumatoneEditorState.h | 5 +- Source/Main.cpp | 18 +++---- Source/Main.h | 2 +- Source/MainComponent.cpp | 22 +++++++-- Source/MainComponent.h | 11 ++++- Source/Settings/SettingsContainer.cpp | 67 ++++++++++++++------------- Source/Settings/SettingsContainer.h | 12 +++-- 8 files changed, 84 insertions(+), 63 deletions(-) diff --git a/Source/GlobalSettingsArea.cpp b/Source/GlobalSettingsArea.cpp index 28fac7cf..6172adab 100644 --- a/Source/GlobalSettingsArea.cpp +++ b/Source/GlobalSettingsArea.cpp @@ -47,8 +47,6 @@ GlobalSettingsArea::GlobalSettingsArea (const LumatoneEditorState& stateIn) lblPresetButtonColours->setColour (juce::TextEditor::textColourId, juce::Colours::black); lblPresetButtonColours->setColour (juce::TextEditor::backgroundColourId, juce::Colour (0x00000000)); - lblPresetButtonColours->setBounds (0, 8, 150, 24); - lblColourInactiveMacroButton.reset (new juce::Label ("lblColourInactiveMacroButton", TRANS("inactive"))); addAndMakeVisible (lblColourInactiveMacroButton.get()); @@ -58,8 +56,6 @@ GlobalSettingsArea::GlobalSettingsArea (const LumatoneEditorState& stateIn) lblColourInactiveMacroButton->setColour (juce::TextEditor::textColourId, juce::Colours::black); lblColourInactiveMacroButton->setColour (juce::TextEditor::backgroundColourId, juce::Colour (0x00000000)); - lblColourInactiveMacroButton->setBounds (152, 32, 64, 24); - lblColourActiveMacroButton.reset (new juce::Label ("lblColourActiveMacroButton", TRANS("active"))); addAndMakeVisible (lblColourActiveMacroButton.get()); @@ -69,16 +65,12 @@ GlobalSettingsArea::GlobalSettingsArea (const LumatoneEditorState& stateIn) lblColourActiveMacroButton->setColour (juce::TextEditor::textColourId, juce::Colours::black); lblColourActiveMacroButton->setColour (juce::TextEditor::backgroundColourId, juce::Colour (0x00000000)); - lblColourActiveMacroButton->setBounds (152, 8, 56, 24); - buttonCalibrate.reset (new juce::TextButton ("buttonCalibrate")); addAndMakeVisible (buttonCalibrate.get()); buttonCalibrate->setTooltip (TRANS("Show controls for calibration, setting controller MIDI channels, and updating firmware")); buttonCalibrate->setButtonText (TRANS("Settings")); buttonCalibrate->addListener (this); - buttonCalibrate->setBounds (336, 8, 112, 24); - //[UserPreSize] activeMacroButtonColourEdit.reset(new ColourViewComponent()); @@ -197,7 +189,7 @@ void GlobalSettingsArea::buttonClicked (juce::Button* buttonThatWasClicked) { //[UserButtonCode_buttonCalibrate] -- add your button handler code here.. - auto settingsComponent = new SettingsContainer(); + auto settingsComponent = new SettingsContainer(*this); settingsComponent->setLookAndFeel(&getLookAndFeel()); DialogWindow::LaunchOptions launchOptions; diff --git a/Source/LumatoneEditorState.h b/Source/LumatoneEditorState.h index 55cd3ea6..47a7362a 100644 --- a/Source/LumatoneEditorState.h +++ b/Source/LumatoneEditorState.h @@ -55,6 +55,8 @@ namespace LumatoneEditorProperty static const juce::Identifier SingleNoteColourSetActive = juce::Identifier("SingleNoteColourSetActive"); static const juce::Identifier SingleNoteKeyTypeSetActive = juce::Identifier("SingleNoteKeyTypeSetActive"); + static const juce::Identifier LastSettingsPanel = juce::Identifier("LastSettingsPanel"); + } enum class EditorMode @@ -135,7 +137,7 @@ class LumatoneEditorState : public LumatoneApplicationState void setCalibrationMode(bool calibrationModeOn); void setDeveloperMode(bool developerModeOn); -private: +protected: bool hasChangesToSave = false; bool hasChangesToSend = false; bool inCalibrationMode = false; @@ -144,6 +146,7 @@ class LumatoneEditorState : public LumatoneApplicationState EditorMode editorMode = EditorMode::OFFLINE; +private: std::shared_ptr appFonts; std::shared_ptr lookAndFeel; std::shared_ptr> colourPalettes; diff --git a/Source/Main.cpp b/Source/Main.cpp index 9f57e400..f3f9d81a 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -29,12 +29,12 @@ #include "LumatoneMenu.h" //============================================================================== - -MainContentComponent* TerpstraSysExApplication::getMainContentComponent() const -{ - jassert(mainWindow != nullptr); - return (MainContentComponent*)(mainWindow->getContentComponent()); -} +// +//MainContentComponent* TerpstraSysExApplication::getMainContentComponent() const +//{ +// jassert(mainWindow != nullptr); +// return (MainContentComponent*)(mainWindow->getContentComponent()); +//} TerpstraSysExApplication::TerpstraSysExApplication() : firmwareDriver(LumatoneFirmwareDriver::HostMode::Driver) @@ -513,7 +513,7 @@ bool TerpstraSysExApplication::pasteModifiedSubBoardData(CommandID commandID) bool TerpstraSysExApplication::canPasteSubBoardData() const { if (mainWindow != nullptr) - return getMainContentComponent()->canPasteCopiedSubBoard(); + return ((MainContentComponent*)(mainWindow->getContentComponent()))->canPasteCopiedSubBoard(); return false; } @@ -562,7 +562,7 @@ bool TerpstraSysExApplication::redo() bool TerpstraSysExApplication::toggleDeveloperMode() { state.setDeveloperMode(!state.getInDeveloperMode()); - return state.getInDeveloperMode(); + return true; // bool newMode = !propertiesFile->getBoolValue("DeveloperMode"); // propertiesFile->setValue("DeveloperMode", newMode); // return ((MainContentComponent*)(mainWindow->getContentComponent()))->state.setDeveloperMode(newMode); @@ -726,7 +726,7 @@ bool TerpstraSysExApplication::requestConfigurationFromDevice() void TerpstraSysExApplication::updateMainTitle() { String windowTitle("Lumatone Editor"); - + if (!state.getCurrentFile().getFileName().isEmpty()) windowTitle << " - " << state.getCurrentFile().getFileName(); if (state.getHasChangesToSave()) diff --git a/Source/Main.h b/Source/Main.h index 33afe844..95791a10 100644 --- a/Source/Main.h +++ b/Source/Main.h @@ -86,7 +86,7 @@ class TerpstraSysExApplication : public JUCEApplication bool aboutTerpstraSysEx(); - MainContentComponent* getMainContentComponent() const; + //MainContentComponent* getMainContentComponent() const; private: LumatoneFirmwareDriver firmwareDriver; diff --git a/Source/MainComponent.cpp b/Source/MainComponent.cpp index 50f6673e..c9131d14 100644 --- a/Source/MainComponent.cpp +++ b/Source/MainComponent.cpp @@ -270,11 +270,11 @@ bool MainContentComponent::canPasteCopiedSubBoard() const return !copiedSubBoardData->isEmpty(); } -bool MainContentComponent::setDeveloperMode(bool developerModeOn) +void MainContentComponent::updateDeveloperMode() { - curvesArea->setDeveloperMode(developerModeOn); - globalSettingsArea->setDeveloperMode(developerModeOn); - return true; + // TODO This can just be implemented individually in handleStatePropertyChange + curvesArea->setDeveloperMode(inDeveloperMode); + globalSettingsArea->setDeveloperMode(inDeveloperMode); } void MainContentComponent::connectionStateChanged(ConnectionState state) @@ -525,3 +525,17 @@ void MainContentComponent::refreshAllFields() curvesArea->loadFromMapping(); curvesArea->repaint(); } + + +void MainContentComponent::handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property) +{ + if (property == LumatoneEditorProperty::DeveloperModeOn) + { + inDeveloperMode = (bool)stateIn[property]; + updateDeveloperMode(); + } + else + { + LumatoneApplicationState::handleStatePropertyChange(stateIn, property); + } +} diff --git a/Source/MainComponent.h b/Source/MainComponent.h index a615bba1..4e1af393 100644 --- a/Source/MainComponent.h +++ b/Source/MainComponent.h @@ -63,8 +63,6 @@ class MainContentComponent : public juce::Component juce::UndoableAction* createModifiedPasteCurrentSectionAction(CommandID commandID); bool canPasteCopiedSubBoard() const; - bool setDeveloperMode(bool developerModeOn); - // Implementation of ChangeListener void changeListenerCallback(juce::ChangeBroadcaster *source) override; @@ -105,6 +103,15 @@ class MainContentComponent : public juce::Component void firmwareRevisionReceived(LumatoneFirmware::Version version) override; + // Implementation of LumatoneState + void handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property) override; + + +private: + + void updateDeveloperMode(); + + private: //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainContentComponent) diff --git a/Source/Settings/SettingsContainer.cpp b/Source/Settings/SettingsContainer.cpp index 7d88b5f0..b08b6220 100644 --- a/Source/Settings/SettingsContainer.cpp +++ b/Source/Settings/SettingsContainer.cpp @@ -29,21 +29,23 @@ void SettingsCategoryModel::paintListBoxItem(int rowNumber, juce::Graphics& g, i } g.setColour(Colours::white); - // TODO - // g.setFont(getAppFonts().getFont(LumatoneEditorFont::GothamNarrowMedium, height)); + + g.setFont(font.withHeight(height)); g.drawFittedText(categories[rowNumber], rowBounds.withLeft(8), juce::Justification::left, 1, 1.0f); } //========================================================================= -SettingsContainer::SettingsContainer() - : Component("SettingsContainer"), - model({ +SettingsContainer::SettingsContainer(const LumatoneEditorState& stateIn) + : Component("SettingsContainer") + , LumatoneEditorState("SettingsContainer", stateIn) + , model({ translate("Calibrate"), translate("Firmware"), translate("MIDI"), translate("Presets") - }) + }, stateIn.getAppFonts().getFont(LumatoneEditorFont::GothamNarrowMedium) + ) { categoryList.reset(new juce::ListBox("CategoryList")); categoryList->setModel(&model); @@ -51,15 +53,14 @@ SettingsContainer::SettingsContainer() addAndMakeVisible(categoryList.get()); model.addChangeListener(this); - // auto lastPanelIndex = TerpstraSysExApplication::getApp().getPropertiesFile()->getIntValue("LastSettingsPanel", 0); - // categoryList->selectRow(lastPanelIndex); + auto lastPanelIndex = (int)getProperty(LumatoneEditorProperty::LastSettingsPanel); + categoryList->selectRow(lastPanelIndex); } SettingsContainer::~SettingsContainer() { settingsPanel = nullptr; categoryList = nullptr; - } void SettingsContainer::paint(Graphics& g) @@ -79,8 +80,8 @@ void SettingsContainer::resized() void SettingsContainer::lookAndFeelChanged() { - //setColour(juce::ResizableWindow::ColourIds::backgroundColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::LightBackground)); - //categoryList->setColour(juce::ListBox::ColourIds::backgroundColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::MediumBackground)); + setColour(juce::ResizableWindow::ColourIds::backgroundColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::LightBackground)); + categoryList->setColour(juce::ListBox::ColourIds::backgroundColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::MediumBackground)); } void SettingsContainer::changeListenerCallback(ChangeBroadcaster* source) { @@ -90,36 +91,36 @@ void SettingsContainer::changeListenerCallback(ChangeBroadcaster* source) void SettingsContainer::showPanel(int editorSettingCategory) { - // TODO - juce:: Component* newPanel = nullptr; - // switch (editorSettingCategory) - // { - // case LumatoneEditorSettingCategories::Calibration: - // newPanel = new CalibrationDlg(); - // break; - - // case LumatoneEditorSettingCategories::Firmware: - // newPanel = new FirmwareDlg(); - // break; - - // case LumatoneEditorSettingCategories::Midi: - // newPanel = new MidiSettingsDlg(); - // break; - - // case LumatoneEditorSettingCategories::Presets: - // newPanel = new PresetSettingsDlg(); - // break; - // } + juce:: Component* newPanel = nullptr; + switch (editorSettingCategory) + { + case LumatoneEditorSettingCategories::Calibration: + newPanel = new CalibrationDlg(*this); + break; + + case LumatoneEditorSettingCategories::Firmware: + newPanel = new FirmwareDlg(*this); + break; + + case LumatoneEditorSettingCategories::Midi: + newPanel = new MidiSettingsDlg(*this); + break; + + case LumatoneEditorSettingCategories::Presets: + newPanel = new PresetSettingsDlg(*this); + break; + } if (newPanel) { - // TerpstraSysExApplication::getApp().getPropertiesFile()->setValue("LastSettingsPanel", editorSettingCategory); - removeChildComponent(settingsPanel.get()); settingsPanel = nullptr; settingsPanel.reset(std::move(newPanel)); addAndMakeVisible(settingsPanel.get()); settingsPanel->setLookAndFeel(&getLookAndFeel()); + + state.setPropertyExcludingListener(this, LumatoneEditorProperty::LastSettingsPanel, editorSettingCategory, nullptr); + resized(); } } diff --git a/Source/Settings/SettingsContainer.h b/Source/Settings/SettingsContainer.h index 9568563d..7fc6ff02 100644 --- a/Source/Settings/SettingsContainer.h +++ b/Source/Settings/SettingsContainer.h @@ -11,6 +11,8 @@ #pragma once #include +#include "../LumatoneEditorState.h" + typedef enum { Calibration = 0, Firmware = 1, @@ -22,7 +24,7 @@ class SettingsCategoryModel : public ListBoxModel, public ChangeBroadcaster { public: - SettingsCategoryModel(StringArray categoryNamesIn) + SettingsCategoryModel(StringArray categoryNamesIn, juce::Font fontIn) : font(fontIn) { for (auto name : categoryNamesIn) { @@ -41,14 +43,16 @@ class SettingsCategoryModel : public ListBoxModel, public ChangeBroadcaster //========================================================================= private: Array categories; - + juce::Font font; }; -class SettingsContainer : public Component, protected ChangeListener +class SettingsContainer : public Component + , private LumatoneEditorState + , protected ChangeListener { public: - SettingsContainer(); + SettingsContainer(const LumatoneEditorState& stateIn); // Send change signal when destructed ~SettingsContainer();