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.

266 lines
9.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCETICE project - Copyright 2008 by Lucio Asnaghi.
  4. JUCETICE is based around the JUCE library - "Jules' Utility Class Extensions"
  5. Copyright 2008 by Julian Storer.
  6. ------------------------------------------------------------------------------
  7. JUCE and JUCETICE can be redistributed and/or modified under the terms of
  8. the GNU Lesser General Public License, as published by the Free Software
  9. Foundation; either version 2 of the License, or (at your option) any later
  10. version.
  11. JUCE and JUCETICE are distributed in the hope that they 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. You should have received a copy of the GNU Lesser General Public License
  16. along with JUCE and JUCETICE; if not, visit www.gnu.org/licenses or write to
  17. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  18. Boston, MA 02111-1307 USA
  19. ==============================================================================
  20. @author rockhardbuns
  21. @tweaker Lucio Asnaghi
  22. @tweaker falkTX
  23. ==============================================================================
  24. */
  25. #ifndef DISTRHO_VEX_PEGGYVIEWCOMPONENT_HEADER_INCLUDED
  26. #define DISTRHO_VEX_PEGGYVIEWCOMPONENT_HEADER_INCLUDED
  27. #include "VexArpSettings.h"
  28. #include "gui/BoolGridComponent.h"
  29. #include "gui/SliderFieldComponent.h"
  30. class PeggyViewComponent : public Component,
  31. public ChangeListener,
  32. public SliderListener,
  33. public ComboBoxListener,
  34. public ButtonListener
  35. {
  36. public:
  37. class Callback
  38. {
  39. public:
  40. virtual ~Callback() {}
  41. virtual void somethingChanged(const uint32_t id) = 0;
  42. };
  43. PeggyViewComponent(const int partID, VexArpSettings& arpSet, Callback* const callback)
  44. : fPart(partID),
  45. fArpSettings(arpSet),
  46. fCallback(callback)
  47. {
  48. addAndMakeVisible(boolGrid = new BoolGridComponent());
  49. boolGrid->addChangeListener(this);
  50. addAndMakeVisible(sliderField = new SliderFieldComponent());
  51. sliderField->addChangeListener(this);
  52. addAndMakeVisible(length = new Slider("sdf"));
  53. length->setRange(1, 16, 1);
  54. length->setTextBoxStyle(Slider::NoTextBox, true, 0, 0 );
  55. length->addListener(this);
  56. addAndMakeVisible(timeMode = new ComboBox("a"));
  57. timeMode->setEditableText (false);
  58. timeMode->setJustificationType (Justification::centredLeft);
  59. timeMode->setTextWhenNothingSelected (String("_"));
  60. timeMode->setTextWhenNoChoicesAvailable (String("_"));
  61. timeMode->setColour(ComboBox::backgroundColourId, Colours::black);
  62. timeMode->setColour(ComboBox::textColourId, Colours::lightgrey);
  63. timeMode->setColour(ComboBox::outlineColourId, Colours::grey);
  64. timeMode->setColour(ComboBox::buttonColourId, Colours::grey);
  65. timeMode->setWantsKeyboardFocus(false);
  66. timeMode->addItem("1/8", 1);
  67. timeMode->addItem("1/16", 2);
  68. timeMode->addItem("1/32", 3);
  69. timeMode->addListener(this);
  70. addAndMakeVisible(syncMode = new ComboBox("a"));
  71. syncMode->setEditableText (false);
  72. syncMode->setJustificationType (Justification::centredLeft);
  73. syncMode->setTextWhenNothingSelected (String("_"));
  74. syncMode->setTextWhenNoChoicesAvailable (String("_"));
  75. syncMode->setColour(ComboBox::backgroundColourId, Colours::black);
  76. syncMode->setColour(ComboBox::textColourId, Colours::lightgrey);
  77. syncMode->setColour(ComboBox::outlineColourId, Colours::grey);
  78. syncMode->setColour(ComboBox::buttonColourId, Colours::grey);
  79. syncMode->setWantsKeyboardFocus(false);
  80. syncMode->addItem("Key Sync", 1);
  81. syncMode->addItem("Bar Sync", 2);
  82. syncMode->addListener(this);
  83. addAndMakeVisible(failMode = new ComboBox("a"));
  84. failMode->setEditableText(false);
  85. failMode->setJustificationType (Justification::centredLeft);
  86. failMode->setTextWhenNothingSelected (String("_"));
  87. failMode->setTextWhenNoChoicesAvailable (String("_"));
  88. failMode->setColour(ComboBox::backgroundColourId, Colours::black);
  89. failMode->setColour(ComboBox::textColourId, Colours::lightgrey);
  90. failMode->setColour(ComboBox::outlineColourId, Colours::grey);
  91. failMode->setColour(ComboBox::buttonColourId, Colours::grey);
  92. failMode->setWantsKeyboardFocus(false);
  93. failMode->addItem("Silent Step", 1);
  94. failMode->addItem("Skip One", 2);
  95. failMode->addItem("Skip Two", 3);
  96. failMode->addListener(this);
  97. addAndMakeVisible(velMode = new ComboBox("a"));
  98. velMode->setEditableText(false);
  99. velMode->setJustificationType(Justification::centredLeft);
  100. velMode->setTextWhenNothingSelected (String("_"));
  101. velMode->setTextWhenNoChoicesAvailable (String("_"));
  102. velMode->setColour(ComboBox::backgroundColourId, Colours::black);
  103. velMode->setColour(ComboBox::textColourId, Colours::lightgrey);
  104. velMode->setColour(ComboBox::outlineColourId, Colours::grey);
  105. velMode->setColour(ComboBox::buttonColourId, Colours::grey);
  106. velMode->setWantsKeyboardFocus(false);
  107. velMode->addItem("Pattern Velocity", 1);
  108. velMode->addItem("Input Velocity", 2);
  109. velMode->addItem("Sum Velocities", 3);
  110. velMode->addListener(this);
  111. addAndMakeVisible(onOffBtn = new ToggleButton ("new button"));
  112. onOffBtn->setButtonText(String( "On"));
  113. onOffBtn->addListener(this);
  114. onOffBtn->setClickingTogglesState(true);
  115. update();
  116. }
  117. ~PeggyViewComponent() override
  118. {
  119. //deleteAllChildren();
  120. removeAllChildren();
  121. }
  122. void resized() override
  123. {
  124. boolGrid->setBounds(5, 5, 193, 63);
  125. sliderField->setBounds(5, 68, 193, 63);
  126. length->setBounds(4, 140, 194, 16);
  127. timeMode->setBounds(6, 160, 93, 23);
  128. syncMode->setBounds(102, 160, 93, 23);
  129. failMode->setBounds(6, 190, 189, 23);
  130. velMode-> setBounds(6, 220, 189, 23);
  131. onOffBtn->setBounds(6, 250, 60, 24);
  132. }
  133. void paint(Graphics& g) override
  134. {
  135. g.setColour(Colours::black.withAlpha(.5f));
  136. g.fillRect(5,5,getWidth(), getHeight());
  137. g.setGradientFill(ColourGradient(Colour(0xffffffff), 0.0f, 0.0f,
  138. Colour(0xff888899), (float)getWidth(), (float)getHeight(), false));
  139. g.fillRect(0,0,getWidth() - 5, getHeight() - 5);
  140. g.setColour(Colours::black);
  141. g.drawRect(0,0,getWidth() - 5, getHeight() - 5);
  142. }
  143. void changeListenerCallback(ChangeBroadcaster* caller) override
  144. {
  145. if (caller == boolGrid)
  146. {
  147. int i = boolGrid->getLastChanged();
  148. fArpSettings.grid[i] = boolGrid->getCellState(i);
  149. fCallback->somethingChanged(6+VexArpSettings::kVelocitiesSize+i);
  150. }
  151. else if (caller == sliderField)
  152. {
  153. int i = sliderField->getLastSlider();
  154. fArpSettings.velocities[i] = jlimit(0.0f, 1.0f, sliderField->getValue(i));
  155. fCallback->somethingChanged(6+i);
  156. }
  157. }
  158. void comboBoxChanged(ComboBox* caller) override
  159. {
  160. if (caller == timeMode)
  161. {
  162. fArpSettings.timeMode = timeMode->getSelectedId();
  163. fCallback->somethingChanged(2);
  164. }
  165. else if (caller == syncMode)
  166. {
  167. fArpSettings.syncMode = syncMode->getSelectedId();
  168. fCallback->somethingChanged(3);
  169. }
  170. else if (caller == failMode)
  171. {
  172. fArpSettings.failMode = failMode->getSelectedId();
  173. fCallback->somethingChanged(4);
  174. }
  175. else if (caller == velMode)
  176. {
  177. fArpSettings.velMode = velMode->getSelectedId();
  178. fCallback->somethingChanged(5);
  179. }
  180. }
  181. void sliderValueChanged(Slider* /*caller*/) override
  182. {
  183. boolGrid->setLength((int)length->getValue());
  184. sliderField->setLength((int)length->getValue());
  185. fArpSettings.length = (int)length->getValue();
  186. fCallback->somethingChanged(1);
  187. }
  188. void buttonClicked(Button* /*caller*/) override
  189. {
  190. fArpSettings.on = onOffBtn->getToggleState();
  191. fCallback->somethingChanged(0);
  192. }
  193. void update()
  194. {
  195. onOffBtn->setToggleState(fArpSettings.on, dontSendNotification);
  196. sliderField->setLength(fArpSettings.length);
  197. boolGrid->setLength(fArpSettings.length);
  198. length->setValue(fArpSettings.length);
  199. for (int i = 0; i < VexArpSettings::kVelocitiesSize; ++i)
  200. sliderField->setValue(i, fArpSettings.velocities[i]);
  201. for (int i = 0; i < VexArpSettings::kGridSize; ++i)
  202. boolGrid->setCellState(i, fArpSettings.grid[i]);
  203. timeMode->setSelectedId(fArpSettings.timeMode);
  204. syncMode->setSelectedId(fArpSettings.syncMode);
  205. failMode->setSelectedId(fArpSettings.failMode);
  206. velMode->setSelectedId(fArpSettings.velMode);
  207. }
  208. private:
  209. const int fPart;
  210. VexArpSettings& fArpSettings;
  211. Callback* const fCallback;
  212. ScopedPointer<BoolGridComponent> boolGrid;
  213. ScopedPointer<SliderFieldComponent> sliderField;
  214. ScopedPointer<ComboBox> timeMode;
  215. ScopedPointer<ComboBox> syncMode;
  216. ScopedPointer<ComboBox> failMode;
  217. ScopedPointer<ComboBox> velMode;
  218. ScopedPointer<ToggleButton> onOffBtn;
  219. ScopedPointer<Slider> length;
  220. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PeggyViewComponent)
  221. };
  222. #endif // DISTRHO_VEX_PEGGYVIEWCOMPONENT_HEADER_INCLUDED