FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Merge remote-tracking branch 'origin/main' into nest-116
Brandon Thomas19d2f1514845
diff --cc crates/ui-egui/src/lib.rsindex 9421e7181,98dd04633..675b35f0c--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@@ -446,63 -457,29 +463,83 @@@ impl FilmcraftAppself.applied_prefs = Some(p);}+ /// Every sequence has its own Timeline view (zoom, scroll, track heights), as Premiere's+ /// sequence tabs do. `ui.timeline` holds the active sequence's; the views of all sequences are+ /// in `session.state.timeline_views`, which is saved with the project. Each frame this+ /// - gives `ui.timeline` the view of a sequence that has just become active (a sequence shown+ /// for the first time is fitted, with default track heights),+ /// - writes a change made in the panel to the session,+ /// - and takes over a view that was changed in the session (by a command or the control+ /// channel).+ fn sync_timeline_view(&mut self) {+ let Some(active) = self.session.state.active_sequence else {+ self.timeline_view_of = None;+ return;+ };+ let stored = self.session.state.timeline_views.get(&active).copied();+ let v = &mut self.ui.timeline;+ let shown = filmcraft_engine::project::SequenceView {+ pps: v.target_pps,+ scroll: v.target_scroll,+ v_scroll: v.v_scroll,+ a_scroll: v.a_scroll,+ video_track_h: v.video_track_h,+ audio_track_h: v.audio_track_h,+ };+ let show = |v: &mut state::TimelineView, s: filmcraft_engine::project::SequenceView| {+ (v.pps, v.target_pps, v.scroll, v.target_scroll) = (s.pps, s.pps, s.scroll, s.scroll);+ (v.v_scroll, v.a_scroll, v.video_track_h, v.audio_track_h) = (s.v_scroll, s.a_scroll, s.video_track_h, s.audio_track_h);+ (v.fit_pending, v.fit_empty) = (false, None);+ };+ if self.timeline_view_of != Some(active) {+ self.timeline_view_of = Some(active);+ match stored.and_then(|s| s.checked()) {+ Some(s) => {+ show(v, s);+ self.timeline_view_last = Some(s);+ }+ None => {+ let d = state::TimelineView::default();+ (v.v_scroll, v.a_scroll, v.video_track_h, v.audio_track_h) = (0.0, 0.0, d.video_track_h, d.audio_track_h);+ (v.fit_pending, v.fit_empty) = (true, None);+ self.timeline_view_last = None;+ }+ }+ } else if v.fit_pending {+ // the panel has not fitted the sequence yet: nothing to keep+ } else if self.timeline_view_last != Some(shown) {+ self.session.state.timeline_views.insert(active, shown);+ self.timeline_view_last = Some(shown);+ } else if let Some(s) = stored.filter(|s| *s != shown).and_then(|s| s.checked()) {+ show(v, s);+ self.timeline_view_last = Some(s);+ self.session.state.timeline_views.insert(active, s);+ }+ }++ fn workspaces_path(&self) -> Option<std::path::PathBuf> {+ self.session.prefs_path.as_ref().and_then(|p| p.parent()).map(|d| d.join(dock::WORKSPACES_FILE))+ }++ /// Replace the saved workspaces and write them to the data directory.+ pub fn set_workspaces(&mut self, w: dock::WorkspacePrefs) -> Result<(), String> {+ self.workspaces = w;+ match self.workspaces_path() {+ Some(p) => self.workspaces.save(&p).map_err(|e| format!("saving workspaces: {e}")),+ None => Ok(()),+ }+ }+pub fn set_workspace(&mut self, name: &str) {self.ui.workspace = name.to_string();- self.ui.dock = dock::workspace(name);+ self.ui.dock = dock::saved_layout(&self.workspaces, name);+ if self.workspaces.current != name {+ let mut next = self.workspaces.clone();+ next.current = name.to_string();+ if let Err(e) = self.set_workspaces(next) {+ self.ui.status = e;+ }+ }if name == "Color" {self.ui.show_scopes = false;}diff --cc crates/ui-egui/src/panels/timeline.rsindex fe317d221,277945e36..8d860b636--- a/crates/ui-egui/src/panels/timeline.rs+++ b/crates/ui-egui/src/panels/timeline.rs@@@ -1493,88 -1463,46 +1570,128 @@@ fn shift_track(seq: &Sequence, tid: TraSome(tid)}+/// The clip context menu: groups (separated by rules) of (label, command id). Entries marked `…`+/// open their dialog through `menus::invoke`, like the same item in the Clip menu.+const CLIP_MENU: &[&[(&str, &str)]] = &[+ &[+ ("Cut", "edit.cut"),+ ("Copy", "edit.copy"),+ ("Paste Attributes…", "edit.pasteAttributes"),+ ("Remove Attributes…", "edit.removeAttributes"),+ ("Clear", "edit.clear"),+ ("Ripple Delete", "edit.rippleDelete"),+ ],+ &[("Edit Original", "edit.editOriginal"), ("Replace With Clip From Source Monitor", "clip.replaceFromSource")],+ &[+ ("Enable", "clip.enable"),+ ("Link", "clip.link"),+ ("Group", "clip.group"),+ ("Ungroup", "clip.ungroup"),+ ("Synchronize…", "clip.synchronize"),+ ("Merge Clips…", "clip.mergeClips"),+ ("Nest…", "clip.nest"),+ ("Make Subsequence", "sequence.makeSubsequence"),+ ("Reveal Nested Sequence", "sequence.revealNested"),+ ("Multi-Camera", "clip.multicam"),+ ],+ &[("Label", "edit.label")],+ &[("Speed/Duration…", "clip.speedDuration")],+ &[+ ("Frame Hold Options…", "clip.frameHoldOptions"),+ ("Add Frame Hold", "clip.frameHold"),+ ("Insert Frame Hold Segment", "clip.insertFrameHoldSegment"),+ ("Field Options…", "clip.fieldOptions"),+ ("Scale to Frame Size", "clip.scaleToFrameSize"),+ ("Fit to frame", "clip.fitToFrame"),+ ("Fill frame", "clip.fillFrame"),+ ],+ &[("Reveal in Project", "clip.revealInProject"), ("Join Through Edits", "sequence.joinThroughEdits")],+];++/// The clip menu's Multi-Camera submenu: Enable, Flatten, and the cameras of the selected nested+/// sequence clips (greyed out when none of the selected clips is a nested sequence).+fn multicam_menu(app: &mut FilmcraftApp, ui: &mut egui::Ui, picked: &[&TrackItem]) {+ let nests: Vec<&TrackItem> = picked.iter().copied().filter(|it| app.session.project.sequence(it.item).is_some()).collect();+ let enabled = !nests.is_empty() && nests.iter().all(|it| it.multicam.is_some_and(|m| m.enabled));+ // camera names of the first selected nest, and the angle it shows+ let cameras: Vec<(usize, String)> = nests+ .first()+ .and_then(|it| app.session.project.sequence(it.item))+ .map(|q| q.cameras().video_angles().map(|(i, c)| (i, c.name.clone())).collect())+ .unwrap_or_default();+ let shown = nests.first().and_then(|it| it.multicam).filter(|m| m.enabled).map(|m| m.angle as usize);+ let mut run: Option<(&str, Value)> = None;+ ui.add_enabled_ui(!nests.is_empty(), |ui| {+ let r = ui.menu_button("Multi-Camera", |ui| {+ for (label, cmd) in [(if enabled { "✓ Enable" } else { "Enable" }, "clip.multicamEnable"), ("Flatten", "clip.multicamFlatten")] {+ let r = ui.add_enabled(app.session.is_enabled(cmd), egui::Button::new(label));+ app.auto.add(&format!("timeline.clipMenu.{cmd}"), r.rect, label);+ if r.clicked() {+ run = Some((cmd, json!({})));+ }+ }+ if enabled && !cameras.is_empty() {+ ui.separator();+ for (angle, name) in &cameras {+ let label = if shown == Some(*angle) { format!("✓ {name}") } else { name.clone() };+ let r = ui.button(&label);+ app.auto.add(&format!("timeline.clipMenu.multicam.camera.{angle}"), r.rect, &label);+ if r.clicked() {+ run = Some(("multicam.switchAngle", json!({"angle": angle, "clips": nests.iter().map(|it| it.id.0).collect::<Vec<_>>()})));+ }+ }+ }+ });+ app.auto.add("timeline.clipMenu.clip.multicam", r.response.rect, "Multi-Camera");+ });+ if let Some((cmd, params)) = run {+ if let Err(e) = app.session.execute(cmd, params) {+ app.ui.status = e.to_string();+ }+ ui.close();+ }+}++ /// What the wheel and the trackpad did this frame.+ struct WheelInput {+ /// Scroll in points (wheel lines and pages converted), positive = content moves right / down.+ delta: egui::Vec2,+ /// Pinch factor (1 = none).+ pinch: f32,+ command: bool,+ alt: bool,+ shift: bool,+ }++ /// The wheel events of this frame, read from the events themselves: egui turns Cmd + wheel into a+ /// zoom and Shift + wheel into a sideways scroll before anyone asks, and the Timeline has its own+ /// meaning for both. The modifiers are those of the events (a script's wheel carries its own).+ fn wheel_input(ctx: &egui::Context) -> WheelInput {+ ctx.input(|i| {+ let mut w = WheelInput { delta: egui::Vec2::ZERO, pinch: 1.0, command: false, alt: false, shift: false };+ for e in &i.events {+ match e {+ egui::Event::MouseWheel { unit, delta, modifiers, .. } => {+ let points = match unit {+ egui::MouseWheelUnit::Point => 1.0,+ egui::MouseWheelUnit::Line => 40.0,+ egui::MouseWheelUnit::Page => 400.0,+ };+ if delta.x.is_finite() && delta.y.is_finite() {+ w.delta += *delta * points;+ }+ w.command |= modifiers.command || modifiers.mac_cmd || modifiers.ctrl;+ w.alt |= modifiers.alt;+ w.shift |= modifiers.shift;+ }+ egui::Event::Zoom(z) if z.is_finite() && *z > 0.0 => w.pinch *= *z,+ _ => {}+ }+ }+ w+ })+ }+fn interact(app: &mut FilmcraftApp, ui: &mut egui::Ui, seq: &Sequence, layout: &Layout, rect: Rect) {let ctx = ui.ctx().clone();let area = Rect::from_min_max(pos2(layout.content.min.x, layout.ruler.min.y), layout.content.max);