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.

VectorJuiceUI.cpp 14KB

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