Skip to content

Commit

Permalink
add properties file integration into LumatoneState, implement in most…
Browse files Browse the repository at this point in the history
… properties
  • Loading branch information
vsicurella committed Jan 26, 2024
1 parent e532408 commit a084d8a
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 107 deletions.
87 changes: 69 additions & 18 deletions Source/LumatoneEditorState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@
#include "./lumatone_editor_library/device/lumatone_controller.h"
#include "./lumatone_editor_library/listeners/editor_listener.h"


static juce::File getDefaultUserDocumentsDirectory()
{
return File::getSpecialLocation(File::userDocumentsDirectory).getChildFile("Lumatone Editor");
}
static juce::File getDefaultUserMappingsDirectory()
{
return getDefaultUserDocumentsDirectory().getChildFile("Mappings");
}
static juce::File getDefaultUserPalettesDirectory()
{
return getDefaultUserDocumentsDirectory().getChildFile("Palettes");
}

juce::Array<juce::Identifier> GetLumatoneEditorProperty()
{
juce::Array<juce::Identifier> properties;
Expand All @@ -41,23 +55,7 @@ LumatoneEditorState::LumatoneEditorState(juce::String name, LumatoneFirmwareDriv
appFonts = std::make_shared<LumatoneEditorFontLibrary>();
lookAndFeel = std::make_shared<LumatoneEditorLookAndFeel>(*appFonts, true);

juce::PropertiesFile::Options options;
options.applicationName = "LumatoneSetup";
options.filenameSuffix = "settings";
options.osxLibrarySubFolder = "Application Support";
#if JUCE_LINUX
options.folderName = "~/.config/LumatoneSetup";
#else
options.folderName = "LumatoneSetup";
#endif

propertiesFile = std::make_shared<juce::PropertiesFile>(options);
DBG(propertiesFile->createXml("LumatoneEditorSettings")->toString());
jassert(propertiesFile != nullptr);

recentFiles = std::make_shared<juce::RecentlyOpenedFilesList>();
recentFiles->restoreFromString(propertiesFile->getValue(LumatoneEditorProperty::RecentFiles));
recentFiles->removeNonExistentFiles();
loadPropertiesFile(nullptr);

colourPalettes = std::make_shared<juce::Array<LumatoneEditorColourPalette>>();
}
Expand Down Expand Up @@ -227,6 +225,56 @@ void LumatoneEditorState::handleStatePropertyChange(juce::ValueTree stateIn, con
}
}

void LumatoneEditorState::loadPropertiesFile(juce::PropertiesFile *propertiesIn)
{
juce::PropertiesFile::Options options;
options.applicationName = "LumatoneSetup";
options.filenameSuffix = "settings";
options.osxLibrarySubFolder = "Application Support";
#if JUCE_LINUX
options.folderName = "~/.config/LumatoneSetup";
#else
options.folderName = "LumatoneSetup";
#endif

propertiesFile = std::make_shared<juce::PropertiesFile>(options);
DBG(propertiesFile->createXml("LumatoneEditorSettings")->toString());
jassert(propertiesFile != nullptr);

recentFiles = std::make_shared<juce::RecentlyOpenedFilesList>();
recentFiles->restoreFromString(propertiesFile->getValue(LumatoneEditorProperty::RecentFiles));
recentFiles->removeNonExistentFiles();

LumatoneApplicationState::loadPropertiesFile(propertiesFile.get());

setStateProperty(LumatoneEditorProperty::UserDocumentsDirectory, propertiesFile->getValue(LumatoneEditorProperty::UserDocumentsDirectory.toString(), getDefaultUserDocumentsDirectory().getFullPathName()));
setStateProperty(LumatoneEditorProperty::UserMappingsDirectory, propertiesFile->getValue(LumatoneEditorProperty::UserMappingsDirectory.toString(), getDefaultUserMappingsDirectory().getFullPathName()));
setStateProperty(LumatoneEditorProperty::UserPalettesDirectory, propertiesFile->getValue(LumatoneEditorProperty::UserPalettesDirectory.toString(), getDefaultUserPalettesDirectory().getFullPathName()));
setStateProperty(LumatoneEditorProperty::RecentFiles, propertiesFile->getValue(LumatoneEditorProperty::RecentFiles.toString(), juce::String()));
setStateProperty(LumatoneEditorProperty::MainWindowState, propertiesFile->getValue(LumatoneEditorProperty::MainWindowState.toString(), juce::String()));

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::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));
setStateProperty(LumatoneEditorProperty::LastFirmwareBinPath, propertiesFile->getValue(LumatoneEditorProperty::LastFirmwareBinPath.toString()
, juce::File::getSpecialLocation(juce::File::SpecialLocationType::userHomeDirectory).getFullPathName()
));

setStateProperty(LumatoneEditorProperty::DeveloperModeOn, propertiesFile->getBoolValue(LumatoneEditorProperty::DeveloperModeOn, false));
}

void LumatoneEditorState::Controller::setColourPalettes(const juce::Array<LumatoneEditorColourPalette> &palettesIn)
{
*editorState.colourPalettes = palettesIn;
Expand Down Expand Up @@ -327,7 +375,7 @@ bool LumatoneEditorState::Controller::resetToCurrentFile()
bool LumatoneEditorState::Controller::setCurrentFile(File fileToOpen)
{
editorState.currentFile = fileToOpen;
editorState.state.setPropertyExcludingListener(&editorState, LumatoneEditorProperty::CurrentFile, editorState.currentFile.getFullPathName(), nullptr);
editorState.setStateProperty(LumatoneEditorProperty::CurrentFile, editorState.currentFile.getFullPathName());
return resetToCurrentFile();
}

Expand Down Expand Up @@ -388,18 +436,21 @@ void LumatoneEditorState::Controller::savePropertyBoolValue(const juce::Identifi
{
editorState.propertiesFile->setValue(id.toString(), juce::var(value));
savePropertiesFile();
editorState.setStateProperty(id, juce::var(value));
}

void LumatoneEditorState::Controller::savePropertyIntValue(const juce::Identifier &id, int value)
{
editorState.propertiesFile->setValue(id.toString(), juce::var(value));
savePropertiesFile();
editorState.setStateProperty(id, juce::var(value));
}

void LumatoneEditorState::Controller::savePropertyStringValue(const juce::Identifier &id, juce::String value)
{
editorState.propertiesFile->setValue(id.toString(), juce::var(value));
savePropertiesFile();
editorState.setStateProperty(id, juce::var(value));
}

void LumatoneEditorState::Controller::setCalibrationMode(bool calibrationModeOn)
Expand Down
7 changes: 7 additions & 0 deletions Source/LumatoneEditorState.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ namespace LumatoneEditorProperty
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 LastSettingsPanel = juce::Identifier("LastSettingsPanel");
static const juce::Identifier LastColourWindowTab = juce::Identifier("LastColourWindowTab");
static const juce::Identifier LastFirmwareBinPath = juce::Identifier("LastFirmwareBinPath");
}

enum class EditorMode
Expand Down Expand Up @@ -109,6 +114,8 @@ class LumatoneEditorState : public LumatoneApplicationState
juce::ValueTree loadStateProperties(juce::ValueTree stateIn) override;
void handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property) override;

void loadPropertiesFile(juce::PropertiesFile* properties);

void setHasChangesToSave(bool hasChangesToSave);

protected:
Expand Down
27 changes: 17 additions & 10 deletions Source/MidiEditArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ MidiEditArea::MidiEditArea (const LumatoneEditorState& stateIn)
cbMidiInput->setTooltip (juce::translate("Receives answers to sent SysEx commands and the current configuration from controller "));
cbMidiInput->setEditableText (false);
cbMidiInput->setJustificationType (juce::Justification::centredLeft);
// cbMidiInput->setTextWhenNothingSelected (juce::translate("Select MIDI Input"));
cbMidiInput->setTextWhenNothingSelected ("pick something ya dummy");
cbMidiInput->setTextWhenNothingSelected (juce::translate("Select MIDI Input"));
cbMidiInput->setTextWhenNoChoicesAvailable (juce::translate("(no choices)"));
cbMidiInput->onChange = [&]()
{
Expand Down Expand Up @@ -143,11 +142,11 @@ MidiEditArea::MidiEditArea (const LumatoneEditorState& stateIn)
addAndMakeVisible (btnAutoConnect.get());
btnAutoConnect->setTooltip (juce::translate("Toggle between automatic or manual connection to Lumatone"));
btnAutoConnect->setButtonText (juce::translate("auto"));
btnAutoConnect->setClickingTogglesState(true);
btnAutoConnect->onClick = [&]()
{
toggleAutoConnection();
onAutoConnectionChanged();
};
btnAutoConnect->setClickingTogglesState(true);


// Set up styles
Expand Down Expand Up @@ -181,8 +180,11 @@ MidiEditArea::MidiEditArea (const LumatoneEditorState& stateIn)

addEditorListener(this);
addStatusListener(this);
btnAutoConnect->setToggleState(isAutoConnectionEnabled(), sendNotificationSync);

// btnAutoConnect->setToggleState(isAutoConnectionEnabled(), sendNotificationSync);
bool enableAutoConnection = getBoolProperty(LumatoneEditorProperty::AutoConnectDevice, true);
btnAutoConnect->setToggleState(enableAutoConnection, dontSendNotification);
onAutoConnectionChanged();
}

MidiEditArea::~MidiEditArea()
Expand Down Expand Up @@ -378,14 +380,19 @@ void MidiEditArea::setConnectivity(bool isConnectedIn, juce::String connectionSt
resized();
}

void MidiEditArea::toggleAutoConnection()
void MidiEditArea::onAutoConnectionChanged()
{
cbMidiInput->setVisible(!btnAutoConnect->getToggleState());
cbMidiOutput->setVisible(!btnAutoConnect->getToggleState());
bool isAuto = btnAutoConnect->getToggleState();
bool isNotAuto = !isAuto;

savePropertyBoolValue(LumatoneEditorProperty::AutoConnectDevice, isAuto);

cbMidiInput->setVisible(isNotAuto);
cbMidiOutput->setVisible(isNotAuto);

setAutoConnectionEnabled(btnAutoConnect->getToggleState());
setAutoConnectionEnabled(isAuto);

if (btnAutoConnect->getToggleState())
if (isAuto)
{
lblConnectionState->setText(translate("Searching for Lumatone..."), dontSendNotification);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/MidiEditArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MidiEditArea : public juce::Component
private:
void setConnectivity(bool isConnected, juce::String connectionStatus=String());

void toggleAutoConnection();
void onAutoConnectionChanged();

void editModeChangedCallback();

Expand Down
2 changes: 1 addition & 1 deletion Source/NoteEditArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void NoteEditArea::setControlsTopLeftPosition(int controlsAreaX, int controlsAre

void NoteEditArea::saveStateToPropertiesFile(PropertiesFile* propertiesFile)
{
dynamic_cast<SingleNoteAssign*>(editFunctionsTab->getTabContentComponent(noteEditMode::SingleNoteAssignMode))->saveStateToPropertiesFile(propertiesFile);
// dynamic_cast<SingleNoteAssign*>(editFunctionsTab->getTabContentComponent(noteEditMode::SingleNoteAssignMode))->saveStateToPropertiesFile(propertiesFile);

if (showIsomorphicMassAssign)
dynamic_cast<IsomorphicMassAssign*>(editFunctionsTab->getTabContentComponent(noteEditMode::IsomorphicMassAssignMode))->saveStateToPropertiesFile(propertiesFile);
Expand Down
Loading

0 comments on commit a084d8a

Please sign in to comment.