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.

VectorJuicePlugin.cpp 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. #include "VectorJuicePlugin.hpp"
  18. START_NAMESPACE_DISTRHO
  19. // -----------------------------------------------------------------------
  20. VectorJuicePlugin::VectorJuicePlugin()
  21. : Plugin(paramCount, 1, 0) // 1 program, 0 states
  22. {
  23. // set default values
  24. loadProgram(0);
  25. }
  26. // -----------------------------------------------------------------------
  27. // Init
  28. void VectorJuicePlugin::initParameter(uint32_t index, Parameter& parameter)
  29. {
  30. switch (index)
  31. {
  32. case paramX:
  33. parameter.hints = kParameterIsAutomable;
  34. parameter.name = "X";
  35. parameter.symbol = "x";
  36. parameter.ranges.def = 0.5f;
  37. parameter.ranges.min = 0.0f;
  38. parameter.ranges.max = 1.0f;
  39. break;
  40. case paramY:
  41. parameter.hints = kParameterIsAutomable;
  42. parameter.name = "Y";
  43. parameter.symbol = "y";
  44. parameter.ranges.def = 0.5f;
  45. parameter.ranges.min = 0.0f;
  46. parameter.ranges.max = 1.0f;
  47. break;
  48. case paramOrbitSizeX:
  49. parameter.hints = kParameterIsAutomable;
  50. parameter.name = "Orbit Size X";
  51. parameter.symbol = "sizex";
  52. parameter.ranges.def = 0.5f;
  53. parameter.ranges.min = 0.0f;
  54. parameter.ranges.max = 1.0f;
  55. break;
  56. case paramOrbitSizeY:
  57. parameter.hints = kParameterIsAutomable;
  58. parameter.name = "Orbit Size Y";
  59. parameter.symbol = "sizey";
  60. parameter.ranges.def = 0.5f;
  61. parameter.ranges.min = 0.0f;
  62. parameter.ranges.max = 1.0f;
  63. break;
  64. case paramOrbitSpeedX:
  65. parameter.hints = kParameterIsAutomable|kParameterIsInteger;
  66. parameter.name = "Orbit Speed X";
  67. parameter.symbol = "speedx";
  68. parameter.ranges.def = 4.0f;
  69. parameter.ranges.min = 1.0f;
  70. parameter.ranges.max = 128.0f;
  71. break;
  72. case paramOrbitSpeedY:
  73. parameter.hints = kParameterIsAutomable|kParameterIsInteger;
  74. parameter.name = "Orbit Speed Y";
  75. parameter.symbol = "speedy";
  76. parameter.ranges.def = 4.0f;
  77. parameter.ranges.min = 1.0f;
  78. parameter.ranges.max = 128.0f;
  79. break;
  80. case paramSubOrbitSize:
  81. parameter.hints = kParameterIsAutomable;
  82. parameter.name = "SubOrbit Size";
  83. parameter.symbol = "subsize";
  84. parameter.ranges.def = 0.5f;
  85. parameter.ranges.min = 0.0f;
  86. parameter.ranges.max = 1.0f;
  87. break;
  88. case paramSubOrbitSpeed:
  89. parameter.hints = kParameterIsAutomable;
  90. parameter.name = "SubOrbit Speed";
  91. parameter.symbol = "subspeed";
  92. parameter.ranges.def = 32.0f;
  93. parameter.ranges.min = 1.0f;
  94. parameter.ranges.max = 128.0f;
  95. break;
  96. case paramSubOrbitSmooth:
  97. parameter.hints = kParameterIsAutomable;
  98. parameter.name = "SubOrbit Wave";
  99. parameter.symbol = "subwave";
  100. parameter.ranges.def = 0.5f;
  101. parameter.ranges.min = 0.0f;
  102. parameter.ranges.max = 1.0f;
  103. break;
  104. case paramOrbitWaveX:
  105. parameter.hints = kParameterIsAutomable|kParameterIsInteger;
  106. parameter.name = "Orbit Wave X";
  107. parameter.symbol = "wavex";
  108. parameter.ranges.def = 3.0f;
  109. parameter.ranges.min = 1.0f;
  110. parameter.ranges.max = 4.0f;
  111. break;
  112. case paramOrbitWaveY:
  113. parameter.hints = kParameterIsAutomable|kParameterIsInteger;
  114. parameter.name = "Orbit Wave Y";
  115. parameter.symbol = "wavey";
  116. parameter.ranges.def = 3.0f;
  117. parameter.ranges.min = 1.0f;
  118. parameter.ranges.max = 4.0f;
  119. break;
  120. case paramOrbitPhaseX:
  121. parameter.hints = kParameterIsAutomable|kParameterIsInteger;
  122. parameter.name = "Orbit Phase X";
  123. parameter.symbol = "phasex";
  124. parameter.ranges.def = 1.0f;
  125. parameter.ranges.min = 1.0f;
  126. parameter.ranges.max = 4.0f;
  127. break;
  128. case paramOrbitPhaseY:
  129. parameter.hints = kParameterIsAutomable|kParameterIsInteger;
  130. parameter.name = "Orbit Phase Y";
  131. parameter.symbol = "phasey";
  132. parameter.ranges.def = 1.0f;
  133. parameter.ranges.min = 1.0f;
  134. parameter.ranges.max = 4.0f;
  135. break;
  136. case paramOrbitOutX:
  137. parameter.hints = kParameterIsOutput;
  138. parameter.name = "Orbit X";
  139. parameter.symbol = "orx";
  140. parameter.ranges.def = 0.5f;
  141. parameter.ranges.min = 0.0f;
  142. parameter.ranges.max = 1.0f;
  143. break;
  144. case paramOrbitOutY:
  145. parameter.hints = kParameterIsOutput;
  146. parameter.name = "Orbit Y";
  147. parameter.symbol = "ory";
  148. parameter.ranges.def = 0.5f;
  149. parameter.ranges.min = 0.0f;
  150. parameter.ranges.max = 1.0f;
  151. break;
  152. case paramSubOrbitOutX:
  153. parameter.hints = kParameterIsOutput;
  154. parameter.name = "SubOrbit X";
  155. parameter.symbol = "sorx";
  156. parameter.ranges.def = 0.5f;
  157. parameter.ranges.min = 0.0f;
  158. parameter.ranges.max = 1.0f;
  159. break;
  160. case paramSubOrbitOutY:
  161. parameter.hints = kParameterIsOutput;
  162. parameter.name = "SubOrbit Y";
  163. parameter.symbol = "sory";
  164. parameter.ranges.def = 0.5f;
  165. parameter.ranges.min = 0.0f;
  166. parameter.ranges.max = 1.0f;
  167. break;
  168. }
  169. }
  170. void VectorJuicePlugin::initProgramName(uint32_t index, String& programName)
  171. {
  172. if (index != 0)
  173. return;
  174. programName = "Default";
  175. }
  176. // -----------------------------------------------------------------------
  177. // Internal data
  178. float VectorJuicePlugin::getParameterValue(uint32_t index) const
  179. {
  180. switch (index)
  181. {
  182. case paramX:
  183. return x;
  184. case paramY:
  185. return y;
  186. case paramOrbitSizeX:
  187. return orbitSizeX;
  188. case paramOrbitSizeY:
  189. return orbitSizeY;
  190. case paramOrbitSpeedX:
  191. return orbitSpeedX;
  192. case paramOrbitSpeedY:
  193. return orbitSpeedY;
  194. case paramSubOrbitSize:
  195. return subOrbitSize;
  196. case paramSubOrbitSpeed:
  197. return subOrbitSpeed;
  198. case paramSubOrbitSmooth:
  199. return subOrbitSmooth;
  200. case paramOrbitWaveX:
  201. return orbitWaveX;
  202. case paramOrbitWaveY:
  203. return orbitWaveY;
  204. case paramOrbitPhaseX:
  205. return orbitPhaseY;
  206. case paramOrbitPhaseY:
  207. return orbitPhaseY;
  208. case paramOrbitOutX:
  209. return orbitX;
  210. case paramOrbitOutY:
  211. return orbitY;
  212. case paramSubOrbitOutX:
  213. return subOrbitX;
  214. case paramSubOrbitOutY:
  215. return subOrbitY;
  216. default:
  217. return 0.0f;
  218. }
  219. }
  220. void VectorJuicePlugin::setParameterValue(uint32_t index, float value)
  221. {
  222. bool resetPhase = false;
  223. switch (index)
  224. {
  225. case paramX:
  226. x = value;
  227. break;
  228. case paramY:
  229. y = value;
  230. break;
  231. case paramOrbitSizeX:
  232. orbitSizeX = value;
  233. break;
  234. case paramOrbitSizeY:
  235. orbitSizeY = value;
  236. break;
  237. case paramOrbitSpeedX:
  238. orbitSpeedX = value;
  239. resetPhase = true;
  240. break;
  241. case paramOrbitSpeedY:
  242. orbitSpeedY = value;
  243. resetPhase = true;
  244. break;
  245. case paramSubOrbitSize:
  246. subOrbitSize = value;
  247. break;
  248. case paramSubOrbitSpeed:
  249. subOrbitSpeed = value;
  250. resetPhase = true;
  251. break;
  252. case paramSubOrbitSmooth:
  253. subOrbitSmooth = value;
  254. break;
  255. case paramOrbitWaveX:
  256. orbitWaveX = value;
  257. break;
  258. case paramOrbitWaveY:
  259. orbitWaveY = value;
  260. break;
  261. case paramOrbitPhaseX:
  262. orbitPhaseX = value;
  263. resetPhase = true;
  264. break;
  265. case paramOrbitPhaseY:
  266. orbitPhaseY = value;
  267. resetPhase = true;
  268. break;
  269. }
  270. if (resetPhase)
  271. {
  272. sinePosX = 0;
  273. sinePosY = 0;
  274. sinePos = 0;
  275. }
  276. }
  277. void VectorJuicePlugin::loadProgram(uint32_t index)
  278. {
  279. if (index != 0)
  280. return;
  281. /* Default parameter values */
  282. x = 0.5f;
  283. y = 0.5f;
  284. orbitSizeX = 0.5f;
  285. orbitSizeY = 0.5f;
  286. orbitSpeedX = 4.0f;
  287. orbitSpeedY = 4.0f;
  288. subOrbitSize = 0.5f;
  289. subOrbitSpeed = 32.0f;
  290. subOrbitSmooth = 0.5f;
  291. orbitWaveX = 3.0f;
  292. orbitWaveY = 3.0f;
  293. orbitPhaseX = 1.0f;
  294. orbitPhaseY = 1.0f;
  295. /* reset filter values */
  296. activate();
  297. }
  298. // -----------------------------------------------------------------------
  299. // Process
  300. void VectorJuicePlugin::activate()
  301. {
  302. /* Default variable values */
  303. orbitX=orbitY=orbitTX=orbitTY=0.5;
  304. subOrbitX=subOrbitY=subOrbitTX=subOrbitTY=0;
  305. interpolationDivider=200;
  306. bar=tickX=tickY=percentageX=percentageY=tickOffsetX=0;
  307. tickOffsetY=sinePosX=sinePosY=tick=percentage=tickOffset=sinePos=0;
  308. waveBlend=0;
  309. //parameter smoothing
  310. for (int i=0; i<2; i++) {
  311. sA[i] = 0.99f;
  312. sB[i] = 1.f - sA[i];
  313. sZ[i] = 0;
  314. }
  315. }
  316. void VectorJuicePlugin::run(const float** inputs, float** outputs, uint32_t frames)
  317. {
  318. float out1, out2, tX, tY;
  319. for (uint32_t i=0; i<frames; i++) {
  320. //1.41421 -> 1
  321. //<0 = 0
  322. animate();
  323. tX = subOrbitX;
  324. tY = subOrbitY;
  325. out1 = inputs[0][i]*tN(1-std::sqrt((tX*tX)+(tY*tY)));
  326. out2 = inputs[1][i]*tN(1-std::sqrt((tX*tX)+(tY*tY)));
  327. out1 += inputs[2][i]*tN(1-std::sqrt(((1-tX)*(1-tX))+(tY*tY)));
  328. out2 += inputs[3][i]*tN(1-std::sqrt(((1-tX)*(1-tX))+(tY*tY)));
  329. out1 += inputs[4][i]*tN(1-std::sqrt(((1-tX)*(1-tX))+((1-tY)*(1-tY))));
  330. out2 += inputs[5][i]*tN(1-std::sqrt(((1-tX)*(1-tX))+((1-tY)*(1-tY))));
  331. out1 += inputs[6][i]*tN(1-std::sqrt((tX*tX)+((1-tY)*(1-tY))));
  332. out2 += inputs[7][i]*tN(1-std::sqrt((tX*tX)+((1-tY)*(1-tY))));
  333. outputs[0][i] = out1;
  334. outputs[1][i] = out2;
  335. }
  336. }
  337. // -----------------------------------------------------------------------
  338. Plugin* createPlugin()
  339. {
  340. return new VectorJuicePlugin();
  341. }
  342. // -----------------------------------------------------------------------
  343. END_NAMESPACE_DISTRHO