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.

150 lines
6.2KB

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