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.

237 lines
7.3KB

  1. /*
  2. * Vector Juice Plugin
  3. * Copyright (C) 2014 Andre Sklenar <andre.sklenar@gmail.com>, www.juicelab.cz
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef VECTORJUICEPLUGIN_HPP_INCLUDED
  18. #define VECTORJUICEPLUGIN_HPP_INCLUDED
  19. #include "DistrhoPlugin.hpp"
  20. START_NAMESPACE_DISTRHO
  21. // -----------------------------------------------------------------------
  22. class VectorJuicePlugin : public Plugin
  23. {
  24. public:
  25. enum Parameters
  26. {
  27. paramX = 0,
  28. paramY,
  29. paramOrbitSizeX,
  30. paramOrbitSizeY,
  31. paramOrbitSpeedX,
  32. paramOrbitSpeedY,
  33. paramSubOrbitSize,
  34. paramSubOrbitSpeed,
  35. paramSubOrbitSmooth,
  36. paramOrbitWaveX,
  37. paramOrbitWaveY,
  38. paramOrbitPhaseX,
  39. paramOrbitPhaseY,
  40. paramOrbitOutX,
  41. paramOrbitOutY,
  42. paramSubOrbitOutX,
  43. paramSubOrbitOutY,
  44. paramCount
  45. };
  46. float smoothParameter(float in, int axis) {
  47. sZ[axis] = (in * sB[axis]) + (sZ[axis] * sA[axis]);
  48. return sZ[axis];
  49. }
  50. float getSinePhase(float x) {
  51. return (-std::sin(x));
  52. }
  53. float getSawPhase(float x) {
  54. return (-(2/M_PI *std::atan(1/std::tan(x/2))));
  55. }
  56. float getRevSawPhase(float x) {
  57. return ((2/M_PI *std::atan(1/std::tan(x/2))));
  58. }
  59. float getSquarePhase(float x) {
  60. return (std::round((std::sin(x)+1)/2)-0.5)*2;
  61. }
  62. //saw, sqr, sin, revSaw
  63. float getBlendedPhase(float x, float wave)
  64. {
  65. //wave = 2;
  66. if (wave>=1 && wave<2) {
  67. /* saw vs sqr */
  68. waveBlend = wave-1;
  69. return (getSawPhase(x)*(1-waveBlend) + getSquarePhase(x)*waveBlend);
  70. } else if (wave>=2 && wave<3) {
  71. /* sqr vs sin */
  72. waveBlend = wave-2;
  73. return (getSquarePhase(x)*(1-waveBlend) + getSinePhase(x)*waveBlend);
  74. } else if (wave>=3 && wave<=4) {
  75. /* sin vs revSaw */
  76. waveBlend = wave-3;
  77. return (getSinePhase(x)*(1-waveBlend) + getRevSawPhase(x)*waveBlend);
  78. } else {
  79. return 0.0f;
  80. }
  81. }
  82. float tN(float x)
  83. {
  84. if (x>0) return x;
  85. else return 0;
  86. }
  87. void animate()
  88. {
  89. //sync orbit with frame, bpm
  90. const TimePos& time = d_getTimePos();
  91. bar = ((120.0/(time.bbt.valid ? time.bbt.beatsPerMinute : 120.0))*(d_getSampleRate()));
  92. int multiplier = 16;//2000*4;
  93. tickX = bar/(std::round(orbitSpeedX))*multiplier;
  94. tickY = bar/(std::round(orbitSpeedY))*multiplier;
  95. tick = bar/(std::round(subOrbitSpeed))*multiplier;
  96. if (time.playing)
  97. {
  98. /* if rolling then sync to timepos */
  99. tickOffsetX = time.frame-std::floor(time.frame/tickX)*tickX;
  100. tickOffsetY = time.frame-std::floor(time.frame/tickY)*tickY;
  101. tickOffset = time.frame-std::floor(time.frame/tick)*tick;
  102. percentageX = tickOffsetX/tickX;
  103. percentageY = tickOffsetY/tickY;
  104. percentage = tickOffset/tick;
  105. sinePosX = (M_PI*2)*percentageX;
  106. sinePosY = (M_PI*2)*percentageY;
  107. sinePos = (M_PI*2)*percentage;
  108. } else {
  109. /* else just keep on wobblin' */
  110. sinePosX += (2*M_PI)/(tickX);
  111. sinePosY += (2*M_PI)/(tickY);
  112. sinePos += (M_PI)/(tick);
  113. if (sinePosX>2*M_PI) {
  114. sinePosX = 0;
  115. }
  116. if (sinePosY>2*M_PI) {
  117. sinePosY = 0;
  118. }
  119. if (sinePos>2*M_PI) {
  120. sinePos = 0;
  121. }
  122. }
  123. //0..1
  124. //0..3
  125. //0, 1, 2, 3
  126. //* 0.25
  127. //0, 0.25, 0.5, 0.75
  128. float tempPhaseX = std::round(orbitPhaseX)*0.25-0.25;
  129. float tempPhaseY = std::round(orbitPhaseY)*0.25-0.25;
  130. orbitX = x+getBlendedPhase(sinePosX + tempPhaseX*(2*M_PI), std::round(orbitWaveX))*(orbitSizeX/2);
  131. orbitY = y+getBlendedPhase(sinePosY+M_PI/2 + tempPhaseY*(2*M_PI), std::round(orbitWaveY))*(orbitSizeY/2);
  132. subOrbitX = smoothParameter(orbitX+getBlendedPhase(sinePos, 3)*(subOrbitSize/3), 0);
  133. subOrbitY = smoothParameter(orbitY+getBlendedPhase(sinePos+M_PI/2, 3)*(subOrbitSize/3), 1);
  134. if (orbitX<0) orbitX=0;
  135. if (orbitX>1) orbitX=1;
  136. if (orbitY<0) orbitY=0;
  137. if (orbitY>1) orbitY=1;
  138. if (subOrbitX<0) subOrbitX=0;
  139. if (subOrbitX>1) subOrbitX=1;
  140. if (subOrbitY<0) subOrbitY=0;
  141. if (subOrbitY>1) subOrbitY=1;
  142. }
  143. VectorJuicePlugin();
  144. protected:
  145. // -------------------------------------------------------------------
  146. // Information
  147. const char* d_getLabel() const noexcept override
  148. {
  149. return "VectorJuice";
  150. }
  151. const char* d_getMaker() const noexcept override
  152. {
  153. return "Andre Sklenar";
  154. }
  155. const char* d_getLicense() const noexcept override
  156. {
  157. return "GPL v2+";
  158. }
  159. uint32_t d_getVersion() const noexcept override
  160. {
  161. return 0x1000;
  162. }
  163. long d_getUniqueId() const noexcept override
  164. {
  165. return d_cconst('V', 'e', 'c', 'J');
  166. }
  167. // -------------------------------------------------------------------
  168. // Init
  169. void d_initParameter(uint32_t index, Parameter& parameter) override;
  170. void d_initProgramName(uint32_t index, d_string& programName) override;
  171. // -------------------------------------------------------------------
  172. // Internal data
  173. float d_getParameterValue(uint32_t index) const override;
  174. void d_setParameterValue(uint32_t index, float value) override;
  175. void d_setProgram(uint32_t index) override;
  176. // -------------------------------------------------------------------
  177. // Process
  178. void d_activate() override;
  179. void d_run(const float** inputs, float** outputs, uint32_t frames) override;
  180. // -------------------------------------------------------------------
  181. private:
  182. float x, y;
  183. float orbitX, orbitY;
  184. float orbitTX, orbitTY; //targetX and targetY for interpolation
  185. float subOrbitX, subOrbitY;
  186. float subOrbitTX, subOrbitTY;
  187. float subOrbitSpeed, subOrbitSize, orbitSpeedX, orbitSpeedY;
  188. float orbitSizeX, orbitSizeY;
  189. float interpolationDivider;
  190. float bar, tickX, tickY, percentageX, percentageY, tickOffsetX, tickOffsetY;
  191. float sinePosX, sinePosY, tick, percentage, tickOffset, sinePos;
  192. float orbitWaveX, orbitWaveY, subOrbitSmooth, waveBlend;
  193. float orbitPhaseX, orbitPhaseY;
  194. //parameter smoothing, for subOrbitX and subOrbitY
  195. float sA[2], sB[2], sZ[2];
  196. };
  197. // -----------------------------------------------------------------------
  198. END_NAMESPACE_DISTRHO
  199. #endif // VECTORJUICE_HPP_INCLUDED