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.

121 lines
4.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. #include "../../threads/juce_CriticalSection.h"
  22. #include "../../containers/juce_Array.h"
  23. #include "../../maths/juce_BigInteger.h"
  24. //==============================================================================
  25. /**
  26. An AudioSource that mixes together the output of a set of other AudioSources.
  27. Input sources can be added and removed while the mixer is running as long as their
  28. prepareToPlay() and releaseResources() methods are called before and after adding
  29. them to the mixer.
  30. */
  31. class JUCE_API MixerAudioSource : public AudioSource
  32. {
  33. public:
  34. //==============================================================================
  35. /** Creates a MixerAudioSource.
  36. */
  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. the mixer is deleted or when removeAllInputs() is
  49. called (unless the source is previously removed
  50. with the removeInputSource method)
  51. */
  52. void addInputSource (AudioSource* newInput, bool deleteWhenRemoved);
  53. /** Removes an input source.
  54. If the mixer is running, this will remove the source but not call its
  55. releaseResources() method, so the caller might want to do this manually.
  56. @param input the source to remove
  57. @param deleteSource whether to delete this source after it's been removed
  58. */
  59. void removeInputSource (AudioSource* input, bool deleteSource);
  60. /** Removes all the input sources.
  61. If the mixer is running, this will remove the sources but not call their
  62. releaseResources() method, so the caller might want to do this manually.
  63. Any sources which were added with the deleteWhenRemoved flag set will be
  64. deleted by this method.
  65. */
  66. void removeAllInputs();
  67. //==============================================================================
  68. /** Implementation of the AudioSource method.
  69. This will call prepareToPlay() on all its input sources.
  70. */
  71. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  72. /** Implementation of the AudioSource method.
  73. This will call releaseResources() on all its input sources.
  74. */
  75. void releaseResources();
  76. /** Implementation of the AudioSource method. */
  77. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  78. private:
  79. //==============================================================================
  80. Array <AudioSource*> inputs;
  81. BigInteger inputsToDelete;
  82. CriticalSection lock;
  83. AudioSampleBuffer tempBuffer;
  84. double currentSampleRate;
  85. int bufferSizeExpected;
  86. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MixerAudioSource);
  87. };
  88. #endif // __JUCE_MIXERAUDIOSOURCE_JUCEHEADER__