Audio plugin host https://kx.studio/carla
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.

juce_MixerAudioSource.h 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef JUCE_MIXERAUDIOSOURCE_H_INCLUDED
  18. #define JUCE_MIXERAUDIOSOURCE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. An AudioSource that mixes together the output of a set of other AudioSources.
  22. Input sources can be added and removed while the mixer is running as long as their
  23. prepareToPlay() and releaseResources() methods are called before and after adding
  24. them to the mixer.
  25. */
  26. class JUCE_API MixerAudioSource : public AudioSource
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates a MixerAudioSource. */
  31. MixerAudioSource();
  32. /** Destructor. */
  33. ~MixerAudioSource();
  34. //==============================================================================
  35. /** Adds an input source to the mixer.
  36. If the mixer is running you'll need to make sure that the input source
  37. is ready to play by calling its prepareToPlay() method before adding it.
  38. If the mixer is stopped, then its input sources will be automatically
  39. prepared when the mixer's prepareToPlay() method is called.
  40. @param newInput the source to add to the mixer
  41. @param deleteWhenRemoved if true, then this source will be deleted when
  42. no longer needed by the mixer.
  43. */
  44. void addInputSource (AudioSource* newInput, bool deleteWhenRemoved);
  45. /** Removes an input source.
  46. If the source was added by calling addInputSource() with the deleteWhenRemoved
  47. flag set, it will be deleted by this method.
  48. */
  49. void removeInputSource (AudioSource* input);
  50. /** Removes all the input sources.
  51. Any sources which were added by calling addInputSource() with the deleteWhenRemoved
  52. flag set will be deleted by this method.
  53. */
  54. void removeAllInputs();
  55. //==============================================================================
  56. /** Implementation of the AudioSource method.
  57. This will call prepareToPlay() on all its input sources.
  58. */
  59. void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
  60. /** Implementation of the AudioSource method.
  61. This will call releaseResources() on all its input sources.
  62. */
  63. void releaseResources() override;
  64. /** Implementation of the AudioSource method. */
  65. void getNextAudioBlock (const AudioSourceChannelInfo&) override;
  66. private:
  67. //==============================================================================
  68. Array<AudioSource*> inputs;
  69. BigInteger inputsToDelete;
  70. CriticalSection lock;
  71. AudioSampleBuffer tempBuffer;
  72. double currentSampleRate;
  73. int bufferSizeExpected;
  74. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MixerAudioSource)
  75. };
  76. #endif // JUCE_MIXERAUDIOSOURCE_H_INCLUDED