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.

107 lines
4.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../JuceLibraryCode/JuceHeader.h"
  18. #include "../../GenericEditor.h"
  19. //==============================================================================
  20. /**
  21. */
  22. class GainProcessor : public AudioProcessor
  23. {
  24. public:
  25. //==============================================================================
  26. GainProcessor()
  27. : AudioProcessor (BusesProperties().withInput ("Input", AudioChannelSet::stereo())
  28. .withOutput ("Output", AudioChannelSet::stereo()))
  29. {
  30. addParameter (gain = new AudioParameterFloat ("gain", "Gain", 0.0f, 1.0f, 0.5f));
  31. }
  32. ~GainProcessor() {}
  33. //==============================================================================
  34. void prepareToPlay (double, int) override {}
  35. void releaseResources() override {}
  36. void processBlock (AudioSampleBuffer& buffer, MidiBuffer&) override
  37. {
  38. buffer.applyGain (*gain);
  39. }
  40. //==============================================================================
  41. AudioProcessorEditor* createEditor() override { return new GenericEditor (*this); }
  42. bool hasEditor() const override { return true; }
  43. //==============================================================================
  44. const String getName() const override { return "Gain PlugIn"; }
  45. bool acceptsMidi() const override { return false; }
  46. bool producesMidi() const override { return false; }
  47. double getTailLengthSeconds() const override { return 0; }
  48. //==============================================================================
  49. int getNumPrograms() override { return 1; }
  50. int getCurrentProgram() override { return 0; }
  51. void setCurrentProgram (int) override {}
  52. const String getProgramName (int) override { return String(); }
  53. void changeProgramName (int , const String& ) override { }
  54. //==============================================================================
  55. void getStateInformation (MemoryBlock& destData) override
  56. {
  57. MemoryOutputStream (destData, true).writeFloat (*gain);
  58. }
  59. void setStateInformation (const void* data, int sizeInBytes) override
  60. {
  61. gain->setValueNotifyingHost (MemoryInputStream (data, static_cast<size_t> (sizeInBytes), false).readFloat());
  62. }
  63. //==============================================================================
  64. bool isBusesLayoutSupported (const BusesLayout& layouts) const override
  65. {
  66. const AudioChannelSet& mainInLayout = layouts.getChannelSet (true, 0);
  67. const AudioChannelSet& mainOutLayout = layouts.getChannelSet (false, 0);
  68. return (mainInLayout == mainOutLayout && (! mainInLayout.isDisabled()));
  69. }
  70. private:
  71. //==============================================================================
  72. AudioParameterFloat* gain;
  73. enum { kVST2MaxChannels = 16 };
  74. //==============================================================================
  75. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GainProcessor)
  76. };
  77. //==============================================================================
  78. // This creates new instances of the plugin..
  79. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  80. {
  81. return new GainProcessor();
  82. }