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.

363 lines
15KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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. #pragma once
  18. //==============================================================================
  19. /**
  20. Represents a set of audio channel types.
  21. For example, you might have a set of left + right channels, which is a stereo
  22. channel set. It is a collection of values from the AudioChannelSet::ChannelType
  23. enum, where each type may only occur once within the set.
  24. The documentation below lists which AudioChannelSet corresponds to which native
  25. layouts used by AAX, VST2/VST3 and CoreAudio/AU. The layout tags in CoreAudio
  26. are particularly confusing. For example, the layout which is labeled as "7.1 SDDS"
  27. in Logic Pro, corresponds to CoreAudio/AU's kAudioChannelLayoutTag_DTS_7_0 tag, whereas
  28. AAX's DTS 7.1 Layout corresponds to CoreAudio/AU's
  29. kAudioChannelLayoutTag_MPEG_7_1_A format, etc. Please do not use the CoreAudio tag
  30. as an indication to the actual layout of the speakers.
  31. @see Bus
  32. */
  33. class JUCE_API AudioChannelSet
  34. {
  35. public:
  36. /** Creates an empty channel set.
  37. You can call addChannel to add channels to the set.
  38. */
  39. AudioChannelSet() noexcept {}
  40. /** Creates a zero-channel set which can be used to indicate that a
  41. bus is disabled. */
  42. static AudioChannelSet JUCE_CALLTYPE disabled();
  43. //==============================================================================
  44. /** Creates a one-channel mono set (centre).
  45. Is equivalent to: kMonoAAX (VST), AAX_eStemFormat_Mono (AAX), kAudioChannelLayoutTag_Mono (CoreAudio)
  46. */
  47. static AudioChannelSet JUCE_CALLTYPE mono();
  48. /** Creates a set containing a stereo set (left, right).
  49. Is equivalent to: kStereo (VST), AAX_eStemFormat_Stereo (AAX), kAudioChannelLayoutTag_Stereo (CoreAudio)
  50. */
  51. static AudioChannelSet JUCE_CALLTYPE stereo();
  52. //==============================================================================
  53. /** Creates a set containing an LCR set (left, right, centre).
  54. Is equivalent to: k30Cine (VST), AAX_eStemFormat_LCR (AAX), kAudioChannelLayoutTag_MPEG_3_0_A (CoreAudio)
  55. This format is referred to as "LRC" in Cubase.
  56. This format is referred to as "LCR" in Pro Tools.
  57. */
  58. static AudioChannelSet JUCE_CALLTYPE createLCR();
  59. /** Creates a set containing an LRS set (left, right, surround).
  60. Is equivalent to: k30Music (VST), n/a (AAX), kAudioChannelLayoutTag_ITU_2_1 (CoreAudio)
  61. This format is referred to as "LRS" in Cubase.
  62. */
  63. static AudioChannelSet JUCE_CALLTYPE createLRS();
  64. /** Creates a set containing an LCRS set (left, right, centre, surround).
  65. Is equivalent to: k40Cine (VST), AAX_eStemFormat_LCRS (AAX), kAudioChannelLayoutTag_MPEG_4_0_A (CoreAudio)
  66. This format is referred to as "LCRS (Pro Logic)" in Logic Pro.
  67. This format is referred to as "LRCS" in Cubase.
  68. This format is referred to as "LCRS" in Pro Tools.
  69. */
  70. static AudioChannelSet JUCE_CALLTYPE createLCRS();
  71. //==============================================================================
  72. /** Creates a set for a 5.0 surround setup (left, right, centre, leftSurround, rightSurround).
  73. Is equivalent to: k50 (VST), AAX_eStemFormat_5_0 (AAX), kAudioChannelLayoutTag_MPEG_5_0_A (CoreAudio)
  74. This format is referred to as "5.0" in Cubase.
  75. This format is referred to as "5.0" in Pro Tools.
  76. */
  77. static AudioChannelSet JUCE_CALLTYPE create5point0();
  78. /** Creates a set for a 5.1 surround setup (left, right, centre, leftSurround, rightSurround, LFE).
  79. Is equivalent to: k51 (VST), AAX_eStemFormat_5_1 (AAX), kAudioChannelLayoutTag_MPEG_5_1_A (CoreAudio)
  80. This format is referred to as "5.1 (ITU 775)" in Logic Pro.
  81. This format is referred to as "5.1" in Cubase.
  82. This format is referred to as "5.1" in Pro Tools.
  83. */
  84. static AudioChannelSet JUCE_CALLTYPE create5point1();
  85. /** Creates a set for a 6.0 Cine surround setup (left, right, centre, leftSurround, rightSurround, centreSurround).
  86. Is equivalent to: k60Cine (VST), AAX_eStemFormat_6_0 (AAX), kAudioChannelLayoutTag_AudioUnit_6_0 (CoreAudio)
  87. Logic Pro incorrectly uses this for the surround format labeled "6.1 (ES/EX)".
  88. This format is referred to as "6.0 Cine" in Cubase.
  89. This format is referred to as "6.0" in Pro Tools.
  90. */
  91. static AudioChannelSet JUCE_CALLTYPE create6point0();
  92. /** Creates a set for a 6.1 Cine surround setup (left, right, centre, leftSurround, rightSurround, centreSurround, LFE).
  93. Is equivalent to: k61Cine (VST), AAX_eStemFormat_6_1 (AAX), kAudioChannelLayoutTag_MPEG_6_1_A (CoreAudio)
  94. This format is referred to as "6.1" in Pro Tools.
  95. */
  96. static AudioChannelSet JUCE_CALLTYPE create6point1();
  97. /** Creates a set for a 6.0 Music surround setup (left, right, leftSurround, rightSurround, leftSurroundSide, rightSurroundSide).
  98. Is equivalent to: k60Music (VST), n/a (AAX), kAudioChannelLayoutTag_DTS_6_0_A (CoreAudio)
  99. This format is referred to as "6.0 Music" in Cubase.
  100. */
  101. static AudioChannelSet JUCE_CALLTYPE create6point0Music();
  102. /** Creates a set for a 6.0 Music surround setup (left, right, leftSurround, rightSurround, leftSurroundSide, rightSurroundSide, LFE).
  103. Is equivalent to: k61Music (VST), n/a (AAX), kAudioChannelLayoutTag_DTS_6_1_A (CoreAudio)
  104. */
  105. static AudioChannelSet JUCE_CALLTYPE create6point1Music();
  106. /** Creates a set for a DTS 7.0 surround setup (left, right, centre, leftSurroundSide, rightSurroundSide, leftSurroundRear, rightSurroundRear).
  107. Is equivalent to: k70Music (VST), AAX_eStemFormat_7_0_DTS (AAX), kAudioChannelLayoutTag_AudioUnit_7_0 (CoreAudio)
  108. This format is referred to as "7.0" in Pro Tools.
  109. */
  110. static AudioChannelSet JUCE_CALLTYPE create7point0();
  111. /** Creates a set for a SDDS 7.0 surround setup (left, right, centre, leftSurround, rightSurround, leftCentre, rightCentre).
  112. Is equivalent to: k70Cine (VST), AAX_eStemFormat_7_0_SDDS (AAX), kAudioChannelLayoutTag_AudioUnit_7_0_Front (CoreAudio)
  113. This format is referred to as "7.0 SDDS" in Pro Tools.
  114. */
  115. static AudioChannelSet JUCE_CALLTYPE create7point0SDDS();
  116. /** Creates a set for a DTS 7.1 surround setup (left, right, centre, leftSurroundSide, rightSurroundSide, leftSurroundRear, rightSurroundRear, LFE).
  117. Is equivalent to: k71CineSideFill (VST), AAX_eStemFormat_7_1_DTS (AAX), kAudioChannelLayoutTag_MPEG_7_1_C/kAudioChannelLayoutTag_ITU_3_4_1 (CoreAudio)
  118. This format is referred to as "7.1 (3/4.1)" in Logic Pro.
  119. This format is referred to as "7.1" in Pro Tools.
  120. */
  121. static AudioChannelSet JUCE_CALLTYPE create7point1();
  122. /** Creates a set for a 7.1 surround setup (left, right, centre, leftSurround, rightSurround, leftCentre, rightCentre, LFE).
  123. Is equivalent to: k71Cine (VST), AAX_eStemFormat_7_1_SDDS (AAX), kAudioChannelLayoutTag_MPEG_7_1_A (CoreAudio)
  124. This format is referred to as "7.1 (SDDS)" in Logic Pro.
  125. This format is referred to as "7.1 SDDS" in Pro Tools.
  126. */
  127. static AudioChannelSet JUCE_CALLTYPE create7point1SDDS();
  128. //==============================================================================
  129. /** Creates a set for ambisonic surround setups (ambisonicW, ambisonicX, ambisonicY, ambisonicZ).
  130. Is equivalent to: kBFormat (VST), n/a (AAX), kAudioChannelLayoutTag_Ambisonic_B_Format (CoreAudio)
  131. */
  132. static AudioChannelSet JUCE_CALLTYPE ambisonic();
  133. /** Creates a set for quadraphonic surround setup (left, right, leftSurround, rightSurround)
  134. Is equivalent to: k40Music (VST), AAX_eStemFormat_Quad (AAX), kAudioChannelLayoutTag_Quadraphonic (CoreAudio)
  135. This format is referred to as "Quadraphonic" in Logic Pro.
  136. This format is referred to as "Quadro" in Cubase.
  137. This format is referred to as "Quad" in Pro Tools.
  138. */
  139. static AudioChannelSet JUCE_CALLTYPE quadraphonic();
  140. /** Creates a set for pentagonal surround setup (left, right, centre, leftSurroundRear, rightSurroundRear).
  141. Is equivalent to: n/a (VST), n/a (AAX), kAudioChannelLayoutTag_Pentagonal (CoreAudio)
  142. */
  143. static AudioChannelSet JUCE_CALLTYPE pentagonal();
  144. /** Creates a set for hexagonal surround setup (left, right, leftSurroundRear, rightSurroundRear, centre, surroundCentre).
  145. Is equivalent to: n/a (VST), n/a (AAX), kAudioChannelLayoutTag_Hexagonal (CoreAudio)
  146. */
  147. static AudioChannelSet JUCE_CALLTYPE hexagonal();
  148. /** Creates a set for octagonal surround setup (left, right, leftSurround, rightSurround, centre, centreSurround, wideLeft, wideRight).
  149. Is equivalent to: n/a (VST), n/a (AAX), kAudioChannelLayoutTag_Octagonal (CoreAudio)
  150. */
  151. static AudioChannelSet JUCE_CALLTYPE octagonal();
  152. //==============================================================================
  153. /** Creates a set of untyped discrete channels. */
  154. static AudioChannelSet JUCE_CALLTYPE discreteChannels (int numChannels);
  155. /** Create a canonical channel set for a given number of channels.
  156. For example, numChannels = 1 will return mono, numChannels = 2 will return stereo, etc. */
  157. static AudioChannelSet JUCE_CALLTYPE canonicalChannelSet (int numChannels);
  158. /** Create a channel set for a given number of channels which is non-discrete.
  159. If numChannels is larger than the number of channels of the surround format
  160. with the maximum amount of channels (currently 7.1 Surround), then this
  161. function returns an empty set.*/
  162. static AudioChannelSet JUCE_CALLTYPE namedChannelSet (int numChannels);
  163. /** Return an array of channel sets which have a given number of channels */
  164. static Array<AudioChannelSet> JUCE_CALLTYPE channelSetsWithNumberOfChannels (int numChannels);
  165. //==============================================================================
  166. /** Represents different audio channel types. */
  167. enum ChannelType
  168. {
  169. unknown = 0,
  170. left = 1, // L
  171. right = 2, // R
  172. centre = 3, // C (sometimes M for mono)
  173. LFE = 4,
  174. leftSurround = 5, // Ls
  175. rightSurround = 6, // Rs
  176. leftCentre = 7, // Lc (AAX/VST), Lc used as Lss in AU for most layouts
  177. rightCentre = 8, // Rc (AAX/VST), Rc used as Rss in AU for most layouts
  178. centreSurround = 9, // Cs/S
  179. surround = centreSurround, // Cs/S
  180. leftSurroundSide = 10, // Lss (AXX), Side Left "Sl" (VST), Left Centre "LC" (AU)
  181. rightSurroundSide = 11, // Rss (AXX), Side right "Sr" (VST), Right Centre "Rc" (AU)
  182. topMiddle = 12,
  183. topFrontLeft = 13,
  184. topFrontCentre = 14,
  185. topFrontRight = 15,
  186. topRearLeft = 16,
  187. topRearCentre = 17,
  188. topRearRight = 18,
  189. LFE2 = 19,
  190. leftSurroundRear = 20, // Lsr (AAX), Lcs (VST), Rls (AU)
  191. rightSurroundRear = 21, // Rsr (AAX), Rcs (VST), Rrs (AU)
  192. wideLeft = 22,
  193. wideRight = 23,
  194. ambisonicW = 24,
  195. ambisonicX = 25,
  196. ambisonicY = 26,
  197. ambisonicZ = 27,
  198. discreteChannel0 = 64 /**< Non-typed individual channels are indexed upwards from this value. */
  199. };
  200. /** Returns the name of a given channel type. For example, this method may return "Surround Left". */
  201. static String JUCE_CALLTYPE getChannelTypeName (ChannelType);
  202. /** Returns the abbreviated name of a channel type. For example, this method may return "Ls". */
  203. static String JUCE_CALLTYPE getAbbreviatedChannelTypeName (ChannelType);
  204. /** Returns the channel type from an abbreviated name. */
  205. static ChannelType JUCE_CALLTYPE getChannelTypeFromAbbreviation (const String& abbreviation);
  206. //==============================================================================
  207. enum
  208. {
  209. maxChannelsOfNamedLayout = 8
  210. };
  211. /** Adds a channel to the set. */
  212. void addChannel (ChannelType newChannelType);
  213. /** Removes a channel from the set. */
  214. void removeChannel (ChannelType newChannelType);
  215. /** Returns the number of channels in the set. */
  216. int size() const noexcept;
  217. /** Returns true if there are no channels in the set. */
  218. bool isDisabled() const noexcept { return size() == 0; }
  219. /** Returns an array of all the types in this channel set. */
  220. Array<ChannelType> getChannelTypes() const;
  221. /** Returns the type of one of the channels in the set, by index. */
  222. ChannelType getTypeOfChannel (int channelIndex) const noexcept;
  223. /** Returns the index for a particular channel-type.
  224. Will return -1 if the this set does not contain a channel of this type. */
  225. int getChannelIndexForType (ChannelType type) const noexcept;
  226. /** Returns a string containing a whitespace-separated list of speaker types
  227. corresponding to each channel. For example in a 5.1 arrangement,
  228. the string may be "L R C Lfe Ls Rs". If the speaker arrangement is unknown,
  229. the returned string will be empty.*/
  230. String getSpeakerArrangementAsString() const;
  231. /** Returns an AudioChannelSet from a string returned by getSpeakerArrangementAsString
  232. @see getSpeakerArrangementAsString */
  233. static AudioChannelSet fromAbbreviatedString (const String& set);
  234. /** Returns the description of the current layout. For example, this method may return
  235. "Quadraphonic". Note that the returned string may not be unique. */
  236. String getDescription() const;
  237. /** Returns if this is a channel layout made-up of discrete channels. */
  238. bool isDiscreteLayout() const noexcept;
  239. /** Intersect two channel layouts. */
  240. void intersect (const AudioChannelSet& other) { channels &= other.channels; }
  241. //==============================================================================
  242. bool operator== (const AudioChannelSet&) const noexcept;
  243. bool operator!= (const AudioChannelSet&) const noexcept;
  244. bool operator< (const AudioChannelSet&) const noexcept;
  245. private:
  246. BigInteger channels;
  247. explicit AudioChannelSet (uint32);
  248. };