zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 067c6b35b087500995bad8e26e4d670135612136
parent 78441a2db078c492bd8df078ae56729d133ce267
Author: Ricard Wanderlof <polluxsynth@butoba.net>
Date:   Tue,  8 Mar 2022 00:50:07 +0100

Update controller values when amounts changed

Similar as was recently done for the modwheel, update the corresponding
parameter values not just when the MIDI CC controlling the parameter
is received, but also when the corresponding amount is changed.
Otherwise the user experience will be confusing, as a new controller
value must be received before a depth change can be noticed.

Diffstat:
Msrc/Params/Controller.cpp | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Msrc/Params/Controller.h | 7+++++++
2 files changed, 69 insertions(+), 4 deletions(-)

diff --git a/src/Params/Controller.cpp b/src/Params/Controller.cpp @@ -31,12 +31,20 @@ namespace zyn { #undef rChangeCb #define rChangeCb rChangeCbBase const rtosc::Ports Controller::ports = { +#undef rChangeCb +#define rChangeCb obj->setpanning(); rChangeCbBase rParamZyn(panning.depth, rShort("pan.d"), rDefault(64), "Depth of Panning MIDI Control"), +#undef rChangeCb +#define rChangeCb obj->setfiltercutoff(); rChangeCbBase rParamZyn(filtercutoff.depth, rShort("fc.d"), rDefault(64), "Depth of Filter Cutoff MIDI Control"), +#undef rChangeCb +#define rChangeCb obj->setfilterq(); rChangeCbBase rParamZyn(filterq.depth, rShort("fq.d"), rDefault(64), "Depth of Filter Q MIDI Control"), +#undef rChangeCb +#define rChangeCb obj->setbandwidth(); rChangeCbBase rParamZyn(bandwidth.depth, rShort("bw.d"), rDefault(64), "Depth of Bandwidth MIDI Control"), rToggle(bandwidth.exponential, rShort("bw.exp"), rDefault(false), @@ -48,7 +56,7 @@ const rtosc::Ports Controller::ports = { rToggle(modwheel.exponential, rShort("mdw.exp"), rDefault(false), "Modwheel Exponential Mode"), #undef rChangeCb -#define rChangeCb rChangeCbBase +#define rChangeCb obj->setpitchwheel(); rChangeCbBase rToggle(pitchwheel.is_split, rDefault(false), "If PitchWheel has unified bendrange or not"), rParamI(pitchwheel.bendrange, rShort("pch.d"), rDefault(200), @@ -56,6 +64,8 @@ const rtosc::Ports Controller::ports = { "Range of MIDI Pitch Wheel"), rParamI(pitchwheel.bendrange_down, rDefault(0), "Lower Range of MIDI Pitch Wheel"), +#undef rChangeCb +#define rChangeCb rChangeCbBase rToggle(expression.receive, rShort("exp.rcv"), rDefault(true), "Expression MIDI Receive"), rToggle(fmamp.receive, rShort("fma.rcv"), rDefault(true), @@ -85,10 +95,16 @@ const rtosc::Ports Controller::ports = { "Type of threshold"), rParamZyn(portamento.updowntimestretch, rShort("up/dwn"), rDefault(64), "Relative length of glide up vs glide down"), +#undef rChangeCb +#define rChangeCb obj->setresonancecenter(); rChangeCbBase rParamZyn(resonancecenter.depth, rShort("rfc.d"), rDefault(64), "Resonance Center MIDI Depth"), +#undef rChangeCb +#define rChangeCb obj->setresonancebw(); rChangeCbBase rParamZyn(resonancebandwidth.depth, rShort("rbw.d"), rDefault(64), "Resonance Bandwidth MIDI Depth"), +#undef rChangeCb +#define rChangeCb rChangeCbBase rToggle(NRPN.receive, rDefault(true), "NRPN MIDI Enable"), rAction(defaults), }; @@ -161,6 +177,12 @@ void Controller::resetall() void Controller::setpitchwheel(int value) { pitchwheel.data = value; + setpitchwheel(); +} + +void Controller::setpitchwheel() +{ + int value = pitchwheel.data; float cents = value / 8192.0f; if(pitchwheel.is_split && cents < 0) cents *= pitchwheel.bendrange_down; @@ -186,12 +208,24 @@ void Controller::setexpression(int value) void Controller::setpanning(int value) { panning.data = value; + setpanning(); +} + +void Controller::setpanning(void) +{ + int value = panning.data; panning.pan = (value / 128.0f - 0.5f) * (panning.depth / 64.0f); } void Controller::setfiltercutoff(int value) { - filtercutoff.data = value; + filtercutoff.data = value; + setfiltercutoff(); +} + +void Controller::setfiltercutoff(void) +{ + int value = filtercutoff.data; filtercutoff.relfreq = (value - 64.0f) * filtercutoff.depth / 4096.0f * 3.321928f; //3.3219f..=ln2(10) } @@ -199,12 +233,24 @@ void Controller::setfiltercutoff(int value) void Controller::setfilterq(int value) { filterq.data = value; + setfilterq(); +} + +void Controller::setfilterq(void) +{ + int value = filterq.data; filterq.relq = powf(30.0f, (value - 64.0f) / 64.0f * (filterq.depth / 64.0f)); } void Controller::setbandwidth(int value) { bandwidth.data = value; + setbandwidth(); +} + +void Controller::setbandwidth(void) +{ + int value = bandwidth.data; if(bandwidth.exponential == 0) { float tmp = powf(25.0f, powf(bandwidth.depth / 127.0f, 1.5f)) - 1.0f; if((value < 64) && (bandwidth.depth >= 64)) @@ -244,7 +290,7 @@ void Controller::setmodwheel(void) void Controller::setfmamp(int value) { - fmamp.data = value; + fmamp.data = value; fmamp.relamp = value / 127.0f; if(fmamp.receive != 0) fmamp.relamp = value / 127.0f; @@ -287,13 +333,25 @@ void Controller::setportamento(int value) void Controller::setresonancecenter(int value) { - resonancecenter.data = value; + resonancecenter.data = value; + setresonancecenter(); +} + +void Controller::setresonancecenter(void) +{ + int value = resonancecenter.data; resonancecenter.relcenter = powf(3.0f, (value - 64.0f) / 64.0f * (resonancecenter.depth / 64.0f)); } + void Controller::setresonancebw(int value) { resonancebandwidth.data = value; +} + +void Controller::setresonancebw(void) +{ + int value = resonancebandwidth.data; resonancebandwidth.relbw = powf(1.5f, (value - 64.0f) / 64.0f * (resonancebandwidth.depth / 127.0f)); } diff --git a/src/Params/Controller.h b/src/Params/Controller.h @@ -34,11 +34,16 @@ class Controller //Controllers functions void setpitchwheel(int value); + void setpitchwheel(void); void setexpression(int value); void setpanning(int value); + void setpanning(void); void setfiltercutoff(int value); + void setfiltercutoff(void); void setfilterq(int value); + void setfilterq(void); void setbandwidth(int value); + void setbandwidth(void); void setmodwheel(int value); void setmodwheel(void); void setfmamp(int value); @@ -48,7 +53,9 @@ class Controller * @param value 0-127 MIDI value (greater than 64 enables)*/ void setportamento(int value); void setresonancecenter(int value); + void setresonancecenter(void); void setresonancebw(int value); + void setresonancebw(void); void setparameternumber(unsigned int type, int value); //used for RPN and NRPN's