Skip to main content

secs_engine/
notes.rs

1//! Typed engine diagnostics; presentation owns their translated text.
2
3use crate::input::Peq;
4
5#[derive(Debug, Clone, PartialEq)]
6pub enum Note {
7    /// ADR 0033, one per main whose direct sound is opposite to the majority
8    /// of the mains it could be correlated with. `compared` is the number of
9    /// decided pairs, `opposite` how many of them were negative, `confidence`
10    /// the median |r| over the decided pairs.
11    PolarityReversed {
12        role: String,
13        confidence: f64,
14        compared: usize,
15        opposite: usize,
16    },
17    PolaritySplit {
18        groups: (Vec<String>, Vec<String>),
19        confidence: f64,
20    },
21    LiftCapped {
22        from_ms: f64,
23        taps: usize,
24        lift_ms: f64,
25    },
26    SubFilters(Vec<(String, crate::setup::SubFilter)>),
27    LowProtect {
28        role: String,
29        rolloff_hz: f64,
30        hp_hz: Option<f64>,
31        limited: bool,
32        reduced: usize,
33        cuts: usize,
34    },
35    RcLimit {
36        hz: f64,
37        auto: bool,
38        schroeder_hz: Option<f64>,
39        basis: secs_types::calibration::RcHiBasis,
40        factor: u8,
41        band_hz: Option<f64>,
42        band_t60_s: Option<f64>,
43        positions: Option<usize>,
44    },
45    RcBands {
46        bands: Vec<(f64, f64)>,
47    },
48    /// ADR 0025, one per main when `lf_align` is on and the mode has FIR
49    /// taps. `arrival_ms` is the median LF arrival left after correction
50    /// (positive = later than HF); `limited` means the pull clamp cut the
51    /// requested correction by more than 1 ms somewhere in the band.
52    LfAlign {
53        role: String,
54        strength: f64,
55        arrival_ms: Option<f64>,
56        limited: bool,
57    },
58    /// ADR 0025, one per main when `mode_decay` is on. Each mode is
59    /// `(hz, measured T60 s, cut depth dB)` with the depth positive; an empty
60    /// list means no mode qualified.
61    ModeDecay {
62        role: String,
63        target_t60_s: f64,
64        modes: Vec<(f64, f64, f64)>,
65    },
66    /// ADR 0030, one per channel whose FIR realizes excess phase when
67    /// `hf_phase` is on. `rotation_deg` is the wrapped rotation unwound above
68    /// the band, `None` when less than an octave is left below 0.45·SR;
69    /// `limited` means the `[−5 ms, lift]` clamp kept part of it.
70    HfPhase {
71        role: String,
72        rotation_deg: Option<f64>,
73        limited: bool,
74    },
75    /// ADR 0031, once when `input_hp_hz` is set: the common input high-pass,
76    /// 8th-order Butterworth, at `hz`.
77    InputHp {
78        hz: f64,
79    },
80    Latency {
81        latency_ms: f64,
82        lift_ms: f64,
83        main_extra_ms: f64,
84    },
85    PhaseStrength(Vec<(String, f64)>),
86    PhaseBand(Vec<(String, Option<f64>)>),
87    // RC (P09)
88    LongModeBoost {
89        cap_db: f64,
90        modes: Vec<(f64, f64)>,
91    },
92    GdCuts {
93        role: String,
94        cuts: Vec<Peq>,
95    },
96    // BA (P10)
97    BaCost(f64),
98    BaBusPass {
99        first: f64,
100        second: f64,
101        kept_first: bool,
102    },
103    BaManual,
104    LayoutFallback(String),
105    Layout(String),
106    TwoWay {
107        roles: Vec<String>,
108        gain_db: f64,
109        xo_hz: f64,
110    },
111    BusGainAnchored(f64),
112    Mimo(MimoNote),
113}
114
115/// Semantic diagnostics in producer order; never translated presentation text.
116#[derive(Debug, Clone, PartialEq)]
117pub enum MimoNote {
118    InsufficientPositions {
119        measured: usize,
120    },
121    ExcludedSupports(Vec<String>),
122    SupportRanges(Vec<(String, Option<(f64, f64)>)>),
123    GuardReduced {
124        role: String,
125        gain_db: f64,
126        cause: GuardCause,
127    },
128    GuardDisabled {
129        role: String,
130        cause: GuardCause,
131    },
132    SupportLimit {
133        max_supports: usize,
134    },
135    FirBudget {
136        support_count: usize,
137        taps_total: usize,
138    },
139}
140
141/// What the MIMO guard rejected last: the support level of that trial
142/// (3 dB above `GuardReduced::gain_db`, or −12 dB before `GuardDisabled`)
143/// and the guard values there that broke their 1 dB limits.
144#[derive(Debug, Clone, PartialEq)]
145pub struct GuardCause {
146    pub rejected_db: f64,
147    /// Late energy rise over every position, `(lo Hz, hi Hz, dB)`: a
148    /// third-octave band or a ±1.5 Hz band around a late mode.
149    pub band: Option<(f64, f64, f64)>,
150    /// Modal tail energy rise over every position, `(mode Hz, dB)`.
151    pub tail: Option<(f64, f64)>,
152}
153
154#[cfg(test)]
155impl MimoNote {
156    // Only the oracle adapter renders the legacy diagnostic strings.
157    pub(crate) fn oracle_text(&self) -> String {
158        match self {
159            Self::InsufficientPositions { measured } => {
160                format!("측정 위치 {measured}곳 — MIMO 는 3곳 이상일 때만")
161            }
162            Self::ExcludedSupports(roles) => format!("서포트 제외(사용자): {}", roles.join(", ")),
163            Self::SupportRanges(ranges) => format!(
164                "서포트 대역 {}",
165                ranges
166                    .iter()
167                    .map(|(role, range)| match range {
168                        Some((lo, hi)) => format!("{role} {lo:.0}–{hi:.0}"),
169                        None => format!("{role} 제외"),
170                    })
171                    .collect::<Vec<_>>()
172                    .join(", ")
173            ),
174            Self::GuardReduced { role, gain_db, .. } => {
175                format!("{role}: 대역 늦은 에너지 악화로 서포트 {gain_db:.0} dB")
176            }
177            Self::GuardDisabled { role, .. } => format!("{role}: MIMO 끔(악화)"),
178            Self::SupportLimit { max_supports } => format!("입력당 서포트 ≤ {max_supports}"),
179            Self::FirBudget {
180                support_count,
181                taps_total,
182            } => {
183                let digits = taps_total.to_string();
184                let grouped = digits
185                    .chars()
186                    .enumerate()
187                    .fold(String::new(), |mut out, (i, ch)| {
188                        if i > 0 && (digits.len() - i).is_multiple_of(3) {
189                            out.push(',');
190                        }
191                        out.push(ch);
192                        out
193                    });
194                format!("FIR 서포트 {support_count}개 · 총 {grouped}탭(48 kHz)")
195            }
196        }
197    }
198}