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.

146 lines
6.3KB

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