ChannelRequests.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Copyright 2025, Ableton AG, Berlin. All rights reserved.
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * If you would like to incorporate Link into a proprietary software application,
  17. * please contact <link-devs@ableton.com>.
  18. */
  19. #pragma once
  20. #include <ableton/discovery/NetworkByteStreamSerializable.hpp>
  21. #include <ableton/discovery/Payload.hpp>
  22. #include <ableton/link_audio/ChannelId.hpp>
  23. namespace ableton
  24. {
  25. namespace link_audio
  26. {
  27. struct ChannelRequest
  28. {
  29. using Payload = decltype(discovery::makePayload(ChannelId{}));
  30. friend bool operator==(const ChannelRequest& lhs, const ChannelRequest& rhs)
  31. {
  32. return std::tie(lhs.peerId, lhs.channelId) == std::tie(rhs.peerId, rhs.channelId);
  33. }
  34. friend Payload toPayload(const ChannelRequest& request)
  35. {
  36. return discovery::makePayload(ChannelId{request.channelId});
  37. }
  38. template <typename It>
  39. static ChannelRequest fromPayload(Id peerId, It begin, It end)
  40. {
  41. using namespace std;
  42. auto request = ChannelRequest{std::move(peerId)};
  43. discovery::parsePayload<ChannelId>(std::move(begin),
  44. std::move(end),
  45. [&request](ChannelId cid)
  46. { request.channelId = std::move(cid.id); });
  47. return request;
  48. }
  49. Id peerId;
  50. Id channelId;
  51. };
  52. struct ChannelStopRequest
  53. {
  54. using Payload = decltype(discovery::makePayload(ChannelId{}));
  55. friend bool operator==(const ChannelStopRequest& lhs, const ChannelStopRequest& rhs)
  56. {
  57. return std::tie(lhs.peerId, lhs.channelId) == std::tie(rhs.peerId, rhs.channelId);
  58. }
  59. friend Payload toPayload(const ChannelStopRequest& request)
  60. {
  61. return discovery::makePayload(ChannelId{request.channelId});
  62. }
  63. template <typename It>
  64. static ChannelStopRequest fromPayload(Id peerId, It begin, It end)
  65. {
  66. using namespace std;
  67. auto request = ChannelStopRequest{std::move(peerId), {}};
  68. discovery::parsePayload<ChannelId>(std::move(begin),
  69. std::move(end),
  70. [&request](ChannelId cid)
  71. { request.channelId = std::move(cid.id); });
  72. return request;
  73. }
  74. Id peerId;
  75. Id channelId;
  76. };
  77. } // namespace link_audio
  78. } // namespace ableton