FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
#172: Sequence Settings… opens Premiere's dialog (General, Color Management, VR Properties)
swillunderscore87bb39f5f55b
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 461aa36ea..1616f1164 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -130,6 +130,8 @@ pub enum Dialog {DeleteTracks,/// Sequence ▸ Add Tracks….AddTracks,+ /// Sequence ▸ Sequence Settings….+ SequenceSettings,}#[derive(Default)]diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex a02ecbf9b..011908939 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -351,6 +351,13 @@ pub fn invoke(app: &mut FilmcraftApp, ctx: &egui::Context, id: &str, params: Valapp.dialog = Some(crate::Dialog::DeleteTracks);return Ok(json!({"dialog": "deleteTracks"}));}+ // Sequence Settings… from the menu opens the dialog; with params the engine command applies+ // them directly.+ "sequence.settings" if params.as_object().is_none_or(|m| m.is_empty()) => {+ filmcraft_engine::find_command(id).map_or(Ok(()), |c| (c.enabled)(&app.session))?;+ crate::panels::sequence_settings::open(app);+ return Ok(json!({"dialog": "sequenceSettings"}));+ }"sequence.colorSettings" if params.as_object().is_none_or(|m| m.is_empty()) => {filmcraft_engine::find_command(id).map_or(Ok(()), |c| (c.enabled)(&app.session))?;crate::panels::color_dialogs::open_sequence(app);diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rsindex 46136e79c..4fc28ffc9 100644--- a/crates/ui-egui/src/panels/dialogs.rs+++ b/crates/ui-egui/src/panels/dialogs.rs@@ -65,6 +65,12 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {}return;}+ Dialog::SequenceSettings => {+ if !crate::panels::sequence_settings::show(app, ctx) && app.dialog == Some(d) {+ app.dialog = None;+ }+ return;+ }Dialog::NewSequence | Dialog::Preferences | Dialog::Recovery | Dialog::RevertConfirm => {}}if !open {diff --git a/crates/ui-egui/src/panels/mod.rs b/crates/ui-egui/src/panels/mod.rsindex f5510dd40..f9fe3b0c7 100644--- a/crates/ui-egui/src/panels/mod.rs+++ b/crates/ui-egui/src/panels/mod.rs@@ -36,6 +36,7 @@ pub mod project_views;pub mod reference;pub mod remix;pub mod scopes;+pub mod sequence_settings;pub mod settings;pub mod shortcuts_dialog;pub mod text;diff --git a/crates/ui-egui/src/panels/sequence_settings.rs b/crates/ui-egui/src/panels/sequence_settings.rsnew file mode 100644index 000000000..060008057--- /dev/null+++ b/crates/ui-egui/src/panels/sequence_settings.rs@@ -0,0 +1,480 @@+//! Sequence ▸ Sequence Settings…, laid out as Premiere Pro's dialog: General, Color Management and+//! VR Properties tabs, Cancel / OK.+//!+//! What it changes (one `sequence.settings` command, one undo step): Timebase, Frame Size (with+//! "Scale motion effects proportionally when changing frame size", on by default), drop-frame or+//! non-drop-frame timecode for the NTSC rates, audio Channel Format and Sample Rate, Maximum Render+//! Quality, and the Color Management tab (working colour space, wide gamut, auto tone map).+//!+//! Premiere settings FilmCraft has no equivalent for yet are shown greyed out with their current+//! value and a "not supported yet" hint, rather than editable and silently ignored: Editing Mode,+//! Pixel Aspect Ratio (stored, not rendered), Fields, the Frames and Feet + Frames display+//! formats, Number of Channels, audio Display Format, the Video Previews format, codec and size,+//! Maximum Bit Depth, and the VR Properties tab. Composite in Linear Color is shown on and greyed:+//! FilmCraft always composites in linear light.+//!+//! Automation ids (`sequenceSettings.` + …): `tab.general`, `tab.color`, `tab.vr`; General:+//! `editingMode`, `timebase` (+ `timebase.option.<num>/<den>` while open), `width`, `height`,+//! `aspect`, `scaleMotion`, `par`, `fields`, `videoDisplay` (+ `videoDisplay.option.<df|ndf|tc>`),+//! `channelFormat` (+ `channelFormat.option.<Stereo|Mono|5.1|Adaptive>`), `channels`, `sampleRate`+//! (+ `sampleRate.option.<hz>`), `audioDisplay`, `previewFormat`, `previewCodec`, `previewWidth`,+//! `previewHeight`, `maxBitDepth`, `maxRenderQuality`, `linearColor`; Color Management:+//! `workingSpace` (+ `workingSpace.option.<id>`), `wideGamut`, `autoToneMap`; VR Properties:+//! `vr.projection`, `vr.layout`, `vr.horizontal`, `vr.vertical`; `ok`, `cancel`.++use filmcraft_color::WorkingSpace;+use filmcraft_project::{AudioChannels, SequenceSettings};+use filmcraft_time::FrameRate;+use serde_json::{Map, Value, json};++use crate::FilmcraftApp;+use crate::state::SequenceSettingsDraft;++const NOT_YET: &str = "Not supported in FilmCraft yet";+const LINEAR: &str = "FilmCraft always composites in linear light";++/// The Timebase list (frames per second as num/den), Premiere's common rates.+const TIMEBASES: [(i64, i64); 15] = [+ (10, 1),+ (12, 1),+ (25, 2),+ (15, 1),+ (24_000, 1001),+ (24, 1),+ (25, 1),+ (30_000, 1001),+ (30, 1),+ (48, 1),+ (50, 1),+ (60_000, 1001),+ (60, 1),+ (120_000, 1001),+ (120, 1),+];+const SAMPLE_RATES: [u32; 5] = [32_000, 44_100, 48_000, 88_200, 96_000];+const MIXES: [&str; 4] = ["Stereo", "Mono", "5.1", "Adaptive"];++fn mix_name(c: AudioChannels) -> &'static str {+ match c {+ AudioChannels::Mono => "Mono",+ AudioChannels::Stereo => "Stereo",+ AudioChannels::Surround51 => "5.1",+ AudioChannels::Adaptive => "Adaptive",+ }+}++/// Fill the draft from the active sequence and open the dialog on the General tab.+pub fn open(app: &mut FilmcraftApp) {+ let Some(q) = app.session.active_sequence() else { return };+ let st = &q.settings;+ app.ui.sequence_settings = SequenceSettingsDraft {+ tab: "general".into(),+ fps_num: st.frame_rate.num,+ fps_den: st.frame_rate.den,+ width: st.width,+ height: st.height,+ scale_motion: true,+ drop_frame: st.drop_frame && st.frame_rate.supports_drop_frame(),+ mix: mix_name(st.audio_master).into(),+ sample_rate: st.sample_rate,+ max_render_quality: st.max_render_quality,+ working_space: st.color.working.id().into(),+ wide_gamut: st.color.wide_gamut,+ auto_tone_map: st.color.auto_tone_map,+ };+ app.dialog = Some(crate::Dialog::SequenceSettings);+}++fn rate(d: &SequenceSettingsDraft) -> FrameRate {+ FrameRate { num: d.fps_num, den: d.fps_den }.sane()+}++/// "16:9" for a frame size, or "1.90:1" when the reduced ratio has no small integer form.+fn aspect(w: u32, h: u32) -> String {+ let g = gcd(w, h).max(1);+ let (a, b) = (w / g, h / g);+ if a <= 64 && b <= 64 {+ format!("{a}:{b}")+ } else if h > 0 {+ format!("{:.2}:1", f64::from(w) / f64::from(h))+ } else {+ String::new()+ }+}++fn gcd(mut a: u32, mut b: u32) -> u32 {+ while b != 0 {+ (a, b) = (b, a % b);+ }+ a+}++fn timebase_label(r: FrameRate) -> String {+ format!("{} frames/second", r.label())+}++/// The Video Display Format choices for a timebase: drop-frame / non-drop-frame timecode for the+/// NTSC rates, plain timecode otherwise (`(id, label)`).+fn timecode_formats(r: FrameRate) -> Vec<(&'static str, String)> {+ if r.supports_drop_frame() {+ vec![("df", format!("{} fps Drop-Frame Timecode", r.label())), ("ndf", format!("{} fps Non Drop-Frame Timecode", r.label()))]+ } else {+ vec![("tc", format!("{} fps Timecode", r.label()))]+ }+}++fn par_label(par: (u32, u32)) -> String {+ if par.0 == par.1 {+ "Square Pixels (1.0)".into()+ } else if par.1 > 0 {+ format!("Custom ({:.4})", f64::from(par.0) / f64::from(par.1))+ } else {+ "Custom".into()+ }+}++/// The parameters for `sequence.settings` that differ from `cur`; empty when nothing changed.+fn changes(d: &SequenceSettingsDraft, cur: &SequenceSettings) -> Map<String, Value> {+ let mut p = Map::new();+ let r = rate(d);+ if r != cur.frame_rate {+ p.insert("fps".into(), json!(r.as_f64()));+ }+ if (d.width, d.height) != (cur.width, cur.height) {+ p.insert("width".into(), json!(d.width));+ p.insert("height".into(), json!(d.height));+ p.insert("scaleMotion".into(), json!(d.scale_motion));+ }+ let df = d.drop_frame && r.supports_drop_frame();+ if df != (cur.drop_frame && cur.frame_rate.supports_drop_frame()) {+ p.insert("dropFrame".into(), json!(df));+ }+ if d.mix != mix_name(cur.audio_master) {+ p.insert("mix".into(), json!(d.mix));+ }+ if d.sample_rate != cur.sample_rate {+ p.insert("sampleRate".into(), json!(d.sample_rate));+ }+ if d.max_render_quality != cur.max_render_quality {+ p.insert("maxRenderQuality".into(), json!(d.max_render_quality));+ }+ if d.working_space != cur.color.working.id() {+ p.insert("workingSpace".into(), json!(d.working_space));+ }+ if d.wide_gamut != cur.color.wide_gamut {+ p.insert("wideGamut".into(), json!(d.wide_gamut));+ }+ if d.auto_tone_map != cur.color.auto_tone_map {+ p.insert("autoToneMap".into(), json!(d.auto_tone_map));+ }+ p+}++type Elems = Vec<(String, egui::Rect, String)>;++/// One labelled row: the label right-aligned in a `label_w` column, then the control.+fn row<R>(ui: &mut egui::Ui, label_w: f32, label: &str, enabled: bool, add: impl FnOnce(&mut egui::Ui) -> R) -> R {+ ui.horizontal(|ui| {+ let h = ui.spacing().interact_size.y;+ ui.allocate_ui_with_layout(egui::vec2(label_w, h), egui::Layout::right_to_left(egui::Align::Center), |ui| {+ ui.add_enabled(enabled, egui::Label::new(label));+ });+ add(ui)+ })+ .inner+}++/// A greyed-out list showing `value`, with the "not supported yet" hint (or `hint`).+fn fixed_combo(ui: &mut egui::Ui, elems: &mut Elems, id: &str, value: &str, width: f32, hint: &str) {+ let r = ui+ .add_enabled_ui(false, |ui| egui::ComboBox::from_id_salt(("seq-settings-fixed", id)).selected_text(value).width(width).show_ui(ui, |_| {}).response)+ .inner+ .on_disabled_hover_text(hint);+ elems.push((format!("sequenceSettings.{id}"), r.rect, value.to_string()));+}++/// A greyed-out read-only value (a number field in Premiere), with the hint.+fn fixed_value(ui: &mut egui::Ui, elems: &mut Elems, id: &str, value: &str) {+ let r = ui.add_enabled(false, egui::Button::new(value).min_size(egui::vec2(64.0, 0.0))).on_disabled_hover_text(NOT_YET);+ elems.push((format!("sequenceSettings.{id}"), r.rect, value.to_string()));+}++fn section(ui: &mut egui::Ui, title: &str, add: impl FnOnce(&mut egui::Ui)) {+ ui.add_space(6.0);+ ui.label(egui::RichText::new(title).strong());+ ui.group(|ui| {+ ui.set_width(ui.available_width());+ add(ui);+ });+}++fn general(ui: &mut egui::Ui, d: &mut SequenceSettingsDraft, cur: &SequenceSettings, audio_samples: bool, elems: &mut Elems) {+ let font = egui::TextStyle::Body.resolve(ui.style());+ let label_w = ["Preview File Format:", "Pixel Aspect Ratio:", "Number of Channels:"]+ .iter()+ .map(|l| ui.painter().layout_no_wrap(l.to_string(), font.clone(), egui::Color32::WHITE).size().x)+ .fold(0.0, f32::max);+ let list_w = 260.0;+ row(ui, label_w, "Editing Mode:", false, |ui| fixed_combo(ui, elems, "editingMode", "Custom", list_w, NOT_YET));+ row(ui, label_w, "Timebase:", true, |ui| {+ let r = rate(d);+ let mut choices: Vec<(i64, i64)> = TIMEBASES.to_vec();+ if !choices.contains(&(r.num, r.den)) {+ choices.insert(0, (r.num, r.den));+ }+ let shown = timebase_label(r);+ // no row limit of our own: the list grows to egui's popup limit (`Spacing::default_area_size`,+ // 400 px), so every rate up to 119.88 shows without scrolling (the default 200 px stopped+ // before 29.97)+ let resp = egui::ComboBox::from_id_salt("seq-settings-timebase").selected_text(&shown).width(list_w).height(f32::INFINITY).show_ui(ui, |ui| {+ for (num, den) in choices {+ let label = timebase_label(FrameRate { num, den });+ let o = ui.selectable_label((d.fps_num, d.fps_den) == (num, den), &label);+ // a new timebase starts on its usual timecode (drop-frame for the NTSC rates);+ // picking the current one again keeps the Display Format chosen for it+ if o.clicked() && (d.fps_num, d.fps_den) != (num, den) {+ d.fps_num = num;+ d.fps_den = den;+ d.drop_frame = FrameRate { num, den }.supports_drop_frame();+ }+ elems.push((format!("sequenceSettings.timebase.option.{num}/{den}"), o.rect, label));+ }+ });+ elems.push(("sequenceSettings.timebase".into(), resp.response.rect, shown));+ });+ section(ui, "Video", |ui| {+ row(ui, label_w, "Frame Size:", true, |ui| {+ let w = ui.add(egui::DragValue::new(&mut d.width).range(1..=filmcraft_project::MAX_FRAME_SIDE).speed(1.0));+ elems.push(("sequenceSettings.width".into(), w.rect, d.width.to_string()));+ ui.label("horizontal");+ let h = ui.add(egui::DragValue::new(&mut d.height).range(1..=filmcraft_project::MAX_FRAME_SIDE).speed(1.0));+ elems.push(("sequenceSettings.height".into(), h.rect, d.height.to_string()));+ ui.label("vertical");+ let a = aspect(d.width, d.height);+ let ar = ui.label(&a);+ elems.push(("sequenceSettings.aspect".into(), ar.rect, a));+ });+ let r = ui.checkbox(&mut d.scale_motion, "Scale motion effects proportionally when changing frame size");+ elems.push(("sequenceSettings.scaleMotion".into(), r.rect, d.scale_motion.to_string()));+ row(ui, label_w, "Pixel Aspect Ratio:", false, |ui| fixed_combo(ui, elems, "par", &par_label(cur.par), list_w, NOT_YET));+ row(ui, label_w, "Fields:", false, |ui| fixed_combo(ui, elems, "fields", "No Fields (Progressive Scan)", list_w, NOT_YET));+ row(ui, label_w, "Display Format:", true, |ui| {+ let r = rate(d);+ let formats = timecode_formats(r);+ let chosen = if r.supports_drop_frame() { if d.drop_frame { "df" } else { "ndf" } } else { "tc" };+ let shown = formats.iter().find(|(id, _)| *id == chosen).map(|(_, l)| l.clone()).unwrap_or_default();+ let resp = egui::ComboBox::from_id_salt("seq-settings-video-display").selected_text(&shown).width(list_w).show_ui(ui, |ui| {+ for (id, label) in &formats {+ let o = ui.selectable_label(*id == chosen, label);+ if o.clicked() {+ d.drop_frame = *id == "df";+ }+ elems.push((format!("sequenceSettings.videoDisplay.option.{id}"), o.rect, label.clone()));+ }+ for label in ["Feet + Frames 16mm", "Feet + Frames 35mm", "Frames"] {+ ui.add_enabled(false, egui::Button::selectable(false, label)).on_disabled_hover_text(NOT_YET);+ }+ });+ elems.push(("sequenceSettings.videoDisplay".into(), resp.response.rect, shown));+ });+ });+ section(ui, "Audio", |ui| {+ row(ui, label_w, "Channel Format:", true, |ui| {+ let shown = d.mix.clone();+ let resp = egui::ComboBox::from_id_salt("seq-settings-mix").selected_text(&shown).width(120.0).show_ui(ui, |ui| {+ for m in MIXES {+ let o = ui.selectable_value(&mut d.mix, m.to_string(), m);+ elems.push((format!("sequenceSettings.channelFormat.option.{m}"), o.rect, m.to_string()));+ }+ });+ elems.push(("sequenceSettings.channelFormat".into(), resp.response.rect, shown));+ ui.add_enabled(false, egui::Label::new("Number of Channels:"));+ let n = match d.mix.as_str() {+ "Mono" => "1",+ "5.1" => "6",+ "Adaptive" => "—",+ _ => "2",+ };+ fixed_combo(ui, elems, "channels", n, 60.0, NOT_YET);+ });+ row(ui, label_w, "Sample Rate:", true, |ui| {+ let mut rates = SAMPLE_RATES.to_vec();+ if !rates.contains(&d.sample_rate) {+ rates.insert(0, d.sample_rate);+ }+ let shown = format!("{} Hz", d.sample_rate);+ let resp = egui::ComboBox::from_id_salt("seq-settings-sample-rate").selected_text(&shown).width(list_w).show_ui(ui, |ui| {+ for hz in rates {+ let label = format!("{hz} Hz");+ let o = ui.selectable_value(&mut d.sample_rate, hz, &label);+ elems.push((format!("sequenceSettings.sampleRate.option.{hz}"), o.rect, label));+ }+ });+ elems.push(("sequenceSettings.sampleRate".into(), resp.response.rect, shown));+ });+ let shown = if audio_samples { "Audio Samples" } else { "Milliseconds" };+ row(ui, label_w, "Display Format:", false, |ui| fixed_combo(ui, elems, "audioDisplay", shown, list_w, NOT_YET));+ });+ section(ui, "Video Previews", |ui| {+ row(ui, label_w, "Preview File Format:", false, |ui| {+ fixed_combo(ui, elems, "previewFormat", "QuickTime", list_w, NOT_YET);+ ui.add_enabled(false, egui::Button::new("Configure…")).on_disabled_hover_text(NOT_YET);+ });+ row(ui, label_w, "Codec:", false, |ui| fixed_combo(ui, elems, "previewCodec", &cur.preview_codec, list_w, NOT_YET));+ row(ui, label_w, "Width:", false, |ui| fixed_value(ui, elems, "previewWidth", &d.width.to_string()));+ row(ui, label_w, "Height:", false, |ui| {+ fixed_value(ui, elems, "previewHeight", &d.height.to_string());+ ui.add_enabled(false, egui::Button::new("Reset")).on_disabled_hover_text(NOT_YET);+ });+ ui.horizontal(|ui| {+ let mut bit_depth = cur.max_bit_depth;+ let r = ui.add_enabled(false, egui::Checkbox::new(&mut bit_depth, "Maximum Bit Depth")).on_disabled_hover_text(NOT_YET);+ elems.push(("sequenceSettings.maxBitDepth".into(), r.rect, bit_depth.to_string()));+ let r = ui.checkbox(&mut d.max_render_quality, "Maximum Render Quality");+ elems.push(("sequenceSettings.maxRenderQuality".into(), r.rect, d.max_render_quality.to_string()));+ });+ let mut linear = true;+ let r = ui.add_enabled(false, egui::Checkbox::new(&mut linear, "Composite in Linear Color")).on_disabled_hover_text(LINEAR);+ elems.push(("sequenceSettings.linearColor".into(), r.rect, "true".into()));+ });+}++fn color(ui: &mut egui::Ui, d: &mut SequenceSettingsDraft, elems: &mut Elems) {+ let font = egui::TextStyle::Body.resolve(ui.style());+ let label_w = ui.painter().layout_no_wrap("Working Color Space:".to_string(), font, egui::Color32::WHITE).size().x;+ row(ui, label_w, "Working Color Space:", true, |ui| {+ let shown = WorkingSpace::parse(&d.working_space).map_or(d.working_space.clone(), |w| w.label().to_string());+ let resp = egui::ComboBox::from_id_salt("seq-settings-working-space").selected_text(&shown).width(220.0).show_ui(ui, |ui| {+ for w in WorkingSpace::ALL {+ let o = ui.selectable_value(&mut d.working_space, w.id().to_string(), w.label());+ elems.push((format!("sequenceSettings.workingSpace.option.{}", w.id()), o.rect, w.label().to_string()));+ }+ });+ elems.push(("sequenceSettings.workingSpace".into(), resp.response.rect, shown));+ });+ ui.add_space(4.0);+ let r = ui.checkbox(&mut d.wide_gamut, "Wide gamut color (composite in BT.2020)");+ elems.push(("sequenceSettings.wideGamut".into(), r.rect, d.wide_gamut.to_string()));+ let r = ui.checkbox(&mut d.auto_tone_map, "Auto Tone Map Media (HDR and log into SDR)");+ elems.push(("sequenceSettings.autoToneMap".into(), r.rect, d.auto_tone_map.to_string()));+}++fn vr(ui: &mut egui::Ui, elems: &mut Elems) {+ let font = egui::TextStyle::Body.resolve(ui.style());+ let label_w = ui.painter().layout_no_wrap("Captured View:".to_string(), font, egui::Color32::WHITE).size().x;+ row(ui, label_w, "Projection:", false, |ui| fixed_combo(ui, elems, "vr.projection", "None", 200.0, NOT_YET));+ row(ui, label_w, "Layout:", false, |ui| fixed_combo(ui, elems, "vr.layout", "Monoscopic", 200.0, NOT_YET));+ row(ui, label_w, "Captured View:", false, |ui| {+ fixed_value(ui, elems, "vr.horizontal", "0°");+ ui.add_enabled(false, egui::Label::new("Horizontal"));+ fixed_value(ui, elems, "vr.vertical", "0°");+ ui.add_enabled(false, egui::Label::new("Vertical"));+ });+}++/// Draw the dialog. Returns whether it stays open.+pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {+ let Some(q) = app.session.active_sequence() else { return false };+ let cur = q.settings.clone();+ let audio_samples = app.session.project.settings.audio_display_samples;+ let accent = app.tokens.accent;+ let mut d = app.ui.sequence_settings.clone();+ let mut keep = true;+ let mut apply = false;+ let mut elems: Elems = Vec::new();+ let max_h = ctx.content_rect().height() * 0.8;+ egui::Window::new("Sequence Settings").collapsible(false).resizable(false).default_width(620.0).anchor(egui::Align2::CENTER_CENTER, [0.0, 0.0]).show(+ ctx,+ |ui| {+ ui.set_width(620.0);+ ui.horizontal(|ui| {+ for (id, label) in [("general", "General"), ("color", "Color Management"), ("vr", "VR Properties")] {+ let r = ui.selectable_label(d.tab == id, label);+ if r.clicked() {+ d.tab = id.to_string();+ }+ elems.push((format!("sequenceSettings.tab.{id}"), r.rect, label.to_string()));+ }+ });+ ui.separator();+ egui::ScrollArea::vertical().max_height(max_h).auto_shrink([false, true]).show(ui, |ui| match d.tab.as_str() {+ "color" => color(ui, &mut d, &mut elems),+ "vr" => vr(ui, &mut elems),+ _ => general(ui, &mut d, &cur, audio_samples, &mut elems),+ });+ ui.add_space(10.0);+ ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {+ let o = ui.add(egui::Button::new(egui::RichText::new("OK").color(egui::Color32::WHITE)).fill(accent));+ elems.push(("sequenceSettings.ok".into(), o.rect, "OK".into()));+ if o.clicked() {+ apply = true;+ }+ let c = ui.button("Cancel");+ elems.push(("sequenceSettings.cancel".into(), c.rect, "Cancel".into()));+ if c.clicked() {+ keep = false;+ }+ });+ },+ );+ for (id, r, l) in elems {+ app.auto.add(&id, r, &l);+ }+ if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {+ keep = false;+ }+ if ctx.input(|i| i.key_pressed(egui::Key::Enter)) && !ctx.egui_wants_keyboard_input() {+ apply = true;+ }+ if apply {+ let p = changes(&d, &cur);+ // nothing changed: OK closes the dialog and adds no undo step+ if !p.is_empty()+ && let Err(e) = app.session.execute("sequence.settings", Value::Object(p))+ {+ app.ui.status = e.to_string();+ }+ keep = false;+ }+ app.ui.sequence_settings = d;+ keep+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn aspect_labels() {+ assert_eq!(aspect(1920, 1080), "16:9");+ assert_eq!(aspect(640, 360), "16:9");+ assert_eq!(aspect(1080, 1920), "9:16");+ assert_eq!(aspect(1440, 1080), "4:3");+ assert_eq!(aspect(4096, 2160), "1.90:1");+ }++ #[test]+ fn display_formats_follow_the_timebase() {+ assert_eq!(timecode_formats(FrameRate::FPS_23_976), vec![("tc", "23.976 fps Timecode".to_string())]);+ let ntsc = timecode_formats(FrameRate::FPS_29_97);+ assert_eq!(ntsc.iter().map(|(id, _)| *id).collect::<Vec<_>>(), vec!["df", "ndf"]);+ assert_eq!(ntsc[0].1, "29.97 fps Drop-Frame Timecode");+ }++ #[test]+ fn only_changed_settings_are_sent() {+ let cur = SequenceSettings::default();+ let mut d = SequenceSettingsDraft::default();+ assert!(changes(&d, &cur).is_empty(), "the defaults match: nothing to send");+ d.width = 1280;+ d.height = 720;+ d.max_render_quality = true;+ let p = changes(&d, &cur);+ assert_eq!(Value::Object(p), json!({"width":1280,"height":720,"scaleMotion":true,"maxRenderQuality":true}));+ // drop-frame only travels for a rate that has it+ let mut d = SequenceSettingsDraft { drop_frame: true, ..Default::default() };+ assert!(changes(&d, &cur).is_empty());+ (d.fps_num, d.fps_den) = (30_000, 1001);+ assert_eq!(Value::Object(changes(&d, &cur)), json!({"fps":30_000.0/1001.0,"dropFrame":true}));+ }+}diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rsindex 0bdfcda85..ee30e34f3 100644--- a/crates/ui-egui/src/state.rs+++ b/crates/ui-egui/src/state.rs@@ -432,6 +432,9 @@ pub struct UiState {/// Delete Tracks dialog draft.#[serde(default)]pub delete_tracks: DeleteTracksDraft,+ /// Sequence Settings dialog draft.+ #[serde(default)]+ pub sequence_settings: SequenceSettingsDraft,/// On-monitor text editing (Type tool / double-click on a text layer).#[serde(default)]pub gfx_edit: Option<GfxEdit>,@@ -735,6 +738,49 @@ impl Default for AddTracksDraft {}}+/// The Sequence Settings dialog (Sequence ▸ Sequence Settings…), filled from the active sequence+/// when it opens (`panels::sequence_settings::open`). `tab`: `general`, `color` or `vr`; the+/// timebase is `fps_num`/`fps_den`; `mix`: `Stereo`, `Mono`, `5.1` or `Adaptive`; `working_space`:+/// a [`filmcraft_color::WorkingSpace`] id. `scale_motion` is "Scale motion effects proportionally+/// when changing frame size", on by default as in Premiere.+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]+#[serde(default)]+pub struct SequenceSettingsDraft {+ pub tab: String,+ pub fps_num: i64,+ pub fps_den: i64,+ pub width: u32,+ pub height: u32,+ pub scale_motion: bool,+ pub drop_frame: bool,+ pub mix: String,+ pub sample_rate: u32,+ pub max_render_quality: bool,+ pub working_space: String,+ pub wide_gamut: bool,+ pub auto_tone_map: bool,+}++impl Default for SequenceSettingsDraft {+ fn default() -> Self {+ Self {+ tab: "general".into(),+ fps_num: 24_000,+ fps_den: 1001,+ width: 1920,+ height: 1080,+ scale_motion: true,+ drop_frame: false,+ mix: "Stereo".into(),+ sample_rate: 48_000,+ max_render_quality: false,+ working_space: "rec709".into(),+ wide_gamut: false,+ auto_tone_map: true,+ }+ }+}+/// The Delete Tracks dialog (Sequence ▸ Delete Tracks…): per kind, whether to delete and which/// track (`"empty"` = All Empty Tracks, or a track name such as `"V2"`).#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]@@ -820,6 +866,7 @@ impl Default for UiState {audio_gain: AudioGainDraft::default(),add_tracks: AddTracksDraft::default(),delete_tracks: DeleteTracksDraft::default(),+ sequence_settings: SequenceSettingsDraft::default(),gfx_edit: None,pen_points: vec![],link_media: None,diff --git a/crates/ui-egui/tests/sequence_ui.rs b/crates/ui-egui/tests/sequence_ui.rsindex 807aaad56..056328179 100644--- a/crates/ui-egui/tests/sequence_ui.rs+++ b/crates/ui-egui/tests/sequence_ui.rs@@ -1,6 +1,9 @@//! Headless UI tests of the Sequence / Markers menu additions: the Add Tracks and Delete Tracks dialogs, the//! through-edit marks on the timeline, the Markers panel colour filter and the Shift+; gap key.//! The real `FilmcraftApp` under `egui_kittest`, driven over the control channel by automation id.+//!+//! Set `FILMCRAFT_UI_SNAPSHOT_DIR=<dir>` to also render the window offscreen with wgpu and write+//! `sequence-settings-*.png` there; without it no GPU is needed.use std::sync::mpsc::{Sender, channel};@@ -13,6 +16,7 @@ use serde_json::{Value, json};struct Driver {harness: Harness<'static, FilmcraftApp>,tx: Sender<ControlRequest>,+ snapshots: Option<std::path::PathBuf>,}impl Driver {@@ -21,8 +25,13 @@ impl Driver {session.execute("file.openDemoProject", json!({})).expect("demo project");let (tx, rx) = channel();let app = FilmcraftApp::new(session).with_control(rx);- let harness = Harness::builder().with_size(egui::vec2(1600.0, 980.0)).with_max_steps(10_000).build_eframe(move |_cc| app);- let mut d = Driver { harness, tx };+ let snapshots = std::env::var_os("FILMCRAFT_UI_SNAPSHOT_DIR").map(std::path::PathBuf::from);+ let mut b = Harness::builder().with_size(egui::vec2(1600.0, 980.0)).with_max_steps(10_000);+ if snapshots.is_some() {+ b = b.wgpu();+ }+ let harness = b.build_eframe(move |_cc| app);+ let mut d = Driver { harness, tx, snapshots };d.frames(4);d}@@ -80,6 +89,34 @@ impl Driver {e["label"].as_str().unwrap_or_default().to_string()}+ /// With `FILMCRAFT_UI_SNAPSHOT_DIR` set, render the window offscreen and write `<name>.png`,+ /// cropped to the elements whose ids start with `prefix`.+ fn snapshot(&mut self, name: &str, prefix: &str) {+ let Some(dir) = self.snapshots.clone() else { return };+ let v = self.ok("ui.elements", json!({"prefix": prefix}));+ let mut bb = [f32::MAX, f32::MAX, f32::MIN, f32::MIN];+ for e in v.as_array().unwrap() {+ let r: Vec<f32> = e["rect"].as_array().unwrap().iter().map(|x| x.as_f64().unwrap() as f32).collect();+ bb = [bb[0].min(r[0]), bb[1].min(r[1]), bb[2].max(r[0] + r[2]), bb[3].max(r[1] + r[3])];+ }+ self.frames(2);+ let img = match self.harness.render() {+ Ok(i) => i,+ Err(e) => {+ eprintln!("snapshot {name} skipped: {e}");+ return;+ }+ };+ let ppp = img.width() as f32 / 1600.0;+ let x0 = ((bb[0] - 24.0) * ppp).max(0.0) as u32;+ let y0 = ((bb[1] - 40.0) * ppp).max(0.0) as u32;+ let x1 = (((bb[2] + 24.0) * ppp) as u32).min(img.width());+ let y1 = (((bb[3] + 24.0) * ppp) as u32).min(img.height());+ let img = image::imageops::crop_imm(&img, x0, y0, x1.saturating_sub(x0), y1.saturating_sub(y0)).to_image();+ std::fs::create_dir_all(&dir).unwrap();+ img.save(dir.join(format!("{name}.png"))).unwrap();+ }+fn ids(&mut self, prefix: &str) -> Vec<String> {let v = self.ok("ui.elements", json!({"prefix": prefix}));v.as_array().unwrap().iter().filter_map(|e| e["id"].as_str().map(str::to_string)).collect()@@ -419,3 +456,104 @@ fn ctrl_x_cuts_clips() {assert!(!d.app().session.state.clipboard.is_empty());assert!(d.app().session.active_sequence().unwrap().find_item(first.id).is_none(), "the cut clip leaves the timeline");}++/// Sequence ▸ Sequence Settings… opens Premiere Pro's dialog (it used to do nothing, #172): the+/// General tab shows the sequence's settings, the ones FilmCraft can't change yet are shown (greyed+/// out), and the Color Management and VR Properties tabs are there. Opening and cancelling change+/// nothing.+#[test]+fn sequence_settings_dialog_shows_the_sequence() {+ let mut d = Driver::demo();+ let before = (*d.app().session.project).clone();+ let history = d.app().session.history.undo.len();+ let r = d.ok("ui.menu.invoke", json!({"id": "sequence.settings"}));+ assert_eq!(r["dialog"], "sequenceSettings", "{r}");+ d.frames(3);+ for (id, shown) in [+ ("sequenceSettings.editingMode", "Custom"),+ ("sequenceSettings.timebase", "23.976 frames/second"),+ ("sequenceSettings.width", "1920"),+ ("sequenceSettings.height", "1080"),+ ("sequenceSettings.aspect", "16:9"),+ ("sequenceSettings.scaleMotion", "true"),+ ("sequenceSettings.par", "Square Pixels (1.0)"),+ ("sequenceSettings.fields", "No Fields (Progressive Scan)"),+ ("sequenceSettings.videoDisplay", "23.976 fps Timecode"),+ ("sequenceSettings.channelFormat", "Stereo"),+ ("sequenceSettings.channels", "2"),+ ("sequenceSettings.sampleRate", "48000 Hz"),+ ("sequenceSettings.maxRenderQuality", "false"),+ ("sequenceSettings.linearColor", "true"),+ ] {+ assert_eq!(d.label(id), shown, "{id}");+ }+ for id in ["sequenceSettings.tab.general", "sequenceSettings.tab.color", "sequenceSettings.tab.vr", "sequenceSettings.ok", "sequenceSettings.cancel"] {+ assert!(d.ids(id).iter().any(|i| i == id), "{id} missing");+ }+ d.snapshot("sequence-settings-general", "sequenceSettings.");+ // the timebase list offers the common rates+ d.click("sequenceSettings.timebase");+ let rates = d.ids("sequenceSettings.timebase.option.");+ for r in ["24000/1001", "24/1", "25/1", "30000/1001", "60/1"] {+ assert!(rates.iter().any(|i| i.ends_with(r)), "{r} missing: {rates:?}");+ }+ d.click("sequenceSettings.timebase.option.24000/1001");+ d.click("sequenceSettings.tab.color");+ assert_eq!(d.label("sequenceSettings.workingSpace"), "Rec. 709");+ assert_eq!(d.label("sequenceSettings.autoToneMap"), "true");+ d.snapshot("sequence-settings-color", "sequenceSettings.");+ d.click("sequenceSettings.tab.vr");+ assert_eq!(d.label("sequenceSettings.vr.projection"), "None");+ d.snapshot("sequence-settings-vr", "sequenceSettings.");+ d.click("sequenceSettings.cancel");+ assert!(d.ids("sequenceSettings.").is_empty(), "dialog closed");+ assert_eq!(*d.app().session.project, before);+ assert_eq!(d.app().session.history.undo.len(), history, "no undo step");+ // OK without a change closes it and adds no undo step either+ d.ok("ui.menu.invoke", json!({"id": "sequence.settings"}));+ d.frames(3);+ d.click("sequenceSettings.ok");+ assert!(d.ids("sequenceSettings.").is_empty());+ assert_eq!(d.app().session.history.undo.len(), history);+}++/// OK applies the dialog in one undo step: a new timebase (29.97 starts on drop-frame timecode), a+/// smaller frame with the clips' Motion scaled to match, and Maximum Render Quality.+#[test]+fn sequence_settings_dialog_applies_in_one_undo_step() {+ let mut d = Driver::demo();+ let before = (*d.app().session.project).clone();+ let motion = |d: &mut Driver| {+ let q = d.app().session.active_sequence().unwrap();+ let m = q.video_tracks.iter().flat_map(|t| &t.items).find_map(|i| i.effect("motion")).unwrap().clone();+ match (&m.param("position").unwrap().value, &m.param("scale").unwrap().value) {+ (filmcraft_engine::project::ParamValue::Vec2(p), filmcraft_engine::project::ParamValue::Float(s)) => (p.x, p.y, *s),+ _ => panic!("Motion has a point and a number"),+ }+ };+ let (x0, y0, s0) = motion(&mut d);+ d.ok("ui.menu.invoke", json!({"id": "sequence.settings"}));+ // the window sizes itself over its first frames; click once it has settled+ d.frames(10);+ d.click("sequenceSettings.timebase");+ d.snapshot("sequence-settings-timebase-list", "sequenceSettings.");+ d.click("sequenceSettings.timebase.option.30000/1001");+ assert_eq!(d.label("sequenceSettings.timebase"), "29.97 frames/second");+ assert_eq!(d.label("sequenceSettings.videoDisplay"), "29.97 fps Drop-Frame Timecode");+ // the frame-size fields are drag values; set the draft as typing would+ d.app().ui.sequence_settings.width = 1280;+ d.app().ui.sequence_settings.height = 720;+ d.frames(2);+ assert_eq!(d.label("sequenceSettings.aspect"), "16:9");+ d.click("sequenceSettings.maxRenderQuality");+ d.click("sequenceSettings.ok");+ assert!(d.ids("sequenceSettings.").is_empty(), "dialog closed");+ let st = d.app().session.active_sequence().unwrap().settings.clone();+ assert_eq!((st.width, st.height, st.frame_rate), (1280, 720, filmcraft_engine::time::FrameRate::FPS_29_97));+ assert!(st.drop_frame && st.max_render_quality);+ let (x1, y1, s1) = motion(&mut d);+ let k = 2.0 / 3.0;+ assert!((x1 - x0 * k).abs() < 1e-9 && (y1 - y0 * k).abs() < 1e-9 && (s1 - s0 * k).abs() < 1e-9, "{x0},{y0},{s0} -> {x1},{y1},{s1}");+ d.exec("edit.undo", json!({}));+ assert_eq!(*d.app().session.project, before, "one undo step for the whole dialog");+}