diff --git a/Source/LumatoneEditorState.cpp b/Source/LumatoneEditorState.cpp index c356c01..a9fda4b 100644 --- a/Source/LumatoneEditorState.cpp +++ b/Source/LumatoneEditorState.cpp @@ -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 GetLumatoneEditorProperty() { juce::Array properties; @@ -41,23 +55,7 @@ LumatoneEditorState::LumatoneEditorState(juce::String name, LumatoneFirmwareDriv appFonts = std::make_shared(); lookAndFeel = std::make_shared(*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(options); - DBG(propertiesFile->createXml("LumatoneEditorSettings")->toString()); - jassert(propertiesFile != nullptr); - - recentFiles = std::make_shared(); - recentFiles->restoreFromString(propertiesFile->getValue(LumatoneEditorProperty::RecentFiles)); - recentFiles->removeNonExistentFiles(); + loadPropertiesFile(nullptr); colourPalettes = std::make_shared>(); } @@ -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(options); + DBG(propertiesFile->createXml("LumatoneEditorSettings")->toString()); + jassert(propertiesFile != nullptr); + + recentFiles = std::make_shared(); + 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 &palettesIn) { *editorState.colourPalettes = palettesIn; @@ -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(); } @@ -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) diff --git a/Source/LumatoneEditorState.h b/Source/LumatoneEditorState.h index bcef96e..461c919 100644 --- a/Source/LumatoneEditorState.h +++ b/Source/LumatoneEditorState.h @@ -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 @@ -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: diff --git a/Source/MidiEditArea.cpp b/Source/MidiEditArea.cpp index 0880695..fba8c42 100644 --- a/Source/MidiEditArea.cpp +++ b/Source/MidiEditArea.cpp @@ -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 = [&]() { @@ -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 @@ -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() @@ -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); } diff --git a/Source/MidiEditArea.h b/Source/MidiEditArea.h index 245de5a..f58c62b 100644 --- a/Source/MidiEditArea.h +++ b/Source/MidiEditArea.h @@ -77,7 +77,7 @@ class MidiEditArea : public juce::Component private: void setConnectivity(bool isConnected, juce::String connectionStatus=String()); - void toggleAutoConnection(); + void onAutoConnectionChanged(); void editModeChangedCallback(); diff --git a/Source/NoteEditArea.cpp b/Source/NoteEditArea.cpp index f18fc96..51f70d9 100644 --- a/Source/NoteEditArea.cpp +++ b/Source/NoteEditArea.cpp @@ -303,7 +303,7 @@ void NoteEditArea::setControlsTopLeftPosition(int controlsAreaX, int controlsAre void NoteEditArea::saveStateToPropertiesFile(PropertiesFile* propertiesFile) { - dynamic_cast(editFunctionsTab->getTabContentComponent(noteEditMode::SingleNoteAssignMode))->saveStateToPropertiesFile(propertiesFile); + // dynamic_cast(editFunctionsTab->getTabContentComponent(noteEditMode::SingleNoteAssignMode))->saveStateToPropertiesFile(propertiesFile); if (showIsomorphicMassAssign) dynamic_cast(editFunctionsTab->getTabContentComponent(noteEditMode::IsomorphicMassAssignMode))->saveStateToPropertiesFile(propertiesFile); diff --git a/Source/SingleNoteAssign.cpp b/Source/SingleNoteAssign.cpp index f803ad4..13dca54 100644 --- a/Source/SingleNoteAssign.cpp +++ b/Source/SingleNoteAssign.cpp @@ -34,10 +34,8 @@ //============================================================================== SingleNoteAssign::SingleNoteAssign (const LumatoneEditorState& stateIn) : LumatoneEditorState("SingleNoteAssign", stateIn) + , LumatoneEditorState::Controller(static_cast(*this)) { - //[Constructor_pre] You can add your own custom stuff here.. - //[/Constructor_pre] - setName ("SingleNoteAssign"); noteAutoIncrButton.reset (new juce::ToggleButton ("noteAutoIncrButton")); addAndMakeVisible (noteAutoIncrButton.get()); @@ -175,25 +173,19 @@ SingleNoteAssign::SingleNoteAssign (const LumatoneEditorState& stateIn) FlexBox::JustifyContent::flexStart)); } - //[/UserPreSize] - - setSize (320, 400); - - - //[Constructor] You can add your own custom stuff here.. - setNoteToggleButton->setToggleState(getProperty(LumatoneEditorProperty::SingleNoteNoteSetActive).getIntValue(), juce::NotificationType::sendNotification); - setChannelToggleButton->setToggleState(getProperty(LumatoneEditorProperty::SingleNoteChannelSetActive).getIntValue(), juce::NotificationType::sendNotification); - setColourToggleButton->setToggleState(getProperty(LumatoneEditorProperty::SingleNoteColourSetActive).getIntValue(), juce::NotificationType::sendNotification); - keyTypeToggleButton->setToggleState(getProperty(LumatoneEditorProperty::SingleNoteKeyTypeSetActive).getIntValue(), juce::NotificationType::sendNotification); + setNoteToggleButton->setToggleState(getBoolProperty(LumatoneEditorProperty::SingleNoteNoteSetActive, true), juce::NotificationType::sendNotification); + setChannelToggleButton->setToggleState(getBoolProperty(LumatoneEditorProperty::SingleNoteChannelSetActive, true), juce::NotificationType::sendNotification); + setColourToggleButton->setToggleState(getBoolProperty(LumatoneEditorProperty::SingleNoteColourSetActive, true), juce::NotificationType::sendNotification); + keyTypeToggleButton->setToggleState(getBoolProperty(LumatoneEditorProperty::SingleNoteKeyTypeSetActive, true), juce::NotificationType::sendNotification); + noteAutoIncrButton->setToggleState(getBoolProperty(LumatoneEditorProperty::SingleNoteAutoIncNoteActive, true), juce::NotificationType::sendNotification); + channelAutoIncrButton->setToggleState(getBoolProperty(LumatoneEditorProperty::SingleNoteAutoIncChannelActive, true), juce::NotificationType::sendNotification); + channelAutoIncrNoteInput->setValue(getIntProperty(LumatoneEditorProperty::SingleNoteAutoIncChannelAfterNumNotes, true), juce::NotificationType::sendNotification); keyTypeCombo->setSelectedId(LumatoneKeyType::noteOnNoteOff); - //[/Constructor] } SingleNoteAssign::~SingleNoteAssign() { - //[Destructor_pre]. You can add your own custom destruction code here.. colourSubwindow = nullptr; - //[/Destructor_pre] noteAutoIncrButton = nullptr; channelAutoIncrButton = nullptr; @@ -217,12 +209,6 @@ SingleNoteAssign::~SingleNoteAssign() //============================================================================== void SingleNoteAssign::paint (juce::Graphics& g) { - //[UserPrePaint] Add your own custom painting code here.. - //[/UserPrePaint] - - g.fillAll (juce::Colour (0xffbad0de)); - - //[UserPaint] Add your own custom painting code here.. g.fillAll(Colour(0xff212626)); Rectangle bottomPart = getLocalBounds().toFloat().withTrimmedTop(instructionsAreaBounds.getBottom()); @@ -428,6 +414,8 @@ void SingleNoteAssign::buttonClicked (juce::Button* buttonThatWasClicked) if (buttonThatWasClicked == noteAutoIncrButton.get()) { //[UserButtonCode_noteAutoIncrButton] -- add your button handler code here.. + bool fieldActive = noteAutoIncrButton->getToggleState(); + savePropertyBoolValue(LumatoneEditorProperty::SingleNoteAutoIncNoteActive, fieldActive); //[/UserButtonCode_noteAutoIncrButton] } else if (buttonThatWasClicked == channelAutoIncrButton.get()) @@ -435,6 +423,7 @@ void SingleNoteAssign::buttonClicked (juce::Button* buttonThatWasClicked) //[UserButtonCode_channelAutoIncrButton] -- add your button handler code here.. bool fieldActive = channelAutoIncrButton->getToggleState(); channelAutoIncrNoteInput->setEnabled(fieldActive); + savePropertyBoolValue(LumatoneEditorProperty::SingleNoteAutoIncChannelActive, fieldActive); //[/UserButtonCode_channelAutoIncrButton] } else if (buttonThatWasClicked == setNoteToggleButton.get()) @@ -443,6 +432,7 @@ void SingleNoteAssign::buttonClicked (juce::Button* buttonThatWasClicked) bool fieldActive = setNoteToggleButton->getToggleState(); noteInput->setEnabled(fieldActive); noteAutoIncrButton->setEnabled(fieldActive); + savePropertyBoolValue(LumatoneEditorProperty::SingleNoteNoteSetActive, fieldActive); //[/UserButtonCode_setNoteToggleButton] } else if (buttonThatWasClicked == setChannelToggleButton.get()) @@ -452,6 +442,7 @@ void SingleNoteAssign::buttonClicked (juce::Button* buttonThatWasClicked) channelInput->setEnabled(fieldActive); channelAutoIncrButton->setEnabled(fieldActive); channelAutoIncrNoteInput->setEnabled(fieldActive); + savePropertyBoolValue(LumatoneEditorProperty::SingleNoteChannelSetActive, fieldActive); //[/UserButtonCode_setChannelToggleButton] } else if (buttonThatWasClicked == setColourToggleButton.get()) @@ -460,6 +451,7 @@ void SingleNoteAssign::buttonClicked (juce::Button* buttonThatWasClicked) bool fieldActive = setColourToggleButton->getToggleState(); colourSubwindow->setEnabled(fieldActive); colourTextEditor->setEnabled(fieldActive); + savePropertyBoolValue(LumatoneEditorProperty::SingleNoteColourSetActive, fieldActive); //[/UserButtonCode_setColourToggleButton] } else if (buttonThatWasClicked == keyTypeToggleButton.get()) @@ -467,12 +459,15 @@ void SingleNoteAssign::buttonClicked (juce::Button* buttonThatWasClicked) //[UserButtonCode_keyTypeToggleButton] -- add your button handler code here.. bool fieldActive = keyTypeToggleButton->getToggleState(); keyTypeCombo->setEnabled(fieldActive); + savePropertyBoolValue(LumatoneEditorProperty::SingleNoteKeyTypeSetActive, fieldActive); //[/UserButtonCode_keyTypeToggleButton] } //[UserbuttonClicked_Post] else if (buttonThatWasClicked == ccFaderIsDefault.get()) { + bool fieldActive = ccFaderIsDefault->getToggleState(); + savePropertyBoolValue(LumatoneEditorProperty::SingleNoteCCFaderIsDefault, fieldActive); } //[/UserbuttonClicked_Post] } @@ -525,6 +520,8 @@ void SingleNoteAssign::sliderValueChanged (juce::Slider* sliderThatWasMoved) else if (sliderThatWasMoved == channelAutoIncrNoteInput.get()) { //[UserSliderCode_channelAutoIncrNoteInput] -- add your slider handling code here.. + int numNotes = channelAutoIncrNoteInput->getValue(); + savePropertyIntValue(LumatoneEditorProperty::SingleNoteAutoIncChannelAfterNumNotes, numNotes); //[/UserSliderCode_channelAutoIncrNoteInput] } @@ -589,13 +586,14 @@ LumatoneAction* SingleNoteAssign::createEditAction(int setSelection, int keySele return editAction; } -void SingleNoteAssign::saveStateToPropertiesFile(PropertiesFile* propertiesFile) -{ - propertiesFile->setValue(LumatoneEditorProperty::SingleNoteNoteSetActive, setNoteToggleButton->getToggleState()); - propertiesFile->setValue(LumatoneEditorProperty::SingleNoteChannelSetActive, setChannelToggleButton->getToggleState()); - propertiesFile->setValue(LumatoneEditorProperty::SingleNoteColourSetActive, setColourToggleButton->getToggleState()); - propertiesFile->setValue(LumatoneEditorProperty::SingleNoteKeyTypeSetActive, keyTypeToggleButton->getToggleState()); -} +// void SingleNoteAssign::saveStateToPropertiesFile(PropertiesFile* propertiesFile) +// { +// propertiesFile->setValue(LumatoneEditorProperty::SingleNoteNoteSetActive, setNoteToggleButton->getToggleState()); +// propertiesFile->setValue(LumatoneEditorProperty::SingleNoteChannelSetActive, setChannelToggleButton->getToggleState()); +// propertiesFile->setValue(LumatoneEditorProperty::SingleNoteColourSetActive, setColourToggleButton->getToggleState()); +// propertiesFile->setValue(LumatoneEditorProperty::SingleNoteKeyTypeSetActive, keyTypeToggleButton->getToggleState()); +// propertiesFile->setValue(LumatoneEditorProperty::SingleNoteAutoIncChannelActive, channelAutoIncrButton->getToggleState()); +// } void SingleNoteAssign::redrawCCFlipBtn() { diff --git a/Source/SingleNoteAssign.h b/Source/SingleNoteAssign.h index bcf0e13..e03c924 100644 --- a/Source/SingleNoteAssign.h +++ b/Source/SingleNoteAssign.h @@ -41,13 +41,14 @@ class LumatoneAction; Describe your class and how it works here! //[/Comments] */ -class SingleNoteAssign : public juce::Component, - public LumatoneEditorState, - public ColourSelectionListener, - public TextEditor::Listener, - public juce::Button::Listener, - public juce::ComboBox::Listener, - public juce::Slider::Listener +class SingleNoteAssign : public juce::Component + , public ColourSelectionListener + , private LumatoneEditorState + , private LumatoneEditorState::Controller + , private TextEditor::Listener + , private juce::Button::Listener + , private juce::ComboBox::Listener + , private juce::Slider::Listener { public: //============================================================================== @@ -55,12 +56,9 @@ class SingleNoteAssign : public juce::Component, ~SingleNoteAssign() override; //============================================================================== - //[UserMethods] -- You can add your own custom methods in this section. LumatoneAction* createEditAction(int setSelection, int keySelection); - //void onSetData(LumatoneLayout& newData); - //void restoreStateFromPropertiesFile(juce::PropertiesFile* propertiesFile); - void saveStateToPropertiesFile(juce::PropertiesFile* propertiesFile); + // void saveStateToPropertiesFile(juce::PropertiesFile* propertiesFile); ColourViewComponent* getColourViewComponent() { return colourSubwindow.get(); } ColourTextEditor* getColourTextEditor() { return colourTextEditor.get(); } @@ -68,18 +66,15 @@ class SingleNoteAssign : public juce::Component, void colourChangedCallback(ColourSelectionBroadcaster* source, Colour newColour) override; void redrawCCFlipBtn(); - //[/UserMethods] + //============================================================================== void paint (juce::Graphics& g) override; void resized() override; void buttonClicked (juce::Button* buttonThatWasClicked) override; void comboBoxChanged (juce::ComboBox* comboBoxThatHasChanged) override; void sliderValueChanged (juce::Slider* sliderThatWasMoved) override; - - private: - //[UserVariables] -- You can add your own custom variables in this section. //============================================================================== // Style Helpers int roundedCornerSize; diff --git a/Source/lumatone_editor_library/data/application_state.cpp b/Source/lumatone_editor_library/data/application_state.cpp index 14fd2dc..aea4c6e 100644 --- a/Source/lumatone_editor_library/data/application_state.cpp +++ b/Source/lumatone_editor_library/data/application_state.cpp @@ -16,8 +16,6 @@ juce::Array getLumatoneApplicationProperties() { juce::Array properties; properties.add(LumatoneApplicationProperty::ConnectionStateId); - // properties.add(LumatoneApplicationProperty::DetectDeviceIfDisconnected); - // properties.add(LumatoneApplicationProperty::CheckConnectionIfInactive); properties.add(LumatoneApplicationProperty::LayoutContextIsSetId); return properties; } @@ -192,6 +190,17 @@ void LumatoneApplicationState::handleStatePropertyChange(juce::ValueTree stateIn } } +void LumatoneApplicationState::loadPropertiesFile(juce::PropertiesFile *properties) +{ + LumatoneState::loadPropertiesFile(properties); + + setStateProperty(LumatoneApplicationProperty::DetectDeviceIfDisconnected, properties->getBoolValue(LumatoneApplicationProperty::DetectDeviceIfDisconnected.toString(), true)); + setStateProperty(LumatoneApplicationProperty::CheckConnectionIfInactive, properties->getBoolValue(LumatoneApplicationProperty::CheckConnectionIfInactive.toString(), true)); + + setStateProperty(LumatoneApplicationProperty::LastInputDeviceId, properties->getValue(LumatoneApplicationProperty::LastInputDeviceId.toString(), juce::String())); + setStateProperty(LumatoneApplicationProperty::LastOutputDeviceId, properties->getValue(LumatoneApplicationProperty::LastOutputDeviceId.toString(), juce::String())); +} + LumatoneKeyContext LumatoneApplicationState::getKeyContext(int boardIndex, int keyIndex) const { if (contextIsSet) diff --git a/Source/lumatone_editor_library/data/application_state.h b/Source/lumatone_editor_library/data/application_state.h index 31f4e9f..893c28e 100644 --- a/Source/lumatone_editor_library/data/application_state.h +++ b/Source/lumatone_editor_library/data/application_state.h @@ -112,6 +112,8 @@ class LumatoneApplicationState : public LumatoneState virtual void handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property) override; + virtual void loadPropertiesFile(juce::PropertiesFile* properties) override; + private: ConnectionState connectionState = ConnectionState::DISCONNECTED; diff --git a/Source/lumatone_editor_library/data/lumatone_state.cpp b/Source/lumatone_editor_library/data/lumatone_state.cpp index 25ffbdd..31b8862 100644 --- a/Source/lumatone_editor_library/data/lumatone_state.cpp +++ b/Source/lumatone_editor_library/data/lumatone_state.cpp @@ -106,6 +106,11 @@ void LumatoneState::handleStatePropertyChange(juce::ValueTree stateIn, const juc } } +void LumatoneState::loadPropertiesFile(juce::PropertiesFile *properties) +{ + // No global properties for now +} + void LumatoneState::setConnectedSerialNumber(juce::String serialNumberIn) { connectedSerialNumber = serialNumberIn; diff --git a/Source/lumatone_editor_library/data/lumatone_state.h b/Source/lumatone_editor_library/data/lumatone_state.h index d88b25b..af73b16 100644 --- a/Source/lumatone_editor_library/data/lumatone_state.h +++ b/Source/lumatone_editor_library/data/lumatone_state.h @@ -119,6 +119,8 @@ class LumatoneState : public LumatoneStateBase virtual void handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property) override; + virtual void loadPropertiesFile(juce::PropertiesFile* properties) override; + public: static juce::Array getLumatoneStateProperties(); diff --git a/Source/lumatone_editor_library/data/state_base.cpp b/Source/lumatone_editor_library/data/state_base.cpp index 721e149..921c5fa 100644 --- a/Source/lumatone_editor_library/data/state_base.cpp +++ b/Source/lumatone_editor_library/data/state_base.cpp @@ -10,12 +10,6 @@ #include "state_base.h" -bool LumatoneStateBase::writeToPropertiesFile() -{ - // todo - return false; -} - void LumatoneStateBase::setStateProperty(const juce::Identifier &id, juce::var value) { state.setPropertyExcludingListener(this, id, value, nullptr); @@ -39,21 +33,6 @@ juce::String LumatoneStateBase::getStringProperty(const juce::Identifier key, ju return prop.toString(); } -void LumatoneStateBase::writeBoolProperty(const juce::Identifier key, bool value, juce::UndoManager* undo) -{ - state.setPropertyExcludingListener(this, key, value, undo); -} - -void LumatoneStateBase::writeIntProperty(const juce::Identifier key, int value, juce::UndoManager* undo ) -{ - state.setPropertyExcludingListener(this, key, value, undo); -} - -void LumatoneStateBase::writeStringProperty(const juce::Identifier key, juce::String value, juce::UndoManager* undo) -{ - state.setPropertyExcludingListener(this, key, value, undo); -} - void LumatoneStateBase::valueTreePropertyChanged(juce::ValueTree& treeWhosePropertyHasChanged, const juce::Identifier &property) { handleStatePropertyChange(treeWhosePropertyHasChanged, property); diff --git a/Source/lumatone_editor_library/data/state_base.h b/Source/lumatone_editor_library/data/state_base.h index c6a6153..7c74ce7 100644 --- a/Source/lumatone_editor_library/data/state_base.h +++ b/Source/lumatone_editor_library/data/state_base.h @@ -22,25 +22,20 @@ class LumatoneStateBase : protected juce::ValueTree::Listener int getIntProperty(const juce::Identifier key, int fallback) const; juce::String getStringProperty(const juce::Identifier key, juce::String fallback = juce::String()) const; - virtual bool writeToPropertiesFile(); protected: void setStateProperty(const juce::Identifier& id, juce::var value); -protected: - void writeBoolProperty(const juce::Identifier key, bool value, juce::UndoManager* undo=nullptr); - void writeIntProperty(const juce::Identifier key, int value, juce::UndoManager* undo=nullptr); - void writeStringProperty(const juce::Identifier key, juce::String value, juce::UndoManager* undo=nullptr); - -protected: virtual void valueTreePropertyChanged(juce::ValueTree& treeWhosePropertyHasChanged, const juce::Identifier& property) override; virtual juce::ValueTree loadStateProperties(juce::ValueTree stateIn) = 0; virtual void handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property) = 0; + + virtual void loadPropertiesFile(juce::PropertiesFile* properties) = 0; protected: juce::ValueTree state; juce::String name; }; -#endif LUMATONE_STATE_BASE_H +#endif // LUMATONE_STATE_BASE_H diff --git a/Source/lumatone_editor_library/device/activity_monitor.cpp b/Source/lumatone_editor_library/device/activity_monitor.cpp index 77c6774..e28eb08 100644 --- a/Source/lumatone_editor_library/device/activity_monitor.cpp +++ b/Source/lumatone_editor_library/device/activity_monitor.cpp @@ -38,7 +38,7 @@ DeviceActivityMonitor::~DeviceActivityMonitor() void DeviceActivityMonitor::setDetectDeviceIfDisconnected(bool doDetection) { detectDevicesIfDisconnected = doDetection; - writeBoolProperty(LumatoneApplicationProperty::DetectDeviceIfDisconnected, detectDevicesIfDisconnected); + setStateProperty(LumatoneApplicationProperty::DetectDeviceIfDisconnected, detectDevicesIfDisconnected); if (!detectDevicesIfDisconnected) { @@ -54,7 +54,7 @@ void DeviceActivityMonitor::setDetectDeviceIfDisconnected(bool doDetection) void DeviceActivityMonitor::setCheckForInactivity(bool monitorActivity) { checkConnectionOnInactivity = monitorActivity; - writeBoolProperty(LumatoneApplicationProperty::CheckConnectionIfInactive, checkConnectionOnInactivity); + setStateProperty(LumatoneApplicationProperty::CheckConnectionIfInactive, checkConnectionOnInactivity); if (checkConnectionOnInactivity && isConnectionEstablished()) {