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.

ZamCompX2UI.cpp 8.7KB

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