Skip to content

Commit

Permalink
reimplement some property recall via state change callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed Jan 8, 2024
1 parent d7719d9 commit ef45d80
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 369 deletions.
44 changes: 22 additions & 22 deletions Source/GlobalSettingsArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ GlobalSettingsArea::GlobalSettingsArea (const LumatoneEditorState& stateIn)
lblColourActiveMacroButton->setColour (juce::TextEditor::textColourId, juce::Colours::black);
lblColourActiveMacroButton->setColour (juce::TextEditor::backgroundColourId, juce::Colour (0x00000000));

buttonCalibrate.reset (new juce::TextButton ("buttonCalibrate"));
addAndMakeVisible (buttonCalibrate.get());
buttonCalibrate->setTooltip (TRANS("Show controls for calibration, setting controller MIDI channels, and updating firmware"));
buttonCalibrate->setButtonText (TRANS("Settings"));
buttonCalibrate->addListener (this);
settingsButton.reset (new juce::TextButton ("buttonCalibrate"));
addAndMakeVisible (settingsButton.get());
settingsButton->setTooltip (TRANS("Show controls for calibration, setting controller MIDI channels, and updating firmware"));
settingsButton->setButtonText (TRANS("Settings"));
settingsButton->addListener (this);


//[UserPreSize]
Expand All @@ -91,7 +91,7 @@ GlobalSettingsArea::GlobalSettingsArea (const LumatoneEditorState& stateIn)

addStatusListener(this);

buttonCalibrate->setEnabled(false);
settingsButton->setEnabled(false);

/* We don't want a resize here
/*
Expand Down Expand Up @@ -119,7 +119,7 @@ GlobalSettingsArea::~GlobalSettingsArea()
lblPresetButtonColours = nullptr;
lblColourInactiveMacroButton = nullptr;
lblColourActiveMacroButton = nullptr;
buttonCalibrate = nullptr;
settingsButton = nullptr;


//[Destructor]. You can add your own custom destruction code here..
Expand All @@ -143,10 +143,10 @@ void GlobalSettingsArea::resized()
// Build right-to-left

int calbrateBtnHeight = roundToInt(getHeight() * calibrateHeight);
int calibrateWidth = getLookAndFeel().getTextButtonWidthToFitText(*buttonCalibrate, calbrateBtnHeight);
int calibrateWidth = getLookAndFeel().getTextButtonWidthToFitText(*settingsButton, calbrateBtnHeight);

buttonCalibrate->setSize(calibrateWidth, calbrateBtnHeight);
buttonCalibrate->setTopRightPosition(getWidth(), roundToInt((getHeight() - buttonCalibrate->getHeight()) * 0.5f));
settingsButton->setSize(calibrateWidth, calbrateBtnHeight);
settingsButton->setTopRightPosition(getWidth(), roundToInt((getHeight() - settingsButton->getHeight()) * 0.5f));

float margin = roundToInt(getHeight() * 0.1f);
float colourEditHeight = proportionOfHeight(controlsHeight);
Expand All @@ -156,7 +156,7 @@ void GlobalSettingsArea::resized()

lblColourInactiveMacroButton->setFont(colourLabelsFont);
resizeLabelWithHeight(lblColourInactiveMacroButton.get(), colourEditHeight);
lblColourInactiveMacroButton->setTopRightPosition(buttonCalibrate->getX() - margin, controlY);
lblColourInactiveMacroButton->setTopRightPosition(settingsButton->getX() - margin, controlY);

inactiveMacroButtonColourEdit->setSize(colourButtonWidth, colourEditHeight);
inactiveMacroButtonColourEdit->setTopRightPosition(lblColourInactiveMacroButton->getX() - margin, controlY);
Expand Down Expand Up @@ -185,7 +185,7 @@ void GlobalSettingsArea::buttonClicked (juce::Button* buttonThatWasClicked)
//[UserbuttonClicked_Pre]
//[/UserbuttonClicked_Pre]

if (buttonThatWasClicked == buttonCalibrate.get())
if (buttonThatWasClicked == settingsButton.get())
{
//[UserButtonCode_buttonCalibrate] -- add your button handler code here..

Expand Down Expand Up @@ -227,8 +227,8 @@ void GlobalSettingsArea::lookAndFeelChanged()
lblColourActiveMacroButton->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::DescriptionText));
lblColourInactiveMacroButton->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::DescriptionText));

buttonCalibrate->setColour(TextButton::ColourIds::buttonColourId, Colour(0xff383b3d));
buttonCalibrate->setColour(TextButton::ColourIds::textColourOffId, Colour(0xffffffff));
settingsButton->setColour(TextButton::ColourIds::buttonColourId, Colour(0xff383b3d));
settingsButton->setColour(TextButton::ColourIds::textColourOffId, Colour(0xffffffff));
}

void GlobalSettingsArea::changeListenerCallback(ChangeBroadcaster *source)
Expand All @@ -248,19 +248,19 @@ void GlobalSettingsArea::changeListenerCallback(ChangeBroadcaster *source)
void GlobalSettingsArea::restoreStateFromPropertiesFile(PropertiesFile* propertiesFile)
{
inactiveMacroButtonColourEdit->setColour(
propertiesFile->getValue("InactiveMacroButtonColour", "000000"));
propertiesFile->getValue(LumatoneEditorProperty::InactiveMacroButtonColour, "000000"));

activeMacroButtonColourEdit->setColour(
propertiesFile->getValue("ActiveMacroButtonColour", "FFFFFF"));
propertiesFile->getValue(LumatoneEditorProperty::ActiveMacroButtonColour, "FFFFFF"));
}

void GlobalSettingsArea::saveStateToPropertiesFile(PropertiesFile* propertiesFile)
{
String inactiveMacroButtonColour = inactiveMacroButtonColourEdit->getColourAsString();
propertiesFile->setValue("InactiveMacroButtonColour", inactiveMacroButtonColour);
propertiesFile->setValue(LumatoneEditorProperty::InactiveMacroButtonColour, inactiveMacroButtonColour);

String activeMacroButtonColour = activeMacroButtonColourEdit->getColourAsString();
propertiesFile->setValue("ActiveMacroButtonColour", activeMacroButtonColour);
propertiesFile->setValue(LumatoneEditorProperty::ActiveMacroButtonColour, activeMacroButtonColour);
}

void GlobalSettingsArea::listenToColourEditButtons(Button::Listener* listenerIn)
Expand All @@ -274,18 +274,18 @@ void GlobalSettingsArea::setDeveloperMode(bool devModeOn)
showDeveloperMode = devModeOn;
lblDeveloperMode->setVisible(showDeveloperMode);
if (devModeOn)
buttonCalibrate->setEnabled(true);
settingsButton->setEnabled(true);
repaint();
}

void GlobalSettingsArea::connectionStateChanged(ConnectionState state)
{
buttonCalibrate->setEnabled(state == ConnectionState::ONLINE);
settingsButton->setEnabled(state == ConnectionState::ONLINE);
}

// void GlobalSettingsArea::connectionFaile()
// {
// buttonCalibrate->setEnabled(false);
// settingsButton->setEnabled(false);
// }

//[/MiscUserCode]
Expand Down Expand Up @@ -321,7 +321,7 @@ BEGIN_JUCER_METADATA
edBkgCol="0" labelText="active" editableSingleClick="0" editableDoubleClick="0"
focusDiscardsChanges="0" fontname="Default font" fontsize="15.0"
kerning="0.0" bold="0" italic="0" justification="33"/>
<TEXTBUTTON name="buttonCalibrate" id="47242594c34a8de9" memberName="buttonCalibrate"
<TEXTBUTTON name="settingsButton" id="47242594c34a8de9" memberName="settingsButton"
virtualName="" explicitFocusOrder="0" pos="336 8 112 24" tooltip="Show controls for calibration, setting controller MIDI channels, and updating firmware"
buttonText="Settings" connectedEdges="0" needsCallback="1" radioGroupId="0"/>
</JUCER_COMPONENT>
Expand Down
2 changes: 1 addition & 1 deletion Source/GlobalSettingsArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class GlobalSettingsArea : public juce::Component,
std::unique_ptr<juce::Label> lblPresetButtonColours;
std::unique_ptr<juce::Label> lblColourInactiveMacroButton;
std::unique_ptr<juce::Label> lblColourActiveMacroButton;
std::unique_ptr<juce::TextButton> buttonCalibrate;
std::unique_ptr<juce::TextButton> settingsButton;


//==============================================================================
Expand Down
29 changes: 4 additions & 25 deletions Source/LumatoneEditorState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ juce::ValueTree LumatoneEditorState::loadStateProperties(juce::ValueTree stateIn

void LumatoneEditorState::handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier &property)
{
LumatoneApplicationState::handleStatePropertyChange(stateIn, property);

if (property == LumatoneEditorProperty::HasChangesToSave)
{
hasChangesToSave = (bool)stateIn[property];
Expand All @@ -219,41 +221,18 @@ void LumatoneEditorState::handleStatePropertyChange(juce::ValueTree stateIn, con
else if (property == LumatoneEditorProperty::FirmwareUpdatePerformed)
{
firmwareUpdateWasPerformed = (bool)stateIn[property];
}
else if (property == LumatoneEditorProperty::ColourPalettes)
{

}
else if (property == LumatoneEditorProperty::CurrentFile)
{
currentFile = juce::File(stateIn[property]);
}
else if (property == LumatoneEditorProperty::RecentFiles)
{
}
else if (property == LumatoneEditorProperty::UserDocumentsDirectory)
{

}
else if (property == LumatoneEditorProperty::UserMappingsDirectory)
{

}
else if (property == LumatoneEditorProperty::UserPalettesDirectory)
{

}
else if (property == LumatoneEditorProperty::DeveloperModeOn)
{

inDeveloperMode = (bool)stateIn[property];
}
else if (property == LumatoneEditorProperty::EditorMode)
{

}
else
{
LumatoneApplicationState::handleStatePropertyChange(stateIn, property);
editorMode = EditorMode((int)stateIn[property]);
}
}

Expand Down
5 changes: 5 additions & 0 deletions Source/LumatoneEditorState.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ namespace LumatoneEditorProperty
static const juce::Identifier InCalibrationMode = juce::Identifier("InCalibrationMode");
static const juce::Identifier FirmwareUpdatePerformed = juce::Identifier("FirmwareUpdatePerformed");

static const juce::Identifier InactiveMacroButtonColour = juce::Identifier("InactiveMacroButtonColour");
static const juce::Identifier ActiveMacroButtonColour = juce::Identifier("ActiveMacroButtonColour");

static const juce::Identifier ColourPalettes = juce::Identifier("ColourPalettes");

static const juce::Identifier CurrentFile = juce::Identifier("CurrentFile");
Expand All @@ -55,6 +58,8 @@ namespace LumatoneEditorProperty
static const juce::Identifier SingleNoteColourSetActive = juce::Identifier("SingleNoteColourSetActive");
static const juce::Identifier SingleNoteKeyTypeSetActive = juce::Identifier("SingleNoteKeyTypeSetActive");

static const juce::Identifier IsomorphicMassAssign = juce::Identifier("IsomorphicMassAssign");

static const juce::Identifier LastSettingsPanel = juce::Identifier("LastSettingsPanel");

}
Expand Down
2 changes: 1 addition & 1 deletion Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ bool TerpstraSysExApplication::performUndoableAction(UndoableAction* editAction,
if (undoManager.perform(editAction)) // UndoManager will check for nullptr and also for disposing of the object
{
// setHasChangesToSave(true);
((MainContentComponent*)(mainWindow->getContentComponent()))->refreshAllFields();
//((MainContentComponent*)(mainWindow->getContentComponent()))->refreshAllFields();
return true;
}
}
Expand Down
Loading

0 comments on commit ef45d80

Please sign in to comment.