| 1 | |
| 2 | |
| 3 | |
| 4 | use super::*; |
| 5 | |
| 6 | |
| 7 | |
| 8 | #[test] |
| 9 | fn file_uri_encodes_what_a_path_carries() { |
| 10 | assert_eq!( |
| 11 | file_uri(std::path::Path::new("/a/b.mp4")), |
| 12 | "file:///a/b.mp4" |
| 13 | ); |
| 14 | assert_eq!( |
| 15 | file_uri(std::path::Path::new("/home/x/out dir/my export.mp4")), |
| 16 | "file:///home/x/out%20dir/my%20export.mp4" |
| 17 | ); |
| 18 | assert_eq!( |
| 19 | file_uri(std::path::Path::new("/tmp/ünlü#1?.mp4")), |
| 20 | "file:///tmp/%C3%BCnl%C3%BC%231%3F.mp4" |
| 21 | ); |
| 22 | } |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | #[test] |
| 30 | fn an_import_adds_a_row_at_its_own_length_and_leaves_the_lanes_alone() { |
| 31 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 32 | session.set_gain(0.0); |
| 33 | let before = session.timeline_duration(); |
| 34 | let clips: Vec<usize> = session |
| 35 | .lanes() |
| 36 | .into_iter() |
| 37 | .map(|lane| session.lane_clips(lane).len()) |
| 38 | .collect(); |
| 39 | session.import(&asset("test_av2.mp4")).expect("av2 matches"); |
| 40 | assert_eq!(session.sources().len(), 2, "the library grew"); |
| 41 | assert_eq!( |
| 42 | session.timeline_duration(), |
| 43 | before, |
| 44 | "an import must not place a clip" |
| 45 | ); |
| 46 | assert_eq!( |
| 47 | session |
| 48 | .lanes() |
| 49 | .into_iter() |
| 50 | .map(|lane| session.lane_clips(lane).len()) |
| 51 | .collect::<Vec<_>>(), |
| 52 | clips, |
| 53 | "no lane moved" |
| 54 | ); |
| 55 | |
| 56 | |
| 57 | let rows = library_rows( |
| 58 | session.sources(), |
| 59 | &HashMap::new(), |
| 60 | &HashMap::new(), |
| 61 | None, |
| 62 | |path| session.file_frames(path), |
| 63 | ); |
| 64 | assert_eq!(rows.len(), 2); |
| 65 | assert_eq!(rows[0].frames, 150, "5 s at 30 fps"); |
| 66 | assert_eq!(rows[1].frames, 120, "4 s at 30 fps, never placed"); |
| 67 | |
| 68 | |
| 69 | for row in 0..rows.len() { |
| 70 | assert_eq!(rows[row].tint, row); |
| 71 | assert_eq!(source_tint(row), SOURCE_TINTS()[row % SOURCE_TINTS().len()]); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | #[test] |
| 82 | fn a_song_opens_the_window_by_itself() { |
| 83 | let mut session = |
| 84 | PlaybackSession::open(asset("test_tone.mp3")).expect("a song is a timeline"); |
| 85 | session.set_gain(0.0); |
| 86 | |
| 87 | let path = session.sources()[0].path.clone(); |
| 88 | assert!(session.lane_clips(Lane::V1).is_empty(), "no picture"); |
| 89 | assert_eq!(session.lane_clips(Lane::A1).len(), 1); |
| 90 | |
| 91 | |
| 92 | |
| 93 | let streams = HashMap::from([( |
| 94 | path.clone(), |
| 95 | engine::AudioSession::probe_streams(&path).expect("probe the song"), |
| 96 | )]); |
| 97 | let rate = streams[&path] |
| 98 | .iter() |
| 99 | .find(|s| s.index == session.sources()[0].audio_stream) |
| 100 | .map(|s| (s.sample_rate, s.channels)); |
| 101 | let frames = session.file_frames(&path); |
| 102 | let rows = library_rows(session.sources(), &streams, &HashMap::new(), rate, |_| { |
| 103 | frames |
| 104 | }); |
| 105 | assert_eq!(rows.len(), 1); |
| 106 | assert_eq!(rows[0].name, "test_tone.mp3"); |
| 107 | assert_eq!(rows[0].unusable, None, "the row is placeable"); |
| 108 | assert_eq!(rows[0].frames, 90, "3 s at the audio-only 30 fps"); |
| 109 | |
| 110 | |
| 111 | |
| 112 | session.seek(1.0); |
| 113 | assert!( |
| 114 | session |
| 115 | .place_stream_at(1.0, &path, 0, Some(Lane::A1)) |
| 116 | .expect("its own file is on this timeline") |
| 117 | ); |
| 118 | assert_eq!(session.lane_clips(Lane::A1).len(), 2); |
| 119 | assert!(session.lane_clips(Lane::V1).is_empty(), "still no picture"); |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | assert_eq!( |
| 125 | format_refusal(&session, Format::Mp4).as_deref(), |
| 126 | Some("no picture — an mp4 would be black; export WAV, FLAC, MP3 or OGG") |
| 127 | ); |
| 128 | assert_eq!( |
| 129 | format_refusal(&session, Format::Av1).as_deref(), |
| 130 | Some("no picture — an AV1 Matroska would be black; export WAV, FLAC, MP3 or OGG") |
| 131 | ); |
| 132 | assert_eq!( |
| 133 | format_refusal(&session, Format::Av1Mp4).as_deref(), |
| 134 | Some("no picture — an AV1 mp4 would be black; export WAV, FLAC, MP3 or OGG") |
| 135 | ); |
| 136 | assert_eq!(format_refusal(&session, Format::Wav), None); |
| 137 | assert_eq!(format_refusal(&session, Format::Flac), None); |
| 138 | assert_eq!(format_refusal(&session, Format::Mp3), None); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | #[test] |
| 146 | fn every_audio_stream_of_a_file_is_a_row_usable_or_not() { |
| 147 | let multi = PathBuf::from("/m/movie.mp4"); |
| 148 | let sources = [source("/m/movie.mp4", 0)]; |
| 149 | let mut streams = HashMap::new(); |
| 150 | streams.insert( |
| 151 | multi.clone(), |
| 152 | vec![ |
| 153 | info(0, 44_100, 2, None, true), |
| 154 | info(1, 44_100, 2, Some("fra"), true), |
| 155 | info(2, 22_050, 1, Some("deu"), true), |
| 156 | info(3, 0, 0, None, false), |
| 157 | ], |
| 158 | ); |
| 159 | let rows = library_rows( |
| 160 | &sources, |
| 161 | &streams, |
| 162 | &HashMap::new(), |
| 163 | Some((44_100, 2)), |
| 164 | |_| 90, |
| 165 | ); |
| 166 | assert_eq!( |
| 167 | rows.iter().map(|r| r.stream).collect::<Vec<_>>(), |
| 168 | [0, 1, 2, 3], |
| 169 | "one row per audio stream, in file order" |
| 170 | ); |
| 171 | assert!( |
| 172 | rows.iter().all(|r| r.path == multi && r.tint == 0), |
| 173 | "every stream of one file wears the file's own tint" |
| 174 | ); |
| 175 | assert_eq!(rows[0].name, "movie.mp4 [audio 1]"); |
| 176 | assert_eq!(rows[1].name, "movie.mp4 [audio 2]"); |
| 177 | assert_eq!(rows[1].detail, "fra 44.1 kHz stereo"); |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | assert_eq!((&rows[0].unusable, &rows[1].unusable), (&None, &None)); |
| 185 | assert_eq!(rows[2].unusable.as_deref(), Some("the timeline is stereo")); |
| 186 | assert_eq!( |
| 187 | unusable(&info(9, 48_000, 2, None, true), Some((44_100, 2))), |
| 188 | None, |
| 189 | "48 kHz stereo joins a 44.1 kHz stereo timeline" |
| 190 | ); |
| 191 | assert_eq!(rows[3].unusable.as_deref(), Some("unsupported codec")); |
| 192 | assert_eq!( |
| 193 | rows[3].detail, "", |
| 194 | "a stream we cannot parse claims nothing" |
| 195 | ); |
| 196 | |
| 197 | assert!(rows.iter().all(|r| r.frames == 90)); |
| 198 | |
| 199 | |
| 200 | |
| 201 | let plain = [source("/m/plain.mp4", 0)]; |
| 202 | let mut one = HashMap::new(); |
| 203 | one.insert( |
| 204 | PathBuf::from("/m/plain.mp4"), |
| 205 | vec![info(0, 44_100, 2, None, true)], |
| 206 | ); |
| 207 | let rows = library_rows(&plain, &one, &HashMap::new(), Some((44_100, 2)), |_| 90); |
| 208 | assert_eq!(rows.len(), 1); |
| 209 | assert_eq!(rows[0].name, "plain.mp4"); |
| 210 | assert_eq!( |
| 211 | rows[0].detail, "", |
| 212 | "one audio track is the row it has always been: name and length" |
| 213 | ); |
| 214 | |
| 215 | let mut silent = HashMap::new(); |
| 216 | silent.insert(PathBuf::from("/m/plain.mp4"), Vec::new()); |
| 217 | for probe in [silent, HashMap::new()] { |
| 218 | let rows = library_rows(&plain, &probe, &HashMap::new(), None, |_| 90); |
| 219 | assert_eq!(rows.len(), 1); |
| 220 | assert_eq!(rows[0].name, "plain.mp4"); |
| 221 | assert_eq!(rows[0].detail, ""); |
| 222 | } |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | let placed = [ |
| 228 | source("/m/movie.mp4", 0), |
| 229 | source("/m/other.mp4", 0), |
| 230 | source("/m/movie.mp4", 2), |
| 231 | ]; |
| 232 | streams.insert( |
| 233 | PathBuf::from("/m/other.mp4"), |
| 234 | vec![info(0, 44_100, 2, None, true)], |
| 235 | ); |
| 236 | let rows = library_rows( |
| 237 | &placed, |
| 238 | &streams, |
| 239 | &HashMap::new(), |
| 240 | Some((44_100, 2)), |
| 241 | |_| 90, |
| 242 | ); |
| 243 | assert_eq!( |
| 244 | rows.iter() |
| 245 | .map(|r| (file_name(&r.path), r.stream)) |
| 246 | .collect::<Vec<_>>(), |
| 247 | [ |
| 248 | ("movie.mp4".to_string(), 0), |
| 249 | ("other.mp4".to_string(), 0), |
| 250 | ("movie.mp4".to_string(), 2), |
| 251 | ("movie.mp4".to_string(), 1), |
| 252 | ("movie.mp4".to_string(), 3), |
| 253 | ] |
| 254 | ); |
| 255 | assert!( |
| 256 | rows[2].unusable.is_none(), |
| 257 | "a stream already on the timeline is playing, whatever a probe says" |
| 258 | ); |
| 259 | assert_eq!(rows[1].tint, 1, "the other file is the other tint"); |
| 260 | } |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | #[test] |
| 273 | fn a_caption_is_deleted_by_the_same_row_and_stroke_every_box_is() { |
| 274 | use keymap::ActionId; |
| 275 | |
| 276 | |
| 277 | let cap = Ctx { |
| 278 | caption: true, |
| 279 | timeline: true, |
| 280 | ..Ctx::default() |
| 281 | }; |
| 282 | assert!(cap.clip.is_none(), "a caption is never a clip"); |
| 283 | assert_eq!( |
| 284 | enable(ActionId::Delete, cap), |
| 285 | Enable::Yes, |
| 286 | "the one thing a placed caption could always be asked to do", |
| 287 | ); |
| 288 | |
| 289 | |
| 290 | for clip_only in [ActionId::Copy, ActionId::Lift, ActionId::Equalizer] { |
| 291 | assert_eq!( |
| 292 | enable(clip_only, cap), |
| 293 | Enable::Hidden("this is a caption"), |
| 294 | "{clip_only:?} is not a row on a caption", |
| 295 | ); |
| 296 | } |
| 297 | |
| 298 | |
| 299 | assert_eq!( |
| 300 | enable(ActionId::Detach, cap), |
| 301 | Enable::No("this caption is not grouped") |
| 302 | ); |
| 303 | assert_eq!(enable(ActionId::Group, cap), Enable::Yes); |
| 304 | |
| 305 | let grouped = Ctx { |
| 306 | caption: true, |
| 307 | caption_link: Some(3), |
| 308 | timeline: true, |
| 309 | ..Ctx::default() |
| 310 | }; |
| 311 | assert_eq!(enable(ActionId::Detach, grouped), Enable::Yes); |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | for playhead in [ |
| 318 | ActionId::Cut, |
| 319 | ActionId::Regroup, |
| 320 | ActionId::Color, |
| 321 | ActionId::Speed, |
| 322 | ActionId::Fit, |
| 323 | ActionId::Silence, |
| 324 | ] { |
| 325 | assert_eq!( |
| 326 | enable(playhead, cap), |
| 327 | Enable::Yes, |
| 328 | "{playhead:?} is about the playhead and not about the mark", |
| 329 | ); |
| 330 | } |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | assert_eq!( |
| 336 | menu_items(cap), |
| 337 | vec![ |
| 338 | ActionId::Paste, |
| 339 | ActionId::Delete, |
| 340 | ActionId::Detach, |
| 341 | ActionId::Group, |
| 342 | ActionId::ToggleMute, |
| 343 | ], |
| 344 | "the caption's menu is its removal, its group rows, and the global ones", |
| 345 | ); |
| 346 | |
| 347 | |
| 348 | assert!(menu_items(Ctx { |
| 349 | timeline: true, |
| 350 | ..Ctx::default() |
| 351 | }) |
| 352 | .contains(&ActionId::Cut)); |
| 353 | } |
| 354 | |
| 355 | |
| 356 | |
| 357 | fn with_subtitle_lane() -> (PlaybackSession, Lane) { |
| 358 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 359 | session.set_gain(0.0); |
| 360 | subtitle_notice(&mut session, &asset("test_subs.mkv")).expect("the mkv carries subtitles"); |
| 361 | let lane = session.add_lane(LaneKind::Subtitle); |
| 362 | (session, lane) |
| 363 | } |
| 364 | |
| 365 | |
| 366 | fn one_second(start: u32) -> SubClip { |
| 367 | SubClip { |
| 368 | start, |
| 369 | frames: 30, |
| 370 | track: 0, |
| 371 | in_us: 0, |
| 372 | out_us: 1_000_000, |
| 373 | link: None, |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | #[test] |
| 383 | fn a_refused_caption_drop_leaves_the_mark_where_it_was() { |
| 384 | use crate::sub_mark; |
| 385 | let (mut session, lane) = with_subtitle_lane(); |
| 386 | session.place_sub(lane, 0, one_second(0)).expect("A goes down"); |
| 387 | session |
| 388 | .place_sub(lane, 60, one_second(0)) |
| 389 | .expect("B goes down after it"); |
| 390 | let before = session.sub_lane(lane).to_vec(); |
| 391 | |
| 392 | assert_eq!(sub_mark(session.sub_lane(lane), 60), Some(1)); |
| 393 | |
| 394 | let err = session |
| 395 | .move_sub(lane, 1, lane, 0) |
| 396 | .expect_err("A already covers frame 0"); |
| 397 | assert!(err.to_string().contains("already covers"), "{err}"); |
| 398 | assert_eq!(session.sub_lane(lane), before, "a refusal moved nothing"); |
| 399 | |
| 400 | |
| 401 | assert_eq!( |
| 402 | sub_mark(session.sub_lane(lane), 0), |
| 403 | Some(0), |
| 404 | "frame 0 is A's, which is why a refused drop must not re-read the mark", |
| 405 | ); |
| 406 | |
| 407 | assert_eq!(sub_mark(session.sub_lane(lane), 60), Some(1)); |
| 408 | } |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | #[test] |
| 416 | fn a_caption_placed_before_the_marked_one_leaves_the_mark_on_the_original() { |
| 417 | use crate::sub_mark; |
| 418 | let (mut session, lane) = with_subtitle_lane(); |
| 419 | session |
| 420 | .place_sub(lane, 100, one_second(0)) |
| 421 | .expect("A goes down"); |
| 422 | let marked = session.sub_lane(lane)[0].start; |
| 423 | assert_eq!(sub_mark(session.sub_lane(lane), marked), Some(0)); |
| 424 | |
| 425 | session |
| 426 | .place_sub(lane, 0, one_second(0)) |
| 427 | .expect("the new one goes down before it"); |
| 428 | assert_eq!( |
| 429 | session |
| 430 | .sub_lane(lane) |
| 431 | .iter() |
| 432 | .map(|s| s.start) |
| 433 | .collect::<Vec<_>>(), |
| 434 | [0, 100], |
| 435 | "the lane holds them in start order", |
| 436 | ); |
| 437 | |
| 438 | let mark = sub_mark(session.sub_lane(lane), marked).expect("A is still there"); |
| 439 | assert_eq!(mark, 1, "A slid one along and the mark went with it"); |
| 440 | |
| 441 | |
| 442 | |
| 443 | assert!(session.lift_sub(lane, mark)); |
| 444 | assert_eq!( |
| 445 | session |
| 446 | .sub_lane(lane) |
| 447 | .iter() |
| 448 | .map(|s| s.start) |
| 449 | .collect::<Vec<_>>(), |
| 450 | [0], |
| 451 | "the caption the user marked is the one that died", |
| 452 | ); |
| 453 | } |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | #[test] |
| 460 | fn a_caption_grouped_with_a_clip_pairs_it_for_the_whole_take_question() { |
| 461 | let (mut session, lane) = with_subtitle_lane(); |
| 462 | session |
| 463 | .place_sub(lane, 0, one_second(0)) |
| 464 | .expect("the caption goes down"); |
| 465 | session |
| 466 | .group_all(&[(Lane::V1, 0), (lane, 0)]) |
| 467 | .expect("a clip and a caption are a group"); |
| 468 | |
| 469 | |
| 470 | assert!( |
| 471 | whole_take(&session, Lane::V1, 0), |
| 472 | "the caption the clip was grouped with pairs it" |
| 473 | ); |
| 474 | |
| 475 | assert!(session.ungroup(lane, 0)); |
| 476 | assert!( |
| 477 | !whole_take(&session, Lane::V1, 0), |
| 478 | "ungrouped, the clip is a half like any other" |
| 479 | ); |
| 480 | } |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | #[test] |
| 487 | fn an_ungrouped_clip_on_a_further_lane_is_a_layer_not_a_take() { |
| 488 | use engine::project::LaneKind; |
| 489 | |
| 490 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 491 | session.set_gain(0.0); |
| 492 | let v2 = session.add_lane(LaneKind::Video); |
| 493 | assert!(session.move_clip_to(Lane::V1, 0, v2, 0), "V1 -> V2"); |
| 494 | |
| 495 | |
| 496 | assert!(session.ungroup(v2, 0)); |
| 497 | assert!( |
| 498 | !whole_take(&session, v2, 0), |
| 499 | "an ungrouped clip on ord >= 1 is a layer, not a take" |
| 500 | ); |
| 501 | |
| 502 | |
| 503 | assert!(session.lift_clip(v2, 0)); |
| 504 | assert!(session.lane_clips(v2).is_empty()); |
| 505 | } |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | #[test] |
| 512 | fn a_caption_anchor_names_the_media_half_of_its_group() { |
| 513 | use crate::caption_media_half; |
| 514 | |
| 515 | let (mut session, lane) = with_subtitle_lane(); |
| 516 | session |
| 517 | .place_sub(lane, 0, one_second(0)) |
| 518 | .expect("the caption goes down"); |
| 519 | |
| 520 | assert_eq!(caption_media_half(&session, (lane, 0), LaneKind::Video), None); |
| 521 | assert_eq!(caption_media_half(&session, (lane, 0), LaneKind::Audio), None); |
| 522 | |
| 523 | |
| 524 | session |
| 525 | .group_all(&[(Lane::V1, 0), (lane, 0)]) |
| 526 | .expect("a clip and a caption are a group"); |
| 527 | assert_eq!( |
| 528 | caption_media_half(&session, (lane, 0), LaneKind::Video), |
| 529 | Some((Lane::V1, 0)) |
| 530 | ); |
| 531 | assert_eq!( |
| 532 | caption_media_half(&session, (lane, 0), LaneKind::Audio), |
| 533 | Some((Lane::A1, 0)) |
| 534 | ); |
| 535 | } |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | #[test] |
| 541 | fn group_is_live_over_a_multi_selection_and_words_a_repeated_lane() { |
| 542 | use keymap::ActionId; |
| 543 | let distinct = Ctx { |
| 544 | timeline: true, |
| 545 | picks: 2, |
| 546 | pick_lanes: 2, |
| 547 | ..Ctx::default() |
| 548 | }; |
| 549 | assert_eq!(enable(ActionId::Group, distinct), Enable::Yes); |
| 550 | let twice = Ctx { |
| 551 | timeline: true, |
| 552 | picks: 2, |
| 553 | pick_lanes: 1, |
| 554 | ..Ctx::default() |
| 555 | }; |
| 556 | assert_eq!( |
| 557 | enable(ActionId::Group, twice), |
| 558 | Enable::No("a group is one clip per lane: keep one pick per track") |
| 559 | ); |
| 560 | |
| 561 | |
| 562 | let one = Ctx { |
| 563 | timeline: true, |
| 564 | picks: 1, |
| 565 | pick_lanes: 1, |
| 566 | ..Ctx::default() |
| 567 | }; |
| 568 | assert_eq!(enable(ActionId::Group, one), Enable::Yes); |
| 569 | |
| 570 | |
| 571 | let none = Ctx { |
| 572 | timeline: true, |
| 573 | ..Ctx::default() |
| 574 | }; |
| 575 | assert_eq!(enable(ActionId::Group, none), Enable::Yes); |
| 576 | |
| 577 | let stale = Ctx { |
| 578 | timeline: true, |
| 579 | picks: 0, |
| 580 | pick_lanes: 0, |
| 581 | ..Ctx::default() |
| 582 | }; |
| 583 | assert_eq!(enable(ActionId::Group, stale), Enable::Yes); |
| 584 | } |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | #[test] |
| 591 | fn the_playhead_actions_still_work_with_a_caption_marked() { |
| 592 | use keymap::ActionId; |
| 593 | let cap = Ctx { |
| 594 | caption: true, |
| 595 | timeline: true, |
| 596 | ..Ctx::default() |
| 597 | }; |
| 598 | assert_eq!(enable(ActionId::Cut, cap), Enable::Yes); |
| 599 | assert_eq!(enable(ActionId::Regroup, cap), Enable::Yes); |
| 600 | |
| 601 | |
| 602 | |
| 603 | let (mut session, lane) = with_subtitle_lane(); |
| 604 | session.place_sub(lane, 0, one_second(0)).expect("it goes down"); |
| 605 | let clips = session.lane_clips(Lane::V1).len(); |
| 606 | assert!(session.cut_at(2.0), "the playhead splits the clip under it"); |
| 607 | assert_eq!(session.lane_clips(Lane::V1).len(), clips + 1); |
| 608 | assert!(session.regroup_at(2.0), "and the seam rejoins"); |
| 609 | assert_eq!(session.lane_clips(Lane::V1).len(), clips); |
| 610 | assert_eq!(session.sub_lane(lane).len(), 1, "the caption is untouched"); |
| 611 | } |
| 612 | |
| 613 | #[test] |
| 614 | fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { |
| 615 | use keymap::{ActionId, Keymap}; |
| 616 | |
| 617 | let clip = Clip { |
| 618 | fade_in: 0, |
| 619 | fade_out: 0, |
| 620 | transition_out: 0, |
| 621 | start: 30, |
| 622 | in_frame: 0, |
| 623 | out_frame: 60, |
| 624 | source: 0, |
| 625 | link: None, |
| 626 | eq: None, |
| 627 | color: None, |
| 628 | transform: None, |
| 629 | fit: FitPolicy::default(), |
| 630 | speed: Speed::NORMAL, |
| 631 | }; |
| 632 | assert_eq!(clip.end(), 90); |
| 633 | let a1 = Lane::A1; |
| 634 | let v1 = Lane::V1; |
| 635 | |
| 636 | |
| 637 | let on = |clip: &Clip, lane, action, playhead| { |
| 638 | enable( |
| 639 | action, |
| 640 | Ctx { |
| 641 | clip: Some((*clip, lane)), |
| 642 | playhead, |
| 643 | timeline: true, |
| 644 | ..Ctx::default() |
| 645 | }, |
| 646 | ) |
| 647 | }; |
| 648 | let offered = |clip: &Clip, lane, action, playhead| on(clip, lane, action, playhead).yes(); |
| 649 | |
| 650 | assert!(offered(&clip, v1, ActionId::Cut, 31)); |
| 651 | assert!(offered(&clip, v1, ActionId::Cut, 89)); |
| 652 | assert!(!offered(&clip, v1, ActionId::Cut, 30)); |
| 653 | assert!(!offered(&clip, v1, ActionId::Cut, 90)); |
| 654 | assert!(!offered(&clip, v1, ActionId::Cut, 200)); |
| 655 | |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | let slow = Clip { |
| 662 | fade_in: 0, |
| 663 | fade_out: 0, |
| 664 | speed: Speed::MIN, |
| 665 | ..clip |
| 666 | }; |
| 667 | assert_eq!(slow.frames(), 240, "a quarter speed is four times as long"); |
| 668 | assert!(offered(&slow, v1, ActionId::Cut, 34), "34 is a source frame"); |
| 669 | assert!(!offered(&slow, v1, ActionId::Cut, 35)); |
| 670 | assert_eq!( |
| 671 | on(&slow, v1, ActionId::Cut, 35).why(), |
| 672 | Some("this speed holds one frame here — step to the next"), |
| 673 | ); |
| 674 | assert_eq!( |
| 675 | on(&slow, v1, ActionId::Cut, 30).why(), |
| 676 | Some("only from inside a clip"), |
| 677 | "the head is still the edge's refusal, speed or no speed", |
| 678 | ); |
| 679 | |
| 680 | assert!(offered(&clip, v1, ActionId::Regroup, 30)); |
| 681 | assert!(offered(&clip, v1, ActionId::Regroup, 90)); |
| 682 | assert!(!offered(&clip, v1, ActionId::Regroup, 60)); |
| 683 | |
| 684 | |
| 685 | |
| 686 | assert!(!offered(&clip, v1, ActionId::Detach, 0)); |
| 687 | let grouped = Clip { |
| 688 | fade_in: 0, |
| 689 | fade_out: 0, |
| 690 | link: Some(3), |
| 691 | ..clip |
| 692 | }; |
| 693 | assert!(offered(&grouped, v1, ActionId::Detach, 60)); |
| 694 | assert!(offered(&clip, a1, ActionId::Group, 0)); |
| 695 | |
| 696 | |
| 697 | assert!(offered(&clip, a1, ActionId::Equalizer, 0)); |
| 698 | assert!(offered(&clip, a1, ActionId::Equalizer, 60)); |
| 699 | assert!(!offered(&clip, v1, ActionId::Equalizer, 60)); |
| 700 | |
| 701 | |
| 702 | for action in [ActionId::Delete, ActionId::Lift, ActionId::ToggleMute] { |
| 703 | assert!(offered(&clip, v1, action, 0)); |
| 704 | assert!(offered(&clip, a1, action, 60)); |
| 705 | } |
| 706 | |
| 707 | |
| 708 | assert!(offered(&clip, v1, ActionId::Color, 0)); |
| 709 | assert!(!offered(&clip, a1, ActionId::Color, 60)); |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | let menu = |lane, image, playhead| { |
| 719 | MENU_ITEMS |
| 720 | .into_iter() |
| 721 | .filter(|&action| { |
| 722 | enable( |
| 723 | action, |
| 724 | Ctx { |
| 725 | clip: Some((clip, lane)), |
| 726 | image, |
| 727 | playhead, |
| 728 | timeline: true, |
| 729 | ..Ctx::default() |
| 730 | }, |
| 731 | ) |
| 732 | .listed() |
| 733 | }) |
| 734 | .collect::<Vec<_>>() |
| 735 | }; |
| 736 | |
| 737 | |
| 738 | let sound = menu(a1, false, 60); |
| 739 | assert!(!sound.contains(&ActionId::Color), "{sound:?}"); |
| 740 | assert!(!sound.contains(&ActionId::Fit), "{sound:?}"); |
| 741 | assert!(sound.contains(&ActionId::Equalizer)); |
| 742 | assert!(sound.contains(&ActionId::Silence)); |
| 743 | |
| 744 | |
| 745 | |
| 746 | let picture = menu(v1, false, 60); |
| 747 | assert!(!picture.contains(&ActionId::Equalizer), "{picture:?}"); |
| 748 | assert!(picture.contains(&ActionId::Color)); |
| 749 | assert!(picture.contains(&ActionId::Fit)); |
| 750 | assert!(picture.contains(&ActionId::Silence)); |
| 751 | |
| 752 | |
| 753 | |
| 754 | let still = menu(v1, true, 60); |
| 755 | assert!(!still.contains(&ActionId::Silence), "{still:?}"); |
| 756 | assert!(!still.contains(&ActionId::Equalizer), "{still:?}"); |
| 757 | assert!(still.contains(&ActionId::Color)); |
| 758 | assert!(still.contains(&ActionId::Fit)); |
| 759 | assert!(still.contains(&ActionId::Speed)); |
| 760 | |
| 761 | |
| 762 | |
| 763 | for rows in [menu(a1, false, 30), menu(v1, false, 30), menu(v1, true, 30)] { |
| 764 | assert!(rows.contains(&ActionId::Cut), "{rows:?}"); |
| 765 | assert!(rows.contains(&ActionId::Detach), "{rows:?}"); |
| 766 | } |
| 767 | |
| 768 | |
| 769 | |
| 770 | |
| 771 | let listed: Vec<ActionId> = keys_rows() |
| 772 | .into_iter() |
| 773 | .filter_map(|r| match r { |
| 774 | KeyRow::Act(action) => Some(action), |
| 775 | _ => None, |
| 776 | }) |
| 777 | .collect(); |
| 778 | for (lane, action) in [ |
| 779 | (a1, ActionId::Color), |
| 780 | (a1, ActionId::Fit), |
| 781 | (v1, ActionId::Equalizer), |
| 782 | ] { |
| 783 | assert!(matches!(on(&clip, lane, action, 60), Enable::Hidden(_))); |
| 784 | assert!(listed.contains(&action), "{action:?} left the actions card"); |
| 785 | assert!(on(&clip, lane, action, 60).why().is_some()); |
| 786 | } |
| 787 | assert!(matches!(on(&clip, v1, ActionId::Cut, 30), Enable::No(_))); |
| 788 | assert!(matches!(on(&clip, v1, ActionId::Regroup, 60), Enable::No(_))); |
| 789 | assert!(matches!(on(&clip, v1, ActionId::Detach, 0), Enable::No(_))); |
| 790 | |
| 791 | |
| 792 | |
| 793 | for action in MENU_ITEMS { |
| 794 | for (lane, image) in [(v1, false), (a1, false), (v1, true)] { |
| 795 | for playhead in [0, 30, 60, 90] { |
| 796 | let refusal = enable( |
| 797 | action, |
| 798 | Ctx { |
| 799 | clip: Some((clip, lane)), |
| 800 | image, |
| 801 | playhead, |
| 802 | timeline: true, |
| 803 | ..Ctx::default() |
| 804 | }, |
| 805 | ); |
| 806 | if let Some(why) = refusal.why() { |
| 807 | assert!(!why.is_empty() && why.len() <= 30, "{action:?}: {why:?}"); |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | assert!(matches!( |
| 813 | enable( |
| 814 | ActionId::Silence, |
| 815 | Ctx { |
| 816 | clip: Some((clip, v1)), |
| 817 | image: true, |
| 818 | playhead: 60, |
| 819 | timeline: true, |
| 820 | ..Ctx::default() |
| 821 | } |
| 822 | ), |
| 823 | Enable::Hidden(_) |
| 824 | )); |
| 825 | |
| 826 | |
| 827 | |
| 828 | let whole = |action, ctx| enable(action, ctx); |
| 829 | assert_eq!( |
| 830 | whole(ActionId::Play, Ctx::default()), |
| 831 | Enable::No("no timeline open") |
| 832 | ); |
| 833 | let live = Ctx { |
| 834 | timeline: true, |
| 835 | playable: true, |
| 836 | ..Ctx::default() |
| 837 | }; |
| 838 | assert!(whole(ActionId::Play, live).yes()); |
| 839 | |
| 840 | |
| 841 | |
| 842 | assert_eq!( |
| 843 | whole( |
| 844 | ActionId::Play, |
| 845 | Ctx { |
| 846 | playable: false, |
| 847 | ..live |
| 848 | } |
| 849 | ), |
| 850 | Enable::No("put a clip on a lane first") |
| 851 | ); |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | for editor_wide in [ |
| 865 | ActionId::ToggleSnap, |
| 866 | ActionId::ToggleMute, |
| 867 | ActionId::VolumeUp, |
| 868 | ActionId::VolumeDown, |
| 869 | ActionId::ToggleProxies, |
| 870 | ActionId::ToggleAutoProxies, |
| 871 | ActionId::Resolution, |
| 872 | ] { |
| 873 | assert!( |
| 874 | whole(editor_wide, Ctx::default()).yes(), |
| 875 | "{editor_wide:?} is dead with no file open while its key still fires" |
| 876 | ); |
| 877 | } |
| 878 | assert!(!whole(ActionId::Delete, live).yes()); |
| 879 | assert!(!whole(ActionId::Paste, live).yes()); |
| 880 | assert!( |
| 881 | whole( |
| 882 | ActionId::Paste, |
| 883 | Ctx { |
| 884 | clipboard: true, |
| 885 | ..live |
| 886 | } |
| 887 | ) |
| 888 | .yes() |
| 889 | ); |
| 890 | assert!(!whole(ActionId::CancelExport, live).yes()); |
| 891 | let busy = Ctx { |
| 892 | exporting: true, |
| 893 | ..live |
| 894 | }; |
| 895 | assert!(whole(ActionId::CancelExport, busy).yes()); |
| 896 | for action in ActionId::ALL { |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | let allowed = action == ActionId::CancelExport |
| 904 | || action == ActionId::Theme |
| 905 | || action == ActionId::Fullscreen |
| 906 | || action == ActionId::SubtitleStyle; |
| 907 | assert_eq!( |
| 908 | whole(action, busy).yes(), |
| 909 | allowed, |
| 910 | "{action:?} while an export reads the edit list" |
| 911 | ); |
| 912 | } |
| 913 | |
| 914 | assert_eq!(frame_at(1.0, 30.), 30); |
| 915 | assert_eq!(frame_at(0.0, 30.), 0); |
| 916 | assert_eq!(frame_at(-1.0, 30.), 0); |
| 917 | |
| 918 | let viewport = size(px(800.), px(400.)); |
| 919 | assert_eq!(menu_at(point(px(10.), px(10.)), viewport, 150.), (10., 10.)); |
| 920 | assert_eq!( |
| 921 | menu_at(point(px(700.), px(380.)), viewport, 150.), |
| 922 | (800. - MENU_W, 250.) |
| 923 | ); |
| 924 | |
| 925 | assert_eq!( |
| 926 | menu_at(point(px(90.), px(40.)), size(px(100.), px(50.)), 150.), |
| 927 | (0., 0.) |
| 928 | ); |
| 929 | |
| 930 | |
| 931 | |
| 932 | let keymap = Keymap::defaults(); |
| 933 | for action in MENU_ITEMS { |
| 934 | assert!(ActionId::ALL.contains(&action), "{action:?} is not listed"); |
| 935 | assert_ne!(keymap.display(action), "unbound", "{action:?}"); |
| 936 | } |
| 937 | |
| 938 | |
| 939 | |
| 940 | let items = MENU_ITEMS.len() + 1; |
| 941 | let floor = size(px(640.), px(360.)); |
| 942 | assert!(MENU_PAD * 2. + menu_rows_h(items, floor) <= 360., "too tall"); |
| 943 | assert!( |
| 944 | menu_rows_h(items, floor) / MENU_ROW_H >= 12., |
| 945 | "too few items visible to scan on the smallest window" |
| 946 | ); |
| 947 | assert_eq!( |
| 948 | menu_at(point(px(0.), px(0.)), floor, { |
| 949 | MENU_PAD * 2. + menu_rows_h(items, floor) |
| 950 | }), |
| 951 | (0., 0.) |
| 952 | ); |
| 953 | |
| 954 | |
| 955 | |
| 956 | |
| 957 | |
| 958 | |
| 959 | |
| 960 | |
| 961 | let families = crate::ui::theme::PaletteId::ALL.len(); |
| 962 | assert_eq!( |
| 963 | menu_rows_h(families, floor), |
| 964 | families as f32 * MENU_ROW_H, |
| 965 | "{families} palettes no longer fit 640x360 -- the picker now needs \ |
| 966 | the 'more below' line and a keyboard cursor that scrolls into view" |
| 967 | ); |
| 968 | |
| 969 | |
| 970 | for id in crate::ui::theme::PaletteId::ALL { |
| 971 | assert!(id.detail().len() <= 30, "{id:?}: {:?}", id.detail()); |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | |
| 976 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | |
| 981 | |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | |
| 987 | |
| 988 | #[test] |
| 989 | fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() { |
| 990 | use keymap::ActionId; |
| 991 | let clip = Clip { |
| 992 | fade_in: 0, |
| 993 | fade_out: 0, |
| 994 | transition_out: 0, |
| 995 | start: 30, |
| 996 | in_frame: 0, |
| 997 | out_frame: 60, |
| 998 | source: 0, |
| 999 | link: Some(1), |
| 1000 | eq: None, |
| 1001 | color: None, |
| 1002 | transform: None, |
| 1003 | fit: FitPolicy::default(), |
| 1004 | speed: Speed::NORMAL, |
| 1005 | }; |
| 1006 | let ctx = |lane, image| Ctx { |
| 1007 | clip: Some((clip, lane)), |
| 1008 | image, |
| 1009 | playhead: 60, |
| 1010 | timeline: true, |
| 1011 | ..Ctx::default() |
| 1012 | }; |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | for (lane, image) in [(Lane::V1, false), (Lane::A1, false), (Lane::V1, true)] { |
| 1017 | let ctx = ctx(lane, image); |
| 1018 | let rows = menu_items(ctx); |
| 1019 | for action in MENU_ITEMS { |
| 1020 | assert_eq!( |
| 1021 | rows.contains(&action), |
| 1022 | enable(action, ctx).listed(), |
| 1023 | "{action:?} on {lane:?}, image={image}" |
| 1024 | ); |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | |
| 1030 | let sound = menu_items(ctx(Lane::A1, false)); |
| 1031 | assert!(!sound.contains(&ActionId::Color), "{sound:?}"); |
| 1032 | assert!(!sound.contains(&ActionId::Fit), "{sound:?}"); |
| 1033 | assert!(sound.contains(&ActionId::Equalizer)); |
| 1034 | let picture = menu_items(ctx(Lane::V1, false)); |
| 1035 | assert!(!picture.contains(&ActionId::Equalizer), "{picture:?}"); |
| 1036 | assert!(picture.contains(&ActionId::Color)); |
| 1037 | assert!(!menu_items(ctx(Lane::V1, true)).contains(&ActionId::Silence)); |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 | let live = RowCtx { |
| 1042 | timeline: true, |
| 1043 | usable: true, |
| 1044 | ..RowCtx::default() |
| 1045 | }; |
| 1046 | for ctx in [ |
| 1047 | live, |
| 1048 | RowCtx { |
| 1049 | usable: false, |
| 1050 | ..live |
| 1051 | }, |
| 1052 | RowCtx { placed: 2, ..live }, |
| 1053 | RowCtx { |
| 1054 | exporting: true, |
| 1055 | ..live |
| 1056 | }, |
| 1057 | RowCtx::default(), |
| 1058 | ] { |
| 1059 | let rows = row_items(ctx); |
| 1060 | for item in ROW_ITEMS { |
| 1061 | assert_eq!(rows.contains(&item), row_enable(item, ctx).listed()); |
| 1062 | } |
| 1063 | |
| 1064 | |
| 1065 | assert!(row_enable(RowItem::Reveal, ctx).yes()); |
| 1066 | assert!(row_enable(RowItem::Properties, ctx).yes()); |
| 1067 | } |
| 1068 | assert!(row_enable(RowItem::Add, live).yes()); |
| 1069 | assert!( |
| 1070 | !row_enable( |
| 1071 | RowItem::Add, |
| 1072 | RowCtx { |
| 1073 | usable: false, |
| 1074 | ..live |
| 1075 | } |
| 1076 | ) |
| 1077 | .yes(), |
| 1078 | "a file that cannot join this timeline is not an Add anybody can ask for" |
| 1079 | ); |
| 1080 | assert!(!row_enable(RowItem::Remove, RowCtx { placed: 1, ..live }).yes()); |
| 1081 | assert!(!row_enable(RowItem::Add, RowCtx::default()).yes()); |
| 1082 | |
| 1083 | |
| 1084 | for item in ROW_ITEMS { |
| 1085 | for ctx in [live, RowCtx::default()] { |
| 1086 | if let Some(why) = row_enable(item, ctx).why() { |
| 1087 | assert!(!why.is_empty() && why.len() <= 30, "{why:?}"); |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | |
| 1093 | |
| 1094 | for viewport in [ |
| 1095 | size(px(640.), px(360.)), |
| 1096 | size(px(800.), px(600.)), |
| 1097 | size(px(1280.), px(690.)), |
| 1098 | |
| 1099 | |
| 1100 | size(px(320.), px(200.)), |
| 1101 | ] { |
| 1102 | for rows in 1..=MENU_ITEMS.len() + 1 { |
| 1103 | let h = MENU_PAD * 2. + menu_rows_h(rows, viewport); |
| 1104 | for at in [ |
| 1105 | point(px(0.), px(0.)), |
| 1106 | point(px(10.), px(10.)), |
| 1107 | |
| 1108 | |
| 1109 | point(px(0.), viewport.height - px(4.)), |
| 1110 | point(viewport.width - px(4.), viewport.height - px(4.)), |
| 1111 | point(viewport.width * 2., viewport.height * 2.), |
| 1112 | ] { |
| 1113 | let (x, y) = menu_at(at, viewport, h); |
| 1114 | assert!(x >= 0. && y >= 0., "{x},{y} outside {viewport:?}"); |
| 1115 | assert!( |
| 1116 | x + MENU_W <= f32::from(viewport.width) + 0.01, |
| 1117 | "{rows} rows at {at:?} hang off the right of {viewport:?}" |
| 1118 | ); |
| 1119 | assert!( |
| 1120 | y + h <= f32::from(viewport.height) + 0.01, |
| 1121 | "{rows} rows at {at:?} hang off the bottom of {viewport:?}" |
| 1122 | ); |
| 1123 | } |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | |
| 1128 | let items = MENU_ITEMS.len() + 1; |
| 1129 | let real = size(px(1280.), px(690.)); |
| 1130 | assert_eq!(menu_rows_h(items, real), items as f32 * MENU_ROW_H); |
| 1131 | assert!(menu_rows_h(items, size(px(640.), px(360.))) < items as f32 * MENU_ROW_H); |
| 1132 | } |
| 1133 | |
| 1134 | |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | #[test] |
| 1140 | fn every_action_is_reachable_without_the_keyboard() { |
| 1141 | use keymap::ActionId; |
| 1142 | let source = ui_source(); |
| 1143 | let source = source.as_str(); |
| 1144 | let element = |id: &str| source.contains(&format!("\"{id}\"")); |
| 1145 | let listed: Vec<ActionId> = keys_rows() |
| 1146 | .iter() |
| 1147 | .filter_map(|r| match r { |
| 1148 | KeyRow::Act(a) => Some(*a), |
| 1149 | _ => None, |
| 1150 | }) |
| 1151 | .collect(); |
| 1152 | for action in ActionId::ALL { |
| 1153 | assert_eq!( |
| 1154 | listed.iter().filter(|a| **a == action).count(), |
| 1155 | 1, |
| 1156 | "{action:?} is reachable by keyboard only" |
| 1157 | ); |
| 1158 | } |
| 1159 | |
| 1160 | |
| 1161 | |
| 1162 | assert!(element("snap"), "no snap button beside the zoom"); |
| 1163 | |
| 1164 | assert!(element("keys"), "no way to open the actions card"); |
| 1165 | |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | for id in [ |
| 1170 | "eq-graph", |
| 1171 | "eq-reset", |
| 1172 | "eq-spectrum", |
| 1173 | "color-bar", |
| 1174 | "color-reset", |
| 1175 | "speed-bar", |
| 1176 | "speed-preset", |
| 1177 | "silence-row", |
| 1178 | "silence-step", |
| 1179 | "mix-row", |
| 1180 | "mix-step", |
| 1181 | "silence-apply", |
| 1182 | "export-confirm", |
| 1183 | ] { |
| 1184 | assert!(element(id), "{id} is not on any card"); |
| 1185 | } |
| 1186 | |
| 1187 | |
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | |
| 1192 | for fixed in keymap::FIXED.iter() { |
| 1193 | match fixed.reach { |
| 1194 | keymap::Reach::Click(id) => assert!( |
| 1195 | element(id), |
| 1196 | "{:?} ({}) points at {id}, which is on no card", |
| 1197 | fixed.chord, |
| 1198 | fixed.label |
| 1199 | ), |
| 1200 | |
| 1201 | |
| 1202 | keymap::Reach::Gesture => {} |
| 1203 | } |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | |
| 1208 | |
| 1209 | |
| 1210 | |
| 1211 | |
| 1212 | |
| 1213 | |
| 1214 | |
| 1215 | |
| 1216 | #[test] |
| 1217 | fn every_card_closes_without_the_keyboard() { |
| 1218 | for card in [ |
| 1219 | "keys_overlay", |
| 1220 | "export_card", |
| 1221 | "eq_card", |
| 1222 | "color_card", |
| 1223 | "speed_card", |
| 1224 | "mix_card", |
| 1225 | "silence_card", |
| 1226 | "subtitle_style_card", |
| 1227 | ] { |
| 1228 | let src = fn_body(card); |
| 1229 | assert!( |
| 1230 | src.contains("this.close_card()"), |
| 1231 | "{card}'s scrim swallows the press without closing the card: \ |
| 1232 | escape is the only way out of it" |
| 1233 | ); |
| 1234 | assert!( |
| 1235 | src.contains("MouseButton::Left, swallow"), |
| 1236 | "{card}'s body does not swallow its own presses, so a press on \ |
| 1237 | one of its controls would close the card under itself" |
| 1238 | ); |
| 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | let close = fn_body("close_card"); |
| 1244 | for field in fn_body("modal").split("self.").skip(1).filter_map(|rest| { |
| 1245 | let name: String = rest |
| 1246 | .chars() |
| 1247 | .take_while(|c| c.is_alphanumeric() || *c == '_') |
| 1248 | .collect(); |
| 1249 | (!rest[name.len()..].starts_with('(')).then_some(name) |
| 1250 | }) { |
| 1251 | assert!( |
| 1252 | close.contains(&format!("self.{field}")), |
| 1253 | "{field} makes the window modal and `close_card` leaves it set: \ |
| 1254 | that card cannot be closed by pointer" |
| 1255 | ); |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 | |
| 1264 | #[test] |
| 1265 | fn a_clip_box_is_never_narrower_than_its_target() { |
| 1266 | |
| 1267 | let far = Scale { |
| 1268 | pps: 0.1, |
| 1269 | start: 0., |
| 1270 | }; |
| 1271 | assert!(far.width_px(2.) < 1., "the fixture is not zoomed out enough"); |
| 1272 | assert_eq!(clip_width(far.width_px(2.)), HIT_MIN); |
| 1273 | |
| 1274 | |
| 1275 | assert_eq!(clip_width(0.), HIT_MIN); |
| 1276 | |
| 1277 | |
| 1278 | let near = Scale::default(); |
| 1279 | assert_eq!(clip_width(near.width_px(5.)), near.width_px(5.)); |
| 1280 | |
| 1281 | |
| 1282 | |
| 1283 | assert!(!trims(far.width_px(2.))); |
| 1284 | assert!(clip_width(far.width_px(2.)) >= HIT_MIN); |
| 1285 | } |
| 1286 | |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | |
| 1291 | #[test] |
| 1292 | fn a_detached_half_is_removed_alone_and_groups_again() { |
| 1293 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 1294 | session.set_gain(0.0); |
| 1295 | assert!(whole_take(&session, Lane::V1, 0), "one take to start with"); |
| 1296 | assert!(whole_take(&session, Lane::A1, 0)); |
| 1297 | let frames = session.lane_clips(Lane::V1)[0].len(); |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | assert!(session.ungroup(Lane::V1, 0)); |
| 1302 | assert!( |
| 1303 | !whole_take(&session, Lane::A1, 0), |
| 1304 | "the sound is a half now" |
| 1305 | ); |
| 1306 | assert!(!whole_take(&session, Lane::V1, 0), "and so is the picture"); |
| 1307 | assert!(session.lift_clip(Lane::A1, 0)); |
| 1308 | assert!(session.lane_clips(Lane::A1).is_empty(), "the sound went"); |
| 1309 | assert_eq!(session.lane_clips(Lane::V1).len(), 1, "the picture stayed"); |
| 1310 | assert_eq!(session.lane_clips(Lane::V1)[0].len(), frames, "untrimmed"); |
| 1311 | |
| 1312 | |
| 1313 | assert!(session.undo()); |
| 1314 | assert_eq!(session.lane_clips(Lane::A1).len(), 1, "the sound is back"); |
| 1315 | assert!(session.undo()); |
| 1316 | assert!(whole_take(&session, Lane::A1, 0), "one take again"); |
| 1317 | |
| 1318 | |
| 1319 | |
| 1320 | assert!(session.ungroup(Lane::V1, 0)); |
| 1321 | assert_eq!(span_partner(&session, Lane::V1, 0), Some((Lane::A1, 0))); |
| 1322 | session |
| 1323 | .group(Lane::V1, 0, Lane::A1, 0) |
| 1324 | .expect("both halves still cover the same frames"); |
| 1325 | assert!( |
| 1326 | whole_take(&session, Lane::A1, 0), |
| 1327 | "a take that ripples again" |
| 1328 | ); |
| 1329 | assert_eq!( |
| 1330 | span_partner(&session, Lane::V1, 0), |
| 1331 | None, |
| 1332 | "and nothing left on another track to group with" |
| 1333 | ); |
| 1334 | } |
| 1335 | |
| 1336 | |
| 1337 | |
| 1338 | |
| 1339 | |
| 1340 | #[test] |
| 1341 | fn group_reaches_the_sound_before_a_video_layer_over_it() { |
| 1342 | use engine::project::LaneKind; |
| 1343 | |
| 1344 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 1345 | session.set_gain(0.0); |
| 1346 | let v2 = session.add_lane(LaneKind::Video); |
| 1347 | |
| 1348 | |
| 1349 | let whole = session.lane_clips(Lane::V1)[0]; |
| 1350 | assert!( |
| 1351 | session.place_at(v2, 0.0, whole), |
| 1352 | "a layer covering the same frames as the take" |
| 1353 | ); |
| 1354 | |
| 1355 | |
| 1356 | |
| 1357 | let dir = engine::scratch::Scratch::dir("ve_group"); |
| 1358 | let file = dir.join("lanes.edith"); |
| 1359 | session.save_project(&file).expect("save the project"); |
| 1360 | let text = std::fs::read_to_string(&file).expect("read it back"); |
| 1361 | let (sound, rest): (Vec<&str>, Vec<&str>) = |
| 1362 | text.lines().partition(|l| l.starts_with("audio ")); |
| 1363 | std::fs::write( |
| 1364 | &file, |
| 1365 | format!("{}\n{}\n", rest.join("\n"), sound.join("\n")), |
| 1366 | ) |
| 1367 | .expect("write the reordered project"); |
| 1368 | let mut session = PlaybackSession::open_project(&file).expect("it loads as it stands"); |
| 1369 | std::fs::remove_dir_all(&dir).ok(); |
| 1370 | assert_eq!( |
| 1371 | session.lanes(), |
| 1372 | vec![Lane::V1, v2, Lane::A1], |
| 1373 | "the sound is the last lane there" |
| 1374 | ); |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | assert!(session.ungroup(Lane::V1, 0)); |
| 1379 | |
| 1380 | assert_eq!(span_partner(&session, Lane::V1, 0), Some((Lane::A1, 0))); |
| 1381 | session |
| 1382 | .group(Lane::V1, 0, Lane::A1, 0) |
| 1383 | .expect("the two halves cover the same frames"); |
| 1384 | |
| 1385 | |
| 1386 | assert_eq!( |
| 1387 | span_partner(&session, Lane::V1, 0), |
| 1388 | Some((v2, 0)), |
| 1389 | "the layer is what is left to group with" |
| 1390 | ); |
| 1391 | } |
| 1392 | |
| 1393 | |
| 1394 | |
| 1395 | |
| 1396 | #[test] |
| 1397 | fn a_refused_import_leaves_no_row_and_an_accepted_one_is_whole() { |
| 1398 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 1399 | |
| 1400 | session.set_gain(0.0); |
| 1401 | assert_eq!(session.sources().len(), 1); |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | let refusal = session |
| 1406 | .import(&asset("test_ac3.mp4")) |
| 1407 | .expect_err("a mono track must not join a stereo timeline") |
| 1408 | .to_string(); |
| 1409 | assert!(refusal.contains("audio"), "refusal must name it: {refusal}"); |
| 1410 | assert_eq!(session.sources().len(), 1, "a refusal added a row"); |
| 1411 | |
| 1412 | |
| 1413 | session.import(&asset("test_av2.mp4")).expect("av2 matches"); |
| 1414 | assert_eq!(session.sources().len(), 2); |
| 1415 | let second = session.sources()[1].path.clone(); |
| 1416 | assert_eq!(session.file_frames(&second), 120); |
| 1417 | assert_eq!(timecode(120. / 30., 30.), "00:00:04:00"); |
| 1418 | } |
| 1419 | |
| 1420 | |
| 1421 | |
| 1422 | |
| 1423 | #[test] |
| 1424 | fn adding_a_row_drops_the_whole_source_in_at_the_playhead() { |
| 1425 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 1426 | session.set_gain(0.0); |
| 1427 | session.import(&asset("test_av2.mp4")).expect("av2 matches"); |
| 1428 | |
| 1429 | assert_eq!(session.timeline_duration(), 5.0); |
| 1430 | |
| 1431 | session.seek(2.0); |
| 1432 | let second = session.sources()[1].path.clone(); |
| 1433 | let frames = session.file_frames(&second); |
| 1434 | |
| 1435 | |
| 1436 | assert!( |
| 1437 | session |
| 1438 | .place_stream_at(2.0, &second, 0, None) |
| 1439 | .expect("av2 is already on the timeline") |
| 1440 | ); |
| 1441 | |
| 1442 | |
| 1443 | assert_eq!(session.timeline_duration(), 9.0); |
| 1444 | let (video, audio) = (session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)); |
| 1445 | |
| 1446 | |
| 1447 | let at = |lane: &[Clip]| { |
| 1448 | *lane |
| 1449 | .iter() |
| 1450 | .find(|c| c.start == 60) |
| 1451 | .expect("inserted at 2 s") |
| 1452 | }; |
| 1453 | assert_eq!(at(video), at(audio)); |
| 1454 | assert_eq!(at(video).source, 1); |
| 1455 | assert_eq!(at(video).len(), frames); |
| 1456 | assert!(at(video).link.is_some()); |
| 1457 | assert_eq!(video.len(), audio.len()); |
| 1458 | |
| 1459 | |
| 1460 | |
| 1461 | |
| 1462 | let mut session = |
| 1463 | PlaybackSession::open(asset("test_multilang.mp4")).expect("open the fixture"); |
| 1464 | session.set_gain(0.0); |
| 1465 | let path = session.sources()[0].path.clone(); |
| 1466 | let frames = session.file_frames(&path); |
| 1467 | let end = session.timeline_duration(); |
| 1468 | assert!( |
| 1469 | session |
| 1470 | .place_stream_at(end, &path, 1, None) |
| 1471 | .expect("the French track shares the timeline's parameters") |
| 1472 | ); |
| 1473 | assert_eq!(session.sources()[1].audio_stream, 1); |
| 1474 | assert_eq!(session.timeline_duration(), end * 2.0); |
| 1475 | |
| 1476 | |
| 1477 | assert_eq!(session.file_frames(&path), frames); |
| 1478 | } |
| 1479 | |
| 1480 | |
| 1481 | |
| 1482 | |
| 1483 | |
| 1484 | |
| 1485 | |
| 1486 | |
| 1487 | |
| 1488 | |
| 1489 | #[test] |
| 1490 | fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() { |
| 1491 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 1492 | session.set_gain(0.0); |
| 1493 | session.import(&asset("test_av2.mp4")).expect("av2 matches"); |
| 1494 | let second = session.sources()[1].path.clone(); |
| 1495 | let fps = session.meta().frame_rate; |
| 1496 | assert_eq!(session.timeline_duration(), 5.0); |
| 1497 | |
| 1498 | |
| 1499 | let bed: Bounds<Pixels> = Bounds { |
| 1500 | origin: point(px(12.), px(400.)), |
| 1501 | size: size(px(600.), px(LANE_H)), |
| 1502 | }; |
| 1503 | let scale = Scale { |
| 1504 | pps: 20., |
| 1505 | start: 0., |
| 1506 | }; |
| 1507 | |
| 1508 | |
| 1509 | |
| 1510 | |
| 1511 | let clips = [session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)]; |
| 1512 | let marks = snap_marks(&clips, None, None, frame_at(session.now(), fps)); |
| 1513 | let under = frame_at(scale.time_at(px_along(px(212.), bed)), fps); |
| 1514 | let (at, cue) = landing(under, 0, 0, true, scale.snap_frames(fps), &marks); |
| 1515 | assert_eq!((at, cue), (300, None), "the pointer is on frame 300"); |
| 1516 | |
| 1517 | |
| 1518 | |
| 1519 | assert!( |
| 1520 | session |
| 1521 | .place_stream_at(f64::from(at) / fps, &second, 0, None) |
| 1522 | .expect("av2 is already on this timeline") |
| 1523 | ); |
| 1524 | let head = |lane| { |
| 1525 | session |
| 1526 | .lane_clips(lane) |
| 1527 | .last() |
| 1528 | .copied() |
| 1529 | .expect("the dropped clip") |
| 1530 | }; |
| 1531 | assert_eq!( |
| 1532 | head(Lane::V1).start, |
| 1533 | at, |
| 1534 | "the drop landed somewhere other than under the pointer" |
| 1535 | ); |
| 1536 | assert_eq!(head(Lane::A1).start, at, "...and its sound with it"); |
| 1537 | assert!(head(Lane::V1).link.is_some(), "one grouped take"); |
| 1538 | assert_eq!(head(Lane::V1).link, head(Lane::A1).link); |
| 1539 | |
| 1540 | |
| 1541 | assert_eq!(session.timeline_duration(), 14.0); |
| 1542 | } |
| 1543 | |
| 1544 | |
| 1545 | |
| 1546 | |
| 1547 | #[test] |
| 1548 | fn removing_a_row_is_refused_while_it_plays_and_takes_the_row_away() { |
| 1549 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 1550 | session.set_gain(0.0); |
| 1551 | |
| 1552 | |
| 1553 | |
| 1554 | session.import(&asset("test_av2.mp4")).expect("av2 matches"); |
| 1555 | let second = session.sources()[1].path.clone(); |
| 1556 | let end = session.timeline_duration(); |
| 1557 | assert!( |
| 1558 | session |
| 1559 | .place_stream_at(end, &second, 0, None) |
| 1560 | .expect("a file just imported is on this timeline") |
| 1561 | ); |
| 1562 | let streams = HashMap::new(); |
| 1563 | let rows = |session: &PlaybackSession| { |
| 1564 | library_rows(session.sources(), &streams, &HashMap::new(), None, |_| 0).len() |
| 1565 | }; |
| 1566 | assert_eq!(rows(&session), 2, "a row per source"); |
| 1567 | |
| 1568 | let refusal = session |
| 1569 | .remove_source(&second, 0) |
| 1570 | .expect_err("its take is still on the timeline") |
| 1571 | .to_string(); |
| 1572 | assert!(refusal.contains("still plays"), "{refusal}"); |
| 1573 | assert!( |
| 1574 | refusal.contains("V1 (1 clip)") && refusal.contains("A1 (1 clip)"), |
| 1575 | "the refusal names the lanes to clear: {refusal}" |
| 1576 | ); |
| 1577 | assert_eq!(rows(&session), 2, "and the row is still there"); |
| 1578 | |
| 1579 | |
| 1580 | |
| 1581 | let last = session.lane_clips(Lane::V1).len() - 1; |
| 1582 | assert!(session.delete_clip(Lane::V1, last)); |
| 1583 | session |
| 1584 | .remove_source(&second, 0) |
| 1585 | .expect("nothing plays av2 any more"); |
| 1586 | assert_eq!(rows(&session), 1, "the row went with it"); |
| 1587 | assert_eq!(session.sources().len(), 1); |
| 1588 | |
| 1589 | |
| 1590 | let first = session.sources()[0].path.clone(); |
| 1591 | let refusal = session |
| 1592 | .remove_source(&first, 0) |
| 1593 | .expect_err("its take is still on the timeline") |
| 1594 | .to_string(); |
| 1595 | assert!(refusal.contains("still plays"), "{refusal}"); |
| 1596 | |
| 1597 | |
| 1598 | |
| 1599 | |
| 1600 | |
| 1601 | assert!(session.delete_clip(Lane::V1, 0)); |
| 1602 | session |
| 1603 | .remove_source(&first, 0) |
| 1604 | .expect("the only row goes like any other"); |
| 1605 | assert_eq!(rows(&session), 0, "an empty library"); |
| 1606 | assert!(session.sources().is_empty()); |
| 1607 | |
| 1608 | |
| 1609 | assert_eq!(session.timeline_duration(), 0.0); |
| 1610 | assert!( |
| 1611 | session.save_project(&asset("nothing.edith")).is_err(), |
| 1612 | "a project naming no file could never be opened again, so it is not written" |
| 1613 | ); |
| 1614 | |
| 1615 | assert!(session.remove_source(&second, 0).is_err()); |
| 1616 | } |
| 1617 | |
| 1618 | |
| 1619 | |
| 1620 | |
| 1621 | |
| 1622 | |
| 1623 | #[test] |
| 1624 | fn a_copied_clip_is_renumbered_or_dropped_when_a_row_leaves_the_library() { |
| 1625 | let clip = |source: usize| Clip { |
| 1626 | fade_in: 0, |
| 1627 | fade_out: 0, |
| 1628 | transition_out: 0, |
| 1629 | start: 0, |
| 1630 | in_frame: 0, |
| 1631 | out_frame: 30, |
| 1632 | source, |
| 1633 | link: None, |
| 1634 | eq: None, |
| 1635 | color: None, |
| 1636 | transform: None, |
| 1637 | fit: Default::default(), |
| 1638 | speed: Default::default(), |
| 1639 | }; |
| 1640 | |
| 1641 | assert_eq!( |
| 1642 | clipboard_after_remove(Some(clip(2)), 0).map(|c| c.source), |
| 1643 | Some(1), |
| 1644 | "the clipboard follows its file down the list" |
| 1645 | ); |
| 1646 | |
| 1647 | assert_eq!( |
| 1648 | clipboard_after_remove(Some(clip(0)), 2).map(|c| c.source), |
| 1649 | Some(0) |
| 1650 | ); |
| 1651 | |
| 1652 | |
| 1653 | assert!(clipboard_after_remove(Some(clip(1)), 1).is_none()); |
| 1654 | assert!(clipboard_after_remove(None, 0).is_none()); |
| 1655 | } |
| 1656 | |
| 1657 | |
| 1658 | |
| 1659 | |
| 1660 | |
| 1661 | |
| 1662 | |
| 1663 | |
| 1664 | |
| 1665 | |
| 1666 | #[test] |
| 1667 | fn a_clip_trimmed_by_its_edge_plays_less_of_its_file() { |
| 1668 | use engine::project::Edge; |
| 1669 | |
| 1670 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 1671 | session.set_gain(0.0); |
| 1672 | let whole = session.lane_clips(Lane::V1)[0]; |
| 1673 | let full = session.timeline_duration(); |
| 1674 | assert_eq!( |
| 1675 | session.trim_room(Lane::V1, 0, Edge::End), |
| 1676 | Some((whole.start + 1, whole.end())), |
| 1677 | "the file's own last frame is how far the tail goes" |
| 1678 | ); |
| 1679 | assert!( |
| 1680 | !session.trim_clip(Lane::V1, 0, Edge::End, 9_999), |
| 1681 | "it already plays all of it" |
| 1682 | ); |
| 1683 | |
| 1684 | |
| 1685 | let shorter = whole.end() - whole.len() / 3; |
| 1686 | assert!(session.trim_clip(Lane::V1, 0, Edge::End, shorter)); |
| 1687 | assert_eq!(session.lane_clips(Lane::V1)[0].end(), shorter); |
| 1688 | assert_eq!( |
| 1689 | session.lane_clips(Lane::A1)[0].end(), |
| 1690 | shorter, |
| 1691 | "the linked sound was trimmed with the picture" |
| 1692 | ); |
| 1693 | assert!(session.timeline_duration() < full, "and plays out earlier"); |
| 1694 | |
| 1695 | |
| 1696 | assert!(session.trim_clip(Lane::V1, 0, Edge::End, 9_999)); |
| 1697 | assert_eq!( |
| 1698 | session.lane_clips(Lane::V1)[0], |
| 1699 | whole, |
| 1700 | "the whole take back" |
| 1701 | ); |
| 1702 | |
| 1703 | |
| 1704 | |
| 1705 | assert!(session.trim_clip(Lane::V1, 0, Edge::Start, 10)); |
| 1706 | let head = session.lane_clips(Lane::V1)[0]; |
| 1707 | assert_eq!((head.start, head.in_frame), (10, 10)); |
| 1708 | assert_eq!(session.lane_clips(Lane::A1)[0].in_frame, 10, "sound too"); |
| 1709 | assert_eq!( |
| 1710 | session.trim_room(Lane::V1, 0, Edge::Start).map(|r| r.0), |
| 1711 | Some(0), |
| 1712 | "and it may be pulled back out to the file's first frame" |
| 1713 | ); |
| 1714 | |
| 1715 | assert!(session.undo(), "one step for the whole drag"); |
| 1716 | assert_eq!(session.lane_clips(Lane::V1)[0], whole); |
| 1717 | } |
| 1718 | |
| 1719 | |
| 1720 | |
| 1721 | |
| 1722 | |
| 1723 | #[test] |
| 1724 | fn a_clip_dragged_onto_another_track_plays_from_it() { |
| 1725 | use engine::project::LaneKind; |
| 1726 | |
| 1727 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 1728 | session.set_gain(0.0); |
| 1729 | let v2 = session.add_lane(LaneKind::Video); |
| 1730 | assert_eq!(session.video_clip_at(0.0), Some((Lane::V1, 0))); |
| 1731 | |
| 1732 | assert!(session.move_clip_to(Lane::V1, 0, v2, 0), "V1 -> V2"); |
| 1733 | assert!(session.lane_clips(Lane::V1).is_empty(), "it left V1"); |
| 1734 | assert_eq!(session.lane_clips(v2).len(), 1, "and landed on V2"); |
| 1735 | assert_eq!( |
| 1736 | session.video_clip_at(0.0), |
| 1737 | Some((v2, 0)), |
| 1738 | "the picture now comes from V2" |
| 1739 | ); |
| 1740 | assert_eq!(session.lane_clips(Lane::A1).len(), 1, "its sound stayed"); |
| 1741 | |
| 1742 | |
| 1743 | |
| 1744 | |
| 1745 | |
| 1746 | assert!(!session.move_clip_to(v2, 0, Lane::A1, 0), "picture on A1"); |
| 1747 | assert_eq!(session.lane_clips(v2).len(), 1, "and it stayed on V2"); |
| 1748 | assert!( |
| 1749 | session.move_clip_to(v2, 0, Lane::V1, 0), |
| 1750 | "dragged back down" |
| 1751 | ); |
| 1752 | |
| 1753 | |
| 1754 | assert!(session.undo(), "the drag back"); |
| 1755 | assert_eq!(session.video_clip_at(0.0), Some((v2, 0))); |
| 1756 | assert!(session.undo(), "the drag up"); |
| 1757 | assert_eq!(session.video_clip_at(0.0), Some((Lane::V1, 0))); |
| 1758 | assert!(session.lane_clips(v2).is_empty()); |
| 1759 | } |
| 1760 | |
| 1761 | |
| 1762 | |
| 1763 | |
| 1764 | |
| 1765 | #[test] |
| 1766 | fn a_track_can_be_added_dropped_on_edited_and_taken_back() { |
| 1767 | use engine::project::LaneKind; |
| 1768 | |
| 1769 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 1770 | session.set_gain(0.0); |
| 1771 | assert_eq!(session.lanes(), vec![Lane::V1, Lane::A1]); |
| 1772 | |
| 1773 | let v2 = session.add_lane(LaneKind::Video); |
| 1774 | assert_eq!(v2.label(), "V2"); |
| 1775 | assert_eq!(session.lanes(), vec![Lane::V1, Lane::A1, v2]); |
| 1776 | assert!(session.lane_clips(v2).is_empty()); |
| 1777 | |
| 1778 | |
| 1779 | let path = session.sources()[0].path.clone(); |
| 1780 | assert!( |
| 1781 | session |
| 1782 | .place_stream_at(1.0, &path, 0, Some(v2)) |
| 1783 | .expect("its own file is on this timeline") |
| 1784 | ); |
| 1785 | assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2"); |
| 1786 | assert_eq!(session.lane_clips(v2)[0].start, 30, "at the playhead"); |
| 1787 | |
| 1788 | |
| 1789 | let a2 = Lane::new(LaneKind::Audio, 1); |
| 1790 | assert_eq!(session.lanes(), vec![Lane::V1, Lane::A1, v2, a2]); |
| 1791 | assert_eq!(session.lane_clips(a2), session.lane_clips(v2), "same take"); |
| 1792 | assert_eq!( |
| 1793 | session.lane_clips(v2)[0].link, |
| 1794 | session.lane_clips(a2)[0].link, |
| 1795 | "grouped, so a drag moves both" |
| 1796 | ); |
| 1797 | |
| 1798 | assert_eq!(session.lane_clips(Lane::V1).len(), 1); |
| 1799 | assert_eq!(session.lane_clips(Lane::A1).len(), 1); |
| 1800 | |
| 1801 | |
| 1802 | let dir = engine::scratch::Scratch::dir("ve_layer"); |
| 1803 | let file = dir.join("layer.edith"); |
| 1804 | session.save_project(&file).expect("save the project"); |
| 1805 | let back = PlaybackSession::open_project(&file).expect("it loads as it stands"); |
| 1806 | std::fs::remove_dir_all(&dir).ok(); |
| 1807 | assert_eq!(back.lanes(), session.lanes()); |
| 1808 | for lane in back.lanes() { |
| 1809 | assert_eq!(back.lane_clips(lane), session.lane_clips(lane), "{lane:?}"); |
| 1810 | } |
| 1811 | |
| 1812 | |
| 1813 | |
| 1814 | |
| 1815 | |
| 1816 | |
| 1817 | assert!(whole_take(&session, v2, 0)); |
| 1818 | assert!(whole_take(&session, Lane::V1, 0)); |
| 1819 | assert!(whole_take(&session, Lane::A1, 0)); |
| 1820 | assert_eq!(a2.label(), "A2"); |
| 1821 | assert!(session.lift_clip(v2, 0)); |
| 1822 | assert!(session.lane_clips(v2).is_empty()); |
| 1823 | assert_eq!(session.lane_clips(Lane::V1).len(), 1, "V1 stayed put"); |
| 1824 | assert_eq!( |
| 1825 | session.lane_clips(a2).len(), |
| 1826 | 1, |
| 1827 | "a lift takes the half it names: the sound is still there to lift" |
| 1828 | ); |
| 1829 | assert!(session.lift_clip(a2, 0)); |
| 1830 | |
| 1831 | |
| 1832 | |
| 1833 | |
| 1834 | for format in [Format::Mp4, Format::Av1, Format::Av1Mp4] { |
| 1835 | assert_eq!( |
| 1836 | format_refusal(&session, format), |
| 1837 | None, |
| 1838 | "two audio lanes are a mix, not a refusal" |
| 1839 | ); |
| 1840 | } |
| 1841 | |
| 1842 | |
| 1843 | |
| 1844 | |
| 1845 | for lanes in [4, 4, 3, 2] { |
| 1846 | assert!(session.undo()); |
| 1847 | assert_eq!(session.lanes().len(), lanes); |
| 1848 | } |
| 1849 | assert_eq!(session.lanes(), vec![Lane::V1, Lane::A1]); |
| 1850 | assert_eq!(session.lane_clips(Lane::V1).len(), 1); |
| 1851 | assert_eq!(format_refusal(&session, Format::Mp4), None); |
| 1852 | } |
| 1853 | |
| 1854 | |
| 1855 | |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | |
| 1861 | |
| 1862 | |
| 1863 | #[test] |
| 1864 | fn a_grouped_clip_on_an_added_lane_closes_its_hole_with_its_caption() { |
| 1865 | use engine::project::LaneKind; |
| 1866 | |
| 1867 | let (mut session, sub_lane) = with_subtitle_lane(); |
| 1868 | let v2 = session.add_lane(LaneKind::Video); |
| 1869 | let path = session.sources()[0].path.clone(); |
| 1870 | assert!( |
| 1871 | session |
| 1872 | .place_stream_at(0.0, &path, 0, Some(v2)) |
| 1873 | .expect("its own file is on this timeline") |
| 1874 | ); |
| 1875 | session |
| 1876 | .place_sub(sub_lane, 0, one_second(0)) |
| 1877 | .expect("the caption goes down"); |
| 1878 | session |
| 1879 | .group_all(&[(v2, 0), (sub_lane, 0)]) |
| 1880 | .expect("a clip on an added lane and a caption are a group"); |
| 1881 | |
| 1882 | |
| 1883 | |
| 1884 | assert!(whole_take(&session, v2, 0)); |
| 1885 | |
| 1886 | |
| 1887 | |
| 1888 | session |
| 1889 | .place_sub(sub_lane, 60, one_second(60)) |
| 1890 | .expect("a second caption after it"); |
| 1891 | assert_eq!(session.sub_lane(sub_lane).len(), 2); |
| 1892 | |
| 1893 | |
| 1894 | |
| 1895 | assert!(session.delete_clip(v2, 0)); |
| 1896 | assert!(session.lane_clips(v2).is_empty(), "the clip is gone"); |
| 1897 | assert_eq!( |
| 1898 | session.sub_lane(sub_lane).len(), |
| 1899 | 1, |
| 1900 | "its grouped caption went with it, not left as an orphan" |
| 1901 | ); |
| 1902 | assert_eq!( |
| 1903 | session.sub_lane(sub_lane)[0].start, 30, |
| 1904 | "and the hole under it closed: the caption after it slid up" |
| 1905 | ); |
| 1906 | } |
| 1907 | |
| 1908 | #[test] |
| 1909 | fn a_source_is_only_ever_asked_for_its_peaks_once() { |
| 1910 | let (a, b) = (asset("test_av.mp4"), asset("test_av2.mp4")); |
| 1911 | |
| 1912 | |
| 1913 | let sources = [ |
| 1914 | Source { |
| 1915 | path: a.clone(), |
| 1916 | audio_stream: 0, |
| 1917 | }, |
| 1918 | Source { |
| 1919 | path: a.clone(), |
| 1920 | audio_stream: 1, |
| 1921 | }, |
| 1922 | Source { |
| 1923 | path: b.clone(), |
| 1924 | audio_stream: 0, |
| 1925 | }, |
| 1926 | ]; |
| 1927 | let keys = |s: &[Source]| { |
| 1928 | s.iter() |
| 1929 | .map(|s| (s.path.clone(), s.audio_stream)) |
| 1930 | .collect::<Vec<_>>() |
| 1931 | }; |
| 1932 | let mut waves: HashMap<(PathBuf, usize), Wave> = HashMap::new(); |
| 1933 | assert_eq!(unseen_sources(&sources, &waves), keys(&sources)); |
| 1934 | |
| 1935 | |
| 1936 | |
| 1937 | waves.insert((a.clone(), 0), Wave::Loading); |
| 1938 | assert_eq!( |
| 1939 | unseen_sources(&sources, &waves), |
| 1940 | keys(&sources[1..]), |
| 1941 | "the file's other stream is a key of its own" |
| 1942 | ); |
| 1943 | |
| 1944 | waves.insert((a, 1), Wave::Silent); |
| 1945 | waves.insert((b.clone(), 0), Wave::Silent); |
| 1946 | assert!(unseen_sources(&sources, &waves).is_empty()); |
| 1947 | |
| 1948 | let mut streams: HashMap<PathBuf, Vec<StreamInfo>> = HashMap::new(); |
| 1949 | assert_eq!( |
| 1950 | unseen_paths(&sources, &streams), |
| 1951 | vec![asset("test_av.mp4"), b] |
| 1952 | ); |
| 1953 | streams.insert(asset("test_av.mp4"), Vec::new()); |
| 1954 | assert_eq!(unseen_paths(&sources, &streams).len(), 1); |
| 1955 | } |
| 1956 | |
| 1957 | |
| 1958 | |
| 1959 | |
| 1960 | |
| 1961 | #[test] |
| 1962 | fn a_project_that_makes_no_proxies_by_itself_starts_none_until_it_is_cut_on_them() { |
| 1963 | let sources = [Source { |
| 1964 | path: asset("test_av.mp4"), |
| 1965 | audio_stream: 0, |
| 1966 | }]; |
| 1967 | let none: HashMap<PathBuf, ()> = HashMap::new(); |
| 1968 | let one = vec![asset("test_av.mp4")]; |
| 1969 | |
| 1970 | |
| 1971 | assert_eq!(proxies_to_start(true, false, &sources, &none), one); |
| 1972 | assert_eq!(proxies_to_start(true, true, &sources, &none), one); |
| 1973 | |
| 1974 | assert!( |
| 1975 | proxies_to_start(false, false, &sources, &none).is_empty(), |
| 1976 | "an import started a stand-in the project asked it not to" |
| 1977 | ); |
| 1978 | |
| 1979 | |
| 1980 | assert_eq!(proxies_to_start(false, true, &sources, &none), one); |
| 1981 | |
| 1982 | |
| 1983 | let seen: HashMap<PathBuf, ()> = HashMap::from([(asset("test_av.mp4"), ())]); |
| 1984 | assert!(proxies_to_start(true, true, &sources, &seen).is_empty()); |
| 1985 | } |
| 1986 | |
| 1987 | #[test] |
| 1988 | fn the_add_button_is_dead_unless_it_would_do_something() { |
| 1989 | let picked = (PathBuf::from("/m/0.mp4"), 0); |
| 1990 | assert!(can_add(Some(&picked), true, false)); |
| 1991 | |
| 1992 | |
| 1993 | assert!(!can_add(None, true, false)); |
| 1994 | assert!(!can_add(Some(&picked), false, false)); |
| 1995 | assert!(!can_add(Some(&picked), true, true)); |
| 1996 | } |
| 1997 | |
| 1998 | #[test] |
| 1999 | fn the_media_column_never_takes_the_picture_over() { |
| 2000 | for window in [360., 640., 1280., 1920., 3840.] { |
| 2001 | let w = crate::library_w(window); |
| 2002 | |
| 2003 | |
| 2004 | assert!(w <= window / 3., "{window}px window gave the list {w}px"); |
| 2005 | assert!(w >= LIBRARY_MIN_W.min(window / 3.), "{window}px: {w}px"); |
| 2006 | assert!(w <= LIBRARY_MAX_W); |
| 2007 | } |
| 2008 | |
| 2009 | assert!(crate::library_w(640.) < crate::library_w(1280.)); |
| 2010 | |
| 2011 | |
| 2012 | assert!(ROW_H >= HIT_MIN); |
| 2013 | assert!(SWATCH_W < LIBRARY_MIN_W); |
| 2014 | } |
| 2015 | |
| 2016 | #[test] |
| 2017 | fn the_window_is_named_after_the_program_and_what_is_open() { |
| 2018 | assert_eq!(window_title("test_av.mp4"), "test_av.mp4 — edith"); |
| 2019 | |
| 2020 | assert_eq!(window_title(NO_FILE), "edith"); |
| 2021 | } |
| 2022 | |
| 2023 | #[test] |
| 2024 | fn frac_along_measures_from_the_elements_own_left_edge() { |
| 2025 | |
| 2026 | let bar: Bounds<Pixels> = Bounds { |
| 2027 | origin: point(px(12.), px(400.)), |
| 2028 | size: size(px(200.), px(6.)), |
| 2029 | }; |
| 2030 | assert_eq!(frac_along(px(12.), bar), 0.); |
| 2031 | assert_eq!(frac_along(px(112.), bar), 0.5); |
| 2032 | assert_eq!(frac_along(px(212.), bar), 1.); |
| 2033 | |
| 2034 | assert_eq!(frac_along(px(0.), bar), 0.); |
| 2035 | assert_eq!(frac_along(px(9999.), bar), 1.); |
| 2036 | |
| 2037 | assert_eq!(frac_along(px(50.), Bounds::default()), 0.); |
| 2038 | |
| 2039 | |
| 2040 | let graph: Bounds<Pixels> = Bounds { |
| 2041 | origin: point(px(12.), px(60.)), |
| 2042 | size: size(px(296.), px(EQ_GRAPH_H)), |
| 2043 | }; |
| 2044 | assert_eq!(frac_down(px(60.), graph), 0.); |
| 2045 | assert_eq!(frac_down(px(60. + EQ_GRAPH_H / 2.), graph), 0.5); |
| 2046 | assert_eq!(frac_down(px(9999.), graph), 1.); |
| 2047 | |
| 2048 | |
| 2049 | assert_eq!(frac_down(px(50.), Bounds::default()), 0.5); |
| 2050 | } |
| 2051 | |
| 2052 | |
| 2053 | |
| 2054 | #[test] |
| 2055 | fn a_fade_drag_converts_pixels_to_frames_at_the_beds_scale() { |
| 2056 | use crate::timeline_math::fade_delta_frames; |
| 2057 | |
| 2058 | assert_eq!(fade_delta_frames(100., 100., 25.), 25); |
| 2059 | |
| 2060 | assert_eq!(fade_delta_frames(-50., 100., 25.), -13); |
| 2061 | |
| 2062 | assert_eq!(fade_delta_frames(40., 0., 25.), 0); |
| 2063 | assert_eq!(fade_delta_frames(40., -1., 25.), 0); |
| 2064 | } |
| 2065 | |
| 2066 | |
| 2067 | |
| 2068 | #[test] |
| 2069 | fn walk_cut_strides_and_clamps_at_either_end() { |
| 2070 | use crate::timeline_math::walk_cut; |
| 2071 | assert_eq!(walk_cut(3, 10, true, 1), 4); |
| 2072 | assert_eq!(walk_cut(3, 10, false, 1), 2); |
| 2073 | assert_eq!(walk_cut(3, 10, true, 10), 9, "clamps at the last cut"); |
| 2074 | assert_eq!(walk_cut(3, 10, false, 10), 0, "clamps at the first cut"); |
| 2075 | assert_eq!(walk_cut(9, 10, true, 1), 9, "already at the end holds"); |
| 2076 | assert_eq!(walk_cut(0, 10, false, 1), 0, "already at the start holds"); |
| 2077 | |
| 2078 | assert_eq!(walk_cut(0, 0, true, 1), 0); |
| 2079 | } |
| 2080 | |
| 2081 | |
| 2082 | |
| 2083 | #[test] |
| 2084 | fn nudge_edge_moves_one_frame_and_clamps_to_the_room() { |
| 2085 | use crate::timeline_math::nudge_edge; |
| 2086 | assert_eq!(nudge_edge(50, 1, 0, 100), 51); |
| 2087 | assert_eq!(nudge_edge(50, -1, 0, 100), 49); |
| 2088 | assert_eq!(nudge_edge(0, -1, 0, 100), 0, "the room's own floor holds"); |
| 2089 | assert_eq!(nudge_edge(100, 1, 0, 100), 100, "the room's own ceiling holds"); |
| 2090 | |
| 2091 | |
| 2092 | assert_eq!(nudge_edge(5, 1, 5, 5), 5); |
| 2093 | } |
| 2094 | |
| 2095 | |
| 2096 | |
| 2097 | #[test] |
| 2098 | fn should_loop_restart_only_at_the_windows_far_edge() { |
| 2099 | use crate::timeline_math::should_loop_restart; |
| 2100 | assert!(!should_loop_restart(40, Some((30, 60)))); |
| 2101 | assert!(should_loop_restart(60, Some((30, 60)))); |
| 2102 | assert!(should_loop_restart(61, Some((30, 60))), "past it restarts too"); |
| 2103 | assert!(!should_loop_restart(60, None), "loop-trim off restarts nothing"); |
| 2104 | } |
| 2105 | |
| 2106 | |
| 2107 | |
| 2108 | |
| 2109 | |
| 2110 | |
| 2111 | |
| 2112 | |
| 2113 | |
| 2114 | |
| 2115 | |
| 2116 | #[test] |
| 2117 | fn should_loop_restart_is_play_state_blind_the_pump_gates_it() { |
| 2118 | use crate::timeline_math::should_loop_restart; |
| 2119 | assert!( |
| 2120 | should_loop_restart(60, Some((30, 60))), |
| 2121 | "the predicate alone can't tell paused-at-the-edge from playing-\ |
| 2122 | into-it -- that distinction is pump's is_playing() guard, not this" |
| 2123 | ); |
| 2124 | } |