Skip to main content

usbdac_core/dac/
routing.rs

1use super::Dac;
2use crate::routing::{
3    ControlKey, RouteEdit, RouteReport, RouteValue, RoutingSessionError, RoutingSnapshot,
4};
5use crate::transport::routing_hw;
6
7/// Unavailable in this release; retained for source compatibility.
8///
9impl Dac {
10    /// Discover source-backed DJM choices on an exact, idle vendor PCM session.
11    /// Discovery leaves the mixer's routing intact.
12    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    /// Unavailable in this release; retained for source compatibility.
28    ///
29    /// Send one explicitly selected DJM option after fresh model, configuration,
30    /// claim and idle-alternate proof. `option` is a listed zero-based option ID.
31    /// Success confirms USB acknowledgement. The mixer's current routing
32    /// remains unknown through this protocol.
33    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    /// Unavailable in this release; retained for source compatibility.
53    ///
54    /// Read source-backed first-generation Focusrite controls using the already
55    /// claimed AudioControl interface while idle. No vendor claim or probe write.
56    /// Hardware behavior remains physically unvalidated.
57    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    /// Unavailable in this release; retained for source compatibility.
71    ///
72    /// Apply bounded typed Gen1 controls against a fresh readback on the live DAC.
73    /// Verify each write and restore attempted controls on failure. Configured
74    /// hand-back preserves external edits; no clock, preamp or persistent writes.
75    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    /// Unavailable in this release; retained for source compatibility.
93    ///
94    /// Inspect the exact Scarlett read candidate and required vendor claim,
95    /// without initializing its protocol or reading proprietary state.
96    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    /// Unavailable in this release; retained for source compatibility.
112    ///
113    /// Initialize and read source-backed Scarlett routing while idle. Requires
114    /// the host's explicit vendor-interface claim. Exact-model firmware and live geometry
115    /// guards apply before mux/mix controls become available. No route, volume or persistent setting
116    /// writes are sent. Hardware behavior remains unvalidated.
117    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    /// Unavailable in this release; retained for source compatibility.
133    ///
134    /// Read firmware-defined modern Focusrite FCP pins, mux banks and mix rows.
135    /// Requires idle ownership and an explicit exact-model vendor-interface claim.
136    /// Does not send persistent configuration commands.
137    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    /// Unavailable in this release; retained for source compatibility.
151    ///
152    /// Apply typed firmware pin routes and mixer coefficients against a fresh readback.
153    /// Requires idle ownership and explicit vendor claim. Verify every affected target,
154    /// restore attempted targets on failure, and preserve external edits at hand-back.
155    /// No persistent configuration commands are sent. Physically unvalidated.
156    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    /// Unavailable in this release; retained for source compatibility.
175    ///
176    /// Apply bounded half-dB replacements to one complete Scarlett mixer row.
177    /// Requires fresh expected raw coefficients, idle ownership and the explicit
178    /// vendor claim. Verifies the whole row and attempts verified restoration
179    /// after any attempted-write failure. Configured hand-back restores only
180    /// rows still matching the last verified write. Source-backed, physically
181    /// unverified; no mux bank or persistent configuration is written.
182    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    /// Unavailable in this release; retained for source compatibility.
199    ///
200    /// Probe optional per-bank support and read every raw bank including padding.
201    /// An unsupported response never enables writes; legacy reads remain usable.
202    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    /// Unavailable in this release; retained for source compatibility.
216    ///
217    /// Apply explicit bank edits only after a fresh complete capability/geometry
218    /// read equals the expected snapshot. Restore each attempted raw bank after
219    /// any uncertain write. Configured hand-back preserves external edits.
220    /// Source-backed; physical routing has not been validated.
221    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    /// Discover standard UAC2 selectors and mixer crosspoints on claimed
238    /// AudioControl interfaces in the active configuration. No vendor protocol
239    /// is inferred. Requires an idle DAC, including no open capture stream.
240    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    /// Explicitly wake affected full ADC3 routing domains on entirely claimed
254    /// idle functions. Restore checked original power after discovery, including
255    /// failures. The snapshot does not retain a power lease.
256    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    /// Revalidate the snapshot and acquire a fresh scoped ADC3 routing lease.
270    /// Preserve external power drift instead of overwriting it on hand-back.
271    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    /// Apply the ordinary verified routing transaction with explicit scoped
289    /// ADC3 wake. Restore original power after success or failure. Configured
290    /// route hand-back reacquires power only for these opted-in edits.
291    pub fn routing_apply_powered(
292        &self,
293        snapshot: &RoutingSnapshot,
294        edits: &[RouteEdit],
295    ) -> Result<RouteReport, RoutingSessionError> {
296        let _control = self
297            .shared
298            .control_guard
299            .try_lock()
300            .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
301        self.shared
302            .reject_reconfigure()
303            .map_err(RoutingSessionError::Session)?;
304        let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
305        routing_hw::apply_with_power(snapshot, edits, true)
306    }
307
308    /// Read a descriptor-backed control after checking the attachment,
309    /// configuration, descriptors and discovered selector pins for drift.
310    pub fn routing_read(
311        &self,
312        snapshot: &RoutingSnapshot,
313        key: ControlKey,
314    ) -> Result<RouteValue, RoutingSessionError> {
315        let _control = self
316            .shared
317            .control_guard
318            .try_lock()
319            .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
320        self.shared
321            .reject_reconfigure()
322            .map_err(RoutingSessionError::Session)?;
323        let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
324        routing_hw::read(snapshot, key)
325    }
326
327    /// Apply bounded, verified routing edits only while idle. Each edit includes
328    /// the expected current value from `routing_read`; stale values fail before
329    /// writing. Rediscover after changing a selector. The configured HandBack
330    /// policy controls route restoration on close; `close_with` overrides volume
331    /// handling only. Feature Unit volume and mute settings are not changed.
332    pub fn routing_apply(
333        &self,
334        snapshot: &RoutingSnapshot,
335        edits: &[RouteEdit],
336    ) -> Result<RouteReport, RoutingSessionError> {
337        let _control = self
338            .shared
339            .control_guard
340            .try_lock()
341            .ok_or(RoutingSessionError::Session(crate::Error::Busy))?;
342        self.shared
343            .reject_reconfigure()
344            .map_err(RoutingSessionError::Session)?;
345        let _scope = self.shared.enter().map_err(RoutingSessionError::Session)?;
346        routing_hw::apply(snapshot, edits)
347    }
348}