From 2c88d10ecb779f526a0a9001934cf3e6ec88204a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 19 Aug 2026 22:25:38 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(app):=20the=20project's=20soun?= =?UTF-8?q?d=20rate=20gets=20a=20picker=20beside=20its=20two=20siblings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolution and rate have long had a card row and a stroke; the mix's own sample rate (engine already honours it end to end) had neither. Wires PlaybackSession::sample_rate/set_sample_rate through a third pending_settings slot, a SampleRate pick/choice, and a project-panel row next to Size and Rate -- reachable before any file is open the same way the other two are. --- crates/app/src/export_ui.rs | 36 ++++++++++++++++++++++++++++++++ crates/app/src/main.rs | 4 ++-- crates/app/src/menus.rs | 7 +++++++ crates/app/src/player/cards.rs | 31 +++++++++++++++++++++++++++ crates/app/src/player/library.rs | 5 ++++- crates/app/src/tests/cards.rs | 27 ++++++++++++++++++++++++ crates/app/src/tests/mod.rs | 3 ++- crates/app/src/ui/inspector.rs | 16 ++++++++++++++ 8 files changed, 125 insertions(+), 4 deletions(-) diff --git a/crates/app/src/export_ui.rs b/crates/app/src/export_ui.rs index d2174a0..a675131 100644 --- a/crates/app/src/export_ui.rs +++ b/crates/app/src/export_ui.rs @@ -30,6 +30,42 @@ pub(crate) const FRAME_RATES: [f64; 8] = [ 60., ]; +/// The project sound rates the list offers, slowest first. Unlike +/// [`RESOLUTIONS`] and [`FRAME_RATES`] there is no media rate to cycle in +/// beside them: a source's own rate is not a number this list has to name to +/// offer it, since [`Choice::SampleRate`]`(None)` -- "source" -- already means +/// exactly that, whatever the number turns out to be. +pub(crate) const SAMPLE_RATES: [u32; 3] = [44_100, 48_000, 96_000]; + +/// The sound-rate list's rows: "source" first -- the derived rate, and the +/// row in force with nothing picked -- then every rate on offer, the one in +/// force marked. The same rows serve [`Pick::SampleRate`] with a session and +/// without one: `current` is [`PlaybackSession::sample_rate`] or +/// [`Player::pending_settings`]`.2`, and `None` means the same thing either +/// way -- nothing picked yet. +pub(crate) fn sample_rate_choices(current: Option) -> Vec { + let mut rows = vec![( + Choice::SampleRate(None), + "Source".into(), + "the first audio source's own rate".into(), + current.is_none(), + )]; + rows.extend(SAMPLE_RATES.into_iter().map(|rate| { + ( + Choice::SampleRate(Some(rate)), + format!("{rate} Hz").into(), + match rate { + 48_000 => "video standard".to_string(), + 44_100 => "CD/audio standard".to_string(), + _ => "high-resolution".to_string(), + } + .into(), + current == Some(rate), + ) + })); + rows +} + /// What the export card offers, top to bottom. Bitrate is the only thing the /// encoder actually takes: the codec and the container are what this program /// can write and nothing else, so the card states them rather than offering diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 89a6576..2e1e893 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -81,7 +81,7 @@ struct Player { /// the moment the first session exists, and cleared there: consumed once, /// the way a project's own saved settings are read once at /// [`engine::PlaybackSession::open_project`]. - pending_settings: (Option<(u32, u32)>, Option), + pending_settings: (Option<(u32, u32)>, Option, Option), /// A library row's own file, opened and playing in place of the /// timeline's picture, and never written to `session` or its undo stack: /// a preview is watched, not edited. `Some` is what [`Player::pump`] and @@ -713,7 +713,7 @@ fn main() { seek_since: None, resynced: None, session: None, - pending_settings: (None, None), + pending_settings: (None, None, None), preview_session: None, preview_playing: false, // Full and unmuted, which is what the session it was just diff --git a/crates/app/src/menus.rs b/crates/app/src/menus.rs index f3520b2..7845172 100644 --- a/crates/app/src/menus.rs +++ b/crates/app/src/menus.rs @@ -49,6 +49,10 @@ pub(crate) struct Picker { pub(crate) enum Pick { Resolution, Fps, + /// The rate the project's own mix runs at + /// ([`engine::PlaybackSession::set_sample_rate`]). Opened from the panel, + /// beside the resolution and rate it shares a row style with. + SampleRate, Fit(Lane, usize), /// What the export's *sound* is coded at. Opened from the card's Sound row, /// which is the only place it means anything. @@ -77,6 +81,9 @@ pub(crate) enum Pick { pub(crate) enum Choice { Size(u32, u32), Fps(f64), + /// `None` is "source" -- the rate derived from the first audio source, + /// [`engine::PlaybackSession::set_sample_rate`]'s own default. + SampleRate(Option), Fit(Lane, usize, FitPolicy), AudioRate(u32), Tone(Preset), diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index 198b9dd..0cc9571 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -76,6 +76,34 @@ impl Player { cx.notify(); } + /// The project's mix cut at another rate: the list names one and this is + /// where it happens, the way [`apply_resolution`](Self::apply_resolution) + /// is for a size. Nothing to reseek here -- unlike a resolution or a rate, + /// this touches no picture and re-times nothing -- so the notice says the + /// truth about when it is heard: the next time the sound is rebuilt (a + /// seek, an edit, a reopen), not the stream already playing + /// ([`engine::PlaybackSession::set_sample_rate`]). + pub(crate) fn apply_sample_rate(&mut self, rate: Option, cx: &mut Context) { + let label = |rate: Option| rate.map_or("the source's own rate".to_string(), |r| format!("{r} Hz")); + if let Some(session) = &mut self.session { + session.set_sample_rate(rate); + self.notify_user( + format!( + "PROJECT SOUND: {} — takes effect on the next seek, edit or reopen", + label(rate) + ) + .into(), + ); + } else { + self.pending_settings.2 = rate; + self.notify_user( + format!("PROJECT SOUND: {} — takes effect on the next file opened", label(rate)) + .into(), + ); + } + cx.notify(); + } + /// The project's HDR media shown another way: the list names a rendition and /// this is where it happens, the way [`apply_resolution`](Self::apply_resolution) /// is for a size. The engine remaps the frame under the playhead at once @@ -117,6 +145,7 @@ impl Player { match choice { Choice::Size(w, h) => self.apply_resolution(w, h, cx), Choice::Fps(fps) => self.apply_frame_rate(fps, cx), + Choice::SampleRate(rate) => self.apply_sample_rate(rate, cx), Choice::Fit(lane, idx, fit) => self.apply_fit(lane, idx, fit, cx), Choice::Tone(preset) => self.apply_tone(preset, cx), // The project's, like the tone map above and unlike the palette @@ -175,6 +204,7 @@ impl Player { return match of { Pick::Resolution => pending_resolution_choices(self.pending_settings.0), Pick::Fps => pending_fps_choices(self.pending_settings.1), + Pick::SampleRate => sample_rate_choices(self.pending_settings.2), _ => Vec::new(), }; }; @@ -183,6 +213,7 @@ impl Player { resolution_choices(session.resolution(), session.native_resolution()) } Pick::Fps => fps_choices(session.meta().frame_rate, session.native_frame_rate()), + Pick::SampleRate => sample_rate_choices(session.sample_rate()), Pick::Fit(lane, idx) => { fit_choices(lane, idx, session.fit_of(lane, idx), session.resolution()) } diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index 5bcd688..2fad9fc 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -949,6 +949,9 @@ impl Player { if let Some(fps) = self.pending_settings.1.take() { session.set_frame_rate(fps); } + if let Some(rate) = self.pending_settings.2.take() { + session.set_sample_rate(Some(rate)); + } self.fps = session.meta().frame_rate; // This window *is* the real-time viewer: a picture already past // the clock is one `pump` takes off the channel and throws away, @@ -1231,7 +1234,7 @@ impl Player { // A `.edith` carries its own saved size and rate, read at // [`engine::PlaybackSession::open_project`] -- a pick made // before this project loaded is not this project's. - self.pending_settings = (None, None); + self.pending_settings = (None, None, None); self.fps = session.meta().frame_rate; // As at the file door above: the window watches in real time. session.drop_late_pictures(true); diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index ae6407c..43eb649 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -1277,6 +1277,33 @@ fn the_resolution_and_rate_lists_work_before_any_file_is_open() { assert!(picked[3].3); } +/// The sample-rate list: "source" first and marked whenever nothing is +/// picked -- true both before any file is open ([`Player::pending_settings`]) +/// and once a session exists with no override ([`PlaybackSession::sample_rate`] +/// returning `None`) -- then every offered rate, exactly one marked once one +/// is picked. +#[test] +fn the_sample_rate_list_marks_source_with_nothing_picked() { + let none = sample_rate_choices(None); + assert_eq!(none.len(), SAMPLE_RATES.len() + 1); + assert_eq!(none[0].0, Choice::SampleRate(None)); + assert!(none[0].3, "source is the row in force with nothing picked"); + assert_eq!( + none.iter().filter(|(.., picked)| *picked).count(), + 1, + "exactly one row marked" + ); + for ((choice, label, ..), rate) in none.iter().skip(1).zip(SAMPLE_RATES) { + assert_eq!(*choice, Choice::SampleRate(Some(rate))); + assert_eq!(label.as_ref(), format!("{rate} Hz")); + } + + let picked = sample_rate_choices(Some(SAMPLE_RATES[1])); + assert!(!picked[0].3, "source no longer in force"); + assert_eq!(picked.iter().filter(|(.., picked)| *picked).count(), 1); + assert!(picked[2].3); +} + #[test] fn the_export_card_fits_the_smallest_window() { // Same 640x360 floor the keybindings card is measured against: the diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index b074cfb..73f7363 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -49,7 +49,8 @@ use super::{ IMPORT_STALL, Import, ImportStage, SEEK_STALL, ScanKey, ScanPlan, SilenceScan, import_line, Landing, arrival, launch_queue, full_scan_key, silence_cached, slice_whole_levels, read_ahead, scan_plan, seek_line, silence_line, source_secs, stash_or_write, - repeats, resolution_choices, resolution_ladder, pending_resolution_choices, pending_fps_choices, span_label, tone_choices, tone_label, + repeats, resolution_choices, resolution_ladder, pending_resolution_choices, pending_fps_choices, + SAMPLE_RATES, sample_rate_choices, span_label, tone_choices, tone_label, clip_width, frames_of_us, trimmed_clip, trimmed_sub, trims, unscannable, unusable, visible_slice, }; diff --git a/crates/app/src/ui/inspector.rs b/crates/app/src/ui/inspector.rs index 7fdd851..f31866b 100644 --- a/crates/app/src/ui/inspector.rs +++ b/crates/app/src/ui/inspector.rs @@ -309,6 +309,22 @@ impl Player { this.open_picker(Pick::Fps, event.position(), cx) }), )) + .child(self.action_control( + "sample-rate", + ZOOM_SLOT_W, + BG_RAISED(), + None, + match self.session.as_ref().map_or(self.pending_settings.2, |s| s.sample_rate()) { + Some(rate) => format!("{rate} Hz"), + None => "Source".to_string(), + }, + "the rate the project's own sound mix is run at; source derives it from \ + the first audio source", + ActionId::Resolution, + cx.listener(|this, event: &ClickEvent, _, cx| { + this.open_picker(Pick::SampleRate, event.position(), cx) + }), + )) .child(self.action_control( "tonemap", TONE_SLOT_W,