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.

104 lines
3.8KB

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