From b586b858f56856f2acbea13ca688d60f3f53b384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 10 Aug 2026 19:54:11 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(timeline):=20a=20pasted=20st?= =?UTF-8?q?ill=20never=20lands=20on=20the=20audio=20lane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Project::paste` routed by `is_audio` alone, so a *copied* still clip -- the one door that does not go through `place_stream_at` -- was pasted as a grouped take across `V1` and `A1`. The A1 half is a PNG the audio worker demuxes: "file contains a box with a larger size than it", which silences the whole session rather than that clip, and the save it writes is one `open_project` then refuses by name. An `is_image` arm mirrors the audio-only one. Same-shape sweep of every clip-level door that routes by source kind: - `Project::paste` (project.rs) -- this defect, fixed. - `PlaybackSession::place_stream_at` -- already routed, image arm returns on the video lane before the audio fork. - `PlaybackSession::open`/`open_project` -- both directions refused by name at load. - `Project::move_to_lane` -- refuses a move across kinds, so no clip can cross by drag. Clean. - `Project::place`, `split`, `regroup`, `lift`, `delete_in`, `trim` -- the caller names the lane or the lane never changes. Clean, and the loader is the backstop for a hand-written file either way. - `Player::insert_source` (app) -- guarded both ways already. Falsification: with the `(_, true) => &[LaneKind::Video]` arm removed the new test fails at the lane count (A1 1 -> 2), and with that assertion lifted it fails on the WAV export with the demux error above -- the two consequences the test names, both reachable. Two doc corrections found with it: `Still::open` now says alpha is dropped by `to_rgb8` (a transparent PNG lands opaque, with the blend as the ponytail), and `first_audio_of` no longer implies an image-first timeline accepts a later audio import -- it widens which source is asked, not what "the timeline is silent" means. tests: images 7/7 (new `pasting_a_copied_still_never_reaches_the_audio_lane` asserts no A1 clip, no audio clip from a picture, the WAV export still carries the sound, and the save reopens), engine lib 155, saveload 12, audio_files 16, lanes 5 (serial), bin 56. --- crates/engine/src/decode.rs | 10 +++++ crates/engine/src/playback.rs | 12 ++++-- crates/engine/src/project.rs | 19 ++++++--- crates/engine/tests/images.rs | 77 +++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 9 deletions(-) diff --git a/crates/engine/src/decode.rs b/crates/engine/src/decode.rs index 3433ab3..5a8b170 100644 --- a/crates/engine/src/decode.rs +++ b/crates/engine/src/decode.rs @@ -446,6 +446,16 @@ impl Still { /// Decodes `path`. Refused by name for a picture that is not one /// ([`crate::is_resolution`]): an 8K limit that a keystroke and a project /// file are both held to cannot be walked around by a 30000-pixel-wide PNG. + /// + /// Alpha is *dropped*, not composited: `to_rgb8` discards the channel, so a + /// transparent PNG arrives fully opaque over its own colours rather than + /// over the clip beneath it. I420 has nowhere to carry it and this engine + /// composes one picture per frame (topmost lane wins), so there is nothing + /// for a blend to blend with. + /// + /// ponytail: the ceiling is a logo with a transparent background, which + /// lands as a rectangle. Upgrade path is keeping the alpha plane here and + /// giving `scale::Composer` a blend over the lane below. pub(crate) fn open(path: &Path) -> crate::Result { let reader = image::ImageReader::open(path)?.with_guessed_format()?; let rgb = reader diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index cc4fa79..1abb98c 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -1637,9 +1637,15 @@ fn matches_timeline( /// export time (`AudioSession::copy_multi_streams`). /// What a timeline's audio is held to: the probe of the first source that could /// have any. A still image is never it -- a picture defines no rate and no -/// layout, and taking its silence for the timeline's would refuse every sound -/// imported after it. `Ok(None)` for a timeline of nothing but stills, which is -/// a silent one. +/// layout, so a PNG at index 0 would otherwise be *probed* as a broken mp4 and +/// fail the open outright. +/// +/// `Ok(None)` for a timeline whose first such source is silent, and for one of +/// nothing but stills. That is a silent timeline, and a file with sound is +/// still refused by [`audio_matches`] in the words it always used ("the file +/// has audio, the timeline is silent") -- the same answer a silent *video* as +/// source 0 has always given. This function widens which source is asked, not +/// what the answer means. fn first_audio_of(sources: &[Source]) -> crate::Result> { match sources.iter().find(|s| !crate::is_image(&s.path)) { Some(first) => AudioSession::probe(&first.path, first.audio_stream), diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 231d989..ca4c9d5 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1390,8 +1390,10 @@ impl Project { /// twice over (and leave an mp4 export with two tracks to copy). A clip of a /// source with no picture ([`crate::is_audio`]) reaches `A1` only -- on a /// video lane it is a clip that decodes to nothing, and a save carrying one - /// does not open again. The room is still opened everywhere, or the lanes it - /// was not inserted into would slide out of step with the ones it was. + /// does not open again -- and a still image ([`crate::is_image`]) reaches + /// `V1` only, for the mirror of that reason. The room is still opened + /// everywhere, or the lanes it was not inserted into would slide out of step + /// with the ones it was. /// /// Exactly one history snapshot, so one [`Project::undo`] takes it back. /// Changes the timeline->source mapping: the caller must reseek. Refused for @@ -1407,6 +1409,11 @@ impl Project { return false; } let audio_only = crate::is_audio(&source.path); + // ...and its mirror: a still is a picture and no sound, so a copy of one + // reaches `V1` only. Pasted onto `A1` as well it is a PNG the audio + // worker tries to demux -- which silences the *whole session*, not just + // that clip -- and a save the engine's own `open_project` then refuses. + let picture_only = crate::is_image(&source.path); let at = timeline_frame.min(self.timeline_frames()); let len = clip.len(); // Room for it: `open_room` adds `len` to every start from `at` on, and a @@ -1433,10 +1440,10 @@ impl Project { // an audio lane and nowhere else, exactly as `place_stream_at` decides // it for an import. On a video lane it would decode to nothing, and the // save it wrote would not open again. - let kinds: &[LaneKind] = if audio_only { - &[LaneKind::Audio] - } else { - &[LaneKind::Video, LaneKind::Audio] + let kinds: &[LaneKind] = match (audio_only, picture_only) { + (true, _) => &[LaneKind::Audio], + (_, true) => &[LaneKind::Video], + _ => &[LaneKind::Video, LaneKind::Audio], }; let takes: Vec = kinds .iter() diff --git a/crates/engine/tests/images.rs b/crates/engine/tests/images.rs index e7b17d8..aab2847 100644 --- a/crates/engine/tests/images.rs +++ b/crates/engine/tests/images.rs @@ -15,6 +15,7 @@ use std::path::PathBuf; use std::sync::Once; use std::time::{Duration, Instant}; +use engine::export::{ExportSettings, Format}; use engine::project::{Edge, Lane, LaneKind}; use engine::{DecodeSession, ExportHandle, PlaybackSession}; @@ -209,6 +210,82 @@ fn a_still_trims_out_to_its_cap_and_no_further() { assert_eq!(session.lane_clips(Lane::V1)[0].len(), 60); } +/// The *clipboard* door, which is the second way a clip picks its lanes and +/// the one that does not go through `place_stream_at`: a copied still pasted at +/// the playhead is a grouped take everywhere else, and a take of a picture with +/// no sound is one lane. Pasted onto `A1` as well it would be a PNG the audio +/// worker demuxes -- which silences the whole session, not just that clip -- +/// and a save the engine's own loader then refuses. +/// +/// Both consequences are asserted, not just the lane count: the failure this +/// guards against was invisible in the clip list. +#[test] +fn pasting_a_copied_still_never_reaches_the_audio_lane() { + pin_software(); + let dir = std::env::temp_dir().join(format!("ve_images_paste_{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("scratch dir"); + let media = dir.join("test_av.mp4"); + let still = dir.join("test_still.png"); + std::fs::copy(asset("test_av.mp4"), &media).expect("copy the video"); + std::fs::copy(asset("test_still.png"), &still).expect("copy the still"); + + let mut session = PlaybackSession::open(&media).expect("open the fixture"); + session.set_gain(0.0); + session.import(&still).expect("a picture"); + let end = session.timeline_duration(); + assert!( + session + .place_stream_at(end, &still, 0, Some(Lane::V1)) + .expect("a still joins any timeline") + ); + let audio_clips = session.lane_clips(Lane::A1).len(); + + // Copy the still clip and paste it at the playhead, exactly as the app's + // ctrl+c / ctrl+v pair does (`Player::copy` takes `clip_at`, `Player::paste` + // hands it to `paste_at`). + let last = session.lane_clips(Lane::V1).len() - 1; + let copied = session.clip_at(last).expect("the clipboard sees the still"); + session.seek(0.0); + assert!(session.paste_at(0.0, copied), "the paste takes"); + + assert_eq!( + session.lane_clips(Lane::A1).len(), + audio_clips, + "a still is silent: the audio lane gains nothing from a paste" + ); + assert!( + session + .lane_clips(Lane::A1) + .iter() + .all(|c| !engine::is_image(&session.sources()[c.source].path)), + "no audio clip may play from a picture" + ); + // The sound itself, through the one public door that reads the same play + // list playback feeds from (`audio_segments_from` -> + // `open_mixed_streams_eq`): a WAV export. With a PNG on the audio lane this + // is the demux error that silences the session, not a file. + let wav = dir.join("pasted.wav"); + let settings = ExportSettings { + format: Format::Wav, + ..ExportSettings::default() + }; + wait( + &session.export_to_with(&wav, &settings), + Duration::from_secs(120), + ) + .expect("the timeline's sound is still there"); + assert!( + std::fs::metadata(&wav).expect("the wav exists").len() > 1_000, + "a silent-by-failure export would be the header alone" + ); + // ...and the save the engine writes is one the engine can open. + let project = dir.join("pasted.edith"); + session.save_project(&project).expect("save"); + PlaybackSession::open_project(&project).expect("the engine's own save reopens"); + let _ = std::fs::remove_dir_all(&dir); +} + /// Saved and reopened: the clip that comes back plays the same picture for the /// same frames. The reload recomputes the still's length, so a clip trimmed out /// to the cap has to still be inside it -- `open_project` refuses one that is