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.

84 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce::midi_ci
  19. {
  20. /**
  21. Identifies a channel or set of channels in a multi-group MIDI endpoint.
  22. @tags{Audio}
  23. */
  24. class ChannelAddress
  25. {
  26. private:
  27. uint8_t group{}; ///< A group within a MIDI endpoint, where 0 <= group && group < 16
  28. ChannelInGroup channel{}; ///< A set of channels related to specified group
  29. auto tie() const { return std::tie (group, channel); }
  30. public:
  31. /** Returns a copy of this object with the specified group. */
  32. [[nodiscard]] ChannelAddress withGroup (int g) const
  33. {
  34. jassert (isPositiveAndBelow (g, 16));
  35. return withMember (*this, &ChannelAddress::group, (uint8_t) g);
  36. }
  37. /** Returns a copy of this object with the specified channel. */
  38. [[nodiscard]] ChannelAddress withChannel (ChannelInGroup c) const
  39. {
  40. return withMember (*this, &ChannelAddress::channel, c);
  41. }
  42. /** Returns the group. */
  43. [[nodiscard]] uint8_t getGroup() const { return group; }
  44. /** Returns the channel in the group. */
  45. [[nodiscard]] ChannelInGroup getChannel() const { return channel; }
  46. /** Returns true if this address refers to all channels in the function
  47. block containing the specified group.
  48. */
  49. bool isBlock() const { return channel == ChannelInGroup::wholeBlock; }
  50. /** Returns true if this address refers to all channels in the specified
  51. group.
  52. */
  53. bool isGroup() const { return channel == ChannelInGroup::wholeGroup; }
  54. /** Returns true if this address refers to a single channel. */
  55. bool isSingleChannel() const { return ! isBlock() && ! isGroup(); }
  56. bool operator< (const ChannelAddress& other) const { return tie() < other.tie(); }
  57. bool operator<= (const ChannelAddress& other) const { return tie() <= other.tie(); }
  58. bool operator> (const ChannelAddress& other) const { return tie() > other.tie(); }
  59. bool operator>= (const ChannelAddress& other) const { return tie() >= other.tie(); }
  60. bool operator== (const ChannelAddress& other) const { return tie() == other.tie(); }
  61. bool operator!= (const ChannelAddress& other) const { return ! operator== (other); }
  62. };
  63. } // namespace juce::midi_ci