usbdac_core/dac/
routing.rs1use super::Dac;
2use crate::routing::{
3 ControlKey, RouteEdit, RouteReport, RouteValue, RoutingSessionError, RoutingSnapshot,
4};
5use crate::transport::routing_hw;
6
7impl Dac {
10 pub fn djm_routing_discover(
13 &self,
14 ) -> Result<crate::pioneer::DjmRoutingProfile, RoutingSessionError> {
15 let _control = self
16 .shared
17 .control_guard
18 .try_lock()
19 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
20 self.shared
21 .reject_reconfigure()
22 .map_err(RoutingSessionError::Session)?;
23 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
24 routing_hw::djm_discover(&self.shared)
25 }
26
27 pub fn djm_routing_apply(
34 &self,
35 model: crate::pioneer::DjmModel,
36 configuration: u8,
37 key: crate::pioneer::DjmControlKey,
38 option: u8,
39 ) -> Result<(), RoutingSessionError> {
40 let _control = self
41 .shared
42 .control_guard
43 .try_lock()
44 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
45 self.shared
46 .reject_reconfigure()
47 .map_err(RoutingSessionError::Session)?;
48 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
49 routing_hw::djm_apply(&self.shared, model, configuration, key, option)
50 }
51
52 pub fn scarlett_gen1_read(&self) -> Result<crate::scarlett::Gen1Readback, RoutingSessionError> {
58 let _control = self
59 .shared
60 .control_guard
61 .try_lock()
62 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
63 self.shared
64 .reject_reconfigure()
65 .map_err(RoutingSessionError::Session)?;
66 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
67 routing_hw::scarlett_gen1_read()
68 }
69
70 pub fn scarlett_gen1_apply(
76 &self,
77 expected: &crate::scarlett::Gen1Readback,
78 edits: &[crate::scarlett::Gen1Edit],
79 ) -> Result<crate::scarlett::Gen1Report, RoutingSessionError> {
80 let _control = self
81 .shared
82 .control_guard
83 .try_lock()
84 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
85 self.shared
86 .reject_reconfigure()
87 .map_err(RoutingSessionError::Session)?;
88 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
89 routing_hw::scarlett_gen1_apply(expected, edits)
90 }
91
92 pub fn scarlett_routing_capability(
97 &self,
98 ) -> Result<Option<crate::scarlett::ReadCapability>, RoutingSessionError> {
99 let _control = self
100 .shared
101 .control_guard
102 .try_lock()
103 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
104 self.shared
105 .reject_reconfigure()
106 .map_err(RoutingSessionError::Session)?;
107 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
108 routing_hw::scarlett_discover()
109 }
110
111 pub fn scarlett_routing_read(
118 &self,
119 ) -> Result<crate::scarlett::RoutingReadback, RoutingSessionError> {
120 let _control = self
121 .shared
122 .control_guard
123 .try_lock()
124 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
125 self.shared
126 .reject_reconfigure()
127 .map_err(RoutingSessionError::Session)?;
128 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
129 routing_hw::scarlett_read()
130 }
131
132 pub fn fcp_routing_read(&self) -> Result<crate::scarlett::FcpReadback, RoutingSessionError> {
138 let _control = self
139 .shared
140 .control_guard
141 .try_lock()
142 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
143 self.shared
144 .reject_reconfigure()
145 .map_err(RoutingSessionError::Session)?;
146 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
147 routing_hw::fcp_read()
148 }
149
150 pub fn fcp_routing_apply(
157 &self,
158 expected: &crate::scarlett::FcpReadback,
159 routes: &[crate::scarlett::FcpRouteEdit],
160 mixes: &[crate::scarlett::FcpMixEdit],
161 ) -> Result<crate::scarlett::FcpWriteReport, RoutingSessionError> {
162 let _control = self
163 .shared
164 .control_guard
165 .try_lock()
166 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
167 self.shared
168 .reject_reconfigure()
169 .map_err(RoutingSessionError::Session)?;
170 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
171 routing_hw::fcp_apply(expected, routes, mixes)
172 }
173
174 pub fn scarlett_mix_apply(
183 &self,
184 edit: &crate::scarlett::MixRowEdit,
185 ) -> Result<crate::scarlett::MixWriteReport, RoutingSessionError> {
186 let _control = self
187 .shared
188 .control_guard
189 .try_lock()
190 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
191 self.shared
192 .reject_reconfigure()
193 .map_err(RoutingSessionError::Session)?;
194 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
195 routing_hw::scarlett_mix_apply(edit)
196 }
197
198 pub fn scarlett_mux_read(&self) -> Result<crate::scarlett::MuxSnapshot, RoutingSessionError> {
203 let _control = self
204 .shared
205 .control_guard
206 .try_lock()
207 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
208 self.shared
209 .reject_reconfigure()
210 .map_err(RoutingSessionError::Session)?;
211 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
212 routing_hw::scarlett_mux_read()
213 }
214
215 pub fn scarlett_mux_apply(
222 &self,
223 edit: &crate::scarlett::MuxEdit,
224 ) -> Result<crate::scarlett::MuxWriteReport, RoutingSessionError> {
225 let _control = self
226 .shared
227 .control_guard
228 .try_lock()
229 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
230 self.shared
231 .reject_reconfigure()
232 .map_err(RoutingSessionError::Session)?;
233 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
234 routing_hw::scarlett_mux_apply(edit)
235 }
236
237 pub fn routing_discover(&self) -> Result<RoutingSnapshot, RoutingSessionError> {
241 let _control = self
242 .shared
243 .control_guard
244 .try_lock()
245 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
246 self.shared
247 .reject_reconfigure()
248 .map_err(RoutingSessionError::Session)?;
249 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
250 routing_hw::discover()
251 }
252
253 pub fn routing_discover_powered(&self) -> Result<RoutingSnapshot, RoutingSessionError> {
257 let _control = self
258 .shared
259 .control_guard
260 .try_lock()
261 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
262 self.shared
263 .reject_reconfigure()
264 .map_err(RoutingSessionError::Session)?;
265 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
266 routing_hw::discover_with_power(true)
267 }
268
269 pub fn routing_read_powered(
272 &self,
273 snapshot: &RoutingSnapshot,
274 key: ControlKey,
275 ) -> Result<RouteValue, RoutingSessionError> {
276 let _control = self
277 .shared
278 .control_guard
279 .try_lock()
280 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
281 self.shared
282 .reject_reconfigure()
283 .map_err(RoutingSessionError::Session)?;
284 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
285 routing_hw::read_with_power(snapshot, key, true)
286 }
287
288 pub fn routing_apply_powered(
292 &self,
293 snapshot: &RoutingSnapshot,
294 edits: &[RouteEdit],
295 ) -> Result<RouteReport, RoutingSessionError> {
296 self.routing_apply_powered_detailed(snapshot, edits)
297 .map_err(|failure| *failure.error)
298 }
299
300 pub fn routing_apply_powered_detailed(
302 &self,
303 snapshot: &RoutingSnapshot,
304 edits: &[RouteEdit],
305 ) -> Result<RouteReport, crate::routing::RoutingApplyError> {
306 let _control = self
307 .shared
308 .control_guard
309 .try_lock()
310 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
311 self.shared
312 .reject_reconfigure()
313 .map_err(RoutingSessionError::Session)?;
314 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
315 routing_hw::apply_with_power_detailed(snapshot, edits, true)
316 }
317
318 pub fn routing_read(
321 &self,
322 snapshot: &RoutingSnapshot,
323 key: ControlKey,
324 ) -> Result<RouteValue, RoutingSessionError> {
325 let _control = self
326 .shared
327 .control_guard
328 .try_lock()
329 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
330 self.shared
331 .reject_reconfigure()
332 .map_err(RoutingSessionError::Session)?;
333 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
334 routing_hw::read(snapshot, key)
335 }
336
337 pub fn routing_apply(
343 &self,
344 snapshot: &RoutingSnapshot,
345 edits: &[RouteEdit],
346 ) -> Result<RouteReport, RoutingSessionError> {
347 let _control = self
348 .shared
349 .control_guard
350 .try_lock()
351 .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
352 self.shared
353 .reject_reconfigure()
354 .map_err(RoutingSessionError::Session)?;
355 let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
356 routing_hw::apply(snapshot, edits)
357 }
358}