The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

162 lines
5.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "MaterialLookAndFeel.h"
  20. //==============================================================================
  21. class AUv3SynthEditor : public AudioProcessorEditor,
  22. public ButtonListener,
  23. public Slider::Listener,
  24. private Timer
  25. {
  26. public:
  27. //==============================================================================
  28. AUv3SynthEditor (AudioProcessor& processor)
  29. : AudioProcessorEditor (processor),
  30. recordButton ("Record"),
  31. roomSizeSlider (Slider::LinearHorizontal, Slider::NoTextBox)
  32. {
  33. LookAndFeel::setDefaultLookAndFeel (&materialLookAndFeel);
  34. roomSizeSlider.setValue (getParameterValue ("roomSize"), NotificationType::dontSendNotification);
  35. recordButton.addListener (this);
  36. addAndMakeVisible (recordButton);
  37. roomSizeSlider.addListener (this);
  38. roomSizeSlider.setRange (0.0, 1.0);
  39. addAndMakeVisible (roomSizeSlider);
  40. Path proAudioPath;
  41. proAudioPath.loadPathFromData (BinaryData::proaudio_path, BinaryData::proaudio_pathSize);
  42. proAudioIcon.setPath (proAudioPath);
  43. addAndMakeVisible (proAudioIcon);
  44. Colour proAudioIconColour = findColour (TextButton::buttonOnColourId);
  45. proAudioIcon.setFill (FillType (proAudioIconColour));
  46. setSize (600, 400);
  47. startTimer (100);
  48. }
  49. //==============================================================================
  50. void paint (Graphics& g) override
  51. {
  52. g.fillAll (findColour (ResizableWindow::backgroundColourId));
  53. }
  54. void resized() override
  55. {
  56. Rectangle<int> r = getLocalBounds();
  57. int guiElementAreaHeight = r.getHeight() / 3;
  58. proAudioIcon.setTransformToFit (r.removeFromLeft (proportionOfWidth (0.25))
  59. .withSizeKeepingCentre (guiElementAreaHeight, guiElementAreaHeight)
  60. .toFloat(),
  61. RectanglePlacement::fillDestination);
  62. int margin = guiElementAreaHeight / 4;
  63. r.reduce (margin, margin);
  64. int buttonHeight = guiElementAreaHeight - margin;
  65. recordButton.setBounds (r.removeFromTop (guiElementAreaHeight).withSizeKeepingCentre (r.getWidth(), buttonHeight));
  66. roomSizeSlider.setBounds (r.removeFromTop (guiElementAreaHeight).withSizeKeepingCentre (r.getWidth(), buttonHeight));
  67. }
  68. //==============================================================================
  69. void buttonClicked (Button* button) override
  70. {
  71. if (button == &recordButton)
  72. {
  73. recordButton.setEnabled (false);
  74. setParameterValue ("isRecording", 1.0f);
  75. }
  76. }
  77. void sliderValueChanged (Slider*) override
  78. {
  79. setParameterValue ("roomSize", roomSizeSlider.getValue());
  80. }
  81. private:
  82. //==============================================================================
  83. void timerCallback() override
  84. {
  85. bool isRecordingNow = (getParameterValue ("isRecording") >= 0.5f);
  86. recordButton.setEnabled (! isRecordingNow);
  87. roomSizeSlider.setValue (getParameterValue ("roomSize"), NotificationType::dontSendNotification);
  88. }
  89. //==============================================================================
  90. AudioProcessorParameter* getParameter (const String& paramId)
  91. {
  92. if (AudioProcessor* processor = getAudioProcessor())
  93. {
  94. const OwnedArray<AudioProcessorParameter>& params = processor->getParameters();
  95. for (int i = 0; i < params.size(); ++i)
  96. {
  97. if (AudioProcessorParameterWithID* param = dynamic_cast<AudioProcessorParameterWithID*> (params[i]))
  98. {
  99. if (param->paramID == paramId)
  100. return param;
  101. }
  102. }
  103. }
  104. return nullptr;
  105. }
  106. //==============================================================================
  107. float getParameterValue (const String& paramId)
  108. {
  109. if (AudioProcessorParameter* param = getParameter (paramId))
  110. return param->getValue();
  111. return 0.0f;
  112. }
  113. void setParameterValue (const String& paramId, float value)
  114. {
  115. if (AudioProcessorParameter* param = getParameter (paramId))
  116. param->setValueNotifyingHost (value);
  117. }
  118. //==============================================================================
  119. MaterialLookAndFeel materialLookAndFeel;
  120. //==============================================================================
  121. TextButton recordButton;
  122. Slider roomSizeSlider;
  123. DrawablePath proAudioIcon;
  124. //==============================================================================
  125. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AUv3SynthEditor)
  126. };