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.

143 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. Copyright (c) 2015 - ROLI Ltd.
  4. ==============================================================================
  5. */
  6. #include "MaterialLookAndFeel.h"
  7. //==============================================================================
  8. class AUv3SynthEditor : public AudioProcessorEditor,
  9. public ButtonListener,
  10. public Slider::Listener,
  11. private Timer
  12. {
  13. public:
  14. //==============================================================================
  15. AUv3SynthEditor (AudioProcessor& processor)
  16. : AudioProcessorEditor (processor),
  17. recordButton ("Record"),
  18. roomSizeSlider (Slider::LinearHorizontal, Slider::NoTextBox)
  19. {
  20. LookAndFeel::setDefaultLookAndFeel (&materialLookAndFeel);
  21. roomSizeSlider.setValue (getParameterValue ("roomSize"), NotificationType::dontSendNotification);
  22. recordButton.addListener (this);
  23. addAndMakeVisible (recordButton);
  24. roomSizeSlider.addListener (this);
  25. roomSizeSlider.setRange (0.0, 1.0);
  26. addAndMakeVisible (roomSizeSlider);
  27. Path proAudioPath;
  28. proAudioPath.loadPathFromData (BinaryData::proaudio_path, BinaryData::proaudio_pathSize);
  29. proAudioIcon.setPath (proAudioPath);
  30. addAndMakeVisible (proAudioIcon);
  31. Colour proAudioIconColour = findColour (TextButton::buttonOnColourId);
  32. proAudioIcon.setFill (FillType (proAudioIconColour));
  33. setSize (600, 400);
  34. startTimer (100);
  35. }
  36. //==============================================================================
  37. void paint (Graphics& g) override
  38. {
  39. g.fillAll (findColour (ResizableWindow::backgroundColourId));
  40. }
  41. void resized() override
  42. {
  43. Rectangle<int> r = getLocalBounds();
  44. int guiElementAreaHeight = r.getHeight() / 3;
  45. proAudioIcon.setTransformToFit (r.removeFromLeft (proportionOfWidth (0.25))
  46. .withSizeKeepingCentre (guiElementAreaHeight, guiElementAreaHeight)
  47. .toFloat(),
  48. RectanglePlacement::fillDestination);
  49. int margin = guiElementAreaHeight / 4;
  50. r.reduce (margin, margin);
  51. int buttonHeight = guiElementAreaHeight - margin;
  52. recordButton.setBounds (r.removeFromTop (guiElementAreaHeight).withSizeKeepingCentre (r.getWidth(), buttonHeight));
  53. roomSizeSlider.setBounds (r.removeFromTop (guiElementAreaHeight).withSizeKeepingCentre (r.getWidth(), buttonHeight));
  54. }
  55. //==============================================================================
  56. void buttonClicked (Button* button) override
  57. {
  58. if (button == &recordButton)
  59. {
  60. recordButton.setEnabled (false);
  61. setParameterValue ("isRecording", 1.0f);
  62. }
  63. }
  64. void sliderValueChanged (Slider*) override
  65. {
  66. setParameterValue ("roomSize", roomSizeSlider.getValue());
  67. }
  68. private:
  69. //==============================================================================
  70. void timerCallback() override
  71. {
  72. bool isRecordingNow = (getParameterValue ("isRecording") >= 0.5f);
  73. recordButton.setEnabled (! isRecordingNow);
  74. roomSizeSlider.setValue (getParameterValue ("roomSize"), NotificationType::dontSendNotification);
  75. }
  76. //==============================================================================
  77. AudioProcessorParameter* getParameter (const String& paramId)
  78. {
  79. if (AudioProcessor* processor = getAudioProcessor())
  80. {
  81. const OwnedArray<AudioProcessorParameter>& params = processor->getParameters();
  82. for (int i = 0; i < params.size(); ++i)
  83. {
  84. if (AudioProcessorParameterWithID* param = dynamic_cast<AudioProcessorParameterWithID*> (params[i]))
  85. {
  86. if (param->paramID == paramId)
  87. return param;
  88. }
  89. }
  90. }
  91. return nullptr;
  92. }
  93. //==============================================================================
  94. float getParameterValue (const String& paramId)
  95. {
  96. if (AudioProcessorParameter* param = getParameter (paramId))
  97. return param->getValue();
  98. return 0.0f;
  99. }
  100. void setParameterValue (const String& paramId, float value)
  101. {
  102. if (AudioProcessorParameter* param = getParameter (paramId))
  103. param->setValueNotifyingHost (value);
  104. }
  105. //==============================================================================
  106. MaterialLookAndFeel materialLookAndFeel;
  107. //==============================================================================
  108. TextButton recordButton;
  109. Slider roomSizeSlider;
  110. DrawablePath proAudioIcon;
  111. //==============================================================================
  112. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AUv3SynthEditor)
  113. };