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.

280 lines
7.8KB

  1. /*
  2. * ZamComp mono compressor
  3. * Copyright (C) 2014 Damien Zammit <damien@zamaudio.com>
  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 "ZamCompPlugin.hpp"
  18. #include "ZamCompUI.hpp"
  19. START_NAMESPACE_DISTRHO
  20. // -----------------------------------------------------------------------
  21. ZamCompUI::ZamCompUI()
  22. : UI()
  23. {
  24. // background
  25. fImgBackground = Image(ZamCompArtwork::zamcompData, ZamCompArtwork::zamcompWidth, ZamCompArtwork::zamcompHeight, GL_BGR);
  26. // led images
  27. fLedRedImg = Image(ZamCompArtwork::ledredData, ZamCompArtwork::ledredWidth, ZamCompArtwork::ledredHeight);
  28. fLedYellowImg = Image(ZamCompArtwork::ledyellowData, ZamCompArtwork::ledyellowWidth, ZamCompArtwork::ledyellowHeight);
  29. // led values
  30. fLedRedValue = 0.0f;
  31. fLedYellowValue = 0.0f;
  32. // knob
  33. Image knobImage(ZamCompArtwork::knobData, ZamCompArtwork::knobWidth, ZamCompArtwork::knobHeight);
  34. // knob
  35. fKnobAttack = new ImageKnob(this, knobImage);
  36. fKnobAttack->setAbsolutePos(24, 45);
  37. fKnobAttack->setId(ZamCompPlugin::paramAttack);
  38. fKnobAttack->setRange(0.1f, 200.0f);
  39. fKnobAttack->setStep(0.1f);
  40. fKnobAttack->setUsingLogScale(true);
  41. fKnobAttack->setDefault(10.0f);
  42. fKnobAttack->setRotationAngle(240);
  43. fKnobAttack->setCallback(this);
  44. fKnobRelease = new ImageKnob(this, knobImage);
  45. fKnobRelease->setAbsolutePos(108, 45);
  46. fKnobRelease->setId(ZamCompPlugin::paramRelease);
  47. fKnobRelease->setRange(50.0f, 500.0f);
  48. fKnobRelease->setStep(1.0f);
  49. fKnobRelease->setDefault(80.0f);
  50. fKnobRelease->setRotationAngle(240);
  51. fKnobRelease->setCallback(this);
  52. fKnobThresh = new ImageKnob(this, knobImage);
  53. fKnobThresh->setAbsolutePos(191.5, 45);
  54. fKnobThresh->setId(ZamCompPlugin::paramThresh);
  55. fKnobThresh->setRange(-60.0f, 0.0f);
  56. fKnobThresh->setStep(1.0f);
  57. fKnobThresh->setDefault(0.0f);
  58. fKnobThresh->setRotationAngle(240);
  59. fKnobThresh->setCallback(this);
  60. fKnobRatio = new ImageKnob(this, knobImage);
  61. fKnobRatio->setAbsolutePos(270, 45);
  62. fKnobRatio->setId(ZamCompPlugin::paramRatio);
  63. fKnobRatio->setRange(1.0f, 20.0f);
  64. fKnobRatio->setStep(0.1f);
  65. fKnobRatio->setDefault(4.0f);
  66. fKnobRatio->setRotationAngle(240);
  67. fKnobRatio->setCallback(this);
  68. fKnobKnee = new ImageKnob(this, knobImage);
  69. fKnobKnee->setAbsolutePos(348.5, 45);
  70. fKnobKnee->setId(ZamCompPlugin::paramKnee);
  71. fKnobKnee->setRange(0.0f, 8.0f);
  72. fKnobKnee->setStep(0.1f);
  73. fKnobKnee->setDefault(0.0f);
  74. fKnobKnee->setRotationAngle(240);
  75. fKnobKnee->setCallback(this);
  76. fKnobMakeup = new ImageKnob(this, knobImage);
  77. fKnobMakeup->setAbsolutePos(427.3, 45);
  78. fKnobMakeup->setId(ZamCompPlugin::paramMakeup);
  79. fKnobMakeup->setRange(-30.0f, 30.0f);
  80. fKnobMakeup->setStep(1.0f);
  81. fKnobMakeup->setDefault(0.0f);
  82. fKnobMakeup->setRotationAngle(240);
  83. fKnobMakeup->setCallback(this);
  84. // set default values
  85. d_programChanged(0);
  86. }
  87. // -----------------------------------------------------------------------
  88. // DSP Callbacks
  89. void ZamCompUI::d_parameterChanged(uint32_t index, float value)
  90. {
  91. switch (index)
  92. {
  93. case ZamCompPlugin::paramAttack:
  94. fKnobAttack->setValue(value);
  95. break;
  96. case ZamCompPlugin::paramRelease:
  97. fKnobRelease->setValue(value);
  98. break;
  99. case ZamCompPlugin::paramThresh:
  100. fKnobThresh->setValue(value);
  101. break;
  102. case ZamCompPlugin::paramRatio:
  103. fKnobRatio->setValue(value);
  104. break;
  105. case ZamCompPlugin::paramKnee:
  106. fKnobKnee->setValue(value);
  107. break;
  108. case ZamCompPlugin::paramMakeup:
  109. fKnobMakeup->setValue(value);
  110. break;
  111. case ZamCompPlugin::paramGainR:
  112. if (fLedRedValue != value)
  113. {
  114. fLedRedValue = value;
  115. repaint();
  116. }
  117. break;
  118. case ZamCompPlugin::paramOutputLevel:
  119. if (fLedYellowValue != value)
  120. {
  121. fLedYellowValue = value;
  122. repaint();
  123. }
  124. break;
  125. }
  126. }
  127. void ZamCompUI::d_programChanged(uint32_t index)
  128. {
  129. if (index != 0)
  130. return;
  131. // Default values
  132. fKnobAttack->setValue(10.0f);
  133. fKnobRelease->setValue(80.0f);
  134. fKnobThresh->setValue(0.0f);
  135. fKnobRatio->setValue(4.0f);
  136. fKnobKnee->setValue(0.0f);
  137. fKnobMakeup->setValue(0.0f);
  138. }
  139. // -----------------------------------------------------------------------
  140. // Widget Callbacks
  141. void ZamCompUI::imageKnobDragStarted(ImageKnob* knob)
  142. {
  143. d_editParameter(knob->getId(), true);
  144. }
  145. void ZamCompUI::imageKnobDragFinished(ImageKnob* knob)
  146. {
  147. d_editParameter(knob->getId(), false);
  148. }
  149. void ZamCompUI::imageKnobValueChanged(ImageKnob* knob, float value)
  150. {
  151. d_setParameterValue(knob->getId(), value);
  152. }
  153. void ZamCompUI::onDisplay()
  154. {
  155. fImgBackground.draw();
  156. // draw leds
  157. static const float sLedSpacing = 15.5f;
  158. static const int sLedInitialX = 498;
  159. static const int sYellowLedStaticY = 16;
  160. static const int sRedLedStaticY = 45;
  161. int numRedLeds;
  162. int numYellowLeds;
  163. if (fLedRedValue >= 40.f)
  164. numRedLeds = 12;
  165. else if (fLedRedValue >= 30.f)
  166. numRedLeds = 11;
  167. else if (fLedRedValue >= 20.f)
  168. numRedLeds = 10;
  169. else if (fLedRedValue >= 15.f)
  170. numRedLeds = 9;
  171. else if (fLedRedValue >= 10.f)
  172. numRedLeds = 8;
  173. else if (fLedRedValue >= 8.f)
  174. numRedLeds = 7;
  175. else if (fLedRedValue >= 6.f)
  176. numRedLeds = 6;
  177. else if (fLedRedValue >= 5.f)
  178. numRedLeds = 5;
  179. else if (fLedRedValue >= 4.f)
  180. numRedLeds = 4;
  181. else if (fLedRedValue >= 3.f)
  182. numRedLeds = 3;
  183. else if (fLedRedValue >= 2.f)
  184. numRedLeds = 2;
  185. else if (fLedRedValue >= 1.f)
  186. numRedLeds = 1;
  187. else numRedLeds = 0;
  188. for (int i=numRedLeds; i>0; --i)
  189. fLedRedImg.drawAt(sLedInitialX + (12 - i)*sLedSpacing, sRedLedStaticY);
  190. if (fLedYellowValue >= 20.f)
  191. numYellowLeds = 19;
  192. else if (fLedYellowValue >= 10.f)
  193. numYellowLeds = 18;
  194. else if (fLedYellowValue >= 8.f)
  195. numYellowLeds = 17;
  196. else if (fLedYellowValue >= 4.f)
  197. numYellowLeds = 16;
  198. else if (fLedYellowValue >= 2.f)
  199. numYellowLeds = 15;
  200. else if (fLedYellowValue >= 1.f)
  201. numYellowLeds = 14;
  202. else if (fLedYellowValue >= 0.f)
  203. numYellowLeds = 13;
  204. else if (fLedYellowValue >= -1.f)
  205. numYellowLeds = 12;
  206. else if (fLedYellowValue >= -2.f)
  207. numYellowLeds = 11;
  208. else if (fLedYellowValue >= -3.f)
  209. numYellowLeds = 10;
  210. else if (fLedYellowValue >= -4.f)
  211. numYellowLeds = 9;
  212. else if (fLedYellowValue >= -5.f)
  213. numYellowLeds = 8;
  214. else if (fLedYellowValue >= -6.f)
  215. numYellowLeds = 7;
  216. else if (fLedYellowValue >= -8.f)
  217. numYellowLeds = 6;
  218. else if (fLedYellowValue >= -10.f)
  219. numYellowLeds = 5;
  220. else if (fLedYellowValue >= -15.f)
  221. numYellowLeds = 4;
  222. else if (fLedYellowValue >= -20.f)
  223. numYellowLeds = 3;
  224. else if (fLedYellowValue >= -30.f)
  225. numYellowLeds = 2;
  226. else if (fLedYellowValue >= -40.f)
  227. numYellowLeds = 1;
  228. else numYellowLeds = 0;
  229. if (numYellowLeds > 12) {
  230. for (int i=12; i<numYellowLeds; ++i)
  231. fLedRedImg.drawAt(sLedInitialX + i*sLedSpacing, sYellowLedStaticY);
  232. for (int i=0; i<12; ++i)
  233. fLedYellowImg.drawAt(sLedInitialX + i*sLedSpacing, sYellowLedStaticY);
  234. } else {
  235. for (int i=0; i<numYellowLeds; ++i)
  236. fLedYellowImg.drawAt(sLedInitialX + i*sLedSpacing, sYellowLedStaticY);
  237. }
  238. }
  239. // -----------------------------------------------------------------------
  240. UI* createUI()
  241. {
  242. return new ZamCompUI();
  243. }
  244. // -----------------------------------------------------------------------
  245. END_NAMESPACE_DISTRHO