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.

129 lines
5.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. #include "../JuceLibraryCode/JuceHeader.h"
  21. //==============================================================================
  22. /**
  23. As the name suggest, this class does the actual audio processing.
  24. */
  25. class JuceDemoPluginAudioProcessor : public AudioProcessor
  26. {
  27. public:
  28. //==============================================================================
  29. JuceDemoPluginAudioProcessor();
  30. ~JuceDemoPluginAudioProcessor();
  31. //==============================================================================
  32. bool isBusesLayoutSupported (const BusesLayout& layouts) const override;
  33. void prepareToPlay (double sampleRate, int samplesPerBlock) override;
  34. void releaseResources() override;
  35. void reset() override;
  36. //==============================================================================
  37. void processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages) override
  38. {
  39. jassert (! isUsingDoublePrecision());
  40. process (buffer, midiMessages, delayBufferFloat);
  41. }
  42. void processBlock (AudioBuffer<double>& buffer, MidiBuffer& midiMessages) override
  43. {
  44. jassert (isUsingDoublePrecision());
  45. process (buffer, midiMessages, delayBufferDouble);
  46. }
  47. //==============================================================================
  48. bool hasEditor() const override { return true; }
  49. AudioProcessorEditor* createEditor() override;
  50. //==============================================================================
  51. const String getName() const override { return JucePlugin_Name; }
  52. bool acceptsMidi() const override { return true; }
  53. bool producesMidi() const override { return true; }
  54. double getTailLengthSeconds() const override { return 0.0; }
  55. //==============================================================================
  56. int getNumPrograms() override { return 0; }
  57. int getCurrentProgram() override { return 0; }
  58. void setCurrentProgram (int /*index*/) override {}
  59. const String getProgramName (int /*index*/) override { return String(); }
  60. void changeProgramName (int /*index*/, const String& /*name*/) override {}
  61. //==============================================================================
  62. void getStateInformation (MemoryBlock&) override;
  63. void setStateInformation (const void* data, int sizeInBytes) override;
  64. //==============================================================================
  65. // These properties are public so that our editor component can access them
  66. // A bit of a hacky way to do it, but it's only a demo! Obviously in your own
  67. // code you'll do this much more neatly..
  68. // this is kept up to date with the midi messages that arrive, and the UI component
  69. // registers with it so it can represent the incoming messages
  70. MidiKeyboardState keyboardState;
  71. // this keeps a copy of the last set of time info that was acquired during an audio
  72. // callback - the UI component will read this and display it.
  73. AudioPlayHead::CurrentPositionInfo lastPosInfo;
  74. // these are used to persist the UI's size - the values are stored along with the
  75. // filter's other parameters, and the UI component will update them when it gets
  76. // resized.
  77. int lastUIWidth = 400, lastUIHeight = 200;
  78. // Our parameters
  79. AudioParameterFloat* gainParam = nullptr;
  80. AudioParameterFloat* delayParam = nullptr;
  81. private:
  82. //==============================================================================
  83. template <typename FloatType>
  84. void process (AudioBuffer<FloatType>& buffer, MidiBuffer& midiMessages, AudioBuffer<FloatType>& delayBuffer);
  85. template <typename FloatType>
  86. void applyGain (AudioBuffer<FloatType>&, AudioBuffer<FloatType>& delayBuffer);
  87. template <typename FloatType>
  88. void applyDelay (AudioBuffer<FloatType>&, AudioBuffer<FloatType>& delayBuffer);
  89. AudioBuffer<float> delayBufferFloat;
  90. AudioBuffer<double> delayBufferDouble;
  91. int delayPosition = 0;
  92. Synthesiser synth;
  93. void initialiseSynth();
  94. void updateCurrentTimeInfoFromHost();
  95. static BusesProperties getBusesProperties();
  96. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JuceDemoPluginAudioProcessor)
  97. };