|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- /*
- ZynAddSubFX - a software synthesizer
-
- LFOParams.cpp - Parameters for LFO
- Copyright (C) 2002-2005 Nasca Octavian Paul
- Author: Nasca Octavian Paul
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- */
-
- #include <cmath>
- #include <cstdio>
- #include "../globals.h"
- #include "../Misc/Util.h"
- #include "../Misc/XMLwrapper.h"
- #include "../Misc/Time.h"
- #include "LFOParams.h"
-
- #include <rtosc/port-sugar.h>
- #include <rtosc/ports.h>
- using namespace rtosc;
-
- namespace zyncarla {
-
- #define rObject LFOParams
- #undef rChangeCb
- #define rChangeCb if (obj->time) { obj->last_update_timestamp = obj->time->time(); }
- #define rBegin [](const char *msg, rtosc::RtData &d) {
- #define rEnd }
- static const rtosc::Ports _ports = {
- rSelf(LFOParams),
- rPaste,
- rParamF(Pfreq, rShort("freq"), rLinear(0.0,1.0), "frequency of LFO\n"
- "lfo frequency = (2^(10*Pfreq)-1)/12 * stretch\n"
- "true frequency is [0,85.33] Hz"),
- rParamZyn(Pintensity, rShort("depth"), "Intensity of LFO"),
- rParamZyn(Pstartphase, rShort("start"), rSpecial(random), "Starting Phase"),
- rOption(PLFOtype, rShort("type"), rOptions(sine, triangle, square, up, down,
- exp1, exp2), "Shape of LFO"),
- rParamZyn(Prandomness, rShort("a.r."), rSpecial(disable),
- "Amplitude Randomness (calculated uniformly at each cycle)"),
- rParamZyn(Pfreqrand, rShort("f.r."), rSpecial(disable), rDefault(0),
- "Frequency Randomness (calculated uniformly at each cycle)"),
- rParamZyn(Pdelay, rShort("delay"), rSpecial(disable), "Delay before LFO start\n"
- "0..4 second delay"),
- rToggle(Pcontinous, rShort("c"), "Enable for global operation"),
- rParamZyn(Pstretch, rShort("str"), rCentered, rDefault(64),
- "Note frequency stretch"),
- // these are currently not yet implemented at must be hidden therefore
- #ifdef DEAD_PORTS
- //Float valued aliases
- {"delay::f", rProp(parameter) rMap(units, ms) rLog(0,4000), 0,
- rBegin;
-
- rEnd},
- #define rPseudoLog(a,b) rLog(a,b)
- {"period::f", rProp(parameter) rMap(units, ms) rPseudoLog(0.10, 1500.0), 0,
- rBegin;
- rEnd},
- #endif
- };
- #undef rPseudoLog
- #undef rBegin
- #undef rEnd
- #undef rChangeCb
-
- const rtosc::Ports &LFOParams::ports = _ports;
-
- LFOParams::LFOParams(const AbsTime *time_) : time(time_)
- {
- Dfreq = 64;
- Dintensity = 0;
- Dstartphase = 0;
- DLFOtype = 0;
- Drandomness = 0;
- Ddelay = 0;
- Dcontinous = 0;
- fel = 0;
-
- defaults();
- }
-
- LFOParams::LFOParams(char Pfreq_,
- char Pintensity_,
- char Pstartphase_,
- char PLFOtype_,
- char Prandomness_,
- char Pdelay_,
- char Pcontinous_,
- char fel_,
- const AbsTime *time_) : time(time_),
- last_update_timestamp(0) {
- switch(fel_) {
- case 0:
- setpresettype("Plfofrequency");
- break;
- case 1:
- setpresettype("Plfoamplitude");
- break;
- case 2:
- setpresettype("Plfofilter");
- break;
- }
- Dfreq = Pfreq_;
- Dintensity = Pintensity_;
- Dstartphase = Pstartphase_;
- DLFOtype = PLFOtype_;
- Drandomness = Prandomness_;
- Ddelay = Pdelay_;
- Dcontinous = Pcontinous_;
- fel = fel_;
-
- defaults();
- }
-
- LFOParams::~LFOParams()
- {}
-
- void LFOParams::defaults()
- {
- Pfreq = Dfreq / 127.0f;
- Pintensity = Dintensity;
- Pstartphase = Dstartphase;
- PLFOtype = DLFOtype;
- Prandomness = Drandomness;
- Pdelay = Ddelay;
- Pcontinous = Dcontinous;
- Pfreqrand = 0;
- Pstretch = 64;
- }
-
-
- void LFOParams::add2XML(XMLwrapper& xml)
- {
- xml.addparreal("freq", Pfreq);
- xml.addpar("intensity", Pintensity);
- xml.addpar("start_phase", Pstartphase);
- xml.addpar("lfo_type", PLFOtype);
- xml.addpar("randomness_amplitude", Prandomness);
- xml.addpar("randomness_frequency", Pfreqrand);
- xml.addpar("delay", Pdelay);
- xml.addpar("stretch", Pstretch);
- xml.addparbool("continous", Pcontinous);
- }
-
- void LFOParams::getfromXML(XMLwrapper& xml)
- {
- Pfreq = xml.getparreal("freq", Pfreq, 0.0f, 1.0f);
- Pintensity = xml.getpar127("intensity", Pintensity);
- Pstartphase = xml.getpar127("start_phase", Pstartphase);
- PLFOtype = xml.getpar127("lfo_type", PLFOtype);
- Prandomness = xml.getpar127("randomness_amplitude", Prandomness);
- Pfreqrand = xml.getpar127("randomness_frequency", Pfreqrand);
- Pdelay = xml.getpar127("delay", Pdelay);
- Pstretch = xml.getpar127("stretch", Pstretch);
- Pcontinous = xml.getparbool("continous", Pcontinous);
- }
-
- #define COPY(y) this->y=x.y
- void LFOParams::paste(LFOParams &x)
- {
- COPY(Pfreq);
- COPY(Pintensity);
- COPY(Pstartphase);
- COPY(PLFOtype);
- COPY(Prandomness);
- COPY(Pfreqrand);
- COPY(Pdelay);
- COPY(Pcontinous);
- COPY(Pstretch);
-
- if ( time ) {
- last_update_timestamp = time->time();
- }
- }
- #undef COPY
-
- }
|