diff --git a/Source/LumatoneEditorState.cpp b/Source/LumatoneEditorState.cpp index 8deb92d..362f61b 100644 --- a/Source/LumatoneEditorState.cpp +++ b/Source/LumatoneEditorState.cpp @@ -17,7 +17,6 @@ #include "./lumatone_editor_library/palettes/colour_selection_group.h" - static juce::File getDefaultUserDocumentsDirectory() { return File::getSpecialLocation(File::userDocumentsDirectory).getChildFile("Lumatone Editor"); @@ -31,7 +30,7 @@ static juce::File getDefaultUserPalettesDirectory() return getDefaultUserDocumentsDirectory().getChildFile("Palettes"); } -juce::Array GetLumatoneEditorProperty() +juce::Array GetLumatoneEditorProperties() { juce::Array properties; properties.add(LumatoneEditorProperty::HasChangesToSave); @@ -78,6 +77,7 @@ LumatoneEditorState::LumatoneEditorState(juce::String name, const LumatoneEditor , colourSelectionGroup(stateIn.colourSelectionGroup) { // DBG(name + " LumatoneEditorState created"); + loadStateProperties(stateIn.state); } LumatoneEditorState::LumatoneEditorState(const LumatoneEditorState &stateIn) @@ -287,17 +287,15 @@ juce::ValueTree LumatoneEditorState::loadStateProperties(juce::ValueTree stateIn ? stateIn : juce::ValueTree(LumatoneEditorProperty::StateTree); - // TODO load editor properties + // LumatoneApplicationState::loadStateProperties(newState); // DBG("LumatoneApplicationState::loadStateProperties:\n" + newState.toXmlString()); - for (auto property : getLumatoneApplicationProperties()) + for (auto property : GetLumatoneEditorProperties()) { if (newState.hasProperty(property)) handleStatePropertyChange(newState, property); } - LumatoneState::loadStateProperties(newState); - return newState; } @@ -596,3 +594,4 @@ void LumatoneEditorState::Controller::setDeveloperMode(bool developerModeOn) editorState.setStateProperty(LumatoneEditorProperty::DeveloperModeOn, editorState.inDeveloperMode); savePropertyBoolValue(LumatoneEditorProperty::DeveloperModeOn, developerModeOn); } + diff --git a/Source/lumatone_editor_library/data/application_state.cpp b/Source/lumatone_editor_library/data/application_state.cpp index 033d30c..c0f3e02 100644 --- a/Source/lumatone_editor_library/data/application_state.cpp +++ b/Source/lumatone_editor_library/data/application_state.cpp @@ -2,6 +2,8 @@ #include "../device/lumatone_controller.h" #include "../device/activity_monitor.h" +#include "../device/lumatone_event_manager.h" + #include "../color/colour_model.h" #include "../data/lumatone_context.h" #include "../actions/lumatone_action.h" @@ -39,8 +41,9 @@ LumatoneApplicationState::LumatoneApplicationState(juce::ValueTree stateIn, Luma layoutContext = std::make_shared(*mappingData); colourModel = std::make_shared(); + eventManager = std::make_shared(*this, driverIn); controller = std::make_shared(*this, driverIn); - activityMonitor = std::make_shared(*this, &driverIn); + activityMonitor = std::make_shared(*this, driverIn); loadStateProperties(stateIn); } @@ -52,13 +55,14 @@ LumatoneApplicationState::LumatoneApplicationState(juce::String nameIn, const Lu , statusListeners(stateIn.statusListeners) , firmwareListeners(stateIn.firmwareListeners) , midiListeners(stateIn.midiListeners) - , layoutContext(stateIn.layoutContext) - , controller(stateIn.controller) - , activityMonitor(stateIn.activityMonitor) - , colourModel(stateIn.colourModel) , selectedKeys(stateIn.selectedKeys) , receiveSettingsStatus(stateIn.receiveSettingsStatus) , receiveLayoutStatus(stateIn.receiveLayoutStatus) + , layoutContext(stateIn.layoutContext) + , colourModel(stateIn.colourModel) + , eventManager(stateIn.eventManager) + , controller(stateIn.controller) + , activityMonitor(stateIn.activityMonitor) { loadStateProperties(state); } @@ -70,10 +74,17 @@ LumatoneApplicationState::LumatoneApplicationState(const LumatoneApplicationStat LumatoneApplicationState::~LumatoneApplicationState() { - layoutContext = nullptr; activityMonitor = nullptr; controller = nullptr; + eventManager = nullptr; colourModel = nullptr; + layoutContext = nullptr; + receiveLayoutStatus = nullptr; + receiveSettingsStatus = nullptr; + midiListeners = nullptr; + firmwareListeners = nullptr; + statusListeners = nullptr; + editorListeners = nullptr; } ConnectionState LumatoneApplicationState::getConnectionState() const @@ -171,23 +182,23 @@ void LumatoneApplicationState::setActiveMacroButtonColour(juce::Colour buttonCol juce::ValueTree LumatoneApplicationState::loadStateProperties(juce::ValueTree stateIn) { - juce::ValueTree newState = (stateIn.hasType(LumatoneStateProperty::LumatoneState)) - ? stateIn - : juce::ValueTree(LumatoneStateProperty::LumatoneState); + // juce::ValueTree newState = stateIn.isValid() + // ? stateIn + // : juce::ValueTree(LumatoneStateProperty::DefaultState); - LumatoneState::loadStateProperties(newState); + // LumatoneState::loadStateProperties(newState); // DBG("LumatoneApplicationState::loadStateProperties:\n" + newState.toXmlString()); for (auto property : getLumatoneApplicationProperties()) { - if (newState.hasProperty(property)) - handleStatePropertyChange(newState, property); + if (stateIn.hasProperty(property)) + handleStatePropertyChange(stateIn, property); } // if (name.contains("Copy")) // DBG(juce::String("Loaded ") + name + juce::String(" properties")); - return newState; + return stateIn; } void LumatoneApplicationState::handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier &property) @@ -274,7 +285,7 @@ void LumatoneApplicationState::setLayout(const LumatoneLayout &layoutIn) if (doSendChangesToDevice()) { - controller->sendCompleteMapping(layoutIn); + controller->sendCompleteMapping(layoutIn, false, false); } clearContext(); @@ -721,12 +732,12 @@ void LumatoneApplicationState::DeviceController::setMidiInput(int deviceIndex, b { auto deviceInfo = getMidiInputList()[deviceIndex]; deviceAppState.setStateProperty(LumatoneApplicationProperty::LastInputDeviceId, deviceInfo.identifier); - deviceAppState.controller->setDriverMidiInput(deviceIndex, test); + deviceAppState.activityMonitor->setMidiInput(deviceIndex, test); } void LumatoneApplicationState::DeviceController::setMidiOutput(int deviceIndex, bool test) { auto deviceInfo = getMidiOutputList()[deviceIndex]; deviceAppState.setStateProperty(LumatoneApplicationProperty::LastOutputDeviceId, deviceInfo.identifier); - deviceAppState.controller->setDriverMidiOutput(deviceIndex, test); + deviceAppState.activityMonitor->setMidiOutput(deviceIndex, test); } diff --git a/Source/lumatone_editor_library/data/application_state.h b/Source/lumatone_editor_library/data/application_state.h index 4713cef..4076151 100644 --- a/Source/lumatone_editor_library/data/application_state.h +++ b/Source/lumatone_editor_library/data/application_state.h @@ -22,6 +22,8 @@ namespace LumatoneEditor class MidiListener; } +class LumatoneEventManager; + namespace LumatoneApplicationProperty { // Device Management @@ -162,12 +164,13 @@ class LumatoneApplicationState : public LumatoneState std::shared_ptr receiveSettingsStatus; std::shared_ptr receiveLayoutStatus; - std::shared_ptr layoutContext; - std::shared_ptr colourModel; + std::shared_ptr layoutContext; + std::shared_ptr colourModel; // Anything inheriting from this state should come after shared data - std::shared_ptr controller; - std::shared_ptr activityMonitor; + std::shared_ptr eventManager; + std::shared_ptr controller; + std::shared_ptr activityMonitor; bool contextIsSet = false; diff --git a/Source/lumatone_editor_library/data/lumatone_state.cpp b/Source/lumatone_editor_library/data/lumatone_state.cpp index 0ade9ac..8aa33a0 100644 --- a/Source/lumatone_editor_library/data/lumatone_state.cpp +++ b/Source/lumatone_editor_library/data/lumatone_state.cpp @@ -41,6 +41,9 @@ LumatoneState::LumatoneState(juce::ValueTree stateIn, juce::UndoManager *undoMan mappingData = std::make_shared(); midiKeyMap = std::make_shared(mappingData.get()); + if (!stateIn.isValid()) + state = juce::ValueTree(LumatoneStateProperty::DefaultState); + state = loadStateProperties(stateIn); state.addListener(this); @@ -73,17 +76,17 @@ LumatoneState::~LumatoneState() juce::ValueTree LumatoneState::loadStateProperties(juce::ValueTree stateIn) { - juce::ValueTree newState = stateIn.isValid() - ? stateIn - : juce::ValueTree(LumatoneStateProperty::DefaultState); + // juce::ValueTree newState = stateIn.isValid() + // ? stateIn + // : juce::ValueTree(LumatoneStateProperty::DefaultState); for (auto property : getLumatoneStateProperties()) { - if (newState.hasProperty(property)) - handleStatePropertyChange(newState, property); + if (stateIn.hasProperty(property)) + handleStatePropertyChange(stateIn, property); } - return newState; + return stateIn; } void LumatoneState::handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property) @@ -205,11 +208,13 @@ void LumatoneState::sendSelectionColours(const juce::Array& s void LumatoneState::setAftertouchEnabled(bool enabled) { mappingData->setAftertouchEnabled(enabled); + setStateProperty(LumatoneStateProperty::AftertouchEnabled, enabled); } void LumatoneState::setLightOnKeyStrokes(bool enabled) { mappingData->setLightOnKeyStrokes(enabled); + setStateProperty(LumatoneStateProperty::LightsOnAfterKeystroke, enabled); } LumatoneFirmware::ReleaseVersion LumatoneState::getLumatoneVersion() const @@ -259,21 +264,25 @@ const FirmwareSupport& LumatoneState::getFirmwareSupport() const void LumatoneState::setInvertExpression(bool invert) { mappingData->setInvertExpression(invert); + setStateProperty(LumatoneStateProperty::InvertExpression, invert); } void LumatoneState::setInvertSustain(bool invert) { mappingData->setInvertSustain(invert); + setStateProperty(LumatoneStateProperty::InvertSustain, invert); } void LumatoneState::setExpressionSensitivity(juce::uint8 sensitivity) { mappingData->setExpressionSensitivity(sensitivity); + setStateProperty(LumatoneStateProperty::ExpressionSensitivity, sensitivity); } void LumatoneState::setConfigTable(LumatoneConfigTable::TableType type, const LumatoneConfigTable& table) { mappingData->setConfigTable(type, table.velocityValues); + // todo update value tree state } void LumatoneState::setInactiveMacroButtonColour(juce::Colour buttonColour)