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.

118 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. The code included in this file is provided under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  7. To use, copy, modify, and/or distribute this software for any purpose with or
  8. without fee is hereby granted provided that the above copyright notice and
  9. this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
  11. WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
  12. PURPOSE, ARE DISCLAIMED.
  13. ==============================================================================
  14. */
  15. /*******************************************************************************
  16. The block below describes the properties of this PIP. A PIP is a short snippet
  17. of code that can be read by the Projucer and used to generate a JUCE project.
  18. BEGIN_JUCE_PIP_METADATA
  19. name: GainPlugin
  20. version: 1.0.0
  21. vendor: JUCE
  22. website: http://juce.com
  23. description: Gain audio plugin.
  24. dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
  25. juce_audio_plugin_client, juce_audio_processors,
  26. juce_audio_utils, juce_core, juce_data_structures,
  27. juce_events, juce_graphics, juce_gui_basics, juce_gui_extra
  28. exporters: xcode_mac, vs2017
  29. type: AudioProcessor
  30. mainClass: GainProcessor
  31. useLocalCopy: 1
  32. END_JUCE_PIP_METADATA
  33. *******************************************************************************/
  34. #pragma once
  35. //==============================================================================
  36. class GainProcessor : public AudioProcessor
  37. {
  38. public:
  39. //==============================================================================
  40. GainProcessor()
  41. : AudioProcessor (BusesProperties().withInput ("Input", AudioChannelSet::stereo())
  42. .withOutput ("Output", AudioChannelSet::stereo()))
  43. {
  44. addParameter (gain = new AudioParameterFloat ("gain", "Gain", 0.0f, 1.0f, 0.5f));
  45. }
  46. ~GainProcessor() {}
  47. //==============================================================================
  48. void prepareToPlay (double, int) override {}
  49. void releaseResources() override {}
  50. void processBlock (AudioBuffer<float>& buffer, MidiBuffer&) override
  51. {
  52. buffer.applyGain (*gain);
  53. }
  54. //==============================================================================
  55. AudioProcessorEditor* createEditor() override { return new GenericAudioProcessorEditor (this); }
  56. bool hasEditor() const override { return true; }
  57. //==============================================================================
  58. const String getName() const override { return "Gain PlugIn"; }
  59. bool acceptsMidi() const override { return false; }
  60. bool producesMidi() const override { return false; }
  61. double getTailLengthSeconds() const override { return 0; }
  62. //==============================================================================
  63. int getNumPrograms() override { return 1; }
  64. int getCurrentProgram() override { return 0; }
  65. void setCurrentProgram (int) override {}
  66. const String getProgramName (int) override { return {}; }
  67. void changeProgramName (int, const String&) override {}
  68. //==============================================================================
  69. void getStateInformation (MemoryBlock& destData) override
  70. {
  71. MemoryOutputStream (destData, true).writeFloat (*gain);
  72. }
  73. void setStateInformation (const void* data, int sizeInBytes) override
  74. {
  75. gain->setValueNotifyingHost (MemoryInputStream (data, static_cast<size_t> (sizeInBytes), false).readFloat());
  76. }
  77. //==============================================================================
  78. bool isBusesLayoutSupported (const BusesLayout& layouts) const override
  79. {
  80. const auto& mainInLayout = layouts.getChannelSet (true, 0);
  81. const auto& mainOutLayout = layouts.getChannelSet (false, 0);
  82. return (mainInLayout == mainOutLayout && (! mainInLayout.isDisabled()));
  83. }
  84. private:
  85. //==============================================================================
  86. AudioParameterFloat* gain;
  87. //==============================================================================
  88. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GainProcessor)
  89. };