Skip to content

Commit

Permalink
fix main window title new file callback, add controller methods for s…
Browse files Browse the repository at this point in the history
…aving properties to file
  • Loading branch information
vsicurella committed Jan 26, 2024
1 parent b4c8b30 commit e532408
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
33 changes: 24 additions & 9 deletions Source/LumatoneEditorState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "./KeyEditComponent.h"

#include "./lumatone_editor_library/device/lumatone_controller.h"
#include "./lumatone_editor_library/listeners/editor_listener.h"

juce::Array<juce::Identifier> GetLumatoneEditorProperty()
{
Expand Down Expand Up @@ -283,6 +284,8 @@ bool LumatoneEditorState::Controller::performAction(LumatoneAction *action, bool
// Open a SysEx mapping from the file specified in currentFile
bool LumatoneEditorState::Controller::resetToCurrentFile()
{
getEditorListeners()->call(&LumatoneEditor::EditorListener::newFileLoaded, editorState.getCurrentFile());

if (editorState.getCurrentFile().getFullPathName().isEmpty())
{
// Replace with blank file
Expand All @@ -299,12 +302,6 @@ bool LumatoneEditorState::Controller::resetToCurrentFile()
editorState.getCurrentFile().readLines(stringArray);
LumatoneLayout keyMapping(stringArray);

// ((MainContentComponent*)(mainWindow->getContentComponent()))->setData(keyMapping);

// TODO FIX
// Window title
// updateMainTitle();

// Send configuration to controller, if connected
editorState.setCompleteConfig(keyMapping);

Expand All @@ -330,7 +327,7 @@ bool LumatoneEditorState::Controller::resetToCurrentFile()
bool LumatoneEditorState::Controller::setCurrentFile(File fileToOpen)
{
editorState.currentFile = fileToOpen;
// editorState.setPropertyExcludingListener(this, LumatoneEditorProperty::CurrentFile, editorState.currentFile.getFullPathName(), nullptr);
editorState.state.setPropertyExcludingListener(&editorState, LumatoneEditorProperty::CurrentFile, editorState.currentFile.getFullPathName(), nullptr);
return resetToCurrentFile();
}

Expand Down Expand Up @@ -387,17 +384,35 @@ bool LumatoneEditorState::Controller::savePropertiesFile() const
return editorState.propertiesFile->saveIfNeeded();
}

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

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

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

void LumatoneEditorState::Controller::setCalibrationMode(bool calibrationModeOn)
{
editorState.inCalibrationMode = calibrationModeOn;
editorState.getLumatoneController()->setCalibratePitchModWheel(calibrationModeOn);
// writeBoolProperty(LumatoneEditorProperty::InCalibrationMode, calibrationModeOn, nullptr);
editorState.setStateProperty(LumatoneEditorProperty::InCalibrationMode, editorState.inCalibrationMode);
savePropertyBoolValue(LumatoneEditorProperty::InCalibrationMode, calibrationModeOn);
}

void LumatoneEditorState::Controller::setDeveloperMode(bool developerModeOn)
{
editorState.inDeveloperMode = developerModeOn;
// writeBoolProperty(LumatoneEditorProperty::DeveloperModeOn, inDeveloperMode, undoManager);
editorState.setStateProperty(LumatoneEditorProperty::DeveloperModeOn, editorState.inDeveloperMode);
savePropertyBoolValue(LumatoneEditorProperty::DeveloperModeOn, developerModeOn);
}
9 changes: 7 additions & 2 deletions Source/LumatoneEditorState.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class LumatoneEditorState : public LumatoneApplicationState
juce::File currentFile;
std::shared_ptr<juce::RecentlyOpenedFilesList> recentFiles;

std::shared_ptr<juce::PropertiesFile> propertiesFile; // TODO move to state base?
std::shared_ptr<juce::PropertiesFile> propertiesFile;

//================================================================================
public:
Expand All @@ -144,7 +144,7 @@ class LumatoneEditorState : public LumatoneApplicationState
bool resetToCurrentFile();
bool openRecentFile(int recentFileIndex);

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

void addPalette(const LumatoneEditorColourPalette& newPalette);
bool deletePaletteFile(juce::File pathToPalette);
Expand All @@ -158,6 +158,11 @@ class LumatoneEditorState : public LumatoneApplicationState
juce::PropertiesFile* getPropertiesFile() const { return editorState.propertiesFile.get(); }
bool savePropertiesFile() const;

// Sets a property in the juce::PropertyFile and saves it to file
void savePropertyBoolValue(const juce::Identifier& id, bool value);
void savePropertyIntValue(const juce::Identifier& id, int value);
void savePropertyStringValue(const juce::Identifier& id, juce::String value);

void setHasChangesToSave(bool hasChanges) { editorState.setHasChangesToSave(hasChanges); }
void setCalibrationMode(bool calibrationModeOn);
void setDeveloperMode(bool developerModeOn);
Expand Down
12 changes: 11 additions & 1 deletion Source/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "MainWindow.h"
#include "MainComponent.h"

#include "LumatoneMenu.h"

#include "LumatoneEditorLookAndFeel.h"
#include "./lumatone_editor_library/palettes/colour_palette_file.h"

Expand Down Expand Up @@ -52,12 +54,15 @@ MainWindow::MainWindow(const LumatoneEditorState& stateIn, juce::ApplicationComm
addKeyListener(commandManager->getKeyMappings());
updateBounds();

addEditorListener(this);

startTimer(2000);
#endif
}

MainWindow::~MainWindow()
{
removeEditorListener(this);
removeKeyListener(commandManager->getKeyMappings());

#if JUCE_MAC
Expand Down Expand Up @@ -183,7 +188,7 @@ void MainWindow::updateTitle()
{
juce::String windowTitle("Lumatone Editor");

if (!getCurrentFile().getFileName().isEmpty())
if (getCurrentFile().getFileName().isNotEmpty())
windowTitle << " - " << getCurrentFile().getFileName();

if (getHasChangesToSave())
Expand All @@ -192,6 +197,11 @@ void MainWindow::updateTitle()
setName(windowTitle);
}

void MainWindow::newFileLoaded(juce::File file)
{
updateTitle();
}

void MainWindow::handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier &property)
{
LumatoneEditorState::handleStatePropertyChange(stateIn, property);
Expand Down
15 changes: 14 additions & 1 deletion Source/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@
#pragma once
#include <JuceHeader.h>

#include "LumatoneMenu.h"
#include "LumatoneEditorState.h"

#include "./lumatone_editor_library/listeners/editor_listener.h"

namespace Lumatone
{
namespace Menu
{
class MainMenuModel;
}
}

//==============================================================================
/*
This class implements the desktop window that contains an instance of
Expand All @@ -21,6 +30,7 @@ our MainContentComponent class.
class MainWindow : public juce::DocumentWindow
, public LumatoneEditorState
, private LumatoneEditorState::Controller
, private LumatoneEditor::EditorListener
, private juce::Timer
{
public:
Expand Down Expand Up @@ -61,6 +71,9 @@ class MainWindow : public juce::DocumentWindow

void updateTitle();

// LumatoneEditor::EditorListener implementation
void newFileLoaded(juce::File file) override;

private:

void handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier &property) override;
Expand Down
2 changes: 2 additions & 0 deletions Source/lumatone_editor_library/listeners/editor_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class EditorListener

virtual void selectionChanged(juce::Array<MappedLumatoneKey> selection) {}

virtual void newFileLoaded(juce::File file) {}

//virtual void tableChanged(LumatoneConfigTable::TableType type, const juce::uint8* table, int tableSize) {}

virtual void contextChanged(LumatoneContext* context) {}
Expand Down

0 comments on commit e532408

Please sign in to comment.