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.

PowerJuiceUI.cpp 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * Power 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 "PowerJuiceUI.hpp"
  18. #include <cstdlib>
  19. #include <ctime>
  20. using DGL::Point;
  21. START_NAMESPACE_DISTRHO
  22. // -----------------------------------------------------------------------
  23. PowerJuiceUI::PowerJuiceUI()
  24. : UI(),
  25. fAboutWindow(this),
  26. dsp((PowerJuicePlugin*)d_getPluginInstancePointer())
  27. {
  28. // background
  29. fImgBackground = Image(PowerJuiceArtwork::backgroundData, PowerJuiceArtwork::backgroundWidth, PowerJuiceArtwork::backgroundHeight, GL_BGR);
  30. // about
  31. Image imageAbout(PowerJuiceArtwork::aboutData, PowerJuiceArtwork::aboutWidth, PowerJuiceArtwork::aboutHeight, GL_BGR);
  32. fAboutWindow.setImage(imageAbout);
  33. // knobs
  34. Image knobImage(PowerJuiceArtwork::knobData, PowerJuiceArtwork::knobWidth, PowerJuiceArtwork::knobHeight);
  35. // knob Attack
  36. fKnobAttack = new ImageKnob(this, knobImage);
  37. fKnobAttack->setAbsolutePos(37, 213);
  38. fKnobAttack->setRange(0.1f, 1000.0f);
  39. fKnobAttack->setStep(0.1f);
  40. fKnobAttack->setValue(20.0f);
  41. fKnobAttack->setRotationAngle(270);
  42. fKnobAttack->setCallback(this);
  43. // knob Release
  44. fKnobRelease = new ImageKnob(this, knobImage);
  45. fKnobRelease->setAbsolutePos(136, 213);
  46. fKnobRelease->setRange(0.1f, 1000.0f);
  47. fKnobRelease->setValue(0.1f);
  48. fKnobRelease->setRotationAngle(270);
  49. fKnobRelease->setCallback(this);
  50. // knob Threshold
  51. fKnobThreshold = new ImageKnob(this, knobImage);
  52. fKnobThreshold->setAbsolutePos(235, 213);
  53. fKnobThreshold->setRange(-60.0f, 0.0f);
  54. fKnobThreshold->setValue(0.0f);
  55. fKnobThreshold->setRotationAngle(270);
  56. fKnobThreshold->setCallback(this);
  57. // knob Ratio
  58. fKnobRatio = new ImageKnob(this, knobImage);
  59. fKnobRatio->setAbsolutePos(334, 213);
  60. fKnobRatio->setRange(1.0f, 10.0f);
  61. fKnobRatio->setValue(1.0f);
  62. fKnobRatio->setRotationAngle(270);
  63. fKnobRatio->setCallback(this);
  64. // knob Make-Up
  65. fKnobMakeup = new ImageKnob(this, knobImage);
  66. fKnobMakeup->setAbsolutePos(433, 213);
  67. fKnobMakeup->setRange(0.0f, 20.0f);
  68. fKnobMakeup->setValue(0.0f);
  69. fKnobMakeup->setRotationAngle(270);
  70. fKnobMakeup->setCallback(this);
  71. // knob Mix
  72. fKnobMix = new ImageKnob(this, knobImage);
  73. fKnobMix->setAbsolutePos(532, 213);
  74. fKnobMix->setRange(0.0f, 1.0f);
  75. fKnobMix->setValue(1.0f);
  76. fKnobMix->setRotationAngle(270);
  77. fKnobMix->setCallback(this);
  78. // about button
  79. Image aboutImageNormal(PowerJuiceArtwork::aboutButtonNormalData, PowerJuiceArtwork::aboutButtonNormalWidth, PowerJuiceArtwork::aboutButtonNormalHeight);
  80. Image aboutImageHover(PowerJuiceArtwork::aboutButtonHoverData, PowerJuiceArtwork::aboutButtonHoverWidth, PowerJuiceArtwork::aboutButtonHoverHeight);
  81. fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover);
  82. fButtonAbout->setAbsolutePos(502, 17);
  83. fButtonAbout->setCallback(this);
  84. }
  85. // -----------------------------------------------------------------------
  86. // DSP Callbacks
  87. void PowerJuiceUI::d_parameterChanged(uint32_t index, float value)
  88. {
  89. switch (index)
  90. {
  91. case PowerJuicePlugin::paramAttack:
  92. fKnobAttack->setValue(value);
  93. break;
  94. case PowerJuicePlugin::paramRelease:
  95. fKnobRelease->setValue(value);
  96. break;
  97. case PowerJuicePlugin::paramThreshold:
  98. fKnobThreshold->setValue(value);
  99. break;
  100. case PowerJuicePlugin::paramRatio:
  101. fKnobRatio->setValue(value);
  102. break;
  103. case PowerJuicePlugin::paramMakeup:
  104. fKnobMakeup->setValue(value);
  105. break;
  106. case PowerJuicePlugin::paramMix:
  107. fKnobMix->setValue(value);
  108. break;
  109. }
  110. }
  111. void PowerJuiceUI::d_programChanged(uint32_t index)
  112. {
  113. if (index != 0)
  114. return;
  115. // Default values
  116. fKnobAttack->setValue(20.0f);
  117. fKnobRelease->setValue(200.0f);
  118. fKnobThreshold->setValue(0.0f);
  119. fKnobRatio->setValue(1.0f);
  120. fKnobMakeup->setValue(0.0f);
  121. fKnobMix->setValue(1.0f);
  122. }
  123. // -----------------------------------------------------------------------
  124. // Widget Callbacks
  125. void PowerJuiceUI::imageButtonClicked(ImageButton* button, int)
  126. {
  127. if (button != fButtonAbout)
  128. return;
  129. fAboutWindow.exec();
  130. }
  131. void PowerJuiceUI::imageKnobDragStarted(ImageKnob* knob)
  132. {
  133. if (knob == fKnobAttack)
  134. d_editParameter(PowerJuicePlugin::paramAttack, true);
  135. else if (knob == fKnobRelease)
  136. d_editParameter(PowerJuicePlugin::paramRelease, true);
  137. else if (knob == fKnobThreshold)
  138. d_editParameter(PowerJuicePlugin::paramThreshold, true);
  139. else if (knob == fKnobRatio)
  140. d_editParameter(PowerJuicePlugin::paramRatio, true);
  141. else if (knob == fKnobMakeup)
  142. d_editParameter(PowerJuicePlugin::paramMakeup, true);
  143. else if (knob == fKnobMix)
  144. d_editParameter(PowerJuicePlugin::paramMix, true);
  145. }
  146. void PowerJuiceUI::imageKnobDragFinished(ImageKnob* knob)
  147. {
  148. if (knob == fKnobAttack)
  149. d_editParameter(PowerJuicePlugin::paramAttack, false);
  150. else if (knob == fKnobRelease)
  151. d_editParameter(PowerJuicePlugin::paramRelease, false);
  152. else if (knob == fKnobThreshold)
  153. d_editParameter(PowerJuicePlugin::paramThreshold, false);
  154. else if (knob == fKnobRatio)
  155. d_editParameter(PowerJuicePlugin::paramRatio, false);
  156. else if (knob == fKnobMakeup)
  157. d_editParameter(PowerJuicePlugin::paramMakeup, false);
  158. else if (knob == fKnobMix)
  159. d_editParameter(PowerJuicePlugin::paramMix, false);
  160. }
  161. void PowerJuiceUI::imageKnobValueChanged(ImageKnob* knob, float value)
  162. {
  163. if (knob == fKnobAttack)
  164. d_setParameterValue(PowerJuicePlugin::paramAttack, value);
  165. else if (knob == fKnobRelease)
  166. d_setParameterValue(PowerJuicePlugin::paramRelease, value);
  167. else if (knob == fKnobThreshold)
  168. d_setParameterValue(PowerJuicePlugin::paramThreshold, value);
  169. else if (knob == fKnobRatio)
  170. d_setParameterValue(PowerJuicePlugin::paramRatio, value);
  171. else if (knob == fKnobMakeup)
  172. d_setParameterValue(PowerJuicePlugin::paramMakeup, value);
  173. else if (knob == fKnobMix)
  174. d_setParameterValue(PowerJuicePlugin::paramMix, value);
  175. }
  176. void PowerJuiceUI::d_uiIdle()
  177. {
  178. if (dsp != nullptr && dsp->repaintNeeded())
  179. repaint();
  180. }
  181. void PowerJuiceUI::onDisplay()
  182. {
  183. fImgBackground.draw();
  184. if (dsp == nullptr)
  185. return;
  186. int w = 563; //waveform plane size, size of the plane in pixels;
  187. int w2 = 1126; //wavefowm array
  188. int h = 121; //waveform plane height
  189. int x = 27; //waveform plane positions
  190. int y = 53;
  191. int dc = 113; //0DC line y position
  192. glEnable(GL_BLEND);
  193. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  194. glEnable(GL_LINE_SMOOTH);
  195. glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
  196. float thresholdPosition = (-toIEC(fKnobThreshold->getValue()))/200*h+h+y;
  197. //draw waveform
  198. /*
  199. glColor4f(0.0f, 1.0f, 0.0f, 0.4f);
  200. glLineWidth(1.2f);
  201. for (int i=0; i<w; i++) {
  202. glBegin(GL_LINES);
  203. glVertex2i(x+i, -toIEC(shmData->input[i])/200*h+h+y);
  204. glVertex2i(x+i, y+h);
  205. glEnd();
  206. }
  207. */
  208. //draw RMS
  209. glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
  210. glLineWidth(2.0f);
  211. glBegin(GL_LINE_STRIP);
  212. for (int i=2; i<w; i++) {
  213. float value = dsp->getRMSHistory(i);
  214. if (value<thresholdPosition) {
  215. glColor4f(0.0f, 0.5f, 0.0f, 1.0f);
  216. } else {
  217. glColor4f(0.0f, 0.5f, 0.2f, 1.0f);
  218. }
  219. glVertex2i(x+i, value);
  220. }
  221. glEnd();
  222. //draw gain reduction
  223. glColor4f(1.0f, 1.0f, 1.0f, 0.3f);
  224. glLineWidth(3.0f);
  225. glBegin(GL_LINES);
  226. for (int i=2; i<w; i++) {
  227. glColor4f(1.0f, 1.0f, 1.0f, 0.3f);
  228. float value = dsp->getGainReductionHistory(i);
  229. glVertex2i(x+i, value);
  230. glVertex2i(x+i, y);
  231. value = dsp->getRMSHistory(i);
  232. glColor4f(0.0f, 0.5f, 0.2f, 0.1f);
  233. glVertex2i(x+i, value);
  234. glVertex2i(x+i, y+h);
  235. }
  236. glEnd();
  237. //draw Threshold
  238. glLineWidth(2.0f);
  239. glColor4f(0.4f, 0.4f, 1.0f, 0.8f);
  240. //float thresholdPosition = ((60-fKnobThreshold->getValue())/60);
  241. glBegin(GL_LINES);
  242. glVertex2i(x, thresholdPosition);
  243. glVertex2i(x+w, thresholdPosition);
  244. glEnd();
  245. // reset color
  246. glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  247. }
  248. // -----------------------------------------------------------------------
  249. UI* createUI()
  250. {
  251. return new PowerJuiceUI();
  252. }
  253. // -----------------------------------------------------------------------
  254. END_NAMESPACE_DISTRHO