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.

267 lines
9.0KB

  1. /*
  2. * DISTRHO MVerb, a DPF'ied MVerb.
  3. * Copyright (c) 2010 Martin Eastwood
  4. * Copyright (C) 2014 Filipe Coelho <falktx@falktx.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 3 of
  9. * the License, or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * For a full copy of the GNU General Public License see the LICENSE file.
  17. */
  18. #include "DistrhoUIMVerb.hpp"
  19. #include "MVerb.h"
  20. #include "font/Kh-Kangrey.h"
  21. START_NAMESPACE_DISTRHO
  22. using DGL::Color;
  23. // -----------------------------------------------------------------------
  24. DistrhoUIMVerb::DistrhoUIMVerb()
  25. : UI()
  26. {
  27. // set UI size
  28. setSize(DistrhoArtworkMVerb::backgroundWidth, DistrhoArtworkMVerb::backgroundHeight);
  29. // background
  30. fImgBackground = Image(DistrhoArtworkMVerb::backgroundData, DistrhoArtworkMVerb::backgroundWidth, DistrhoArtworkMVerb::backgroundHeight, GL_BGR);
  31. // text
  32. fNanoText.createFontMem("kh", (const uchar*)khkangrey_ttf, khkangrey_ttfSize, false);
  33. // knobs
  34. Image knobImage(DistrhoArtworkMVerb::knobData, DistrhoArtworkMVerb::knobWidth, DistrhoArtworkMVerb::knobHeight);
  35. {
  36. ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical));
  37. knob->setId(MVerb<float>::DAMPINGFREQ);
  38. knob->setAbsolutePos(56 + 7*40, 40);
  39. knob->setRange(0.0f, 100.0f);
  40. knob->setDefault(50.0f);
  41. knob->setCallback(this);
  42. fKnobs.push_back(knob);
  43. }
  44. {
  45. ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical));
  46. knob->setId(MVerb<float>::DENSITY);
  47. knob->setAbsolutePos(56 + 4*40, 40);
  48. knob->setRange(0.0f, 100.0f);
  49. knob->setDefault(50.0f);
  50. knob->setCallback(this);
  51. fKnobs.push_back(knob);
  52. }
  53. {
  54. ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical));
  55. knob->setId(MVerb<float>::BANDWIDTHFREQ);
  56. knob->setAbsolutePos(56 + 5*40, 40);
  57. knob->setRange(0.0f, 100.0f);
  58. knob->setDefault(50.0f);
  59. knob->setCallback(this);
  60. fKnobs.push_back(knob);
  61. }
  62. {
  63. ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical));
  64. knob->setId(MVerb<float>::DECAY);
  65. knob->setAbsolutePos(56 + 6*40, 40);
  66. knob->setRange(0.0f, 100.0f);
  67. knob->setDefault(50.0f);
  68. knob->setCallback(this);
  69. fKnobs.push_back(knob);
  70. }
  71. {
  72. ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical));
  73. knob->setId(MVerb<float>::PREDELAY);
  74. knob->setAbsolutePos(56 + 1*40, 40);
  75. knob->setRange(0.0f, 100.0f);
  76. knob->setDefault(50.0f);
  77. knob->setCallback(this);
  78. fKnobs.push_back(knob);
  79. }
  80. {
  81. ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical));
  82. knob->setId(MVerb<float>::SIZE);
  83. knob->setAbsolutePos(56 + 3*40, 40);
  84. knob->setRange(5.0f, 100.0f);
  85. knob->setDefault(100.0f);
  86. knob->setCallback(this);
  87. fKnobs.push_back(knob);
  88. }
  89. {
  90. ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical));
  91. knob->setId(MVerb<float>::GAIN);
  92. knob->setAbsolutePos(56 + 8*40, 40);
  93. knob->setRange(0.0f, 100.0f);
  94. knob->setDefault(75.0f);
  95. knob->setCallback(this);
  96. fKnobs.push_back(knob);
  97. }
  98. {
  99. ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical));
  100. knob->setId(MVerb<float>::MIX);
  101. knob->setAbsolutePos(56 + 0*40, 40);
  102. knob->setRange(0.0f, 100.0f);
  103. knob->setDefault(50.0f);
  104. knob->setCallback(this);
  105. fKnobs.push_back(knob);
  106. }
  107. {
  108. ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical));
  109. knob->setId(MVerb<float>::EARLYMIX);
  110. knob->setAbsolutePos(56 + 2*40, 40);
  111. knob->setRange(0.0f, 100.0f);
  112. knob->setDefault(50.0f);
  113. knob->setCallback(this);
  114. fKnobs.push_back(knob);
  115. }
  116. // set initial values
  117. d_programChanged(0);
  118. }
  119. DistrhoUIMVerb::~DistrhoUIMVerb()
  120. {
  121. for (std::vector<ImageKnob*>::iterator it=fKnobs.begin(), end=fKnobs.end(); it != end; ++it)
  122. {
  123. ImageKnob* const knob(*it);
  124. delete knob;
  125. }
  126. fKnobs.clear();
  127. }
  128. // -----------------------------------------------------------------------
  129. // DSP Callbacks
  130. void DistrhoUIMVerb::d_parameterChanged(uint32_t index, float value)
  131. {
  132. fKnobs[index]->setValue(value);
  133. }
  134. void DistrhoUIMVerb::d_programChanged(uint32_t index)
  135. {
  136. switch(index)
  137. {
  138. case 0:
  139. fKnobs[MVerb<float>::DAMPINGFREQ]->setValue(0.5f*100.0f);
  140. fKnobs[MVerb<float>::DENSITY]->setValue(0.5f*100.0f);
  141. fKnobs[MVerb<float>::BANDWIDTHFREQ]->setValue(0.5f*100.0f);
  142. fKnobs[MVerb<float>::DECAY]->setValue(0.5f*100.0f);
  143. fKnobs[MVerb<float>::PREDELAY]->setValue(0.5f*100.0f);
  144. fKnobs[MVerb<float>::GAIN]->setValue(1.0f*100.0f);
  145. fKnobs[MVerb<float>::MIX]->setValue(0.5f*100.0f);
  146. fKnobs[MVerb<float>::EARLYMIX]->setValue(0.5f*100.0f);
  147. fKnobs[MVerb<float>::SIZE]->setValue(0.75f*100.0f);
  148. break;
  149. case 1:
  150. fKnobs[MVerb<float>::DAMPINGFREQ]->setValue(0.9f*100.0f);
  151. fKnobs[MVerb<float>::DENSITY]->setValue(0.5f*100.0f);
  152. fKnobs[MVerb<float>::BANDWIDTHFREQ]->setValue(0.1f*100.0f);
  153. fKnobs[MVerb<float>::DECAY]->setValue(0.5f*100.0f);
  154. fKnobs[MVerb<float>::PREDELAY]->setValue(0.0f*100.0f);
  155. fKnobs[MVerb<float>::SIZE]->setValue(0.5f*100.0f);
  156. fKnobs[MVerb<float>::GAIN]->setValue(1.0f*100.0f);
  157. fKnobs[MVerb<float>::MIX]->setValue(0.5f*100.0f);
  158. fKnobs[MVerb<float>::EARLYMIX]->setValue(0.75f*100.0f);
  159. break;
  160. case 2:
  161. fKnobs[MVerb<float>::DAMPINGFREQ]->setValue(0.0f*100.0f);
  162. fKnobs[MVerb<float>::DENSITY]->setValue(0.5f*100.0f);
  163. fKnobs[MVerb<float>::BANDWIDTHFREQ]->setValue(1.0f*100.0f);
  164. fKnobs[MVerb<float>::DECAY]->setValue(0.5f*100.0f);
  165. fKnobs[MVerb<float>::PREDELAY]->setValue(0.0f*100.0f);
  166. fKnobs[MVerb<float>::SIZE]->setValue(0.25f*100.0f);
  167. fKnobs[MVerb<float>::GAIN]->setValue(1.0f*100.0f);
  168. fKnobs[MVerb<float>::MIX]->setValue(0.35f*100.0f);
  169. fKnobs[MVerb<float>::EARLYMIX]->setValue(0.75f*100.0f);
  170. break;
  171. case 3:
  172. fKnobs[MVerb<float>::DAMPINGFREQ]->setValue(0.0f*100.0f);
  173. fKnobs[MVerb<float>::DENSITY]->setValue(0.5f*100.0f);
  174. fKnobs[MVerb<float>::BANDWIDTHFREQ]->setValue(1.0f*100.0f);
  175. fKnobs[MVerb<float>::DECAY]->setValue(0.5f*100.0f);
  176. fKnobs[MVerb<float>::PREDELAY]->setValue(0.0f*100.0f);
  177. fKnobs[MVerb<float>::SIZE]->setValue(1.0f*100.0f);
  178. fKnobs[MVerb<float>::GAIN]->setValue(1.0f*100.0f);
  179. fKnobs[MVerb<float>::MIX]->setValue(0.35f*100.0f);
  180. fKnobs[MVerb<float>::EARLYMIX]->setValue(0.75f*100.0f);
  181. break;
  182. case 4:
  183. fKnobs[MVerb<float>::DAMPINGFREQ]->setValue(0.0f*100.0f);
  184. fKnobs[MVerb<float>::DENSITY]->setValue(0.5f*100.0f);
  185. fKnobs[MVerb<float>::BANDWIDTHFREQ]->setValue(1.0f*100.0f);
  186. fKnobs[MVerb<float>::DECAY]->setValue(0.5f*100.0f);
  187. fKnobs[MVerb<float>::PREDELAY]->setValue(0.0f*100.0f);
  188. fKnobs[MVerb<float>::SIZE]->setValue(0.5f*100.0f);
  189. fKnobs[MVerb<float>::GAIN]->setValue(1.0f*100.0f);
  190. fKnobs[MVerb<float>::MIX]->setValue(0.15f*100.0f);
  191. fKnobs[MVerb<float>::EARLYMIX]->setValue(0.75f*100.0f);
  192. break;
  193. }
  194. }
  195. // -----------------------------------------------------------------------
  196. // Widget Callbacks
  197. void DistrhoUIMVerb::imageKnobDragStarted(ImageKnob* knob)
  198. {
  199. d_editParameter(knob->getId(), true);
  200. }
  201. void DistrhoUIMVerb::imageKnobDragFinished(ImageKnob* knob)
  202. {
  203. d_editParameter(knob->getId(), false);
  204. }
  205. void DistrhoUIMVerb::imageKnobValueChanged(ImageKnob* knob, float value)
  206. {
  207. d_setParameterValue(knob->getId(), value);
  208. }
  209. void DistrhoUIMVerb::onDisplay()
  210. {
  211. fImgBackground.draw();
  212. // text display
  213. fNanoText.beginFrame(getWidth(), getHeight());
  214. fNanoText.fontFace("kh");
  215. fNanoText.fontSize(20);
  216. fNanoText.textAlign(NanoVG::Align(NanoVG::ALIGN_CENTER|NanoVG::ALIGN_TOP));
  217. fNanoText.fillColor(Color(1.0f, 1.0f, 1.0f));
  218. char strBuf[32+1];
  219. strBuf[32] = '\0';
  220. for (std::size_t i=0; i<MVerb<float>::NUM_PARAMS; ++i)
  221. {
  222. std::snprintf(strBuf, 32, "%i%%", int(fKnobs[i]->getValue()));
  223. fNanoText.textBox(58 + fKnobs[i]->getAbsoluteX()-56, 73, 30.0f, strBuf, nullptr);
  224. }
  225. fNanoText.endFrame();
  226. // just in case
  227. glDisable(GL_CULL_FACE);
  228. }
  229. // -----------------------------------------------------------------------
  230. UI* createUI()
  231. {
  232. return new DistrhoUIMVerb();
  233. }
  234. // -----------------------------------------------------------------------
  235. END_NAMESPACE_DISTRHO