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.

113 lines
3.8KB

  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. Acting as a ResponderListener, instances of this class can formulate
  22. appropriate replies to profile transactions initiated by remote devices.
  23. ProfileHost instances also contains methods to inform remote devices about
  24. changes to local profile state.
  25. Stores the current state of profiles on the local device.
  26. @tags{Audio}
  27. */
  28. class ProfileHost final : public ResponderDelegate
  29. {
  30. public:
  31. /** @internal
  32. Rather than constructing one of these objects yourself, you should configure
  33. a Device with profile support, and then use Device::getProfileHost()
  34. to retrieve a profile host that has been set up to work with that device.
  35. */
  36. ProfileHost (FunctionBlock fb, ProfileDelegate& d, BufferOutput& o)
  37. : functionBlock (fb), delegate (d), output (o) {}
  38. /** Adds support for a profile on the specified group/channel with a
  39. maximum number of channels that may be activated.
  40. */
  41. void addProfile (ProfileAtAddress, int maxNumChannels = 1);
  42. /** Removes support for a profile on the specified group/channel.
  43. */
  44. void removeProfile (ProfileAtAddress);
  45. /** Activates a profile on the specified group/channel with the provided
  46. number of channels.
  47. The profile should previously have been added with addProfile(), and
  48. numChannels should be in the closed range between 1 and the maximum
  49. number of channels allowed for that profile.
  50. */
  51. void enableProfile (ProfileAtAddress, int numChannels);
  52. /** Deactivates a profile on the specified group/channel.
  53. */
  54. void disableProfile (ProfileAtAddress);
  55. /** Returns the profile states (supported/active) for all groups and channels.
  56. */
  57. const BlockProfileStates& getProfileStates() const { return states; }
  58. /** Returns the number of supported and active channels for the given
  59. profile on the specified group/channel.
  60. If the supported channels is 0, then the profile is not supported
  61. on the group/channel.
  62. If the active channels is 0, then the profile is inactive on the
  63. group/channel.
  64. */
  65. SupportedAndActive getState (ProfileAtAddress profileAtAddress) const
  66. {
  67. if (auto* state = states.getStateForDestination (profileAtAddress.address))
  68. return state->get (profileAtAddress.profile);
  69. return {};
  70. }
  71. /** @internal */
  72. bool tryRespond (ResponderOutput&, const Message::Parsed&) override;
  73. private:
  74. class Visitor;
  75. template <typename Body>
  76. bool profileEnablementReceived (ResponderOutput&, const Body&);
  77. FunctionBlock functionBlock;
  78. ProfileDelegate& delegate;
  79. BufferOutput& output;
  80. BlockProfileStates states;
  81. bool isResponder = false;
  82. std::optional<ProfileAtAddress> currentEnablementMessage;
  83. };
  84. } // namespace juce::midi_ci