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.

108 lines
4.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_MIXERAUDIOSOURCE_H_INCLUDED
  24. #define JUCE_MIXERAUDIOSOURCE_H_INCLUDED
  25. //==============================================================================
  26. /**
  27. An AudioSource that mixes together the output of a set of other AudioSources.
  28. Input sources can be added and removed while the mixer is running as long as their
  29. prepareToPlay() and releaseResources() methods are called before and after adding
  30. them to the mixer.
  31. */
  32. class JUCE_API MixerAudioSource : public AudioSource
  33. {
  34. public:
  35. //==============================================================================
  36. /** Creates a MixerAudioSource. */
  37. MixerAudioSource();
  38. /** Destructor. */
  39. ~MixerAudioSource();
  40. //==============================================================================
  41. /** Adds an input source to the mixer.
  42. If the mixer is running you'll need to make sure that the input source
  43. is ready to play by calling its prepareToPlay() method before adding it.
  44. If the mixer is stopped, then its input sources will be automatically
  45. prepared when the mixer's prepareToPlay() method is called.
  46. @param newInput the source to add to the mixer
  47. @param deleteWhenRemoved if true, then this source will be deleted when
  48. no longer needed by the mixer.
  49. */
  50. void addInputSource (AudioSource* newInput, bool deleteWhenRemoved);
  51. /** Removes an input source.
  52. If the source was added by calling addInputSource() with the deleteWhenRemoved
  53. flag set, it will be deleted by this method.
  54. */
  55. void removeInputSource (AudioSource* input);
  56. /** Removes all the input sources.
  57. Any sources which were added by calling addInputSource() with the deleteWhenRemoved
  58. flag set will be deleted by this method.
  59. */
  60. void removeAllInputs();
  61. //==============================================================================
  62. /** Implementation of the AudioSource method.
  63. This will call prepareToPlay() on all its input sources.
  64. */
  65. void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
  66. /** Implementation of the AudioSource method.
  67. This will call releaseResources() on all its input sources.
  68. */
  69. void releaseResources() override;
  70. /** Implementation of the AudioSource method. */
  71. void getNextAudioBlock (const AudioSourceChannelInfo&) override;
  72. private:
  73. //==============================================================================
  74. Array<AudioSource*> inputs;
  75. BigInteger inputsToDelete;
  76. CriticalSection lock;
  77. AudioSampleBuffer tempBuffer;
  78. double currentSampleRate;
  79. int bufferSizeExpected;
  80. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MixerAudioSource)
  81. };
  82. #endif // JUCE_MIXERAUDIOSOURCE_H_INCLUDED