Skip to content

Commit

Permalink
fix developer mode callback and settings window
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed Jan 7, 2024
1 parent 66bc20e commit d7719d9
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 63 deletions.
10 changes: 1 addition & 9 deletions Source/GlobalSettingsArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion Source/LumatoneEditorState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -144,6 +146,7 @@ class LumatoneEditorState : public LumatoneApplicationState

EditorMode editorMode = EditorMode::OFFLINE;

private:
std::shared_ptr<LumatoneEditorFontLibrary> appFonts;
std::shared_ptr<LumatoneEditorLookAndFeel> lookAndFeel;
std::shared_ptr<juce::Array<LumatoneEditorColourPalette>> colourPalettes;
Expand Down
18 changes: 9 additions & 9 deletions Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion Source/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class TerpstraSysExApplication : public JUCEApplication

bool aboutTerpstraSysEx();

MainContentComponent* getMainContentComponent() const;
//MainContentComponent* getMainContentComponent() const;

private:
LumatoneFirmwareDriver firmwareDriver;
Expand Down
22 changes: 18 additions & 4 deletions Source/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
11 changes: 9 additions & 2 deletions Source/MainComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
67 changes: 34 additions & 33 deletions Source/Settings/SettingsContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,38 @@ 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);

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)
Expand All @@ -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)
{
Expand All @@ -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();
}
}
12 changes: 8 additions & 4 deletions Source/Settings/SettingsContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#pragma once
#include <JuceHeader.h>

#include "../LumatoneEditorState.h"

typedef enum {
Calibration = 0,
Firmware = 1,
Expand All @@ -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)
{
Expand All @@ -41,14 +43,16 @@ class SettingsCategoryModel : public ListBoxModel, public ChangeBroadcaster
//=========================================================================
private:
Array<String> 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();
Expand Down

0 comments on commit d7719d9

Please sign in to comment.