Skip to content

Commit

Permalink
improve editor state construction
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed Jun 13, 2024
1 parent d18c35a commit 216e4b4
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 44 deletions.
69 changes: 55 additions & 14 deletions Source/LumatoneEditorState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "LumatoneEditorState.h"

#include "./LumatoneEditorLookAndFeel.h"
#include "./KeyEditComponent.h"

#include "./lumatone_editor_library/device/lumatone_controller.h"
#include "./lumatone_editor_library/listeners/editor_listener.h"
Expand Down Expand Up @@ -48,9 +47,9 @@ juce::Array<juce::Identifier> GetLumatoneEditorProperty()
return properties;
}


LumatoneEditorState::LumatoneEditorState(juce::String name, LumatoneFirmwareDriver& driverIn, juce::UndoManager *undoManagerIn)
: LumatoneApplicationState("LumatoneEditor", driverIn, juce::ValueTree(), undoManagerIn)
LumatoneEditorState::LumatoneEditorState(juce::ValueTree stateIn, LumatoneFirmwareDriver &driverIn, juce::UndoManager *undoManagerIn)
: LumatoneApplicationState(stateIn, driverIn, undoManagerIn)
, editSelectionState(name + "_EditSelection", state)
{
appFonts = std::make_shared<LumatoneEditorFontLibrary>();
lookAndFeel = std::make_shared<LumatoneEditorLookAndFeel>(*appFonts, true);
Expand All @@ -62,6 +61,7 @@ LumatoneEditorState::LumatoneEditorState(juce::String name, LumatoneFirmwareDriv

LumatoneEditorState::LumatoneEditorState(juce::String name, const LumatoneEditorState &stateIn)
: LumatoneApplicationState(name, stateIn)
, editSelectionState(name, state)
, appFonts(stateIn.appFonts)
, lookAndFeel(stateIn.lookAndFeel)
, recentFiles(stateIn.recentFiles)
Expand All @@ -70,8 +70,16 @@ LumatoneEditorState::LumatoneEditorState(juce::String name, const LumatoneEditor
{
}

LumatoneEditorState::LumatoneEditorState(const LumatoneEditorState &stateIn)
: LumatoneEditorState(stateIn.name + "Copy", stateIn)
{
}

LumatoneEditorState::~LumatoneEditorState()
{
if (name == LumatoneEditorProperty::StateTree.toString())
DBG(state.toXmlString());

recentFiles = nullptr;
propertiesFile = nullptr;
lookAndFeel = nullptr;
Expand All @@ -93,7 +101,12 @@ juce::RecentlyOpenedFilesList& LumatoneEditorState::getRecentFiles()
return *recentFiles;
}

const juce::Array<LumatoneEditorColourPalette>& LumatoneEditorState::getColourPalettes()
LumatoneEditSelectionState::Data LumatoneEditorState::getEditSelectionData() const
{
return editSelectionState.getData();
}

const juce::Array<LumatoneEditorColourPalette> &LumatoneEditorState::getColourPalettes()
{
return *colourPalettes;
}
Expand Down Expand Up @@ -181,6 +194,31 @@ void LumatoneEditorState::Controller::setEditMode(EditorMode editMode)
editorState.setStateProperty(LumatoneEditorProperty::EditorMode, (int)editorState.editorMode);
}

void LumatoneEditorState::Controller::setAssignKeyColour(bool set, juce::Colour colourIn)
{
editorState.editSelectionState.setKeyColour(set, colourIn);
}

void LumatoneEditorState::Controller::setAssignKeyType(bool set, LumatoneKeyType typeIn)
{
editorState.editSelectionState.setKeyType(set, typeIn);
}

void LumatoneEditorState::Controller::setAssignKeyNote(bool set, int noteIn)
{
editorState.editSelectionState.setKeyNote(set, noteIn);
}

void LumatoneEditorState::Controller::setAssignKeyChannel(bool set, int channelIn)
{
editorState.editSelectionState.setKeyChannel(set, channelIn);
}

void LumatoneEditorState::Controller::setAssignCCFader(bool set, bool ccFaderDefaultIn)
{
editorState.editSelectionState.setCCFader(set, ccFaderDefaultIn);
}

void LumatoneEditorState::Controller::setWindowState(const juce::Rectangle<int> &windowBounds, juce::String stateString)
{
editorState.windowBounds = windowBounds;
Expand Down Expand Up @@ -210,6 +248,9 @@ juce::ValueTree LumatoneEditorState::loadStateProperties(juce::ValueTree stateIn

void LumatoneEditorState::handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier &property)
{
// DBG(name + " state changed");
// DBG(state.toXmlString());

LumatoneApplicationState::handleStatePropertyChange(stateIn, property);

if (property == LumatoneEditorProperty::MainWindowBounds)
Expand Down Expand Up @@ -276,16 +317,16 @@ void LumatoneEditorState::loadPropertiesFile(juce::PropertiesFile *propertiesIn)

setStateProperty(LumatoneEditorProperty::AutoConnectDevice, propertiesFile->getBoolValue(LumatoneEditorProperty::AutoConnectDevice.toString(), true));

setStateProperty(LumatoneEditorProperty::SingleNoteKeyTypeSetActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteKeyTypeSetActive.toString(), true));
setStateProperty(LumatoneEditorProperty::SingleNoteNoteSetActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteNoteSetActive.toString(), true));
setStateProperty(LumatoneEditorProperty::SingleNoteChannelSetActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteChannelSetActive.toString(), true));
setStateProperty(LumatoneEditorProperty::SingleNoteColourSetActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteColourSetActive.toString(), true));
setStateProperty(LumatoneEditorProperty::SingleNoteCCFaderIsDefault, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteCCFaderIsDefault.toString(), false));
setStateProperty(LumatoneEditorProperty::SingleNoteAutoIncNoteActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteAutoIncNoteActive.toString(), true));
setStateProperty(LumatoneEditorProperty::SingleNoteAutoIncChannelActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteAutoIncChannelActive.toString(), true));
setStateProperty(LumatoneEditorProperty::SingleNoteAutoIncChannelAfterNumNotes, propertiesFile->getIntValue(LumatoneEditorProperty::SingleNoteAutoIncChannelAfterNumNotes.toString(), 127));
// setStateProperty(LumatoneEditorProperty::SingleNoteKeyTypeSetActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteKeyTypeSetActive.toString(), true));
// setStateProperty(LumatoneEditorProperty::SingleNoteNoteSetActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteNoteSetActive.toString(), true));
// setStateProperty(LumatoneEditorProperty::SingleNoteChannelSetActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteChannelSetActive.toString(), true));
// setStateProperty(LumatoneEditorProperty::SingleNoteColourSetActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteColourSetActive.toString(), true));
// setStateProperty(LumatoneEditorProperty::SingleNoteCCFaderIsDefault, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteCCFaderIsDefault.toString(), false));
// setStateProperty(LumatoneEditorProperty::SingleNoteAutoIncNoteActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteAutoIncNoteActive.toString(), true));
// setStateProperty(LumatoneEditorProperty::SingleNoteAutoIncChannelActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteAutoIncChannelActive.toString(), true));
// setStateProperty(LumatoneEditorProperty::SingleNoteAutoIncChannelAfterNumNotes, propertiesFile->getIntValue(LumatoneEditorProperty::SingleNoteAutoIncChannelAfterNumNotes.toString(), 127));

setStateProperty(LumatoneEditorProperty::IsomorphicMassAssign, propertiesFile->getBoolValue(LumatoneEditorProperty::IsomorphicMassAssign.toString(), false));
// setStateProperty(LumatoneEditorProperty::IsomorphicMassAssign, propertiesFile->getBoolValue(LumatoneEditorProperty::IsomorphicMassAssign.toString(), false))

setStateProperty(LumatoneEditorProperty::LastSettingsPanel, propertiesFile->getIntValue(LumatoneEditorProperty::LastSettingsPanel.toString(), 1));
setStateProperty(LumatoneEditorProperty::LastColourWindowTab, propertiesFile->getIntValue(LumatoneEditorProperty::LastColourWindowTab.toString(), 1));
Expand Down
43 changes: 32 additions & 11 deletions Source/LumatoneEditorState.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "./lumatone_editor_library/data/application_state.h"
#include "./lumatone_editor_library/palettes/colour_palette_file.h"

#include "./data/LumatoneEditSelectionState.h"

#define CHOOSE_FILE_NOOP [](bool) -> void {}

struct LumatoneEditorFontLibrary;
Expand Down Expand Up @@ -50,16 +52,18 @@ namespace LumatoneEditorProperty

static const juce::Identifier EditorMode = juce::Identifier("EditorMode");

static const juce::Identifier SingleNoteNoteSetActive = juce::Identifier("SingleNoteNoteSetActive");
static const juce::Identifier SingleNoteChannelSetActive = juce::Identifier("SingleNoteChannelSetActive");
static const juce::Identifier SingleNoteColourSetActive = juce::Identifier("SingleNoteColourSetActive");
static const juce::Identifier SingleNoteKeyTypeSetActive = juce::Identifier("SingleNoteKeyTypeSetActive");
static const juce::Identifier SingleNoteAutoIncNoteActive = juce::Identifier("SingleNoteAutoIncNoteActive");
static const juce::Identifier SingleNoteAutoIncChannelActive = juce::Identifier("SingleNoteAutoIncChannelActive");
static const juce::Identifier SingleNoteAutoIncChannelAfterNumNotes = juce::Identifier("SingleNoteAutoIncChannelAfterNumNotes");
static const juce::Identifier SingleNoteCCFaderIsDefault = juce::Identifier("SingleNoteCCFaderIsDefault");
// static const juce::Identifier SingleNoteNoteSetActive = juce::Identifier("SingleNoteNoteSetActive");
// static const juce::Identifier SingleNoteChannelSetActive = juce::Identifier("SingleNoteChannelSetActive");
// static const juce::Identifier SingleNoteColourSetActive = juce::Identifier("SingleNoteColourSetActive");
// static const juce::Identifier SingleNoteKeyTypeSetActive = juce::Identifier("SingleNoteKeyTypeSetActive");
// static const juce::Identifier SingleNoteAutoIncNoteActive = juce::Identifier("SingleNoteAutoIncNoteActive");
// static const juce::Identifier SingleNoteAutoIncChannelActive = juce::Identifier("SingleNoteAutoIncChannelActive");
// static const juce::Identifier SingleNoteAutoIncChannelAfterNumNotes = juce::Identifier("SingleNoteAutoIncChannelAfterNumNotes");
// static const juce::Identifier SingleNoteCCFaderIsDefault = juce::Identifier("SingleNoteCCFaderIsDefault");

// static const juce::Identifier IsomorphicMassAssign = juce::Identifier("IsomorphicMassAssign");

static const juce::Identifier IsomorphicMassAssign = juce::Identifier("IsomorphicMassAssign");
static const juce::Identifier SelectedKeys = juce::Identifier("SelectedKeys");

static const juce::Identifier LastSettingsPanel = juce::Identifier("LastSettingsPanel");
static const juce::Identifier LastColourWindowTab = juce::Identifier("LastColourWindowTab");
Expand All @@ -77,8 +81,11 @@ static juce::Array<juce::Identifier> GetLumatoneEditorProperties();
class LumatoneEditorState : public LumatoneApplicationState
{
public:
LumatoneEditorState(juce::String name, LumatoneFirmwareDriver& driverIn, juce::UndoManager* undoManagerIn);
// Only for "top level" state instance
LumatoneEditorState(juce::ValueTree stateIn, LumatoneFirmwareDriver& driverIn, juce::UndoManager* undoManagerIn);

LumatoneEditorState(juce::String name, const LumatoneEditorState& stateIn);
LumatoneEditorState(const LumatoneEditorState& stateIn);

~LumatoneEditorState() override;

Expand All @@ -95,6 +102,10 @@ class LumatoneEditorState : public LumatoneApplicationState

EditorMode getEditorMode() const { return editorMode; }

juce::Array<LumatoneKey> getSelectedKeys() const;

LumatoneEditSelectionState::Data getEditSelectionData() const;

LumatoneEditorLookAndFeel& getEditorLookAndFeel() { return *lookAndFeel; }

virtual const juce::Array<LumatoneEditorColourPalette>& getColourPalettes();
Expand Down Expand Up @@ -134,6 +145,10 @@ class LumatoneEditorState : public LumatoneApplicationState

EditorMode editorMode = EditorMode::OFFLINE;

juce::Array<LumatoneKey> selectedKeys;

LumatoneEditSelectionState editSelectionState;

private:
std::shared_ptr<LumatoneEditorFontLibrary> appFonts;
std::shared_ptr<LumatoneEditorLookAndFeel> lookAndFeel;
Expand All @@ -148,7 +163,7 @@ class LumatoneEditorState : public LumatoneApplicationState

//================================================================================
public:
class Controller : protected LumatoneApplicationState::Controller
class Controller : public LumatoneApplicationState::Controller
{
public:
Controller(LumatoneEditorState& stateIn)
Expand Down Expand Up @@ -184,6 +199,12 @@ class LumatoneEditorState : public LumatoneApplicationState
void setDeveloperMode(bool developerModeOn);
void setEditMode(EditorMode editMode);

void setAssignKeyColour(bool set, juce::Colour colourIn);
void setAssignKeyType(bool set, LumatoneKeyType typeIn);
void setAssignKeyNote(bool set, int noteIn);
void setAssignKeyChannel(bool set, int channelIn);
void setAssignCCFader(bool set, bool ccFaderDefaultIn);

void setWindowState(const juce::Rectangle<int>& windowBounds, juce::String stateString);

private:
Expand Down
2 changes: 1 addition & 1 deletion Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

TerpstraSysExApplication::TerpstraSysExApplication()
: firmwareDriver(LumatoneFirmwareDriver::HostMode::Driver)
, state("LumatoneEditor", firmwareDriver, &undoManager)
, state(juce::ValueTree(LumatoneEditorProperty::StateTree), firmwareDriver, &undoManager)
, LumatoneEditorState::Controller(state)
{
// Localisation
Expand Down
40 changes: 26 additions & 14 deletions Source/data/LumatoneEditSelectionState.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "LumatoneEditSelectionState.h"
#include "../lumatone_editor_library/data/lumatone_layout.h"
#include "../LumatoneEditorState.h"

static juce::Array<juce::Identifier> getEditSelectionProperties()
{
Expand All @@ -11,23 +13,27 @@ static juce::Array<juce::Identifier> getEditSelectionProperties()
return properties;
}

LumatoneEditSelectionState::LumatoneEditSelectionState(juce::String nameIn)
: LumatoneStateBase(nameIn)
{
state = juce::ValueTree(LumatoneEditSelectionProperty::AssignKeyEdits);
}

LumatoneEditSelectionState::LumatoneEditSelectionState(juce::String nameIn, juce::ValueTree parentStateIn)
: LumatoneStateBase(nameIn)
{
state = juce::ValueTree(LumatoneEditSelectionProperty::AssignKeyEdits);
parentStateIn.addChild(state, -1, nullptr);
state = parentStateIn.getChildWithName(LumatoneEditSelectionProperty::AssignKeyEdits);

if (!state.isValid())
{
state = juce::ValueTree(LumatoneEditSelectionProperty::AssignKeyEdits);
parentStateIn.addChild(state, -1, nullptr);
}

state.addListener(this);
}

LumatoneEditSelectionState::LumatoneEditSelectionState(juce::String nameIn, juce::ValueTree parentStateIn, const LumatoneEditSelectionState &stateToCopy)
: LumatoneStateBase(nameIn)
{
state = loadStateProperties(stateToCopy.state.getChildWithName(LumatoneEditSelectionProperty::AssignKeyEdits));
juce::ValueTree stateData = stateToCopy.state.getChildWithName(LumatoneEditSelectionProperty::AssignKeyEdits);
state = loadStateProperties(stateData);
state.addListener(this);

parentStateIn.addChild(state, -1, nullptr);
}

Expand All @@ -47,6 +53,12 @@ juce::ValueTree LumatoneEditSelectionState::loadStateProperties(juce::ValueTree

void LumatoneEditSelectionState::handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier &property)
{
// DBG(name + " edit selection state changed");
// DBG(state.toXmlString());

if (stateIn != state)
return;

bool setProperty = stateIn.hasProperty(property);
juce::var value = stateIn.getProperty(property);

Expand Down Expand Up @@ -119,7 +131,7 @@ void LumatoneEditSelectionState::setKeyColour(bool set, juce::Colour colourIn)

if (set)
{
state.setProperty(LumatoneEditSelectionProperty::AssignKeyColour, colourIn.toString(), nullptr);
state.setPropertyExcludingListener(this, LumatoneEditSelectionProperty::AssignKeyColour, colourIn.toString(), nullptr);
}
else
{
Expand All @@ -134,7 +146,7 @@ void LumatoneEditSelectionState::setKeyType(bool set, LumatoneKeyType typeIn)

if (set)
{
state.setProperty(LumatoneEditSelectionProperty::AssignKeyType, juce::var((int)typeIn), nullptr);
state.setPropertyExcludingListener(this, LumatoneEditSelectionProperty::AssignKeyType, juce::var((int)typeIn), nullptr);
}
else
{
Expand All @@ -149,7 +161,7 @@ void LumatoneEditSelectionState::setKeyNote(bool set, int noteIn)

if (set)
{
state.setProperty(LumatoneEditSelectionProperty::AssignKeyNote, juce::var(noteIn), nullptr);
state.setPropertyExcludingListener(this, LumatoneEditSelectionProperty::AssignKeyNote, juce::var(noteIn), nullptr);
}
else
{
Expand All @@ -164,7 +176,7 @@ void LumatoneEditSelectionState::setKeyChannel(bool set, int channelIn)

if (set)
{
state.setProperty(LumatoneEditSelectionProperty::AssignKeyChannel, juce::var(channelIn), nullptr);
state.setPropertyExcludingListener(this, LumatoneEditSelectionProperty::AssignKeyChannel, juce::var(channelIn), nullptr);
}
else
{
Expand All @@ -179,7 +191,7 @@ void LumatoneEditSelectionState::setCCFader(bool set, bool ccFaderDefaultIn)

if (set)
{
state.setProperty(LumatoneEditSelectionProperty::AssignKeyCCFader, juce::var(ccFaderDefaultIn), nullptr);
state.setPropertyExcludingListener(this, LumatoneEditSelectionProperty::AssignKeyCCFader, juce::var(ccFaderDefaultIn), nullptr);
}
else
{
Expand Down
1 change: 0 additions & 1 deletion Source/data/LumatoneEditSelectionState.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class LumatoneEditSelectionState : public LumatoneStateBase

public:

LumatoneEditSelectionState(juce::String nameIn);
LumatoneEditSelectionState(juce::String nameIn, juce::ValueTree parentStateIn);
LumatoneEditSelectionState(juce::String nameIn, juce::ValueTree parentStateIn, const LumatoneEditSelectionState& stateToCopy);

Expand Down
2 changes: 1 addition & 1 deletion Source/mapping_editors/KeyEditorPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

KeyEditorPanel::KeyEditorPanel(const LumatoneEditorState &stateIn)
: juce::Component("KeyEditorPanel")
, LumatoneEditorState(stateIn)
, LumatoneEditorState("KeyEditorPanel", stateIn)
{
keyEditorControls = std::make_unique<KeyEditorControls>(stateIn);
addAndMakeVisible(keyEditorControls.get());
Expand Down
2 changes: 1 addition & 1 deletion Source/mapping_editors/MappingSettingsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

MappingSettingsPanel::MappingSettingsPanel(const LumatoneEditorState& stateIn)
: juce::Component("MappingSettingsPanel")
, LumatoneEditorState(stateIn)
, LumatoneEditorState("MappingSettingsPanel", stateIn)
{
settingsControls = std::make_unique<MappingSettingsControls>(stateIn);
addAndMakeVisible(settingsControls.get());
Expand Down
2 changes: 1 addition & 1 deletion Source/mapping_editors/MultiSelectControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "../lumatone_editor_library/palettes/colour_edit_textbox.h"

MultiSelectControls::MultiSelectControls(const LumatoneEditorState& stateIn)
: LumatoneEditorState(stateIn)
: LumatoneEditorState("MultiSelectControls", stateIn)
, juce::Component("MultiSelectControls")
{
lblMultiSelect = std::make_unique<juce::Label>("lblMultiSelect", "Multi-Select");
Expand Down

0 comments on commit 216e4b4

Please sign in to comment.