#pragma once
#include <ableton/link_audio/Controller.hpp>
#include <ableton/link_audio/Id.hpp>
namespace ableton
{
namespace link_audio
{
template <typename PeerCountCallback,
typename TempoCallback,
typename StartStopStateCallback,
typename Clock,
typename Random,
typename IoContext>
class SessionController : public Controller<PeerCountCallback,
TempoCallback,
StartStopStateCallback,
Clock,
Random,
IoContext,
SessionController<PeerCountCallback,
TempoCallback,
StartStopStateCallback,
Clock,
Random,
IoContext>>
{
public:
using LinkAudioController = Controller<PeerCountCallback,
TempoCallback,
StartStopStateCallback,
Clock,
Random,
IoContext,
SessionController<PeerCountCallback,
TempoCallback,
StartStopStateCallback,
Clock,
Random,
IoContext>>;
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 <typename Peer, typename Handler>
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()
{
this->mRtClientStateSetter.processPendingClientStates();
this->mRtClientStateSetter.updateEnabled();
this->updateIsLinkAudioEnabled();
}
void sawAudioEndpointCallback(Id peerId,
std::optional<discovery::UdpEndpoint> endpoint,
discovery::IpAddress gateway)
{
this->sawLinkAudioEndpoint(peerId, endpoint, gateway);
}
};
} }