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.

462 lines
14KB

  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. #include "VectorJuiceUI.hpp"
  19. using DGL_NAMESPACE::Point;
  20. START_NAMESPACE_DISTRHO
  21. // -----------------------------------------------------------------------
  22. VectorJuiceUI::VectorJuiceUI()
  23. : UI(),
  24. fAboutWindow(this)
  25. {
  26. setSize(VectorJuiceArtwork::backgroundWidth, VectorJuiceArtwork::backgroundHeight);
  27. // xy params
  28. paramX = paramY = 0.5f;
  29. // orbit params
  30. orbitX = orbitY = subOrbitX = subOrbitY = 0.5f;
  31. // set the XY canvas area
  32. fDragging = false;
  33. fDragValid = false;
  34. fLastX = fLastY = 0;
  35. fCanvasArea.setPos(22+12, 49+12);
  36. fCanvasArea.setSize(368-24, 368-24);
  37. // background
  38. fImgBackground = Image(VectorJuiceArtwork::backgroundData, VectorJuiceArtwork::backgroundWidth, VectorJuiceArtwork::backgroundHeight, GL_BGR);
  39. //roundlet
  40. fImgRoundlet = Image(VectorJuiceArtwork::roundletData, VectorJuiceArtwork::roundletWidth, VectorJuiceArtwork::roundletHeight);
  41. //orbit
  42. fImgOrbit = Image(VectorJuiceArtwork::orbitData, VectorJuiceArtwork::orbitWidth, VectorJuiceArtwork::orbitHeight);
  43. //subOrbit
  44. fImgSubOrbit = Image(VectorJuiceArtwork::subOrbitData, VectorJuiceArtwork::subOrbitWidth, VectorJuiceArtwork::subOrbitHeight);
  45. // about
  46. Image aboutImage(VectorJuiceArtwork::aboutData, VectorJuiceArtwork::aboutWidth, VectorJuiceArtwork::aboutHeight, GL_BGR);
  47. fAboutWindow.setImage(aboutImage);
  48. // about button
  49. Image aboutImageNormal(VectorJuiceArtwork::aboutButtonNormalData, VectorJuiceArtwork::aboutButtonNormalWidth, VectorJuiceArtwork::aboutButtonNormalHeight);
  50. Image aboutImageHover(VectorJuiceArtwork::aboutButtonHoverData, VectorJuiceArtwork::aboutButtonHoverWidth, VectorJuiceArtwork::aboutButtonHoverHeight);
  51. fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover);
  52. fButtonAbout->setAbsolutePos(599, 17);
  53. fButtonAbout->setCallback(this);
  54. // knobs
  55. Image knobImage(VectorJuiceArtwork::knobData, VectorJuiceArtwork::knobWidth, VectorJuiceArtwork::knobHeight);
  56. // knob KnobOrbitSizeX
  57. fKnobOrbitSizeX = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  58. fKnobOrbitSizeX->setId(VectorJuicePlugin::paramOrbitSizeX);
  59. fKnobOrbitSizeX->setAbsolutePos(423, 73);
  60. fKnobOrbitSizeX->setRotationAngle(270);
  61. fKnobOrbitSizeX->setRange(0.0f, 1.0f);
  62. fKnobOrbitSizeX->setDefault(0.5f);
  63. fKnobOrbitSizeX->setCallback(this);
  64. // knob KnobOrbitSizeY
  65. fKnobOrbitSizeY = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  66. fKnobOrbitSizeY->setId(VectorJuicePlugin::paramOrbitSizeY);
  67. fKnobOrbitSizeY->setAbsolutePos(516, 73);
  68. fKnobOrbitSizeY->setRotationAngle(270);
  69. fKnobOrbitSizeY->setRange(0.0f, 1.0f);
  70. fKnobOrbitSizeY->setDefault(0.5f);
  71. fKnobOrbitSizeY->setCallback(this);
  72. // knob KnobOrbitSpeedX
  73. fKnobOrbitSpeedX = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  74. fKnobOrbitSpeedX->setId(VectorJuicePlugin::paramOrbitSpeedX);
  75. fKnobOrbitSpeedX->setAbsolutePos(423, 185);
  76. fKnobOrbitSpeedX->setRotationAngle(270);
  77. fKnobOrbitSpeedX->setStep(1.0f);
  78. fKnobOrbitSpeedX->setRange(1.0f, 128.0f);
  79. fKnobOrbitSpeedX->setDefault(4.0f);
  80. fKnobOrbitSpeedX->setCallback(this);
  81. // knob KnobOrbitSpeedY
  82. fKnobOrbitSpeedY = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  83. fKnobOrbitSpeedY->setId(VectorJuicePlugin::paramOrbitSpeedY);
  84. fKnobOrbitSpeedY->setAbsolutePos(516, 185);
  85. fKnobOrbitSpeedY->setRotationAngle(270);
  86. fKnobOrbitSpeedY->setStep(1.0f);
  87. fKnobOrbitSpeedY->setRange(1.0f, 128.0f);
  88. fKnobOrbitSpeedY->setDefault(4.0f);
  89. fKnobOrbitSpeedY->setCallback(this);
  90. // knob KnobSubOrbitSize
  91. fKnobSubOrbitSize = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  92. fKnobSubOrbitSize->setId(VectorJuicePlugin::paramSubOrbitSize);
  93. fKnobSubOrbitSize->setAbsolutePos(620, 73);
  94. fKnobSubOrbitSize->setRange(0.0f, 1.0f);
  95. fKnobSubOrbitSize->setRotationAngle(270);
  96. fKnobSubOrbitSize->setDefault(0.5f);
  97. fKnobSubOrbitSize->setCallback(this);
  98. // knob KnobSubOrbitSpeed
  99. fKnobSubOrbitSpeed = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  100. fKnobSubOrbitSpeed->setId(VectorJuicePlugin::paramSubOrbitSpeed);
  101. fKnobSubOrbitSpeed->setAbsolutePos(620, 185);
  102. fKnobSubOrbitSpeed->setRotationAngle(270);
  103. fKnobSubOrbitSpeed->setStep(1.0f);
  104. fKnobSubOrbitSpeed->setRange(1.0f, 128.0f);
  105. fKnobSubOrbitSpeed->setDefault(32.0f);
  106. fKnobSubOrbitSpeed->setCallback(this);
  107. // knob KnobSubOrbitSmooth
  108. fKnobSubOrbitSmooth = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  109. fKnobSubOrbitSmooth->setId(VectorJuicePlugin::paramSubOrbitSmooth);
  110. fKnobSubOrbitSmooth->setAbsolutePos(620, 297);
  111. fKnobSubOrbitSmooth->setRotationAngle(270);
  112. fKnobSubOrbitSmooth->setRange(0.0f, 1.0f);
  113. fKnobSubOrbitSmooth->setDefault(0.5f);
  114. fKnobSubOrbitSmooth->setCallback(this);
  115. // sliders
  116. Image sliderImage(VectorJuiceArtwork::sliderData, VectorJuiceArtwork::sliderWidth, VectorJuiceArtwork::sliderHeight);
  117. Point<int> sliderPosStart(410, 284);
  118. Point<int> sliderPosEnd(410+48, 284);
  119. // slider OrbitWaveX
  120. fSliderOrbitWaveX = new ImageSlider(this, sliderImage);
  121. fSliderOrbitWaveX->setId(VectorJuicePlugin::paramOrbitWaveX);
  122. fSliderOrbitWaveX->setStartPos(sliderPosStart);
  123. fSliderOrbitWaveX->setEndPos(sliderPosEnd);
  124. fSliderOrbitWaveX->setRange(1.0f, 4.0f);
  125. fSliderOrbitWaveX->setStep(1.0f);
  126. fSliderOrbitWaveX->setCallback(this);
  127. // slider OrbitWaveY
  128. sliderPosStart.setX(503);
  129. sliderPosEnd.setX(503+48);
  130. fSliderOrbitWaveY = new ImageSlider(this, sliderImage);
  131. fSliderOrbitWaveY->setId(VectorJuicePlugin::paramOrbitWaveY);
  132. fSliderOrbitWaveY->setStartPos(sliderPosStart);
  133. fSliderOrbitWaveY->setEndPos(sliderPosEnd);
  134. fSliderOrbitWaveY->setRange(1.0f, 4.0f);
  135. fSliderOrbitWaveY->setStep(1.0f);
  136. fSliderOrbitWaveY->setCallback(this);
  137. // slider OrbitPhaseX
  138. sliderPosStart.setX(410);
  139. sliderPosStart.setY(345);
  140. sliderPosEnd.setX(410+48);
  141. sliderPosEnd.setY(345);
  142. fSliderOrbitPhaseX = new ImageSlider(this, sliderImage);
  143. fSliderOrbitPhaseX->setId(VectorJuicePlugin::paramOrbitPhaseX);
  144. fSliderOrbitPhaseX->setStartPos(sliderPosStart);
  145. fSliderOrbitPhaseX->setEndPos(sliderPosEnd);
  146. fSliderOrbitPhaseX->setRange(1.0f, 4.0f);
  147. fSliderOrbitPhaseX->setStep(1.0f);
  148. fSliderOrbitPhaseX->setCallback(this);
  149. // slider OrbitPhaseY
  150. sliderPosStart.setX(503);
  151. sliderPosEnd.setX(503+48);
  152. fSliderOrbitPhaseY = new ImageSlider(this, sliderImage);
  153. fSliderOrbitPhaseY->setId(VectorJuicePlugin::paramOrbitPhaseY);
  154. fSliderOrbitPhaseY->setStartPos(sliderPosStart);
  155. fSliderOrbitPhaseY->setEndPos(sliderPosEnd);
  156. fSliderOrbitPhaseY->setRange(1.0f, 4.0f);
  157. fSliderOrbitPhaseY->setStep(1.0f);
  158. fSliderOrbitPhaseY->setCallback(this);
  159. // set default values
  160. programLoaded(0);
  161. }
  162. // -----------------------------------------------------------------------
  163. // DSP Callbacks
  164. void VectorJuiceUI::parameterChanged(uint32_t index, float value)
  165. {
  166. switch (index)
  167. {
  168. case VectorJuicePlugin::paramX:
  169. if (paramX != value)
  170. {
  171. paramX = value;
  172. fDragValid = false;
  173. repaint();
  174. }
  175. break;
  176. case VectorJuicePlugin::paramY:
  177. if (paramY != value)
  178. {
  179. paramY = value;
  180. fDragValid = false;
  181. repaint();
  182. }
  183. break;
  184. case VectorJuicePlugin::paramOrbitSizeX:
  185. fKnobOrbitSizeX->setValue(value);
  186. break;
  187. case VectorJuicePlugin::paramOrbitSizeY:
  188. fKnobOrbitSizeY->setValue(value);
  189. break;
  190. case VectorJuicePlugin::paramOrbitSpeedX:
  191. fKnobOrbitSpeedX->setValue(value);
  192. break;
  193. case VectorJuicePlugin::paramOrbitSpeedY:
  194. fKnobOrbitSpeedY->setValue(value);
  195. break;
  196. case VectorJuicePlugin::paramSubOrbitSize:
  197. fKnobSubOrbitSize->setValue(value);
  198. break;
  199. case VectorJuicePlugin::paramSubOrbitSpeed:
  200. fKnobSubOrbitSpeed->setValue(value);
  201. break;
  202. case VectorJuicePlugin::paramSubOrbitSmooth:
  203. fKnobSubOrbitSmooth->setValue(value);
  204. break;
  205. case VectorJuicePlugin::paramOrbitWaveX:
  206. fSliderOrbitWaveX->setValue(value);
  207. break;
  208. case VectorJuicePlugin::paramOrbitWaveY:
  209. fSliderOrbitWaveY->setValue(value);
  210. break;
  211. case VectorJuicePlugin::paramOrbitPhaseX:
  212. fSliderOrbitPhaseX->setValue(value);
  213. break;
  214. case VectorJuicePlugin::paramOrbitPhaseY:
  215. fSliderOrbitPhaseY->setValue(value);
  216. break;
  217. case VectorJuicePlugin::paramOrbitOutX:
  218. if (orbitX != value)
  219. {
  220. orbitX = value;
  221. repaint();
  222. }
  223. break;
  224. case VectorJuicePlugin::paramOrbitOutY:
  225. if (orbitY != value)
  226. {
  227. orbitY = value;
  228. repaint();
  229. }
  230. break;
  231. case VectorJuicePlugin::paramSubOrbitOutX:
  232. if (subOrbitX != value)
  233. {
  234. subOrbitX = value;
  235. repaint();
  236. }
  237. break;
  238. case VectorJuicePlugin::paramSubOrbitOutY:
  239. if (subOrbitY != value)
  240. {
  241. subOrbitY = value;
  242. repaint();
  243. }
  244. break;
  245. }
  246. }
  247. void VectorJuiceUI::programLoaded(uint32_t index)
  248. {
  249. if (index != 0)
  250. return;
  251. // Default values
  252. paramX = paramY = 0.5f;
  253. fKnobOrbitSizeX->setValue(0.5f);
  254. fKnobOrbitSizeY->setValue(0.5f);
  255. fKnobOrbitSpeedX->setValue(4.0f);
  256. fKnobOrbitSpeedY->setValue(4.0f);
  257. fKnobSubOrbitSize->setValue(0.5f);
  258. fKnobSubOrbitSpeed->setValue(32.0f);
  259. fKnobSubOrbitSmooth->setValue(0.5f);
  260. fSliderOrbitWaveX->setValue(3.0f);
  261. fSliderOrbitWaveY->setValue(3.0f);
  262. fSliderOrbitPhaseX->setValue(1.0f);
  263. fSliderOrbitPhaseY->setValue(1.0f);
  264. }
  265. // -----------------------------------------------------------------------
  266. // Widget Callbacks
  267. void VectorJuiceUI::imageButtonClicked(ImageButton* button, int)
  268. {
  269. if (button != fButtonAbout)
  270. return;
  271. fAboutWindow.exec();
  272. }
  273. void VectorJuiceUI::imageKnobDragStarted(ImageKnob* knob)
  274. {
  275. editParameter(knob->getId(), true);
  276. }
  277. void VectorJuiceUI::imageKnobDragFinished(ImageKnob* knob)
  278. {
  279. editParameter(knob->getId(), false);
  280. }
  281. void VectorJuiceUI::imageKnobValueChanged(ImageKnob* knob, float value)
  282. {
  283. setParameterValue(knob->getId(), value);
  284. }
  285. void VectorJuiceUI::imageSliderDragStarted(ImageSlider* slider)
  286. {
  287. editParameter(slider->getId(), true);
  288. }
  289. void VectorJuiceUI::imageSliderDragFinished(ImageSlider* slider)
  290. {
  291. editParameter(slider->getId(), false);
  292. }
  293. void VectorJuiceUI::imageSliderValueChanged(ImageSlider* slider, float value)
  294. {
  295. setParameterValue(slider->getId(), value);
  296. }
  297. void VectorJuiceUI::onDisplay()
  298. {
  299. fImgBackground.draw();
  300. // get x, y mapped to XY area
  301. int x = fCanvasArea.getX() + paramX*fCanvasArea.getWidth() - fImgRoundlet.getWidth()/2;
  302. int y = fCanvasArea.getY() + paramY*fCanvasArea.getHeight() - fImgRoundlet.getHeight()/2;
  303. int nOrbitX = fCanvasArea.getX()+((orbitX)*fCanvasArea.getWidth())-15;
  304. int nOrbitY = fCanvasArea.getY()+((orbitY)*fCanvasArea.getWidth())-15;
  305. int nSubOrbitX = fCanvasArea.getX()+(subOrbitX*fCanvasArea.getWidth())-15;
  306. int nSubOrbitY = fCanvasArea.getY()+(subOrbitY*fCanvasArea.getWidth())-14;
  307. //draw lines, just for fun
  308. glEnable(GL_BLEND);
  309. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  310. glColor4f(0.0f, 1.0f, 0.0f, 0.05f);
  311. glLineWidth(4);
  312. glBegin(GL_LINES);
  313. glVertex2i(x+ fImgRoundlet.getWidth()/2, y+ fImgRoundlet.getHeight()/2);
  314. glVertex2i(nOrbitX+15, nOrbitY+15);
  315. glEnd();
  316. glBegin(GL_LINES);
  317. glVertex2i(nOrbitX+15, nOrbitY+15);
  318. glVertex2i(nSubOrbitX+15, nSubOrbitY+14);
  319. glEnd();
  320. // reset color
  321. glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  322. // draw roundlet and orbits
  323. fImgRoundlet.drawAt(x, y);
  324. fImgOrbit.drawAt(nOrbitX, nOrbitY);
  325. fImgSubOrbit.drawAt(nSubOrbitX, nSubOrbitY);
  326. }
  327. bool VectorJuiceUI::onMouse(const MouseEvent& ev)
  328. {
  329. if (ev.button != 1)
  330. return false;
  331. if (ev.press)
  332. {
  333. if (! fCanvasArea.contains(ev.pos))
  334. return false;
  335. fDragging = true;
  336. fDragValid = true;
  337. fLastX = ev.pos.getX();
  338. fLastY = ev.pos.getY();
  339. return true;
  340. }
  341. else if (fDragging)
  342. {
  343. fDragging = false;
  344. return true;
  345. }
  346. return false;
  347. }
  348. bool VectorJuiceUI::onMotion(const MotionEvent& ev)
  349. {
  350. if (! fDragging)
  351. return false;
  352. const int x = ev.pos.getX();
  353. const int y = ev.pos.getY();
  354. if (! fDragValid)
  355. {
  356. fDragValid = true;
  357. fLastX = x;
  358. fLastY = y;
  359. }
  360. const int movedX = fLastX - x;
  361. const int movedY = fLastY - y;
  362. fLastX = x;
  363. fLastY = y;
  364. float newX = paramX;
  365. float newY = paramY;
  366. newX -= float(movedX)/fCanvasArea.getWidth();
  367. newY -= float(movedY)/fCanvasArea.getHeight();
  368. if (newX < 0.0f)
  369. newX = 0.0f;
  370. else if (newX > 1.0f)
  371. newX = 1.0f;
  372. if (newY < 0.0f)
  373. newY = 0.0f;
  374. else if (newY > 1.0f)
  375. newY = 1.0f;
  376. if (newX != paramX)
  377. {
  378. paramX = newX;
  379. setParameterValue(VectorJuicePlugin::paramX, paramX);
  380. repaint();
  381. }
  382. if (newY != paramY)
  383. {
  384. paramY = newY;
  385. setParameterValue(VectorJuicePlugin::paramY, paramY);
  386. repaint();
  387. }
  388. return true;
  389. }
  390. // -----------------------------------------------------------------------
  391. UI* createUI()
  392. {
  393. return new VectorJuiceUI();
  394. }
  395. // -----------------------------------------------------------------------
  396. END_NAMESPACE_DISTRHO