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.

313 lines
9.4KB

  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(PowerJuiceArtwork::backgroundWidth, PowerJuiceArtwork::backgroundHeight),
  25. fAboutWindow(this),
  26. dsp((PowerJuicePlugin*)getPluginInstancePointer())
  27. {
  28. DISTRHO_SAFE_ASSERT(dsp != nullptr);
  29. // background
  30. fImgBackground = Image(PowerJuiceArtwork::backgroundData, PowerJuiceArtwork::backgroundWidth, PowerJuiceArtwork::backgroundHeight, GL_BGR);
  31. // about
  32. Image imageAbout(PowerJuiceArtwork::aboutData, PowerJuiceArtwork::aboutWidth, PowerJuiceArtwork::aboutHeight, GL_BGR);
  33. fAboutWindow.setImage(imageAbout);
  34. // knobs
  35. Image knobImage(PowerJuiceArtwork::knobData, PowerJuiceArtwork::knobWidth, PowerJuiceArtwork::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(PowerJuiceArtwork::aboutButtonNormalData, PowerJuiceArtwork::aboutButtonNormalWidth, PowerJuiceArtwork::aboutButtonNormalHeight);
  81. Image aboutImageHover(PowerJuiceArtwork::aboutButtonHoverData, PowerJuiceArtwork::aboutButtonHoverWidth, PowerJuiceArtwork::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. // automatically-scale
  88. setGeometryConstraints(PowerJuiceArtwork::backgroundWidth, PowerJuiceArtwork::backgroundHeight, true, true);
  89. }
  90. // -----------------------------------------------------------------------
  91. // DSP Callbacks
  92. void PowerJuiceUI::parameterChanged(uint32_t index, float value)
  93. {
  94. switch (index)
  95. {
  96. case PowerJuicePlugin::paramAttack:
  97. fKnobAttack->setValue(value);
  98. break;
  99. case PowerJuicePlugin::paramRelease:
  100. fKnobRelease->setValue(value);
  101. break;
  102. case PowerJuicePlugin::paramThreshold:
  103. fKnobThreshold->setValue(value);
  104. break;
  105. case PowerJuicePlugin::paramRatio:
  106. fKnobRatio->setValue(value);
  107. break;
  108. case PowerJuicePlugin::paramMakeup:
  109. fKnobMakeup->setValue(value);
  110. break;
  111. case PowerJuicePlugin::paramMix:
  112. fKnobMix->setValue(value);
  113. break;
  114. }
  115. }
  116. void PowerJuiceUI::programLoaded(uint32_t index)
  117. {
  118. if (index != 0)
  119. return;
  120. // Default values
  121. fKnobAttack->setValue(20.0f);
  122. fKnobRelease->setValue(200.0f);
  123. fKnobThreshold->setValue(0.0f);
  124. fKnobRatio->setValue(1.0f);
  125. fKnobMakeup->setValue(0.0f);
  126. fKnobMix->setValue(1.0f);
  127. }
  128. // -----------------------------------------------------------------------
  129. // Widget Callbacks
  130. void PowerJuiceUI::imageButtonClicked(ImageButton* button, int)
  131. {
  132. if (button != fButtonAbout)
  133. return;
  134. fAboutWindow.runAsModal();
  135. }
  136. void PowerJuiceUI::imageKnobDragStarted(ImageKnob* knob)
  137. {
  138. if (knob == fKnobAttack)
  139. editParameter(PowerJuicePlugin::paramAttack, true);
  140. else if (knob == fKnobRelease)
  141. editParameter(PowerJuicePlugin::paramRelease, true);
  142. else if (knob == fKnobThreshold)
  143. editParameter(PowerJuicePlugin::paramThreshold, true);
  144. else if (knob == fKnobRatio)
  145. editParameter(PowerJuicePlugin::paramRatio, true);
  146. else if (knob == fKnobMakeup)
  147. editParameter(PowerJuicePlugin::paramMakeup, true);
  148. else if (knob == fKnobMix)
  149. editParameter(PowerJuicePlugin::paramMix, true);
  150. }
  151. void PowerJuiceUI::imageKnobDragFinished(ImageKnob* knob)
  152. {
  153. if (knob == fKnobAttack)
  154. editParameter(PowerJuicePlugin::paramAttack, false);
  155. else if (knob == fKnobRelease)
  156. editParameter(PowerJuicePlugin::paramRelease, false);
  157. else if (knob == fKnobThreshold)
  158. editParameter(PowerJuicePlugin::paramThreshold, false);
  159. else if (knob == fKnobRatio)
  160. editParameter(PowerJuicePlugin::paramRatio, false);
  161. else if (knob == fKnobMakeup)
  162. editParameter(PowerJuicePlugin::paramMakeup, false);
  163. else if (knob == fKnobMix)
  164. editParameter(PowerJuicePlugin::paramMix, false);
  165. }
  166. void PowerJuiceUI::imageKnobValueChanged(ImageKnob* knob, float value)
  167. {
  168. if (knob == fKnobAttack)
  169. setParameterValue(PowerJuicePlugin::paramAttack, value);
  170. else if (knob == fKnobRelease)
  171. setParameterValue(PowerJuicePlugin::paramRelease, value);
  172. else if (knob == fKnobThreshold)
  173. setParameterValue(PowerJuicePlugin::paramThreshold, value);
  174. else if (knob == fKnobRatio)
  175. setParameterValue(PowerJuicePlugin::paramRatio, value);
  176. else if (knob == fKnobMakeup)
  177. setParameterValue(PowerJuicePlugin::paramMakeup, value);
  178. else if (knob == fKnobMix)
  179. setParameterValue(PowerJuicePlugin::paramMix, value);
  180. }
  181. void PowerJuiceUI::uiIdle()
  182. {
  183. if (dsp != nullptr && dsp->repaintNeeded())
  184. repaint();
  185. }
  186. void PowerJuiceUI::onDisplay()
  187. {
  188. const GraphicsContext& context(getGraphicsContext());
  189. fImgBackground.draw(context);
  190. if (dsp == nullptr)
  191. return;
  192. int w = 563; //waveform plane size, size of the plane in pixels;
  193. int w2 = 1126; //wavefowm array
  194. int h = 121; //waveform plane height
  195. int x = 27; //waveform plane positions
  196. int y = 53;
  197. int dc = 113; //0DC line y position
  198. glEnable(GL_BLEND);
  199. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  200. glEnable(GL_LINE_SMOOTH);
  201. glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
  202. float thresholdPosition = (-toIEC(fKnobThreshold->getValue()))/200*h+h+y;
  203. //draw waveform
  204. /*
  205. glColor4f(0.0f, 1.0f, 0.0f, 0.4f);
  206. glLineWidth(1.2f);
  207. for (int i=0; i<w; i++) {
  208. glBegin(GL_LINES);
  209. glVertex2i(x+i, -toIEC(shmData->input[i])/200*h+h+y);
  210. glVertex2i(x+i, y+h);
  211. glEnd();
  212. }
  213. */
  214. //draw RMS
  215. glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
  216. glLineWidth(2.0f);
  217. glBegin(GL_LINE_STRIP);
  218. for (int i=2; i<w; i++) {
  219. float value = dsp->getRMSHistory(i);
  220. if (value<thresholdPosition) {
  221. glColor4f(0.0f, 0.5f, 0.0f, 1.0f);
  222. } else {
  223. glColor4f(0.0f, 0.5f, 0.2f, 1.0f);
  224. }
  225. glVertex2i(x+i, value);
  226. }
  227. glEnd();
  228. //draw gain reduction
  229. glColor4f(1.0f, 1.0f, 1.0f, 0.3f);
  230. glLineWidth(3.0f);
  231. glBegin(GL_LINES);
  232. for (int i=2; i<w; i++) {
  233. glColor4f(1.0f, 1.0f, 1.0f, 0.3f);
  234. float value = dsp->getGainReductionHistory(i);
  235. glVertex2i(x+i, value);
  236. glVertex2i(x+i, y);
  237. value = dsp->getRMSHistory(i);
  238. glColor4f(0.0f, 0.5f, 0.2f, 0.1f);
  239. glVertex2i(x+i, value);
  240. glVertex2i(x+i, y+h);
  241. }
  242. glEnd();
  243. //draw Threshold
  244. glLineWidth(2.0f);
  245. glColor4f(0.4f, 0.4f, 1.0f, 0.8f);
  246. //float thresholdPosition = ((60-fKnobThreshold->getValue())/60);
  247. glBegin(GL_LINES);
  248. glVertex2i(x, thresholdPosition);
  249. glVertex2i(x+w, thresholdPosition);
  250. glEnd();
  251. // reset color
  252. glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  253. }
  254. // -----------------------------------------------------------------------
  255. UI* createUI()
  256. {
  257. return new PowerJuiceUI();
  258. }
  259. // -----------------------------------------------------------------------
  260. END_NAMESPACE_DISTRHO