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.

97 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. GainProcessor.cpp
  4. Created: 23 Nov 2015 3:08:33pm
  5. Author: Fabian Renn
  6. ==============================================================================
  7. */
  8. #include "../JuceLibraryCode/JuceHeader.h"
  9. #include "../../GenericEditor.h"
  10. //==============================================================================
  11. /**
  12. */
  13. class GainProcessor : public AudioProcessor
  14. {
  15. public:
  16. //==============================================================================
  17. GainProcessor()
  18. {
  19. addParameter (gain = new AudioParameterFloat ("gain", "Gain", 0.0f, 1.0f, 0.5f));
  20. }
  21. ~GainProcessor() {}
  22. //==============================================================================
  23. void prepareToPlay (double sampleRate, int samplesPerBlock) override {}
  24. void releaseResources() override {}
  25. void processBlock (AudioSampleBuffer& buffer, MidiBuffer&) override
  26. {
  27. buffer.applyGain (*gain);
  28. }
  29. //==============================================================================
  30. AudioProcessorEditor* createEditor() override { return new GenericEditor (*this); }
  31. bool hasEditor() const override { return true; }
  32. //==============================================================================
  33. const String getName() const override { return "Gain PlugIn"; }
  34. bool acceptsMidi() const override { return false; }
  35. bool producesMidi() const override { return false; }
  36. bool silenceInProducesSilenceOut() const override { return true; }
  37. double getTailLengthSeconds() const override { return 0; }
  38. //==============================================================================
  39. int getNumPrograms() override { return 1; }
  40. int getCurrentProgram() override { return 0; }
  41. void setCurrentProgram (int) override {}
  42. const String getProgramName (int) override { return String(); }
  43. void changeProgramName (int , const String& ) override { }
  44. //==============================================================================
  45. void getStateInformation (MemoryBlock& destData) override
  46. {
  47. MemoryOutputStream (destData, true).writeFloat (*gain);
  48. }
  49. void setStateInformation (const void* data, int sizeInBytes) override
  50. {
  51. gain->setValueNotifyingHost (MemoryInputStream (data, sizeInBytes, false).readFloat());
  52. }
  53. //==============================================================================
  54. bool setPreferredBusArrangement (bool isInputBus, int busIndex,
  55. const AudioChannelSet& preferred) override
  56. {
  57. const int numChannels = preferred.size();
  58. // do not allow disabling channels
  59. if (numChannels == 0) return false;
  60. // always have the same channel layout on both input and output on the main bus
  61. if (! AudioProcessor::setPreferredBusArrangement (! isInputBus, busIndex, preferred))
  62. return false;
  63. return AudioProcessor::setPreferredBusArrangement (isInputBus, busIndex, preferred);
  64. }
  65. private:
  66. //==============================================================================
  67. AudioParameterFloat* gain;
  68. //==============================================================================
  69. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GainProcessor)
  70. };
  71. //==============================================================================
  72. // This creates new instances of the plugin..
  73. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  74. {
  75. return new GainProcessor();
  76. }