A crossfade key joins two audio clips end to end (ctrl+f)
Browse files at this commit43b4f691dfd85b19439be29e9f764251021abc8cParent: 8cb7334- feat
- a crossfade key joins two audio clips end to end (ctrl+f)
4 changed files +57 -2
- crates/app/src/keymap.rs +13 -2
- crates/app/src/player/actions.rs +2 -0
- crates/app/src/player/timeline_edit.rs +28 -0
- crates/app/src/tests/editing.rs +14 -0
crates/app/src/keymap.rsmodified+13 -2
| @@ -130,6 +130,10 @@ actions! { | |||
| 130 | Equalizer, | 130 | Equalizer, |
| 131 | Speed, | 131 | Speed, |
| 132 | Silence, | 132 | Silence, |
| 133 | + /// Crossfades the selected audio clip into its neighbour ([`Project::crossfade`]): | ||
| 134 | + /// two adjacent clips picked on one lane, or a single pick faded into the | ||
| 135 | + /// clip right after it. | ||
| 136 | + Crossfade, | ||
| 133 | Mix, | 137 | Mix, |
| 134 | ToggleSnap, | 138 | ToggleSnap, |
| 135 | ToggleSubtitles, | 139 | ToggleSubtitles, |
| @@ -220,6 +224,7 @@ impl ActionId { | |||
| 220 | ActionId::Equalizer => "Equalizer", | 224 | ActionId::Equalizer => "Equalizer", |
| 221 | ActionId::Speed => "Speed (tape)…", | 225 | ActionId::Speed => "Speed (tape)…", |
| 222 | ActionId::Silence => "Silences: cut or speed up…", | 226 | ActionId::Silence => "Silences: cut or speed up…", |
| 227 | + ActionId::Crossfade => "Crossfade into the next clip", | ||
| 223 | ActionId::Mix => "Mix: track volumes and the limiter…", | 228 | ActionId::Mix => "Mix: track volumes and the limiter…", |
| 224 | ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)", | 229 | ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)", |
| 225 | ActionId::ToggleSubtitles => "Subtitles on / off over the picture", | 230 | ActionId::ToggleSubtitles => "Subtitles on / off over the picture", |
| @@ -286,6 +291,7 @@ impl ActionId { | |||
| 286 | ActionId::Equalizer => "equalizer", | 291 | ActionId::Equalizer => "equalizer", |
| 287 | ActionId::Speed => "speed", | 292 | ActionId::Speed => "speed", |
| 288 | ActionId::Silence => "silence", | 293 | ActionId::Silence => "silence", |
| 294 | + ActionId::Crossfade => "crossfade", | ||
| 289 | ActionId::Mix => "mix", | 295 | ActionId::Mix => "mix", |
| 290 | ActionId::ToggleSnap => "toggle-snap", | 296 | ActionId::ToggleSnap => "toggle-snap", |
| 291 | ActionId::ToggleSubtitles => "toggle-subtitles", | 297 | ActionId::ToggleSubtitles => "toggle-subtitles", |
| @@ -339,7 +345,8 @@ impl ActionId { | |||
| 339 | // The scan reads a clip's sound, but what it does is edit the | 345 | // The scan reads a clip's sound, but what it does is edit the |
| 340 | // timeline the clip is on -- it is a clip card like the three | 346 | // timeline the clip is on -- it is a clip card like the three |
| 341 | // above it, opened on whichever half was picked. | 347 | // above it, opened on whichever half was picked. |
| 342 | - | ActionId::Silence => Category::Clips, | 348 | + | ActionId::Silence |
| 349 | + | ActionId::Crossfade => Category::Clips, | ||
| 343 | // The project's own picture size is not a clip's business, and not | 350 | // The project's own picture size is not a clip's business, and not |
| 344 | // a file operation either: it is what the viewer is looking at. | 351 | // a file operation either: it is what the viewer is looking at. |
| 345 | // Neither is how much of the timeline the panel shows: a zoom edits | 352 | // Neither is how much of the timeline the panel shows: a zoom edits |
| @@ -953,6 +960,10 @@ impl Keymap { | |||
| 953 | // delete (x and delete) -- what it opens is a card that can cut | 960 | // delete (x and delete) -- what it opens is a card that can cut |
| 954 | // forty places at once. | 961 | // forty places at once. |
| 955 | b(ActionId::Silence, "u", false), | 962 | b(ActionId::Silence, "u", false), |
| 963 | + // Crossfade takes ctrl+f: the mnemonic letter for "fade", with | ||
| 964 | + // ctrl its own room now that plain "f" is the mix card's own | ||
| 965 | + // (below) -- the same letter, the modifier telling them apart. | ||
| 966 | + b(ActionId::Crossfade, "f", true), | ||
| 956 | // The mix card takes "f", for the faders on it: "m" would be | 967 | // The mix card takes "f", for the faders on it: "m" would be |
| 957 | // the word but it is the monitoring mute, which is this | 968 | // the word but it is the monitoring mute, which is this |
| 958 | // machine's volume and not the project's -- two things one key | 969 | // machine's volume and not the project's -- two things one key |
| @@ -1265,7 +1276,7 @@ mod tests { | |||
| 1265 | #[test] | 1276 | #[test] |
| 1266 | fn every_default_stroke_reaches_its_action() { | 1277 | fn every_default_stroke_reaches_its_action() { |
| 1267 | let k = Keymap::defaults(); | 1278 | let k = Keymap::defaults(); |
| 1268 | - assert_eq!(k.entries().len(), 61); | 1279 | + assert_eq!(k.entries().len(), 62); |
| 1269 | assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); | 1280 | assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); |
| 1270 | assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); | 1281 | assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); |
| 1271 | assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); | 1282 | assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); |
crates/app/src/player/actions.rsmodified+2 -0
| @@ -53,6 +53,7 @@ impl Player { | |||
| 53 | | ActionId::AddSubtitleLane | 53 | | ActionId::AddSubtitleLane |
| 54 | | ActionId::RemoveSubtitleLane | 54 | | ActionId::RemoveSubtitleLane |
| 55 | | ActionId::ImportSubtitles | 55 | | ActionId::ImportSubtitles |
| 56 | + | ActionId::Crossfade | ||
| 56 | ) { | 57 | ) { |
| 57 | self.mark_dirty(); | 58 | self.mark_dirty(); |
| 58 | } | 59 | } |
| @@ -88,6 +89,7 @@ impl Player { | |||
| 88 | ActionId::Paste => self.paste(cx), | 89 | ActionId::Paste => self.paste(cx), |
| 89 | ActionId::Cut => self.cut(cx), | 90 | ActionId::Cut => self.cut(cx), |
| 90 | ActionId::Regroup => self.regroup(cx), | 91 | ActionId::Regroup => self.regroup(cx), |
| 92 | + ActionId::Crossfade => self.crossfade_selected(cx), | ||
| 91 | ActionId::Detach => self.detach(cx), | 93 | ActionId::Detach => self.detach(cx), |
| 92 | ActionId::Group => self.group(cx), | 94 | ActionId::Group => self.group(cx), |
| 93 | ActionId::Select => self.select_under_playhead(cx), | 95 | ActionId::Select => self.select_under_playhead(cx), |
crates/app/src/player/timeline_edit.rsmodified+28 -0
| @@ -1267,6 +1267,34 @@ impl Player { | |||
| 1267 | } | 1267 | } |
| 1268 | } | 1268 | } |
| 1269 | 1269 | ||
| 1270 | + /// Crossfades across the join the selection names: two picks on one audio | ||
| 1271 | + /// lane take the pair, one pick takes it and its right-hand neighbour. The | ||
| 1272 | + /// engine owns adjacency ([`Project::crossfade`]); a refusal is worded | ||
| 1273 | + /// here, in [`Player::regroup`]'s voice, because `false` is all it says. | ||
| 1274 | + pub(crate) fn crossfade_selected(&mut self, cx: &mut Context<Self>) { | ||
| 1275 | + if self.exporting().is_some() { | ||
| 1276 | + return; | ||
| 1277 | + } | ||
| 1278 | + let Some((lane, idx)) = (match self.selected.picks() { | ||
| 1279 | + [a, b] if a.0 == b.0 && a.1.abs_diff(b.1) == 1 => Some((a.0, a.1.min(b.1))), | ||
| 1280 | + _ => self.selected.anchor(), | ||
| 1281 | + }) else { | ||
| 1282 | + self.notify_user("NOTHING TO CROSSFADE — select an audio clip that has a neighbour".into()); | ||
| 1283 | + cx.notify(); | ||
| 1284 | + return; | ||
| 1285 | + }; | ||
| 1286 | + let frames = self.fps.round().max(1.) as u32; | ||
| 1287 | + if let Some(session) = &mut self.session { | ||
| 1288 | + if !session.crossfade(lane, idx, frames) { | ||
| 1289 | + self.notify_user( | ||
| 1290 | + "NOTHING TO CROSSFADE — it takes two audio clips sitting end to end on one lane" | ||
| 1291 | + .into(), | ||
| 1292 | + ); | ||
| 1293 | + } | ||
| 1294 | + } | ||
| 1295 | + cx.notify(); | ||
| 1296 | + } | ||
| 1297 | + | ||
| 1270 | /// The clip as the drag is showing it: an edge under the pointer moves its | 1298 | /// The clip as the drag is showing it: an edge under the pointer moves its |
| 1271 | /// own box, and the boxes of everything linked to it, before anything is | 1299 | /// own box, and the boxes of everything linked to it, before anything is |
| 1272 | /// committed. Display only -- the project is not touched until the release. | 1300 | /// committed. Display only -- the project is not touched until the release. |
crates/app/src/tests/editing.rsmodified+14 -0
| @@ -2042,3 +2042,17 @@ fn frac_along_measures_from_the_elements_own_left_edge() { | |||
| 2042 | // to +12 dB on the first press. | 2042 | // to +12 dB on the first press. |
| 2043 | assert_eq!(frac_down(px(50.), Bounds::default()), 0.5); | 2043 | assert_eq!(frac_down(px(50.), Bounds::default()), 0.5); |
| 2044 | } | 2044 | } |
| 2045 | + | ||
| 2046 | +/// A fade handle's pixels turn into frames at the bed's own scale, and a | ||
| 2047 | +/// degenerate scale (nothing painted) turns into no movement at all. | ||
| 2048 | +#[test] | ||
| 2049 | +fn a_fade_drag_converts_pixels_to_frames_at_the_beds_scale() { | ||
| 2050 | + use crate::timeline_math::fade_delta_frames; | ||
| 2051 | + // 100 px/s at 25 fps: one second of pixels is one second of frames. | ||
| 2052 | + assert_eq!(fade_delta_frames(100., 100., 25.), 25); | ||
| 2053 | + // Signed: dragging back shrinks the fade by the same conversion. | ||
| 2054 | + assert_eq!(fade_delta_frames(-50., 100., 25.), -13); | ||
| 2055 | + // Nothing drawn to drag against moves nothing. | ||
| 2056 | + assert_eq!(fade_delta_frames(40., 0., 25.), 0); | ||
| 2057 | + assert_eq!(fade_delta_frames(40., -1., 25.), 0); | ||
| 2058 | +} | ||