Merge pull request #674 from jpcima/volume-and-pan-knobs

Volume and pan knobs
This commit is contained in:
JP Cimalando 2021-02-28 11:22:44 +01:00 committed by GitHub
commit 4edbf1f6a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 25 deletions

View file

@ -3,7 +3,7 @@ version 1.0305
header_name {.h} header_name {.h}
code_name {.cxx} code_name {.cxx}
widget_class mainView {open widget_class mainView {open
xywh {571 362 800 475} type Double xywh {659 319 800 475} type Double
class LogicalGroup visible class LogicalGroup visible
} { } {
Fl_Box {} { Fl_Box {} {
@ -121,7 +121,7 @@ widget_class mainView {open
class ChevronValueDropDown class ChevronValueDropDown
} }
} }
Fl_Group {} {open selected Fl_Group {} {open
xywh {570 5 225 100} box ROUNDED_BOX xywh {570 5 225 100} box ROUNDED_BOX
class RoundedGroup class RoundedGroup
} { } {
@ -134,20 +134,22 @@ widget_class mainView {open
xywh {610 70 60 5} labelsize 12 hide xywh {610 70 60 5} labelsize 12 hide
class ValueLabel 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 {} { Fl_Box {} {
xywh {745 20 35 55} box BORDER_BOX xywh {745 20 35 55} box BORDER_BOX
class VMeter 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]} { Fl_Group {subPanels_[kPanelGeneral]} {

View file

@ -73,7 +73,7 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
kTagPreviousSfzFile, kTagPreviousSfzFile,
kTagNextSfzFile, kTagNextSfzFile,
kTagFileOperations, kTagFileOperations,
kTagSetVolume, kTagSetMainVolume,
kTagSetNumVoices, kTagSetNumVoices,
kTagSetOversampling, kTagSetOversampling,
kTagSetPreloadSize, kTagSetPreloadSize,
@ -82,6 +82,8 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
kTagSetScalaRootKey, kTagSetScalaRootKey,
kTagSetTuningFrequency, kTagSetTuningFrequency,
kTagSetStretchedTuning, kTagSetStretchedTuning,
kTagSetCCVolume,
kTagSetCCPan,
kTagChooseUserFilesDir, kTagChooseUserFilesDir,
kTagFirstChangePanel, kTagFirstChangePanel,
kTagLastChangePanel = kTagFirstChangePanel + kNumPanels - 1, kTagLastChangePanel = kTagFirstChangePanel + kNumPanels - 1,
@ -128,6 +130,18 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
SControlsPanel* controlsPanel_ = nullptr; 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 uiReceiveValue(EditId id, const EditValue& v) override;
void uiReceiveMessage(const char* path, const char* sig, const sfizz_arg_t* args) override; void uiReceiveMessage(const char* path, const char* sig, const sfizz_arg_t* args) override;
@ -144,6 +158,8 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
template <class Control> template <class Control>
void adjustMinMaxToEditRange(Control* c, EditId id) void adjustMinMaxToEditRange(Control* c, EditId id)
{ {
if (!c)
return;
const EditRange er = EditRange::get(id); const EditRange er = EditRange::get(id);
c->setMin(er.min); c->setMin(er.min);
c->setMax(er.max); c->setMax(er.max);
@ -824,12 +840,19 @@ void Editor::Impl::createFrameContents()
menu->setBackColor(CColor(0x00, 0x00, 0x00, 0x00)); menu->setBackColor(CColor(0x00, 0x00, 0x00, 0x00));
return menu; 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); SKnobCCBox* box = new SKnobCCBox(bounds, this, tag);
auto font = makeOwned<CFontDesc>("Roboto", fontsize);
box->setNameLabelText(label); box->setNameLabelText(label);
box->setNameLabelFont(font);
box->setNameLabelFontColor(theme->text); box->setNameLabelFontColor(theme->text);
box->setKnobFont(font);
box->setKnobFontColor(theme->text); box->setKnobFontColor(theme->text);
box->setKnobLineIndicatorColor(theme->knobLineIndicatorColor); box->setKnobLineIndicatorColor(theme->knobLineIndicatorColor);
box->setValueToStringFunction([](float value, std::string& text) -> bool {
text = std::to_string(std::lround(value * 127));
return true;
});
return box; return box;
}; };
auto createBackground = [&background](const CRect& bounds, int, const char*, CHoriTxtAlign, int) { auto createBackground = [&background](const CRect& bounds, int, const char*, CHoriTxtAlign, int) {
@ -1003,6 +1026,7 @@ void Editor::Impl::createFrameContents()
if (SControlsPanel* panel = controlsPanel_) { if (SControlsPanel* panel = controlsPanel_) {
panel->ValueChangeFunction = [this](uint32_t cc, float value) { panel->ValueChangeFunction = [this](uint32_t cc, float value) {
performCCValueChange(cc, value); performCCValueChange(cc, value);
updateCCValue(cc, value);
}; };
panel->BeginEditFunction = [this](uint32_t cc) { panel->BeginEditFunction = [this](uint32_t cc) {
performCCBeginEdit(cc); performCCBeginEdit(cc);
@ -1012,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(); updateKeyswitchNameLabel();
/// ///
@ -1481,12 +1514,18 @@ void Editor::Impl::updateCCValue(unsigned cc, float value)
{ {
if (SControlsPanel* panel = controlsPanel_) if (SControlsPanel* panel = controlsPanel_)
panel->setControlValue(cc, value); panel->setControlValue(cc, value);
if (CControl* other = getSecondaryCCControl(cc))
other->setValue(value);
} }
void Editor::Impl::updateCCDefaultValue(unsigned cc, float value) void Editor::Impl::updateCCDefaultValue(unsigned cc, float value)
{ {
if (SControlsPanel* panel = controlsPanel_) if (SControlsPanel* panel = controlsPanel_)
panel->setControlDefaultValue(cc, value); panel->setControlDefaultValue(cc, value);
if (CControl* other = getSecondaryCCControl(cc))
other->setDefaultValue(value);
} }
void Editor::Impl::updateCCLabel(unsigned cc, const char* label) void Editor::Impl::updateCCLabel(unsigned cc, const char* label)
@ -1650,11 +1689,21 @@ void Editor::Impl::valueChanged(CControl* ctl)
changeScalaFile(std::string()); changeScalaFile(std::string());
break; break;
case kTagSetVolume: case kTagSetMainVolume:
ctrl.uiSendValue(EditId::Volume, value); ctrl.uiSendValue(EditId::Volume, value);
updateVolumeLabel(value); updateVolumeLabel(value);
break; break;
case kTagSetCCVolume:
performCCValueChange(7, value);
updateCCValue(7, value);
break;
case kTagSetCCPan:
performCCValueChange(10, value);
updateCCValue(10, value);
break;
case kTagSetNumVoices: case kTagSetNumVoices:
ctrl.uiSendValue(EditId::Polyphony, value); ctrl.uiSendValue(EditId::Polyphony, value);
updateNumVoicesLabel(static_cast<int>(value)); updateNumVoicesLabel(static_cast<int>(value));
@ -1715,13 +1764,15 @@ void Editor::Impl::enterOrLeaveEdit(CControl* ctl, bool enter)
EditId id; EditId id;
switch (tag) { switch (tag) {
case kTagSetVolume: id = EditId::Volume; break; case kTagSetMainVolume: id = EditId::Volume; break;
case kTagSetNumVoices: id = EditId::Polyphony; break; case kTagSetNumVoices: id = EditId::Polyphony; break;
case kTagSetOversampling: id = EditId::Oversampling; break; case kTagSetOversampling: id = EditId::Oversampling; break;
case kTagSetPreloadSize: id = EditId::PreloadSize; break; case kTagSetPreloadSize: id = EditId::PreloadSize; break;
case kTagSetScalaRootKey: id = EditId::ScalaRootKey; break; case kTagSetScalaRootKey: id = EditId::ScalaRootKey; break;
case kTagSetTuningFrequency: id = EditId::TuningFrequency; break; case kTagSetTuningFrequency: id = EditId::TuningFrequency; break;
case kTagSetStretchedTuning: id = EditId::StretchTuning; break; case kTagSetStretchedTuning: id = EditId::StretchTuning; break;
case kTagSetCCVolume: id = editIdForCC(7); break;
case kTagSetCCPan: id = editIdForCC(10); break;
default: return; default: return;
} }

View file

@ -636,11 +636,11 @@ void SKnobCCBox::updateViewSizes()
const CRect size = getViewSize(); const CRect size = getViewSize();
const CCoord ypad = 4.0; const CCoord ypad = 4.0;
const CFontRef nameFont = ccLabel_->getFont(); const CFontRef nameFont = label_->getFont();
const CFontRef ccFont = ccLabel_->getFont(); const CFontRef ccFont = ccLabel_->getFont();
nameLabelSize_ = CRect(0.0, 0.0, size.getWidth(), nameFont->getSize() + 2 * ypad); nameLabelSize_ = CRect(0.0, 0.0, size.getWidth(), nameFont->getSize() + 2 * ypad);
ccLabelSize_ = CRect(0.0, size.bottom - ccFont->getSize() - 2 * ypad, size.getWidth(), size.bottom); ccLabelSize_ = CRect(0.0, size.getHeight() - ccFont->getSize() - 2 * ypad, size.getWidth(), size.getHeight());
knobSize_ = CRect(0.0, nameLabelSize_.bottom, size.getWidth(), ccLabelSize_.top); knobSize_ = CRect(0.0, nameLabelSize_.bottom, size.getWidth(), ccLabelSize_.top);
// remove knob side areas // remove knob side areas
@ -743,8 +743,11 @@ void SControlsPanel::setControlValue(uint32_t index, float value)
{ {
ControlSlot* slot = getOrCreateSlot(index); ControlSlot* slot = getOrCreateSlot(index);
SKnobCCBox* box = slot->box; SKnobCCBox* box = slot->box;
box->getControl()->setValue(value); auto* control = box->getControl();
box->invalid(); float oldValue = control->getValue();
control->setValue(value);
if (control->getValue() != oldValue)
box->invalid();
} }
void SControlsPanel::setControlDefaultValue(uint32_t index, float value) void SControlsPanel::setControlDefaultValue(uint32_t index, float value)

View file

@ -68,13 +68,13 @@ view__26->setVisible(false);
auto* const view__27 = createValueLabel(CRect(40, 65, 100, 70), -1, "Center", kCenterText, 12); auto* const view__27 = createValueLabel(CRect(40, 65, 100, 70), -1, "Center", kCenterText, 12);
view__25->addView(view__27); view__25->addView(view__27);
view__27->setVisible(false); view__27->setVisible(false);
auto* const view__28 = createStyledKnob(CRect(110, 15, 158, 63), kTagSetVolume, "", kCenterText, 14); auto* const view__28 = createVMeter(CRect(175, 15, 210, 70), -1, "", kCenterText, 14);
volumeSlider_ = view__28;
view__25->addView(view__28); view__25->addView(view__28);
auto* const view__29 = createValueLabel(CRect(105, 65, 165, 87), -1, "0.0 dB", kCenterText, 12); auto* const view__29 = createKnobCCBox(CRect(10, 5, 80, 95), kTagSetCCVolume, "Volume", kCenterText, 12);
volumeLabel_ = view__29; volumeCCKnob_ = view__29;
view__25->addView(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); view__25->addView(view__30);
enterTheme(defaultTheme); enterTheme(defaultTheme);
auto* const view__31 = createLogicalGroup(CRect(5, 110, 796, 395), -1, "", kCenterText, 14); auto* const view__31 = createLogicalGroup(CRect(5, 110, 796, 395), -1, "", kCenterText, 14);