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.

159 lines
4.6KB

  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 modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include <cmath>
  18. #include <cstdio>
  19. #include "../globals.h"
  20. #include "../Misc/Util.h"
  21. #include "../Misc/XMLwrapper.h"
  22. #include "LFOParams.h"
  23. #include <rtosc/port-sugar.h>
  24. #include <rtosc/ports.h>
  25. using namespace rtosc;
  26. #define rObject LFOParams
  27. static const rtosc::Ports _ports = {
  28. rSelf(LFOParams),
  29. rPaste,
  30. rParamF(Pfreq, 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, "Intensity of LFO"),
  34. rParamZyn(Pstartphase, rSpecial(random), "Starting Phase"),
  35. rOption(PLFOtype, rOptions(sine, triangle, square, ramp-up, ramp-down,
  36. exponential-down1, exponential-down2), "Shape of LFO"),
  37. rParamZyn(Prandomness, rSpecial(disable), "Amplitude Randomness (calculated uniformly at each cycle)"),
  38. rParamZyn(Pfreqrand, rSpecial(disable), "Frequency Randomness (calculated uniformly at each cycle)"),
  39. rParamZyn(Pdelay, rSpecial(disable), "Delay before LFO start\n"
  40. "0..4 second delay"),
  41. rToggle(Pcontinous, "Enable for global operation"),
  42. rParamZyn(Pstretch, rCentered, "Note frequency stretch"),
  43. };
  44. const rtosc::Ports &LFOParams::ports = _ports;
  45. LFOParams::LFOParams()
  46. {
  47. Dfreq = 64;
  48. Dintensity = 0;
  49. Dstartphase = 0;
  50. DLFOtype = 0;
  51. Drandomness = 0;
  52. Ddelay = 0;
  53. Dcontinous = 0;
  54. fel = 0;
  55. defaults();
  56. }
  57. LFOParams::LFOParams(char Pfreq_,
  58. char Pintensity_,
  59. char Pstartphase_,
  60. char PLFOtype_,
  61. char Prandomness_,
  62. char Pdelay_,
  63. char Pcontinous_,
  64. char fel_)
  65. {
  66. switch(fel_) {
  67. case 0:
  68. setpresettype("Plfofrequency");
  69. break;
  70. case 1:
  71. setpresettype("Plfoamplitude");
  72. break;
  73. case 2:
  74. setpresettype("Plfofilter");
  75. break;
  76. }
  77. Dfreq = Pfreq_;
  78. Dintensity = Pintensity_;
  79. Dstartphase = Pstartphase_;
  80. DLFOtype = PLFOtype_;
  81. Drandomness = Prandomness_;
  82. Ddelay = Pdelay_;
  83. Dcontinous = Pcontinous_;
  84. fel = fel_;
  85. defaults();
  86. }
  87. LFOParams::~LFOParams()
  88. {}
  89. void LFOParams::defaults()
  90. {
  91. Pfreq = Dfreq / 127.0f;
  92. Pintensity = Dintensity;
  93. Pstartphase = Dstartphase;
  94. PLFOtype = DLFOtype;
  95. Prandomness = Drandomness;
  96. Pdelay = Ddelay;
  97. Pcontinous = Dcontinous;
  98. Pfreqrand = 0;
  99. Pstretch = 64;
  100. }
  101. void LFOParams::add2XML(XMLwrapper *xml)
  102. {
  103. xml->addparreal("freq", Pfreq);
  104. xml->addpar("intensity", Pintensity);
  105. xml->addpar("start_phase", Pstartphase);
  106. xml->addpar("lfo_type", PLFOtype);
  107. xml->addpar("randomness_amplitude", Prandomness);
  108. xml->addpar("randomness_frequency", Pfreqrand);
  109. xml->addpar("delay", Pdelay);
  110. xml->addpar("stretch", Pstretch);
  111. xml->addparbool("continous", Pcontinous);
  112. }
  113. void LFOParams::getfromXML(XMLwrapper *xml)
  114. {
  115. Pfreq = xml->getparreal("freq", Pfreq, 0.0f, 1.0f);
  116. Pintensity = xml->getpar127("intensity", Pintensity);
  117. Pstartphase = xml->getpar127("start_phase", Pstartphase);
  118. PLFOtype = xml->getpar127("lfo_type", PLFOtype);
  119. Prandomness = xml->getpar127("randomness_amplitude", Prandomness);
  120. Pfreqrand = xml->getpar127("randomness_frequency", Pfreqrand);
  121. Pdelay = xml->getpar127("delay", Pdelay);
  122. Pstretch = xml->getpar127("stretch", Pstretch);
  123. Pcontinous = xml->getparbool("continous", Pcontinous);
  124. }
  125. #define COPY(y) this->y=x.y
  126. void LFOParams::paste(LFOParams &x)
  127. {
  128. COPY(Pfreq);
  129. COPY(Pintensity);
  130. COPY(Pstartphase);
  131. COPY(PLFOtype);
  132. COPY(Prandomness);
  133. COPY(Pfreqrand);
  134. COPY(Pdelay);
  135. COPY(Pcontinous);
  136. COPY(Pstretch);
  137. }
  138. #undef COPY