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.

166 lines
4.6KB

  1. /*
  2. * Stutter 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 "StutterJuiceUI.hpp"
  18. using DGL::Point;
  19. START_NAMESPACE_DISTRHO
  20. // -----------------------------------------------------------------------
  21. StutterJuiceUI::StutterJuiceUI()
  22. : UI(),
  23. fAboutWindow(this)
  24. {
  25. // background
  26. fImgBackground = Image(StutterJuiceArtwork::backgroundData, StutterJuiceArtwork::backgroundWidth, StutterJuiceArtwork::backgroundHeight, GL_BGR);
  27. // overlay
  28. fImgOverlay = Image(StutterJuiceArtwork::overlayData, StutterJuiceArtwork::overlayWidth, StutterJuiceArtwork::overlayHeight, GL_BGRA);
  29. // about
  30. Image imageAbout(StutterJuiceArtwork::aboutData, StutterJuiceArtwork::aboutWidth, StutterJuiceArtwork::aboutHeight, GL_BGRA);
  31. fAboutWindow.setImage(imageAbout);
  32. // about button
  33. Image aboutImageNormal(StutterJuiceArtwork::aboutButtonNormalData, StutterJuiceArtwork::aboutButtonNormalWidth, StutterJuiceArtwork::aboutButtonNormalHeight);
  34. Image aboutImageHover(StutterJuiceArtwork::aboutButtonHoverData, StutterJuiceArtwork::aboutButtonHoverWidth, StutterJuiceArtwork::aboutButtonHoverHeight);
  35. fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover);
  36. fButtonAbout->setAbsolutePos(358, 17);
  37. fButtonAbout->setCallback(this);
  38. // sliders
  39. Image sliderImage(StutterJuiceArtwork::sliderData, StutterJuiceArtwork::sliderWidth, StutterJuiceArtwork::sliderHeight);
  40. Point<int> sliderPosStart(293, 74);
  41. Point<int> sliderPosEnd(293+11, 74);
  42. int oX = 130;
  43. int oY = 93;
  44. int mX = 357 - oX;
  45. int mY = 120-oY;
  46. int mMY = 208 - oY;
  47. int w = 235 - oX - StutterJuiceArtwork::sliderWidth;
  48. for (int module=0; module<9; module++) {
  49. for (int param=0; param<3; param++) {
  50. sliderPosStart.setX(oX+(module%3)*mX);
  51. sliderPosStart.setY(oY+(param*mY) + (int) (floor(module/3)*mMY));
  52. sliderPosEnd.setX(sliderPosStart.getX() + w);
  53. sliderPosEnd.setY(sliderPosStart.getY());
  54. fSliders[module][param]= new ImageSlider(this, sliderImage);
  55. fSliders[module][param]->setStartPos(sliderPosStart);
  56. fSliders[module][param]->setEndPos(sliderPosEnd);
  57. fSliders[module][param]->setRange(0.0f, 1.0f);
  58. fSliders[module][param]->setValue(0.0f);
  59. fSliders[module][param]->setStep(0.125f);
  60. fSliders[module][param]->setCallback(this);
  61. }
  62. outputParams[module] = 0;
  63. }
  64. // set default values
  65. d_programChanged(0);
  66. }
  67. // -----------------------------------------------------------------------
  68. // DSP Callbacks
  69. void StutterJuiceUI::d_parameterChanged(uint32_t index, float value)
  70. {
  71. if (index<26) {
  72. int module = index/3;
  73. int param = index%3;
  74. fSliders[module][param]->setValue(value);
  75. } else {
  76. outputParams[index-26] = value;
  77. repaint();
  78. }
  79. }
  80. void StutterJuiceUI::d_programChanged(uint32_t index)
  81. {
  82. if (index != 0)
  83. return;
  84. }
  85. // -----------------------------------------------------------------------
  86. // Widget Callbacks
  87. void StutterJuiceUI::imageButtonClicked(ImageButton* button, int)
  88. {
  89. if (button != fButtonAbout)
  90. return;
  91. fAboutWindow.exec();
  92. }
  93. void StutterJuiceUI::imageSliderDragStarted(ImageSlider* slider)
  94. {
  95. for (int module=0; module<9; module++) {
  96. for (int param=0; param<3; param++) {
  97. if (slider == fSliders[module][param]) {
  98. d_editParameter(module*3+param, true);
  99. }
  100. }
  101. }
  102. }
  103. void StutterJuiceUI::imageSliderDragFinished(ImageSlider* slider)
  104. {
  105. for (int module=0; module<9; module++) {
  106. for (int param=0; param<3; param++) {
  107. if (slider == fSliders[module][param]) {
  108. d_editParameter(module*3+param, false);
  109. }
  110. }
  111. }
  112. }
  113. void StutterJuiceUI::imageSliderValueChanged(ImageSlider* slider, float value)
  114. {
  115. for (int module=0; module<9; module++) {
  116. for (int param=0; param<3; param++) {
  117. if (slider == fSliders[module][param]) {
  118. d_setParameterValue(module*3+param, value);
  119. }
  120. }
  121. }
  122. }
  123. void StutterJuiceUI::onDisplay()
  124. {
  125. fImgBackground.draw();
  126. drawLFOs();
  127. fImgOverlay.draw();
  128. }
  129. // -----------------------------------------------------------------------
  130. UI* createUI()
  131. {
  132. return new StutterJuiceUI();
  133. }
  134. // -----------------------------------------------------------------------
  135. END_NAMESPACE_DISTRHO