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.

340 lines
10KB

  1. /*
  2. * ZamCompX2 Stereo 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 "ZamCompX2UI.hpp"
  18. using DGL::Point;
  19. START_NAMESPACE_DISTRHO
  20. // -----------------------------------------------------------------------
  21. ZamCompX2UI::ZamCompX2UI()
  22. : UI()
  23. {
  24. // background
  25. fImgBackground = Image(ZamCompX2Artwork::zamcompx2Data, ZamCompX2Artwork::zamcompx2Width, ZamCompX2Artwork::zamcompx2Height, GL_BGR);
  26. // led images
  27. fLedRedImg = Image(ZamCompX2Artwork::ledredData, ZamCompX2Artwork::ledredWidth, ZamCompX2Artwork::ledredHeight);
  28. fLedYellowImg = Image(ZamCompX2Artwork::ledyellowData, ZamCompX2Artwork::ledyellowWidth, ZamCompX2Artwork::ledyellowHeight);
  29. // led values
  30. fLedRedValue = 0.0f;
  31. fLedYellowValue = 0.0f;
  32. // knob
  33. Image knobImage(ZamCompX2Artwork::knobData, ZamCompX2Artwork::knobWidth, ZamCompX2Artwork::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. Image toggleonImage(ZamCompX2Artwork::toggleonData, ZamCompX2Artwork::toggleonWidth, ZamCompX2Artwork::toggleonHeight);
  79. Image toggleoffImage(ZamCompX2Artwork::toggleoffData, ZamCompX2Artwork::toggleoffWidth, ZamCompX2Artwork::toggleoffHeight);
  80. Point<int> togglePosStart(652,72);
  81. fToggleStereo = new ImageToggle(this, toggleoffImage, toggleoffImage, toggleonImage);
  82. fToggleStereo->setPos(togglePosStart);
  83. fToggleStereo->setCallback(this);
  84. }
  85. ZamCompX2UI::~ZamCompX2UI()
  86. {
  87. delete fKnobAttack;
  88. delete fKnobRelease;
  89. delete fKnobThresh;
  90. delete fKnobRatio;
  91. delete fKnobKnee;
  92. delete fKnobMakeup;
  93. delete fToggleStereo;
  94. }
  95. // -----------------------------------------------------------------------
  96. // DSP Callbacks
  97. void ZamCompX2UI::d_parameterChanged(uint32_t index, float value)
  98. {
  99. switch (index)
  100. {
  101. case ZamCompX2Plugin::paramAttack:
  102. fKnobAttack->setValue(value);
  103. break;
  104. case ZamCompX2Plugin::paramRelease:
  105. fKnobRelease->setValue(value);
  106. break;
  107. case ZamCompX2Plugin::paramThresh:
  108. fKnobThresh->setValue(value);
  109. break;
  110. case ZamCompX2Plugin::paramRatio:
  111. fKnobRatio->setValue(value);
  112. break;
  113. case ZamCompX2Plugin::paramKnee:
  114. fKnobKnee->setValue(value);
  115. break;
  116. case ZamCompX2Plugin::paramMakeup:
  117. fKnobMakeup->setValue(value);
  118. break;
  119. case ZamCompX2Plugin::paramGainRed:
  120. if (fLedRedValue != value)
  121. {
  122. fLedRedValue = value;
  123. repaint();
  124. }
  125. break;
  126. case ZamCompX2Plugin::paramOutputLevel:
  127. if (fLedYellowValue != value)
  128. {
  129. fLedYellowValue = value;
  130. repaint();
  131. }
  132. break;
  133. case ZamCompX2Plugin::paramStereo:
  134. //fToggleStereo->setValue((int)value);
  135. break;
  136. }
  137. }
  138. void ZamCompX2UI::d_programChanged(uint32_t index)
  139. {
  140. if (index != 0)
  141. return;
  142. // Default values
  143. /*
  144. fKnobAttack->setValue(10.0f);
  145. fKnobRelease->setValue(80.0f);
  146. fKnobThresh->setValue(0.0f);
  147. fKnobRatio->setValue(4.0f);
  148. fKnobKnee->setValue(0.0f);
  149. fKnobMakeup->setValue(0.0f);
  150. */
  151. //fToggleStereo->setValue(1.f);
  152. }
  153. // -----------------------------------------------------------------------
  154. // Widget Callbacks
  155. void ZamCompX2UI::imageKnobDragStarted(ImageKnob* knob)
  156. {
  157. if (knob == fKnobAttack)
  158. d_editParameter(ZamCompX2Plugin::paramAttack, true);
  159. else if (knob == fKnobRelease)
  160. d_editParameter(ZamCompX2Plugin::paramRelease, true);
  161. else if (knob == fKnobThresh)
  162. d_editParameter(ZamCompX2Plugin::paramThresh, true);
  163. else if (knob == fKnobRatio)
  164. d_editParameter(ZamCompX2Plugin::paramRatio, true);
  165. else if (knob == fKnobKnee)
  166. d_editParameter(ZamCompX2Plugin::paramKnee, true);
  167. else if (knob == fKnobMakeup)
  168. d_editParameter(ZamCompX2Plugin::paramMakeup, true);
  169. }
  170. void ZamCompX2UI::imageKnobDragFinished(ImageKnob* knob)
  171. {
  172. if (knob == fKnobAttack)
  173. d_editParameter(ZamCompX2Plugin::paramAttack, false);
  174. else if (knob == fKnobRelease)
  175. d_editParameter(ZamCompX2Plugin::paramRelease, false);
  176. else if (knob == fKnobThresh)
  177. d_editParameter(ZamCompX2Plugin::paramThresh, false);
  178. else if (knob == fKnobRatio)
  179. d_editParameter(ZamCompX2Plugin::paramRatio, false);
  180. else if (knob == fKnobKnee)
  181. d_editParameter(ZamCompX2Plugin::paramKnee, false);
  182. else if (knob == fKnobMakeup)
  183. d_editParameter(ZamCompX2Plugin::paramMakeup, false);
  184. }
  185. void ZamCompX2UI::imageKnobValueChanged(ImageKnob* knob, float value)
  186. {
  187. if (knob == fKnobAttack)
  188. d_setParameterValue(ZamCompX2Plugin::paramAttack, value);
  189. else if (knob == fKnobRelease)
  190. d_setParameterValue(ZamCompX2Plugin::paramRelease, value);
  191. else if (knob == fKnobThresh)
  192. d_setParameterValue(ZamCompX2Plugin::paramThresh, value);
  193. else if (knob == fKnobRatio)
  194. d_setParameterValue(ZamCompX2Plugin::paramRatio, value);
  195. else if (knob == fKnobKnee)
  196. d_setParameterValue(ZamCompX2Plugin::paramKnee, value);
  197. else if (knob == fKnobMakeup)
  198. d_setParameterValue(ZamCompX2Plugin::paramMakeup, value);
  199. }
  200. void ZamCompX2UI::imageToggleClicked(ImageToggle *toggle, int)
  201. {
  202. int flip = !toggle->getValue();
  203. if (toggle == fToggleStereo) {
  204. d_setParameterValue(ZamCompX2Plugin::paramStereo, flip);
  205. }
  206. }
  207. void ZamCompX2UI::onDisplay()
  208. {
  209. fImgBackground.draw();
  210. // draw leds
  211. static const float sLedSpacing = 15.5f;
  212. static const int sLedInitialX = 498;
  213. static const int sYellowLedStaticY = 16;
  214. static const int sRedLedStaticY = 45;
  215. int numRedLeds;
  216. int numYellowLeds;
  217. if (fLedRedValue >= 40.f)
  218. numRedLeds = 12;
  219. else if (fLedRedValue >= 30.f)
  220. numRedLeds = 11;
  221. else if (fLedRedValue >= 20.f)
  222. numRedLeds = 10;
  223. else if (fLedRedValue >= 15.f)
  224. numRedLeds = 9;
  225. else if (fLedRedValue >= 10.f)
  226. numRedLeds = 8;
  227. else if (fLedRedValue >= 8.f)
  228. numRedLeds = 7;
  229. else if (fLedRedValue >= 6.f)
  230. numRedLeds = 6;
  231. else if (fLedRedValue >= 5.f)
  232. numRedLeds = 5;
  233. else if (fLedRedValue >= 4.f)
  234. numRedLeds = 4;
  235. else if (fLedRedValue >= 3.f)
  236. numRedLeds = 3;
  237. else if (fLedRedValue >= 2.f)
  238. numRedLeds = 2;
  239. else if (fLedRedValue >= 1.f)
  240. numRedLeds = 1;
  241. else numRedLeds = 0;
  242. for (int i=numRedLeds; i>0; --i)
  243. fLedRedImg.draw(sLedInitialX + (12 - i)*sLedSpacing, sRedLedStaticY);
  244. if (fLedYellowValue >= 20.f)
  245. numYellowLeds = 19;
  246. else if (fLedYellowValue >= 10.f)
  247. numYellowLeds = 18;
  248. else if (fLedYellowValue >= 8.f)
  249. numYellowLeds = 17;
  250. else if (fLedYellowValue >= 4.f)
  251. numYellowLeds = 16;
  252. else if (fLedYellowValue >= 2.f)
  253. numYellowLeds = 15;
  254. else if (fLedYellowValue >= 1.f)
  255. numYellowLeds = 14;
  256. else if (fLedYellowValue >= 0.f)
  257. numYellowLeds = 13;
  258. else if (fLedYellowValue >= -1.f)
  259. numYellowLeds = 12;
  260. else if (fLedYellowValue >= -2.f)
  261. numYellowLeds = 11;
  262. else if (fLedYellowValue >= -3.f)
  263. numYellowLeds = 10;
  264. else if (fLedYellowValue >= -4.f)
  265. numYellowLeds = 9;
  266. else if (fLedYellowValue >= -5.f)
  267. numYellowLeds = 8;
  268. else if (fLedYellowValue >= -6.f)
  269. numYellowLeds = 7;
  270. else if (fLedYellowValue >= -8.f)
  271. numYellowLeds = 6;
  272. else if (fLedYellowValue >= -10.f)
  273. numYellowLeds = 5;
  274. else if (fLedYellowValue >= -15.f)
  275. numYellowLeds = 4;
  276. else if (fLedYellowValue >= -20.f)
  277. numYellowLeds = 3;
  278. else if (fLedYellowValue >= -30.f)
  279. numYellowLeds = 2;
  280. else if (fLedYellowValue >= -40.f)
  281. numYellowLeds = 1;
  282. else numYellowLeds = 0;
  283. if (numYellowLeds > 12) {
  284. for (int i=12; i<numYellowLeds; ++i)
  285. fLedRedImg.draw(sLedInitialX + i*sLedSpacing, sYellowLedStaticY);
  286. for (int i=0; i<12; ++i)
  287. fLedYellowImg.draw(sLedInitialX + i*sLedSpacing, sYellowLedStaticY);
  288. } else {
  289. for (int i=0; i<numYellowLeds; ++i)
  290. fLedYellowImg.draw(sLedInitialX + i*sLedSpacing, sYellowLedStaticY);
  291. }
  292. }
  293. // -----------------------------------------------------------------------
  294. UI* createUI()
  295. {
  296. return new ZamCompX2UI();
  297. }
  298. // -----------------------------------------------------------------------
  299. END_NAMESPACE_DISTRHO