47 std::size_t channel_index)>;
51 virtual std::vector<AudioRouteInfo>
enumerate()
const = 0;
77 virtual bool connect(std::string_view stable_id, std::size_t bus_index) {
86 std::size_t channel_index) {
88 return connect(stable_id, bus_index);
106 std::size_t channel_index)
const {
132 std::vector<AudioRouteInfo>
enumerate()
const override {
143 std::vector<std::string> retained;
144 retained.reserve(selected_.size());
145 for (
const auto& selected : selected_) {
152 retained.push_back(selected);
154 std::vector<std::array<std::string, 2>> retained_channels;
155 retained_channels.reserve(selected_channels_.size());
156 for (
const auto& selected : selected_channels_)
157 retained_channels.push_back(selected);
158 routes_ = std::move(routes);
159 selected_ = std::move(retained);
160 selected_channels_ = std::move(retained_channels);
161 if (connect_channel_callback_) {
162 for (std::size_t bus_index = 0; bus_index < selected_channels_.size(); ++bus_index) {
163 for (std::size_t channel_index = 0; channel_index < 2; ++channel_index) {
164 const auto& selected = selected_channels_[bus_index][channel_index];
165 if (selected.empty())
167 const auto it = std::find_if(
168 routes_.begin(), routes_.end(), [&](
const AudioRouteInfo& route) {
169 return route.stable_id == selected && route.available &&
170 channel_index < static_cast<std::size_t>(route.channels);
172 if (it != routes_.end())
173 (void)connect_channel_callback_(*it, bus_index, channel_index);
176 }
else if (connect_callback_) {
177 for (std::size_t bus_index = 0; bus_index < selected_.size(); ++bus_index) {
179 std::find_if(routes_.begin(), routes_.end(), [&](
const AudioRouteInfo& route) {
180 return route.stable_id == selected_[bus_index] && route.available &&
183 if (it != routes_.end())
184 (void)connect_callback_(*it, bus_index);
191 callback_ = std::move(callback);
195 connect_callback_ = std::move(callback);
199 connect_channel_callback_ = std::move(callback);
203 disconnect_callback_ = std::move(callback);
206 bool connect(std::string_view stable_id, std::size_t bus_index)
override {
207 if (bus_index == std::numeric_limits<std::size_t>::max() ||
208 bus_index >= selected_.max_size())
211 std::find_if(routes_.begin(), routes_.end(), [stable_id](
const AudioRouteInfo& route) {
212 return route.stable_id == stable_id && route.available && route.channels > 0;
214 if (it == routes_.end())
216 ensure_bus(bus_index);
217 const bool feeds_right = it->channels > 1;
218 if (connect_channel_callback_) {
222 const bool stale_right = !selected_channels_[bus_index][1].empty() && !feeds_right;
224 if (!disconnect_callback_ || !disconnect_callback_(bus_index))
226 selected_[bus_index].clear();
227 selected_channels_[bus_index] = {};
229 if (!connect_channel_callback_(*it, bus_index, 0)) {
234 selected_[bus_index] = it->stable_id;
235 selected_channels_[bus_index][0] = it->stable_id;
237 selected_channels_[bus_index][1].clear();
238 }
else if (connect_channel_callback_(*it, bus_index, 1)) {
239 selected_channels_[bus_index][1] = it->stable_id;
242 return !feeds_right || !selected_channels_[bus_index][1].empty();
244 if (connect_callback_ && !connect_callback_(*it, bus_index))
246 set_whole_bus(bus_index, *it);
252 std::size_t channel_index)
override {
253 if (bus_index == std::numeric_limits<std::size_t>::max() ||
254 bus_index >= selected_.max_size() || channel_index >= 2)
257 std::find_if(routes_.begin(), routes_.end(), [stable_id](
const AudioRouteInfo& route) {
258 return route.stable_id == stable_id && route.available && route.channels > 0;
260 if (it == routes_.end())
262 if (channel_index >=
static_cast<std::size_t
>(it->channels))
264 if (connect_channel_callback_) {
265 if (!connect_channel_callback_(*it, bus_index, channel_index))
267 }
else if (connect_callback_ && channel_index == 0) {
270 if (!connect_callback_(*it, bus_index))
272 ensure_bus(bus_index);
273 set_whole_bus(bus_index, *it);
276 }
else if (connect_callback_) {
280 ensure_bus(bus_index);
281 selected_channels_[bus_index][channel_index] = it->stable_id;
282 if (channel_index == 0)
283 selected_[bus_index] = it->stable_id;
289 const bool bus_selected = bus_index < selected_.size() && !selected_[bus_index].empty();
290 const bool channel_selected =
291 bus_index < selected_channels_.size() &&
293 selected_channels_[bus_index].begin(), selected_channels_[bus_index].end(),
294 [](
const std::string& selected) {
return !selected.empty(); });
295 if (!bus_selected && !channel_selected)
297 if (disconnect_callback_ && !disconnect_callback_(bus_index))
299 if (bus_index < selected_.size())
300 selected_[bus_index].clear();
301 if (bus_index < selected_channels_.size())
302 selected_channels_[bus_index] = {};
308 return bus_index < selected_.size() ? selected_[bus_index] : std::string{};
312 std::size_t channel_index)
const override {
313 if (bus_index >= selected_channels_.size() || channel_index >= 2)
315 return selected_channels_[bus_index][channel_index];
323 for (std::size_t bus_index = 0; bus_index < ids.size(); ++bus_index) {
324 if (!ids[bus_index].empty())
325 (void)
connect(ids[bus_index], bus_index);
330 void ensure_bus(std::size_t bus_index) {
331 if (selected_.size() <= bus_index)
332 selected_.resize(bus_index + 1);
333 if (selected_channels_.size() <= bus_index)
334 selected_channels_.resize(bus_index + 1);
337 void set_whole_bus(std::size_t bus_index,
const AudioRouteInfo& route) {
338 selected_[bus_index] = route.stable_id;
339 selected_channels_[bus_index][0] = route.stable_id;
340 selected_channels_[bus_index][1] = route.channels > 1 ? route.stable_id : std::string{};
348 std::vector<AudioRouteInfo> routes_;
349 std::vector<std::string> selected_;
350 std::vector<std::array<std::string, 2>> selected_channels_;
Control-thread source catalog supplied by a Pulp host (standalone, Forge, or another graph host).
Definition audio_route_catalog.hpp:42
virtual std::string connected_route(std::size_t bus_index) const
Return the stable source currently connected to a bus, or empty when the host has not selected one.
Definition audio_route_catalog.hpp:98
virtual void set_connect_callback(ConnectCallback callback)
Install the host graph/bus binding invoked by connect().
Definition audio_route_catalog.hpp:58
std::function< bool(std::size_t bus_index)> DisconnectCallback
Definition audio_route_catalog.hpp:48
virtual void set_disconnect_callback(DisconnectCallback callback)
Install the host graph binding for disconnect().
Definition audio_route_catalog.hpp:70
virtual std::vector< std::string > selected_route_ids() const
Return the stable IDs selected for each declared input bus.
Definition audio_route_catalog.hpp:115
virtual bool disconnect(std::size_t bus_index)
Definition audio_route_catalog.hpp:91
virtual void restore_selected_route_ids(std::span< const std::string > ids)
Restore previously saved stable IDs on the control thread.
Definition audio_route_catalog.hpp:122
virtual bool connect(std::string_view stable_id, std::size_t bus_index)
Connect a host-owned source to a declared processor input bus.
Definition audio_route_catalog.hpp:77
std::function< void()> ChangeCallback
Definition audio_route_catalog.hpp:44
virtual void set_change_callback(ChangeCallback callback)=0
virtual std::vector< AudioRouteInfo > enumerate() const =0
virtual ~AudioRouteCatalog()=default
std::function< bool(const AudioRouteInfo &, std::size_t bus_index, std::size_t channel_index)> ConnectChannelCallback
Definition audio_route_catalog.hpp:46
std::function< bool(const AudioRouteInfo &, std::size_t bus_index)> ConnectCallback
Definition audio_route_catalog.hpp:45
virtual void set_connect_channel_callback(ConnectChannelCallback callback)
Install the host graph binding for an individual channel connection.
Definition audio_route_catalog.hpp:64
virtual std::string connected_route_channel(std::size_t bus_index, std::size_t channel_index) const
Return the stable source currently connected to one bus channel.
Definition audio_route_catalog.hpp:105
virtual bool connect_channel(std::string_view stable_id, std::size_t bus_index, std::size_t channel_index)
Connect one channel of a declared input bus.
Definition audio_route_catalog.hpp:85
Small host-side implementation for standalone/Forge hosts.
Definition audio_route_catalog.hpp:130
std::string connected_route_channel(std::size_t bus_index, std::size_t channel_index) const override
Return the stable source currently connected to one bus channel.
Definition audio_route_catalog.hpp:311
void set_change_callback(ChangeCallback callback) override
Definition audio_route_catalog.hpp:190
bool connect_channel(std::string_view stable_id, std::size_t bus_index, std::size_t channel_index) override
Connect one channel of a declared input bus.
Definition audio_route_catalog.hpp:251
void set_connect_callback(ConnectCallback callback) override
Install the host graph/bus binding invoked by connect().
Definition audio_route_catalog.hpp:194
void set_disconnect_callback(DisconnectCallback callback) override
Install the host graph binding for disconnect().
Definition audio_route_catalog.hpp:202
void restore_selected_route_ids(std::span< const std::string > ids) override
Restore previously saved stable IDs on the control thread.
Definition audio_route_catalog.hpp:322
std::vector< AudioRouteInfo > enumerate() const override
Definition audio_route_catalog.hpp:132
bool disconnect(std::size_t bus_index) override
Definition audio_route_catalog.hpp:288
std::vector< std::string > selected_route_ids() const override
Return the stable IDs selected for each declared input bus.
Definition audio_route_catalog.hpp:318
std::string connected_route(std::size_t bus_index) const override
Return the stable source currently connected to a bus, or empty when the host has not selected one.
Definition audio_route_catalog.hpp:307
void set_routes(std::vector< AudioRouteInfo > routes)
Definition audio_route_catalog.hpp:136
bool connect(std::string_view stable_id, std::size_t bus_index) override
Connect a host-owned source to a declared processor input bus.
Definition audio_route_catalog.hpp:206
void set_connect_channel_callback(ConnectChannelCallback callback) override
Install the host graph binding for an individual channel connection.
Definition audio_route_catalog.hpp:198
Bounded event contracts shared by host ingress and graph-authored nodes.
Definition anticipation_eligibility.hpp:9
AudioRouteKind
Definition audio_route_catalog.hpp:21
@ File
Definition audio_route_catalog.hpp:26
@ Instrument
Definition audio_route_catalog.hpp:24
@ Bus
Definition audio_route_catalog.hpp:25
@ Track
Definition audio_route_catalog.hpp:23
@ Internal
Definition audio_route_catalog.hpp:27
@ PhysicalInput
Definition audio_route_catalog.hpp:22
Definition audio_route_catalog.hpp:30
std::string stable_id
Definition audio_route_catalog.hpp:31
std::string display_name
Definition audio_route_catalog.hpp:32
bool available
Definition audio_route_catalog.hpp:35
int channels
Definition audio_route_catalog.hpp:34
AudioRouteKind kind
Definition audio_route_catalog.hpp:33