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.

134 lines
5.5KB

  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 "SurroundEditor.h"
  19. //==============================================================================
  20. /**
  21. */
  22. class SurroundProcessor : public AudioProcessor, public ChannelClickListener
  23. {
  24. public:
  25. //==============================================================================
  26. SurroundProcessor()
  27. {
  28. }
  29. ~SurroundProcessor() {}
  30. //==============================================================================
  31. void prepareToPlay (double sampleRate, int samplesPerBlock) override
  32. {
  33. channelClicked = 0;
  34. sampleOffset = static_cast<int> (std::ceil (sampleRate));
  35. ignoreUnused (samplesPerBlock);
  36. }
  37. void releaseResources() override {}
  38. void processBlock (AudioSampleBuffer& buffer, MidiBuffer&) override
  39. {
  40. buffer.clear();
  41. const int fillSamples
  42. = jmin (static_cast<int> (std::ceil (getSampleRate())) - sampleOffset, buffer.getNumSamples());
  43. float* channelBuffer = buffer.getWritePointer (channelClicked);
  44. const float freq = 440.f / static_cast<float> (getSampleRate());
  45. for (int i = 0; i < fillSamples; ++i)
  46. channelBuffer[i] = std::sin (2.0f * static_cast<float> (M_PI) * freq * static_cast<float> (sampleOffset++));
  47. }
  48. //==============================================================================
  49. AudioProcessorEditor* createEditor() override { return new SurroundEditor (*this); }
  50. bool hasEditor() const override { return true; }
  51. //==============================================================================
  52. bool setPreferredBusArrangement (bool isInputBus, int busIndex,
  53. const AudioChannelSet& preferred) override
  54. {
  55. if ( preferred == AudioChannelSet::mono()
  56. || preferred == AudioChannelSet::stereo()
  57. || preferred == AudioChannelSet::createLCR()
  58. || preferred == AudioChannelSet::createLCRS()
  59. || preferred == AudioChannelSet::quadraphonic()
  60. || preferred == AudioChannelSet::pentagonal()
  61. || preferred == AudioChannelSet::hexagonal()
  62. || preferred == AudioChannelSet::octagonal()
  63. || preferred == AudioChannelSet::ambisonic()
  64. || preferred == AudioChannelSet::create5point0()
  65. || preferred == AudioChannelSet::create5point1()
  66. || preferred == AudioChannelSet::create6point0()
  67. || preferred == AudioChannelSet::create6point1()
  68. || preferred == AudioChannelSet::create7point0()
  69. || preferred == AudioChannelSet::create7point1()
  70. || preferred == AudioChannelSet::createFront7point0()
  71. || preferred == AudioChannelSet::createFront7point1())
  72. return AudioProcessor::setPreferredBusArrangement (isInputBus, busIndex, preferred);
  73. return false;
  74. }
  75. //==============================================================================
  76. const String getName() const override { return "Surround PlugIn"; }
  77. bool acceptsMidi() const override { return false; }
  78. bool producesMidi() const override { return false; }
  79. bool silenceInProducesSilenceOut() const override { return true; }
  80. double getTailLengthSeconds() const override { return 0; }
  81. //==============================================================================
  82. int getNumPrograms() override { return 1; }
  83. int getCurrentProgram() override { return 0; }
  84. void setCurrentProgram (int) override {}
  85. const String getProgramName (int) override { return String(); }
  86. void changeProgramName (int , const String& ) override { }
  87. //==============================================================================
  88. void getStateInformation (MemoryBlock&) override {}
  89. void setStateInformation (const void* , int) override {}
  90. void channelButtonClicked (int channelIndex) override
  91. {
  92. channelClicked = channelIndex;
  93. sampleOffset = 0;
  94. }
  95. private:
  96. int channelClicked;
  97. int sampleOffset;
  98. //==============================================================================
  99. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SurroundProcessor)
  100. };
  101. //==============================================================================
  102. // This creates new instances of the plugin..
  103. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  104. {
  105. return new SurroundProcessor();
  106. }