diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index b322447..22367e9 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -130,6 +130,10 @@ actions! { Equalizer, Speed, Silence, + /// Crossfades the selected audio clip into its neighbour ([`Project::crossfade`]): + /// two adjacent clips picked on one lane, or a single pick faded into the + /// clip right after it. + Crossfade, Mix, ToggleSnap, ToggleSubtitles, @@ -220,6 +224,7 @@ impl ActionId { ActionId::Equalizer => "Equalizer", ActionId::Speed => "Speed (tape)…", ActionId::Silence => "Silences: cut or speed up…", + ActionId::Crossfade => "Crossfade into the next clip", ActionId::Mix => "Mix: track volumes and the limiter…", ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)", ActionId::ToggleSubtitles => "Subtitles on / off over the picture", @@ -286,6 +291,7 @@ impl ActionId { ActionId::Equalizer => "equalizer", ActionId::Speed => "speed", ActionId::Silence => "silence", + ActionId::Crossfade => "crossfade", ActionId::Mix => "mix", ActionId::ToggleSnap => "toggle-snap", ActionId::ToggleSubtitles => "toggle-subtitles", @@ -339,7 +345,8 @@ impl ActionId { // The scan reads a clip's sound, but what it does is edit the // timeline the clip is on -- it is a clip card like the three // above it, opened on whichever half was picked. - | ActionId::Silence => Category::Clips, + | ActionId::Silence + | ActionId::Crossfade => Category::Clips, // The project's own picture size is not a clip's business, and not // a file operation either: it is what the viewer is looking at. // Neither is how much of the timeline the panel shows: a zoom edits @@ -953,6 +960,10 @@ impl Keymap { // delete (x and delete) -- what it opens is a card that can cut // forty places at once. b(ActionId::Silence, "u", false), + // Crossfade takes ctrl+f: the mnemonic letter for "fade", with + // ctrl its own room now that plain "f" is the mix card's own + // (below) -- the same letter, the modifier telling them apart. + b(ActionId::Crossfade, "f", true), // The mix card takes "f", for the faders on it: "m" would be // the word but it is the monitoring mute, which is this // machine's volume and not the project's -- two things one key @@ -1265,7 +1276,7 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 61); + assert_eq!(k.entries().len(), 62); assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 5a21b37..ca77480 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -53,6 +53,7 @@ impl Player { | ActionId::AddSubtitleLane | ActionId::RemoveSubtitleLane | ActionId::ImportSubtitles + | ActionId::Crossfade ) { self.mark_dirty(); } @@ -88,6 +89,7 @@ impl Player { ActionId::Paste => self.paste(cx), ActionId::Cut => self.cut(cx), ActionId::Regroup => self.regroup(cx), + ActionId::Crossfade => self.crossfade_selected(cx), ActionId::Detach => self.detach(cx), ActionId::Group => self.group(cx), ActionId::Select => self.select_under_playhead(cx), diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index c796653..e856c25 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1267,6 +1267,34 @@ impl Player { } } + /// Crossfades across the join the selection names: two picks on one audio + /// lane take the pair, one pick takes it and its right-hand neighbour. The + /// engine owns adjacency ([`Project::crossfade`]); a refusal is worded + /// here, in [`Player::regroup`]'s voice, because `false` is all it says. + pub(crate) fn crossfade_selected(&mut self, cx: &mut Context) { + if self.exporting().is_some() { + return; + } + let Some((lane, idx)) = (match self.selected.picks() { + [a, b] if a.0 == b.0 && a.1.abs_diff(b.1) == 1 => Some((a.0, a.1.min(b.1))), + _ => self.selected.anchor(), + }) else { + self.notify_user("NOTHING TO CROSSFADE — select an audio clip that has a neighbour".into()); + cx.notify(); + return; + }; + let frames = self.fps.round().max(1.) as u32; + if let Some(session) = &mut self.session { + if !session.crossfade(lane, idx, frames) { + self.notify_user( + "NOTHING TO CROSSFADE — it takes two audio clips sitting end to end on one lane" + .into(), + ); + } + } + cx.notify(); + } + /// The clip as the drag is showing it: an edge under the pointer moves its /// own box, and the boxes of everything linked to it, before anything is /// committed. Display only -- the project is not touched until the release. diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index 0421f74..5a57fe8 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -2042,3 +2042,17 @@ fn frac_along_measures_from_the_elements_own_left_edge() { // to +12 dB on the first press. assert_eq!(frac_down(px(50.), Bounds::default()), 0.5); } + +/// A fade handle's pixels turn into frames at the bed's own scale, and a +/// degenerate scale (nothing painted) turns into no movement at all. +#[test] +fn a_fade_drag_converts_pixels_to_frames_at_the_beds_scale() { + use crate::timeline_math::fade_delta_frames; + // 100 px/s at 25 fps: one second of pixels is one second of frames. + assert_eq!(fade_delta_frames(100., 100., 25.), 25); + // Signed: dragging back shrinks the fade by the same conversion. + assert_eq!(fade_delta_frames(-50., 100., 25.), -13); + // Nothing drawn to drag against moves nothing. + assert_eq!(fade_delta_frames(40., 0., 25.), 0); + assert_eq!(fade_delta_frames(40., -1., 25.), 0); +}