Skip to content

Commit

Permalink
improve app/layout state construction, fix inherited state listening
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed Jun 13, 2024
1 parent a868422 commit d18c35a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 54 deletions.
30 changes: 15 additions & 15 deletions Source/lumatone_editor_library/data/application_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ juce::Array<juce::Identifier> getLumatoneApplicationProperties()
return properties;
}

LumatoneApplicationState::LumatoneApplicationState(juce::String nameIn, LumatoneFirmwareDriver& driverIn, juce::ValueTree stateIn, juce::UndoManager *undoManagerIn)
: LumatoneState(nameIn, stateIn, undoManagerIn)
LumatoneApplicationState::LumatoneApplicationState(juce::ValueTree stateIn, LumatoneFirmwareDriver& driverIn, juce::UndoManager *undoManagerIn)
: LumatoneState(stateIn, undoManagerIn)
, firmwareDriver(driverIn)
{
editorListeners = std::make_shared<juce::ListenerList<LumatoneEditor::EditorListener>>();
Expand All @@ -37,14 +37,6 @@ LumatoneApplicationState::LumatoneApplicationState(juce::String nameIn, Lumatone
loadStateProperties(stateIn);
}

// LumatoneApplicationState::LumatoneApplicationState(juce::String nameIn, const LumatoneState &stateIn, juce::UndoManager *undoManagerIn)
// : LumatoneState(nameIn, stateIn, undoManagerIn)
// {
// colourModel = std::make_shared<LumatoneColourModel>();
// layoutContext = std::make_shared<LumatoneContext>(*mappingData);
// loadStateProperties(state);
// }

LumatoneApplicationState::LumatoneApplicationState(juce::String nameIn, const LumatoneApplicationState &stateIn)
: LumatoneState(nameIn, (const LumatoneState&)stateIn)
, firmwareDriver(stateIn.firmwareDriver)
Expand All @@ -60,6 +52,11 @@ LumatoneApplicationState::LumatoneApplicationState(juce::String nameIn, const Lu
loadStateProperties(state);
}

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

LumatoneApplicationState::~LumatoneApplicationState()
{
layoutContext = nullptr;
Expand Down Expand Up @@ -158,9 +155,11 @@ void LumatoneApplicationState::setActiveMacroButtonColour(juce::Colour buttonCol

juce::ValueTree LumatoneApplicationState::loadStateProperties(juce::ValueTree stateIn)
{
juce::ValueTree newState = (stateIn.hasType(LumatoneStateProperty::StateTree))
juce::ValueTree newState = (stateIn.hasType(LumatoneStateProperty::LumatoneState))
? stateIn
: juce::ValueTree(LumatoneStateProperty::StateTree);
: juce::ValueTree(LumatoneStateProperty::LumatoneState);

LumatoneState::loadStateProperties(newState);

// DBG("LumatoneApplicationState::loadStateProperties:\n" + newState.toXmlString());
for (auto property : getLumatoneApplicationProperties())
Expand All @@ -169,7 +168,8 @@ juce::ValueTree LumatoneApplicationState::loadStateProperties(juce::ValueTree st
handleStatePropertyChange(newState, property);
}

LumatoneState::loadStateProperties(newState);
// if (name.contains("Copy"))
// DBG(juce::String("Loaded ") + name + juce::String(" properties"));

return newState;
}
Expand Down Expand Up @@ -378,7 +378,7 @@ void LumatoneApplicationState::setInvertExpression(bool invert)
void LumatoneApplicationState::setInvertSustain(bool invert)
{
LumatoneState::setInvertSustain(invert);

if (doSendChangesToDevice())
{
controller->invertSustainPedal(invert);
Expand Down Expand Up @@ -514,7 +514,7 @@ bool LumatoneApplicationState::Controller::requestSettingsFromDevice()

// Macro button colours
appState.controller->requestMacroButtonColours();

// General options
appState.controller->requestPresetFlags();
appState.controller->requestExpressionPedalSensitivity();
Expand Down
11 changes: 7 additions & 4 deletions Source/lumatone_editor_library/data/application_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ class DeviceActivityMonitor;
class LumatoneApplicationState : public LumatoneState
{
public:
LumatoneApplicationState(juce::String nameIn, LumatoneFirmwareDriver& driverIn, juce::ValueTree stateIn=juce::ValueTree(), juce::UndoManager* undoManager=nullptr);
// Top-level constructor
LumatoneApplicationState(juce::ValueTree stateIn, LumatoneFirmwareDriver& driverIn, juce::UndoManager* undoManager);

LumatoneApplicationState(juce::String nameIn, const LumatoneApplicationState& stateIn);
LumatoneApplicationState(const LumatoneApplicationState& stateIn);

virtual ~LumatoneApplicationState() override;

Expand Down Expand Up @@ -84,19 +87,19 @@ class LumatoneApplicationState : public LumatoneState
virtual void setCompleteConfig(const LumatoneLayout& layoutIn) override;
virtual void setLayout(const LumatoneLayout& layoutIn) override;
virtual void setBoard(const LumatoneBoard& boardIn, int boardId) override;

virtual void setKey(const LumatoneKey& keyIn, int boardId, int keyIndex) override;
virtual void setKeyConfig(const LumatoneKey& keyIn, int boardId, int keyIndex) override;
virtual void setKeyColour(juce::Colour colour, int boardId, int keyIndex) override;
virtual void sendSelectionParam(const juce::Array<MappedLumatoneKey>& selection, bool signalEditorListeners = true, bool bufferKeyUpdates = false) override;
virtual void sendSelectionColours(const juce::Array<MappedLumatoneKey>& selection, bool signalEditorListeners = true, bool bufferKeyUpdates = false) override;

virtual void setAftertouchEnabled(bool enabled) override;
virtual void setLightOnKeyStrokes(bool enabled) override;
virtual void setInvertExpression(bool invert) override;
virtual void setInvertSustain(bool invert) override;
virtual void setExpressionSensitivity(juce::uint8 sensitivity) override;

virtual void setConfigTable(LumatoneConfigTable::TableType type, const LumatoneConfigTable& table) override;

private:
Expand Down
57 changes: 26 additions & 31 deletions Source/lumatone_editor_library/data/lumatone_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ juce::Array<juce::Identifier> LumatoneState::getLumatoneStateProperties()
properties.add(LumatoneStateProperty::AftertouchEnabled);
properties.add(LumatoneStateProperty::InvertExpression);
properties.add(LumatoneStateProperty::InvertSustain);

properties.add(LumatoneStateProperty::ExpressionSensitivity);

properties.add(LumatoneStateProperty::InactiveMacroButtonColour);
properties.add(LumatoneStateProperty::ActiveMacroButtonColour);

Expand All @@ -34,29 +34,34 @@ juce::Array<juce::Identifier> LumatoneState::getLumatoneStateProperties()
return properties;
}

LumatoneState::LumatoneState(juce::String nameIn, juce::ValueTree stateIn, juce::UndoManager* undoManagerIn)
: LumatoneStateBase(nameIn)
LumatoneState::LumatoneState(juce::ValueTree stateIn, juce::UndoManager *undoManagerIn)
: LumatoneStateBase(stateIn.getType().toString())
, undoManager(undoManagerIn)
{
state = loadStateProperties(stateIn);
state.addListener(this);

mappingData = std::make_shared<LumatoneLayout>();
midiKeyMap = std::make_shared<LumatoneOutputMap>(mappingData.get());

juce::ValueTree layoutState = juce::ValueTree(juce::Identifier(nameIn));
layoutState.appendChild(mappingData->getState(), nullptr);
state.appendChild(layoutState, nullptr);
state = loadStateProperties(stateIn);
state.addListener(this);

auto mappingState = mappingData->getState();
state.appendChild(mappingState, nullptr);
}

LumatoneState::LumatoneState(juce::String nameIn, const LumatoneState& stateToCopy)
: LumatoneState(nameIn, stateToCopy.state, stateToCopy.undoManager)
LumatoneState::LumatoneState(juce::String nameIn, const LumatoneState &stateIn)
: LumatoneStateBase(nameIn)
, undoManager(stateIn.undoManager)
, mappingData(stateIn.mappingData)
, midiKeyMap(stateIn.midiKeyMap)
{
mappingData = stateToCopy.mappingData;
midiKeyMap = stateToCopy.midiKeyMap;
state = loadStateProperties(stateIn.state);
state.addListener(this);
}

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

LumatoneState::~LumatoneState()
{
Expand All @@ -68,9 +73,9 @@ LumatoneState::~LumatoneState()

juce::ValueTree LumatoneState::loadStateProperties(juce::ValueTree stateIn)
{
juce::ValueTree newState = (stateIn.hasType(LumatoneStateProperty::StateTree))
juce::ValueTree newState = stateIn.isValid()
? stateIn
: juce::ValueTree(LumatoneStateProperty::StateTree);
: juce::ValueTree(LumatoneStateProperty::DefaultState);

for (auto property : getLumatoneStateProperties())
{
Expand All @@ -83,6 +88,10 @@ juce::ValueTree LumatoneState::loadStateProperties(juce::ValueTree stateIn)

void LumatoneState::handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property)
{
// Ignore any changes from parents
if (stateIn != state || !stateIn.isAChildOf(state))
return;

if (property == LumatoneStateProperty::LastConnectedSerialNumber)
{
connectedSerialNumber = stateIn.getProperty(property).toString();
Expand Down Expand Up @@ -203,20 +212,6 @@ void LumatoneState::setLightOnKeyStrokes(bool enabled)
mappingData->setLightOnKeyStrokes(enabled);
}

void LumatoneState::valueTreePropertyChanged(juce::ValueTree& treeWhosePropertyHasChanged, const juce::Identifier& property)
{
//if (treeWhosePropertyHasChanged == state)
//{
DBG("LumatoneState::valueTreePropertyChanged("
+ treeWhosePropertyHasChanged.getType().toString() + ", "
+ property.toString() + ")");

if (treeWhosePropertyHasChanged == state)
{
handleStatePropertyChange(state, property);
}
}

LumatoneFirmware::ReleaseVersion LumatoneState::getLumatoneVersion() const
{
return determinedVersion;
Expand Down
8 changes: 4 additions & 4 deletions Source/lumatone_editor_library/data/lumatone_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class LumatoneOutputMap;

namespace LumatoneStateProperty
{
static const juce::Identifier StateTree = juce::Identifier("LumatoneEditorStateTree");
static const juce::Identifier DefaultState = juce::Identifier("LumatoneStateTree");
static const juce::Identifier LumatoneState = juce::Identifier("LumatoneState");

// Lumatone Data
static const juce::Identifier LastConnectedSerialNumber = juce::Identifier("LastConnectedSerialNumber");
Expand All @@ -43,8 +44,9 @@ namespace LumatoneStateProperty
class LumatoneState : public LumatoneStateBase
{
public:
// Top-level constructor
LumatoneState(juce::ValueTree stateIn, juce::UndoManager* undoManager);

LumatoneState(juce::String nameIn, juce::ValueTree stateIn=juce::ValueTree(), juce::UndoManager* undoManager=nullptr);
LumatoneState(juce::String nameIn, const LumatoneState& stateToCopy);
LumatoneState(const LumatoneState& stateIn);

Expand Down Expand Up @@ -115,8 +117,6 @@ class LumatoneState : public LumatoneStateBase

virtual juce::ValueTree loadStateProperties(juce::ValueTree stateIn) override;

virtual void valueTreePropertyChanged(juce::ValueTree& treeWhosePropertyHasChanged, const juce::Identifier& property) override;

virtual void handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property) override;

virtual void loadPropertiesFile(juce::PropertiesFile* properties) override;
Expand Down

0 comments on commit d18c35a

Please sign in to comment.