zynaddsubfx

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

commit a68a44736c6ae24b31475d691979a312351cecd4
parent c7678a6680a2a8ba908c6ba3e7250703de5a881a
Author: fundamental <[email protected]>
Date:   Mon,  1 Aug 2016 22:18:22 -0400

EnvelopeParams: Add Float Setters For Delay/Values

Diffstat:
Msrc/Params/EnvelopeParams.cpp | 49++++++++++++++++++++++++++++++++++---------------
Msrc/Params/EnvelopeParams.h | 1+
2 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/src/Params/EnvelopeParams.cpp b/src/Params/EnvelopeParams.cpp @@ -55,28 +55,41 @@ static const rtosc::Ports localPorts = { rParamZyn(PS_val, rShort("s.val"), "Sustain Value"), rParamZyn(PR_dt, rShort("r.dt"), "Release Time"), rParamZyn(PR_val, rShort("r.val"), "Release Value"), - - {"envdt:", rDoc("Envelope Delay Times"), NULL, + + {"envdt", rDoc("Envelope Delay Times"), NULL, rBegin; const int N = MAX_ENVELOPE_POINTS; - rtosc_arg_t args[N]; - char arg_types[N+1] = {0}; - for(int i=0; i<N; ++i) { - args[i].f = env->getdt(i); - arg_types[i] = 'f'; + const int M = rtosc_narguments(msg); + if(M == 0) { + rtosc_arg_t args[N]; + char arg_types[N+1] = {0}; + for(int i=0; i<N; ++i) { + args[i].f = env->getdt(i); + arg_types[i] = 'f'; + } + d.replyArray(d.loc, arg_types, args); + } else { + for(int i=0; i<N && i<M; ++i) + env->Penvdt[i] = env->inv_dt(rtosc_argument(msg, i).f); } - d.replyArray(d.loc, arg_types, args); rEnd}, - {"envval:", rDoc("Envelope Delay Times"), NULL, + {"envval", rDoc("Envelope Delay Times"), NULL, rBegin; const int N = MAX_ENVELOPE_POINTS; - rtosc_arg_t args[N]; - char arg_types[N+1] = {0}; - for(int i=0; i<N; ++i) { - args[i].f = env->Penvval[i]/127.0f; - arg_types[i] = 'f'; + const int M = rtosc_narguments(msg); + if(M == 0) { + rtosc_arg_t args[N]; + char arg_types[N+1] = {0}; + for(int i=0; i<N; ++i) { + args[i].f = env->Penvval[i]/127.0f; + arg_types[i] = 'f'; + } + d.replyArray(d.loc, arg_types, args); + } else { + for(int i=0; i<N && i<M; ++i) { + env->Penvval[i] = limit(roundf(rtosc_argument(msg,i).f*127.0f), 0.0f, 127.0f); + } } - d.replyArray(d.loc, arg_types, args); rEnd}, {"addPoint:i", rProp(internal) rDoc("Add point to envelope"), NULL, @@ -191,6 +204,12 @@ float EnvelopeParams::dt(char val) return (powf(2.0f, val / 127.0f * 12.0f) - 1.0f) * 10.0f; //miliseconds } +char EnvelopeParams::inv_dt(float val) +{ + int ival = roundf(logf(val/10.0f + 1.0f)/logf(2.0f) * 127.0f/12.0f); + return limit(ival, 0, 127); +} + /* * ADSR/ASR... initialisations diff --git a/src/Params/EnvelopeParams.h b/src/Params/EnvelopeParams.h @@ -44,6 +44,7 @@ class EnvelopeParams:public Presets float getdt(char i) const; static float dt(char val); + static char inv_dt(float val); /* MIDI Parameters */ unsigned char Pfreemode; //1 for free mode, 0 otherwise