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.

109 lines
4.3KB

  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 "../JuceLibraryCode/JuceHeader.h"
  20. #include "../../GenericEditor.h"
  21. //==============================================================================
  22. /**
  23. */
  24. class GainProcessor : public AudioProcessor
  25. {
  26. public:
  27. //==============================================================================
  28. GainProcessor()
  29. : AudioProcessor (BusesProperties().withInput ("Input", AudioChannelSet::stereo())
  30. .withOutput ("Output", AudioChannelSet::stereo()))
  31. {
  32. addParameter (gain = new AudioParameterFloat ("gain", "Gain", 0.0f, 1.0f, 0.5f));
  33. }
  34. ~GainProcessor() {}
  35. //==============================================================================
  36. void prepareToPlay (double, int) override {}
  37. void releaseResources() override {}
  38. void processBlock (AudioSampleBuffer& buffer, MidiBuffer&) override
  39. {
  40. buffer.applyGain (*gain);
  41. }
  42. //==============================================================================
  43. AudioProcessorEditor* createEditor() override { return new GenericEditor (*this); }
  44. bool hasEditor() const override { return true; }
  45. //==============================================================================
  46. const String getName() const override { return "Gain PlugIn"; }
  47. bool acceptsMidi() const override { return false; }
  48. bool producesMidi() const override { return false; }
  49. double getTailLengthSeconds() const override { return 0; }
  50. //==============================================================================
  51. int getNumPrograms() override { return 1; }
  52. int getCurrentProgram() override { return 0; }
  53. void setCurrentProgram (int) override {}
  54. const String getProgramName (int) override { return String(); }
  55. void changeProgramName (int , const String& ) override { }
  56. //==============================================================================
  57. void getStateInformation (MemoryBlock& destData) override
  58. {
  59. MemoryOutputStream (destData, true).writeFloat (*gain);
  60. }
  61. void setStateInformation (const void* data, int sizeInBytes) override
  62. {
  63. gain->setValueNotifyingHost (MemoryInputStream (data, static_cast<size_t> (sizeInBytes), false).readFloat());
  64. }
  65. //==============================================================================
  66. bool isBusesLayoutSupported (const BusesLayout& layouts) const override
  67. {
  68. const AudioChannelSet& mainInLayout = layouts.getChannelSet (true, 0);
  69. const AudioChannelSet& mainOutLayout = layouts.getChannelSet (false, 0);
  70. return (mainInLayout == mainOutLayout && (! mainInLayout.isDisabled()));
  71. }
  72. private:
  73. //==============================================================================
  74. AudioParameterFloat* gain;
  75. enum { kVST2MaxChannels = 16 };
  76. //==============================================================================
  77. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GainProcessor)
  78. };
  79. //==============================================================================
  80. // This creates new instances of the plugin..
  81. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  82. {
  83. return new GainProcessor();
  84. }