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.

182 lines
5.2KB

  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. namespace zyncarla {
  22. #define rObject LFOParams
  23. #undef rChangeCb
  24. #define rChangeCb if (obj->time) { obj->last_update_timestamp = obj->time->time(); }
  25. #define rBegin [](const char *msg, rtosc::RtData &d) {
  26. #define rEnd }
  27. static const rtosc::Ports _ports = {
  28. rSelf(LFOParams),
  29. rPaste,
  30. rParamF(Pfreq, rShort("freq"), rLinear(0.0,1.0), "frequency of LFO\n"
  31. "lfo frequency = (2^(10*Pfreq)-1)/12 * stretch\n"
  32. "true frequency is [0,85.33] Hz"),
  33. rParamZyn(Pintensity, rShort("depth"), "Intensity of LFO"),
  34. rParamZyn(Pstartphase, rShort("start"), rSpecial(random), "Starting Phase"),
  35. rOption(PLFOtype, rShort("type"), rOptions(sine, triangle, square, up, down,
  36. exp1, exp2), "Shape of LFO"),
  37. rParamZyn(Prandomness, rShort("a.r."), rSpecial(disable),
  38. "Amplitude Randomness (calculated uniformly at each cycle)"),
  39. rParamZyn(Pfreqrand, rShort("f.r."), rSpecial(disable), rDefault(0),
  40. "Frequency Randomness (calculated uniformly at each cycle)"),
  41. rParamZyn(Pdelay, rShort("delay"), rSpecial(disable), "Delay before LFO start\n"
  42. "0..4 second delay"),
  43. rToggle(Pcontinous, rShort("c"), "Enable for global operation"),
  44. rParamZyn(Pstretch, rShort("str"), rCentered, rDefault(64),
  45. "Note frequency stretch"),
  46. // these are currently not yet implemented at must be hidden therefore
  47. #ifdef DEAD_PORTS
  48. //Float valued aliases
  49. {"delay::f", rProp(parameter) rMap(units, ms) rLog(0,4000), 0,
  50. rBegin;
  51. rEnd},
  52. #define rPseudoLog(a,b) rLog(a,b)
  53. {"period::f", rProp(parameter) rMap(units, ms) rPseudoLog(0.10, 1500.0), 0,
  54. rBegin;
  55. rEnd},
  56. #endif
  57. };
  58. #undef rPseudoLog
  59. #undef rBegin
  60. #undef rEnd
  61. #undef rChangeCb
  62. const rtosc::Ports &LFOParams::ports = _ports;
  63. LFOParams::LFOParams(const AbsTime *time_) : time(time_)
  64. {
  65. Dfreq = 64;
  66. Dintensity = 0;
  67. Dstartphase = 0;
  68. DLFOtype = 0;
  69. Drandomness = 0;
  70. Ddelay = 0;
  71. Dcontinous = 0;
  72. fel = 0;
  73. defaults();
  74. }
  75. LFOParams::LFOParams(char Pfreq_,
  76. char Pintensity_,
  77. char Pstartphase_,
  78. char PLFOtype_,
  79. char Prandomness_,
  80. char Pdelay_,
  81. char Pcontinous_,
  82. char fel_,
  83. const AbsTime *time_) : time(time_),
  84. last_update_timestamp(0) {
  85. switch(fel_) {
  86. case 0:
  87. setpresettype("Plfofrequency");
  88. break;
  89. case 1:
  90. setpresettype("Plfoamplitude");
  91. break;
  92. case 2:
  93. setpresettype("Plfofilter");
  94. break;
  95. }
  96. Dfreq = Pfreq_;
  97. Dintensity = Pintensity_;
  98. Dstartphase = Pstartphase_;
  99. DLFOtype = PLFOtype_;
  100. Drandomness = Prandomness_;
  101. Ddelay = Pdelay_;
  102. Dcontinous = Pcontinous_;
  103. fel = fel_;
  104. defaults();
  105. }
  106. LFOParams::~LFOParams()
  107. {}
  108. void LFOParams::defaults()
  109. {
  110. Pfreq = Dfreq / 127.0f;
  111. Pintensity = Dintensity;
  112. Pstartphase = Dstartphase;
  113. PLFOtype = DLFOtype;
  114. Prandomness = Drandomness;
  115. Pdelay = Ddelay;
  116. Pcontinous = Dcontinous;
  117. Pfreqrand = 0;
  118. Pstretch = 64;
  119. }
  120. void LFOParams::add2XML(XMLwrapper& xml)
  121. {
  122. xml.addparreal("freq", Pfreq);
  123. xml.addpar("intensity", Pintensity);
  124. xml.addpar("start_phase", Pstartphase);
  125. xml.addpar("lfo_type", PLFOtype);
  126. xml.addpar("randomness_amplitude", Prandomness);
  127. xml.addpar("randomness_frequency", Pfreqrand);
  128. xml.addpar("delay", Pdelay);
  129. xml.addpar("stretch", Pstretch);
  130. xml.addparbool("continous", Pcontinous);
  131. }
  132. void LFOParams::getfromXML(XMLwrapper& xml)
  133. {
  134. Pfreq = xml.getparreal("freq", Pfreq, 0.0f, 1.0f);
  135. Pintensity = xml.getpar127("intensity", Pintensity);
  136. Pstartphase = xml.getpar127("start_phase", Pstartphase);
  137. PLFOtype = xml.getpar127("lfo_type", PLFOtype);
  138. Prandomness = xml.getpar127("randomness_amplitude", Prandomness);
  139. Pfreqrand = xml.getpar127("randomness_frequency", Pfreqrand);
  140. Pdelay = xml.getpar127("delay", Pdelay);
  141. Pstretch = xml.getpar127("stretch", Pstretch);
  142. Pcontinous = xml.getparbool("continous", Pcontinous);
  143. }
  144. #define COPY(y) this->y=x.y
  145. void LFOParams::paste(LFOParams &x)
  146. {
  147. COPY(Pfreq);
  148. COPY(Pintensity);
  149. COPY(Pstartphase);
  150. COPY(PLFOtype);
  151. COPY(Prandomness);
  152. COPY(Pfreqrand);
  153. COPY(Pdelay);
  154. COPY(Pcontinous);
  155. COPY(Pstretch);
  156. if ( time ) {
  157. last_update_timestamp = time->time();
  158. }
  159. }
  160. #undef COPY
  161. }