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

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_CHANNELREMAPPINGAUDIOSOURCE_H_INCLUDED
  24. #define JUCE_CHANNELREMAPPINGAUDIOSOURCE_H_INCLUDED
  25. //==============================================================================
  26. /**
  27. An AudioSource that takes the audio from another source, and re-maps its
  28. input and output channels to a different arrangement.
  29. You can use this to increase or decrease the number of channels that an
  30. audio source uses, or to re-order those channels.
  31. Call the reset() method before using it to set up a default mapping, and then
  32. the setInputChannelMapping() and setOutputChannelMapping() methods to
  33. create an appropriate mapping, otherwise no channels will be connected and
  34. it'll produce silence.
  35. @see AudioSource
  36. */
  37. class ChannelRemappingAudioSource : public AudioSource
  38. {
  39. public:
  40. //==============================================================================
  41. /** Creates a remapping source that will pass on audio from the given input.
  42. @param source the input source to use. Make sure that this doesn't
  43. get deleted before the ChannelRemappingAudioSource object
  44. @param deleteSourceWhenDeleted if true, the input source will be deleted
  45. when this object is deleted, if false, the caller is
  46. responsible for its deletion
  47. */
  48. ChannelRemappingAudioSource (AudioSource* source,
  49. bool deleteSourceWhenDeleted);
  50. /** Destructor. */
  51. ~ChannelRemappingAudioSource();
  52. //==============================================================================
  53. /** Specifies a number of channels that this audio source must produce from its
  54. getNextAudioBlock() callback.
  55. */
  56. void setNumberOfChannelsToProduce (int requiredNumberOfChannels);
  57. /** Clears any mapped channels.
  58. After this, no channels are mapped, so this object will produce silence. Create
  59. some mappings with setInputChannelMapping() and setOutputChannelMapping().
  60. */
  61. void clearAllMappings();
  62. /** Creates an input channel mapping.
  63. When the getNextAudioBlock() method is called, the data in channel sourceChannelIndex of the incoming
  64. data will be sent to destChannelIndex of our input source.
  65. @param destChannelIndex the index of an input channel in our input audio source (i.e. the
  66. source specified when this object was created).
  67. @param sourceChannelIndex the index of the input channel in the incoming audio data buffer
  68. during our getNextAudioBlock() callback
  69. */
  70. void setInputChannelMapping (int destChannelIndex,
  71. int sourceChannelIndex);
  72. /** Creates an output channel mapping.
  73. When the getNextAudioBlock() method is called, the data returned in channel sourceChannelIndex by
  74. our input audio source will be copied to channel destChannelIndex of the final buffer.
  75. @param sourceChannelIndex the index of an output channel coming from our input audio source
  76. (i.e. the source specified when this object was created).
  77. @param destChannelIndex the index of the output channel in the incoming audio data buffer
  78. during our getNextAudioBlock() callback
  79. */
  80. void setOutputChannelMapping (int sourceChannelIndex,
  81. int destChannelIndex);
  82. /** Returns the channel from our input that will be sent to channel inputChannelIndex of
  83. our input audio source.
  84. */
  85. int getRemappedInputChannel (int inputChannelIndex) const;
  86. /** Returns the output channel to which channel outputChannelIndex of our input audio
  87. source will be sent to.
  88. */
  89. int getRemappedOutputChannel (int outputChannelIndex) const;
  90. //==============================================================================
  91. /** Returns an XML object to encapsulate the state of the mappings.
  92. @see restoreFromXml
  93. */
  94. XmlElement* createXml() const;
  95. /** Restores the mappings from an XML object created by createXML().
  96. @see createXml
  97. */
  98. void restoreFromXml (const XmlElement&);
  99. //==============================================================================
  100. void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
  101. void releaseResources() override;
  102. void getNextAudioBlock (const AudioSourceChannelInfo&) override;
  103. private:
  104. //==============================================================================
  105. OptionalScopedPointer<AudioSource> source;
  106. Array<int> remappedInputs, remappedOutputs;
  107. int requiredNumberOfChannels;
  108. AudioSampleBuffer buffer;
  109. AudioSourceChannelInfo remappedInfo;
  110. CriticalSection lock;
  111. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChannelRemappingAudioSource)
  112. };
  113. #endif // JUCE_CHANNELREMAPPINGAUDIOSOURCE_H_INCLUDED