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.

110 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. {
  28. addParameter (gain = new AudioParameterFloat ("gain", "Gain", 0.0f, 1.0f, 0.5f));
  29. }
  30. ~GainProcessor() {}
  31. //==============================================================================
  32. void prepareToPlay (double sampleRate, int samplesPerBlock) override {}
  33. void releaseResources() override {}
  34. void processBlock (AudioSampleBuffer& buffer, MidiBuffer&) override
  35. {
  36. buffer.applyGain (*gain);
  37. }
  38. //==============================================================================
  39. AudioProcessorEditor* createEditor() override { return new GenericEditor (*this); }
  40. bool hasEditor() const override { return true; }
  41. //==============================================================================
  42. const String getName() const override { return "Gain PlugIn"; }
  43. bool acceptsMidi() const override { return false; }
  44. bool producesMidi() const override { return false; }
  45. double getTailLengthSeconds() const override { return 0; }
  46. //==============================================================================
  47. int getNumPrograms() override { return 1; }
  48. int getCurrentProgram() override { return 0; }
  49. void setCurrentProgram (int) override {}
  50. const String getProgramName (int) override { return String(); }
  51. void changeProgramName (int , const String& ) override { }
  52. //==============================================================================
  53. void getStateInformation (MemoryBlock& destData) override
  54. {
  55. MemoryOutputStream (destData, true).writeFloat (*gain);
  56. }
  57. void setStateInformation (const void* data, int sizeInBytes) override
  58. {
  59. gain->setValueNotifyingHost (MemoryInputStream (data, sizeInBytes, false).readFloat());
  60. }
  61. //==============================================================================
  62. bool setPreferredBusArrangement (bool isInputBus, int busIndex,
  63. const AudioChannelSet& preferred) override
  64. {
  65. const int numChannels = preferred.size();
  66. // do not allow disabling channels
  67. if (numChannels == 0) return false;
  68. // always have the same channel layout on both input and output on the main bus
  69. if (! AudioProcessor::setPreferredBusArrangement (! isInputBus, busIndex, preferred))
  70. return false;
  71. return AudioProcessor::setPreferredBusArrangement (isInputBus, busIndex, preferred);
  72. }
  73. private:
  74. //==============================================================================
  75. AudioParameterFloat* gain;
  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. }