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.

100 lines
3.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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. @tags{Audio}
  26. */
  27. class JUCE_API MixerAudioSource : public AudioSource
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a MixerAudioSource. */
  32. MixerAudioSource();
  33. /** Destructor. */
  34. ~MixerAudioSource() override;
  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) override;
  61. /** Implementation of the AudioSource method.
  62. This will call releaseResources() on all its input sources.
  63. */
  64. void releaseResources() override;
  65. /** Implementation of the AudioSource method. */
  66. void getNextAudioBlock (const AudioSourceChannelInfo&) override;
  67. private:
  68. //==============================================================================
  69. Array<AudioSource*> inputs;
  70. BigInteger inputsToDelete;
  71. CriticalSection lock;
  72. AudioBuffer<float> tempBuffer;
  73. double currentSampleRate;
  74. int bufferSizeExpected;
  75. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MixerAudioSource)
  76. };
  77. } // namespace juce