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.

130 lines
5.4KB

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