Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LFOParams.cpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. LFOParams.cpp - Parameters for LFO
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. */
  11. #include <cmath>
  12. #include <cstdio>
  13. #include "../globals.h"
  14. #include "../Misc/Util.h"
  15. #include "../Misc/XMLwrapper.h"
  16. #include "../Misc/Time.h"
  17. #include "LFOParams.h"
  18. #include <rtosc/port-sugar.h>
  19. #include <rtosc/ports.h>
  20. using namespace rtosc;
  21. #define rObject LFOParams
  22. #undef rChangeCb
  23. #define rChangeCb if (obj->time) { obj->last_update_timestamp = obj->time->time(); }
  24. #define rBegin [](const char *msg, rtosc::RtData &d) {
  25. #define rEnd }
  26. static const rtosc::Ports _ports = {
  27. rSelf(LFOParams),
  28. rPaste,
  29. rParamF(Pfreq, rShort("freq"), rLinear(0.0,1.0), "frequency of LFO\n"
  30. "lfo frequency = (2^(10*Pfreq)-1)/12 * stretch\n"
  31. "true frequency is [0,85.33] Hz"),
  32. rParamZyn(Pintensity, rShort("depth"), "Intensity of LFO"),
  33. rParamZyn(Pstartphase, rShort("start"), rSpecial(random), "Starting Phase"),
  34. rOption(PLFOtype, rShort("type"), rOptions(sine, triangle, square, up, down,
  35. exp1, exp2), "Shape of LFO"),
  36. rParamZyn(Prandomness, rShort("a.r."), rSpecial(disable),
  37. "Amplitude Randomness (calculated uniformly at each cycle)"),
  38. rParamZyn(Pfreqrand, rShort("f.r."), rSpecial(disable),
  39. "Frequency Randomness (calculated uniformly at each cycle)"),
  40. rParamZyn(Pdelay, rShort("delay"), rSpecial(disable), "Delay before LFO start\n"
  41. "0..4 second delay"),
  42. rToggle(Pcontinous, rShort("c"), "Enable for global operation"),
  43. rParamZyn(Pstretch, rShort("str"), rCentered, "Note frequency stretch"),
  44. //Float valued aliases
  45. {"delay::f", rProp(parameter) rMap(units, ms) rLog(0,4000), 0,
  46. rBegin;
  47. rEnd},
  48. #define rPseudoLog(a,b) rLog(a,b)
  49. {"period::f", rProp(parameter) rMap(units, ms) rPseudoLog(0.10, 1500.0), 0,
  50. rBegin;
  51. rEnd},
  52. };
  53. #undef rPseudoLog
  54. #undef rBegin
  55. #undef rEnd
  56. #undef rChangeCb
  57. const rtosc::Ports &LFOParams::ports = _ports;
  58. LFOParams::LFOParams(const AbsTime *time_) : time(time_)
  59. {
  60. Dfreq = 64;
  61. Dintensity = 0;
  62. Dstartphase = 0;
  63. DLFOtype = 0;
  64. Drandomness = 0;
  65. Ddelay = 0;
  66. Dcontinous = 0;
  67. fel = 0;
  68. defaults();
  69. }
  70. LFOParams::LFOParams(char Pfreq_,
  71. char Pintensity_,
  72. char Pstartphase_,
  73. char PLFOtype_,
  74. char Prandomness_,
  75. char Pdelay_,
  76. char Pcontinous_,
  77. char fel_,
  78. const AbsTime *time_) : time(time_),
  79. last_update_timestamp(0) {
  80. switch(fel_) {
  81. case 0:
  82. setpresettype("Plfofrequency");
  83. break;
  84. case 1:
  85. setpresettype("Plfoamplitude");
  86. break;
  87. case 2:
  88. setpresettype("Plfofilter");
  89. break;
  90. }
  91. Dfreq = Pfreq_;
  92. Dintensity = Pintensity_;
  93. Dstartphase = Pstartphase_;
  94. DLFOtype = PLFOtype_;
  95. Drandomness = Prandomness_;
  96. Ddelay = Pdelay_;
  97. Dcontinous = Pcontinous_;
  98. fel = fel_;
  99. defaults();
  100. }
  101. LFOParams::~LFOParams()
  102. {}
  103. void LFOParams::defaults()
  104. {
  105. Pfreq = Dfreq / 127.0f;
  106. Pintensity = Dintensity;
  107. Pstartphase = Dstartphase;
  108. PLFOtype = DLFOtype;
  109. Prandomness = Drandomness;
  110. Pdelay = Ddelay;
  111. Pcontinous = Dcontinous;
  112. Pfreqrand = 0;
  113. Pstretch = 64;
  114. }
  115. void LFOParams::add2XML(XMLwrapper& xml)
  116. {
  117. xml.addparreal("freq", Pfreq);
  118. xml.addpar("intensity", Pintensity);
  119. xml.addpar("start_phase", Pstartphase);
  120. xml.addpar("lfo_type", PLFOtype);
  121. xml.addpar("randomness_amplitude", Prandomness);
  122. xml.addpar("randomness_frequency", Pfreqrand);
  123. xml.addpar("delay", Pdelay);
  124. xml.addpar("stretch", Pstretch);
  125. xml.addparbool("continous", Pcontinous);
  126. }
  127. void LFOParams::getfromXML(XMLwrapper& xml)
  128. {
  129. Pfreq = xml.getparreal("freq", Pfreq, 0.0f, 1.0f);
  130. Pintensity = xml.getpar127("intensity", Pintensity);
  131. Pstartphase = xml.getpar127("start_phase", Pstartphase);
  132. PLFOtype = xml.getpar127("lfo_type", PLFOtype);
  133. Prandomness = xml.getpar127("randomness_amplitude", Prandomness);
  134. Pfreqrand = xml.getpar127("randomness_frequency", Pfreqrand);
  135. Pdelay = xml.getpar127("delay", Pdelay);
  136. Pstretch = xml.getpar127("stretch", Pstretch);
  137. Pcontinous = xml.getparbool("continous", Pcontinous);
  138. }
  139. #define COPY(y) this->y=x.y
  140. void LFOParams::paste(LFOParams &x)
  141. {
  142. COPY(Pfreq);
  143. COPY(Pintensity);
  144. COPY(Pstartphase);
  145. COPY(PLFOtype);
  146. COPY(Prandomness);
  147. COPY(Pfreqrand);
  148. COPY(Pdelay);
  149. COPY(Pcontinous);
  150. COPY(Pstretch);
  151. if ( time ) {
  152. last_update_timestamp = time->time();
  153. }
  154. }
  155. #undef COPY