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.

124 lines
4.9KB

  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. // Some VST-2 DAWs want the maximum amount of channels to be enabled by default
  30. if (wrapperType == wrapperType_VST)
  31. {
  32. busArrangement.inputBuses. getReference (0).channels = AudioChannelSet::discreteChannels (kVST2MaxChannels);
  33. busArrangement.outputBuses.getReference (0).channels = AudioChannelSet::discreteChannels (kVST2MaxChannels);
  34. }
  35. }
  36. ~GainProcessor() {}
  37. //==============================================================================
  38. void prepareToPlay (double, int) override {}
  39. void releaseResources() override {}
  40. void processBlock (AudioSampleBuffer& buffer, MidiBuffer&) override
  41. {
  42. buffer.applyGain (*gain);
  43. }
  44. //==============================================================================
  45. AudioProcessorEditor* createEditor() override { return new GenericEditor (*this); }
  46. bool hasEditor() const override { return true; }
  47. //==============================================================================
  48. const String getName() const override { return "Gain PlugIn"; }
  49. bool acceptsMidi() const override { return false; }
  50. bool producesMidi() const override { return false; }
  51. double getTailLengthSeconds() const override { return 0; }
  52. //==============================================================================
  53. int getNumPrograms() override { return 1; }
  54. int getCurrentProgram() override { return 0; }
  55. void setCurrentProgram (int) override {}
  56. const String getProgramName (int) override { return String(); }
  57. void changeProgramName (int , const String& ) override { }
  58. //==============================================================================
  59. void getStateInformation (MemoryBlock& destData) override
  60. {
  61. MemoryOutputStream (destData, true).writeFloat (*gain);
  62. }
  63. void setStateInformation (const void* data, int sizeInBytes) override
  64. {
  65. gain->setValueNotifyingHost (MemoryInputStream (data, static_cast<size_t> (sizeInBytes), false).readFloat());
  66. }
  67. //==============================================================================
  68. bool setPreferredBusArrangement (bool isInputBus, int busIndex,
  69. const AudioChannelSet& preferred) override
  70. {
  71. const int numChannels = preferred.size();
  72. // do not allow disabling channels
  73. if (numChannels == 0)
  74. return false;
  75. // limit the amount of channels for VST-2
  76. if (wrapperType == wrapperType_VST && numChannels > kVST2MaxChannels)
  77. return false;
  78. // always have the same channel layout on both input and output on the main bus
  79. if (! AudioProcessor::setPreferredBusArrangement (! isInputBus, busIndex, preferred))
  80. return false;
  81. return AudioProcessor::setPreferredBusArrangement (isInputBus, busIndex, preferred);
  82. }
  83. private:
  84. //==============================================================================
  85. AudioParameterFloat* gain;
  86. enum { kVST2MaxChannels = 16 };
  87. //==============================================================================
  88. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GainProcessor)
  89. };
  90. //==============================================================================
  91. // This creates new instances of the plugin..
  92. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  93. {
  94. return new GainProcessor();
  95. }