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.

319 lines
9.3KB

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