Skip to content

Commit

Permalink
move state response handling to event manager, implement get macro co…
Browse files Browse the repository at this point in the history
…lour callbacks
  • Loading branch information
vsicurella committed Jan 21, 2024
1 parent e287c11 commit ce465ca
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 186 deletions.
54 changes: 23 additions & 31 deletions Source/GlobalSettingsArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "./Settings/SettingsContainer.h"

#include "./lumatone_editor_library/device/lumatone_controller.h"
//[/Headers]

#include "GlobalSettingsArea.h"
Expand Down Expand Up @@ -76,10 +75,12 @@ GlobalSettingsArea::GlobalSettingsArea (const LumatoneEditorState& stateIn)
activeMacroButtonColourEdit.reset(new ColourViewComponent());
addAndMakeVisible(activeMacroButtonColourEdit.get());
activeMacroButtonColourEdit->addChangeListener(this);
activeMacroButtonColourEdit->setColour(getActiveMacroButtonColour().toString(), false);

inactiveMacroButtonColourEdit.reset(new ColourViewComponent());
addAndMakeVisible(inactiveMacroButtonColourEdit.get());
inactiveMacroButtonColourEdit->addChangeListener(this);
inactiveMacroButtonColourEdit->setColour(getInactiveMacroButtonColour().toString(), false);

lblDeveloperMode.reset(new juce::Label("DeveloperModeLabel", "Developer Mode"));
addChildComponent(lblDeveloperMode.get());
Expand All @@ -90,9 +91,18 @@ GlobalSettingsArea::GlobalSettingsArea (const LumatoneEditorState& stateIn)
lblPresetButtonColours->setFont(getAppFonts().getFont(LumatoneEditorFont::UniviaProBold));

addStatusListener(this);
addEditorListener(this);

settingsButton->setEnabled(false);

lblPresetButtonColours->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::LabelPink));

lblColourActiveMacroButton->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::DescriptionText));
lblColourInactiveMacroButton->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::DescriptionText));

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

/* We don't want a resize here
/*
//[/UserPreSize]
Expand Down Expand Up @@ -126,6 +136,16 @@ GlobalSettingsArea::~GlobalSettingsArea()
//[/Destructor]
}

void GlobalSettingsArea::macroButtonInactiveColourChanged(juce::Colour colour)
{
inactiveMacroButtonColourEdit->setColour(colour.toString(), false);
}

void GlobalSettingsArea::macroButtonActiveColourChanged(juce::Colour colour)
{
activeMacroButtonColourEdit->setColour(colour.toString(), false);
}

//==============================================================================
void GlobalSettingsArea::paint (juce::Graphics& g)
{
Expand Down Expand Up @@ -220,46 +240,18 @@ void GlobalSettingsArea::buttonClicked (juce::Button* buttonThatWasClicked)

//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...

void GlobalSettingsArea::lookAndFeelChanged()
{
lblPresetButtonColours->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::LabelPink));

lblColourActiveMacroButton->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::DescriptionText));
lblColourInactiveMacroButton->setColour(Label::ColourIds::textColourId, getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::DescriptionText));

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

void GlobalSettingsArea::changeListenerCallback(ChangeBroadcaster *source)
{
if (source == inactiveMacroButtonColourEdit.get())
{
String inactiveMacroButtonColour = inactiveMacroButtonColourEdit->getColourAsString();
getLumatoneController()->sendMacroButtonInactiveColour(inactiveMacroButtonColour);
setInactiveMacroButtonColour(inactiveMacroButtonColourEdit->getColourAsObject());
}
else if (source == activeMacroButtonColourEdit.get())
{
String activeMacroButtonColour = activeMacroButtonColourEdit->getColourAsString();
getLumatoneController()->sendMacroButtonActiveColour(activeMacroButtonColour);
setActiveMacroButtonColour(activeMacroButtonColourEdit->getColourAsObject());
}
}

void GlobalSettingsArea::restoreStateFromPropertiesFile()
{
inactiveMacroButtonColourEdit->setColour(getProperty(LumatoneEditorProperty::InactiveMacroButtonColour, "000000"));
activeMacroButtonColourEdit->setColour(getProperty(LumatoneEditorProperty::ActiveMacroButtonColour, "FFFFFF"));
}

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

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

void GlobalSettingsArea::listenToColourEditButtons(Button::Listener* listenerIn)
{
inactiveMacroButtonColourEdit->addListener(listenerIn);
Expand Down
14 changes: 6 additions & 8 deletions Source/GlobalSettingsArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "./LumatoneEditorState.h"

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

//[/Headers]
Expand All @@ -43,6 +44,7 @@ class GlobalSettingsArea : public juce::Component,
public LumatoneEditorState,
public ChangeListener,
public LumatoneEditor::StatusListener,
public LumatoneEditor::EditorListener,
public juce::Button::Listener
{
public:
Expand All @@ -54,27 +56,23 @@ class GlobalSettingsArea : public juce::Component,
//[UserMethods] -- You can add your own custom methods in this section.
void changeListenerCallback(ChangeBroadcaster *source) override;

void saveStateToPropertiesFile(PropertiesFile* propertiesFile);

void listenToColourEditButtons(Button::Listener* listenerIn);

void lookAndFeelChanged() override;

void setDeveloperMode(bool devModeOn);

// LumatoneEditor::StatusListener implementation
// void connectionEstablished(int inputDevice, int outputDevice) override;
void connectionStateChanged(ConnectionState newState) override;
// void connectionFailed() override;

// LumatoneEditor::EditorListener implementation
void macroButtonInactiveColourChanged(juce::Colour colour) override;
void macroButtonActiveColourChanged(juce::Colour colour) override;

//[/UserMethods]

void paint (juce::Graphics& g) override;
void resized() override;
void buttonClicked (juce::Button* buttonThatWasClicked) override;

private:
void restoreStateFromPropertiesFile();

private:
//[UserVariables] -- You can add your own custom variables in this section.
Expand Down
2 changes: 1 addition & 1 deletion Source/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ MainContentComponent::~MainContentComponent()
void MainContentComponent::saveStateToPropertiesFile(PropertiesFile* propertiesFile)
{
noteEditArea->saveStateToPropertiesFile(propertiesFile);
globalSettingsArea->saveStateToPropertiesFile(propertiesFile);
// globalSettingsArea->saveStateToPropertiesFile(propertiesFile);
}

// Set the currentSectionKey mapping to be edited to the value passed in parameter
Expand Down
5 changes: 3 additions & 2 deletions Source/colour_view_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void ColourViewComponent::paintButton(juce::Graphics& g, bool shouldDrawButtonAs
g.drawFittedText(getButtonText(), getLocalBounds(), juce::Justification::centred, 1);
}

void ColourViewComponent::setColour(juce::String colourAsString)
void ColourViewComponent::setColour(juce::String colourAsString, bool sendChange)
{
//jassert(colourCombo != nullptr);

Expand All @@ -254,7 +254,8 @@ void ColourViewComponent::setColour(juce::String colourAsString)
repaint();

// Notify parent that value has changed and can be sent to MIDI controller
sendChangeMessage();
if (sendChange)
sendChangeMessage();
}

juce::String ColourViewComponent::getColourAsString()
Expand Down
2 changes: 1 addition & 1 deletion Source/colour_view_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ColourViewComponent : public juce::Button,
//[UserMethods] -- You can add your own custom methods in this section.
//void changeListenerCallback(juce::ChangeBroadcaster *source) override;

void setColour(juce::String colourAsString);
void setColour(juce::String colourAsString, bool sendChangeMessage = true);
juce::String getColourAsString();
int getColourAsNumber();
juce::Colour getColourAsObject();
Expand Down
117 changes: 6 additions & 111 deletions Source/lumatone_editor_library/device/lumatone_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,12 @@ void LumatoneController::requestExpressionPedalSensitivity()
firmwareDriver.sendGetExpressionPedalSensitivity();
}

void LumatoneController::requestMacroButtonColours()
{
if (firmwareSupport.versionAcknowledgesCommand(getLumatoneVersion(), GET_MACRO_LIGHT_INTENSITY))
firmwareDriver.sendGetMacroLightIntensity();
}

bool LumatoneController::connectionConfirmed() const
{
return firmwareDriver.hasDevicesDefined() && currentDevicePairConfirmed;
Expand Down Expand Up @@ -637,114 +643,3 @@ void LumatoneController::pingResponseReceived(unsigned int pingValue)
setConnectionState(ConnectionState::ONLINE);
}
}

void LumatoneController::octaveColourConfigReceived(int boardId, juce::uint8 rgbFlag, const int* colourData)
{
int boardIndex = boardId - 1;

for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++)
{
auto newValue = colourData[keyIndex];

juce::Colour colour = getKey(boardIndex, keyIndex).getColour();
if (rgbFlag == 0)
{
colour = juce::Colour(newValue, colour.getGreen(), colour.getBlue());
}
else if (rgbFlag == 1)
{
colour = juce::Colour(colour.getRed(), newValue, colour.getBlue());
}
else if (rgbFlag == 2)
{
colour = juce::Colour(colour.getRed(), colour.getGreen(), newValue);
}
else
{
jassertfalse;
}

LumatoneState::setKeyColour(colour, boardId, keyIndex);
}

getEditorListeners()->call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex));
}

void LumatoneController::octaveChannelConfigReceived(int boardId, const int* channelData)
{
int boardIndex = boardId - 1;

for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++)
{
juce::uint8 ch = channelData[keyIndex];
if (ch == 0 || ch > 16)
ch = 1;

auto key = getKey(boardIndex, keyIndex);
key.setChannelNumber(ch);
LumatoneState::setKeyConfig(key, boardId, keyIndex);
}

getEditorListeners()->call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex));
}

void LumatoneController::octaveNoteConfigReceived(int boardId, const int* noteData)
{
int boardIndex = boardId - 1;

for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++)
{
int note = noteData[keyIndex];
if (note < 0 || note > 127)
note = 0;

auto key = getKey(boardIndex, keyIndex);
key.setNoteOrCC(noteData[keyIndex]);
LumatoneState::setKeyConfig(key, boardId, keyIndex);
}

getEditorListeners()->call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex));
}

void LumatoneController::keyTypeConfigReceived(int boardId, const int* keyTypeData)
{
int boardIndex = boardId - 1;

for (int keyIndex = 0; keyIndex < getOctaveBoardSize(); keyIndex++)
{
auto type = LumatoneKeyType(keyTypeData[keyIndex]);

auto key = getKey(boardIndex, keyIndex);
key.setKeyType(type);
LumatoneState::setKeyConfig(key, boardId, keyIndex);
}

getEditorListeners()->call(&LumatoneEditor::EditorListener::boardChanged, getBoard(boardIndex));
}

void LumatoneController::macroButtonColoursReceived(juce::Colour inactiveColour, juce::Colour activeColour)
{

}

//void LumatoneController::loadRandomMapping(int testTimeoutMs, int maxIterations, int i)
//{
// auto dir = juce::File::getSpecialLocation(juce::File::SpecialLocationType::userDocumentsDirectory).getChildFile("Lumatone Editor").getChildFile("Mappings");
// auto mappings = dir.findChildFiles(juce::File::TypesOfFileToFind::findFiles, true);
// auto numfiles = mappings.size();
// auto r = juce::Random();
//
// auto fileIndex = r.nextInt(numfiles-1);
// auto file = mappings[fileIndex];
//
// if (file.exists() && file.hasFileExtension(".ltn"))
// {
// DBG("Found " + juce::String(numfiles) + " files, loading " + file.getFileName());
// juce::MessageManager::callAsync([file]() { TerpstraSysExApplication::getApp().setCurrentFile(file); });
// }
//
//// if (i < maxIterations)
//// Timer::callAfterDelay(testTimeoutMs, [&]() { loadRandomMapping(testTimeoutMs, maxIterations, i + 1); });
//// else
//// DBG("Finished random mappings test.");
//}
12 changes: 4 additions & 8 deletions Source/lumatone_editor_library/device/lumatone_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,28 +201,24 @@ class LumatoneController : private LumatoneApplicationState
// Get sensitivity setting of expression pedal
void requestExpressionPedalSensitivity();

// Get preset button light colours
void requestMacroButtonColours();

private:
// juce::ValueTree::Listener implementation

void handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier& property) override;

protected:
//============================================================================
// LumatoneEditor::FirmwareListener implementation
// LumatoneEditor::FirmwareListener implementation - use to establish device connection

void serialIdentityReceived(const int* serialBytes) override;

void firmwareRevisionReceived(LumatoneFirmware::Version version) override;

void pingResponseReceived(unsigned int pingValue) override;

void octaveColourConfigReceived(int boardId, juce::uint8 rgbFlag, const int* colourData) override;
void octaveChannelConfigReceived(int octaveIndex, const int* channelData) override;
void octaveNoteConfigReceived(int octaveIndex, const int* noteData) override;
void keyTypeConfigReceived(int boardId, const int* keyTypeData) override;

void macroButtonColoursReceived(juce::Colour inactiveColour, juce::Colour activeColour) override;

//============================================================================
// Test functions

Expand Down
Loading

0 comments on commit ce465ca

Please sign in to comment.