secs_types/ipc.rs
1//! IPC between the screen and the service.
2//!
3//! The screen sends a [`Request`] as `{"method": "...", "params": {...}}` and
4//! always receives an envelope: `{"ok": true, "data": Response}` or
5//! `{"ok": false, "error": IpcError}`. The service never throws across this
6//! seam. Long jobs report progress through the event sink supplied with the call.
7//!
8//! Errors carry a code and parameters, not prose: the screen turns them into
9//! a sentence in the current language and keeps `detail` (the raw text) for
10//! the details view and the log.
11
12use std::collections::BTreeMap;
13
14use serde::{Deserialize, Serialize};
15use ts_rs::TS;
16
17use crate::calibration::{CalibrationSettings, Mode};
18use crate::compute::{ComputePreference, ComputeReport, ComputeStatus};
19pub use crate::settings_edit::CalibrationSettingsEditParams;
20
21/// A call from the screen.
22///
23/// The method names come from the variant names in one place: serde and
24/// strum both rename them to snake_case, and `method_names_match_the_wire`
25/// checks that the two agree.
26#[derive(
27 Debug, Clone, PartialEq, Serialize, Deserialize, TS, strum::VariantNames, strum::IntoStaticStr,
28)]
29#[serde(tag = "method", content = "params", rename_all = "snake_case")]
30#[strum(serialize_all = "snake_case")]
31#[ts(export)]
32pub enum Request {
33 /// Version, the upstream release this build is ported from, and the
34 /// platform. The first call the screen makes.
35 Bootstrap,
36 /// The `ProjectNew` Request variant.
37 ProjectNew(ProjectNewParams),
38 /// The `ProjectOpen` Request variant.
39 ProjectOpen(ProjectPathParams),
40 /// The `ProjectSave` Request variant.
41 ProjectSave(ProjectSaveParams),
42 /// The `ProjectInfo` Request variant.
43 ProjectInfo,
44 /// The `SampleLoad` Request variant.
45 SampleLoad(SampleLoadParams),
46 /// The `Calibrate` Request variant.
47 Calibrate(CalibrateParams),
48 /// The `RecommendXo` Request variant.
49 RecommendXo,
50 /// The `Mimo` Request variant.
51 Mimo(MimoParams),
52 /// The `Results` Request variant.
53 Results,
54 /// The `Export` Request variant.
55 Export(ExportParams),
56 /// The `JobCancel` Request variant.
57 JobCancel(JobCancelParams),
58 /// The `Jobs` Request variant.
59 Jobs,
60 /// The `MeasureMethods` Request variant.
61 MeasureMethods,
62 /// The `MeasureConfigure` Request variant.
63 MeasureConfigure(MeasureConfigureParams),
64 /// Returns the measurement settings stored in the open project.
65 MeasureConfigGet,
66 /// Returns one recording-status entry per arranged position.
67 MeasurementRecords,
68 /// Returns the project's microphone calibration and attachment counts.
69 MicCalibrationGet,
70 /// Reads, validates and stores a microphone calibration file in the project.
71 MicCalibrationSet(MicCalibrationSetParams),
72 /// Removes the project's selected microphone calibration file.
73 MicCalibrationClear,
74 /// Attaches the selected file to sweep measurements that have no mic curve.
75 MicCalibrationAttach,
76 /// Returns stored per-role level and SPL values.
77 LevelsGet,
78 /// Fills only missing per-role level values with upstream defaults.
79 LevelsFillDefaults,
80 /// Stops the current 2.5-second level burst without stopping its monitor.
81 LevelStop,
82 /// The `MeasurePosition` Request variant.
83 MeasurePosition(MeasurePositionParams),
84 /// The `PositionClear` Request variant.
85 PositionClear(PositionClearParams),
86 /// The `Undo` Request variant.
87 Undo(UndoParams),
88 /// The `RewLaunch` Request variant.
89 RewLaunch,
90 /// The `MdatScan` Request variant.
91 MdatScan(MdatScanParams),
92 /// The `MdatImport` Request variant.
93 MdatImport(MdatImportParams),
94 /// Returns the editable speaker configuration.
95 ConfigGet,
96 /// Replaces the speaker configuration with a built-in preset.
97 ConfigApplyPreset(ConfigPresetParams),
98 /// Changes the number of configured subwoofers.
99 ConfigSetSubCount(ConfigSubCountParams),
100 /// Changes one speaker or one of its bands.
101 ConfigSetSpeaker(ConfigSetSpeakerParams),
102 /// Adds the first unused upstream speaker role.
103 ConfigAddSpeaker,
104 /// Removes one configured speaker.
105 ConfigRemoveSpeaker(ConfigIndexParams),
106 /// Renumbers outputs in configuration order.
107 ConfigRenumber,
108 /// Returns structured configuration validation notices.
109 ConfigValidate,
110 /// Writes the upstream patch-sheet CSV.
111 PatchSheetCsv(PathParams),
112 /// Returns the editable DSP profile.
113 DspGet,
114 /// Applies a DSP preset or manual fields.
115 DspSet(DspSetParams),
116 /// Returns measurement arrangement and timing options.
117 LayoutGet,
118 /// Changes measurement arrangement or timing options.
119 LayoutSet(LayoutSetParams),
120 /// Returns the current per-position and total estimate.
121 PositionEstimate,
122 /// Returns the target curve and presets.
123 TargetGet,
124 /// Replaces target control points.
125 TargetSetPoints(TargetPointsParams),
126 /// Applies a built-in target preset.
127 TargetApplyPreset(TargetPresetParams),
128 /// Saves the target curve as upstream JSON.
129 TargetSave(PathParams),
130 /// Loads the target curve from upstream JSON.
131 TargetLoad(PathParams),
132 /// Returns calibration settings stored in the project.
133 CalibrationSettingsGet,
134 /// Stores calibration settings in the project.
135 CalibrationSettingsSet(CalibrationSettingsParams),
136 /// Applies one upstream calibration-screen edit and stores the settings.
137 CalibrationSettingsEdit(CalibrationSettingsEditParams),
138 /// Filter warnings from current settings (gain warnings require a run).
139 SubWarnings,
140 /// Optional REW facts read through the injected transport.
141 RewInfo,
142 /// Changes REW's audio driver and returns refreshed REW facts.
143 RewDriverSet(RewDriverSetParams),
144 /// Returns numeric capabilities for one calibration mode.
145 ModeSpec(ModeSpecParams),
146 /// Returns application-local settings.
147 AppSettingsGet,
148 /// Stores application-local settings.
149 AppSettingsSet(AppSettingsParams),
150 /// Reports the opt-in local API server and token.
151 LocalApiStatus,
152 /// Replaces the local API bearer token and restarts its server when needed.
153 LocalApiTokenRegenerate,
154 /// Available compute devices and the effective application preference.
155 ComputeStatus,
156 /// Opens the official GPU runtime installation guide for this platform.
157 OpenGpuHelp,
158 /// Smoothed, normalized measurement curves and their shared frequency grid.
159 MeasurementCurves(MeasurementCurvesParams),
160 /// Ready-to-draw calibration curves and axis limits for one result tab.
161 ResultCurves(ResultCurvesParams),
162 /// Numeric metrics, filter counts, BA rows and coded result notices.
163 ResultLines,
164 /// Copies the last BA output alignment into the manual sub settings.
165 SubTakeValues,
166 /// Opens a project-file picker through the application host.
167 DialogOpenProject,
168 /// Opens a project save-file picker through the application host.
169 DialogSaveProject(DialogSuggestedParams),
170 /// Opens an mdat-file picker through the application host.
171 DialogPickMdat,
172 /// Opens a folder picker through the application host.
173 DialogPickFolder(DialogPickFolderParams),
174 /// Opens a typed save-file picker through the application host.
175 DialogSaveFile(DialogSaveFileParams),
176 /// Opens a typed file picker through the application host.
177 DialogOpenFile(DialogOpenFileParams),
178 /// Opens a folder in the operating-system file manager.
179 OpenFolder(OpenFolderParams),
180 /// Starts the live input level monitor.
181 LevelMonitorStart(LevelMonitorStartParams),
182 /// Stops the live input level monitor.
183 LevelMonitorStop,
184 /// Plays a role's level-check signal for 2.5 seconds.
185 LevelPlay(LevelPlayParams),
186 /// Starts watching measurement-method status.
187 StatusWatchStart,
188 /// Stops watching measurement-method status.
189 StatusWatchStop,
190 /// Returns the stored or derived export base folder.
191 ExportFolderGet,
192 /// Stores the export base folder in the open project.
193 ExportFolderSet(ExportFolderSetParams),
194}
195
196impl Request {
197 /// Every method name, as it appears on the wire, derived from the
198 /// variants. `secs-policy` checks that each one is registered in
199 /// `features.toml` as `ipc.<method>`.
200 pub const METHODS: &'static [&'static str] = <Self as strum::VariantNames>::VARIANTS;
201
202 /// The wire name of this request's method.
203 pub fn method(&self) -> &'static str {
204 self.into()
205 }
206}
207
208/// The successful result of a [`Request`], tagged with the same method name.
209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
210#[serde(tag = "method", content = "data", rename_all = "snake_case")]
211#[ts(export)]
212pub enum Response {
213 /// The `Bootstrap` Response variant.
214 Bootstrap(BootstrapInfo),
215 /// The `ProjectNew` Response variant.
216 ProjectNew(ProjectInfo),
217 /// The `ProjectOpen` Response variant.
218 ProjectOpen(ProjectInfo),
219 /// The `ProjectSave` Response variant.
220 ProjectSave(ProjectInfo),
221 /// The `ProjectInfo` Response variant.
222 ProjectInfo(ProjectInfo),
223 /// The `SampleLoad` Response variant.
224 SampleLoad(JobStarted),
225 /// The `Calibrate` Response variant.
226 Calibrate(JobStarted),
227 /// The `RecommendXo` Response variant.
228 RecommendXo(JobStarted),
229 /// The `Mimo` Response variant.
230 Mimo(JobStarted),
231 /// The `Results` Response variant.
232 Results(ResultsSummary),
233 /// The `Export` Response variant.
234 Export(JobStarted),
235 /// The `JobCancel` Response variant.
236 JobCancel(JobSnapshot),
237 /// The `Jobs` Response variant.
238 Jobs(Vec<JobSnapshot>),
239 /// The `MeasureMethods` Response variant.
240 MeasureMethods(MeasureMethodsResult),
241 /// The `MeasureConfigure` Response variant.
242 MeasureConfigure(MeasureConfigResult),
243 /// Measurement settings stored in the open project.
244 MeasureConfigGet(MeasureConfigResult),
245 /// Recording status for every arranged position.
246 MeasurementRecords(MeasurementRecordsResult),
247 /// Selected microphone calibration and attachment counts.
248 MicCalibrationGet(MicCalibrationStatus),
249 /// Selected microphone calibration after storing a file.
250 MicCalibrationSet(MicCalibrationStatus),
251 /// Empty microphone calibration status after clearing the selection.
252 MicCalibrationClear(MicCalibrationStatus),
253 /// Microphone calibration status after attaching it to eligible sweeps.
254 MicCalibrationAttach(MicCalibrationStatus),
255 /// Stored per-role level and SPL values.
256 LevelsGet(LevelsResult),
257 /// Stored values after filling missing level defaults.
258 LevelsFillDefaults(LevelsResult),
259 /// Confirms that the current level burst was stopped.
260 LevelStop(()),
261 /// The `MeasurePosition` Response variant.
262 MeasurePosition(JobStarted),
263 /// The `PositionClear` Response variant.
264 PositionClear(UndoResult),
265 /// The `Undo` Response variant.
266 Undo(ProjectInfo),
267 /// The `RewLaunch` Response variant.
268 RewLaunch(RewStatusResult),
269 /// The `MdatScan` Response variant.
270 MdatScan(MdatScanResult),
271 /// The `MdatImport` Response variant.
272 MdatImport(JobStarted),
273 /// The `ConfigGet` Response variant.
274 ConfigGet(ConfigResult),
275 /// The `ConfigApplyPreset` Response variant.
276 ConfigApplyPreset(ConfigMutationResult),
277 /// The `ConfigSetSubCount` Response variant.
278 ConfigSetSubCount(ConfigMutationResult),
279 /// The `ConfigSetSpeaker` Response variant.
280 ConfigSetSpeaker(ConfigResult),
281 /// The `ConfigAddSpeaker` Response variant.
282 ConfigAddSpeaker(ConfigResult),
283 /// The `ConfigRemoveSpeaker` Response variant.
284 ConfigRemoveSpeaker(ConfigResult),
285 /// The `ConfigRenumber` Response variant.
286 ConfigRenumber(ConfigResult),
287 /// The `ConfigValidate` Response variant.
288 ConfigValidate(Vec<Notice>),
289 /// The `PatchSheetCsv` Response variant.
290 PatchSheetCsv(PathResult),
291 /// The `DspGet` Response variant.
292 DspGet(DspResult),
293 /// The `DspSet` Response variant.
294 DspSet(DspResult),
295 /// The `LayoutGet` Response variant.
296 LayoutGet(LayoutResult),
297 /// The `LayoutSet` Response variant.
298 LayoutSet(LayoutMutationResult),
299 /// The `PositionEstimate` Response variant.
300 PositionEstimate(PositionEstimateResult),
301 /// The `TargetGet` Response variant.
302 TargetGet(TargetResult),
303 /// The `TargetSetPoints` Response variant.
304 TargetSetPoints(TargetResult),
305 /// The `TargetApplyPreset` Response variant.
306 TargetApplyPreset(TargetResult),
307 /// The `TargetSave` Response variant.
308 TargetSave(PathResult),
309 /// The `TargetLoad` Response variant.
310 TargetLoad(TargetResult),
311 /// The `CalibrationSettingsGet` Response variant.
312 CalibrationSettingsGet(CalibrationSettings),
313 /// The `CalibrationSettingsSet` Response variant.
314 CalibrationSettingsSet(CalibrationSettings),
315 /// Settings after one edit.
316 CalibrationSettingsEdit(CalibrationSettings),
317 /// Current settings-only filter warnings.
318 SubWarnings(Vec<Notice>),
319 /// Current REW facts; unavailable fields are null.
320 RewInfo(RewInfoResult),
321 /// Current REW facts after changing its driver.
322 RewDriverSet(RewInfoResult),
323 /// The `ModeSpec` Response variant.
324 ModeSpec(ModeSpecResult),
325 /// The `AppSettingsGet` Response variant.
326 AppSettingsGet(AppSettings),
327 /// The `AppSettingsSet` Response variant.
328 AppSettingsSet(AppSettings),
329 /// Current local API server and token state.
330 LocalApiStatus(LocalApiStatus),
331 /// Local API state after replacing its bearer token.
332 LocalApiTokenRegenerate(LocalApiStatus),
333 /// Device capability and automatic-selection result.
334 ComputeStatus(ComputeStatus),
335 /// GPU installation documentation opened by the application host.
336 OpenGpuHelp(()),
337 /// Measurement curves on the common display grid.
338 MeasurementCurves(MeasurementCurvesResult),
339 /// Calibration tab curves, ranges and staleness.
340 ResultCurves(ResultCurvesResult),
341 /// Numeric summary lines and BA table.
342 ResultLines(ResultLinesResult),
343 /// Stored settings after taking the last sub alignment.
344 SubTakeValues(CalibrationSettings),
345 /// The chosen project path, or null when cancelled.
346 DialogOpenProject(Option<String>),
347 /// The chosen project destination, or null when cancelled.
348 DialogSaveProject(Option<String>),
349 /// The chosen mdat path, or null when cancelled.
350 DialogPickMdat(Option<String>),
351 /// The chosen folder, or null when cancelled.
352 DialogPickFolder(Option<String>),
353 /// The chosen save destination, or null when cancelled.
354 DialogSaveFile(Option<String>),
355 /// The chosen source path, or null when cancelled.
356 DialogOpenFile(Option<String>),
357 /// Confirms that the folder-open request reached the host.
358 OpenFolder(()),
359 /// The live level-monitor job.
360 LevelMonitorStart(JobStarted),
361 /// The stopped live level-monitor job, when one was running.
362 LevelMonitorStop(Option<JobSnapshot>),
363 /// Confirms that role playback was accepted.
364 LevelPlay(()),
365 /// The measurement-status watch job.
366 StatusWatchStart(JobStarted),
367 /// The stopped status-watch job, when one was running.
368 StatusWatchStop(Option<JobSnapshot>),
369 /// The current export base folder.
370 ExportFolderGet(ExportFolderResult),
371 /// The stored export base folder.
372 ExportFolderSet(ExportFolderResult),
373}
374
375/// Optional measurement selection; an absent selection includes every recorded pair.
376#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS, Default)]
377#[ts(export)]
378pub struct MeasurementCurvesParams {
379 /// Position numbers to include.
380 #[ts(type = "number[] | null")]
381 pub positions: Option<Vec<i64>>,
382 /// Speaker roles to include.
383 pub roles: Option<Vec<String>>,
384}
385/// A measurement curve, already smoothed and normalized to the mid-band mean.
386#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
387#[ts(export)]
388pub struct MeasurementCurve {
389 /// Speaker role.
390 pub role: String,
391 /// Measurement position.
392 #[ts(type = "number")]
393 pub position: i64,
394 /// Configuration kind: main, sub or top.
395 pub kind: String,
396 /// Levels in dB on the shared grid.
397 pub values: Vec<f64>,
398}
399/// Display limits; both endpoints are data values, not logarithms.
400#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
401#[ts(export)]
402pub struct CurveAxes {
403 /// Frequency bounds in Hz.
404 pub frequency_hz: [f64; 2],
405 /// Level or delay bounds.
406 pub value: [f64; 2],
407 /// Vertical unit: db or ms.
408 pub unit: String,
409}
410/// Measurement graph data.
411#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
412#[ts(export)]
413pub struct MeasurementCurvesResult {
414 /// Shared 280-point logarithmic frequency grid in Hz.
415 pub grid: Vec<f64>,
416 /// One curve per recorded role and position.
417 pub curves: Vec<MeasurementCurve>,
418 /// Upstream default axis bounds.
419 pub axes: CurveAxes,
420}
421/// The calibration graph to display.
422#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
423#[serde(rename_all = "snake_case")]
424#[ts(export)]
425pub enum ResultTab {
426 /// Sound pressure level relative to the target reference.
427 Spl,
428 /// Group delay in milliseconds.
429 Gd,
430 /// Crossover preview.
431 Xo,
432 /// Bass alignment.
433 Ba,
434}
435/// Selection for one ready-to-draw result graph.
436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
437#[ts(export)]
438pub struct ResultCurvesParams {
439 /// Graph tab.
440 pub tab: ResultTab,
441 /// Selected main role; absent selects the first available channel.
442 pub channel: Option<String>,
443 /// Crossover group; absent selects the selected channel's group.
444 pub group: Option<String>,
445 /// Dragged crossover in Hz; absent uses the configured value.
446 pub xo_hz: Option<f64>,
447 /// Apply input correction to the XO preview; defaults to true.
448 pub corrected: Option<bool>,
449}
450/// One named series on a result graph.
451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
452#[ts(export)]
453pub struct ResultCurve {
454 /// Series identity: before, after, target, mimo, main, sub, sum_before or sum_after.
455 pub kind: String,
456 /// Speaker role for per-sub curves, otherwise absent.
457 pub role: Option<String>,
458 /// Values on the response's shared grid.
459 pub values: Vec<f64>,
460}
461/// A result graph whose calculations are entirely owned by the service.
462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
463#[ts(export)]
464pub struct ResultCurvesResult {
465 /// Requested tab.
466 pub tab: ResultTab,
467 /// Shared frequency grid in Hz.
468 pub grid: Vec<f64>,
469 /// Ordered drawable series.
470 pub curves: Vec<ResultCurve>,
471 /// Upstream default axis bounds.
472 pub axes: CurveAxes,
473 /// Whether the retained result no longer matches current inputs.
474 pub stale: bool,
475 /// Whether the graph comes from a dedicated subs-only result.
476 pub subs_only: bool,
477 /// RC lower and upper bounds, with an unknown auto upper bound represented as null.
478 pub rc_band_hz: Option<(f64, Option<f64>)>,
479 /// Selected crossover frequency for the draggable line.
480 pub xo_hz: Option<f64>,
481}
482/// Values behind one channel's metrics and filters lines.
483#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
484#[ts(export)]
485pub struct ChannelResultLine {
486 /// Main role.
487 pub role: String,
488 /// Before and after percentage within one dB, 20–200 Hz.
489 pub within_1db_pct: [f64; 2],
490 /// Before and after group-delay spread, 20–100 Hz, in ms.
491 pub gd_spread_ms: [f64; 2],
492 /// Number of input PEQs.
493 pub peq_count: usize,
494 /// FIR taps, absent when no FIR is used.
495 pub fir_taps: Option<usize>,
496 /// Crossover frequency, absent without bass management.
497 pub xo_hz: Option<f64>,
498 /// Fresh, enabled MIMO support path count, absent when not shown.
499 pub mimo_support_count: Option<usize>,
500}
501/// One sub's output alignment and fixed filters.
502#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
503#[ts(export)]
504pub struct SubResultRow {
505 /// Sub role.
506 pub role: String,
507 /// Alignment mode code.
508 pub mode: String,
509 /// Output gain in dB.
510 pub gain_db: f64,
511 /// Output delay in ms.
512 pub delay_ms: f64,
513 /// Output polarity, plus or minus one.
514 pub polarity: i8,
515 /// Ordered all-pass frequency and Q pairs.
516 pub allpass: Vec<(f64, f64)>,
517 /// High-pass frequency and filter type.
518 pub high_pass: (f64, String),
519 /// Low-pass frequency and filter type.
520 pub low_pass: (f64, String),
521 /// Fixed and generated peaking filters as frequency, Q and gain.
522 pub peq: Vec<(f64, f64, f64)>,
523}
524/// A typed BA layout summary.
525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
526#[ts(export)]
527pub struct SubLayoutLine {
528 /// Bundle name.
529 pub bundle: String,
530 /// Layout code, dba or multi.
531 pub kind: String,
532 /// All members.
533 pub members: Vec<String>,
534 /// Front row roles.
535 pub front: Vec<String>,
536 /// Rear row roles.
537 pub rear: Vec<String>,
538 /// Rear delay in ms.
539 pub rear_ms: f64,
540 /// Automatic rear delay in ms, when available.
541 pub auto_ms: Option<f64>,
542 /// Manual rear trim in ms.
543 pub trim_ms: f64,
544 /// Shared peaking filters.
545 pub peq: Vec<(f64, f64, f64)>,
546}
547/// BA metrics and table, independent of the selected main channel.
548#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
549#[ts(export)]
550pub struct SubResultLines {
551 /// Whether this BA result is stale.
552 pub stale: bool,
553 /// Whether a dedicated subs-only run supplies these values.
554 pub subs_only: bool,
555 /// Metric band in Hz.
556 pub band_hz: [f64; 2],
557 /// Before and after flatness in dB.
558 pub flatness_db: [f64; 2],
559 /// Before and after across-seat spread, absent for a single seat.
560 pub seat_spread_db: Option<[f64; 2]>,
561 /// Number of complete sub positions.
562 pub positions: usize,
563 /// Output rows in configuration order.
564 pub rows: Vec<SubResultRow>,
565 /// Bundle layouts.
566 pub layouts: Vec<SubLayoutLine>,
567 /// Filter and gain warning codes and their arguments.
568 pub warnings: Vec<Notice>,
569}
570/// Numeric calibration summary lines; no localized sentences cross IPC.
571#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
572#[ts(export)]
573pub struct ResultLinesResult {
574 /// Whether the full calibration result is stale.
575 pub stale: bool,
576 /// Per-main metrics and filter counts.
577 pub channels: Vec<ChannelResultLine>,
578 /// Total delay in milliseconds, absent before calibration.
579 pub total_delay_ms: Option<f64>,
580 /// Engine notes as codes and arguments.
581 pub notes: Vec<Notice>,
582 /// RC ceiling provenance and room-volume notices.
583 pub rc: Vec<Notice>,
584 /// BA metrics, table, layouts and warnings when at least two subs are available.
585 pub ba: Option<SubResultLines>,
586}
587
588/// What the screen needs before it draws anything.
589#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
590#[ts(export)]
591pub struct BootstrapInfo {
592 /// Product name shown in the title bar and the about view.
593 pub app_name: String,
594 /// The SECS 2R version (the workspace version).
595 pub version: String,
596 /// True while the major version is 0: every 0.x build is a prerelease.
597 pub prerelease: bool,
598 /// The SECS 2 release this build follows.
599 pub upstream: UpstreamBase,
600 /// The operating-system platform running this build.
601 pub platform: Platform,
602}
603/// The upstream SECS 2 release a build is ported from (`UPSTREAM.toml`).
604#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
605#[ts(export)]
606pub struct UpstreamBase {
607 /// Upstream product name from `UPSTREAM.toml`.
608 pub name: String,
609 /// Upstream repository URL from `UPSTREAM.toml`.
610 pub repository: String,
611 /// Upstream release version from `UPSTREAM.toml`.
612 pub version: String,
613 /// Forty-character upstream Git commit from `UPSTREAM.toml`.
614 pub commit: String,
615 /// Upstream snapshot date from `UPSTREAM.toml`.
616 pub date: String,
617}
618/// The operating-system platform running the service.
619#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
620#[ts(export)]
621pub struct Platform {
622 /// `windows`, `macos` or `linux` (`std::env::consts::OS`).
623 pub os: String,
624 /// `x86_64` or `aarch64` (`std::env::consts::ARCH`).
625 pub arch: String,
626}
627
628/// Inputs for creating a project.
629#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
630#[ts(export)]
631pub struct ProjectNewParams {
632 /// Destination `.secs` file path.
633 pub path: String,
634 /// Speaker-layout preset name.
635 pub preset: String,
636 /// Number of subwoofers.
637 pub sub_count: u8,
638 /// Whether to create the fixed 7.1.4 sample-room project.
639 pub sample: bool,
640 /// Whether this is a tutorial session using the sample room. The session
641 /// cannot be saved or exported; its measurements and results live in a
642 /// temporary folder that is removed when the session ends, and `path` is
643 /// only reported back.
644 #[serde(default)]
645 pub tutorial: bool,
646}
647/// Inputs for loading embedded or synthetic sample measurements.
648#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
649#[ts(export)]
650pub struct SampleLoadParams {
651 /// Synthetic position count, 2 to 17 (the largest layout); absent loads
652 /// the one-position embedded room. Other counts are refused with
653 /// `measurement_input` (`field = positions`).
654 pub positions: Option<u32>,
655}
656/// A project file path.
657#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
658#[ts(export)]
659pub struct ProjectPathParams {
660 /// Source `.secs` file path.
661 pub path: String,
662}
663/// Inputs for saving the open project.
664#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
665#[ts(export)]
666pub struct ProjectSaveParams {
667 /// Optional save-as `.secs` path; absent saves in place.
668 pub path: Option<String>,
669}
670/// Screen-facing information about the open project.
671#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
672#[ts(export)]
673pub struct ProjectInfo {
674 /// Open `.secs` file path.
675 pub path: String,
676 /// Project display name.
677 pub name: String,
678 /// Speaker-layout preset name.
679 pub preset: String,
680 /// Number of configured subwoofers.
681 pub sub_count: usize,
682 /// Measured position numbers.
683 pub positions: Vec<i64>,
684 /// Whether the in-memory project has unsaved changes.
685 pub dirty: bool,
686 /// Whether this open project is a non-writable tutorial session.
687 pub tutorial: bool,
688 /// Warnings produced while loading legacy project entries.
689 pub migration_warnings: Vec<MigrationWarning>,
690}
691/// A project migration warning code and affected entry.
692#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
693#[ts(export)]
694pub struct MigrationWarning {
695 /// Stable warning code translated by the screen.
696 pub code: String,
697 /// Project entry affected by the warning.
698 pub entry: String,
699}
700
701/// Optional settings for a calibration run.
702#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS, Default)]
703#[ts(export)]
704pub struct CalibrateParams {
705 /// Settings override; absent uses the open project.
706 pub settings: Option<CalibrationSettings>,
707 /// Designs the subwoofers only (upstream [서브만 계산]); the result is
708 /// kept apart and shown by the BA tab until the next full run.
709 #[serde(default)]
710 pub subs_only: bool,
711}
712/// Optional settings for a MIMO run.
713#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS, Default)]
714#[ts(export)]
715pub struct MimoParams {
716 /// Settings override; absent uses the open project.
717 pub settings: Option<CalibrationSettings>,
718}
719
720/// A service-assigned long-running job identifier.
721#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, TS)]
722#[serde(transparent)]
723#[ts(export)]
724pub struct JobId(#[ts(type = "number")] pub u64);
725/// The operation performed by a long-running job.
726#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, TS)]
727#[serde(rename_all = "snake_case")]
728#[ts(export)]
729pub enum JobKind {
730 /// Records all configured roles at one measurement position.
731 Measure,
732 /// Loads embedded or deterministic synthetic sample measurements.
733 SampleLoad,
734 /// Imports assigned measurements from a REW mdat file.
735 MdatImport,
736 /// Computes a calibration design from project measurements.
737 Calibrate,
738 /// Scores crossover-frequency candidates.
739 RecommendXo,
740 /// Computes MIMO support paths.
741 Mimo,
742 /// Writes one selected export bundle.
743 Export,
744 /// Streams microphone levels and controls level-check playback.
745 LevelMonitor,
746 /// Watches measurement-method status changes.
747 StatusWatch,
748}
749/// The current lifecycle state of a job.
750#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
751#[serde(rename_all = "snake_case")]
752#[ts(export)]
753pub enum JobStatus {
754 /// The worker is still running and may accept cancellation.
755 Running,
756 /// Cancellation was requested and the worker has not stopped yet.
757 CancelRequested,
758 /// The worker completed and produced a result.
759 Succeeded,
760 /// The worker stopped with an error.
761 Failed,
762 /// The caller cancelled the operation.
763 Cancelled,
764}
765impl JobStatus {
766 /// Whether the job can no longer change state.
767 pub fn is_terminal(self) -> bool {
768 matches!(self, Self::Succeeded | Self::Failed | Self::Cancelled)
769 }
770}
771/// The immediate response after a job starts.
772#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
773#[ts(export)]
774pub struct JobStarted {
775 /// Identifier assigned to the job.
776 pub job: JobId,
777 /// Operation the job performs.
778 pub kind: JobKind,
779}
780/// The latest observable state of a job.
781#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
782#[ts(export)]
783pub struct JobSnapshot {
784 /// Identifier assigned to the job.
785 pub job: JobId,
786 /// Operation the job performs.
787 pub kind: JobKind,
788 /// Current lifecycle state.
789 pub status: JobStatus,
790 /// Whether a cancellation request can still prevent commit.
791 pub cancellable: bool,
792 /// Most recently reported stage progress.
793 pub progress: Option<JobProgress>,
794 /// Failure once finished unsuccessfully.
795 pub error: Option<IpcError>,
796}
797/// Progress within one named job stage.
798#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
799#[ts(export)]
800pub struct JobProgress {
801 /// Stable stage code translated by the screen.
802 pub stage: String,
803 #[ts(type = "number")]
804 /// Completed work units in this stage.
805 pub done: u64,
806 #[ts(type = "number")]
807 /// Total work units in this stage.
808 pub total: u64,
809}
810/// A pushed lifecycle event for a long-running job.
811#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
812#[serde(tag = "event", rename_all = "snake_case")]
813#[ts(export)]
814pub enum JobEvent {
815 /// Announces a newly accepted job and its operation.
816 Started { job: JobId, kind: JobKind },
817 /// Reports completed and total work units for a stable stage code.
818 Progress {
819 job: JobId,
820 stage: String,
821 #[ts(type = "number")]
822 done: u64,
823 #[ts(type = "number")]
824 total: u64,
825 },
826 /// Reports a presentation-neutral log code and template parameters.
827 Log {
828 job: JobId,
829 code: String,
830 params: BTreeMap<String, String>,
831 },
832 /// Reports a terminal status and an ephemeral operation result or error.
833 /// Calibration and MIMO carry only a marker; read `results` for their summary.
834 Finished {
835 job: JobId,
836 status: JobStatus,
837 result: Option<Box<JobResult>>,
838 error: Option<IpcError>,
839 },
840 /// Reports a live input level at the monitor cadence.
841 Meter {
842 job: JobId,
843 rms_dbfs: f64,
844 peak_dbfs: f64,
845 spl_db: Option<f64>,
846 clipping: bool,
847 },
848 /// Reports a changed measurement-method status snapshot.
849 MeasureStatus {
850 job: JobId,
851 status: MeasureMethodsResult,
852 },
853}
854/// The successful result produced by a job.
855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
856#[serde(tag = "kind", content = "data", rename_all = "snake_case")]
857#[ts(export)]
858pub enum JobResult {
859 /// Calibration committed; fetch the current screen summary with `results`.
860 Calibration,
861 /// Crossover recommendation computed for the current project.
862 Xo(XoRecommendation),
863 /// MIMO committed; fetch the current screen summary with `results`.
864 Mimo,
865 /// Paths written by an exporter.
866 Export(ExportResult),
867 /// Project state after a completed measurement.
868 Measurement(ProjectInfo),
869 /// Project state after an mdat import.
870 MdatImport(ProjectInfo),
871 /// A long-lived monitor or watcher stopped without a payload.
872 Stopped,
873}
874/// The job to cancel.
875#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
876#[ts(export)]
877pub struct JobCancelParams {
878 /// Identifier of the job to cancel.
879 pub job: JobId,
880}
881
882/// The latest calibration and MIMO results.
883#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
884#[ts(export)]
885pub struct ResultsSummary {
886 /// Latest calibration result, including stale state.
887 pub calibration: Option<CalibrationSummary>,
888 /// Latest MIMO result, including stale state.
889 pub mimo: Option<MimoSummary>,
890 /// Whether the MIMO result goes into an export, and if not, why.
891 pub mimo_export: MimoExportDecision,
892}
893/// Whether the MIMO result goes into an export, and if not, why.
894#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
895#[serde(rename_all = "snake_case")]
896#[ts(export)]
897pub enum MimoExportDecision {
898 /// The current MIMO support paths go into the export.
899 Included,
900 /// MIMO is switched off in the current settings.
901 Off,
902 /// No MIMO result has been computed or restored.
903 None,
904 /// The MIMO result does not match the current inputs or compute environment.
905 Stale,
906 /// MIMO needs at least three measured positions.
907 TooFewPositions,
908 /// The current MIMO result contains no support paths.
909 NoSupports,
910}
911/// A presentation-neutral note or warning code with template parameters.
912#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
913#[ts(export)]
914pub struct Notice {
915 /// Stable snake_case code derived from the engine note variant.
916 pub code: String,
917 /// String values for the screen message template.
918 pub params: BTreeMap<String, String>,
919}
920
921/// The screen-facing summary of one calibration design.
922#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
923#[ts(export)]
924pub struct CalibrationSummary {
925 /// Whether this result was restored from the project cache instead of computed in this
926 /// session; staged and before/after mdat need a live design.
927 #[serde(default)]
928 pub cached: bool,
929 /// Whether current project inputs differ from this result.
930 pub stale: bool,
931 /// Which input first differs: measurements, settings or target.
932 pub stale_reason: Option<String>,
933 /// Calibration mode used to compute this result.
934 pub mode: Mode,
935 /// Ultra-mode latency limit used to compute this result, in milliseconds.
936 pub ultra_ms: f64,
937 /// Values for the upstream verdict card.
938 pub verdict: VerdictSummary,
939 /// Per-channel before-and-after metrics.
940 pub scorecard: Vec<ChannelScore>,
941 /// Total filter latency in milliseconds.
942 pub latency_ms: f64,
943 /// Informational codes and values translated by the screen.
944 pub notes: Vec<Notice>,
945 /// Main-channel roles in design order; filter coefficients stay in Rust.
946 pub main_roles: Vec<String>,
947 /// Subwoofer roles in design order; filter coefficients stay in Rust.
948 pub sub_roles: Vec<String>,
949}
950/// Values shown by the upstream `step_calibration.py` verdict card.
951#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
952#[ts(export)]
953pub struct VerdictSummary {
954 /// Share within ±1 dB before correction, in percent.
955 pub within_1db_before_pct: f64,
956 /// Share within ±1 dB after correction, in percent.
957 pub within_1db_after_pct: f64,
958 /// Low-band group-delay spread before correction, in milliseconds.
959 pub low_band_time_spread_before_ms: f64,
960 /// Low-band group-delay spread after correction, in milliseconds.
961 pub low_band_time_spread_after_ms: f64,
962 /// Delay added by correction, in milliseconds.
963 pub added_delay_ms: f64,
964 /// Across-position level spread after correction, in dB.
965 pub position_spread_db: f64,
966}
967/// Before-and-after scorecard metrics for one speaker role.
968#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
969#[ts(export)]
970pub struct ChannelScore {
971 /// Internal speaker role.
972 pub role: String,
973 /// Metrics before correction.
974 pub before: MetricsSummary,
975 /// Metrics after correction.
976 pub after: MetricsSummary,
977}
978/// The upstream `Metrics` fields for one response.
979#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, TS)]
980#[ts(export)]
981pub struct MetricsSummary {
982 /// Reference level from upstream `Metrics.level`, in dB.
983 pub level: f64,
984 /// Share within ±1 dB from 20 Hz, in percent.
985 pub in1_20: f64,
986 /// Share within ±2 dB from 20 Hz, in percent.
987 pub in2_20: f64,
988 /// Share within ±1 dB from 200 Hz, in percent.
989 pub in1_200: f64,
990 /// Share within ±2 dB from 200 Hz, in percent.
991 pub in2_200: f64,
992 /// Share within ±1 dB from 2,000 Hz, in percent.
993 pub in1_2000: f64,
994 /// Share within ±2 dB from 2,000 Hz, in percent.
995 pub in2_2000: f64,
996 /// Phase rotation from upstream `Metrics.turns`, in turns.
997 pub turns: f64,
998 /// Group-delay spread near 20 Hz, in milliseconds.
999 pub gd_20: f64,
1000 /// Group-delay spread near 100 Hz, in milliseconds.
1001 pub gd_100: f64,
1002 /// Group-delay spread near 500 Hz, in milliseconds.
1003 pub gd_500: f64,
1004 /// Largest absolute 1/24-octave group-delay peak, in milliseconds.
1005 pub gd24_abs: f64,
1006 /// Frequency of the largest absolute group-delay peak, in Hz.
1007 pub gd24_abs_hz: f64,
1008 /// Largest signed 1/24-octave group-delay peak, in milliseconds.
1009 pub gd24_max: f64,
1010 /// Span of 1/24-octave group delay, in milliseconds.
1011 pub gd24_span: f64,
1012 /// Group-delay spread near 30 Hz, in milliseconds.
1013 pub gd_30: f64,
1014 /// Pre-ringing level from upstream `Metrics.pre_db`, in dB.
1015 pub pre_db: f64,
1016}
1017/// The screen-facing summary of one MIMO run.
1018#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1019#[ts(export)]
1020pub struct MimoSummary {
1021 /// Actual computation backend, retained with the result.
1022 #[serde(default)]
1023 pub compute: ComputeReport,
1024 /// Whether current calibration inputs differ from this MIMO result.
1025 pub stale: bool,
1026 /// Realization kind, `iir` or `fir`.
1027 pub kind: String,
1028 /// Upper support frequency in Hz.
1029 pub fsiso: f64,
1030 /// Number of generated support paths.
1031 pub support_count: usize,
1032 /// Total FIR-tap budget across all generated paths.
1033 pub fir_taps_total: usize,
1034 /// Informational codes and values translated by the screen.
1035 pub notes: Vec<Notice>,
1036 /// Number of distinct input roles with at least one generated support path.
1037 pub input_count: usize,
1038}
1039/// Crossover candidates and the best value for each group.
1040#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1041#[ts(export)]
1042pub struct XoRecommendation {
1043 /// Best crossover frequency in Hz for each speaker group.
1044 pub best: Vec<(String, f64)>,
1045 /// Evaluated crossover frequencies in Hz.
1046 pub candidates: Vec<f64>,
1047}
1048
1049/// The supported export bundle.
1050#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
1051#[serde(rename_all = "snake_case")]
1052#[ts(export)]
1053pub enum ExportKind {
1054 /// CamillaDSP configuration and FIR coefficient WAV files.
1055 CamillaDsp,
1056 /// REW mdat containing the upstream staged responses.
1057 StagedMdat,
1058 /// REW mdat containing the original measurements, the correction results
1059 /// or both ([`ExportParams::mdat_scope`]; upstream's before-and-after mdat).
1060 BeforeAfterMdat,
1061 /// Per-channel filter values as text plus FIR WAV files (upstream
1062 /// `calibration.export_filter_text`). Results with RC only.
1063 FilterText,
1064 /// A complete Equalizer APO configuration: `config.txt`, the filter file
1065 /// and FIR WAV files (upstream `calibration.export_eqapo`). RC, BA and
1066 /// MIMO support paths, which upstream refuses (docs/DEVIATIONS.md F12).
1067 EqualizerApo,
1068 /// One complete 48 kHz impulse response and response CSV per reachable
1069 /// input-to-output path, including RC, BA, LFE and MIMO operations.
1070 Convolution,
1071}
1072
1073/// Why a filter export cannot carry the current result (upstream
1074/// `calibration.filter_export_block`).
1075#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
1076#[serde(rename_all = "snake_case")]
1077#[ts(export)]
1078pub enum ExportBlock {
1079 /// The result has subs (BA); filter text carries RC only.
1080 Subs,
1081 /// The result includes MIMO; filter text does not carry it.
1082 Mimo,
1083 /// The result was restored from the cache and is stale; mdat needs the measurements' spectra,
1084 /// so it must be recalibrated first.
1085 StaleCache,
1086}
1087
1088impl ExportBlock {
1089 /// The `params.reason` value of an [`ErrorCode::ExportScope`] error.
1090 pub fn name(self) -> &'static str {
1091 match self {
1092 Self::Subs => "subs",
1093 Self::Mimo => "mimo",
1094 Self::StaleCache => "stale_cache",
1095 }
1096 }
1097}
1098
1099/// Upstream `filter_export_block`: whether `kind` can carry a result with
1100/// subs (`has_subs`) and MIMO support paths (`has_mimo`). CamillaDSP, the
1101/// mdat exports, Equalizer APO and convolution carry everything; filter text
1102/// carries RC only (subs are checked first, as upstream). Upstream stops MIMO at
1103/// Equalizer APO as well; its writer already routes the support paths, and
1104/// `secs-filters/tests/eqapo_playback.rs` plays them through the engine
1105/// (DEVIATIONS F12). The screen mirrors this rule (`screens/export/types.ts`).
1106pub fn filter_export_block(
1107 kind: ExportKind,
1108 has_subs: bool,
1109 has_mimo: bool,
1110) -> Option<ExportBlock> {
1111 match kind {
1112 ExportKind::FilterText if has_subs => Some(ExportBlock::Subs),
1113 ExportKind::FilterText if has_mimo => Some(ExportBlock::Mimo),
1114 _ => None,
1115 }
1116}
1117
1118/// Whether an export format can carry the current result. Stale cached
1119/// calibration blocks mdat; filter formats retain [`filter_export_block`].
1120pub fn export_block(
1121 kind: ExportKind,
1122 has_subs: bool,
1123 has_mimo: bool,
1124 stale_cache: bool,
1125) -> Option<ExportBlock> {
1126 match kind {
1127 ExportKind::StagedMdat | ExportKind::BeforeAfterMdat if stale_cache => {
1128 Some(ExportBlock::StaleCache)
1129 }
1130 _ => filter_export_block(kind, has_subs, has_mimo),
1131 }
1132}
1133/// What the REW mdat export ([`ExportKind::BeforeAfterMdat`]) carries
1134/// (docs/DEVIATIONS.md F19). The file name says which: `원 측정` for the
1135/// measurements, `보정 결과` for the computed responses.
1136#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize, TS)]
1137#[serde(rename_all = "snake_case")]
1138#[ts(export)]
1139pub enum MdatScope {
1140 /// The main position's before-and-after responses (upstream's file) and
1141 /// the original measurements of the other positions.
1142 #[default]
1143 All,
1144 /// The original measurements of every position, as stored; needs no
1145 /// correction result.
1146 Measurements,
1147 /// The computed responses at the main position only.
1148 Results,
1149}
1150
1151/// Sample formats accepted by CamillaDSP's Wasapi backend.
1152#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
1153#[ts(export)]
1154pub enum CamillaWasapiFormat {
1155 /// Signed 32-bit integer.
1156 #[serde(rename = "S32")]
1157 S32,
1158 /// Signed 24-bit integer.
1159 #[serde(rename = "S24")]
1160 S24,
1161 /// Signed 16-bit integer.
1162 #[serde(rename = "S16")]
1163 S16,
1164 /// 32-bit floating point.
1165 #[serde(rename = "F32")]
1166 F32,
1167}
1168
1169impl CamillaWasapiFormat {
1170 /// CamillaDSP configuration spelling.
1171 pub fn name(self) -> &'static str {
1172 match self {
1173 Self::S32 => "S32",
1174 Self::S24 => "S24",
1175 Self::S16 => "S16",
1176 Self::F32 => "F32",
1177 }
1178 }
1179}
1180
1181/// CamillaDSP capture backend. Channel counts come from the export plan.
1182#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
1183#[serde(tag = "type", rename_all = "snake_case")]
1184#[ts(export)]
1185pub enum CamillaCaptureDevice {
1186 /// File placeholder compatible with the existing export.
1187 #[default]
1188 File,
1189 /// Windows Audio Session API capture.
1190 Wasapi {
1191 /// Endpoint name; absent selects the system default.
1192 device: Option<String>,
1193 /// Sample representation.
1194 format: CamillaWasapiFormat,
1195 /// Request exclusive access.
1196 exclusive: bool,
1197 /// Capture a playback endpoint in shared mode.
1198 loopback: bool,
1199 },
1200 /// ASIO capture. Requires CamillaDSP's ASIO build (`camilladsp-windows-asio`).
1201 Asio {
1202 /// ASIO driver name.
1203 device: String,
1204 },
1205}
1206
1207/// CamillaDSP playback backend. Channel counts come from the export plan.
1208#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
1209#[serde(tag = "type", rename_all = "snake_case")]
1210#[ts(export)]
1211pub enum CamillaPlaybackDevice {
1212 /// File placeholder compatible with the existing export.
1213 #[default]
1214 File,
1215 /// Windows Audio Session API playback.
1216 Wasapi {
1217 /// Endpoint name; absent selects the system default.
1218 device: Option<String>,
1219 /// Sample representation.
1220 format: CamillaWasapiFormat,
1221 /// Request exclusive access.
1222 exclusive: bool,
1223 },
1224 /// ASIO playback. Requires CamillaDSP's ASIO build (`camilladsp-windows-asio`).
1225 Asio {
1226 /// ASIO driver name.
1227 device: String,
1228 },
1229}
1230
1231/// Capture and playback backends for a CamillaDSP export.
1232#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
1233#[ts(export)]
1234pub struct CamillaDevices {
1235 /// Capture backend.
1236 pub capture: CamillaCaptureDevice,
1237 /// Playback backend.
1238 pub playback: CamillaPlaybackDevice,
1239}
1240
1241/// The export bundle and destination folder.
1242#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1243#[ts(export)]
1244pub struct ExportParams {
1245 /// Export bundle to write.
1246 pub kind: ExportKind,
1247 /// Destination folder path. An empty path uses the project's export folder
1248 /// and applies the upstream timestamped subfolder convention.
1249 pub folder: String,
1250 /// What the REW mdat carries; absent means [`MdatScope::All`]. Only
1251 /// [`ExportKind::BeforeAfterMdat`] takes it; other kinds refuse it.
1252 #[serde(default, skip_serializing_if = "Option::is_none")]
1253 #[ts(optional)]
1254 pub mdat_scope: Option<MdatScope>,
1255 /// Optional stable export name. Named exports replace the matching bundle.
1256 #[serde(default, skip_serializing_if = "Option::is_none")]
1257 #[ts(optional)]
1258 pub design_name: Option<String>,
1259 /// Optional CamillaDSP Windows backends. File placeholders are the default.
1260 #[serde(default, skip_serializing_if = "Option::is_none")]
1261 #[ts(optional)]
1262 pub camilla_devices: Option<CamillaDevices>,
1263}
1264/// Files written by a completed export job.
1265#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1266#[ts(export)]
1267pub struct ExportResult {
1268 /// Paths of all files written by the exporter.
1269 pub files: Vec<String>,
1270 /// Actual export folder written by the job.
1271 pub folder: String,
1272 /// Whether the exported calibration differed from current project inputs.
1273 pub stale: bool,
1274}
1275
1276// P28 host, live-monitor, watch and export-folder types. Keep this block
1277// contiguous so the parallel M5 IPC additions merge without interleaving.
1278/// Optional suggested name for a save dialog.
1279#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
1280#[ts(export)]
1281pub struct DialogSuggestedParams {
1282 /// Suggested file name.
1283 pub suggested: String,
1284}
1285/// Optional starting folder for a folder picker.
1286#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
1287#[ts(export)]
1288pub struct DialogPickFolderParams {
1289 /// Starting folder, when known.
1290 pub start: Option<String>,
1291}
1292/// The kind of file a host save dialog accepts.
1293#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
1294#[serde(rename_all = "snake_case")]
1295#[ts(export)]
1296pub enum SaveFileKind {
1297 /// UTF-8 patch-sheet CSV.
1298 PatchSheet,
1299 /// Target-curve JSON.
1300 Target,
1301}
1302/// Typed save-file dialog parameters.
1303#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1304#[ts(export)]
1305pub struct DialogSaveFileParams {
1306 /// File type and filter.
1307 pub kind: SaveFileKind,
1308 /// Suggested file name.
1309 pub suggested: String,
1310}
1311/// The kind of file a host open dialog accepts.
1312#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
1313#[serde(rename_all = "snake_case")]
1314#[ts(export)]
1315pub enum OpenFileKind {
1316 /// Target-curve JSON.
1317 Target,
1318 /// Microphone response calibration text (`.txt`, `.cal` or `.frd`).
1319 MicCalibration,
1320}
1321/// Typed open-file dialog parameters.
1322#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1323#[ts(export)]
1324pub struct DialogOpenFileParams {
1325 /// File type and filter.
1326 pub kind: OpenFileKind,
1327}
1328/// Folder to reveal in the operating-system file manager.
1329#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1330#[ts(export)]
1331pub struct OpenFolderParams {
1332 /// Folder path.
1333 pub path: String,
1334}
1335/// Optional role to associate with a level-monitor start.
1336#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
1337#[ts(export)]
1338pub struct LevelMonitorStartParams {
1339 /// Speaker role initially selected for playback.
1340 pub role: Option<String>,
1341}
1342/// Role and output level for one 2.5-second level-check burst.
1343#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1344#[ts(export)]
1345pub struct LevelPlayParams {
1346 /// Internal speaker role.
1347 pub role: String,
1348 /// Master output level in dBFS.
1349 pub master_dbfs: f64,
1350}
1351/// Export base-folder update.
1352#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1353#[ts(export)]
1354pub struct ExportFolderSetParams {
1355 /// Folder path to store in the open project.
1356 pub folder: String,
1357}
1358/// Current export base folder and whether it came from project storage.
1359#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1360#[ts(export)]
1361pub struct ExportFolderResult {
1362 /// Export base folder.
1363 pub folder: String,
1364 /// True when `extra.export.folder` supplied this value.
1365 pub stored: bool,
1366}
1367
1368// Measurement request and response types.
1369/// A validated microphone calibration file selected for the open project.
1370#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1371#[ts(export)]
1372pub struct MicCalibrationFile {
1373 /// File name as selected by the user.
1374 pub name: String,
1375 /// Full selected path; the project retains the decoded text separately.
1376 pub path: String,
1377 /// miniDSP serial number from `SERNO`, when present.
1378 pub serial: Option<String>,
1379 /// USB microphone sensitivity factor in dB.
1380 pub sens_factor_db: Option<f64>,
1381 /// Analog input gain from `AGain`, in dB.
1382 pub analog_gain_db: Option<f64>,
1383 /// Analog microphone sensitivity at 94 dB SPL, in dBFS.
1384 pub sensitivity_dbfs: Option<f64>,
1385 /// Quoted metadata lines other than the sensitivity header.
1386 pub notes: Vec<String>,
1387 /// Number of frequency-response points.
1388 pub points: u32,
1389 /// Lowest tabulated frequency in Hz.
1390 pub min_hz: f64,
1391 /// Highest tabulated frequency in Hz.
1392 pub max_hz: f64,
1393 /// Whether any response point includes phase.
1394 pub has_phase: bool,
1395}
1396/// Selected microphone calibration and recorded-measurement attachment counts.
1397#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1398#[ts(export)]
1399pub struct MicCalibrationStatus {
1400 /// The project's selected file, or absent when none is selected.
1401 pub file: Option<MicCalibrationFile>,
1402 /// Recorded position-role pairs whose sidecar attaches a `meterCal` curve.
1403 pub attached: u32,
1404 /// Sweep measurements without a `meterCal` curve that can receive the file.
1405 pub attachable: u32,
1406}
1407/// A microphone calibration file selected by full path.
1408#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1409#[ts(export)]
1410pub struct MicCalibrationSetParams {
1411 /// Full path selected by the user.
1412 pub path: String,
1413}
1414
1415/// Measurement methods available on this host.
1416#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
1417#[ts(export)]
1418pub struct MeasureMethodsResult {
1419 /// Stable identifiers for available measurement methods.
1420 pub methods: Vec<String>,
1421 /// Native endpoints with their channel counts.
1422 pub native_devices: Vec<MeasureDevice>,
1423 /// Native enumeration failure, without hiding the other methods.
1424 pub native_error: Option<IpcError>,
1425 /// REW process, API, and license status.
1426 pub rew: RewStatusResult,
1427 /// Positions present in the unmodified sample room.
1428 pub mock_positions: Vec<i64>,
1429 /// Roles present in the unmodified sample room.
1430 pub mock_roles: Vec<String>,
1431}
1432/// An enumerated native audio endpoint.
1433#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1434#[ts(export)]
1435pub struct MeasureDevice {
1436 /// Backend endpoint identifier.
1437 pub id: String,
1438 /// Backend endpoint display name.
1439 pub name: String,
1440 /// Maximum number of input channels.
1441 pub input_channels: usize,
1442 /// Maximum number of output channels.
1443 pub output_channels: usize,
1444}
1445/// Measurement method and device settings.
1446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS, Default)]
1447#[ts(export)]
1448pub struct MeasureConfigureParams {
1449 /// Measurement method identifier.
1450 pub method: String,
1451 /// Optional input device identifier.
1452 pub input_device: Option<String>,
1453 /// Optional output device identifier.
1454 pub output_device: Option<String>,
1455 /// Optional one-based input channel number.
1456 pub input_channel: Option<u16>,
1457 /// One-based output channels in measurement-plan role order; empty preserves wiring.
1458 #[serde(default)]
1459 pub output_channels: Vec<u16>,
1460 /// Optional sweep length in samples.
1461 pub sweep_length: Option<usize>,
1462 /// Optional sweep repetition count; allowed values are 1, 2, 4 and 8.
1463 pub repetitions: Option<u8>,
1464 /// Optional sweep level in dBFS.
1465 pub sweep_level_dbfs: Option<f64>,
1466 /// Optional timing-reference mode.
1467 pub timing: Option<String>,
1468 /// Optional one-based loopback input channel.
1469 pub loopback_input_channel: Option<u16>,
1470 /// Optional acoustic timing-reference output channel.
1471 pub timing_ref_output: Option<u16>,
1472 /// Optional share preference: auto, exclusive, or shared.
1473 pub share_mode: Option<String>,
1474}
1475/// The active measurement settings.
1476#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS, Default)]
1477#[ts(export)]
1478pub struct MeasureConfigResult {
1479 /// Active measurement method identifier.
1480 pub method: String,
1481 /// Active sweep level in dBFS.
1482 pub sweep_level_dbfs: Option<f64>,
1483 /// Active input endpoint identifier; empty selects the default.
1484 pub input_device: String,
1485 /// Active output endpoint identifier; empty selects the default.
1486 pub output_device: String,
1487 /// One-based microphone input channel.
1488 pub input_channel: u16,
1489 /// Roles in the same order as output_channels.
1490 pub roles: Vec<String>,
1491 /// One-based output channels in measurement-plan role order.
1492 pub output_channels: Vec<u16>,
1493 /// Sweep length in samples.
1494 pub sweep_length: usize,
1495 /// Active repetition count after timing-reference normalization.
1496 pub repetitions: u8,
1497 /// Sweep sample rate in Hz.
1498 pub sample_rate: u32,
1499 /// Supported sweep lengths in samples.
1500 pub sweep_lengths: Vec<usize>,
1501 /// Timing-reference mode.
1502 pub timing: String,
1503 /// Optional one-based loopback input channel.
1504 pub loopback_input_channel: Option<u16>,
1505 /// Optional acoustic timing-reference output channel.
1506 pub timing_ref_output: Option<u16>,
1507 /// Share preference: auto, exclusive, or shared.
1508 pub share_mode: String,
1509}
1510/// Recording status and upstream source values for one arranged position.
1511#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1512#[ts(export)]
1513pub struct PositionRecord {
1514 /// One-based arranged position number.
1515 #[ts(type = "number")]
1516 pub position: i64,
1517 /// Whether every planned role is recorded at this position.
1518 pub done: bool,
1519 /// Planned roles that have a recording at this position.
1520 pub roles: Vec<String>,
1521 /// Source file/value by recorded role; native and REW sweeps use `measured`.
1522 pub sources: BTreeMap<String, String>,
1523}
1524/// Recording status for the complete measurement arrangement.
1525#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1526#[ts(export)]
1527pub struct MeasurementRecordsResult {
1528 /// One entry per arranged position.
1529 pub records: Vec<PositionRecord>,
1530}
1531/// Stored level-check readings, keyed by measurement role (upstream `extra['levels']`).
1532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1533#[ts(export)]
1534pub struct LevelsResult {
1535 /// Measured input level in dBFS by role: the meter reading while that channel played.
1536 pub levels: BTreeMap<String, f64>,
1537 /// Measured sound-pressure level in dB SPL by role.
1538 pub spl: BTreeMap<String, f64>,
1539}
1540/// The measurement position to record.
1541#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1542#[ts(export)]
1543pub struct MeasurePositionParams {
1544 /// One-based measurement position number.
1545 pub position: i64,
1546}
1547/// The measurement position to clear.
1548#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1549#[ts(export)]
1550pub struct PositionClearParams {
1551 /// One-based measurement position number.
1552 pub position: i64,
1553}
1554/// A service-issued undo token.
1555#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1556#[ts(export)]
1557pub struct UndoParams {
1558 /// Opaque service-issued undo token.
1559 pub token: String,
1560}
1561/// An undo token and the project state it restores.
1562#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1563#[ts(export)]
1564pub struct UndoResult {
1565 /// Opaque token for the inverse action.
1566 pub token: String,
1567 /// Project state after the action.
1568 pub project: ProjectInfo,
1569}
1570/// Whether REW is running, reachable, and licensed as Pro.
1571#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
1572#[ts(export)]
1573pub struct RewStatusResult {
1574 /// Whether an REW process is running.
1575 pub running: bool,
1576 /// Whether the REW API responds.
1577 pub reachable: bool,
1578 /// Observed automatic-sweep license state: unknown until success or rejection.
1579 pub pro: Option<bool>,
1580}
1581/// A requested REW audio driver.
1582#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1583#[ts(export)]
1584pub struct RewDriverSetParams {
1585 /// Driver name as REW reports it (`ASIO` or `Java`).
1586 pub driver: String,
1587}
1588/// Facts from REW, distinct from project-stored measurement preferences.
1589#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS, Default)]
1590#[ts(export)]
1591pub struct RewInfoResult {
1592 pub executable_path: Option<String>,
1593 pub running: bool,
1594 pub reachable: bool,
1595 pub version: Option<String>,
1596 /// REW's current audio driver, or null when it could not be read.
1597 pub driver: Option<String>,
1598 /// Observed automatic-sweep license state: unknown until success or rejection.
1599 pub pro: Option<bool>,
1600 /// REW's current input device, read from its own audio preferences.
1601 pub input_device: Option<String>,
1602 /// REW's current output device, read from its own audio preferences.
1603 pub output_device: Option<String>,
1604 /// REW's current input channel name.
1605 pub input: Option<String>,
1606 pub blocking: Option<bool>,
1607 /// Empty means no file loaded; null means unknown or per-input calibration.
1608 pub input_calibration_file: Option<String>,
1609 pub input_devices: Option<Vec<RewDeviceInfo>>,
1610 pub output_devices: Option<Vec<RewDeviceInfo>>,
1611 pub input_channel_names: Option<Vec<String>>,
1612 pub sample_rate: Option<f64>,
1613 pub sweep: Option<RewSweepInfo>,
1614 pub level_dbfs: Option<f64>,
1615}
1616
1617#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1618#[ts(export)]
1619pub struct RewDeviceInfo {
1620 pub id: String,
1621 pub name: String,
1622 pub channels: usize,
1623}
1624
1625#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1626#[ts(export)]
1627pub struct RewSweepInfo {
1628 pub start_hz: Option<f64>,
1629 pub end_hz: Option<f64>,
1630 pub length: Option<String>,
1631}
1632
1633/// The REW mdat file to scan.
1634#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1635#[ts(export)]
1636pub struct MdatScanParams {
1637 /// Source `.mdat` file path.
1638 pub path: String,
1639}
1640/// Measurements, suggested assignments, and problem codes found in an mdat file.
1641#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
1642#[ts(export)]
1643pub struct MdatScanResult {
1644 /// Measurements in file order, including assignment guesses.
1645 pub measurements: Vec<MdatScanMeasurement>,
1646 /// Suggested measurement-to-role assignments.
1647 pub suggestions: Vec<MdatAssignment>,
1648 /// Stable problem codes and template parameters.
1649 pub problems: Vec<Notice>,
1650}
1651/// One scanned measurement with an unambiguous row identifier.
1652#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1653#[ts(export)]
1654pub struct MdatScanMeasurement {
1655 /// Zero-based row index, also usable when titles repeat.
1656 pub index: usize,
1657 /// Original measurement title.
1658 pub title: String,
1659 /// Suggested internal role, or no assignment.
1660 pub role: Option<String>,
1661 /// Guessed one-based measurement position.
1662 pub position: i64,
1663 /// Whether the title explicitly names a position, including position 1.
1664 pub position_tagged: bool,
1665 /// Low-band classifier result, absent when no IR is available.
1666 pub looks_like_sub: Option<bool>,
1667}
1668/// An mdat measurement assigned to a speaker role.
1669#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1670#[ts(export)]
1671pub struct MdatAssignment {
1672 /// Measurement title from the mdat file.
1673 pub measurement: String,
1674 /// Internal speaker role.
1675 pub role: String,
1676 /// Optional zero-based row index to disambiguate repeated titles.
1677 pub index: Option<usize>,
1678 /// Optional per-row position overriding the import destination.
1679 pub position: Option<i64>,
1680}
1681/// An mdat file, its assignments, and destination position.
1682#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1683#[ts(export)]
1684pub struct MdatImportParams {
1685 /// Source `.mdat` file path.
1686 pub path: String,
1687 /// Accepted measurement-to-role assignments.
1688 pub assignments: Vec<MdatAssignment>,
1689 /// Destination measurement position number.
1690 pub position: i64,
1691}
1692
1693// Project editing request and response types.
1694/// A filesystem path used by a project editor.
1695#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1696#[ts(export)]
1697pub struct PathParams {
1698 /// File system path chosen by the user.
1699 pub path: String,
1700}
1701/// A path written by an editor.
1702#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1703#[ts(export)]
1704pub struct PathResult {
1705 /// File system path that was written.
1706 pub path: String,
1707}
1708/// A preset change which may need measurement-clearing confirmation.
1709#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1710#[ts(export)]
1711pub struct ConfigPresetParams {
1712 /// Preset name (`2.0`, `2.1`, `2.2`, `4.0`, `4.1`, `4.2`, `5.1`, `7.1`, `7.1.4`, `9.1.6`, or `custom` for an empty layout).
1713 pub preset: String,
1714 /// Clears existing measurements; without it a project with measurements answers `confirm_required` (U5).
1715 #[serde(default)]
1716 pub confirm: bool,
1717}
1718/// A sub-count change which may need measurement-clearing confirmation.
1719#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1720#[ts(export)]
1721pub struct ConfigSubCountParams {
1722 /// Number of subwoofers, 0 to 8.
1723 pub count: i64,
1724 /// Clears existing measurements; without it a project with measurements answers `confirm_required` (U5).
1725 #[serde(default)]
1726 pub confirm: bool,
1727}
1728/// One speaker index.
1729#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1730#[ts(export)]
1731pub struct ConfigIndexParams {
1732 /// Speaker index in `ConfigResult.speakers`.
1733 pub index: usize,
1734}
1735/// Optional edits to one speaker or one of its bands.
1736#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1737#[ts(export)]
1738pub struct ConfigSetSpeakerParams {
1739 /// Speaker index in `ConfigResult.speakers`.
1740 pub index: usize,
1741 /// New role code; a sub role forces a single SUB band (`step2_config.py:988-1002`).
1742 pub role: Option<String>,
1743 /// New size: `small` (crossover applied) or `large` (full range).
1744 pub size: Option<String>,
1745 /// Band the output and polarity edits apply to; absent means the first band.
1746 pub band_index: Option<usize>,
1747 /// New measurement output channel (1-based).
1748 pub out: Option<i64>,
1749 /// New polarity: `+` normal or `-` inverted.
1750 pub pol: Option<String>,
1751}
1752/// One configured output band.
1753#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1754#[ts(export)]
1755pub struct ConfigBand {
1756 /// Band name: `FULL`, `LF`, `MF`, `HF` or `SUB`.
1757 pub band: String,
1758 /// Measurement output channel (1-based).
1759 pub out: i64,
1760 /// Polarity: `+` normal or `-` inverted.
1761 pub pol: String,
1762}
1763/// One configured speaker.
1764#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1765#[ts(export)]
1766pub struct ConfigSpeaker {
1767 /// Role code (`L`, `C`, `SW1`, `Tfl`, ...).
1768 pub role: String,
1769 /// `small` (crossover applied) or `large` (full range); subs are `sub`.
1770 pub size: String,
1771 /// Bands in order; one band unless bi-amped.
1772 pub bands: Vec<ConfigBand>,
1773}
1774/// One upstream speaker group in upstream order.
1775#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1776#[ts(export)]
1777pub struct ConfigGroup {
1778 /// Stable presentation group id: front, center, sub, surround, back, wide, top, height or other.
1779 pub id: String,
1780 /// Upstream group name used as the project and crossover-map key.
1781 pub key: String,
1782 /// Indices into `ConfigResult.speakers` that belong to this group.
1783 pub speaker_indices: Vec<usize>,
1784}
1785/// Values derived from the complete speaker configuration.
1786#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1787#[ts(export)]
1788pub struct ConfigSummary {
1789 /// Number of speakers.
1790 pub speaker_count: usize,
1791 /// Number of measurement outputs in use.
1792 pub outputs: Vec<i64>,
1793 /// Highest output channel in use.
1794 pub max_channel: i64,
1795 /// Number of output channels used twice or more.
1796 pub duplicate_outputs: Vec<i64>,
1797 /// Number of subwoofers.
1798 pub sub_count: usize,
1799}
1800/// Screen-facing editable speaker configuration.
1801#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1802#[ts(export)]
1803pub struct ConfigResult {
1804 /// Speakers in table order.
1805 pub speakers: Vec<ConfigSpeaker>,
1806 /// Preset name, or `custom` after any manual edit.
1807 pub preset: String,
1808 /// Measurement output device name (`config.device`).
1809 pub device: String,
1810 /// Table group header rows in upstream order.
1811 pub groups: Vec<ConfigGroup>,
1812 /// Counts the summary line shows.
1813 pub summary: ConfigSummary,
1814}
1815/// Configuration after a destructive edit and its optional inverse token.
1816#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1817#[ts(export)]
1818pub struct ConfigMutationResult {
1819 /// The configuration after the edit.
1820 pub config: ConfigResult,
1821 /// Token for `undo` when the edit cleared measurements (U5).
1822 pub undo_token: Option<String>,
1823}
1824/// The five manually editable DSP profile fields.
1825#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1826#[ts(export)]
1827pub struct DspFields {
1828 /// FIR taps per channel.
1829 pub fir_taps: i64,
1830 /// Total FIR taps the DSP can run across channels.
1831 pub fir_budget: i64,
1832 /// IIR (PEQ) bands per channel.
1833 pub iir_bands: i64,
1834 /// All-pass bands per channel.
1835 pub allpass_bands: i64,
1836 /// Bass-management path delays the DSP offers.
1837 pub bm_path_delays: i64,
1838}
1839/// One DSP preset in the built-in table.
1840#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1841#[ts(export)]
1842pub struct DspPreset {
1843 /// Preset key (`camilla`, `tesira`, `qsys`, `minidsp`, `custom`).
1844 pub key: String,
1845 /// Device name shown in the device list.
1846 pub name: String,
1847 /// The preset's filter resources.
1848 pub fields: DspFields,
1849}
1850/// A preset selection or a complete manual edit.
1851#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
1852#[ts(export)]
1853pub struct DspSetParams {
1854 /// Selects a preset; absent with `fields` set means a manual edit.
1855 pub preset: Option<String>,
1856 /// Manual values; any manual edit makes the profile `custom`.
1857 pub fields: Option<DspFields>,
1858}
1859/// Editable DSP state and derived resolution values.
1860#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1861#[ts(export)]
1862pub struct DspResult {
1863 /// Current profile key.
1864 pub profile: String,
1865 /// Current device name.
1866 pub name: String,
1867 /// Current filter resources.
1868 pub fields: DspFields,
1869 /// Every preset, for the device list.
1870 pub presets: Vec<DspPreset>,
1871 /// FIR window length the taps give, in ms (note line).
1872 pub window_ms: f64,
1873 /// Frequency resolution the taps give, in Hz (note line).
1874 pub resolution_hz: f64,
1875}
1876/// Measurement timing-reference settings stored under `extra.devices`.
1877#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1878#[ts(export)]
1879pub struct LayoutTiming {
1880 /// Timing reference: `acoustic`, `loopback` or `none`.
1881 pub reference: String,
1882 /// Reference speaker role for the acoustic reference (default `R`).
1883 pub role: String,
1884 /// Reference output channel for the loopback reference (1-based).
1885 pub output: i64,
1886}
1887/// One measurement microphone point in centimetres.
1888#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1889#[ts(export)]
1890pub struct LayoutPoint {
1891 /// Position number; 1 is the listening position.
1892 pub position: usize,
1893 /// Left-right offset from the centre seat, in cm (`layout_map.py`).
1894 pub x_cm: f64,
1895 /// Front-back offset from the centre seat, in cm (`layout_map.py`).
1896 pub y_cm: f64,
1897 /// Height step: 0 at ear height, +1 or -1 for ±20 cm.
1898 pub height: i8,
1899}
1900/// One supported measurement arrangement.
1901#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1902#[ts(export)]
1903pub struct LayoutArrangement {
1904 /// Number of positions: 1, 9, 13 or 17.
1905 pub count: usize,
1906 /// Microphone points of this arrangement.
1907 pub points: Vec<LayoutPoint>,
1908}
1909/// Editable arrangement and measurement options.
1910#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1911#[ts(export)]
1912pub struct LayoutResult {
1913 /// Chosen arrangement (`extra['array']`).
1914 pub count: usize,
1915 /// Start delay before each position as stored (`extra['start_delay']`):
1916 /// one of [`crate::rules::START_DELAYS`], `끄기` or `5 초` to `15 초`.
1917 pub start_delay: String,
1918 /// Timing reference and its reference speaker or output.
1919 pub timing: LayoutTiming,
1920 /// Every arrangement with its geometry, for the cards and maps.
1921 pub arrangements: Vec<LayoutArrangement>,
1922}
1923/// Optional arrangement and timing edits.
1924#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
1925#[ts(export)]
1926pub struct LayoutSetParams {
1927 /// New arrangement; changing it clears measurements (U5).
1928 pub count: Option<usize>,
1929 /// New start delay, one of [`crate::rules::START_DELAYS`]; any other
1930 /// value answers `invalid_request` (field `start_delay`).
1931 pub start_delay: Option<String>,
1932 /// New timing reference.
1933 pub timing: Option<LayoutTiming>,
1934 /// Clears existing measurements; without it a project with measurements answers `confirm_required` (U5).
1935 #[serde(default)]
1936 pub confirm: bool,
1937}
1938/// Arrangement after editing and its optional inverse token.
1939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1940#[ts(export)]
1941pub struct LayoutMutationResult {
1942 /// The arrangement and options after the edit.
1943 pub layout: LayoutResult,
1944 /// Token for `undo` when the edit cleared measurements (U5).
1945 pub undo_token: Option<String>,
1946}
1947/// Position-duration estimate from upstream step 4 semantics.
1948#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1949#[ts(export)]
1950pub struct PositionEstimateResult {
1951 /// Number of positions in the arrangement.
1952 pub positions: usize,
1953 /// Estimated time per position, in seconds (`step4_layout.position_seconds`).
1954 pub per_position_seconds: f64,
1955 /// Estimated time for every position, without moving the microphone, in seconds.
1956 pub total_seconds: f64,
1957}
1958/// Target control points.
1959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1960#[ts(export)]
1961pub struct TargetPointsParams {
1962 /// Target points as (Hz, dB); clamped to 10–24000 Hz and ±30 dB, at least two.
1963 pub points: Vec<(f64, f64)>,
1964}
1965/// One built-in target preset selection.
1966#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
1967#[ts(export)]
1968pub struct TargetPresetParams {
1969 /// Target preset: `flat`, `harman` or `cinema`.
1970 pub preset: String,
1971}
1972/// Target curve, selected preset, and built-in preset table.
1973#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1974#[ts(export)]
1975pub struct TargetResult {
1976 /// Target points as (Hz, dB).
1977 pub points: Vec<(f64, f64)>,
1978 /// Preset name, or absent when the points were edited (custom).
1979 pub preset: Option<String>,
1980 /// Preset names the target menu offers.
1981 pub presets: Vec<(String, Vec<(f64, f64)>)>,
1982}
1983/// Complete calibration settings replacement.
1984#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1985#[ts(export)]
1986pub struct CalibrationSettingsParams {
1987 /// The complete calibration settings to store.
1988 pub settings: CalibrationSettings,
1989}
1990/// Mode whose numeric specification should be returned.
1991#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
1992#[ts(export)]
1993pub struct ModeSpecParams {
1994 /// Correction mode: `zero`, `mixed`, `linear` or `ultra`.
1995 pub mode: Mode,
1996 /// Latency limit for the ultra mode, in ms.
1997 pub ultra_ms: Option<f64>,
1998 /// Whether MIMO support paths use FIR instead of IIR.
1999 #[serde(default, skip_serializing_if = "Option::is_none")]
2000 #[ts(optional)]
2001 pub mimo_fir: Option<bool>,
2002}
2003/// Presentation-neutral values underlying the upstream mode specification line.
2004#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
2005#[ts(export)]
2006pub struct ModeSpecResult {
2007 /// Room-correction filters: `iir` (IIR only) or `iir_fir` (IIR plus FIR).
2008 pub rc_filter: String,
2009 /// FIR taps the mode uses (0 without FIR).
2010 pub fir_taps: usize,
2011 /// PEQ bands per channel, when the mode uses IIR.
2012 pub peq_bands: Option<usize>,
2013 /// MIMO support filter kind (`fir` when requested, otherwise `iir`).
2014 pub mimo_filter: String,
2015 /// Delay the FIR may add ahead of the main arrival (`lift_ms`), in ms.
2016 pub lift_ms: f64,
2017 /// Octave fraction of the excess-phase smoothing (6, or 24 in linear and ultra modes).
2018 pub phase_frac: f64,
2019 /// Upper latency bound of the mode, in ms.
2020 pub max_latency_ms: f64,
2021}
2022/// Application theme preference.
2023#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
2024#[serde(rename_all = "snake_case")]
2025#[ts(export)]
2026pub enum AppTheme {
2027 /// Follow the operating-system preference.
2028 #[default]
2029 System,
2030 /// Always use the light theme.
2031 Light,
2032 /// Always use the dark theme.
2033 Dark,
2034}
2035/// The skin set the screen draws with (docs/skins, ADR 0010).
2036#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
2037#[serde(rename_all = "snake_case")]
2038#[ts(export)]
2039pub enum AppSkin {
2040 /// The instrument skin: the default tokens.
2041 #[default]
2042 Default,
2043 /// Hardware Rack: a 19-inch rack faceplate.
2044 Rack,
2045 /// Signal Matrix: a routing board of cells on a grid.
2046 Matrix,
2047}
2048/// The logo on the rail and the window (docs/DEVIATIONS.md U12). The
2049/// installed program's own icon is always `Expert`.
2050#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS, Default)]
2051#[serde(rename_all = "snake_case")]
2052#[ts(export)]
2053pub enum AppIcon {
2054 /// "전문가 모드": upstream's confirmed logo (`logo_b8.svg`).
2055 #[default]
2056 Expert,
2057 /// "킹반인 모드": SECS 2R's own logo (`apps/secs2r/icons/logo/civilian.svg`),
2058 /// a measured response and its correction on the target.
2059 Civilian,
2060}
2061/// Opt-in loopback API settings.
2062#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
2063#[ts(export)]
2064pub struct LocalApiSettings {
2065 /// Whether the app starts the local API server.
2066 pub enabled: bool,
2067 /// Loopback TCP port; zero asks the operating system for a free port.
2068 pub port: u16,
2069}
2070impl Default for LocalApiSettings {
2071 fn default() -> Self {
2072 Self {
2073 enabled: false,
2074 port: crate::local_api::DEFAULT_PORT,
2075 }
2076 }
2077}
2078
2079/// Application-local settings, independent of an open project.
2080#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
2081#[ts(export)]
2082pub struct AppSettings {
2083 /// Application-local compute preference; never stored in an upstream project.
2084 #[serde(default)]
2085 pub compute: ComputePreference,
2086 /// Screen language: `ko` or `en`.
2087 pub language: String,
2088 /// Application theme preference.
2089 #[serde(default)]
2090 pub theme: AppTheme,
2091 /// Logo on the rail and the window.
2092 #[serde(default)]
2093 pub icon: AppIcon,
2094 /// Skin set the screen draws with.
2095 #[serde(default)]
2096 pub skin: AppSkin,
2097 /// Opt-in loopback API server.
2098 #[serde(default)]
2099 pub local_api: LocalApiSettings,
2100 /// Recently opened project paths, newest first (at most 10).
2101 pub recent_projects: Vec<String>,
2102 /// Last window size in logical pixels.
2103 pub last_window_size: Option<(u32, u32)>,
2104}
2105impl Default for AppSettings {
2106 fn default() -> Self {
2107 Self {
2108 language: "ko".into(),
2109 compute: ComputePreference::Auto,
2110 theme: AppTheme::System,
2111 icon: AppIcon::Expert,
2112 skin: AppSkin::Default,
2113 local_api: LocalApiSettings::default(),
2114 recent_projects: Vec::new(),
2115 last_window_size: None,
2116 }
2117 }
2118}
2119/// Complete application-local settings replacement.
2120#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
2121#[ts(export)]
2122pub struct AppSettingsParams {
2123 /// The complete app settings to store.
2124 pub settings: AppSettings,
2125}
2126
2127/// App-facing state of the opt-in local API server.
2128#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
2129#[ts(export)]
2130pub struct LocalApiStatus {
2131 /// Configured enabled state.
2132 pub enabled: bool,
2133 /// Configured port, or the selected free port while running with port zero.
2134 pub port: u16,
2135 /// Whether a listener is currently running.
2136 pub running: bool,
2137 /// Most recent startup failure, when present.
2138 pub error: Option<String>,
2139 /// Loopback base URL.
2140 pub url: String,
2141 /// Current bearer token.
2142 pub token: String,
2143 /// Full token-file path.
2144 pub token_path: String,
2145}
2146
2147/// Why a call failed. The screen maps each code to a written message with the
2148/// cause and the next action.
2149#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
2150#[serde(rename_all = "snake_case")]
2151#[ts(export)]
2152pub enum ErrorCode {
2153 /// The request did not parse or named an unknown method.
2154 InvalidRequest,
2155 /// A bug: the service failed in a way it does not expect.
2156 Internal,
2157 /// The method is registered but not connected yet.
2158 NotImplemented,
2159 /// The method opens a window or program and is unavailable to local API clients.
2160 UiOnly,
2161 /// The call requires an open project.
2162 ProjectNotOpen,
2163 /// Opening, reading, or writing project data failed.
2164 ProjectIo,
2165 /// Another job in the same group is running.
2166 JobBusy,
2167 /// The named job does not exist.
2168 JobNotFound,
2169 /// The caller cancelled the operation.
2170 Cancelled,
2171 /// Project measurements or settings are not valid engine inputs.
2172 EngineInput,
2173 /// Explicit GPU execution was requested but no usable GPU backend is available.
2174 ComputeUnavailable,
2175 /// The requested exporter failed.
2176 ExportFailed,
2177 /// The chosen export cannot carry the result (upstream
2178 /// `filter_export_block`); `params.reason` is an [`ExportBlock`] name.
2179 ExportScope,
2180 /// Cached results no longer match project inputs.
2181 StaleInputs,
2182 /// The audio backend or selected endpoint is unavailable.
2183 DeviceUnavailable,
2184 /// Recording completed but was discarded because it had a gap or corrupt samples.
2185 RecordingFailed,
2186 /// The backend refused a pinned audio share mode.
2187 ShareModeRefused,
2188 /// The REW API cannot be reached.
2189 RewUnreachable,
2190 /// REW requires a Pro license for this operation.
2191 RewProRequired,
2192 /// REW returned an HTTP or schema failure.
2193 RewFailed,
2194 /// A measurement setting or plan field is invalid.
2195 MeasurementInput,
2196 /// Tutorial sessions cannot save or export project data.
2197 TutorialBlocked,
2198 /// A destructive edit needs explicit confirmation while measurements exist.
2199 ConfirmRequired,
2200}
2201/// A coded IPC failure with template parameters and diagnostic detail.
2202#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
2203#[ts(export)]
2204pub struct IpcError {
2205 /// Stable error code translated by the screen.
2206 pub code: ErrorCode,
2207 /// Values for the message template of `code` (file names, counts, ...).
2208 pub params: BTreeMap<String, String>,
2209 /// Whether trying the same call again can succeed.
2210 pub retryable: bool,
2211 /// The raw error text, for the details view and the log only.
2212 pub detail: String,
2213}
2214impl IpcError {
2215 /// Creates a non-retryable error without template parameters.
2216 pub fn new(code: ErrorCode, detail: impl Into<String>) -> Self {
2217 Self {
2218 code,
2219 params: BTreeMap::new(),
2220 retryable: false,
2221 detail: detail.into(),
2222 }
2223 }
2224 /// Adds one screen message-template parameter.
2225 pub fn with_param(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
2226 self.params.insert(key.into(), value.into());
2227 self
2228 }
2229}
2230
2231/// The reply to every call: `{"ok": true, "data": ...}` or
2232/// `{"ok": false, "error": ...}`.
2233///
2234/// The TypeScript side declares the same union in `src/ipc/client.ts`
2235/// (`Envelope`); `envelope_wire_shape` below pins the JSON both sides rely on.
2236#[derive(Debug, Clone, PartialEq)]
2237pub enum Envelope {
2238 /// The `Ok` Envelope variant.
2239 Ok(Box<Response>),
2240 /// The `Err` Envelope variant.
2241 Err(IpcError),
2242}
2243impl Serialize for Envelope {
2244 fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
2245 use serde::ser::SerializeStruct;
2246 let mut state = serializer.serialize_struct("Envelope", 2)?;
2247 match self {
2248 Self::Ok(data) => {
2249 state.serialize_field("ok", &true)?;
2250 state.serialize_field("data", data)?;
2251 }
2252 Self::Err(error) => {
2253 state.serialize_field("ok", &false)?;
2254 state.serialize_field("error", error)?;
2255 }
2256 }
2257 state.end()
2258 }
2259}
2260
2261#[cfg(test)]
2262mod tests {
2263 use super::*;
2264
2265 /// One value of every variant. A new variant fails to compile here until
2266 /// it gets an example, which `method_names_match_the_wire` then checks.
2267 fn examples() -> Vec<Request> {
2268 vec![
2269 Request::Bootstrap,
2270 Request::ProjectNew(ProjectNewParams {
2271 path: "x.secs".into(),
2272 preset: "2.1".into(),
2273 sub_count: 1,
2274 sample: false,
2275 tutorial: false,
2276 }),
2277 Request::ProjectOpen(ProjectPathParams {
2278 path: "x.secs".into(),
2279 }),
2280 Request::ProjectSave(ProjectSaveParams::default()),
2281 Request::ProjectInfo,
2282 Request::SampleLoad(SampleLoadParams::default()),
2283 Request::Calibrate(CalibrateParams::default()),
2284 Request::RecommendXo,
2285 Request::Mimo(MimoParams::default()),
2286 Request::Results,
2287 Request::Export(ExportParams {
2288 kind: ExportKind::CamillaDsp,
2289 folder: ".".into(),
2290 mdat_scope: None,
2291 design_name: None,
2292 camilla_devices: None,
2293 }),
2294 Request::JobCancel(JobCancelParams { job: JobId(1) }),
2295 Request::Jobs,
2296 Request::MeasureMethods,
2297 Request::MeasureConfigure(MeasureConfigureParams::default()),
2298 Request::MeasureConfigGet,
2299 Request::MeasurementRecords,
2300 Request::MicCalibrationGet,
2301 Request::MicCalibrationSet(MicCalibrationSetParams {
2302 path: "mic.txt".into(),
2303 }),
2304 Request::MicCalibrationClear,
2305 Request::MicCalibrationAttach,
2306 Request::LevelsGet,
2307 Request::LevelsFillDefaults,
2308 Request::LevelStop,
2309 Request::MeasurePosition(MeasurePositionParams { position: 1 }),
2310 Request::PositionClear(PositionClearParams { position: 1 }),
2311 Request::Undo(UndoParams { token: "x".into() }),
2312 Request::RewLaunch,
2313 Request::MdatScan(MdatScanParams {
2314 path: "x.mdat".into(),
2315 }),
2316 Request::MdatImport(MdatImportParams {
2317 path: "x.mdat".into(),
2318 assignments: vec![],
2319 position: 1,
2320 }),
2321 Request::ConfigGet,
2322 Request::ConfigApplyPreset(ConfigPresetParams {
2323 preset: "2.1".into(),
2324 confirm: false,
2325 }),
2326 Request::ConfigSetSubCount(ConfigSubCountParams {
2327 count: 2,
2328 confirm: false,
2329 }),
2330 Request::ConfigSetSpeaker(ConfigSetSpeakerParams {
2331 index: 0,
2332 role: Some("L".into()),
2333 size: None,
2334 band_index: Some(0),
2335 out: Some(1),
2336 pol: Some("+".into()),
2337 }),
2338 Request::ConfigAddSpeaker,
2339 Request::ConfigRemoveSpeaker(ConfigIndexParams { index: 0 }),
2340 Request::ConfigRenumber,
2341 Request::ConfigValidate,
2342 Request::PatchSheetCsv(PathParams {
2343 path: "patch.csv".into(),
2344 }),
2345 Request::DspGet,
2346 Request::DspSet(DspSetParams {
2347 preset: Some("tesira".into()),
2348 fields: None,
2349 }),
2350 Request::LayoutGet,
2351 Request::LayoutSet(LayoutSetParams {
2352 count: Some(9),
2353 ..Default::default()
2354 }),
2355 Request::PositionEstimate,
2356 Request::TargetGet,
2357 Request::TargetSetPoints(TargetPointsParams {
2358 points: vec![(20.0, 0.0), (20_000.0, 0.0)],
2359 }),
2360 Request::TargetApplyPreset(TargetPresetParams {
2361 preset: "flat".into(),
2362 }),
2363 Request::TargetSave(PathParams {
2364 path: "target.json".into(),
2365 }),
2366 Request::TargetLoad(PathParams {
2367 path: "target.json".into(),
2368 }),
2369 Request::CalibrationSettingsGet,
2370 Request::CalibrationSettingsEdit(CalibrationSettingsEditParams {
2371 edit: crate::settings_edit::SettingEdit::MimoOn { on: true },
2372 }),
2373 Request::SubWarnings,
2374 Request::RewInfo,
2375 Request::RewDriverSet(RewDriverSetParams {
2376 driver: "ASIO".into(),
2377 }),
2378 Request::CalibrationSettingsSet(CalibrationSettingsParams {
2379 settings: CalibrationSettings::default(),
2380 }),
2381 Request::ModeSpec(ModeSpecParams {
2382 mode: Mode::Mixed,
2383 ultra_ms: None,
2384 mimo_fir: None,
2385 }),
2386 Request::AppSettingsGet,
2387 Request::AppSettingsSet(AppSettingsParams {
2388 settings: AppSettings::default(),
2389 }),
2390 Request::LocalApiStatus,
2391 Request::LocalApiTokenRegenerate,
2392 Request::ComputeStatus,
2393 Request::OpenGpuHelp,
2394 Request::MeasurementCurves(MeasurementCurvesParams::default()),
2395 Request::ResultCurves(ResultCurvesParams {
2396 tab: ResultTab::Spl,
2397 channel: None,
2398 group: None,
2399 xo_hz: None,
2400 corrected: None,
2401 }),
2402 Request::ResultLines,
2403 Request::SubTakeValues,
2404 Request::DialogOpenProject,
2405 Request::DialogSaveProject(DialogSuggestedParams {
2406 suggested: "x.secs".into(),
2407 }),
2408 Request::DialogPickMdat,
2409 Request::DialogPickFolder(DialogPickFolderParams { start: None }),
2410 Request::DialogSaveFile(DialogSaveFileParams {
2411 kind: SaveFileKind::PatchSheet,
2412 suggested: "x.csv".into(),
2413 }),
2414 Request::DialogOpenFile(DialogOpenFileParams {
2415 kind: OpenFileKind::Target,
2416 }),
2417 Request::OpenFolder(OpenFolderParams { path: ".".into() }),
2418 Request::LevelMonitorStart(LevelMonitorStartParams::default()),
2419 Request::LevelMonitorStop,
2420 Request::LevelPlay(LevelPlayParams {
2421 role: "L".into(),
2422 master_dbfs: -20.0,
2423 }),
2424 Request::StatusWatchStart,
2425 Request::StatusWatchStop,
2426 Request::ExportFolderGet,
2427 Request::ExportFolderSet(ExportFolderSetParams { folder: ".".into() }),
2428 ]
2429 }
2430 #[test]
2431 fn method_names_match_the_wire() {
2432 let examples = examples();
2433 assert_eq!(examples.len(), Request::METHODS.len());
2434 for request in examples {
2435 let wire = serde_json::to_value(&request).unwrap();
2436 assert_eq!(wire["method"], request.method());
2437 }
2438 }
2439 #[test]
2440 fn every_method_name_is_listed_and_parses() {
2441 for request in examples() {
2442 let wire = serde_json::to_value(&request).unwrap();
2443 let parsed: Request = serde_json::from_value(wire).unwrap();
2444 assert_eq!(parsed.method(), request.method());
2445 }
2446 }
2447 #[test]
2448 fn old_app_settings_without_local_api_use_the_disabled_default() {
2449 let settings: AppSettings = serde_json::from_str(
2450 r#"{"language":"ko","recent_projects":[],"last_window_size":null}"#,
2451 )
2452 .unwrap();
2453 assert_eq!(settings.local_api, LocalApiSettings::default());
2454 assert!(!settings.local_api.enabled);
2455 assert_eq!(settings.local_api.port, crate::local_api::DEFAULT_PORT);
2456 }
2457
2458 #[test]
2459 fn mdat_scope_is_optional_on_the_wire() {
2460 let old: ExportParams =
2461 serde_json::from_str(r#"{"kind":"before_after_mdat","folder":""}"#).unwrap();
2462 assert_eq!(old.mdat_scope, None);
2463 assert_eq!(old.mdat_scope.unwrap_or_default(), MdatScope::All);
2464 let wire = serde_json::to_value(&old).unwrap();
2465 assert!(wire.get("mdat_scope").is_none());
2466 let scoped = ExportParams {
2467 mdat_scope: Some(MdatScope::Measurements),
2468 design_name: None,
2469 camilla_devices: None,
2470 ..old
2471 };
2472 let wire = serde_json::to_value(&scoped).unwrap();
2473 assert_eq!(wire["mdat_scope"], "measurements");
2474 assert_eq!(
2475 serde_json::from_value::<ExportParams>(wire).unwrap(),
2476 scoped
2477 );
2478 }
2479 #[test]
2480 fn envelope_wire_shape() {
2481 let ok = Envelope::Ok(Box::new(Response::Bootstrap(BootstrapInfo {
2482 app_name: "SECS 2R".into(),
2483 version: "0.0.1".into(),
2484 prerelease: true,
2485 upstream: UpstreamBase {
2486 name: "SECS".into(),
2487 repository: "https://example.invalid/secs".into(),
2488 version: "Beta".into(),
2489 commit: "0".repeat(40),
2490 date: "2026-10-12".into(),
2491 },
2492 platform: Platform {
2493 os: "linux".into(),
2494 arch: "x86_64".into(),
2495 },
2496 })));
2497 let value = serde_json::to_value(ok).unwrap();
2498 assert_eq!(value["ok"], true);
2499 assert_eq!(value["data"]["method"], "bootstrap");
2500 let value = serde_json::to_value(Envelope::Err(IpcError::new(
2501 ErrorCode::InvalidRequest,
2502 "bad",
2503 )))
2504 .unwrap();
2505 assert_eq!(value["ok"], false);
2506 assert_eq!(value["error"]["code"], "invalid_request");
2507 }
2508
2509 #[test]
2510 fn compute_completion_events_are_payload_free_markers() {
2511 for (result, kind) in [
2512 (JobResult::Calibration, "calibration"),
2513 (JobResult::Mimo, "mimo"),
2514 ] {
2515 let event = JobEvent::Finished {
2516 job: JobId(1),
2517 status: JobStatus::Succeeded,
2518 result: Some(Box::new(result)),
2519 error: None,
2520 };
2521 let wire = serde_json::to_vec(&event).unwrap();
2522 let value: serde_json::Value = serde_json::from_slice(&wire).unwrap();
2523 assert_eq!(value["result"], serde_json::json!({ "kind": kind }));
2524 assert!(wire.len() < 128, "completion must not carry a design");
2525 assert_eq!(serde_json::from_slice::<JobEvent>(&wire).unwrap(), event);
2526 }
2527 }
2528
2529 #[test]
2530 fn job_snapshot_is_metadata_without_a_result_payload() {
2531 let snapshot = JobSnapshot {
2532 job: JobId(42),
2533 kind: JobKind::Mimo,
2534 status: JobStatus::Succeeded,
2535 cancellable: false,
2536 progress: None,
2537 error: None,
2538 };
2539 let wire = serde_json::to_value(&snapshot).unwrap();
2540 assert!(wire.get("result").is_none());
2541 assert_eq!(
2542 serde_json::from_value::<JobSnapshot>(wire).unwrap(),
2543 snapshot
2544 );
2545 }
2546
2547 #[test]
2548 fn filter_export_scope_follows_upstream_but_eqapo_carries_mimo_f12() {
2549 use ExportKind::*;
2550 for kind in [
2551 CamillaDsp,
2552 StagedMdat,
2553 BeforeAfterMdat,
2554 EqualizerApo,
2555 Convolution,
2556 ] {
2557 for (subs, mimo) in [(false, false), (true, false), (false, true), (true, true)] {
2558 assert_eq!(filter_export_block(kind, subs, mimo), None, "{kind:?}");
2559 }
2560 }
2561 assert_eq!(filter_export_block(FilterText, false, false), None);
2562 assert_eq!(
2563 export_block(StagedMdat, false, false, true),
2564 Some(ExportBlock::StaleCache)
2565 );
2566 assert_eq!(
2567 export_block(BeforeAfterMdat, true, true, true),
2568 Some(ExportBlock::StaleCache)
2569 );
2570 assert_eq!(export_block(CamillaDsp, true, true, true), None);
2571 assert_eq!(
2572 filter_export_block(FilterText, true, false),
2573 Some(ExportBlock::Subs)
2574 );
2575 assert_eq!(
2576 filter_export_block(FilterText, true, true),
2577 Some(ExportBlock::Subs)
2578 );
2579 assert_eq!(
2580 filter_export_block(FilterText, false, true),
2581 Some(ExportBlock::Mimo)
2582 );
2583 assert_eq!(serde_json::to_value(FilterText).unwrap(), "filter_text");
2584 assert_eq!(serde_json::to_value(EqualizerApo).unwrap(), "equalizer_apo");
2585 assert_eq!(serde_json::to_value(Convolution).unwrap(), "convolution");
2586 assert_eq!(
2587 serde_json::to_value(ExportBlock::Subs).unwrap(),
2588 ExportBlock::Subs.name()
2589 );
2590 assert_eq!(
2591 serde_json::to_value(ExportBlock::Mimo).unwrap(),
2592 ExportBlock::Mimo.name()
2593 );
2594 assert_eq!(
2595 serde_json::to_value(ErrorCode::ExportScope).unwrap(),
2596 "export_scope"
2597 );
2598 }
2599}