DISTRHO Juice Plugins
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.

193 lines
6.2KB

  1. /*
  2. * Wobble Juice Plugin
  3. * Copyright (C) 2014 Andre Sklenar <andre.sklenar@gmail.com>, www.juicelab.cz
  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 "WobbleJuicePlugin.hpp"
  18. #include "WobbleJuiceUI.hpp"
  19. START_NAMESPACE_DISTRHO
  20. // -----------------------------------------------------------------------
  21. WobbleJuiceUI::WobbleJuiceUI()
  22. : UI(WobbleJuiceArtwork::backgroundWidth, WobbleJuiceArtwork::backgroundHeight),
  23. fAboutWindow(this)
  24. {
  25. // background
  26. fImgBackground = Image(WobbleJuiceArtwork::backgroundData, WobbleJuiceArtwork::backgroundWidth, WobbleJuiceArtwork::backgroundHeight, kImageFormatBGR);
  27. // about
  28. Image aboutImage(WobbleJuiceArtwork::aboutData, WobbleJuiceArtwork::aboutWidth, WobbleJuiceArtwork::aboutHeight, kImageFormatBGR);
  29. fAboutWindow.setImage(aboutImage);
  30. // knobs
  31. Image knobImage(WobbleJuiceArtwork::knobData, WobbleJuiceArtwork::knobWidth, WobbleJuiceArtwork::knobHeight, kImageFormatBGRA);
  32. // knob Division
  33. fKnobDivision = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  34. fKnobDivision->setId(WobbleJuicePlugin::paramDivision);
  35. fKnobDivision->setAbsolutePos(222, 74);
  36. fKnobDivision->setRotationAngle(270);
  37. fKnobDivision->setRange(1.0f, 16.0f);
  38. fKnobDivision->setDefault(4.0f);
  39. fKnobDivision->setStep(1.0f);
  40. fKnobDivision->setCallback(this);
  41. // knob Resonance
  42. fKnobResonance = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  43. fKnobResonance->setId(WobbleJuicePlugin::paramReso);
  44. fKnobResonance->setAbsolutePos(222, 199);
  45. fKnobResonance->setRotationAngle(270);
  46. fKnobResonance->setRange(0.0f, 0.2f);
  47. fKnobResonance->setDefault(0.1f);
  48. fKnobResonance->setCallback(this);
  49. // knob Range
  50. fKnobRange = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  51. fKnobRange->setId(WobbleJuicePlugin::paramRange);
  52. fKnobRange->setAbsolutePos(77, 199);
  53. fKnobRange->setRotationAngle(270);
  54. fKnobRange->setRange(500.0f, 16000.0f);
  55. fKnobRange->setDefault(16000.0f);
  56. fKnobRange->setCallback(this);
  57. // knob Phase
  58. fKnobPhase = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  59. fKnobPhase->setId(WobbleJuicePlugin::paramPhase);
  60. fKnobPhase->setAbsolutePos(362, 74);
  61. fKnobPhase->setRotationAngle(270);
  62. fKnobPhase->setRange(-1.0f, 1.0f);
  63. fKnobPhase->setDefault(0.0f);
  64. fKnobPhase->setCallback(this);
  65. // knob Wave
  66. fKnobWave = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  67. fKnobWave->setId(WobbleJuicePlugin::paramWave);
  68. fKnobWave->setAbsolutePos(77, 74);
  69. fKnobWave->setRotationAngle(270);
  70. fKnobWave->setRange(1.0f, 4.0f);
  71. fKnobWave->setDefault(2.0f);
  72. fKnobWave->setCallback(this);
  73. // knob Drive
  74. fKnobDrive = new ImageKnob(this, knobImage, ImageKnob::Vertical);
  75. fKnobDrive->setId(WobbleJuicePlugin::paramDrive);
  76. fKnobDrive->setAbsolutePos(362, 199);
  77. fKnobDrive->setRotationAngle(270);
  78. fKnobDrive->setRange(0.0f, 1.0f);
  79. fKnobDrive->setDefault(0.5f);
  80. fKnobDrive->setCallback(this);
  81. // about button
  82. Image aboutImageNormal(WobbleJuiceArtwork::aboutButtonNormalData, WobbleJuiceArtwork::aboutButtonNormalWidth, WobbleJuiceArtwork::aboutButtonNormalHeight, kImageFormatBGRA);
  83. Image aboutImageHover(WobbleJuiceArtwork::aboutButtonHoverData, WobbleJuiceArtwork::aboutButtonHoverWidth, WobbleJuiceArtwork::aboutButtonHoverHeight, kImageFormatBGRA);
  84. fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover);
  85. fButtonAbout->setAbsolutePos(390, 20);
  86. fButtonAbout->setCallback(this);
  87. // set default values
  88. programLoaded(0);
  89. // automatically-scale
  90. setGeometryConstraints(WobbleJuiceArtwork::backgroundWidth, WobbleJuiceArtwork::backgroundHeight, true, true);
  91. }
  92. // -----------------------------------------------------------------------
  93. // DSP Callbacks
  94. void WobbleJuiceUI::parameterChanged(uint32_t index, float value)
  95. {
  96. switch (index)
  97. {
  98. case WobbleJuicePlugin::paramDivision:
  99. fKnobDivision->setValue(value);
  100. break;
  101. case WobbleJuicePlugin::paramReso:
  102. fKnobResonance->setValue(value);
  103. break;
  104. case WobbleJuicePlugin::paramRange:
  105. fKnobRange->setValue(value);
  106. break;
  107. case WobbleJuicePlugin::paramPhase:
  108. fKnobPhase->setValue(value);
  109. break;
  110. case WobbleJuicePlugin::paramWave:
  111. fKnobWave->setValue(value);
  112. break;
  113. case WobbleJuicePlugin::paramDrive:
  114. fKnobDrive->setValue(value);
  115. break;
  116. }
  117. }
  118. void WobbleJuiceUI::programLoaded(uint32_t index)
  119. {
  120. if (index != 0)
  121. return;
  122. // Default values
  123. fKnobDivision->setValue(4.0f);
  124. fKnobResonance->setValue(0.1f);
  125. fKnobRange->setValue(16000.0f);
  126. fKnobPhase->setValue(0.0f);
  127. fKnobWave->setValue(2.0f);
  128. fKnobDrive->setValue(0.5f);
  129. }
  130. // -----------------------------------------------------------------------
  131. // Widget Callbacks
  132. void WobbleJuiceUI::imageButtonClicked(ImageButton* button, int)
  133. {
  134. if (button != fButtonAbout)
  135. return;
  136. fAboutWindow.runAsModal();
  137. }
  138. void WobbleJuiceUI::imageKnobDragStarted(ImageKnob* knob)
  139. {
  140. editParameter(knob->getId(), true);
  141. }
  142. void WobbleJuiceUI::imageKnobDragFinished(ImageKnob* knob)
  143. {
  144. editParameter(knob->getId(), false);
  145. }
  146. void WobbleJuiceUI::imageKnobValueChanged(ImageKnob* knob, float value)
  147. {
  148. setParameterValue(knob->getId(), value);
  149. }
  150. void WobbleJuiceUI::onDisplay()
  151. {
  152. const GraphicsContext& context(getGraphicsContext());
  153. fImgBackground.draw(context);
  154. }
  155. // -----------------------------------------------------------------------
  156. UI* createUI()
  157. {
  158. return new WobbleJuiceUI();
  159. }
  160. // -----------------------------------------------------------------------
  161. END_NAMESPACE_DISTRHO