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.

105 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_MIXERAUDIOSOURCE_JUCEHEADER__
  19. #define __JUCE_MIXERAUDIOSOURCE_JUCEHEADER__
  20. #include "juce_AudioSource.h"
  21. //==============================================================================
  22. /**
  23. An AudioSource that mixes together the output of a set of other AudioSources.
  24. Input sources can be added and removed while the mixer is running as long as their
  25. prepareToPlay() and releaseResources() methods are called before and after adding
  26. them to the mixer.
  27. */
  28. class JUCE_API MixerAudioSource : public AudioSource
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a MixerAudioSource. */
  33. MixerAudioSource();
  34. /** Destructor. */
  35. ~MixerAudioSource();
  36. //==============================================================================
  37. /** Adds an input source to the mixer.
  38. If the mixer is running you'll need to make sure that the input source
  39. is ready to play by calling its prepareToPlay() method before adding it.
  40. If the mixer is stopped, then its input sources will be automatically
  41. prepared when the mixer's prepareToPlay() method is called.
  42. @param newInput the source to add to the mixer
  43. @param deleteWhenRemoved if true, then this source will be deleted when
  44. no longer needed by the mixer.
  45. */
  46. void addInputSource (AudioSource* newInput, bool deleteWhenRemoved);
  47. /** Removes an input source.
  48. If the source was added by calling addInputSource() with the deleteWhenRemoved
  49. flag set, it will be deleted by this method.
  50. */
  51. void removeInputSource (AudioSource* input);
  52. /** Removes all the input sources.
  53. Any sources which were added by calling addInputSource() with the deleteWhenRemoved
  54. flag set will be deleted by this method.
  55. */
  56. void removeAllInputs();
  57. //==============================================================================
  58. /** Implementation of the AudioSource method.
  59. This will call prepareToPlay() on all its input sources.
  60. */
  61. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  62. /** Implementation of the AudioSource method.
  63. This will call releaseResources() on all its input sources.
  64. */
  65. void releaseResources();
  66. /** Implementation of the AudioSource method. */
  67. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  68. private:
  69. //==============================================================================
  70. Array <AudioSource*> inputs;
  71. BigInteger inputsToDelete;
  72. CriticalSection lock;
  73. AudioSampleBuffer tempBuffer;
  74. double currentSampleRate;
  75. int bufferSizeExpected;
  76. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MixerAudioSource);
  77. };
  78. #endif // __JUCE_MIXERAUDIOSOURCE_JUCEHEADER__