DISTRHO ndc Plugs
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.

229 lines
7.4KB

  1. /*
  2. * DISTRHO SoulForce, a DPF'ied SoulForce.
  3. * Copyright (C) 2006 Niall Moody
  4. * Copyright (C) 2015 Filipe Coelho <falktx@falktx.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #include "DistrhoUISoulForce.hpp"
  25. #include "DistrhoPluginSoulForce.hpp"
  26. START_NAMESPACE_DISTRHO
  27. namespace Art = DistrhoArtworkSoulForce;
  28. // -----------------------------------------------------------------------
  29. DistrhoUISoulForce::DistrhoUISoulForce()
  30. : UI(Art::backgroundWidth, Art::backgroundHeight),
  31. fImgBackground(Art::backgroundData, Art::backgroundWidth, Art::backgroundHeight, GL_BGR),
  32. fImgLedOff(Art::led_offData, Art::led_offWidth, Art::led_offHeight, GL_BGR),
  33. fImgLedOn(Art::led_onData, Art::led_onWidth, Art::led_onHeight, GL_BGR),
  34. fFootDown(true)
  35. {
  36. // knobs
  37. fKnobShape = new ImageKnob(this,
  38. Image(Art::knob_shapeData, Art::knob_shapeWidth, Art::knob_shapeHeight, GL_BGR));
  39. fKnobShape->setId(DistrhoPluginSoulForce::kParameterShape);
  40. fKnobShape->setAbsolutePos(17, 64);
  41. fKnobShape->setRange(0.0f, 1.0f);
  42. fKnobShape->setDefault(0.5f);
  43. fKnobShape->setImageLayerCount(92);
  44. fKnobShape->setCallback(this);
  45. fKnobFBack = new ImageKnob(this,
  46. Image(Art::knob_feedbackData, Art::knob_feedbackWidth, Art::knob_feedbackHeight, GL_BGR));
  47. fKnobFBack->setId(DistrhoPluginSoulForce::kParameterFeedback);
  48. fKnobFBack->setAbsolutePos(176, 64);
  49. fKnobFBack->setRange(0.0f, 1.0f);
  50. fKnobFBack->setDefault(0.5f);
  51. fKnobFBack->setImageLayerCount(92);
  52. fKnobFBack->setCallback(this);
  53. // switches
  54. fSwitchSource = new ImageSwitch(this,
  55. Image(Art::switch_leftData, Art::switch_leftWidth, Art::switch_leftHeight, GL_BGR),
  56. Image(Art::switch_rightData, Art::switch_rightWidth, Art::switch_rightHeight, GL_BGR));
  57. fSwitchSource->setId(DistrhoPluginSoulForce::kParameterSource);
  58. fSwitchSource->setAbsolutePos(116, 191);
  59. fSwitchSource->setCallback(this);
  60. // buttons
  61. fButtonFoot = new ImageButton(this,
  62. Image(Art::button_upData, Art::button_upWidth, Art::button_upHeight, GL_BGR),
  63. Image(Art::button_upData, Art::button_upWidth, Art::button_upHeight, GL_BGR),
  64. Image(Art::button_downData, Art::button_downWidth, Art::button_downHeight, GL_BGR));
  65. fButtonFoot->setId(DistrhoPluginSoulForce::kParameterFootswitch);
  66. fButtonFoot->setAbsolutePos(125, 282);
  67. fButtonFoot->setCallback(this);
  68. // set initial values
  69. programLoaded(0);
  70. }
  71. // -----------------------------------------------------------------------
  72. // DSP Callbacks
  73. void DistrhoUISoulForce::parameterChanged(uint32_t index, float value)
  74. {
  75. switch (index)
  76. {
  77. case DistrhoPluginSoulForce::kParameterShape:
  78. fKnobShape->setValue(value);
  79. break;
  80. case DistrhoPluginSoulForce::kParameterFeedback:
  81. fKnobFBack->setValue(value);
  82. break;
  83. case DistrhoPluginSoulForce::kParameterSource:
  84. fSwitchSource->setDown(value > 0.5f);
  85. break;
  86. case DistrhoPluginSoulForce::kParameterFootswitch:
  87. if (fFootDown != (value > 0.5f))
  88. {
  89. fFootDown = !fFootDown;
  90. repaint();
  91. }
  92. break;
  93. }
  94. }
  95. void DistrhoUISoulForce::programLoaded(uint32_t index)
  96. {
  97. switch(index)
  98. {
  99. case DistrhoPluginSoulForce::kProgramDefault:
  100. fKnobShape->setValue(0.5f);
  101. fKnobFBack->setValue(0.0f);
  102. fSwitchSource->setDown(false);
  103. break;
  104. case DistrhoPluginSoulForce::kProgramStayDown:
  105. fKnobShape->setValue(0.4f);
  106. fKnobFBack->setValue(0.0f);
  107. fSwitchSource->setDown(false);
  108. break;
  109. case DistrhoPluginSoulForce::kProgramLookingForTheWorld:
  110. fKnobShape->setValue(1.0f);
  111. fKnobFBack->setValue(0.0f);
  112. fSwitchSource->setDown(false);
  113. break;
  114. case DistrhoPluginSoulForce::kProgramGuerillaLove:
  115. fKnobShape->setValue(0.5f);
  116. fKnobFBack->setValue(1.0f);
  117. fSwitchSource->setDown(false);
  118. break;
  119. case DistrhoPluginSoulForce::kProgramTumbleToThePower:
  120. fKnobShape->setValue(0.0f);
  121. fKnobFBack->setValue(1.0f);
  122. fSwitchSource->setDown(false);
  123. break;
  124. case DistrhoPluginSoulForce::kProgramDoYourselfFavour:
  125. fKnobShape->setValue(0.5f);
  126. fKnobFBack->setValue(1.0f);
  127. fSwitchSource->setDown(true);
  128. break;
  129. case DistrhoPluginSoulForce::kProgramPastIsPast:
  130. fKnobShape->setValue(0.0f);
  131. fKnobFBack->setValue(1.0f);
  132. fSwitchSource->setDown(true);
  133. break;
  134. case DistrhoPluginSoulForce::kProgramYouAndOnlyYou:
  135. fKnobShape->setValue(0.3f);
  136. fKnobFBack->setValue(0.5f);
  137. fSwitchSource->setDown(false);
  138. break;
  139. case DistrhoPluginSoulForce::kProgramSoulForce:
  140. fKnobShape->setValue(0.3f);
  141. fKnobFBack->setValue(0.5f);
  142. fSwitchSource->setDown(true);
  143. break;
  144. }
  145. // always true
  146. if (! fFootDown)
  147. {
  148. fFootDown = true;
  149. repaint();
  150. }
  151. }
  152. // -----------------------------------------------------------------------
  153. // Widget Callbacks
  154. void DistrhoUISoulForce::imageKnobDragStarted(ImageKnob* knob)
  155. {
  156. editParameter(knob->getId(), true);
  157. }
  158. void DistrhoUISoulForce::imageKnobDragFinished(ImageKnob* knob)
  159. {
  160. editParameter(knob->getId(), false);
  161. }
  162. void DistrhoUISoulForce::imageKnobValueChanged(ImageKnob* knob, float value)
  163. {
  164. setParameterValue(knob->getId(), value);
  165. }
  166. void DistrhoUISoulForce::imageButtonClicked(ImageButton* imageButton, int)
  167. {
  168. const uint buttonId(imageButton->getId());
  169. if (buttonId != DistrhoPluginSoulForce::kParameterFootswitch)
  170. return;
  171. fFootDown = !fFootDown;
  172. editParameter(buttonId, true);
  173. setParameterValue(buttonId, fFootDown ? 1.0f : 0.0f);
  174. editParameter(buttonId, false);
  175. repaint();
  176. }
  177. void DistrhoUISoulForce::imageSwitchClicked(ImageSwitch* imageSwitch, bool down)
  178. {
  179. const uint buttonId(imageSwitch->getId());
  180. editParameter(buttonId, true);
  181. setParameterValue(buttonId, down ? 1.0f : 0.0f);
  182. editParameter(buttonId, false);
  183. }
  184. void DistrhoUISoulForce::onDisplay()
  185. {
  186. fImgBackground.draw();
  187. if (fFootDown)
  188. fImgLedOn.drawAt(123, 240);
  189. else
  190. fImgLedOff.drawAt(123, 240);
  191. }
  192. // -----------------------------------------------------------------------
  193. UI* createUI()
  194. {
  195. return new DistrhoUISoulForce();
  196. }
  197. // -----------------------------------------------------------------------
  198. END_NAMESPACE_DISTRHO