/* Copyright 2025, Ableton AG, Berlin. All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * If you would like to incorporate Link into a proprietary software application, * please contact . */ #pragma once #include #include namespace ableton { namespace link_audio { template class SessionController : public Controller> { public: using LinkAudioController = Controller>; SessionController(link::Tempo tempo, PeerCountCallback peerCallback, TempoCallback tempoCallback, StartStopStateCallback startStopStateCallback, Clock clock) : LinkAudioController( tempo, peerCallback, tempoCallback, startStopStateCallback, clock) { this->mRtClientStateSetter.start(); } ~SessionController() { this->mIo->async([this]() { this->stopAudio(); }); this->shutdown(); } void sessionMembershipCallback() { this->mSessionPeerCounter(); this->updateLinkAudio(); } void joinSessionCallback(const link::Session& session) { this->joinSession(session); this->updateLinkAudio(); } template void measurePeerCallback(Peer peer, Handler handler) { this->measurePeer(std::move(peer), std::move(handler)); } void updateDiscoveryCallback() { this->updateDiscovery(); this->updateAudioDiscovery(); } void gatewaysChangedCallback() { this->updateLinkAudioGateways(); } void updateRtStatesCallback() { // Process the pending client states first to make sure we don't push one // after we have joined a running session when enabling this->mRtClientStateSetter.processPendingClientStates(); this->mRtClientStateSetter.updateEnabled(); this->updateIsLinkAudioEnabled(); } void sawAudioEndpointCallback(Id peerId, std::optional endpoint, discovery::IpAddress gateway) { this->sawLinkAudioEndpoint(peerId, endpoint, gateway); } }; } // namespace link_audio } // namespace ableton