From 73ab9f48584d0a134acd7fd02218f633e80a76de Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Sun, 28 Feb 2021 11:11:15 +0100 Subject: [PATCH] Volume and Pan knobs at top-right corner --- plugins/editor/layout/main.fl | 26 +++++----- plugins/editor/src/editor/Editor.cpp | 57 +++++++++++++++++++-- plugins/editor/src/editor/GUIComponents.cpp | 7 ++- plugins/editor/src/editor/layout/main.hpp | 10 ++-- 4 files changed, 77 insertions(+), 23 deletions(-) diff --git a/plugins/editor/layout/main.fl b/plugins/editor/layout/main.fl index b6d7510c..9c077163 100644 --- a/plugins/editor/layout/main.fl +++ b/plugins/editor/layout/main.fl @@ -3,7 +3,7 @@ version 1.0305 header_name {.h} code_name {.cxx} widget_class mainView {open - xywh {571 362 800 475} type Double + xywh {659 319 800 475} type Double class LogicalGroup visible } { Fl_Box {} { @@ -121,7 +121,7 @@ widget_class mainView {open class ChevronValueDropDown } } - Fl_Group {} {open selected + Fl_Group {} {open xywh {570 5 225 100} box ROUNDED_BOX class RoundedGroup } { @@ -134,20 +134,22 @@ widget_class mainView {open xywh {610 70 60 5} labelsize 12 hide class ValueLabel } - Fl_Dial volumeSlider_ { - comment {tag=kTagSetVolume} - xywh {680 20 48 48} value 0.5 - class StyledKnob - } - Fl_Box volumeLabel_ { - label {0.0 dB} - xywh {675 70 60 22} labelsize 12 - class ValueLabel - } Fl_Box {} { xywh {745 20 35 55} box BORDER_BOX class VMeter } + Fl_Box volumeCCKnob_ { + label Volume + comment {tag=kTagSetCCVolume} selected + xywh {580 10 70 90} box BORDER_BOX labelsize 12 align 17 + class KnobCCBox + } + Fl_Box panCCKnob_ { + label Pan + comment {tag=kTagSetCCPan} + xywh {655 10 70 90} box BORDER_BOX labelsize 12 align 17 + class KnobCCBox + } } } Fl_Group {subPanels_[kPanelGeneral]} { diff --git a/plugins/editor/src/editor/Editor.cpp b/plugins/editor/src/editor/Editor.cpp index 4a539451..9f6407ef 100644 --- a/plugins/editor/src/editor/Editor.cpp +++ b/plugins/editor/src/editor/Editor.cpp @@ -73,7 +73,7 @@ struct Editor::Impl : EditorController::Receiver, IControlListener { kTagPreviousSfzFile, kTagNextSfzFile, kTagFileOperations, - kTagSetVolume, + kTagSetMainVolume, kTagSetNumVoices, kTagSetOversampling, kTagSetPreloadSize, @@ -82,6 +82,8 @@ struct Editor::Impl : EditorController::Receiver, IControlListener { kTagSetScalaRootKey, kTagSetTuningFrequency, kTagSetStretchedTuning, + kTagSetCCVolume, + kTagSetCCPan, kTagChooseUserFilesDir, kTagFirstChangePanel, kTagLastChangePanel = kTagFirstChangePanel + kNumPanels - 1, @@ -128,6 +130,18 @@ struct Editor::Impl : EditorController::Receiver, IControlListener { SControlsPanel* controlsPanel_ = nullptr; + SKnobCCBox* volumeCCKnob_ = nullptr; + SKnobCCBox* panCCKnob_ = nullptr; + + CControl* getSecondaryCCControl(unsigned cc) + { + switch (cc) { + case 7: return volumeCCKnob_ ? volumeCCKnob_->getControl() : nullptr; + case 10: return panCCKnob_ ? panCCKnob_->getControl() : nullptr; + default: return nullptr; + } + } + void uiReceiveValue(EditId id, const EditValue& v) override; void uiReceiveMessage(const char* path, const char* sig, const sfizz_arg_t* args) override; @@ -826,12 +840,19 @@ void Editor::Impl::createFrameContents() menu->setBackColor(CColor(0x00, 0x00, 0x00, 0x00)); return menu; }; - auto createKnobCCBox = [this, &theme](const CRect& bounds, int tag, const char* label, CHoriTxtAlign, int) { + auto createKnobCCBox = [this, &theme](const CRect& bounds, int tag, const char* label, CHoriTxtAlign, int fontsize) { SKnobCCBox* box = new SKnobCCBox(bounds, this, tag); + auto font = makeOwned("Roboto", fontsize); box->setNameLabelText(label); + box->setNameLabelFont(font); box->setNameLabelFontColor(theme->text); + box->setKnobFont(font); box->setKnobFontColor(theme->text); box->setKnobLineIndicatorColor(theme->knobLineIndicatorColor); + box->setValueToStringFunction([](float value, std::string& text) -> bool { + text = std::to_string(std::lround(value * 127)); + return true; + }); return box; }; auto createBackground = [&background](const CRect& bounds, int, const char*, CHoriTxtAlign, int) { @@ -1005,6 +1026,7 @@ void Editor::Impl::createFrameContents() if (SControlsPanel* panel = controlsPanel_) { panel->ValueChangeFunction = [this](uint32_t cc, float value) { performCCValueChange(cc, value); + updateCCValue(cc, value); }; panel->BeginEditFunction = [this](uint32_t cc) { performCCBeginEdit(cc); @@ -1014,6 +1036,15 @@ void Editor::Impl::createFrameContents() }; } + if (SKnobCCBox* box = volumeCCKnob_) { + unsigned ccNumber = 7; + box->setCCLabelText(("CC " + std::to_string(ccNumber)).c_str()); + } + if (SKnobCCBox* box = panCCKnob_) { + unsigned ccNumber = 10; + box->setCCLabelText(("CC " + std::to_string(ccNumber)).c_str()); + } + updateKeyswitchNameLabel(); /// @@ -1483,12 +1514,18 @@ void Editor::Impl::updateCCValue(unsigned cc, float value) { if (SControlsPanel* panel = controlsPanel_) panel->setControlValue(cc, value); + + if (CControl* other = getSecondaryCCControl(cc)) + other->setValue(value); } void Editor::Impl::updateCCDefaultValue(unsigned cc, float value) { if (SControlsPanel* panel = controlsPanel_) panel->setControlDefaultValue(cc, value); + + if (CControl* other = getSecondaryCCControl(cc)) + other->setDefaultValue(value); } void Editor::Impl::updateCCLabel(unsigned cc, const char* label) @@ -1652,11 +1689,21 @@ void Editor::Impl::valueChanged(CControl* ctl) changeScalaFile(std::string()); break; - case kTagSetVolume: + case kTagSetMainVolume: ctrl.uiSendValue(EditId::Volume, value); updateVolumeLabel(value); break; + case kTagSetCCVolume: + performCCValueChange(7, value); + updateCCValue(7, value); + break; + + case kTagSetCCPan: + performCCValueChange(10, value); + updateCCValue(10, value); + break; + case kTagSetNumVoices: ctrl.uiSendValue(EditId::Polyphony, value); updateNumVoicesLabel(static_cast(value)); @@ -1717,13 +1764,15 @@ void Editor::Impl::enterOrLeaveEdit(CControl* ctl, bool enter) EditId id; switch (tag) { - case kTagSetVolume: id = EditId::Volume; break; + case kTagSetMainVolume: id = EditId::Volume; break; case kTagSetNumVoices: id = EditId::Polyphony; break; case kTagSetOversampling: id = EditId::Oversampling; break; case kTagSetPreloadSize: id = EditId::PreloadSize; break; case kTagSetScalaRootKey: id = EditId::ScalaRootKey; break; case kTagSetTuningFrequency: id = EditId::TuningFrequency; break; case kTagSetStretchedTuning: id = EditId::StretchTuning; break; + case kTagSetCCVolume: id = editIdForCC(7); break; + case kTagSetCCPan: id = editIdForCC(10); break; default: return; } diff --git a/plugins/editor/src/editor/GUIComponents.cpp b/plugins/editor/src/editor/GUIComponents.cpp index d8b02acc..294a5703 100644 --- a/plugins/editor/src/editor/GUIComponents.cpp +++ b/plugins/editor/src/editor/GUIComponents.cpp @@ -743,8 +743,11 @@ void SControlsPanel::setControlValue(uint32_t index, float value) { ControlSlot* slot = getOrCreateSlot(index); SKnobCCBox* box = slot->box; - box->getControl()->setValue(value); - box->invalid(); + auto* control = box->getControl(); + float oldValue = control->getValue(); + control->setValue(value); + if (control->getValue() != oldValue) + box->invalid(); } void SControlsPanel::setControlDefaultValue(uint32_t index, float value) diff --git a/plugins/editor/src/editor/layout/main.hpp b/plugins/editor/src/editor/layout/main.hpp index 626d093e..96557324 100644 --- a/plugins/editor/src/editor/layout/main.hpp +++ b/plugins/editor/src/editor/layout/main.hpp @@ -68,13 +68,13 @@ view__26->setVisible(false); auto* const view__27 = createValueLabel(CRect(40, 65, 100, 70), -1, "Center", kCenterText, 12); view__25->addView(view__27); view__27->setVisible(false); -auto* const view__28 = createStyledKnob(CRect(110, 15, 158, 63), kTagSetVolume, "", kCenterText, 14); -volumeSlider_ = view__28; +auto* const view__28 = createVMeter(CRect(175, 15, 210, 70), -1, "", kCenterText, 14); view__25->addView(view__28); -auto* const view__29 = createValueLabel(CRect(105, 65, 165, 87), -1, "0.0 dB", kCenterText, 12); -volumeLabel_ = view__29; +auto* const view__29 = createKnobCCBox(CRect(10, 5, 80, 95), kTagSetCCVolume, "Volume", kCenterText, 12); +volumeCCKnob_ = view__29; view__25->addView(view__29); -auto* const view__30 = createVMeter(CRect(175, 15, 210, 70), -1, "", kCenterText, 14); +auto* const view__30 = createKnobCCBox(CRect(85, 5, 155, 95), kTagSetCCPan, "Pan", kCenterText, 12); +panCCKnob_ = view__30; view__25->addView(view__30); enterTheme(defaultTheme); auto* const view__31 = createLogicalGroup(CRect(5, 110, 796, 395), -1, "", kCenterText, 14);