weirdnet_audio_engine/
route_exec.rs1use crate::router::{Route, RouterControl, RouterError};
4use crate::talkback::db_to_gain;
5use weirdnet_audio_route::{Executor, Graph, PortId, RouteError};
6
7impl Executor for RouterControl {
8 fn apply(&mut self, graph: &Graph) -> Result<(), RouteError> {
13 let known = |id: &str| graph.port(&PortId::new(id)).is_some();
14 let mut routes: Vec<Route> = self.routes().iter().filter(|r| !(known(&r.from) && known(&r.to))).cloned().collect();
15 let mut skipped = Vec::new();
16 for c in graph.connections() {
17 if !c.enabled {
18 continue;
19 }
20 if self.kind(c.from.as_str()).is_some() && self.kind(c.to.as_str()).is_some() {
21 routes.push(Route { from: c.from.as_str().to_string(), to: c.to.as_str().to_string(), gain: db_to_gain(c.gain_db) });
22 } else {
23 skipped.push(c.id.0.clone());
24 }
25 }
26 self.set_routes(routes).map_err(|e| match e {
27 RouterError::Cycle(_) => RouteError::Cycle,
28 RouterError::Unknown(id) => RouteError::UnknownPort(PortId::new(&id)),
29 RouterError::NotAnOutput(_) | RouterError::NotAnInput(_) => RouteError::WrongDirection,
30 RouterError::Duplicate(..) => RouteError::Duplicate,
31 other => RouteError::Denied(other.to_string()),
32 })?;
33 self.skipped = skipped;
34 Ok(())
35 }
36}
37
38impl RouterControl {
39 pub fn remote_connections(&self) -> &[String] {
41 &self.skipped
42 }
43}