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.

190 lines
9.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. AudioChannelSet::AudioChannelSet (uint32 c) : channels (c) {}
  18. bool AudioChannelSet::operator== (const AudioChannelSet& other) const noexcept { return channels == other.channels; }
  19. bool AudioChannelSet::operator!= (const AudioChannelSet& other) const noexcept { return channels != other.channels; }
  20. bool AudioChannelSet::operator< (const AudioChannelSet& other) const noexcept { return channels < other.channels; }
  21. String AudioChannelSet::getChannelTypeName (AudioChannelSet::ChannelType type)
  22. {
  23. if (type >= discreteChannel0)
  24. return String ("Discrete ") + String (type - discreteChannel0 + 1);
  25. switch (type)
  26. {
  27. case left: return NEEDS_TRANS("Left");
  28. case right: return NEEDS_TRANS("Right");
  29. case centre: return NEEDS_TRANS("Centre");
  30. case subbass: return NEEDS_TRANS("Subbass");
  31. case surroundLeft: return NEEDS_TRANS("Left Surround");
  32. case surroundRight: return NEEDS_TRANS("Right Surround");
  33. case centreLeft: return NEEDS_TRANS("Centre Left");
  34. case centreRight: return NEEDS_TRANS("Centre Right");
  35. case surround: return NEEDS_TRANS("Surround");
  36. case sideLeft: return NEEDS_TRANS("Side Left");
  37. case sideRight: return NEEDS_TRANS("Side Right");
  38. case topMiddle: return NEEDS_TRANS("Top Middle");
  39. case topFrontLeft: return NEEDS_TRANS("Top Front Left");
  40. case topFrontCentre: return NEEDS_TRANS("Top Front Centre");
  41. case topFrontRight: return NEEDS_TRANS("Top Front Right");
  42. case topRearLeft: return NEEDS_TRANS("Top Rear Left");
  43. case topRearCentre: return NEEDS_TRANS("Top Rear Centre");
  44. case topRearRight: return NEEDS_TRANS("Top Rear Right");
  45. case wideLeft: return NEEDS_TRANS("Wide Left");
  46. case wideRight: return NEEDS_TRANS("Wide Right");
  47. case subbass2: return NEEDS_TRANS("Subbass 2");
  48. case ambisonicW: return NEEDS_TRANS("Ambisonic W");
  49. case ambisonicX: return NEEDS_TRANS("Ambisonic X");
  50. case ambisonicY: return NEEDS_TRANS("Ambisonic Y");
  51. case ambisonicZ: return NEEDS_TRANS("Ambisonic Z");
  52. default: break;
  53. }
  54. return "Unknown";
  55. }
  56. String AudioChannelSet::getAbbreviatedChannelTypeName (AudioChannelSet::ChannelType type)
  57. {
  58. if (type >= discreteChannel0)
  59. return String (type - discreteChannel0 + 1);
  60. switch (type)
  61. {
  62. case left: return "L";
  63. case right: return "R";
  64. case centre: return "C";
  65. case subbass: return "Lfe";
  66. case surroundLeft: return "Ls";
  67. case surroundRight: return "Rs";
  68. case centreLeft: return "Lc";
  69. case centreRight: return "Rc";
  70. case surround: return "S";
  71. case sideLeft: return "Sl";
  72. case sideRight: return "Sr";
  73. case topMiddle: return "Tm";
  74. case topFrontLeft: return "Tfl";
  75. case topFrontCentre: return "Tfc";
  76. case topFrontRight: return "Tfr";
  77. case topRearLeft: return "Trl";
  78. case topRearCentre: return "Trc";
  79. case topRearRight: return "Trr";
  80. case wideLeft: return "Wl";
  81. case wideRight: return "Wr";
  82. case subbass2: return "Lfe2";
  83. case ambisonicW: return "W";
  84. case ambisonicX: return "X";
  85. case ambisonicY: return "Y";
  86. case ambisonicZ: return "Z";
  87. default: break;
  88. }
  89. return "";
  90. }
  91. String AudioChannelSet::getSpeakerArrangementAsString() const
  92. {
  93. StringArray speakerTypes;
  94. Array<AudioChannelSet::ChannelType> speakers = getChannelTypes();
  95. for (int i = 0; i < speakers.size(); ++i)
  96. {
  97. String name = getAbbreviatedChannelTypeName (speakers.getReference (i));
  98. if (name.isNotEmpty())
  99. speakerTypes.add (name);
  100. }
  101. return speakerTypes.joinIntoString (" ");
  102. }
  103. int AudioChannelSet::size() const noexcept
  104. {
  105. return channels.countNumberOfSetBits();
  106. }
  107. AudioChannelSet::ChannelType AudioChannelSet::getTypeOfChannel (int index) const noexcept
  108. {
  109. int bit = channels.findNextSetBit(0);
  110. for (int i = 0; i < index && bit >= 0; ++i)
  111. bit = channels.findNextSetBit (bit + 1);
  112. return static_cast<ChannelType> (bit);
  113. }
  114. Array<AudioChannelSet::ChannelType> AudioChannelSet::getChannelTypes() const
  115. {
  116. Array<ChannelType> result;
  117. for (int bit = channels.findNextSetBit(0); bit >= 0; bit = channels.findNextSetBit (bit + 1))
  118. result.add (static_cast<ChannelType> (bit));
  119. return result;
  120. }
  121. void AudioChannelSet::addChannel (ChannelType newChannel)
  122. {
  123. const int bit = static_cast<int> (newChannel);
  124. jassert (bit >= 0 && bit < 1024);
  125. channels.setBit (bit);
  126. }
  127. AudioChannelSet AudioChannelSet::disabled() { return AudioChannelSet(); }
  128. AudioChannelSet AudioChannelSet::mono() { return AudioChannelSet (1u << centre); }
  129. AudioChannelSet AudioChannelSet::stereo() { return AudioChannelSet ((1u << left) | (1u << right)); }
  130. AudioChannelSet AudioChannelSet::createLCR() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre)); }
  131. AudioChannelSet AudioChannelSet::createLCRS() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << surround)); }
  132. AudioChannelSet AudioChannelSet::quadraphonic() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << surroundLeft) | (1u << surroundRight)); }
  133. AudioChannelSet AudioChannelSet::pentagonal() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << surroundLeft) | (1u << surroundRight) | (1u << centre)); }
  134. AudioChannelSet AudioChannelSet::hexagonal() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << surroundLeft) | (1u << surroundRight) | (1u << centre) | (1u << surround)); }
  135. AudioChannelSet AudioChannelSet::octagonal() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << surroundLeft) | (1u << surroundRight) | (1u << centre) | (1u << surround) | (1u << wideLeft) | (1u << wideRight)); }
  136. AudioChannelSet AudioChannelSet::ambisonic() { return AudioChannelSet ((1u << ambisonicW) | (1u << ambisonicX) | (1u << ambisonicY) | (1u << ambisonicZ)); }
  137. AudioChannelSet AudioChannelSet::create5point0() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << surroundLeft) | (1u << surroundRight)); }
  138. AudioChannelSet AudioChannelSet::create5point1() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << subbass) | (1u << surroundLeft) | (1u << surroundRight)); }
  139. AudioChannelSet AudioChannelSet::create6point0() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << surroundLeft) | (1u << surroundRight) | (1u << surround)); }
  140. AudioChannelSet AudioChannelSet::create6point1() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << subbass) | (1u << surroundLeft) | (1u << surroundRight) | (1u << surround)); }
  141. AudioChannelSet AudioChannelSet::create7point0() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << surroundLeft) | (1u << surroundRight) | (1u << sideLeft) | (1u << sideRight)); }
  142. AudioChannelSet AudioChannelSet::create7point1() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << subbass) | (1u << surroundLeft) | (1u << surroundRight) | (1u << sideLeft) | (1u << sideRight)); }
  143. AudioChannelSet AudioChannelSet::createFront7point0() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << surroundLeft) | (1u << surroundRight) | (1u << centreLeft) | (1u << centreRight)); }
  144. AudioChannelSet AudioChannelSet::createFront7point1() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << subbass) | (1u << surroundLeft) | (1u << surroundRight) | (1u << centreLeft) | (1u << centreRight)); }
  145. AudioChannelSet AudioChannelSet::discreteChannels (int numChannels)
  146. {
  147. AudioChannelSet s;
  148. s.channels.setRange (discreteChannel0, numChannels, true);
  149. return s;
  150. }
  151. AudioChannelSet AudioChannelSet::canonicalChannelSet (int numChannels)
  152. {
  153. if (numChannels == 1) return AudioChannelSet::mono();
  154. if (numChannels == 2) return AudioChannelSet::stereo();
  155. if (numChannels == 4) return AudioChannelSet::quadraphonic();
  156. return discreteChannels (numChannels);
  157. }