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.

316 lines
9.1KB

  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 "ZamCompUI.hpp"
  18. using DGL::Point;
  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->setPos(24, 45);
  37. fKnobAttack->setRange(0.1f, 200.0f);
  38. fKnobAttack->setStep(0.1f);
  39. //fKnobAttack->setLogScale(true);
  40. //fKnobAttack->setDefault(10.0f);
  41. fKnobAttack->setRotationAngle(240);
  42. fKnobAttack->setCallback(this);
  43. fKnobRelease = new ImageKnob(this, knobImage);
  44. fKnobRelease->setPos(108, 45);
  45. fKnobRelease->setRange(50.0f, 500.0f);
  46. fKnobRelease->setStep(1.0f);
  47. //fKnobRelease->setDefault(80.0f);
  48. fKnobRelease->setRotationAngle(240);
  49. fKnobRelease->setCallback(this);
  50. fKnobThresh = new ImageKnob(this, knobImage);
  51. fKnobThresh->setPos(191.5, 45);
  52. fKnobThresh->setRange(-60.0f, 0.0f);
  53. fKnobThresh->setStep(1.0f);
  54. //fKnobThresh->setDefault(0.0f);
  55. fKnobThresh->setRotationAngle(240);
  56. fKnobThresh->setCallback(this);
  57. fKnobRatio = new ImageKnob(this, knobImage);
  58. fKnobRatio->setPos(270, 45);
  59. fKnobRatio->setRange(1.0f, 20.0f);
  60. fKnobRatio->setStep(0.1f);
  61. //fKnobRatio->setDefault(4.0f);
  62. fKnobRatio->setRotationAngle(240);
  63. fKnobRatio->setCallback(this);
  64. fKnobKnee = new ImageKnob(this, knobImage);
  65. fKnobKnee->setPos(348.5, 45);
  66. fKnobKnee->setRange(0.0f, 8.0f);
  67. fKnobKnee->setStep(0.1f);
  68. //fKnobKnee->setDefault(0.0f);
  69. fKnobKnee->setRotationAngle(240);
  70. fKnobKnee->setCallback(this);
  71. fKnobMakeup = new ImageKnob(this, knobImage);
  72. fKnobMakeup->setPos(427.3, 45);
  73. fKnobMakeup->setRange(-30.0f, 30.0f);
  74. fKnobMakeup->setStep(1.0f);
  75. //fKnobMakeup->setDefault(0.0f);
  76. fKnobMakeup->setRotationAngle(240);
  77. fKnobMakeup->setCallback(this);
  78. }
  79. ZamCompUI::~ZamCompUI()
  80. {
  81. delete fKnobAttack;
  82. delete fKnobRelease;
  83. delete fKnobThresh;
  84. delete fKnobRatio;
  85. delete fKnobKnee;
  86. delete fKnobMakeup;
  87. }
  88. // -----------------------------------------------------------------------
  89. // DSP Callbacks
  90. void ZamCompUI::d_parameterChanged(uint32_t index, float value)
  91. {
  92. switch (index)
  93. {
  94. case ZamCompPlugin::paramAttack:
  95. fKnobAttack->setValue(value);
  96. break;
  97. case ZamCompPlugin::paramRelease:
  98. fKnobRelease->setValue(value);
  99. break;
  100. case ZamCompPlugin::paramThresh:
  101. fKnobThresh->setValue(value);
  102. break;
  103. case ZamCompPlugin::paramRatio:
  104. fKnobRatio->setValue(value);
  105. break;
  106. case ZamCompPlugin::paramKnee:
  107. fKnobKnee->setValue(value);
  108. break;
  109. case ZamCompPlugin::paramMakeup:
  110. fKnobMakeup->setValue(value);
  111. break;
  112. case ZamCompPlugin::paramGainR:
  113. if (fLedRedValue != value)
  114. {
  115. fLedRedValue = value;
  116. repaint();
  117. }
  118. break;
  119. case ZamCompPlugin::paramOutputLevel:
  120. if (fLedYellowValue != value)
  121. {
  122. fLedYellowValue = value;
  123. repaint();
  124. }
  125. break;
  126. }
  127. }
  128. void ZamCompUI::d_programChanged(uint32_t index)
  129. {
  130. if (index != 0)
  131. return;
  132. /* Default values
  133. fKnobAttack->setDefault(10.0f);
  134. fKnobRelease->setDefault(80.0f);
  135. fKnobThresh->setDefault(0.0f);
  136. fKnobRatio->setDefault(4.0f);
  137. fKnobKnee->setDefault(0.0f);
  138. fKnobMakeup->setDefault(0.0f);
  139. */
  140. }
  141. // -----------------------------------------------------------------------
  142. // Widget Callbacks
  143. void ZamCompUI::imageKnobDragStarted(ImageKnob* knob)
  144. {
  145. if (knob == fKnobAttack)
  146. d_editParameter(ZamCompPlugin::paramAttack, true);
  147. else if (knob == fKnobRelease)
  148. d_editParameter(ZamCompPlugin::paramRelease, true);
  149. else if (knob == fKnobThresh)
  150. d_editParameter(ZamCompPlugin::paramThresh, true);
  151. else if (knob == fKnobRatio)
  152. d_editParameter(ZamCompPlugin::paramRatio, true);
  153. else if (knob == fKnobKnee)
  154. d_editParameter(ZamCompPlugin::paramKnee, true);
  155. else if (knob == fKnobMakeup)
  156. d_editParameter(ZamCompPlugin::paramMakeup, true);
  157. }
  158. void ZamCompUI::imageKnobDragFinished(ImageKnob* knob)
  159. {
  160. if (knob == fKnobAttack)
  161. d_editParameter(ZamCompPlugin::paramAttack, false);
  162. else if (knob == fKnobRelease)
  163. d_editParameter(ZamCompPlugin::paramRelease, false);
  164. else if (knob == fKnobThresh)
  165. d_editParameter(ZamCompPlugin::paramThresh, false);
  166. else if (knob == fKnobRatio)
  167. d_editParameter(ZamCompPlugin::paramRatio, false);
  168. else if (knob == fKnobKnee)
  169. d_editParameter(ZamCompPlugin::paramKnee, false);
  170. else if (knob == fKnobMakeup)
  171. d_editParameter(ZamCompPlugin::paramMakeup, false);
  172. }
  173. void ZamCompUI::imageKnobValueChanged(ImageKnob* knob, float value)
  174. {
  175. if (knob == fKnobAttack)
  176. d_setParameterValue(ZamCompPlugin::paramAttack, value);
  177. else if (knob == fKnobRelease)
  178. d_setParameterValue(ZamCompPlugin::paramRelease, value);
  179. else if (knob == fKnobThresh)
  180. d_setParameterValue(ZamCompPlugin::paramThresh, value);
  181. else if (knob == fKnobRatio)
  182. d_setParameterValue(ZamCompPlugin::paramRatio, value);
  183. else if (knob == fKnobKnee)
  184. d_setParameterValue(ZamCompPlugin::paramKnee, value);
  185. else if (knob == fKnobMakeup)
  186. d_setParameterValue(ZamCompPlugin::paramMakeup, value);
  187. }
  188. void ZamCompUI::onDisplay()
  189. {
  190. fImgBackground.draw();
  191. // draw leds
  192. static const float sLedSpacing = 15.5f;
  193. static const int sLedInitialX = 498;
  194. static const int sYellowLedStaticY = 16;
  195. static const int sRedLedStaticY = 45;
  196. int numRedLeds;
  197. int numYellowLeds;
  198. if (fLedRedValue >= 40.f)
  199. numRedLeds = 12;
  200. else if (fLedRedValue >= 30.f)
  201. numRedLeds = 11;
  202. else if (fLedRedValue >= 20.f)
  203. numRedLeds = 10;
  204. else if (fLedRedValue >= 15.f)
  205. numRedLeds = 9;
  206. else if (fLedRedValue >= 10.f)
  207. numRedLeds = 8;
  208. else if (fLedRedValue >= 8.f)
  209. numRedLeds = 7;
  210. else if (fLedRedValue >= 6.f)
  211. numRedLeds = 6;
  212. else if (fLedRedValue >= 5.f)
  213. numRedLeds = 5;
  214. else if (fLedRedValue >= 4.f)
  215. numRedLeds = 4;
  216. else if (fLedRedValue >= 3.f)
  217. numRedLeds = 3;
  218. else if (fLedRedValue >= 2.f)
  219. numRedLeds = 2;
  220. else if (fLedRedValue >= 1.f)
  221. numRedLeds = 1;
  222. else numRedLeds = 0;
  223. for (int i=numRedLeds; i>0; --i)
  224. fLedRedImg.draw(sLedInitialX + (12 - i)*sLedSpacing, sRedLedStaticY);
  225. if (fLedYellowValue >= 20.f)
  226. numYellowLeds = 19;
  227. else if (fLedYellowValue >= 10.f)
  228. numYellowLeds = 18;
  229. else if (fLedYellowValue >= 8.f)
  230. numYellowLeds = 17;
  231. else if (fLedYellowValue >= 4.f)
  232. numYellowLeds = 16;
  233. else if (fLedYellowValue >= 2.f)
  234. numYellowLeds = 15;
  235. else if (fLedYellowValue >= 1.f)
  236. numYellowLeds = 14;
  237. else if (fLedYellowValue >= 0.f)
  238. numYellowLeds = 13;
  239. else if (fLedYellowValue >= -1.f)
  240. numYellowLeds = 12;
  241. else if (fLedYellowValue >= -2.f)
  242. numYellowLeds = 11;
  243. else if (fLedYellowValue >= -3.f)
  244. numYellowLeds = 10;
  245. else if (fLedYellowValue >= -4.f)
  246. numYellowLeds = 9;
  247. else if (fLedYellowValue >= -5.f)
  248. numYellowLeds = 8;
  249. else if (fLedYellowValue >= -6.f)
  250. numYellowLeds = 7;
  251. else if (fLedYellowValue >= -8.f)
  252. numYellowLeds = 6;
  253. else if (fLedYellowValue >= -10.f)
  254. numYellowLeds = 5;
  255. else if (fLedYellowValue >= -15.f)
  256. numYellowLeds = 4;
  257. else if (fLedYellowValue >= -20.f)
  258. numYellowLeds = 3;
  259. else if (fLedYellowValue >= -30.f)
  260. numYellowLeds = 2;
  261. else if (fLedYellowValue >= -40.f)
  262. numYellowLeds = 1;
  263. else numYellowLeds = 0;
  264. if (numYellowLeds > 12) {
  265. for (int i=12; i<numYellowLeds; ++i)
  266. fLedRedImg.draw(sLedInitialX + i*sLedSpacing, sYellowLedStaticY);
  267. for (int i=0; i<12; ++i)
  268. fLedYellowImg.draw(sLedInitialX + i*sLedSpacing, sYellowLedStaticY);
  269. } else {
  270. for (int i=0; i<numYellowLeds; ++i)
  271. fLedYellowImg.draw(sLedInitialX + i*sLedSpacing, sYellowLedStaticY);
  272. }
  273. }
  274. // -----------------------------------------------------------------------
  275. UI* createUI()
  276. {
  277. return new ZamCompUI();
  278. }
  279. // -----------------------------------------------------------------------
  280. END_NAMESPACE_DISTRHO