forge
Explore
Log in

Don't you dare go Hollow

The project's sound rate gets a picker beside its two siblings

Browse files at this commit

2c88d10ecb779f526a0a9001934cf3e6ec88204aAhmet Kaan GümüşParent: 3a2e5ea
  • feat
    • the project's sound rate gets a picker beside its two siblings
Show full message
✨ feat(app): the project's sound rate gets a picker beside its two siblings

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.rsmodified+36 -0
@@ -30,6 +30,42 @@ pub(crate) const FRAME_RATES: [f64; 8] = [
30 60.,30 60.,
31 ];31 ];
32 32
33+/// The project sound rates the list offers, slowest first. Unlike
34+/// [`RESOLUTIONS`] and [`FRAME_RATES`] there is no media rate to cycle in
35+/// beside them: a source's own rate is not a number this list has to name to
36+/// offer it, since [`Choice::SampleRate`]`(None)` -- "source" -- already means
37+/// exactly that, whatever the number turns out to be.
38+pub(crate) const SAMPLE_RATES: [u32; 3] = [44_100, 48_000, 96_000];
39+
40+/// The sound-rate list's rows: "source" first -- the derived rate, and the
41+/// row in force with nothing picked -- then every rate on offer, the one in
42+/// force marked. The same rows serve [`Pick::SampleRate`] with a session and
43+/// without one: `current` is [`PlaybackSession::sample_rate`] or
44+/// [`Player::pending_settings`]`.2`, and `None` means the same thing either
45+/// way -- nothing picked yet.
46+pub(crate) fn sample_rate_choices(current: Option<u32>) -> Vec<ChoiceRow> {
47+ let mut rows = vec![(
48+ Choice::SampleRate(None),
49+ "Source".into(),
50+ "the first audio source's own rate".into(),
51+ current.is_none(),
52+ )];
53+ rows.extend(SAMPLE_RATES.into_iter().map(|rate| {
54+ (
55+ Choice::SampleRate(Some(rate)),
56+ format!("{rate} Hz").into(),
57+ match rate {
58+ 48_000 => "video standard".to_string(),
59+ 44_100 => "CD/audio standard".to_string(),
60+ _ => "high-resolution".to_string(),
61+ }
62+ .into(),
63+ current == Some(rate),
64+ )
65+ }));
66+ rows
67+}
68+
33 /// What the export card offers, top to bottom. Bitrate is the only thing the69 /// What the export card offers, top to bottom. Bitrate is the only thing the
34 /// encoder actually takes: the codec and the container are what this program70 /// encoder actually takes: the codec and the container are what this program
35 /// can write and nothing else, so the card states them rather than offering71 /// can write and nothing else, so the card states them rather than offering
crates/app/src/main.rsmodified+2 -2
@@ -81,7 +81,7 @@ struct Player {
81 /// the moment the first session exists, and cleared there: consumed once,81 /// the moment the first session exists, and cleared there: consumed once,
82 /// the way a project's own saved settings are read once at82 /// the way a project's own saved settings are read once at
83 /// [`engine::PlaybackSession::open_project`].83 /// [`engine::PlaybackSession::open_project`].
84- pending_settings: (Option<(u32, u32)>, Option<f64>),84+ pending_settings: (Option<(u32, u32)>, Option<f64>, Option<u32>),
85 /// A library row's own file, opened and playing in place of the85 /// A library row's own file, opened and playing in place of the
86 /// timeline's picture, and never written to `session` or its undo stack:86 /// timeline's picture, and never written to `session` or its undo stack:
87 /// a preview is watched, not edited. `Some` is what [`Player::pump`] and87 /// a preview is watched, not edited. `Some` is what [`Player::pump`] and
@@ -713,7 +713,7 @@ fn main() {
713 seek_since: None,713 seek_since: None,
714 resynced: None,714 resynced: None,
715 session: None,715 session: None,
716- pending_settings: (None, None),716+ pending_settings: (None, None, None),
717 preview_session: None,717 preview_session: None,
718 preview_playing: false,718 preview_playing: false,
719 // Full and unmuted, which is what the session it was just719 // Full and unmuted, which is what the session it was just
crates/app/src/menus.rsmodified+7 -0
@@ -49,6 +49,10 @@ pub(crate) struct Picker {
49 pub(crate) enum Pick {49 pub(crate) enum Pick {
50 Resolution,50 Resolution,
51 Fps,51 Fps,
52+ /// The rate the project's own mix runs at
53+ /// ([`engine::PlaybackSession::set_sample_rate`]). Opened from the panel,
54+ /// beside the resolution and rate it shares a row style with.
55+ SampleRate,
52 Fit(Lane, usize),56 Fit(Lane, usize),
53 /// What the export's *sound* is coded at. Opened from the card's Sound row,57 /// What the export's *sound* is coded at. Opened from the card's Sound row,
54 /// which is the only place it means anything.58 /// which is the only place it means anything.
@@ -77,6 +81,9 @@ pub(crate) enum Pick {
77 pub(crate) enum Choice {81 pub(crate) enum Choice {
78 Size(u32, u32),82 Size(u32, u32),
79 Fps(f64),83 Fps(f64),
84+ /// `None` is "source" -- the rate derived from the first audio source,
85+ /// [`engine::PlaybackSession::set_sample_rate`]'s own default.
86+ SampleRate(Option<u32>),
80 Fit(Lane, usize, FitPolicy),87 Fit(Lane, usize, FitPolicy),
81 AudioRate(u32),88 AudioRate(u32),
82 Tone(Preset),89 Tone(Preset),
crates/app/src/player/cards.rsmodified+31 -0
@@ -76,6 +76,34 @@ impl Player {
76 cx.notify();76 cx.notify();
77 }77 }
78 78
79+ /// The project's mix cut at another rate: the list names one and this is
80+ /// where it happens, the way [`apply_resolution`](Self::apply_resolution)
81+ /// is for a size. Nothing to reseek here -- unlike a resolution or a rate,
82+ /// this touches no picture and re-times nothing -- so the notice says the
83+ /// truth about when it is heard: the next time the sound is rebuilt (a
84+ /// seek, an edit, a reopen), not the stream already playing
85+ /// ([`engine::PlaybackSession::set_sample_rate`]).
86+ pub(crate) fn apply_sample_rate(&mut self, rate: Option<u32>, cx: &mut Context<Self>) {
87+ let label = |rate: Option<u32>| rate.map_or("the source's own rate".to_string(), |r| format!("{r} Hz"));
88+ if let Some(session) = &mut self.session {
89+ session.set_sample_rate(rate);
90+ self.notify_user(
91+ format!(
92+ "PROJECT SOUND: {} — takes effect on the next seek, edit or reopen",
93+ label(rate)
94+ )
95+ .into(),
96+ );
97+ } else {
98+ self.pending_settings.2 = rate;
99+ self.notify_user(
100+ format!("PROJECT SOUND: {} — takes effect on the next file opened", label(rate))
101+ .into(),
102+ );
103+ }
104+ cx.notify();
105+ }
106+
79 /// The project's HDR media shown another way: the list names a rendition and107 /// The project's HDR media shown another way: the list names a rendition and
80 /// this is where it happens, the way [`apply_resolution`](Self::apply_resolution)108 /// this is where it happens, the way [`apply_resolution`](Self::apply_resolution)
81 /// is for a size. The engine remaps the frame under the playhead at once109 /// is for a size. The engine remaps the frame under the playhead at once
@@ -117,6 +145,7 @@ impl Player {
117 match choice {145 match choice {
118 Choice::Size(w, h) => self.apply_resolution(w, h, cx),146 Choice::Size(w, h) => self.apply_resolution(w, h, cx),
119 Choice::Fps(fps) => self.apply_frame_rate(fps, cx),147 Choice::Fps(fps) => self.apply_frame_rate(fps, cx),
148+ Choice::SampleRate(rate) => self.apply_sample_rate(rate, cx),
120 Choice::Fit(lane, idx, fit) => self.apply_fit(lane, idx, fit, cx),149 Choice::Fit(lane, idx, fit) => self.apply_fit(lane, idx, fit, cx),
121 Choice::Tone(preset) => self.apply_tone(preset, cx),150 Choice::Tone(preset) => self.apply_tone(preset, cx),
122 // The project's, like the tone map above and unlike the palette151 // The project's, like the tone map above and unlike the palette
@@ -175,6 +204,7 @@ impl Player {
175 return match of {204 return match of {
176 Pick::Resolution => pending_resolution_choices(self.pending_settings.0),205 Pick::Resolution => pending_resolution_choices(self.pending_settings.0),
177 Pick::Fps => pending_fps_choices(self.pending_settings.1),206 Pick::Fps => pending_fps_choices(self.pending_settings.1),
207+ Pick::SampleRate => sample_rate_choices(self.pending_settings.2),
178 _ => Vec::new(),208 _ => Vec::new(),
179 };209 };
180 };210 };
@@ -183,6 +213,7 @@ impl Player {
183 resolution_choices(session.resolution(), session.native_resolution())213 resolution_choices(session.resolution(), session.native_resolution())
184 }214 }
185 Pick::Fps => fps_choices(session.meta().frame_rate, session.native_frame_rate()),215 Pick::Fps => fps_choices(session.meta().frame_rate, session.native_frame_rate()),
216+ Pick::SampleRate => sample_rate_choices(session.sample_rate()),
186 Pick::Fit(lane, idx) => {217 Pick::Fit(lane, idx) => {
187 fit_choices(lane, idx, session.fit_of(lane, idx), session.resolution())218 fit_choices(lane, idx, session.fit_of(lane, idx), session.resolution())
188 }219 }
crates/app/src/player/library.rsmodified+4 -1
@@ -949,6 +949,9 @@ impl Player {
949 if let Some(fps) = self.pending_settings.1.take() {949 if let Some(fps) = self.pending_settings.1.take() {
950 session.set_frame_rate(fps);950 session.set_frame_rate(fps);
951 }951 }
952+ if let Some(rate) = self.pending_settings.2.take() {
953+ session.set_sample_rate(Some(rate));
954+ }
952 self.fps = session.meta().frame_rate;955 self.fps = session.meta().frame_rate;
953 // This window *is* the real-time viewer: a picture already past956 // This window *is* the real-time viewer: a picture already past
954 // the clock is one `pump` takes off the channel and throws away,957 // the clock is one `pump` takes off the channel and throws away,
@@ -1231,7 +1234,7 @@ impl Player {
1231 // A `.edith` carries its own saved size and rate, read at1234 // A `.edith` carries its own saved size and rate, read at
1232 // [`engine::PlaybackSession::open_project`] -- a pick made1235 // [`engine::PlaybackSession::open_project`] -- a pick made
1233 // before this project loaded is not this project's.1236 // before this project loaded is not this project's.
1234- self.pending_settings = (None, None);1237+ self.pending_settings = (None, None, None);
1235 self.fps = session.meta().frame_rate;1238 self.fps = session.meta().frame_rate;
1236 // As at the file door above: the window watches in real time.1239 // As at the file door above: the window watches in real time.
1237 session.drop_late_pictures(true);1240 session.drop_late_pictures(true);
crates/app/src/tests/cards.rsmodified+27 -0
@@ -1277,6 +1277,33 @@ fn the_resolution_and_rate_lists_work_before_any_file_is_open() {
1277 assert!(picked[3].3);1277 assert!(picked[3].3);
1278 }1278 }
1279 1279
1280+/// The sample-rate list: "source" first and marked whenever nothing is
1281+/// picked -- true both before any file is open ([`Player::pending_settings`])
1282+/// and once a session exists with no override ([`PlaybackSession::sample_rate`]
1283+/// returning `None`) -- then every offered rate, exactly one marked once one
1284+/// is picked.
1285+#[test]
1286+fn the_sample_rate_list_marks_source_with_nothing_picked() {
1287+ let none = sample_rate_choices(None);
1288+ assert_eq!(none.len(), SAMPLE_RATES.len() + 1);
1289+ assert_eq!(none[0].0, Choice::SampleRate(None));
1290+ assert!(none[0].3, "source is the row in force with nothing picked");
1291+ assert_eq!(
1292+ none.iter().filter(|(.., picked)| *picked).count(),
1293+ 1,
1294+ "exactly one row marked"
1295+ );
1296+ for ((choice, label, ..), rate) in none.iter().skip(1).zip(SAMPLE_RATES) {
1297+ assert_eq!(*choice, Choice::SampleRate(Some(rate)));
1298+ assert_eq!(label.as_ref(), format!("{rate} Hz"));
1299+ }
1300+
1301+ let picked = sample_rate_choices(Some(SAMPLE_RATES[1]));
1302+ assert!(!picked[0].3, "source no longer in force");
1303+ assert_eq!(picked.iter().filter(|(.., picked)| *picked).count(), 1);
1304+ assert!(picked[2].3);
1305+}
1306+
1280 #[test]1307 #[test]
1281 fn the_export_card_fits_the_smallest_window() {1308 fn the_export_card_fits_the_smallest_window() {
1282 // Same 640x360 floor the keybindings card is measured against: the1309 // Same 640x360 floor the keybindings card is measured against: the
crates/app/src/tests/mod.rsmodified+2 -1
@@ -49,7 +49,8 @@ use super::{
49 IMPORT_STALL, Import, ImportStage, SEEK_STALL, ScanKey, ScanPlan, SilenceScan, import_line,49 IMPORT_STALL, Import, ImportStage, SEEK_STALL, ScanKey, ScanPlan, SilenceScan, import_line,
50 Landing, arrival, launch_queue, full_scan_key, silence_cached, slice_whole_levels,50 Landing, arrival, launch_queue, full_scan_key, silence_cached, slice_whole_levels,
51 read_ahead, scan_plan, seek_line, silence_line, source_secs, stash_or_write,51 read_ahead, scan_plan, seek_line, silence_line, source_secs, stash_or_write,
52- repeats, resolution_choices, resolution_ladder, pending_resolution_choices, pending_fps_choices, span_label, tone_choices, tone_label,52+ repeats, resolution_choices, resolution_ladder, pending_resolution_choices, pending_fps_choices,
53+ SAMPLE_RATES, sample_rate_choices, span_label, tone_choices, tone_label,
53 clip_width, frames_of_us, trimmed_clip, trimmed_sub, trims, unscannable, unusable,54 clip_width, frames_of_us, trimmed_clip, trimmed_sub, trims, unscannable, unusable,
54 visible_slice,55 visible_slice,
55 };56 };
crates/app/src/ui/inspector.rsmodified+16 -0
@@ -309,6 +309,22 @@ impl Player {
309 this.open_picker(Pick::Fps, event.position(), cx)309 this.open_picker(Pick::Fps, event.position(), cx)
310 }),310 }),
311 ))311 ))
312+ .child(self.action_control(
313+ "sample-rate",
314+ ZOOM_SLOT_W,
315+ BG_RAISED(),
316+ None,
317+ match self.session.as_ref().map_or(self.pending_settings.2, |s| s.sample_rate()) {
318+ Some(rate) => format!("{rate} Hz"),
319+ None => "Source".to_string(),
320+ },
321+ "the rate the project's own sound mix is run at; source derives it from \
322+ the first audio source",
323+ ActionId::Resolution,
324+ cx.listener(|this, event: &ClickEvent, _, cx| {
325+ this.open_picker(Pick::SampleRate, event.position(), cx)
326+ }),
327+ ))
312 .child(self.action_control(328 .child(self.action_control(
313 "tonemap",329 "tonemap",
314 TONE_SLOT_W,330 TONE_SLOT_W,