DISTRHO Juice Plugins
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.

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