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.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  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. } // namespace juce