Skip to content

Commit

Permalink
refactor some low level controller methods, add import status structs…
Browse files Browse the repository at this point in the history
…, add wip lastSavedLayout to editor state
  • Loading branch information
vsicurella committed Jul 29, 2024
1 parent ba63cd9 commit f3b21b3
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 53 deletions.
12 changes: 9 additions & 3 deletions Source/LumatoneEditorState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ LumatoneEditorState::LumatoneEditorState(juce::ValueTree stateIn, LumatoneFirmwa

loadPropertiesFile(nullptr);

lastSavedLayout = std::make_shared<LumatoneLayout>();

colourPalettes = std::make_shared<juce::Array<LumatoneEditorColourPalette>>();
colourSelectionGroup = std::make_shared<ColourSelectionGroup>("LumatoneEditorAppColourGroup");
}
Expand Down Expand Up @@ -437,7 +439,7 @@ bool LumatoneEditorState::Controller::performAction(LumatoneAction *action, bool
{
if (LumatoneApplicationState::Controller::performAction(action, undoable, newTransaction))
{
setHasChangesToSave(true);

return true;
}

Expand All @@ -452,6 +454,7 @@ bool LumatoneEditorState::Controller::resetToCurrentFile()
// Replace with blank file
LumatoneLayout defaultLayout;
editorState.setCompleteConfig(defaultLayout);
*editorState.lastSavedLayout = defaultLayout;
editorState.setHasChangesToSave(false);
return true;
}
Expand All @@ -474,6 +477,9 @@ bool LumatoneEditorState::Controller::resetToCurrentFile()
// Send configuration to controller, if connected
editorState.setCompleteConfig(keyMapping);

// Save copy that doesn't get updated
*editorState.lastSavedLayout = keyMapping;

// Clear undo history
editorState.undoManager->clearUndoHistory();

Expand Down Expand Up @@ -506,11 +512,11 @@ bool LumatoneEditorState::Controller::openRecentFile(int recentFileIndex)
return setCurrentFile(editorState.recentFiles->getFile(recentFileIndex));
}

bool LumatoneEditorState::Controller::requestCompleteConfigFromDevice()
bool LumatoneEditorState::Controller::requestCompleteDeviceConfig()
{
setHasChangesToSave(false);
editorState.undoManager->clearUndoHistory();
return LumatoneApplicationState::Controller::requestCompleteConfigFromDevice();
return LumatoneApplicationState::Controller::requestCompleteDeviceConfig();
}

bool LumatoneEditorState::Controller::saveMappingToFile(juce::File fileToSave)
Expand Down
4 changes: 3 additions & 1 deletion Source/LumatoneEditorState.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ class LumatoneEditorState : public LumatoneApplicationState

std::shared_ptr<juce::PropertiesFile> propertiesFile;

std::shared_ptr<LumatoneLayout> lastSavedLayout;

protected:

// Global UI constants
Expand Down Expand Up @@ -205,7 +207,7 @@ class LumatoneEditorState : public LumatoneApplicationState
bool resetToCurrentFile();
bool openRecentFile(int recentFileIndex);

virtual bool requestCompleteConfigFromDevice() override;
virtual bool requestCompleteDeviceConfig() override;

void addPalette(const LumatoneEditorColourPalette& newPalette);
bool deletePaletteFile(juce::File pathToPalette);
Expand Down
2 changes: 1 addition & 1 deletion Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ bool TerpstraSysExApplication::onRequestDeviceConfig()
}

// resetSysExMapping();
requestCompleteConfigFromDevice();
requestCompleteDeviceConfig();

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/MidiEditArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ void MidiEditArea::onOpenConnectionToDevice(juce::String dialogTitle)
if (retc == 0) // Import
{
// TODO non getLumatoneController call
LumatoneEditorState::Controller::requestCompleteConfigFromDevice();
LumatoneEditorState::Controller::requestCompleteDeviceConfig();
setEditMode(EditorMode::ONLINE);
}
else if (retc == 1) // Send
Expand Down
59 changes: 44 additions & 15 deletions Source/lumatone_editor_library/data/application_state.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "application_state.h"

#include "../device/lumatone_controller.h"
#include "../device/activity_monitor.h"
#include "../color/colour_model.h"
Expand All @@ -11,6 +12,7 @@
#include "../listeners/midi_listener.h"

#include "../lumatone_midi_driver/lumatone_midi_driver.h"
#include "../lumatone_midi_driver/firmware_types.h"

juce::Array<juce::Identifier> getLumatoneApplicationProperties()
{
Expand All @@ -36,6 +38,9 @@ LumatoneApplicationState::LumatoneApplicationState(juce::ValueTree stateIn, Luma

selectedKeys = std::make_shared<juce::Array<MappedLumatoneKey>>();

receiveSettingsStatus = std::make_shared<FirmwareSupport::ReceiveSettingsStatus>();
receiveLayoutStatus = std::make_shared<FirmwareSupport::ReceiveLayoutStatus>();

loadStateProperties(stateIn);
}

Expand All @@ -51,6 +56,8 @@ LumatoneApplicationState::LumatoneApplicationState(juce::String nameIn, const Lu
, activityMonitor(stateIn.activityMonitor)
, colourModel(stateIn.colourModel)
, selectedKeys(stateIn.selectedKeys)
, receiveSettingsStatus(stateIn.receiveSettingsStatus)
, receiveLayoutStatus(stateIn.receiveLayoutStatus)
{
loadStateProperties(state);
}
Expand Down Expand Up @@ -389,7 +396,7 @@ void LumatoneApplicationState::setInvertSustain(bool invert)

if (doSendChangesToDevice())
{
controller->invertSustainPedal(invert);
controller->setInvertSustainPedal(invert);
}

editorListeners->call(&LumatoneEditor::EditorListener::invertSustainToggled, invert);
Expand Down Expand Up @@ -561,6 +568,16 @@ void LumatoneApplicationState::Controller::updatedSelectedKeys()
appState.editorListeners->call(&LumatoneEditor::EditorListener::selectionChanged);
}

FirmwareSupport::ReceiveSettingsStatus &LumatoneApplicationState::Controller::getReceivedSettingsStatus()
{
return *appState.receiveSettingsStatus;
}

FirmwareSupport::ReceiveLayoutStatus &LumatoneApplicationState::Controller::getReceivedLayoutStatus()
{
return *appState.receiveLayoutStatus;
}

bool LumatoneApplicationState::Controller::performAction(LumatoneAction *action, bool undoable, bool newTransaction)
{
return appState.performLumatoneAction(action, undoable, newTransaction);
Expand Down Expand Up @@ -606,45 +623,57 @@ void LumatoneApplicationState::removeMidiListener(LumatoneEditor::MidiListener*
midiListeners->remove(listenerIn);
}

bool LumatoneApplicationState::Controller::requestCompleteConfigFromDevice()
bool LumatoneApplicationState::Controller::requestCompleteDeviceConfig()
{
if (appState.connectionState != ConnectionState::ONLINE)
return false;

requestSettingsFromDevice();
requestMappingFromDevice();
requestDeviceGlobalSettings();
requestDeviceMapping();

return true;
}

bool LumatoneApplicationState::Controller::requestSettingsFromDevice()
bool LumatoneApplicationState::Controller::requestDeviceGlobalSettings()
{
if (appState.connectionState != ConnectionState::ONLINE)
return false;

// Reset state for tracking response progress
*appState.receiveSettingsStatus = FirmwareSupport::ReceiveSettingsStatus(appState.getLumatoneVersion());

// Velocity curve config
appState.controller->sendVelocityIntervalConfigRequest();

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

// General options
appState.controller->requestPresetFlags();
appState.controller->requestExpressionPedalSensitivity();

// Velocity curve config
appState.controller->sendVelocityIntervalConfigRequest();
appState.controller->sendVelocityConfigRequest();
appState.controller->sendFaderConfigRequest();
appState.controller->sendAftertouchConfigRequest();
appState.controller->getPeripheralChannels();

return true;
}

bool LumatoneApplicationState::Controller::requestMappingFromDevice()
bool LumatoneApplicationState::Controller::requestDeviceMapping()
{
if (appState.connectionState != ConnectionState::ONLINE)
return false;

// Reset state for tracking response progress
*appState.receiveLayoutStatus = FirmwareSupport::ReceiveLayoutStatus(appState.getLumatoneVersion(), appState.getNumBoards());

// Request MIDI channel, MIDI note, colour and key type config for all keys
appState.controller->sendGetCompleteMappingRequest();
appState.controller->sendGetAllBoardsMappingRequest();

// Request mapping look-up tables
appState.controller->sendVelocityConfigRequest();
appState.controller->sendFaderConfigRequest();
appState.controller->sendAftertouchConfigRequest();

// Request settings associated with mapping
appState.controller->requestExpressionPedalSensitivity();
appState.controller->requestPresetFlags();

return true;
}

Expand Down
25 changes: 15 additions & 10 deletions Source/lumatone_editor_library/data/application_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class LumatoneApplicationState : public LumatoneState
std::shared_ptr<DeviceActivityMonitor> activityMonitor;
std::shared_ptr<LumatoneColourModel> colourModel;

std::shared_ptr<FirmwareSupport::ReceiveSettingsStatus> receiveSettingsStatus;
std::shared_ptr<FirmwareSupport::ReceiveLayoutStatus> receiveLayoutStatus;

bool contextIsSet = false;

//================================================================================
Expand All @@ -174,24 +177,26 @@ class LumatoneApplicationState : public LumatoneState
Controller(LumatoneApplicationState& stateIn)
: appState(stateIn) {}

virtual bool requestSettingsFromDevice();
virtual bool requestMappingFromDevice();
virtual bool requestCompleteConfigFromDevice();
virtual bool requestDeviceGlobalSettings();
virtual bool requestDeviceMapping();
virtual bool requestCompleteDeviceConfig();

void setInactiveMacroButtonColour(juce::Colour buttonColour);
void setActiveMacroButtonColour(juce::Colour buttonColour);
void setInactiveMacroButtonColour(juce::Colour buttonColour);
void setActiveMacroButtonColour(juce::Colour buttonColour);

void setSelectedKeys(juce::Array<MappedLumatoneKey> selection);
void addSelectedKey(int keyNum);
void removeSelectedKey(int keyNum);
void setSelectedKeys(juce::Array<MappedLumatoneKey> selection);
void addSelectedKey(int keyNum);
void removeSelectedKey(int keyNum);

protected:
void updatedSelectedKeys();

void updatedSelectedKeys();
FirmwareSupport::ReceiveSettingsStatus& getReceivedSettingsStatus();
FirmwareSupport::ReceiveLayoutStatus& getReceivedLayoutStatus();

public:

virtual bool performAction(LumatoneAction* action, bool undoable=true, bool newTransaction=true);
virtual bool performAction(LumatoneAction* action, bool undoable=true, bool newTransaction=true);

protected:
juce::ListenerList<LumatoneEditor::EditorListener>* getEditorListeners() const { return appState.editorListeners.get(); }
Expand Down
10 changes: 5 additions & 5 deletions Source/lumatone_editor_library/device/lumatone_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void LumatoneController::sendCurrentCompleteConfig(bool signalEditorListeners)
sendLightOnKeyStrokes(getMappingData()->getLightOnKeyStrokes());
sendInvertFootController(getMappingData()->getInvertExpression());
sendExpressionPedalSensivity(getMappingData()->getExpressionSensitivity());
invertSustainPedal(getMappingData()->getInvertSustain());
setInvertSustainPedal(getMappingData()->getInvertSustain());

// Velocity curve config
setVelocityIntervalConfig(getMappingData()->getConfigTable(LumatoneConfigTable::velocityInterval)->velocityValues);
Expand All @@ -146,7 +146,7 @@ void LumatoneController::sendGetMappingOfBoardRequest(int boardId)
getFaderTypeConfig(boardId);
}

void LumatoneController::sendGetCompleteMappingRequest()
void LumatoneController::sendGetAllBoardsMappingRequest()
{
for (int boardId = 1; boardId <= getNumBoards(); boardId++)
sendGetMappingOfBoardRequest(boardId);
Expand Down Expand Up @@ -520,7 +520,7 @@ void LumatoneController::getPeripheralChannels()
firmwareDriver.getPeripheralChannels();
}

void LumatoneController::invertSustainPedal(bool setInverted)
void LumatoneController::setInvertSustainPedal(bool setInverted)
{
LumatoneState::setInvertSustain(setInverted);

Expand Down Expand Up @@ -571,7 +571,7 @@ void LumatoneController::onConnectionConfirmed()
{
checkingDeviceIsLumatone = false;
currentDevicePairConfirmed = true;

if (getSerialNumber().isEmpty())
{
waitingForFirmwareVersion = true;
Expand Down Expand Up @@ -613,7 +613,7 @@ void LumatoneController::serialIdentityReceived(const int* serialBytes)
sendGetFirmwareRevisionRequest();
else
onConnectionConfirmed();

setConnectionState(ConnectionState::ONLINE);
}

Expand Down
4 changes: 2 additions & 2 deletions Source/lumatone_editor_library/device/lumatone_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LumatoneController : private LumatoneApplicationState
void sendGetMappingOfBoardRequest(int boardId);

// Send request to receive the complete current mapping on the controller
void sendGetCompleteMappingRequest();
void sendGetAllBoardsMappingRequest();

// Send parametrization of one key to the device
void sendKeyParam(int boardId, int keyIndex, LumatoneKey keyData, bool signalEditorListeners=true, bool bufferKeyUpdates=false);
Expand Down Expand Up @@ -189,7 +189,7 @@ class LumatoneController : private LumatoneApplicationState
void getPeripheralChannels();

// Invert the polarity of the sustain pedal
void invertSustainPedal(bool setInverted);
void setInvertSustainPedal(bool setInverted);

// Reset preset mappings to factory mappings
void resetPresetsToFactoryDefault();
Expand Down
Loading

0 comments on commit f3b21b3

Please sign in to comment.