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.

149 lines
6.0KB

  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_CHANNELREMAPPINGAUDIOSOURCE_JUCEHEADER__
  18. #define __JUCE_CHANNELREMAPPINGAUDIOSOURCE_JUCEHEADER__
  19. #include "juce_AudioSource.h"
  20. //==============================================================================
  21. /**
  22. An AudioSource that takes the audio from another source, and re-maps its
  23. input and output channels to a different arrangement.
  24. You can use this to increase or decrease the number of channels that an
  25. audio source uses, or to re-order those channels.
  26. Call the reset() method before using it to set up a default mapping, and then
  27. the setInputChannelMapping() and setOutputChannelMapping() methods to
  28. create an appropriate mapping, otherwise no channels will be connected and
  29. it'll produce silence.
  30. @see AudioSource
  31. */
  32. class ChannelRemappingAudioSource : public AudioSource
  33. {
  34. public:
  35. //==============================================================================
  36. /** Creates a remapping source that will pass on audio from the given input.
  37. @param source the input source to use. Make sure that this doesn't
  38. get deleted before the ChannelRemappingAudioSource object
  39. @param deleteSourceWhenDeleted if true, the input source will be deleted
  40. when this object is deleted, if false, the caller is
  41. responsible for its deletion
  42. */
  43. ChannelRemappingAudioSource (AudioSource* source,
  44. bool deleteSourceWhenDeleted);
  45. /** Destructor. */
  46. ~ChannelRemappingAudioSource();
  47. //==============================================================================
  48. /** Specifies a number of channels that this audio source must produce from its
  49. getNextAudioBlock() callback.
  50. */
  51. void setNumberOfChannelsToProduce (int requiredNumberOfChannels);
  52. /** Clears any mapped channels.
  53. After this, no channels are mapped, so this object will produce silence. Create
  54. some mappings with setInputChannelMapping() and setOutputChannelMapping().
  55. */
  56. void clearAllMappings();
  57. /** Creates an input channel mapping.
  58. When the getNextAudioBlock() method is called, the data in channel sourceChannelIndex of the incoming
  59. data will be sent to destChannelIndex of our input source.
  60. @param destChannelIndex the index of an input channel in our input audio source (i.e. the
  61. source specified when this object was created).
  62. @param sourceChannelIndex the index of the input channel in the incoming audio data buffer
  63. during our getNextAudioBlock() callback
  64. */
  65. void setInputChannelMapping (int destChannelIndex,
  66. int sourceChannelIndex);
  67. /** Creates an output channel mapping.
  68. When the getNextAudioBlock() method is called, the data returned in channel sourceChannelIndex by
  69. our input audio source will be copied to channel destChannelIndex of the final buffer.
  70. @param sourceChannelIndex the index of an output channel coming from our input audio source
  71. (i.e. the source specified when this object was created).
  72. @param destChannelIndex the index of the output channel in the incoming audio data buffer
  73. during our getNextAudioBlock() callback
  74. */
  75. void setOutputChannelMapping (int sourceChannelIndex,
  76. int destChannelIndex);
  77. /** Returns the channel from our input that will be sent to channel inputChannelIndex of
  78. our input audio source.
  79. */
  80. int getRemappedInputChannel (int inputChannelIndex) const;
  81. /** Returns the output channel to which channel outputChannelIndex of our input audio
  82. source will be sent to.
  83. */
  84. int getRemappedOutputChannel (int outputChannelIndex) const;
  85. //==============================================================================
  86. /** Returns an XML object to encapsulate the state of the mappings.
  87. @see restoreFromXml
  88. */
  89. XmlElement* createXml() const;
  90. /** Restores the mappings from an XML object created by createXML().
  91. @see createXml
  92. */
  93. void restoreFromXml (const XmlElement& e);
  94. //==============================================================================
  95. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  96. void releaseResources();
  97. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  98. private:
  99. //==============================================================================
  100. OptionalScopedPointer<AudioSource> source;
  101. Array <int> remappedInputs, remappedOutputs;
  102. int requiredNumberOfChannels;
  103. AudioSampleBuffer buffer;
  104. AudioSourceChannelInfo remappedInfo;
  105. CriticalSection lock;
  106. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChannelRemappingAudioSource)
  107. };
  108. #endif // __JUCE_CHANNELREMAPPINGAUDIOSOURCE_JUCEHEADER__