Skip to content

Commit

Permalink
implement color group selection, key assignment, some key editor UI i…
Browse files Browse the repository at this point in the history
…mprovements
  • Loading branch information
vsicurella committed Jul 8, 2024
1 parent 43439c4 commit 134f450
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 49 deletions.
54 changes: 47 additions & 7 deletions Source/ColourPaletteWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ ColourPaletteWindow::ColourPaletteWindow(const LumatoneEditorState& stateIn)
setName("ColourPaletteWindow");
setLookAndFeel(&getEditorLookAndFeel());

colourSelectorGroup.reset(new ColourSelectionGroup());

loadColourPalettesFromFile();

colourSelectorGroup.reset(new ColourSelectionGroup());

palettePanel.reset(new ColourPalettesPanel(getColourPalettes(), colourSelectorGroup.get()));
palettePanel->addListener(this);

Expand All @@ -50,7 +50,7 @@ ColourPaletteWindow::ColourPaletteWindow(const LumatoneEditorState& stateIn)
colourToolTabs->addTab(juce::translate("ColourPalettes"), juce::Colour(), palettePanelViewport.get(), false);
colourToolTabs->addTab(juce::translate("CustomPicker"), juce::Colour(), customPickerPanel.get(), false);
colourToolTabs->setColour(juce::TabbedComponent::ColourIds::outlineColourId, juce::Colour());
colourToolTabs->getTabbedButtonBar().getProperties().set(LumatoneEditorStyleIDs::fontHeightScalar, 0.9f);
colourToolTabs->getTabbedButtonBar().getProperties().set(LumatoneEditorStyleIDs::fontHeightScalar, 0.75f);
addAndMakeVisible(*colourToolTabs);

const int firstTabIndex = getProperty(LumatoneEditorProperty::LastColourWindowTab, "0").getIntValue();
Expand All @@ -60,24 +60,44 @@ ColourPaletteWindow::ColourPaletteWindow(const LumatoneEditorState& stateIn)

ColourPaletteWindow::~ColourPaletteWindow()
{
setLookAndFeel(nullptr);

paletteEditPanel = nullptr;

colourToolTabs = nullptr;

colourSelectorGroup->removeSelector(customPickerPanel.get());
customPickerPanel = nullptr;

palettePanelViewport = nullptr;
palettePanel = nullptr;

colourSelectorGroup = nullptr;
}

setLookAndFeel(nullptr);
void ColourPaletteWindow::paint(juce::Graphics &g)
{
g.setColour(backgroundColour);

auto controlBounds = getLocalBounds().toFloat()
.withTop(colourToolTabs->getTabbedButtonBar().getHeight())
.withTrimmedTop(indent)
.withTrimmedBottom(indent);

g.fillRoundedRectangle(controlBounds, getRoundedRectCornerSize());
}

void ColourPaletteWindow::resized()
{
palettePanelViewport->setScrollBarThickness(proportionOfWidth(viewportScrollbarWidthScalar));

colourToolTabs->setIndent(indent);
colourToolTabs->setTabBarDepth(tabBarDepth);
colourToolTabs->setBounds(getLocalBounds());


// colourToolTabs->setIndent(indent);

if (paletteEditPanel.get())
paletteEditPanel->setBounds(getLocalBounds());

Expand All @@ -102,7 +122,7 @@ void ColourPaletteWindow::duplicatePalette(int paletteIndexIn)
{
auto colourPalettes = getColourPalettes();
auto copiedPalette = getColourPalettes()[paletteIndexIn].clone();

if (! copiedPalette.saveToFile())
return; // TODO

Expand All @@ -117,7 +137,7 @@ void ColourPaletteWindow::removePalette(int paletteIndexToRemove)
// Remove loaded colour palette
auto colourPalettes = getColourPalettes();
auto deletedPalette = colourPalettes[paletteIndexToRemove];

if (!deletedPalette.deleteFile())
return; // TODO

Expand Down Expand Up @@ -166,7 +186,7 @@ void ColourPaletteWindow::newPaletteRequested()
auto newPalette = LumatoneEditorColourPalette();
newPalette.saveToFile();
colourPalettes.insert(0, newPalette);

setColourPalettes(colourPalettes);
startEditingPalette(0, 0);
}
Expand Down Expand Up @@ -210,3 +230,23 @@ void ColourPaletteWindow::changeListenerCallback(juce::ChangeBroadcaster* source
getPropertiesFile()->setValue(LumatoneEditorProperty::LastColourWindowTab, juce::String(newTab));
}
}

void ColourPaletteWindow::setIndentSize(int size, bool resize)
{
indent = size;
if (resize)
resized();
}

void ColourPaletteWindow::setTabBarDepth(int height, bool resize)
{
tabBarDepth = height;
if (resize)
resized();
}

void ColourPaletteWindow::setBackgroundColour(juce::Colour backgroundIn)
{
backgroundColour = backgroundIn;
repaint();
}
26 changes: 19 additions & 7 deletions Source/ColourPaletteWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ class ColourPaletteWindow : public juce::Component
ColourPaletteWindow(const LumatoneEditorState& stateIn);
~ColourPaletteWindow() override;

void paint(juce::Graphics& g) override;

void resized() override;

void changeListenerCallback(juce::ChangeBroadcaster* source) override;

void setIndentSize(int size, bool resize=true);
void setTabBarDepth(int height, bool resize=true);

void setBackgroundColour(juce::Colour backgroundIn);

//====================================================================

/// <summary>
Expand Down Expand Up @@ -67,6 +74,8 @@ class ColourPaletteWindow : public juce::Component
colourSelectorGroup->setCurrentSelector(newSelector);
}

ColourSelectionGroup* getColourSelectionGroup() { return colourSelectorGroup.get(); }

private:

/// <summary>
Expand Down Expand Up @@ -99,23 +108,26 @@ class ColourPaletteWindow : public juce::Component

private:

// LumatoneEditorLookAndFeel lookAndFeel;

//juce::Array<LumatoneEditorColourPalette>& colourPalettes;
std::unique_ptr<ColourSelectionGroup> colourSelectorGroup;

std::unique_ptr<juce::TabbedComponent> colourToolTabs;
std::unique_ptr<ColourPalettesPanel> palettePanel;
std::unique_ptr<juce::Viewport> palettePanelViewport;

std::unique_ptr<CustomPickerPanel> customPickerPanel;
std::unique_ptr<PaletteEditPanel> paletteEditPanel;

std::unique_ptr<juce::Viewport> palettePanelViewport;
std::unique_ptr<juce::TabbedComponent> colourToolTabs;

std::unique_ptr<ColourSelectionGroup> colourSelectorGroup;
std::unique_ptr<PaletteEditPanel> paletteEditPanel;

int paletteIndexEditing = -1;
bool paletteEditingIsNew = false;

int indent = 48;
int tabBarDepth = 48;

const float viewportScrollbarWidthScalar = 0.020833f;

juce::Colour backgroundColour;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ColourPaletteWindow)
};
2 changes: 2 additions & 0 deletions Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ void TerpstraSysExApplication::initialise(const String& commandLine)

void TerpstraSysExApplication::shutdown()
{
undoManager.clearUndoHistory();

LocalisedStrings::setCurrentMappings(nullptr);

// Save state of main window
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ColourSelectionGroup : public ColourSelectionBroadcaster,

~ColourSelectionGroup()
{
selectorListeners.clear();

for (auto selector : colourSelectors)
selector->removeColourSelectionListener(this);
}
Expand Down
69 changes: 57 additions & 12 deletions Source/mapping_editors/KeyEditorControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
#include "../ColourPaletteWindow.h"
// #include "../lumatone_editor_library/palettes/palette_selection_panel.h"
#include "../lumatone_editor_library/palettes/colour_picker_panel.h"
#include "../lumatone_editor_library/palettes/colour_selection_group.h"

#include "../actions/EditorControlActions.h"

#include "../components/RangedControl.h"

#include "../actions/EditorControlActions.h"


KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn)
: juce::Component("KeyEditorControls")
, LumatoneEditorState("KeyEditorControls", stateIn)
Expand Down Expand Up @@ -50,7 +54,8 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn)
keyTypeCombo->addItem (juce::translate("Disabled"), (int)LumatoneKeyType::disabled);
keyTypeCombo->onChange = [&]()
{
performAction(SetKeySettingsAction::NewSetAssignKeyTypeAction(*this, LumatoneKeyType(keyTypeCombo->getSelectedId() - 1)));
performAction(SetKeySettingsAction::NewSetAssignKeyTypeAction(*this, LumatoneKeyType(keyTypeCombo->getSelectedId())));
performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys()));
};
addAndMakeVisible(keyTypeCombo.get());

Expand All @@ -59,13 +64,15 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn)
noteInput->setValueChangedCallback([&]()
{
performAction(SetKeySettingsAction::NewSetAssignKeyNoteAction(*this, (int)noteInput->getValue()));
performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys()));
});
addAndMakeVisible(noteInput.get());

channelInput = std::make_unique<RangedControl>("channelInput", 1, 16, RangedControl::Style::IncDecButtons);
channelInput->setValueChangedCallback([&]()
{
performAction(SetKeySettingsAction::NewSetAssignKeyChannelAction(*this, (int)channelInput->getValue()));
performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys()));
});
addAndMakeVisible(channelInput.get());

Expand Down Expand Up @@ -94,23 +101,42 @@ KeyEditorControls::KeyEditorControls(const LumatoneEditorState& stateIn)
addAndMakeVisible(lblChannel.get());

colourPalettePanel = std::make_unique<ColourPaletteWindow>(stateIn);
colourPalettePanel->setBackgroundColour(getEditorLookAndFeel().findColour(LumatoneEditorColourIDs::ColourPaletteBackground));
// colourPalettePanel->setColourSelectionGroup(group);
addAndMakeVisible(colourPalettePanel.get());
// colourPalettePanel->addColourSelectorToGroup(colourSelectionGroup.get());

// ColourSelectionGroup* group = new ColourSelectionGroup("KeyEditorControlColour");
colourSelectionGroup = colourPalettePanel->getColourSelectionGroup();
// colourSelectionGroup = std::make_unique<ColourSelectionGroup>("KeyEditorControlColour");
colourSelectionGroup->addSelector(colourTextEditor.get());
colourSelectionGroup->addColourSelectionListener(colourSubwindow.get());
colourSelectionGroup->addColourSelectionListener(colourTextEditor.get());
colourSelectionGroup->addColourSelectionListener(this);
// group->addSelector(colourTextEditor.get());
// group->addColourSelectionListener(colourSubwindow.get());
// group->addColourSelectionListener(colourTextEditor.get());

addEditorListener(this);
}

KeyEditorControls::~KeyEditorControls()
{
colourControlTabs = nullptr;
colourPickerPanel = nullptr;
colourSelectionGroup = nullptr;
colourPalettePanel = nullptr;

lblChannel = nullptr;
lblNote = nullptr;
lblKeyType = nullptr;
lblColour = nullptr;

channelInput = nullptr;
noteInput = nullptr;
keyTypeCombo = nullptr;
// colourPickerToggle = nullptr;

colourSubwindow = nullptr;
colourTextEditor = nullptr;

lblKeySettings = nullptr;
}

Expand Down Expand Up @@ -173,7 +199,9 @@ void KeyEditorControls::resized()
colourColumnWidth = w - colourColumnX - contentMarginWidth;
colourColumnHeight = roundToInt(h * colourColumnH);

colourPalettePanel->setBounds(colourColumnX, 0, colourColumnWidth, h - contentMarginHeight);
colourPalettePanel->setBounds(colourColumnX, 0, colourColumnWidth, h);
colourPalettePanel->setIndentSize(contentMarginHeight, false);
colourPalettePanel->setTabBarDepth(headerHeight, false);
}

void KeyEditorControls::selectionChanged()
Expand All @@ -182,26 +210,35 @@ void KeyEditorControls::selectionChanged()
auto newData = LumatoneEditSelectionState::findSharedSelectionProperties(*getSelectedKeys());

if (newData.setColour)
colourTextEditor->setText(newData.colour.toDisplayString(false));
{
setAssignKeyColour(newData.setColour, newData.colour);
// performAction(SetKeySettingsAction::NewSetAssignColourAction(*this, newData.colour), true, false);
colourSubwindow->setColour(newData.colour.toString(), false);
if (newData.colour.isTransparent())
colourTextEditor->setText("", juce::NotificationType::dontSendNotification);
else
colourTextEditor->setText(newData.colour.toDisplayString(false), juce::NotificationType::dontSendNotification);
}
else
colourTextEditor->clear();
{
colourSubwindow->setColour("", false);
colourTextEditor->setText("", juce::NotificationType::dontSendNotification);
}

if (newData.setType)
keyTypeCombo->setSelectedId((int)newData.type, juce::NotificationType::dontSendNotification);
else
keyTypeCombo->setSelectedId(0, juce::NotificationType::dontSendNotification);

if (newData.setNote)
noteInput->setValue(newData.note);
noteInput->setValue(newData.note, juce::NotificationType::dontSendNotification);
else
noteInput->setValue(-1, juce::NotificationType::dontSendNotification);

if (newData.setChannel)
channelInput->setValue(newData.channel);
channelInput->setValue(newData.channel, juce::NotificationType::dontSendNotification);
else
channelInput->setValue(-1, juce::NotificationType::dontSendNotification);


}

void KeyEditorControls::handleStatePropertyChange(juce::ValueTree stateIn, const juce::Identifier &property)
Expand All @@ -212,7 +249,9 @@ void KeyEditorControls::handleStatePropertyChange(juce::ValueTree stateIn, const

if (property == LumatoneEditSelectionProperty::AssignKeyColour)
{

auto colourString = stateIn[property].toString();
colourTextEditor->setText(colourString, juce::NotificationType::dontSendNotification);
colourSubwindow->setColour(colourString, false);
}
else if (property == LumatoneEditSelectionProperty::AssignKeyType)
{
Expand All @@ -231,3 +270,9 @@ void KeyEditorControls::handleStatePropertyChange(juce::ValueTree stateIn, const

}
}

void KeyEditorControls::colourChangedCallback(ColourSelectionBroadcaster *source, juce::Colour newColour)
{
performAction(SetKeySettingsAction::NewSetAssignColourAction(*this, newColour));
performAction(new ApplyAssignmentsToSelectionAction(*this, getEditSelectionData(), *getSelectedKeys()), true, false);
}
Loading

0 comments on commit 134f450

Please sign in to comment.