Skip to content

Commit

Permalink
feat(control setting panel): add control setting import/export
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Dec 26, 2024
1 parent 207275b commit 8c86fc8
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 23 deletions.
5 changes: 1 addition & 4 deletions source/gui/label/name_look_and_feel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace zlInterface {
bound.removeFromBottom(dPadding.load());
bound.removeFromLeft(lPadding.load());
bound.removeFromRight(rPadding.load());
g.drawText(label.getText(), bound, justification.load());
g.drawText(label.getText(), bound, label.getJustificationType());
}

inline void setEditable(const bool f) { editable.store(f); }
Expand All @@ -45,8 +45,6 @@ namespace zlInterface {

inline void setFontScale(const float x) { fontScale.store(x); }

inline void setJustification(const juce::Justification j) { justification.store(j); }

inline void setPadding(const float l, const float r, const float u, const float d) {
lPadding.store(l);
rPadding.store(r);
Expand All @@ -58,7 +56,6 @@ namespace zlInterface {
std::atomic<bool> editable{true};
std::atomic<float> alpha{1.f};
std::atomic<float> fontScale{FontNormal};
std::atomic<juce::Justification> justification{juce::Justification::centred};
std::atomic<float> lPadding{0.f}, rPadding{0.f}, uPadding{0.f}, dPadding{0.f};

UIBase *uiBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace zlInterface {
addAndMakeVisible(slider);

text.setText(getDisplayValue(slider), juce::dontSendNotification);
text.setJustificationType(juce::Justification::centred);
textLookAndFeel.setAlpha(0.f);
textLookAndFeel.setFontScale(FontHuge);
text.setLookAndFeel(&textLookAndFeel);
Expand All @@ -37,6 +38,7 @@ namespace zlInterface {

// setup label
label.setText(labelText, juce::dontSendNotification);
label.setJustificationType(juce::Justification::centred);
label.setLookAndFeel(&nameLookAndFeel);
nameLookAndFeel.setFontScale(FontHuge);
label.setInterceptsMouseClicks(false, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ namespace zlInterface {
addAndMakeVisible(slider2);

label.setText(labelText, juce::dontSendNotification);
label.setJustificationType(juce::Justification::centred);
label1.setText(getDisplayValue(slider1), juce::dontSendNotification);
label2.setText(getDisplayValue(slider2), juce::dontSendNotification);

labelLookAndFeel.setFontScale(1.75f);
labelLookAndFeel1.setFontScale(FontHuge);
labelLookAndFeel1.setJustification(juce::Justification::centredBottom);
label1.setJustificationType(juce::Justification::centredBottom);
labelLookAndFeel1.setAlpha(0.f);
labelLookAndFeel2.setFontScale(FontHuge);
labelLookAndFeel2.setJustification(juce::Justification::centredTop);
label2.setJustificationType(juce::Justification::centredTop);
labelLookAndFeel2.setAlpha(0.f);

label.setLookAndFeel(&labelLookAndFeel);
Expand Down Expand Up @@ -110,14 +111,14 @@ namespace zlInterface {
const auto valueBound2 = labelBound;
label1.setBounds(valueBound1.toNearestInt());
label2.setBounds(valueBound2.toNearestInt());
labelLookAndFeel1.setJustification(juce::Justification::centredBottom);
labelLookAndFeel2.setJustification(juce::Justification::centredTop);
label1.setJustificationType(juce::Justification::centredBottom);
label2.setJustificationType(juce::Justification::centredTop);
} else {
slider2LAF.setEditable(false);
labelBound = labelBound.withSizeKeepingCentre(labelBound.getWidth(), labelBound.getHeight() * .5f);
label1.setBounds(labelBound.toNearestInt());
label2.setBounds(0, 0, 0, 0);
labelLookAndFeel1.setJustification(juce::Justification::centred);
label1.setJustificationType(juce::Justification::centred);
}
}

Expand Down
1 change: 1 addition & 0 deletions source/panel/state_panel/comp_setting_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace zlPanel {
name.setLookAndFeel(&nameLAF);
name.setEditable(false);
name.setInterceptsMouseClicks(false, false);
name.setJustificationType(juce::Justification::centred);
addAndMakeVisible(name);
}

Expand Down
1 change: 1 addition & 0 deletions source/panel/state_panel/conflict_setting_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace zlPanel {
name.setLookAndFeel(&nameLAF);
name.setEditable(false);
name.setInterceptsMouseClicks(false, false);
name.setJustificationType(juce::Justification::centred);
addAndMakeVisible(name);
}

Expand Down
1 change: 1 addition & 0 deletions source/panel/state_panel/fft_setting_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ namespace zlPanel {
name.setLookAndFeel(&nameLAF);
name.setEditable(false);
name.setInterceptsMouseClicks(false, false);
name.setJustificationType(juce::Justification::centred);
addAndMakeVisible(name);
}

Expand Down
1 change: 1 addition & 0 deletions source/panel/state_panel/general_setting_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace zlPanel {
name.setLookAndFeel(&nameLAF);
name.setEditable(false);
name.setInterceptsMouseClicks(false, false);
name.setJustificationType(juce::Justification::centred);
addAndMakeVisible(name);
}

Expand Down
1 change: 1 addition & 0 deletions source/panel/state_panel/match_setting_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace zlPanel {
name.setLookAndFeel(&nameLAF);
name.setEditable(false);
name.setInterceptsMouseClicks(false, false);
name.setJustificationType(juce::Justification::centred);
addAndMakeVisible(name);

uiBase.setProperty(zlInterface::settingIdx::matchPanelShow, false);
Expand Down
20 changes: 13 additions & 7 deletions source/panel/ui_setting_panel/colour_setting_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,31 @@ namespace zlPanel {
if (!settingDirectory.isDirectory()) {
settingDirectory.createDirectory();
}
nameLAF.setJustification(juce::Justification::centredRight);
nameLAF.setFontScale(zlInterface::FontHuge);
for (size_t i = 0; i < numSelectors; ++i) {
selectorLabels[i].setText(selectorNames[i], juce::dontSendNotification);
selectorLabels[i].setJustificationType(juce::Justification::centredRight);
selectorLabels[i].setLookAndFeel(&nameLAF);
addAndMakeVisible(selectorLabels[i]);
addAndMakeVisible(selectors[i]);
}
cMap1Label.setText("Colour Map 1", juce::dontSendNotification);
cMap1Label.setJustificationType(juce::Justification::centredRight);
cMap1Label.setLookAndFeel(&nameLAF);
addAndMakeVisible(cMap1Label);
addAndMakeVisible(cMap1Selector);
cMap2Label.setText("Colour Map 2", juce::dontSendNotification);
cMap2Label.setJustificationType(juce::Justification::centredRight);
cMap2Label.setLookAndFeel(&nameLAF);
addAndMakeVisible(cMap2Label);
addAndMakeVisible(cMap2Selector);
importLabel.setText("Import", juce::dontSendNotification);
importLabel.setText("Import Colours", juce::dontSendNotification);
importLabel.setJustificationType(juce::Justification::centred);
importLabel.setLookAndFeel(&nameLAF);
importLabel.addMouseListener(this, false);
addAndMakeVisible(importLabel);
exportLabel.setText("Export", juce::dontSendNotification);
exportLabel.setText("Export Colours", juce::dontSendNotification);
exportLabel.setJustificationType(juce::Justification::centred);
exportLabel.setLookAndFeel(&nameLAF);
exportLabel.addMouseListener(this, false);
addAndMakeVisible(exportLabel);
Expand All @@ -70,15 +74,15 @@ namespace zlPanel {

void ColourSettingPanel::loadSetting() {
for (size_t i = 0; i < numSelectors; ++i) {
selectors[i]->setColour(uiBase.getColourByIdx(static_cast<zlInterface::colourIdx>(i)));
selectors[i]->setColour(uiBase.getColourByIdx(colourIdx[i]));
}
cMap1Selector.getBox().setSelectedId(static_cast<int>(uiBase.getCMap1Idx()) + 1);
cMap2Selector.getBox().setSelectedId(static_cast<int>(uiBase.getCMap2Idx()) + 1);
}

void ColourSettingPanel::saveSetting() {
for (size_t i = 0; i < numSelectors; ++i) {
uiBase.setColourByIdx(static_cast<zlInterface::colourIdx>(i), selectors[i]->getColour());
uiBase.setColourByIdx(colourIdx[i], selectors[i]->getColour());
}
uiBase.setCMap1Idx(static_cast<size_t>(cMap1Selector.getBox().getSelectedId() - 1));
uiBase.setCMap2Idx(static_cast<size_t>(cMap2Selector.getBox().getSelectedId() - 1));
Expand Down Expand Up @@ -124,7 +128,7 @@ namespace zlPanel {
auto localBound = bound.removeFromTop(uiBase.getFontSize() * 3);
importLabel.setBounds(localBound.removeFromLeft(bound.getWidth() * .45f).toNearestInt());
localBound.removeFromLeft(bound.getWidth() * .10f);
exportLabel.setBounds(localBound.removeFromLeft(uiBase.getFontSize() * 5.f).toNearestInt());
exportLabel.setBounds(localBound.toNearestInt());
}
}

Expand All @@ -146,9 +150,11 @@ namespace zlPanel {
xmlColour->getIntAttribute("g"),
xmlColour->getIntAttribute("b"),
static_cast<float>(xmlColour->getDoubleAttribute("o")));
selectors[i]->setColour(colour);
uiBase.setColourByIdx(colourIdx[i], colour);
}
}
uiBase.saveToAPVTS();
loadSetting();
}
});
} else if (event.originalComponent == &exportLabel) {
Expand Down
17 changes: 17 additions & 0 deletions source/panel/ui_setting_panel/colour_setting_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
namespace zlPanel {
class ColourSettingPanel final : public juce::Component {
public:
static constexpr float heightP = 52.f;

explicit ColourSettingPanel(PluginProcessor &p, zlInterface::UIBase &base);

~ColourSettingPanel() override;
Expand Down Expand Up @@ -63,6 +65,20 @@ namespace zlPanel {
"Tag Colour",
"Gain Colour",
};

std::array<zlInterface::colourIdx, numSelectors> colourIdx {
zlInterface::colourIdx::textColour,
zlInterface::colourIdx::backgroundColour,
zlInterface::colourIdx::shadowColour,
zlInterface::colourIdx::glowColour,
zlInterface::colourIdx::preColour,
zlInterface::colourIdx::postColour,
zlInterface::colourIdx::sideColour,
zlInterface::colourIdx::gridColour,
zlInterface::colourIdx::tagColour,
zlInterface::colourIdx::gainColour
};

std::array<std::string, numSelectors> tagNames{
"text_colour",
"background_colour",
Expand All @@ -73,6 +89,7 @@ namespace zlPanel {
"side_colour",
"grid_colour",
};

juce::Label cMap1Label, cMap2Label;
zlInterface::ColourMapSelector cMap1Selector, cMap2Selector;
juce::Label importLabel, exportLabel;
Expand Down
128 changes: 127 additions & 1 deletion source/panel/ui_setting_panel/control_setting_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ namespace zlPanel {
rotaryDragSensitivitySlider("Distance", base),
sliderDoubleClickBox("", zlState::sliderDoubleClickFunc::choices, base) {
juce::ignoreUnused(pRef);
nameLAF.setJustification(juce::Justification::centredRight);
nameLAF.setFontScale(zlInterface::FontHuge);

wheelLabel.setText("Mouse-Wheel Sensitivity", juce::dontSendNotification);
wheelLabel.setJustificationType(juce::Justification::centredRight);
wheelLabel.setLookAndFeel(&nameLAF);
addAndMakeVisible(wheelLabel);
dragLabel.setText("Mouse-Drag Sensitivity", juce::dontSendNotification);
dragLabel.setJustificationType(juce::Justification::centredRight);
dragLabel.setLookAndFeel(&nameLAF);
addAndMakeVisible(dragLabel);
for (auto &s: sensitivitySliders) {
Expand All @@ -45,16 +46,29 @@ namespace zlPanel {
sensitivitySliders[2].getSlider().setDoubleClickReturnValue(true, 1.0);
sensitivitySliders[3].getSlider().setDoubleClickReturnValue(true, 0.25);
rotaryStyleLabel.setText("Rotary Slider Style", juce::dontSendNotification);
rotaryStyleLabel.setJustificationType(juce::Justification::centredRight);
rotaryStyleLabel.setLookAndFeel(&nameLAF);
addAndMakeVisible(rotaryStyleLabel);
addAndMakeVisible(rotaryStyleBox);
rotaryDragSensitivitySlider.getSlider().setRange(2.0, 32.0, 0.01);
rotaryDragSensitivitySlider.getSlider().setDoubleClickReturnValue(true, 10.0);
addAndMakeVisible(rotaryDragSensitivitySlider);
sliderDoubleClickLabel.setText("Slider Double Click", juce::dontSendNotification);
sliderDoubleClickLabel.setJustificationType(juce::Justification::centredRight);
sliderDoubleClickLabel.setLookAndFeel(&nameLAF);
addAndMakeVisible(sliderDoubleClickLabel);
addAndMakeVisible(sliderDoubleClickBox);

importLabel.setText("Import Controls", juce::dontSendNotification);
importLabel.setJustificationType(juce::Justification::centred);
importLabel.setLookAndFeel(&nameLAF);
importLabel.addMouseListener(this, false);
addAndMakeVisible(importLabel);
exportLabel.setText("Export Controls", juce::dontSendNotification);
exportLabel.setJustificationType(juce::Justification::centred);
exportLabel.setLookAndFeel(&nameLAF);
exportLabel.addMouseListener(this, false);
addAndMakeVisible(exportLabel);
}

ControlSettingPanel::~ControlSettingPanel() = default;
Expand Down Expand Up @@ -123,6 +137,118 @@ namespace zlPanel {
localBound.removeFromLeft(bound.getWidth() * .05f);
const auto sWidth = (bound.getWidth() * .5f - uiBase.getFontSize() * 2.f) * 0.425f;
sliderDoubleClickBox.setBounds(localBound.removeFromLeft(sWidth).toNearestInt());
} {
bound.removeFromTop(uiBase.getFontSize());
auto localBound = bound.removeFromTop(uiBase.getFontSize() * 3);
importLabel.setBounds(localBound.removeFromLeft(bound.getWidth() * .45f).toNearestInt());
localBound.removeFromLeft(bound.getWidth() * .10f);
exportLabel.setBounds(localBound.toNearestInt());
}
}

void ControlSettingPanel::mouseDown(const juce::MouseEvent &event) {
if (event.originalComponent == &importLabel) {
importControls();
} else if (event.originalComponent == &exportLabel) {
exportControls();
}
}

void ControlSettingPanel::importControls() {
myChooser = std::make_unique<juce::FileChooser>(
"Load the control settings...", settingDirectory, "*.xml",
true, false, nullptr);
constexpr auto settingOpenFlags = juce::FileBrowserComponent::openMode |
juce::FileBrowserComponent::canSelectFiles;
myChooser->launchAsync(settingOpenFlags, [this](const juce::FileChooser &chooser) {
if (chooser.getResults().size() <= 0) { return; }
const juce::File settingFile(chooser.getResult());
if (const auto xmlInput = juce::XmlDocument::parse(settingFile)) {
if (const auto *xmlElement = xmlInput->getChildByName("drag_fine_sensitivity")) {
const auto x = xmlElement->getDoubleAttribute("value");
uiBase.setSensitivity(static_cast<float>(x), zlInterface::sensitivityIdx::mouseDragFine);
}
if (const auto *xmlElement = xmlInput->getChildByName("drag_sensitivity")) {
const auto x = xmlElement->getDoubleAttribute("value");
uiBase.setSensitivity(static_cast<float>(x), zlInterface::sensitivityIdx::mouseDrag);
}
if (const auto *xmlElement = xmlInput->getChildByName("wheel_fine_sensitivity")) {
const auto x = xmlElement->getDoubleAttribute("value");
uiBase.setSensitivity(static_cast<float>(x), zlInterface::sensitivityIdx::mouseWheelFine);
}
if (const auto *xmlElement = xmlInput->getChildByName("wheel_sensitivity")) {
const auto x = xmlElement->getDoubleAttribute("value");
uiBase.setSensitivity(static_cast<float>(x), zlInterface::sensitivityIdx::mouseWheel);
}
if (const auto *xmlElement = xmlInput->getChildByName("rotary_drag_sensitivity")) {
const auto x = xmlElement->getDoubleAttribute("value");
uiBase.setRotaryDragSensitivity(static_cast<float>(x));
}
if (const auto *xmlElement = xmlInput->getChildByName("rotary_style")) {
const auto x = xmlElement->getDoubleAttribute("value");
uiBase.setRotaryStyleID(static_cast<size_t>(x));
}
if (const auto *xmlElement = xmlInput->getChildByName("slider_double_click_func")) {
const auto x = xmlElement->getDoubleAttribute("value");
uiBase.setIsSliderDoubleClickOpenEditor(x > 0.5);
}
if (const auto *xmlElement = xmlInput->getChildByName("wheel_shift_reverse")) {
const auto x = xmlElement->getDoubleAttribute("value");
uiBase.setIsMouseWheelShiftReverse(x > 0.5);
}
uiBase.saveToAPVTS();
loadSetting();
}
});
}

void ControlSettingPanel::exportControls() {
myChooser = std::make_unique<juce::FileChooser>(
"Save the control settings...", settingDirectory.getChildFile("control.xml"), "*.xml",
true, false, nullptr);
constexpr auto settingSaveFlags = juce::FileBrowserComponent::saveMode |
juce::FileBrowserComponent::warnAboutOverwriting;
myChooser->launchAsync(settingSaveFlags, [this](const juce::FileChooser &chooser) {
if (chooser.getResults().size() <= 0) { return; }
juce::File settingFile(chooser.getResult().withFileExtension("xml"));
if (settingFile.create()) {
saveSetting();
juce::XmlElement xmlOutput{"colour_setting"};
{
auto *xmlElement = xmlOutput.createNewChildElement("drag_fine_sensitivity");
xmlElement->setAttribute("value", uiBase.getSensitivity(zlInterface::mouseDragFine));
}
{
auto *xmlElement = xmlOutput.createNewChildElement("drag_sensitivity");
xmlElement->setAttribute("value", uiBase.getSensitivity(zlInterface::mouseDrag));
}
{
auto *xmlElement = xmlOutput.createNewChildElement("wheel_fine_sensitivity");
xmlElement->setAttribute("value", uiBase.getSensitivity(zlInterface::mouseWheelFine));
}
{
auto *xmlElement = xmlOutput.createNewChildElement("wheel_sensitivity");
xmlElement->setAttribute("value", uiBase.getSensitivity(zlInterface::mouseWheel));
}
{
auto *xmlElement = xmlOutput.createNewChildElement("rotary_drag_sensitivity");
xmlElement->setAttribute("value", uiBase.getRotaryDragSensitivity());
}
{
auto *xmlElement = xmlOutput.createNewChildElement("rotary_style");
xmlElement->setAttribute("value", static_cast<double>(uiBase.getRotaryStyleID()));
}
{
auto *xmlElement = xmlOutput.createNewChildElement("slider_double_click_func");
xmlElement->setAttribute("value", static_cast<double>(uiBase.getIsSliderDoubleClickOpenEditor()));
}
{
auto *xmlElement = xmlOutput.createNewChildElement("wheel_shift_reverse");
xmlElement->setAttribute("value", static_cast<double>(uiBase.getIsMouseWheelShiftReverse()));
}
const auto result = xmlOutput.writeTo(settingFile);
juce::ignoreUnused(result);
}
});
}
} // zlPanel
Loading

0 comments on commit 8c86fc8

Please sign in to comment.