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.

280 lines
10KB

  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. #include "lookandfeel/MyLookAndFeel.h"
  31. class PeggyViewComponent : public Component,
  32. public ChangeListener,
  33. public SliderListener,
  34. public ComboBoxListener,
  35. public ButtonListener
  36. {
  37. public:
  38. class Callback
  39. {
  40. public:
  41. virtual ~Callback() {}
  42. virtual void arpParameterChanged(const uint32_t id) = 0;
  43. };
  44. PeggyViewComponent(VexArpSettings& arpSet, Callback* const callback, const bool isStandalone = false)
  45. : fArpSettings(arpSet),
  46. fCallback(callback),
  47. fIsStandalone(isStandalone)
  48. {
  49. addAndMakeVisible(boolGrid = new BoolGridComponent());
  50. boolGrid->addChangeListener(this);
  51. addAndMakeVisible(sliderField = new SliderFieldComponent());
  52. sliderField->addChangeListener(this);
  53. addAndMakeVisible(length = new Slider("sdf"));
  54. length->setRange(1, 16, 1);
  55. length->setTextBoxStyle(Slider::NoTextBox, true, 0, 0 );
  56. length->addListener(this);
  57. addAndMakeVisible(timeMode = new ComboBox("a"));
  58. timeMode->setEditableText (false);
  59. timeMode->setJustificationType (Justification::centredLeft);
  60. timeMode->setTextWhenNothingSelected (String("_"));
  61. timeMode->setTextWhenNoChoicesAvailable (String("_"));
  62. timeMode->setColour(ComboBox::backgroundColourId, Colours::black);
  63. timeMode->setColour(ComboBox::textColourId, Colours::lightgrey);
  64. timeMode->setColour(ComboBox::outlineColourId, Colours::grey);
  65. timeMode->setColour(ComboBox::buttonColourId, Colours::grey);
  66. timeMode->setWantsKeyboardFocus(false);
  67. timeMode->addItem("1/8", 1);
  68. timeMode->addItem("1/16", 2);
  69. timeMode->addItem("1/32", 3);
  70. timeMode->addListener(this);
  71. addAndMakeVisible(syncMode = new ComboBox("a"));
  72. syncMode->setEditableText (false);
  73. syncMode->setJustificationType (Justification::centredLeft);
  74. syncMode->setTextWhenNothingSelected (String("_"));
  75. syncMode->setTextWhenNoChoicesAvailable (String("_"));
  76. syncMode->setColour(ComboBox::backgroundColourId, Colours::black);
  77. syncMode->setColour(ComboBox::textColourId, Colours::lightgrey);
  78. syncMode->setColour(ComboBox::outlineColourId, Colours::grey);
  79. syncMode->setColour(ComboBox::buttonColourId, Colours::grey);
  80. syncMode->setWantsKeyboardFocus(false);
  81. syncMode->addItem("Key Sync", 1);
  82. syncMode->addItem("Bar Sync", 2);
  83. syncMode->addListener(this);
  84. addAndMakeVisible(failMode = new ComboBox("a"));
  85. failMode->setEditableText(false);
  86. failMode->setJustificationType (Justification::centredLeft);
  87. failMode->setTextWhenNothingSelected (String("_"));
  88. failMode->setTextWhenNoChoicesAvailable (String("_"));
  89. failMode->setColour(ComboBox::backgroundColourId, Colours::black);
  90. failMode->setColour(ComboBox::textColourId, Colours::lightgrey);
  91. failMode->setColour(ComboBox::outlineColourId, Colours::grey);
  92. failMode->setColour(ComboBox::buttonColourId, Colours::grey);
  93. failMode->setWantsKeyboardFocus(false);
  94. failMode->addItem("Silent Step", 1);
  95. failMode->addItem("Skip One", 2);
  96. failMode->addItem("Skip Two", 3);
  97. failMode->addListener(this);
  98. addAndMakeVisible(velMode = new ComboBox("a"));
  99. velMode->setEditableText(false);
  100. velMode->setJustificationType(Justification::centredLeft);
  101. velMode->setTextWhenNothingSelected (String("_"));
  102. velMode->setTextWhenNoChoicesAvailable (String("_"));
  103. velMode->setColour(ComboBox::backgroundColourId, Colours::black);
  104. velMode->setColour(ComboBox::textColourId, Colours::lightgrey);
  105. velMode->setColour(ComboBox::outlineColourId, Colours::grey);
  106. velMode->setColour(ComboBox::buttonColourId, Colours::grey);
  107. velMode->setWantsKeyboardFocus(false);
  108. velMode->addItem("Pattern Velocity", 1);
  109. velMode->addItem("Input Velocity", 2);
  110. velMode->addItem("Sum Velocities", 3);
  111. velMode->addListener(this);
  112. addAndMakeVisible(onOffBtn = new ToggleButton ("new button"));
  113. onOffBtn->setButtonText(String( "On"));
  114. onOffBtn->addListener(this);
  115. onOffBtn->setClickingTogglesState(true);
  116. if (isStandalone)
  117. {
  118. static MyLookAndFeel mlaf;
  119. setLookAndFeel(&mlaf);
  120. }
  121. update();
  122. }
  123. ~PeggyViewComponent() override
  124. {
  125. //deleteAllChildren();
  126. removeAllChildren();
  127. }
  128. void resized() override
  129. {
  130. boolGrid->setBounds(5, 5, 193, 63);
  131. sliderField->setBounds(5, 68, 193, 63);
  132. length->setBounds(4, 140, 194, 16);
  133. timeMode->setBounds(6, 160, 93, 23);
  134. syncMode->setBounds(102, 160, 93, 23);
  135. failMode->setBounds(6, 190, 189, 23);
  136. velMode-> setBounds(6, 220, 189, 23);
  137. onOffBtn->setBounds(6, 250, 60, 24);
  138. }
  139. void paint(Graphics& g) override
  140. {
  141. g.setColour(Colours::black.withAlpha(.5f));
  142. g.fillRect(5,5,getWidth(), getHeight());
  143. g.setGradientFill(ColourGradient(Colour(0xffffffff), 0.0f, 0.0f,
  144. Colour(0xff888899), (float)getWidth(), (float)getHeight(), false));
  145. if (fIsStandalone)
  146. {
  147. g.fillRect(0, 0, getWidth(), getHeight());
  148. }
  149. else
  150. {
  151. g.fillRect(0, 0, getWidth() - 5, getHeight() - 5);
  152. g.setColour(Colours::black);
  153. g.drawRect(0, 0, getWidth() - 5, getHeight() - 5);
  154. }
  155. }
  156. void changeListenerCallback(ChangeBroadcaster* caller) override
  157. {
  158. if (caller == boolGrid)
  159. {
  160. int i = boolGrid->getLastChanged();
  161. fArpSettings.grid[i] = boolGrid->getCellState(i);
  162. fCallback->arpParameterChanged(6+VexArpSettings::kVelocitiesSize+i);
  163. }
  164. else if (caller == sliderField)
  165. {
  166. int i = sliderField->getLastSlider();
  167. fArpSettings.velocities[i] = jlimit(0.0f, 1.0f, sliderField->getValue(i));
  168. fCallback->arpParameterChanged(6+i);
  169. }
  170. }
  171. void comboBoxChanged(ComboBox* caller) override
  172. {
  173. if (caller == timeMode)
  174. {
  175. fArpSettings.timeMode = timeMode->getSelectedId();
  176. fCallback->arpParameterChanged(2);
  177. }
  178. else if (caller == syncMode)
  179. {
  180. fArpSettings.syncMode = syncMode->getSelectedId();
  181. fCallback->arpParameterChanged(3);
  182. }
  183. else if (caller == failMode)
  184. {
  185. fArpSettings.failMode = failMode->getSelectedId();
  186. fCallback->arpParameterChanged(4);
  187. }
  188. else if (caller == velMode)
  189. {
  190. fArpSettings.velMode = velMode->getSelectedId();
  191. fCallback->arpParameterChanged(5);
  192. }
  193. }
  194. void sliderValueChanged(Slider* /*caller*/) override
  195. {
  196. boolGrid->setLength((int)length->getValue());
  197. sliderField->setLength((int)length->getValue());
  198. fArpSettings.length = (int)length->getValue();
  199. fCallback->arpParameterChanged(1);
  200. }
  201. void buttonClicked(Button* /*caller*/) override
  202. {
  203. fArpSettings.on = onOffBtn->getToggleState();
  204. fCallback->arpParameterChanged(0);
  205. }
  206. void update()
  207. {
  208. onOffBtn->setToggleState(fArpSettings.on, dontSendNotification);
  209. sliderField->setLength(fArpSettings.length);
  210. boolGrid->setLength(fArpSettings.length);
  211. length->setValue(fArpSettings.length);
  212. for (int i = 0; i < VexArpSettings::kVelocitiesSize; ++i)
  213. sliderField->setValue(i, fArpSettings.velocities[i]);
  214. for (int i = 0; i < VexArpSettings::kGridSize; ++i)
  215. boolGrid->setCellState(i, fArpSettings.grid[i]);
  216. timeMode->setSelectedId(fArpSettings.timeMode);
  217. syncMode->setSelectedId(fArpSettings.syncMode);
  218. failMode->setSelectedId(fArpSettings.failMode);
  219. velMode->setSelectedId(fArpSettings.velMode);
  220. }
  221. private:
  222. VexArpSettings& fArpSettings;
  223. Callback* const fCallback;
  224. const bool fIsStandalone;
  225. ScopedPointer<BoolGridComponent> boolGrid;
  226. ScopedPointer<SliderFieldComponent> sliderField;
  227. ScopedPointer<ComboBox> timeMode;
  228. ScopedPointer<ComboBox> syncMode;
  229. ScopedPointer<ComboBox> failMode;
  230. ScopedPointer<ComboBox> velMode;
  231. ScopedPointer<ToggleButton> onOffBtn;
  232. ScopedPointer<Slider> length;
  233. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PeggyViewComponent)
  234. };
  235. #endif // DISTRHO_VEX_PEGGYVIEWCOMPONENT_HEADER_INCLUDED