From 7915d6ff4dbf9b60aafc5cd82325d7fdb364bc57 Mon Sep 17 00:00:00 2001 From: OpenSauce Date: Mon, 23 Nov 2026 08:54:18 +0000 Subject: [PATCH] feat(nam): make the sample-rate bypass warning prominent Replace the one-line mismatch text with a bordered callout that states the stage is bypassed, shows model and engine rates (with the oversampling factor), explains the dry passthrough and names the setting to change. Mismatched rows in the model list get a tooltip saying so. --- rustortion-ui/src/app.rs | 3 +- .../src/components/nam_browser/view.rs | 122 +++++++++++++++--- rustortion-ui/src/i18n/mod.rs | 30 ++++- 3 files changed, 135 insertions(+), 20 deletions(-) diff --git a/rustortion-ui/src/app.rs b/rustortion-ui/src/app.rs index 24d1e8b..ba9fc4f 100644 --- a/rustortion-ui/src/app.rs +++ b/rustortion-ui/src/app.rs @@ -593,7 +593,8 @@ impl SharedApp { fn view_nam_tab(&self) -> Element<'_, Message> { let ctx = NamViewContext { stages: &self.stages, - engine_sample_rate: self.backend.sample_rate() * self.backend.oversampling_factor(), + device_sample_rate: self.backend.sample_rate(), + oversampling: self.backend.oversampling_factor(), models_dir: self.backend.nam_models_dir(), ir_bypassed: self.ir_cabinet_control.is_bypassed(), chain_full: self.stages.len() >= DEFAULT_CHAIN_CAPACITY, diff --git a/rustortion-ui/src/components/nam_browser/view.rs b/rustortion-ui/src/components/nam_browser/view.rs index ee5d97f..6591e46 100644 --- a/rustortion-ui/src/components/nam_browser/view.rs +++ b/rustortion-ui/src/components/nam_browser/view.rs @@ -15,8 +15,8 @@ use super::tree::{ListRow, leaf_label, model_tree, visible_rows}; use crate::app::{tab_button_active, tab_button_inactive}; use crate::components::widgets::common::{ BORDER_RADIUS_CARD, COLOR_MUTED, COLOR_SUBTLE, COLOR_WARNING, PADDING_NORMAL, PADDING_SMALL, - SPACING_NORMAL, SPACING_TIGHT, TEXT_SIZE_SECTION_TITLE, TEXT_SIZE_SMALL, icon_button, - labeled_slider, section_container, + SPACING_NORMAL, SPACING_TIGHT, TEXT_SIZE_LABEL, TEXT_SIZE_SECTION_TITLE, TEXT_SIZE_SMALL, + icon_button, labeled_slider, section_container, }; use crate::messages::{Message, NamTabMessage}; use crate::stages::{NamMessage, StageConfig, StageMessage}; @@ -28,17 +28,26 @@ const INDENT_PER_LEVEL: f32 = 18.0; const LOADED_ROW_ALPHA: f32 = 0.22; /// Gap between list rows, so neighbouring hover highlights stay apart. const ROW_SPACING: f32 = 2.0; +/// Opacity of the warning tint behind the rate-mismatch callout. +const CALLOUT_TINT_ALPHA: f32 = 0.12; pub struct NamViewContext<'a> { pub stages: &'a [StageConfig], - /// Device rate × oversampling: the rate stages are built at. - pub engine_sample_rate: u32, + pub device_sample_rate: u32, + pub oversampling: u32, pub models_dir: Option, pub ir_bypassed: bool, /// The chain is at `DEFAULT_CHAIN_CAPACITY`. pub chain_full: bool, } +impl NamViewContext<'_> { + /// Device rate × oversampling: the rate stages are built at. + const fn engine_sample_rate(&self) -> u32 { + self.device_sample_rate * self.oversampling + } +} + impl NamBrowser { pub fn view<'a>(&'a self, ctx: &NamViewContext<'a>) -> Element<'a, Message> { let pane = pane_state(ctx.stages, self.focus, |k| registry::get(k).is_some()); @@ -87,7 +96,7 @@ impl NamBrowser { loaded, ) .into_iter() - .map(|r| list_row(r, loaded, ctx.engine_sample_rate, models_clickable)); + .map(|r| list_row(r, loaded, ctx.engine_sample_rate(), models_clickable)); scrollable(column(rows).spacing(ROW_SPACING).width(Length::Fill)) .spacing(SPACING_TIGHT) .height(Length::Fill) @@ -254,7 +263,13 @@ fn model_row<'a>( .spacing(SPACING_NORMAL) .align_y(Alignment::Center); if rate_mismatch { - content = content.push(text(format_khz(rate_hz)).style(text_color(COLOR_WARNING))); + content = content.push(tooltip( + text(format_khz(rate_hz)).style(text_color(COLOR_WARNING)), + container(text(tr!(nam_rate_mismatch_tooltip)).size(TEXT_SIZE_SMALL)) + .padding(PADDING_SMALL) + .style(container::bordered_box), + tooltip::Position::Left, + )); } list_button(content, depth, is_loaded) @@ -349,18 +364,14 @@ fn stage_pane<'a>(ctx: &NamViewContext<'a>, pane: &PaneState) -> Element<'a, Mes if matches!(pane, PaneState::Missing { .. }) { content = content.push(text(tr!(nam_model_not_found)).style(text_color(COLOR_WARNING))); } - // A mismatched model is bypassed (dry passthrough, no resampling): show both rates. if let Some(native) = native_rate - && native.abs_diff(ctx.engine_sample_rate) > 1 + && native.abs_diff(ctx.engine_sample_rate()) > 1 { - content = content.push( - text(format!( - "{}: {native} Hz · {} Hz", - tr!(nam_rate_mismatch_bypassed), - ctx.engine_sample_rate - )) - .style(text_color(COLOR_WARNING)), - ); + content = content.push(rate_mismatch_callout( + native, + ctx.device_sample_rate, + ctx.oversampling, + )); } content = content .push(rule::horizontal(1)) @@ -379,6 +390,70 @@ fn stage_pane<'a>(ctx: &NamViewContext<'a>, pane: &PaneState) -> Element<'a, Mes .into() } +/// The engine passes a mismatched model through dry (no resampling): say so loudly, +/// with both rates and the setting that would make it run. +fn rate_mismatch_callout<'a>( + native: u32, + device_rate: u32, + oversampling: u32, +) -> Element<'a, Message> { + let engine = if oversampling > 1 { + format!( + "{} ({} × {oversampling})", + format_khz(device_rate * oversampling), + format_khz(device_rate) + ) + } else { + format_khz(device_rate) + }; + let line = |label: &str, value: String| text(format!("{label}: {value}")).size(TEXT_SIZE_SMALL); + container( + column![ + text(tr!(nam_rate_mismatch_title)) + .size(TEXT_SIZE_LABEL) + .style(text_color(COLOR_WARNING)), + line(tr!(nam_rate_model), format_khz(native)), + line(tr!(nam_rate_engine), engine), + text(tr!(nam_rate_mismatch_explain)) + .size(TEXT_SIZE_SMALL) + .style(text_color(COLOR_SUBTLE)), + text(rate_fix(native, device_rate, oversampling)).size(TEXT_SIZE_SMALL), + ] + .spacing(SPACING_TIGHT), + ) + .width(Length::Fill) + .padding(PADDING_NORMAL) + .style(|_| { + container::Style::default() + .background(Color { + a: CALLOUT_TINT_ALPHA, + ..COLOR_WARNING + }) + .border( + Border::default() + .color(COLOR_WARNING) + .width(1.0) + .rounded(BORDER_RADIUS_CARD), + ) + }) + .into() +} + +/// The settings change that makes `native` the engine rate. +fn rate_fix(native: u32, device_rate: u32, oversampling: u32) -> String { + let device = format!("{} {}", tr!(nam_rate_fix_device), format_khz(native)); + let fix = match (oversampling > 1, native.abs_diff(device_rate) <= 1) { + (true, true) => tr!(nam_rate_fix_oversampling).to_owned(), + (true, false) => format!( + "{device}{}{}", + tr!(nam_rate_fix_and), + tr!(nam_rate_fix_oversampling) + ), + (false, _) => device, + }; + format!("{}{fix}", tr!(nam_rate_fix_prefix)) +} + fn no_stage_message<'a>(chain_full: bool) -> Element<'a, Message> { let hint = if chain_full { tr!(nam_chain_full) @@ -592,6 +667,21 @@ fn detail_rows<'a>(info: Option<&ModelInfo>, native_rate: u32) -> Element<'a, Me mod tests { use super::*; + #[test] + fn rate_fix_names_the_setting_that_is_off() { + let fix = |n, d, o| rate_fix(n, d, o); + // Oversampling alone pushed a matching device past the model's rate. + assert!(fix(48_000, 48_000, 2).contains(tr!(nam_rate_fix_oversampling))); + assert!(!fix(48_000, 48_000, 2).contains(tr!(nam_rate_fix_device))); + // No oversampling: only the device rate is wrong. + let device_only = fix(44_100, 48_000, 1); + assert!(device_only.contains("44.1 kHz")); + assert!(!device_only.contains(tr!(nam_rate_fix_oversampling))); + // Both are wrong. + let both = fix(44_100, 48_000, 2); + assert!(both.contains("44.1 kHz") && both.contains(tr!(nam_rate_fix_oversampling))); + } + #[test] fn rates_are_shown_in_khz_without_trailing_zeros() { assert_eq!(format_khz(44_100), "44.1 kHz"); diff --git a/rustortion-ui/src/i18n/mod.rs b/rustortion-ui/src/i18n/mod.rs index aa46cf8..7b7c25e 100644 --- a/rustortion-ui/src/i18n/mod.rs +++ b/rustortion-ui/src/i18n/mod.rs @@ -182,7 +182,15 @@ pub struct Translations { pub stage_tremolo: &'static str, pub stage_nam: &'static str, pub nam_native_rate: &'static str, - pub nam_rate_mismatch_bypassed: &'static str, + pub nam_rate_mismatch_title: &'static str, + pub nam_rate_mismatch_explain: &'static str, + pub nam_rate_mismatch_tooltip: &'static str, + pub nam_rate_model: &'static str, + pub nam_rate_engine: &'static str, + pub nam_rate_fix_prefix: &'static str, + pub nam_rate_fix_device: &'static str, + pub nam_rate_fix_and: &'static str, + pub nam_rate_fix_oversampling: &'static str, pub nam_model_not_found: &'static str, pub nam_input_gain: &'static str, pub nam_output_gain: &'static str, @@ -411,7 +419,15 @@ pub static EN: Translations = Translations { stage_tremolo: "Tremolo", stage_nam: "NAM", nam_native_rate: "Native rate", - nam_rate_mismatch_bypassed: "Bypassed — model rate vs engine rate", + nam_rate_mismatch_title: "BYPASSED: sample rate mismatch", + nam_rate_mismatch_explain: "NAM models are not resampled, so this stage passes the dry signal through unchanged.", + nam_rate_mismatch_tooltip: "Different rate from the engine: this model would be bypassed", + nam_rate_model: "Model", + nam_rate_engine: "Engine", + nam_rate_fix_prefix: "To use it: ", + nam_rate_fix_device: "set the audio device to", + nam_rate_fix_and: " and ", + nam_rate_fix_oversampling: "set oversampling to 1×", nam_model_not_found: "Model not found", nam_input_gain: "Input", nam_output_gain: "Output", @@ -631,7 +647,15 @@ pub static ZH_CN: Translations = Translations { stage_tremolo: "颤音", stage_nam: "NAM", nam_native_rate: "原始采样率", - nam_rate_mismatch_bypassed: "已旁通 — 模型采样率 vs 引擎采样率", + nam_rate_mismatch_title: "已旁通:采样率不匹配", + nam_rate_mismatch_explain: "NAM 模型不会被重采样,因此该模块会直接输出未处理的干信号。", + nam_rate_mismatch_tooltip: "与引擎采样率不同:该模型将被旁通", + nam_rate_model: "模型", + nam_rate_engine: "引擎", + nam_rate_fix_prefix: "启用方法:", + nam_rate_fix_device: "将音频设备设为", + nam_rate_fix_and: ",并", + nam_rate_fix_oversampling: "将过采样设为 1×", nam_model_not_found: "未找到模型", nam_input_gain: "输入", nam_output_gain: "输出",