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.

184 lines
9.2KB

  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. const char* AudioChannelSet::getChannelTypeName (AudioChannelSet::ChannelType type) noexcept
  22. {
  23. switch (type)
  24. {
  25. case left: return NEEDS_TRANS("Left");
  26. case right: return NEEDS_TRANS("Right");
  27. case centre: return NEEDS_TRANS("Centre");
  28. case subbass: return NEEDS_TRANS("Subbass");
  29. case surroundLeft: return NEEDS_TRANS("Left Surround");
  30. case surroundRight: return NEEDS_TRANS("Right Surround");
  31. case centreLeft: return NEEDS_TRANS("Centre Left");
  32. case centreRight: return NEEDS_TRANS("Centre Right");
  33. case surround: return NEEDS_TRANS("Surround");
  34. case sideLeft: return NEEDS_TRANS("Side Left");
  35. case sideRight: return NEEDS_TRANS("Side Right");
  36. case topMiddle: return NEEDS_TRANS("Top Middle");
  37. case topFrontLeft: return NEEDS_TRANS("Top Front Left");
  38. case topFrontCentre: return NEEDS_TRANS("Top Front Centre");
  39. case topFrontRight: return NEEDS_TRANS("Top Front Right");
  40. case topRearLeft: return NEEDS_TRANS("Top Rear Left");
  41. case topRearCentre: return NEEDS_TRANS("Top Rear Centre");
  42. case topRearRight: return NEEDS_TRANS("Top Rear Right");
  43. case wideLeft: return NEEDS_TRANS("Wide Left");
  44. case wideRight: return NEEDS_TRANS("Wide Right");
  45. case subbass2: return NEEDS_TRANS("Subbass 2");
  46. case ambisonicW: return NEEDS_TRANS("Ambisonic W");
  47. case ambisonicX: return NEEDS_TRANS("Ambisonic X");
  48. case ambisonicY: return NEEDS_TRANS("Ambisonic Y");
  49. case ambisonicZ: return NEEDS_TRANS("Ambisonic Z");
  50. default: break;
  51. }
  52. return "Unknown";
  53. }
  54. const char* AudioChannelSet::getAbbreviatedChannelTypeName (AudioChannelSet::ChannelType type) noexcept
  55. {
  56. switch (type)
  57. {
  58. case left: return "L";
  59. case right: return "R";
  60. case centre: return "C";
  61. case subbass: return "Lfe";
  62. case surroundLeft: return "Ls";
  63. case surroundRight: return "Rs";
  64. case centreLeft: return "Lc";
  65. case centreRight: return "Rc";
  66. case surround: return "S";
  67. case sideLeft: return "Sl";
  68. case sideRight: return "Sr";
  69. case topMiddle: return "Tm";
  70. case topFrontLeft: return "Tfl";
  71. case topFrontCentre: return "Tfc";
  72. case topFrontRight: return "Tfr";
  73. case topRearLeft: return "Trl";
  74. case topRearCentre: return "Trc";
  75. case topRearRight: return "Trr";
  76. case wideLeft: return "Wl";
  77. case wideRight: return "Wr";
  78. case subbass2: return "Lfe2";
  79. case ambisonicW: return "W";
  80. case ambisonicX: return "X";
  81. case ambisonicY: return "Y";
  82. case ambisonicZ: return "Z";
  83. default: break;
  84. }
  85. return "";
  86. }
  87. String AudioChannelSet::getSpeakerArrangementAsString() const
  88. {
  89. StringArray speakerTypes;
  90. Array<AudioChannelSet::ChannelType> speakers = getChannelTypes();
  91. for (int i = 0; i < speakers.size(); ++i)
  92. {
  93. String name = getAbbreviatedChannelTypeName (speakers.getReference (i));
  94. if (name.isNotEmpty())
  95. speakerTypes.add (name);
  96. }
  97. return speakerTypes.joinIntoString (" ");
  98. }
  99. int AudioChannelSet::size() const noexcept
  100. {
  101. return channels.countNumberOfSetBits();
  102. }
  103. AudioChannelSet::ChannelType AudioChannelSet::getTypeOfChannel (int index) const noexcept
  104. {
  105. int bit = channels.findNextSetBit(0);
  106. for (int i = 0; i < index && bit >= 0; ++i)
  107. bit = channels.findNextSetBit (bit + 1);
  108. return static_cast<ChannelType> (bit);
  109. }
  110. Array<AudioChannelSet::ChannelType> AudioChannelSet::getChannelTypes() const
  111. {
  112. Array<ChannelType> result;
  113. for (int bit = channels.findNextSetBit(0); bit >= 0; bit = channels.findNextSetBit (bit + 1))
  114. result.add (static_cast<ChannelType> (bit));
  115. return result;
  116. }
  117. void AudioChannelSet::addChannel (ChannelType newChannel)
  118. {
  119. const int bit = static_cast<int> (newChannel);
  120. jassert (bit >= 0 && bit < 1024);
  121. channels.setBit (bit);
  122. }
  123. AudioChannelSet AudioChannelSet::disabled() { return AudioChannelSet(); }
  124. AudioChannelSet AudioChannelSet::mono() { return AudioChannelSet (1u << centre); }
  125. AudioChannelSet AudioChannelSet::stereo() { return AudioChannelSet ((1u << left) | (1u << right)); }
  126. AudioChannelSet AudioChannelSet::createLCR() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre)); }
  127. AudioChannelSet AudioChannelSet::createLCRS() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << surround)); }
  128. AudioChannelSet AudioChannelSet::quadraphonic() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << sideLeft) | (1u << sideRight)); }
  129. AudioChannelSet AudioChannelSet::pentagonal() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << sideLeft) | (1u << sideRight) | (1u << centre)); }
  130. AudioChannelSet AudioChannelSet::hexagonal() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << sideLeft) | (1u << sideRight) | (1u << centre) | (1u << surround)); }
  131. AudioChannelSet AudioChannelSet::octagonal() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << sideLeft) | (1u << sideRight) | (1u << centre) | (1u << surround) | (1u << wideLeft) | (1u << wideRight)); }
  132. AudioChannelSet AudioChannelSet::ambisonic() { return AudioChannelSet ((1u << ambisonicW) | (1u << ambisonicX) | (1u << ambisonicY) | (1u << ambisonicZ)); }
  133. AudioChannelSet AudioChannelSet::create5point0() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << surroundLeft) | (1u << surroundRight)); }
  134. AudioChannelSet AudioChannelSet::create5point1() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << subbass) | (1u << surroundLeft) | (1u << surroundRight)); }
  135. AudioChannelSet AudioChannelSet::create6point0() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << surroundLeft) | (1u << surroundRight) | (1u << surround)); }
  136. AudioChannelSet AudioChannelSet::create6point1() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << subbass) | (1u << surroundLeft) | (1u << surroundRight) | (1u << surround)); }
  137. AudioChannelSet AudioChannelSet::create7point0() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << surroundLeft) | (1u << surroundRight) | (1u << topRearLeft) | (1u << topRearRight)); }
  138. AudioChannelSet AudioChannelSet::create7point1() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << subbass) | (1u << surroundLeft) | (1u << surroundRight) | (1u << topRearLeft) | (1u << topRearRight)); }
  139. AudioChannelSet AudioChannelSet::createFront7point0() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << surroundLeft) | (1u << surroundRight) | (1u << centreLeft) | (1u << centreRight)); }
  140. AudioChannelSet AudioChannelSet::createFront7point1() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre) | (1u << subbass) | (1u << surroundLeft) | (1u << surroundRight) | (1u << centreLeft) | (1u << centreRight)); }
  141. AudioChannelSet AudioChannelSet::discreteChannels (int numChannels)
  142. {
  143. AudioChannelSet s;
  144. s.channels.setRange (discreteChannel0, numChannels, true);
  145. return s;
  146. }
  147. AudioChannelSet AudioChannelSet::canonicalChannelSet (int numChannels)
  148. {
  149. if (numChannels == 1) return AudioChannelSet::mono();
  150. if (numChannels == 2) return AudioChannelSet::stereo();
  151. if (numChannels == 4) return AudioChannelSet::quadraphonic();
  152. return discreteChannels (numChannels);
  153. }