Audio plugin host https://kx.studio/carla
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.

409 lines
18KB

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