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.

308 lines
9.2KB

  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(),
  25. fAboutWindow(this),
  26. dsp((PowerJuiceX2Plugin*)d_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. d_programChanged(0);
  87. }
  88. // -----------------------------------------------------------------------
  89. // DSP Callbacks
  90. void PowerJuiceX2UI::d_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::d_programChanged(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.exec();
  133. }
  134. void PowerJuiceX2UI::imageKnobDragStarted(ImageKnob* knob)
  135. {
  136. if (knob == fKnobAttack)
  137. d_editParameter(PowerJuiceX2Plugin::paramAttack, true);
  138. else if (knob == fKnobRelease)
  139. d_editParameter(PowerJuiceX2Plugin::paramRelease, true);
  140. else if (knob == fKnobThreshold)
  141. d_editParameter(PowerJuiceX2Plugin::paramThreshold, true);
  142. else if (knob == fKnobRatio)
  143. d_editParameter(PowerJuiceX2Plugin::paramRatio, true);
  144. else if (knob == fKnobMakeup)
  145. d_editParameter(PowerJuiceX2Plugin::paramMakeup, true);
  146. else if (knob == fKnobMix)
  147. d_editParameter(PowerJuiceX2Plugin::paramMix, true);
  148. }
  149. void PowerJuiceX2UI::imageKnobDragFinished(ImageKnob* knob)
  150. {
  151. if (knob == fKnobAttack)
  152. d_editParameter(PowerJuiceX2Plugin::paramAttack, false);
  153. else if (knob == fKnobRelease)
  154. d_editParameter(PowerJuiceX2Plugin::paramRelease, false);
  155. else if (knob == fKnobThreshold)
  156. d_editParameter(PowerJuiceX2Plugin::paramThreshold, false);
  157. else if (knob == fKnobRatio)
  158. d_editParameter(PowerJuiceX2Plugin::paramRatio, false);
  159. else if (knob == fKnobMakeup)
  160. d_editParameter(PowerJuiceX2Plugin::paramMakeup, false);
  161. else if (knob == fKnobMix)
  162. d_editParameter(PowerJuiceX2Plugin::paramMix, false);
  163. }
  164. void PowerJuiceX2UI::imageKnobValueChanged(ImageKnob* knob, float value)
  165. {
  166. if (knob == fKnobAttack)
  167. d_setParameterValue(PowerJuiceX2Plugin::paramAttack, value);
  168. else if (knob == fKnobRelease)
  169. d_setParameterValue(PowerJuiceX2Plugin::paramRelease, value);
  170. else if (knob == fKnobThreshold)
  171. d_setParameterValue(PowerJuiceX2Plugin::paramThreshold, value);
  172. else if (knob == fKnobRatio)
  173. d_setParameterValue(PowerJuiceX2Plugin::paramRatio, value);
  174. else if (knob == fKnobMakeup)
  175. d_setParameterValue(PowerJuiceX2Plugin::paramMakeup, value);
  176. else if (knob == fKnobMix)
  177. d_setParameterValue(PowerJuiceX2Plugin::paramMix, value);
  178. }
  179. void PowerJuiceX2UI::d_uiIdle()
  180. {
  181. if (dsp != nullptr && dsp->repaintNeeded())
  182. repaint();
  183. }
  184. void PowerJuiceX2UI::onDisplay()
  185. {
  186. fImgBackground.draw();
  187. if (dsp == nullptr)
  188. return;
  189. int w = 563; //waveform plane size, size of the plane in pixels;
  190. int w2 = 1126; //wavefowm array
  191. int h = 121; //waveform plane height
  192. int x = 27; //waveform plane positions
  193. int y = 53;
  194. int dc = 113; //0DC line y position
  195. glEnable(GL_BLEND);
  196. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  197. glEnable(GL_LINE_SMOOTH);
  198. glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
  199. float thresholdPosition = (-toIEC(fKnobThreshold->getValue()))/200*h+h+y;
  200. //draw waveform
  201. /*
  202. glColor4f(0.0f, 1.0f, 0.0f, 0.4f);
  203. glLineWidth(1.2f);
  204. for (int i=0; i<w; i++) {
  205. glBegin(GL_LINES);
  206. glVertex2i(x+i, -toIEC(shmData->input[i])/200*h+h+y);
  207. glVertex2i(x+i, y+h);
  208. glEnd();
  209. }
  210. */
  211. //draw RMS
  212. glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
  213. glLineWidth(2.0f);
  214. glBegin(GL_LINE_STRIP);
  215. for (int i=2; i<w; i++) {
  216. float value = dsp->getRMSHistory(i);
  217. if (value<thresholdPosition) {
  218. glColor4f(0.0f, 0.5f, 0.0f, 1.0f);
  219. } else {
  220. glColor4f(0.0f, 0.5f, 0.2f, 1.0f);
  221. }
  222. glVertex2i(x+i, value);
  223. }
  224. glEnd();
  225. //draw gain reduction
  226. glColor4f(1.0f, 1.0f, 1.0f, 0.3f);
  227. glLineWidth(3.0f);
  228. glBegin(GL_LINES);
  229. for (int i=2; i<w; i++) {
  230. glColor4f(1.0f, 1.0f, 1.0f, 0.3f);
  231. float value = dsp->getGainReductionHistory(i);
  232. glVertex2i(x+i, value);
  233. glVertex2i(x+i, y);
  234. value = dsp->getRMSHistory(i);
  235. glColor4f(0.0f, 0.5f, 0.2f, 0.1f);
  236. glVertex2i(x+i, value);
  237. glVertex2i(x+i, y+h);
  238. }
  239. glEnd();
  240. //draw Threshold
  241. glLineWidth(2.0f);
  242. glColor4f(0.4f, 0.4f, 1.0f, 0.8f);
  243. //float thresholdPosition = ((60-fKnobThreshold->getValue())/60);
  244. glBegin(GL_LINES);
  245. glVertex2i(x, thresholdPosition);
  246. glVertex2i(x+w, thresholdPosition);
  247. glEnd();
  248. // reset color
  249. glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  250. }
  251. // -----------------------------------------------------------------------
  252. UI* createUI()
  253. {
  254. return new PowerJuiceX2UI();
  255. }
  256. // -----------------------------------------------------------------------
  257. END_NAMESPACE_DISTRHO