Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

A frame reuses the document's plan, a knob drag is one commit, a publish rebuilds less

Jareer0f340a74b889
diff --git a/engine/crates/concat-export/src/lib.rs b/engine/crates/concat-export/src/lib.rs
index 6f51980c..84314b7b 100644
--- a/engine/crates/concat-export/src/lib.rs
+++ b/engine/crates/concat-export/src/lib.rs
@@ -66,7 +66,7 @@ impl ClipKind {
}
/// One clip, as the frontend's flattener describes it.
-#[derive(Deserialize, Clone)]
+#[derive(Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ExportClip {
/// The media file this clip shows or plays.
@@ -226,7 +226,7 @@ fn linear_ease() -> [f64; 4] {
}
/// A transition on the cut into a clip.
-#[derive(Deserialize, Clone)]
+#[derive(Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct TransitionSpec {
/// "cross-fade", "fade-black" or "fade-white". Anything else is ignored.
@@ -1585,7 +1585,16 @@ pub fn preview_sources(
request: &PreviewFrameRequest,
gpu: bool,
) -> Result<PreviewSources, String> {
- let rate = FrameRate::new(Rational::new(request.rate_num, request.rate_den));
+ preview_sources_of(pool, &preview_timeline(request, gpu), request.time)
+}
+
+/// [`preview_sources`] for one instant of a plan already built.
+pub fn preview_sources_of(
+ pool: &concat_media::ReaderPool,
+ plan: &PreviewPlan,
+ seconds: f64,
+) -> Result<PreviewSources, String> {
+ let rate = plan.rate;
let BuiltTimeline {
timeline,
stills,
@@ -1598,18 +1607,20 @@ pub fn preview_sources(
riding,
cutouts,
highlight,
- } = preview_timeline(request, rate, gpu);
- let time = quantise(request.time, rate);
+ } = &plan.built;
+ let highlight = *highlight;
+ let time = quantise(seconds, rate);
let frame_seconds = time.as_f64();
- let plan = plan_frame(&timeline, time);
+ let plan_at = plan_frame(timeline, time);
- let mut sources: Vec<Source<std::sync::Arc<Frame>>> = Vec::with_capacity(plan.layers.len());
+ let mut sources: Vec<Source<std::sync::Arc<Frame>>> =
+ Vec::with_capacity(plan_at.layers.len());
let mut failures: Vec<String> = Vec::new();
- for layer in &plan.layers {
+ for layer in &plan_at.layers {
let (decode_width, decode_height) = decode_sizes
.get(&layer.clip)
.copied()
- .unwrap_or((request.width, request.height));
+ .unwrap_or((plan.width, plan.height));
let chain = filter_chains.get(&layer.clip).map(String::as_str);
let pre = pre_chains.get(&layer.clip).map(String::as_str);
// A source that fails to decode contributes nothing rather than
@@ -1641,7 +1652,7 @@ pub fn preview_sources(
transform: layer.transform,
track: tracks.get(&layer.clip).copied().unwrap_or(0),
blend: layer.blend,
- passes: passes_at(&passes, &riding, layer.clip, frame_seconds),
+ passes: passes_at(passes, riding, layer.clip, frame_seconds),
})
}
Err(error) => failures.push(format!("{}: {error}", layer.media.display())),
@@ -1652,7 +1663,7 @@ pub fn preview_sources(
// frame: compositing zero sources yields opaque black, and the caller
// would draw that "truth" over its own perfectly good approximation. An
// *empty plan* still composites - a gap in the timeline really is black.
- if sources.is_empty() && !plan.layers.is_empty() {
+ if sources.is_empty() && !plan_at.layers.is_empty() {
return Err(format!(
"no layer decoded for the paused preview: {}",
failures.join(" / ")
@@ -1661,16 +1672,38 @@ pub fn preview_sources(
Ok(PreviewSources {
sources,
- width: request.width,
- height: request.height,
+ width: plan.width,
+ height: plan.height,
time,
- treatments,
+ treatments: treatments.clone(),
})
}
-/// The preview's timeline, built the exporter's way.
-fn preview_timeline(request: &PreviewFrameRequest, rate: FrameRate, gpu: bool) -> BuiltTimeline {
- let mut resolved = request.clips.clone();
+/// The preview's timeline, built the exporter's way and kept: everything
+/// about a clip list that does not depend on the instant, so a caller
+/// showing many instants of one document builds it once. See
+/// [`preview_plan`].
+pub struct PreviewPlan {
+ built: BuiltTimeline,
+ rate: FrameRate,
+ width: u32,
+ height: u32,
+}
+
+/// Builds the plan for `clips` at one output size and rate. The costly
+/// half of a preview - transitions resolved, the engine timeline, every
+/// chain and pass, every cutout's masks found on disk - and the half that
+/// only changes when the document does.
+pub fn preview_plan(
+ clips: &[ExportClip],
+ width: u32,
+ height: u32,
+ rate_num: i64,
+ rate_den: i64,
+ gpu: bool,
+) -> PreviewPlan {
+ let rate = FrameRate::new(Rational::new(rate_num, rate_den));
+ let mut resolved = clips.to_vec();
resolve_transitions(&mut resolved, rate, false);
let visible: Vec<&ExportClip> = resolved
.iter()
@@ -1681,15 +1714,32 @@ fn preview_timeline(request: &PreviewFrameRequest, rate: FrameRate, gpu: bool) -
// keeps one conversion path rather than a preview-flavoured copy of it.
let shim = ExportRequest {
output: String::new(),
- width: request.width,
- height: request.height,
- rate_num: request.rate_num,
- rate_den: request.rate_den,
+ width,
+ height,
+ rate_num,
+ rate_den,
crf: 18,
preset: String::new(),
clips: Vec::new(),
};
- build_timeline(&shim, rate, &visible, gpu)
+ PreviewPlan {
+ built: build_timeline(&shim, rate, &visible, gpu),
+ rate,
+ width,
+ height,
+ }
+}
+
+/// The plan a request describes; see [`preview_plan`].
+fn preview_timeline(request: &PreviewFrameRequest, gpu: bool) -> PreviewPlan {
+ preview_plan(
+ &request.clips,
+ request.width,
+ request.height,
+ request.rate_num,
+ request.rate_den,
+ gpu,
+ )
}
/// Warms the reader pool for the frames about to be presented.
@@ -1709,7 +1759,17 @@ pub fn preview_prefetch(
frames: u32,
gpu: bool,
) {
- let rate = FrameRate::new(Rational::new(request.rate_num, request.rate_den));
+ preview_prefetch_of(pool, &preview_timeline(request, gpu), request.time, frames);
+}
+
+/// [`preview_prefetch`] from a plan already built.
+pub fn preview_prefetch_of(
+ pool: &concat_media::ReaderPool,
+ plan: &PreviewPlan,
+ seconds: f64,
+ frames: u32,
+) {
+ let rate = plan.rate;
let BuiltTimeline {
timeline,
stills,
@@ -1717,17 +1777,17 @@ pub fn preview_prefetch(
filter_chains,
pre_chains,
..
- } = preview_timeline(request, rate, gpu);
+ } = &plan.built;
let fps = rate.fps().as_f64();
for ahead in 0..frames {
- let time = request.time + f64::from(ahead) / fps;
- let plan = plan_frame(&timeline, quantise(time, rate));
- for layer in &plan.layers {
+ let time = seconds + f64::from(ahead) / fps;
+ let plan_at = plan_frame(timeline, quantise(time, rate));
+ for layer in &plan_at.layers {
let (decode_width, decode_height) = decode_sizes
.get(&layer.clip)
.copied()
- .unwrap_or((request.width, request.height));
+ .unwrap_or((plan.width, plan.height));
let chain = filter_chains.get(&layer.clip).map(String::as_str);
let pre = pre_chains.get(&layer.clip).map(String::as_str);
let _ = pool.frame_at(
diff --git a/engine/crates/concat-host/src/preview.rs b/engine/crates/concat-host/src/preview.rs
index 7f74371f..c85f9f81 100644
--- a/engine/crates/concat-host/src/preview.rs
+++ b/engine/crates/concat-host/src/preview.rs
@@ -18,7 +18,7 @@ use std::sync::Arc;
#[cfg(feature = "gpu")]
use std::sync::Mutex;
-use concat_export::{ExportClip, PreviewFrameRequest};
+use concat_export::ExportClip;
use concat_project::DocumentSettings;
/// A frame request: the instant and the size, with the clips coming from
@@ -37,10 +37,24 @@ pub struct FrameSpec {
#[derive(Clone)]
pub struct Monitor {
pool: Arc<concat_media::ReaderPool>,
+ /// The last clip list's plan, kept until the list changes: playback
+ /// and scrubbing ask for many instants of one document, and the plan
+ /// is the half of a frame that does not depend on the instant.
+ plan: Arc<Mutex<Option<PlanEntry>>>,
#[cfg(feature = "gpu")]
gpu: Option<Arc<Mutex<concat_render::WgpuCompositor>>>,
}
+/// One kept plan and what it was built for.
+struct PlanEntry {
+ clips: Arc<Vec<ExportClip>>,
+ width: u32,
+ height: u32,
+ rate: (i64, i64),
+ gpu: bool,
+ plan: Arc<concat_export::PreviewPlan>,
+}
+
/// The wgpu the monitor's textures belong to.
#[cfg(feature = "gpu")]
pub use concat_render::wgpu;
@@ -56,6 +70,7 @@ impl Monitor {
pub fn new() -> Self {
Self {
pool: Arc::new(concat_media::ReaderPool::with_defaults()),
+ plan: Arc::new(Mutex::new(None)),
#[cfg(feature = "gpu")]
gpu: None,
}
@@ -68,6 +83,7 @@ impl Monitor {
pub fn with_gpu(device: wgpu::Device, queue: wgpu::Queue) -> Self {
Self {
pool: Arc::new(concat_media::ReaderPool::with_defaults()),
+ plan: Arc::new(Mutex::new(None)),
gpu: Some(Arc::new(Mutex::new(
concat_render::WgpuCompositor::with_device(device, queue),
))),
@@ -93,7 +109,7 @@ impl Monitor {
#[cfg(feature = "gpu")]
pub fn frame_texture(
&self,
- clips: Vec<ExportClip>,
+ clips: Arc<Vec<ExportClip>>,
settings: &DocumentSettings,
spec: FrameSpec,
) -> Result<wgpu::Texture, String> {
@@ -101,8 +117,8 @@ impl Monitor {
.gpu
.as_ref()
.ok_or_else(|| "the monitor has no GPU device".to_owned())?;
- let request = Self::request(clips, settings, spec);
- let sources = concat_export::preview_sources(&self.pool, &request, true)?;
+ let plan = self.plan_for(clips, settings, spec, true);
+ let sources = concat_export::preview_sources_of(&self.pool, &plan, spec.time)?;
let mut gpu = gpu.lock().map_err(|_| "compositor poisoned".to_owned())?;
if sources.has_treatments() {
// A layer whose look is a shader is applied where the stack is
@@ -131,31 +147,59 @@ impl Monitor {
.ok_or_else(|| "the GPU device was lost".to_owned())
}
- fn request(
- clips: Vec<ExportClip>,
+ /// The plan for this clip list at this size and rate: the kept one
+ /// when it was built for the same list - the same allocation, or an
+ /// equal one - and a fresh one otherwise, kept in its place.
+ fn plan_for(
+ &self,
+ clips: Arc<Vec<ExportClip>>,
settings: &DocumentSettings,
spec: FrameSpec,
- ) -> PreviewFrameRequest {
- PreviewFrameRequest {
- time: spec.time,
+ gpu: bool,
+ ) -> Arc<concat_export::PreviewPlan> {
+ let rate = (settings.rate_num, settings.rate_den);
+ let mut slot = self.plan.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
+ if let Some(entry) = slot.as_ref()
+ && entry.width == spec.width
+ && entry.height == spec.height
+ && entry.rate == rate
+ && entry.gpu == gpu
+ && (Arc::ptr_eq(&entry.clips, &clips) || *entry.clips == *clips)
+ {
+ return Arc::clone(&entry.plan);
+ }
+ let plan = Arc::new(concat_export::preview_plan(
+ &clips,
+ spec.width,
+ spec.height,
+ rate.0,
+ rate.1,
+ gpu,
+ ));
+ *slot = Some(PlanEntry {
+ clips,
width: spec.width,
height: spec.height,
- rate_num: settings.rate_num,
- rate_den: settings.rate_den,
- clips,
- }
+ rate,
+ gpu,
+ plan: Arc::clone(&plan),
+ });
+ plan
}
/// The engine-composited frame at one instant, as raw RGBA bytes:
/// exactly `width * height * 4` of them.
pub fn frame(
&self,
- clips: Vec<ExportClip>,
+ clips: Arc<Vec<ExportClip>>,
settings: &DocumentSettings,
spec: FrameSpec,
) -> Result<Vec<u8>, String> {
- let request = Self::request(clips, settings, spec);
- concat_export::preview_frame(&self.pool, &request)
+ let plan = self.plan_for(clips, settings, spec, false);
+ let sources = concat_export::preview_sources_of(&self.pool, &plan, spec.time)?;
+ Ok(sources
+ .composite(&mut concat_render::CpuCompositor)
+ .into_pixels())
}
/// Decode-ahead for the playback stream: warms the pool for the next
@@ -164,17 +208,19 @@ impl Monitor {
/// caller cannot park the pool's mutex on a long decode march.
pub fn prefetch(
&self,
- clips: Vec<ExportClip>,
+ clips: Arc<Vec<ExportClip>>,
settings: &DocumentSettings,
spec: FrameSpec,
frames: u32,
) {
- let request = Self::request(clips, settings, spec);
- concat_export::preview_prefetch(&self.pool, &request, frames.min(8), self.has_gpu());
+ let plan = self.plan_for(clips, settings, spec, self.has_gpu());
+ concat_export::preview_prefetch_of(&self.pool, &plan, spec.time, frames.min(8));
}
- /// Forgets every cached frame and reader, for when the project closes.
+ /// Forgets every cached frame, reader and plan, for when the project
+ /// closes.
pub fn clear(&self) {
self.pool.clear();
+ *self.plan.lock().unwrap_or_else(|poisoned| poisoned.into_inner()) = None;
}
}
diff --git a/engine/crates/concat-render/src/compositor.rs b/engine/crates/concat-render/src/compositor.rs
index 3729261b..82162eb3 100644
--- a/engine/crates/concat-render/src/compositor.rs
+++ b/engine/crates/concat-render/src/compositor.rs
@@ -155,11 +155,11 @@ pub trait Compositor {
/// encoder, and neither has anything to show through.
fn composite(&mut self, width: u32, height: u32, layers: &[Layer<'_>]) -> Frame;
- /// Draws `layers` - each with the track it came from, bottom-most first
- /// - with every treatment applied over the stack beneath its track, the
- /// treatments in ascending track order. `None` from a compositor that
- /// cannot run passes, which the CPU reference cannot: the caller then
- /// applies the treatments its own way.
+ /// Draws `layers`, each with the track it came from and bottom-most
+ /// first, with every treatment applied over the stack beneath its
+ /// track, the treatments in ascending track order. `None` from a
+ /// compositor that cannot run passes, which the CPU reference cannot:
+ /// the caller then applies the treatments its own way.
fn composite_treated(
&mut self,
_width: u32,
diff --git a/engine/crates/concat-render/src/gpu.rs b/engine/crates/concat-render/src/gpu.rs
index 03584c11..62be0009 100644
--- a/engine/crates/concat-render/src/gpu.rs
+++ b/engine/crates/concat-render/src/gpu.rs
@@ -541,8 +541,8 @@ impl WgpuCompositor {
/// The draws of a treated frame, every treatment applied over the
/// stack beneath its track without a pixel leaving the GPU: the stack
/// below is drawn into a pooled texture, the passes run over that, and
- /// the result - blended back over the untreated stack by the strength
- /// - becomes the ground the rest is drawn on. What comes back are the
+ /// the result, blended back over the untreated stack by the strength,
+ /// becomes the ground the rest is drawn on. What comes back are the
/// draws for the final render, into whichever target the caller wants.
fn prepare_treated(
&mut self,
diff --git a/engine/crates/concat/src/lib.rs b/engine/crates/concat/src/lib.rs
index 3a2472de..a480816b 100644
--- a/engine/crates/concat/src/lib.rs
+++ b/engine/crates/concat/src/lib.rs
@@ -104,6 +104,8 @@ pub fn run() -> Result<(), slint::PlatformError> {
editor.set_visual_params(ModelRc::from(models.visual_params.clone()));
editor.set_audio_params(ModelRc::from(models.audio_params.clone()));
editor.set_adjust_params(ModelRc::from(models.adjust_params.clone()));
+ app.global::<Keyframes>().set_rows(ModelRc::from(models.key_rows.clone()));
+ app.global::<Library>().set_views(ModelRc::from(models.library_views.clone()));
editor.set_menu_items(ModelRc::from(models.menu.clone()));
app.set_caption_models(ModelRc::from(models.caption_models.clone()));
app.set_speech_models(ModelRc::from(models.speech_models.clone()));
@@ -720,7 +722,9 @@ pub fn run() -> Result<(), slint::PlatformError> {
state.clip_set_colour(field, value);
}
));
- editor.on_clip_commit(on_window!(|state| {
+ // Lanes only: the commit is held and lands with a full publish of its
+ // own once the control's moves pause; see `Studio::clip_commit`.
+ editor.on_clip_commit(on_lanes!(|state| {
state.clip_commit();
}));
diff --git a/engine/crates/concat/src/studio.rs b/engine/crates/concat/src/studio.rs
index 0e87945c..a4db7a45 100644
--- a/engine/crates/concat/src/studio.rs
+++ b/engine/crates/concat/src/studio.rs
@@ -530,6 +530,11 @@ pub struct Models {
pub audio_params: Rc<VecModel<AppliedParamData>>,
/// The colour panel's knobs.
pub adjust_params: Rc<VecModel<AppliedParamData>>,
+ /// The keyframe cluster's rows and the libraries' views: synced like
+ /// the rest, since a model handed over fresh is unequal to the last by
+ /// identity and re-evaluates every binding on it.
+ pub key_rows: Rc<VecModel<ClipKeyData>>,
+ pub library_views: Rc<VecModel<LibraryViewData>>,
pub menu: Rc<VecModel<MenuItemData>>,
pub bar: Rc<VecModel<MenuItemData>>,
/// The sheets' option lists: what is installed, and who can speak.
@@ -568,6 +573,8 @@ impl Models {
visual_params: Rc::new(VecModel::default()),
audio_params: Rc::new(VecModel::default()),
adjust_params: Rc::new(VecModel::default()),
+ key_rows: Rc::new(VecModel::default()),
+ library_views: Rc::new(VecModel::default()),
menu: Rc::new(VecModel::default()),
bar: Rc::new(VecModel::default()),
caption_models: Rc::new(VecModel::default()),
@@ -699,6 +706,23 @@ pub struct Studio {
/// card is double-clicked or its plus pressed, which lays a filter
/// layer at the playhead.
audition: Option<String>,
+ /// Counts every change to the document. What the flattened clip list
+ /// below is keyed on, so a frame of an unchanged document reuses it.
+ revision: u64,
+ /// The last flattening of the document for the monitor - titles
+ /// included - and the revision and output size it was made at. Shared
+ /// with the monitor by pointer, so it can keep its plan for as long as
+ /// the list is the same one.
+ flat: Option<(u64, u32, u32, std::sync::Arc<Vec<concat_export::ExportClip>>)>,
+ /// An inspector commit waiting to land: a knob being dragged commits
+ /// on every move, and each commit was a command, an undo of the last,
+ /// a rebuild of the mix and a full publish. The commit is held until
+ /// the moves pause; the echo shows the value meanwhile.
+ commit_pending: bool,
+ commit_timer: slint::Timer,
+ /// What the catalogue shelves were last built from; while nothing in
+ /// it changes the shelves are not rebuilt.
+ shelf_stamp: std::cell::RefCell<Option<ShelfStamp>>,
/// The card stills of the user's own looks, by package id, loaded once
/// from the package folder's `preview.png` and kept: the shelves are
/// rebuilt on every publish and a picture read from disk each time
@@ -977,6 +1001,15 @@ fn set_slot(
});
}
+/// What the catalogue shelves are a function of; see `Studio::shelf_stamp`.
+#[derive(PartialEq)]
+struct ShelfStamp {
+ catalogue: usize,
+ lang: String,
+ views: Vec<(String, i32, bool)>,
+ favourites: Vec<String>,
+}
+
/// The built-in colour package's id; see `adjust_rows` and `Studio::adjust_set`.
const ADJUST_ID: &str = "concat.adjust";
@@ -1293,6 +1326,11 @@ impl Studio {
stage_guides: Vec::new(),
inspector_jump: (0, "", ""),
audition: None,
+ revision: 0,
+ flat: None,
+ commit_pending: false,
+ commit_timer: slint::Timer::default(),
+ shelf_stamp: std::cell::RefCell::new(None),
look_art: std::cell::RefCell::new(HashMap::new()),
last_commit: None,
title_blocks: HashMap::new(),
@@ -1482,6 +1520,7 @@ impl Studio {
/// A refusal becomes a notice; the echo, if any, is dropped either way,
/// because the session's project is the truth again.
pub fn apply(&mut self, command: Command) -> Option<String> {
+ self.flush_commit();
self.echo = None;
// Anything but an inspector commit ends the coalescing window; the
// commit path sets `last_commit` again right after calling here.
@@ -1503,6 +1542,7 @@ impl Studio {
/// follow the document, the autosave, the monitor and the mix.
fn after_change(&mut self) {
self.dirty = true;
+ self.revision += 1;
self.assign_media_rows();
let survivors: HashSet<String> = self
.timeline()
@@ -1520,6 +1560,7 @@ impl Studio {
}
pub fn undo(&mut self) {
+ self.flush_commit();
self.echo = None;
if let Some(session) = self.session.as_mut()
&& session.can_undo()
@@ -1530,6 +1571,7 @@ impl Studio {
}
pub fn redo(&mut self) {
+ self.flush_commit();
self.echo = None;
if let Some(session) = self.session.as_mut()
&& session.can_redo()
@@ -1662,17 +1704,38 @@ impl Studio {
// folder included: that is what names a cutout's masks, and
// without it the monitor would show every cutout as shot.
let project_dir = std::path::PathBuf::from(session.path());
- let mut clips = concat_export::flatten::flatten_timeline_in(
- self.project(),
- None,
- Some(&project_dir),
- );
let (width, height) = self.output_size();
- // Titles, painted to pictures and rejoined; see concat-host's titles.
- for title in self.host.titles.clips(self.project(), width, height) {
- self.title_blocks.insert(title.clip_id, title.block);
- clips.push(title.clip);
- }
+ // The flattening is the document's, not the frame's: kept between
+ // frames of an unchanged document and handed over by pointer, so
+ // playback and scrubbing neither flatten nor plan again. A gesture
+ // in flight - the echo - is not the document, and flattens fresh.
+ let cached = self.echo.is_none()
+ && self
+ .flat
+ .as_ref()
+ .is_some_and(|(at, w, h, _)| *at == self.revision && *w == width && *h == height);
+ let clips = if cached {
+ std::sync::Arc::clone(&self.flat.as_ref().expect("checked").3)
+ } else {
+ let mut clips = concat_export::flatten::flatten_timeline_in(
+ self.project(),
+ None,
+ Some(&project_dir),
+ );
+ // Titles, painted to pictures and rejoined; see concat-host's titles.
+ for title in self.host.titles.clips(self.project(), width, height) {
+ self.title_blocks.insert(title.clip_id, title.block);
+ clips.push(title.clip);
+ }
+ let clips = std::sync::Arc::new(clips);
+ if self.echo.is_none() {
+ self.flat = Some((self.revision, width, height, std::sync::Arc::clone(&clips)));
+ }
+ clips
+ };
+ // The frame's own additions - a look being shown, a cutout being
+ // painted - go on a copy, so the kept list stays the document's.
+ let mut own: Option<Vec<concat_export::ExportClip>> = None;
let scale = match self.quality_of() {
0 => 1.0,
1 => 0.5,
@@ -1687,7 +1750,7 @@ impl Studio {
let effects = vec![AppliedFilter::new(filter_id)];
let video_filter_chain = concat_export::chains::video_effect_chain(&effects);
let track = clips.iter().map(|flat| flat.track).max().map_or(0, |top| top + 1);
- clips.push(concat_export::ExportClip {
+ own.get_or_insert_with(|| (*clips).clone()).push(concat_export::ExportClip {
path: String::new(),
kind: concat_export::ClipKind::Layer,
start: 0.0,
@@ -1735,12 +1798,17 @@ impl Studio {
if self.painting
&& let Some(target) = self.paint_target()
&& let Some(media) = self.project().media_by_id(&target.media_id)
- && let Some(flat) = clips.iter_mut().find(|flat| {
- flat.path == media.path && (flat.start - target.start).abs() < 1e-6
- })
{
- flat.highlighted = true;
+ let (path, start) = (media.path.clone(), target.start);
+ if let Some(flat) = own
+ .get_or_insert_with(|| (*clips).clone())
+ .iter_mut()
+ .find(|flat| flat.path == path && (flat.start - start).abs() < 1e-6)
+ {
+ flat.highlighted = true;
+ }
}
+ let clips = own.map(std::sync::Arc::new).unwrap_or(clips);
let spec = FrameSpec {
time: f64::from(self.playhead),
width,
@@ -1756,11 +1824,11 @@ impl Studio {
// one it comes back as pixels and is uploaded here.
let frame = if monitor.has_gpu() {
monitor
- .frame_texture(clips.clone(), &settings, spec)
+ .frame_texture(std::sync::Arc::clone(&clips), &settings, spec)
.map(Picture::Texture)
} else {
monitor
- .frame(clips.clone(), &settings, spec)
+ .frame(std::sync::Arc::clone(&clips), &settings, spec)
.map(|bytes| Picture::Pixels(bytes, width, height))
};
// Decode-ahead for whatever comes next, while the pool is warm.
@@ -2700,6 +2768,7 @@ impl Studio {
vec![id.to_owned()]
};
+ self.flush_commit();
self.begin_echo();
if edge >= 0 && self.selection.len() <= 1 {
self.gesture = Gesture::Trim {
@@ -3059,7 +3128,38 @@ impl Studio {
/// The inspector's gesture is over: what differs between the echo and
/// the session becomes commands, as one batch.
+ /// An inspector control changed something on the echo and wants it
+ /// committed. Held, not applied: a knob commits on every move, and the
+ /// command, the mix and the publish happen once the moves pause. The
+ /// monitor follows the echo in the meantime.
pub fn clip_commit(&mut self) {
+ self.commit_pending = true;
+ self.request_preview();
+ self.commit_timer.start(
+ slint::TimerMode::SingleShot,
+ std::time::Duration::from_millis(120),
+ || {
+ crate::host::Shell::with(|shell, app| {
+ shell.studio.borrow_mut().flush_commit();
+ shell.studio.borrow().publish(&app, &shell.models);
+ });
+ },
+ );
+ }
+
+ /// Lands the held commit now, if there is one. Called before anything
+ /// that would drop the echo it lives on - a command from elsewhere, an
+ /// undo, a gesture on the lanes or the stage.
+ pub fn flush_commit(&mut self) {
+ if !self.commit_pending {
+ return;
+ }
+ self.commit_pending = false;
+ self.commit_timer.stop();
+ self.commit_now();
+ }
+
+ fn commit_now(&mut self) {
let Some(id) = self.sole_selection() else {
self.echo = None;
return;
@@ -3426,6 +3526,7 @@ impl Studio {
offset_y: clip.offset_y,
})
.collect();
+ self.flush_commit();
self.begin_echo();
self.stage_guides.clear();
self.gesture = Gesture::StageMove {
@@ -3471,6 +3572,7 @@ impl Studio {
let dx = f64::from(x) * f64::from(width) - centre.0;
let dy = f64::from(y) * f64::from(height) - centre.1;
let half = footprint.half_bounds((width, height));
+ self.flush_commit();
self.begin_echo();
self.gesture = if grip == 4 {
Gesture::StageRotate {
@@ -4292,6 +4394,8 @@ impl Studio {
self.recents = projects::list(&self.host.dirs.config);
self.host.monitor.clear();
self.audition = None;
+ self.revision += 1;
+ self.flat = None;
self.sync_audio();
self.request_media_art();
self.request_preview();
@@ -4360,6 +4464,8 @@ impl Studio {
self.preview = slint::Image::default();
self.host.monitor.clear();
self.audition = None;
+ self.revision += 1;
+ self.flat = None;
self.host
.playback
.set_clips(std::path::PathBuf::new(), Vec::new());
@@ -5238,7 +5344,7 @@ impl Studio {
let keys = app.global::<Keyframes>();
let rows = self.key_rows();
keys.set_available(!rows.is_empty());
- keys.set_rows(slint::ModelRc::from(Rc::new(VecModel::from(rows))));
+ sync(&models.key_rows, rows);
editor.set_inspector_jump_token(self.inspector_jump.0);
editor.set_library_audition(self.audition_of().unwrap_or("").into());
editor.set_inspector_jump_tab(self.inspector_jump.1.into());
@@ -5745,26 +5851,39 @@ impl Studio {
// through, so they are rebuilt here and `sync` makes an unchanged
// one a no-op.
let starred = &self.prefs.favourites;
- let (groups, entries) = shelves(SHELF_KINDS[0], &self.library[0], starred, &self.look_art);
- sync(&models.filter_groups, groups);
- sync(&models.catalogue_filters, entries);
- let (groups, entries) = shelves(SHELF_KINDS[1], &self.library[1], starred, &self.look_art);
- sync(&models.effect_groups, groups);
- sync(&models.catalogue_effects, entries);
- let (groups, entries) = shelves(SHELF_KINDS[2], &self.library[2], starred, &self.look_art);
- sync(&models.audio_groups, groups);
- sync(&models.catalogue_audio, entries);
- app.global::<Library>()
- .set_views(slint::ModelRc::from(Rc::new(VecModel::from(
- self.library
- .iter()
- .map(|view| LibraryViewData {
- query: view.query.as_str().into(),
- group: view.group,
- favourites: view.favourites,
- })
- .collect::<Vec<_>>(),
- ))));
+ let stamp = ShelfStamp {
+ catalogue: std::ptr::from_ref(Catalogue::builtin()) as usize,
+ lang: i18n::current(),
+ views: self
+ .library
+ .iter()
+ .map(|view| (view.query.clone(), view.group, view.favourites))
+ .collect(),
+ favourites: starred.clone(),
+ };
+ if self.shelf_stamp.borrow().as_ref() != Some(&stamp) {
+ let (groups, entries) = shelves(SHELF_KINDS[0], &self.library[0], starred, &self.look_art);
+ sync(&models.filter_groups, groups);
+ sync(&models.catalogue_filters, entries);
+ let (groups, entries) = shelves(SHELF_KINDS[1], &self.library[1], starred, &self.look_art);
+ sync(&models.effect_groups, groups);
+ sync(&models.catalogue_effects, entries);
+ let (groups, entries) = shelves(SHELF_KINDS[2], &self.library[2], starred, &self.look_art);
+ sync(&models.audio_groups, groups);
+ sync(&models.catalogue_audio, entries);
+ *self.shelf_stamp.borrow_mut() = Some(stamp);
+ }
+ sync(
+ &models.library_views,
+ self.library
+ .iter()
+ .map(|view| LibraryViewData {
+ query: view.query.as_str().into(),
+ group: view.group,
+ favourites: view.favourites,
+ })
+ .collect(),
+ );
app.set_on_start(self.on_start);
app.set_project_name(self.project_name.as_str().into());