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.

153 lines
4.5KB

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