| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | use std::path::{Path, PathBuf}; |
| 11 | |
| 12 | use engine::PlaybackSession; |
| 13 | use engine::project::{GainKey, Lane, LaneKind, Source}; |
| 14 | use engine::scratch::Scratch; |
| 15 | |
| 16 | fn asset(name: &str) -> PathBuf { |
| 17 | PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 18 | .join("../../assets") |
| 19 | .join(name) |
| 20 | } |
| 21 | |
| 22 | |
| 23 | fn scratch(name: &str) -> Scratch { |
| 24 | Scratch::dir(&format!("ve_saveload_{name}")) |
| 25 | } |
| 26 | |
| 27 | fn copy_in(dir: &Path, name: &str) -> PathBuf { |
| 28 | let to = dir.join(name); |
| 29 | std::fs::copy(asset(name), &to).expect("copy the fixture"); |
| 30 | to |
| 31 | } |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | #[test] |
| 39 | fn a_picked_audio_stream_lands_saves_and_comes_back() { |
| 40 | let dir = scratch("streams"); |
| 41 | let media = copy_in(&dir, "test_multilang.mp4"); |
| 42 | let mut session = PlaybackSession::open(&media).expect("open the fixture"); |
| 43 | session.set_gain(0.0); |
| 44 | let end = session.timeline_duration(); |
| 45 | |
| 46 | |
| 47 | |
| 48 | assert!( |
| 49 | session |
| 50 | .place_stream_at(end, &media, 1, None) |
| 51 | .expect("stream 1 matches the timeline") |
| 52 | ); |
| 53 | assert_eq!( |
| 54 | session |
| 55 | .sources() |
| 56 | .iter() |
| 57 | .map(|s| s.audio_stream) |
| 58 | .collect::<Vec<_>>(), |
| 59 | [0, 1], |
| 60 | "the same file twice, on two streams" |
| 61 | ); |
| 62 | assert_eq!(session.timeline_duration(), end * 2.0); |
| 63 | |
| 64 | let path = dir.join("langs.edith"); |
| 65 | session.save_project(&path).expect("save"); |
| 66 | let text = std::fs::read_to_string(&path).expect("read back"); |
| 67 | assert!( |
| 68 | text.contains("source 0 test_multilang.mp4") |
| 69 | && text.contains("source 1 test_multilang.mp4"), |
| 70 | "the streams did not reach the file:\n{text}" |
| 71 | ); |
| 72 | |
| 73 | let loaded = PlaybackSession::open_project(&path).expect("reopen the project"); |
| 74 | assert_eq!(loaded.sources(), session.sources()); |
| 75 | assert_eq!(loaded.timeline_duration(), session.timeline_duration()); |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | let other = copy_in(&dir, "test_multiaudio.mp4"); |
| 81 | let mut session = PlaybackSession::open(&other).expect("open the fixture"); |
| 82 | session.set_gain(0.0); |
| 83 | session |
| 84 | .place_stream_at(0.0, &other, 1, None) |
| 85 | .expect("a mono stream up-mixes onto a stereo timeline"); |
| 86 | assert!( |
| 87 | session |
| 88 | .place_stream_at(0.0, &media, 1, None) |
| 89 | .expect_err("a file that is not a source") |
| 90 | .to_string() |
| 91 | .contains("not on this timeline") |
| 92 | ); |
| 93 | assert_eq!( |
| 94 | session.sources().len(), |
| 95 | 2, |
| 96 | "the mono stream landed, the not-a-source refusal added nothing more" |
| 97 | ); |
| 98 | std::fs::remove_dir_all(&dir).expect("cleanup"); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | #[test] |
| 105 | fn both_proxy_switches_survive_a_save_and_a_reopen() { |
| 106 | let dir = scratch("proxyswitches"); |
| 107 | let media = copy_in(&dir, "test_av.mp4"); |
| 108 | let mut session = PlaybackSession::open(&media).expect("open the fixture"); |
| 109 | session.set_gain(0.0); |
| 110 | assert!(!session.auto_proxies(), "a fresh project makes none by itself"); |
| 111 | assert!(!session.proxies(), "and is cut on the film itself"); |
| 112 | |
| 113 | session.set_proxies(true); |
| 114 | session.set_auto_proxies(false); |
| 115 | let path = dir.join("switches.edith"); |
| 116 | session.save_project(&path).expect("save"); |
| 117 | let text = std::fs::read_to_string(&path).expect("read back"); |
| 118 | assert!(text.contains("proxy on\nautoproxy off\n"), "{text}"); |
| 119 | |
| 120 | let loaded = PlaybackSession::open_project(&path).expect("reopen"); |
| 121 | assert!(loaded.proxies(), "cut on the stand-ins came back"); |
| 122 | assert!(!loaded.auto_proxies(), "and so did making none of them"); |
| 123 | |
| 124 | |
| 125 | session.set_auto_proxies(true); |
| 126 | session.save_project(&path).expect("save"); |
| 127 | let text = std::fs::read_to_string(&path).expect("read back"); |
| 128 | assert!( |
| 129 | !text.contains("autoproxy"), |
| 130 | "on is written by saying nothing" |
| 131 | ); |
| 132 | assert!( |
| 133 | PlaybackSession::open_project(&path) |
| 134 | .expect("reopen") |
| 135 | .auto_proxies() |
| 136 | ); |
| 137 | std::fs::remove_dir_all(&dir).expect("cleanup"); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | #[test] |
| 145 | fn the_encoder_seat_survives_a_save_and_a_reopen() { |
| 146 | use engine::export::EncoderSeat; |
| 147 | |
| 148 | let dir = scratch("encoderseat"); |
| 149 | let media = copy_in(&dir, "test_av.mp4"); |
| 150 | let mut session = PlaybackSession::open(&media).expect("open the fixture"); |
| 151 | session.set_gain(0.0); |
| 152 | assert_eq!( |
| 153 | session.encoder_seat(), |
| 154 | EncoderSeat::Auto, |
| 155 | "a fresh project takes the seat this machine has" |
| 156 | ); |
| 157 | |
| 158 | let path = dir.join("seat.edith"); |
| 159 | for seat in [EncoderSeat::Software, EncoderSeat::Hardware] { |
| 160 | session.set_encoder_seat(seat); |
| 161 | session.save_project(&path).expect("save"); |
| 162 | let text = std::fs::read_to_string(&path).expect("read back"); |
| 163 | assert!( |
| 164 | text.contains(&format!("encoder {}\n", seat.name())), |
| 165 | "{text}" |
| 166 | ); |
| 167 | assert_eq!( |
| 168 | PlaybackSession::open_project(&path) |
| 169 | .expect("reopen") |
| 170 | .encoder_seat(), |
| 171 | seat |
| 172 | ); |
| 173 | } |
| 174 | |
| 175 | |
| 176 | session.set_encoder_seat(EncoderSeat::Auto); |
| 177 | session.save_project(&path).expect("save"); |
| 178 | let text = std::fs::read_to_string(&path).expect("read back"); |
| 179 | assert!( |
| 180 | !text.contains("encoder"), |
| 181 | "auto is written by saying nothing" |
| 182 | ); |
| 183 | assert_eq!( |
| 184 | PlaybackSession::open_project(&path) |
| 185 | .expect("reopen") |
| 186 | .encoder_seat(), |
| 187 | EncoderSeat::Auto |
| 188 | ); |
| 189 | std::fs::remove_dir_all(&dir).expect("cleanup"); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | #[test] |
| 197 | fn a_trimmed_timeline_saves_and_opens_again() { |
| 198 | use engine::project::Edge; |
| 199 | |
| 200 | let dir = scratch("trim"); |
| 201 | let media = copy_in(&dir, "test_av.mp4"); |
| 202 | let mut session = PlaybackSession::open(&media).expect("open the fixture"); |
| 203 | session.set_gain(0.0); |
| 204 | let whole = session.clip_at(0).expect("one clip"); |
| 205 | |
| 206 | assert!(session.trim_clip(Lane::V1, 0, Edge::End, whole.end() / 2)); |
| 207 | assert!(session.trim_clip(Lane::V1, 0, Edge::Start, 5)); |
| 208 | let path = dir.join("trimmed.edith"); |
| 209 | session.save_project(&path).expect("save"); |
| 210 | let loaded = PlaybackSession::open_project(&path).expect("a trimmed project opens"); |
| 211 | assert_eq!( |
| 212 | loaded |
| 213 | .clip_at(0) |
| 214 | .map(|c| (c.start, c.in_frame, c.out_frame)), |
| 215 | Some((5, 5, whole.end() / 2)), |
| 216 | "the trimmed range is what came back" |
| 217 | ); |
| 218 | |
| 219 | |
| 220 | |
| 221 | assert!(session.trim_clip(Lane::V1, 0, Edge::End, u32::MAX)); |
| 222 | assert_eq!( |
| 223 | session.clip_at(0).expect("still one clip").out_frame, |
| 224 | whole.out_frame, |
| 225 | "as far as the file goes and not one frame further" |
| 226 | ); |
| 227 | session.save_project(&path).expect("save"); |
| 228 | PlaybackSession::open_project(&path).expect("and it still opens"); |
| 229 | std::fs::remove_dir_all(&dir).expect("cleanup"); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | |
| 234 | fn edited(dir: &Path) -> PlaybackSession { |
| 235 | let mut session = PlaybackSession::open(copy_in(dir, "test_av.mp4")).expect("open"); |
| 236 | |
| 237 | |
| 238 | let second = copy_in(dir, "test_av2.mp4"); |
| 239 | session.import(&second).expect("import the second file"); |
| 240 | let end = session.timeline_duration(); |
| 241 | assert!( |
| 242 | session |
| 243 | .place_stream_at(end, &second, 0, None) |
| 244 | .expect("a file just imported is on this timeline"), |
| 245 | "drag it onto the end" |
| 246 | ); |
| 247 | assert!(session.cut_at(2.0), "cut inside the first file"); |
| 248 | assert!(session.cut_at(6.5), "cut inside the second file"); |
| 249 | assert!( |
| 250 | session.delete_clip(Lane::V1, 1), |
| 251 | "drop the second half of the first" |
| 252 | ); |
| 253 | session.seek(3.0); |
| 254 | assert_eq!(session.timeline_duration(), 6.0); |
| 255 | session |
| 256 | } |
| 257 | |
| 258 | |
| 259 | fn shape(session: &PlaybackSession) -> (Vec<(f64, f64, usize)>, Vec<Source>, f64) { |
| 260 | ( |
| 261 | session.clip_spans_by_source(), |
| 262 | session.sources().to_vec(), |
| 263 | session.timeline_duration(), |
| 264 | ) |
| 265 | } |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | #[test] |
| 271 | fn a_version_1_project_loads_fully_grouped_and_saves_as_version_7() { |
| 272 | let dir = scratch("v1"); |
| 273 | copy_in(&dir, "test_av.mp4"); |
| 274 | let path = dir.join("old.edith"); |
| 275 | |
| 276 | std::fs::write( |
| 277 | &path, |
| 278 | "edith 1\nplayhead 45\nsource test_av.mp4\nclip 0 30 0\nclip 60 90 0\n", |
| 279 | ) |
| 280 | .expect("write a v1 file"); |
| 281 | |
| 282 | let loaded = PlaybackSession::open_project(&path).expect("a v1 file still opens"); |
| 283 | let fps = loaded.meta().frame_rate; |
| 284 | assert_eq!( |
| 285 | loaded.clip_spans_by_source(), |
| 286 | vec![(0.0, 30.0 / fps, 0), (30.0 / fps, 30.0 / fps, 0)], |
| 287 | "v1 clips queue up, the second starting where the first ended" |
| 288 | ); |
| 289 | assert_eq!( |
| 290 | loaded.lane_spans_by_source(engine::project::Lane::A1), |
| 291 | loaded.clip_spans_by_source(), |
| 292 | "both lanes, fully grouped: a v1 timeline had no holes" |
| 293 | ); |
| 294 | assert!( |
| 295 | (loaded.now() - 45.0 / fps).abs() < 1.0 / fps, |
| 296 | "playhead kept" |
| 297 | ); |
| 298 | |
| 299 | |
| 300 | let v2 = dir.join("new.edith"); |
| 301 | loaded.save_project(&v2).expect("save"); |
| 302 | let text = std::fs::read_to_string(&v2).expect("read back"); |
| 303 | assert!(text.starts_with("edith 30\n"), "{text}"); |
| 304 | assert!( |
| 305 | text.contains("\nresolution 1280 720\n"), |
| 306 | "a project with no resolution of its own is saved at source 0's: {text}" |
| 307 | ); |
| 308 | assert_eq!( |
| 309 | text.lines().filter(|l| l.starts_with("video ")).count(), |
| 310 | 2, |
| 311 | "{text}" |
| 312 | ); |
| 313 | assert_eq!( |
| 314 | text.lines().filter(|l| l.starts_with("audio ")).count(), |
| 315 | 2, |
| 316 | "{text}" |
| 317 | ); |
| 318 | let again = PlaybackSession::open_project(&v2).expect("open the v2 file"); |
| 319 | assert_eq!(shape(&again), shape(&loaded)); |
| 320 | |
| 321 | let third = dir.join("third.edith"); |
| 322 | again.save_project(&third).expect("save"); |
| 323 | assert_eq!(std::fs::read(&third).expect("read"), text.as_bytes()); |
| 324 | |
| 325 | |
| 326 | |
| 327 | let v2 = dir.join("v2.edith"); |
| 328 | std::fs::write( |
| 329 | &v2, |
| 330 | "edith 2\nplayhead 0\nsource test_av.mp4\nvideo 0 0 30 0 0\naudio 0 0 30 0 0\n", |
| 331 | ) |
| 332 | .expect("write a v2 file"); |
| 333 | let loaded = PlaybackSession::open_project(&v2).expect("a v2 file still opens"); |
| 334 | assert_eq!(loaded.sources().len(), 1); |
| 335 | assert_eq!(loaded.sources()[0].audio_stream, 0); |
| 336 | loaded.save_project(&v2).expect("save"); |
| 337 | assert!( |
| 338 | std::fs::read_to_string(&v2) |
| 339 | .expect("read back") |
| 340 | .contains("source 0 test_av.mp4"), |
| 341 | "a re-saved v2 project says the stream it always meant" |
| 342 | ); |
| 343 | } |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | #[test] |
| 350 | fn a_version_4_project_holds_more_than_two_lanes() { |
| 351 | use engine::project::{Lane, LaneKind}; |
| 352 | |
| 353 | let dir = scratch("v4_lanes"); |
| 354 | copy_in(&dir, "test_av.mp4"); |
| 355 | let path = dir.join("many.edith"); |
| 356 | |
| 357 | |
| 358 | |
| 359 | let text = "edith 4\nplayhead 0\nsource 0 test_av.mp4\n\ |
| 360 | video 1 0 0 30 0 3\naudio 1\nvideo 2 40 0 20 0 -\naudio 2 0 0 30 0 3\n"; |
| 361 | std::fs::write(&path, text).expect("write a v4 file"); |
| 362 | |
| 363 | let loaded = PlaybackSession::open_project(&path).expect("a four-lane project opens"); |
| 364 | let v2 = Lane::new(LaneKind::Video, 1); |
| 365 | let a2 = Lane::new(LaneKind::Audio, 1); |
| 366 | assert_eq!(loaded.lane_clips(Lane::V1).len(), 1); |
| 367 | assert!(loaded.lane_clips(Lane::A1).is_empty(), "A1 holds nothing"); |
| 368 | assert_eq!( |
| 369 | loaded |
| 370 | .lane_clips(v2) |
| 371 | .iter() |
| 372 | .map(|c| (c.start, c.end())) |
| 373 | .collect::<Vec<_>>(), |
| 374 | vec![(40, 60)], |
| 375 | "V2 is a lane of its own, gap and all" |
| 376 | ); |
| 377 | assert_eq!( |
| 378 | loaded.lane_clips(a2)[0].link, |
| 379 | loaded.lane_clips(Lane::V1)[0].link, |
| 380 | "the group spans V1 and A2, which are not a pair" |
| 381 | ); |
| 382 | assert_eq!(loaded.timeline_duration(), 60.0 / loaded.meta().frame_rate); |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | let again = dir.join("again.edith"); |
| 388 | loaded.save_project(&again).expect("save"); |
| 389 | assert_eq!( |
| 390 | std::fs::read_to_string(&again).expect("read back"), |
| 391 | "edith 30\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ |
| 392 | video 1 0 0 30 0 3 - - fit 1000 0 0 0 - 0 0\naudio 1\n\ |
| 393 | video 2 40 0 20 0 - - - fit 1000 0 0 0 - 0 0\naudio 2 0 0 30 0 3 - - fit 1000 0 0 0 - 0 0\n", |
| 394 | "a four-lane project is written as it was read, three versions on" |
| 395 | ); |
| 396 | } |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | #[test] |
| 403 | fn a_version_5_project_carries_per_clip_equalizers() { |
| 404 | let dir = scratch("v5_eq"); |
| 405 | copy_in(&dir, "test_av.mp4"); |
| 406 | let path = dir.join("eq.edith"); |
| 407 | |
| 408 | let text = "edith 5\nplayhead 0\nsource 0 test_av.mp4\n\ |
| 409 | eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ |
| 410 | eq 12000.0:6.25:0.5:hs\n\ |
| 411 | video 1 0 0 30 0 - 0\nvideo 1 30 30 60 0 - 1\n\ |
| 412 | audio 1 0 0 30 0 - 0\naudio 1 30 30 60 0 - -\n"; |
| 413 | std::fs::write(&path, text).expect("write a v5 file"); |
| 414 | |
| 415 | let loaded = PlaybackSession::open_project(&path).expect("a v5 project opens"); |
| 416 | assert_eq!(loaded.lane_clips(engine::project::Lane::V1).len(), 2); |
| 417 | let again = dir.join("again.edith"); |
| 418 | loaded.save_project(&again).expect("save"); |
| 419 | assert_eq!( |
| 420 | std::fs::read_to_string(&again).expect("read back"), |
| 421 | "edith 30\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ |
| 422 | eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ |
| 423 | eq 12000.0:6.25:0.5:hs\n\ |
| 424 | video 1 0 0 30 0 - 0 - fit 1000 0 0 0 - 0 0\nvideo 1 30 30 60 0 - 1 - fit 1000 0 0 0 - 0 0\n\ |
| 425 | audio 1 0 0 30 0 - 0 - fit 1000 0 0 0 - 0 0\naudio 1 30 30 60 0 - - - fit 1000 0 0 0 - 0 0\n", |
| 426 | "the equalizer table and every clip's index survive a round trip" |
| 427 | ); |
| 428 | } |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | #[test] |
| 436 | fn a_version_6_project_carries_per_clip_colours() { |
| 437 | let dir = scratch("v6_color"); |
| 438 | copy_in(&dir, "test_av.mp4"); |
| 439 | let path = dir.join("color.edith"); |
| 440 | |
| 441 | |
| 442 | let text = "edith 6\nplayhead 0\nsource 0 test_av.mp4\n\ |
| 443 | eq 80.0:-3.0:0.707:ls\n\ |
| 444 | color 0.1:1.2:0.9:-0.3\n\ |
| 445 | color -0.25:1.0:0.0:0.5\n\ |
| 446 | video 1 0 0 30 0 - 0 0\nvideo 1 30 30 60 0 - - 1\n\ |
| 447 | audio 1 0 0 30 0 - - 0\naudio 1 30 30 60 0 - - -\n"; |
| 448 | std::fs::write(&path, text).expect("write a v6 file"); |
| 449 | |
| 450 | let loaded = PlaybackSession::open_project(&path).expect("a v6 project opens"); |
| 451 | assert_eq!(loaded.lane_clips(engine::project::Lane::V1).len(), 2); |
| 452 | let again = dir.join("again.edith"); |
| 453 | loaded.save_project(&again).expect("save"); |
| 454 | assert_eq!( |
| 455 | std::fs::read_to_string(&again).expect("read back"), |
| 456 | "edith 30\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ |
| 457 | eq 80.0:-3.0:0.707:ls\n\ |
| 458 | color 0.1:1.2:0.9:-0.3\n\ |
| 459 | color -0.25:1.0:0.0:0.5\n\ |
| 460 | video 1 0 0 30 0 - 0 0 fit 1000 0 0 0 - 0 0\nvideo 1 30 30 60 0 - - 1 fit 1000 0 0 0 - 0 0\n\ |
| 461 | audio 1 0 0 30 0 - - 0 fit 1000 0 0 0 - 0 0\naudio 1 30 30 60 0 - - - fit 1000 0 0 0 - 0 0\n", |
| 462 | "the colour table and every clip's index survive a round trip" |
| 463 | ); |
| 464 | |
| 465 | |
| 466 | assert_eq!(loaded.resolution(), (1280, 720)); |
| 467 | assert_eq!( |
| 468 | loaded.fit_of(engine::project::Lane::V1, 0), |
| 469 | engine::scale::FitPolicy::Fit |
| 470 | ); |
| 471 | } |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | #[test] |
| 478 | fn a_version_7_project_carries_a_resolution_and_fit_policies() { |
| 479 | let dir = scratch("v7_resolution"); |
| 480 | copy_in(&dir, "test_av.mp4"); |
| 481 | let path = dir.join("mixed.edith"); |
| 482 | let text = "edith 7\nplayhead 0\nresolution 960 720\nsource 0 test_av.mp4\n\ |
| 483 | video 1 0 0 30 0 - - - fill\nvideo 1 30 30 60 0 - - - center\n\ |
| 484 | audio 1 0 0 60 0 - - - fit\n"; |
| 485 | std::fs::write(&path, text).expect("write a v7 file"); |
| 486 | |
| 487 | let loaded = PlaybackSession::open_project(&path).expect("a v7 project opens"); |
| 488 | assert_eq!( |
| 489 | loaded.resolution(), |
| 490 | (960, 720), |
| 491 | "the project's own size, which is not the media's 1280x720" |
| 492 | ); |
| 493 | assert_eq!( |
| 494 | loaded.native_resolution(), |
| 495 | (1280, 720), |
| 496 | "...and the media's own size is still known" |
| 497 | ); |
| 498 | let v1 = engine::project::Lane::V1; |
| 499 | assert_eq!(loaded.fit_of(v1, 0), engine::scale::FitPolicy::Fill); |
| 500 | assert_eq!(loaded.fit_of(v1, 1), engine::scale::FitPolicy::Center); |
| 501 | |
| 502 | let again = dir.join("again.edith"); |
| 503 | loaded.save_project(&again).expect("save"); |
| 504 | assert_eq!( |
| 505 | std::fs::read_to_string(&again).expect("read back"), |
| 506 | "edith 30\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\ |
| 507 | video 1 0 0 30 0 - - - fill 1000 0 0 0 - 0 0\nvideo 1 30 30 60 0 - - - center 1000 0 0 0 - 0 0\n\ |
| 508 | audio 1 0 0 60 0 - - - fit 1000 0 0 0 - 0 0\n", |
| 509 | "a v7 project is written back as the v8 it now is: the same clips, each \ |
| 510 | saying it plays at real time, which is what it always played at" |
| 511 | ); |
| 512 | |
| 513 | |
| 514 | for (bad, want) in [ |
| 515 | ( |
| 516 | "edith 7\nresolution 0 720\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - fit\n", |
| 517 | "0x720 is not a picture", |
| 518 | ), |
| 519 | ( |
| 520 | "edith 7\nresolution 960 720\nresolution 960 720\nsource 0 test_av.mp4\n\ |
| 521 | video 1 0 0 30 0 - - - fit\n", |
| 522 | "resolution belongs once", |
| 523 | ), |
| 524 | |
| 525 | |
| 526 | ( |
| 527 | "edith 7\nresolution 4294967295 4294967295\nsource 0 test_av.mp4\n\ |
| 528 | video 1 0 0 30 0 - - - fit\n", |
| 529 | "4294967295x4294967295 is not a picture", |
| 530 | ), |
| 531 | ( |
| 532 | "edith 7\nresolution 7681 1080\nsource 0 test_av.mp4\n\ |
| 533 | video 1 0 0 30 0 - - - fit\n", |
| 534 | "7681x1080 is not a picture", |
| 535 | ), |
| 536 | ( |
| 537 | "edith 7\nresolution 960 720\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - squish\n", |
| 538 | "not a fit policy", |
| 539 | ), |
| 540 | ] { |
| 541 | let path = dir.join("bad.edith"); |
| 542 | std::fs::write(&path, bad).expect("write"); |
| 543 | let err = PlaybackSession::open_project(&path) |
| 544 | .err() |
| 545 | .expect("a malformed v7 file must be refused") |
| 546 | .to_string(); |
| 547 | assert!(err.contains(want), "wanted {want:?}, got {err:?}"); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | #[test] |
| 552 | fn a_saved_project_reopens_as_the_same_timeline() { |
| 553 | let dir = scratch("round_trip"); |
| 554 | let saved = edited(&dir); |
| 555 | let path = dir.join("edit.edith"); |
| 556 | saved.save_project(&path).expect("save"); |
| 557 | |
| 558 | let mut loaded = PlaybackSession::open_project(&path).expect("open the project"); |
| 559 | assert_eq!(shape(&loaded), shape(&saved), "clips, sources and duration"); |
| 560 | assert!( |
| 561 | (loaded.now() - saved.now()).abs() < 1.0 / loaded.meta().frame_rate, |
| 562 | "playhead landed at {:.3}s, saved at {:.3}s", |
| 563 | loaded.now(), |
| 564 | saved.now() |
| 565 | ); |
| 566 | assert!(!loaded.is_playing(), "a loaded project starts paused"); |
| 567 | assert!(!loaded.undo(), "history is not saved"); |
| 568 | |
| 569 | |
| 570 | |
| 571 | let again = dir.join("again.edith"); |
| 572 | loaded |
| 573 | .save_project(&again) |
| 574 | .expect("save the loaded project"); |
| 575 | assert_eq!( |
| 576 | std::fs::read(&path).unwrap(), |
| 577 | std::fs::read(&again).unwrap(), |
| 578 | "save -> load -> save is not a fixed point" |
| 579 | ); |
| 580 | assert!(!path.with_extension("edith.part").exists(), "left a .part"); |
| 581 | } |
| 582 | |
| 583 | #[test] |
| 584 | fn a_folder_of_media_and_its_project_can_be_moved() { |
| 585 | let from = scratch("relocate_from"); |
| 586 | let saved = edited(&from); |
| 587 | saved.save_project(&from.join("edit.edith")).expect("save"); |
| 588 | drop(saved); |
| 589 | |
| 590 | let to = scratch("relocate_to"); |
| 591 | for name in ["test_av.mp4", "test_av2.mp4", "edit.edith"] { |
| 592 | std::fs::copy(from.join(name), to.join(name)).expect("copy"); |
| 593 | } |
| 594 | |
| 595 | std::fs::remove_dir_all(&from).expect("remove the original folder"); |
| 596 | |
| 597 | let moved = PlaybackSession::open_project(&to.join("edit.edith")).expect("open the copy"); |
| 598 | assert_eq!(moved.timeline_duration(), 6.0); |
| 599 | assert!( |
| 600 | moved.sources().iter().all(|s| s.path.starts_with(&to)), |
| 601 | "sources did not follow the folder: {:?}", |
| 602 | moved.sources() |
| 603 | ); |
| 604 | } |
| 605 | |
| 606 | #[test] |
| 607 | fn imported_sources_are_written_even_when_no_clip_plays_them() { |
| 608 | let dir = scratch("orphans"); |
| 609 | let mut session = PlaybackSession::open(copy_in(&dir, "test_av.mp4")).expect("open"); |
| 610 | |
| 611 | |
| 612 | |
| 613 | session |
| 614 | .import(©_in(&dir, "test_av2.mp4")) |
| 615 | .expect("import"); |
| 616 | assert_eq!( |
| 617 | session.sources().len(), |
| 618 | 2, |
| 619 | "the orphan entry stays in-session" |
| 620 | ); |
| 621 | |
| 622 | let path = dir.join("orphan.edith"); |
| 623 | session.save_project(&path).expect("save"); |
| 624 | let text = std::fs::read_to_string(&path).expect("read back"); |
| 625 | assert_eq!( |
| 626 | text.lines().filter(|l| l.starts_with("source ")).count(), |
| 627 | 2, |
| 628 | "the imported source did not reach the file:\n{text}" |
| 629 | ); |
| 630 | let loaded = PlaybackSession::open_project(&path).expect("open the project"); |
| 631 | assert_eq!( |
| 632 | loaded.sources(), |
| 633 | session.sources(), |
| 634 | "same indices after reopen" |
| 635 | ); |
| 636 | assert_eq!(loaded.timeline_duration(), 5.0); |
| 637 | } |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | #[test] |
| 644 | fn a_source_that_vanished_opens_offline_and_is_named() { |
| 645 | let dir = scratch("missing"); |
| 646 | let session = edited(&dir); |
| 647 | let path = dir.join("edit.edith"); |
| 648 | session.save_project(&path).expect("save"); |
| 649 | drop(session); |
| 650 | |
| 651 | let gone = dir.join("test_av2.mp4"); |
| 652 | std::fs::remove_file(&gone).expect("unlink"); |
| 653 | let opened = PlaybackSession::open_project(&path) |
| 654 | .expect("a project with one source gone opens with it offline"); |
| 655 | let offline = opened.offline_sources(); |
| 656 | assert_eq!(offline.len(), 1, "{offline:?}"); |
| 657 | assert!( |
| 658 | offline[0].1.ends_with("test_av2.mp4"), |
| 659 | "the offline source must be named by file: {offline:?}" |
| 660 | ); |
| 661 | assert!(!opened.lanes().is_empty(), "the clips stay on the timeline"); |
| 662 | drop(opened); |
| 663 | |
| 664 | |
| 665 | std::fs::remove_file(dir.join("test_av.mp4")).expect("unlink"); |
| 666 | let opened = PlaybackSession::open_project(&path).expect("every source gone still opens"); |
| 667 | let names: Vec<String> = opened |
| 668 | .offline_sources() |
| 669 | .iter() |
| 670 | .map(|(_, p)| p.file_name().unwrap().to_string_lossy().into_owned()) |
| 671 | .collect(); |
| 672 | assert_eq!(names.len(), 2, "{names:?}"); |
| 673 | assert!(names.iter().any(|n| n == "test_av.mp4"), "{names:?}"); |
| 674 | assert!(names.iter().any(|n| n == "test_av2.mp4"), "{names:?}"); |
| 675 | } |
| 676 | |
| 677 | #[test] |
| 678 | fn a_source_that_shrank_is_refused_by_clip() { |
| 679 | let dir = scratch("shrunk"); |
| 680 | copy_in(&dir, "test_av.mp4"); |
| 681 | let path = dir.join("shrunk.edith"); |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | std::fs::write( |
| 687 | &path, |
| 688 | "edith 1\nplayhead 0\nsource test_av.mp4\nclip 0 30 0\nclip 30 10000 0\n", |
| 689 | ) |
| 690 | .expect("write"); |
| 691 | let clamped = PlaybackSession::open_project(&path).expect("an overrun clip still opens"); |
| 692 | assert_eq!(clamped.timeline_duration(), 5.0, "clip 1 is cut to the 120 frames left after clip 0"); |
| 693 | let warnings = clamped.load_warnings(); |
| 694 | |
| 695 | assert_eq!(warnings.len(), 2, "{warnings:?}"); |
| 696 | assert!( |
| 697 | warnings[0].contains("clip 1") && warnings[0].contains("test_av.mp4") && warnings[0].contains("150"), |
| 698 | "the warning names the clip, the file and its length: {warnings:?}" |
| 699 | ); |
| 700 | |
| 701 | |
| 702 | std::fs::write( |
| 703 | &path, |
| 704 | "edith 1\nplayhead 0\nsource test_av.mp4\nclip 0 150 0\n", |
| 705 | ) |
| 706 | .expect("write"); |
| 707 | let whole = PlaybackSession::open_project(&path).expect("the exact length is legal"); |
| 708 | assert_eq!(whole.timeline_duration(), 5.0); |
| 709 | assert!(whole.load_warnings().is_empty()); |
| 710 | } |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | #[test] |
| 723 | fn a_refused_project_does_not_hang_on_its_own_decoder() { |
| 724 | let dir = scratch("refusal_hang"); |
| 725 | copy_in(&dir, "test_av.mp4"); |
| 726 | let path = dir.join("refused.edith"); |
| 727 | let mut text = String::from("edith 1\nplayhead 0\n"); |
| 728 | for _ in 0..1024 { |
| 729 | text.push_str("source test_av.mp4\n"); |
| 730 | } |
| 731 | |
| 732 | |
| 733 | std::fs::write(dir.join("notes.txt"), "not a video\n").expect("write"); |
| 734 | text.push_str("source notes.txt\n"); |
| 735 | text.push_str("clip 0 150 0\n"); |
| 736 | std::fs::write(&path, &text).expect("write"); |
| 737 | |
| 738 | let (tx, rx) = std::sync::mpsc::sync_channel(1); |
| 739 | let probe = path.clone(); |
| 740 | std::thread::spawn(move || { |
| 741 | let err = PlaybackSession::open_project(&probe) |
| 742 | .err() |
| 743 | .map(|e| e.to_string()); |
| 744 | let _ = tx.send(err); |
| 745 | }); |
| 746 | match rx.recv_timeout(std::time::Duration::from_secs(60)) { |
| 747 | Ok(Some(err)) => assert!(err.contains("notes.txt"), "refused, but not by name: {err}"), |
| 748 | Ok(None) => panic!("a project with a non-media source must not open"), |
| 749 | Err(_) => panic!( |
| 750 | "open_project hung on a refusal: its own decode worker is parked in \ |
| 751 | send and the teardown is waiting for it" |
| 752 | ), |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | #[test] |
| 757 | fn a_project_that_names_itself_is_refused() { |
| 758 | let dir = scratch("self_reference"); |
| 759 | let path = dir.join("ouroboros.edith"); |
| 760 | std::fs::write( |
| 761 | &path, |
| 762 | "edith 1\nplayhead 0\nsource ouroboros.edith\nclip 0 30 0\n", |
| 763 | ) |
| 764 | .expect("write"); |
| 765 | let err = PlaybackSession::open_project(&path) |
| 766 | .err() |
| 767 | .expect("a project is not a video") |
| 768 | .to_string(); |
| 769 | assert!(err.contains("ouroboros.edith"), "{err}"); |
| 770 | } |
| 771 | |
| 772 | #[test] |
| 773 | fn malformed_files_are_numbered_errors_and_never_panics() { |
| 774 | let dir = scratch("malformed"); |
| 775 | copy_in(&dir, "test_av.mp4"); |
| 776 | let path = dir.join("bad.edith"); |
| 777 | let good = "edith 1\nplayhead 0\nsource test_av.mp4\nclip 0 30 0\n"; |
| 778 | |
| 779 | for (text, want) in [ |
| 780 | ( |
| 781 | "edith 17\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - fit\n", |
| 782 | "line 3", |
| 783 | ), |
| 784 | |
| 785 | ( |
| 786 | "edith 5\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - 0\n", |
| 787 | "line 3", |
| 788 | ), |
| 789 | ( |
| 790 | "edith 5\nsource 0 test_av.mp4\neq 80.0:0.0:0.707:band\nvideo 1 0 0 30 0 - 0\n", |
| 791 | "line 3", |
| 792 | ), |
| 793 | |
| 794 | ( |
| 795 | "edith 4\nsource 0 test_av.mp4\nvideo 2 0 0 30 0 -\n", |
| 796 | "line 3", |
| 797 | ), |
| 798 | |
| 799 | ("edith 3\nsource test_av.mp4\nvideo 0 0 30 0 -\n", "line 2"), |
| 800 | ("not a project at all\n", "line 1"), |
| 801 | |
| 802 | ("edith 2\nsource test_av.mp4\nclip 0 30 0\n", "line 3"), |
| 803 | ("edith 1\nsource test_av.mp4\nvideo 0 0 30 0 -\n", "line 3"), |
| 804 | ("edith 2\nsource test_av.mp4\nvideo 0 0 30 0\n", "line 3"), |
| 805 | ( |
| 806 | "edith 2\nsource test_av.mp4\nvideo 0 0 30 0 -\nvideo 10 0 30 0 -\n", |
| 807 | "line 4", |
| 808 | ), |
| 809 | ("edith 1\nsource test_av.mp4\nclip 0 30\n", "line 3"), |
| 810 | ("edith 1\nsource test_av.mp4\nclip 0 30 4\n", "line 3"), |
| 811 | ("edith 1\nsource test_av.mp4\nclip 30 30 0\n", "line 3"), |
| 812 | ("edith 1\nsource test_av.mp4\n\nclip 0 30 0\n", "line 3"), |
| 813 | ("edith 1\nsource test_av.mp4\nwhat 1\n", "line 3"), |
| 814 | |
| 815 | |
| 816 | ( |
| 817 | "edith 2\nsource test_av.mp4\nvideo 4294967290 0 30 0 -\n", |
| 818 | "line 3", |
| 819 | ), |
| 820 | ] { |
| 821 | std::fs::write(&path, text).expect("write"); |
| 822 | let err = PlaybackSession::open_project(&path) |
| 823 | .err() |
| 824 | .unwrap_or_else(|| panic!("accepted {text:?}")) |
| 825 | .to_string(); |
| 826 | assert!(err.starts_with(want), "{text:?} -> {err}"); |
| 827 | } |
| 828 | |
| 829 | |
| 830 | |
| 831 | for cut in 0..good.len() { |
| 832 | std::fs::write(&path, &good[..cut]).expect("write"); |
| 833 | let _ = PlaybackSession::open_project(&path); |
| 834 | } |
| 835 | |
| 836 | std::fs::remove_file(&path).expect("unlink"); |
| 837 | assert!(PlaybackSession::open_project(&path).is_err()); |
| 838 | } |
| 839 | |
| 840 | #[test] |
| 841 | fn a_stereo_source_that_joins_a_mono_timeline_reopens() { |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | let dir = scratch("mismatch"); |
| 849 | std::fs::copy(asset("test_ac3.mp4"), dir.join("test_av.mp4")).expect("substitute"); |
| 850 | copy_in(&dir, "test_av2.mp4"); |
| 851 | let path = dir.join("swapped.edith"); |
| 852 | std::fs::write( |
| 853 | &path, |
| 854 | "edith 1\nplayhead 0\nsource test_av.mp4\nsource test_av2.mp4\nclip 0 30 0\nclip 0 30 1\n", |
| 855 | ) |
| 856 | .expect("write"); |
| 857 | let loaded = |
| 858 | PlaybackSession::open_project(&path).expect("a stereo source on a mono timeline opens"); |
| 859 | assert_eq!(loaded.sources().len(), 2); |
| 860 | std::fs::remove_dir_all(&dir).expect("cleanup"); |
| 861 | } |
| 862 | |
| 863 | |
| 864 | |
| 865 | |
| 866 | #[test] |
| 867 | fn a_stereo_wav_imported_into_a_mono_project_saves_and_reopens() { |
| 868 | let dir = scratch("stereo_on_mono"); |
| 869 | let mono = copy_in(&dir, "test_audio_only.mp4"); |
| 870 | let wav = copy_in(&dir, "test_tone.wav"); |
| 871 | let mut session = PlaybackSession::open(&mono).expect("open the mono fixture"); |
| 872 | session.set_gain(0.0); |
| 873 | let end = session.timeline_duration(); |
| 874 | session |
| 875 | .import(&wav) |
| 876 | .expect("a stereo file imports into a mono timeline"); |
| 877 | assert!( |
| 878 | session |
| 879 | .place_stream_at(end, &wav, 0, None) |
| 880 | .expect("a stereo file joins a mono timeline"), |
| 881 | "the stereo wav landed on the timeline" |
| 882 | ); |
| 883 | let length = session.timeline_duration(); |
| 884 | let path = dir.join("stereo_on_mono.edith"); |
| 885 | session.save_project(&path).expect("save"); |
| 886 | let loaded = PlaybackSession::open_project(&path).expect("the saved project reopens"); |
| 887 | assert_eq!(loaded.sources(), session.sources()); |
| 888 | assert!((loaded.timeline_duration() - length).abs() < 1e-6); |
| 889 | std::fs::remove_dir_all(&dir).expect("cleanup"); |
| 890 | } |
| 891 | |
| 892 | |
| 893 | |
| 894 | #[test] |
| 895 | fn unused_sources_keep_their_index_across_save_and_open() { |
| 896 | let dir = scratch("stable_indices"); |
| 897 | let media = copy_in(&dir, "test_multilang.mp4"); |
| 898 | let other = copy_in(&dir, "test_multiaudio.mp4"); |
| 899 | let mut session = PlaybackSession::open(&media).expect("open the fixture"); |
| 900 | session.set_gain(0.0); |
| 901 | session.import(&other).expect("import, unplaced"); |
| 902 | let placed = session.sources().to_vec(); |
| 903 | assert_eq!(placed.len(), 2); |
| 904 | let path = dir.join("library.edith"); |
| 905 | session.save_project(&path).expect("save"); |
| 906 | let loaded = PlaybackSession::open_project(&path).expect("reopen"); |
| 907 | assert_eq!( |
| 908 | loaded.sources(), |
| 909 | &placed[..], |
| 910 | "every imported source comes back, in order" |
| 911 | ); |
| 912 | std::fs::remove_dir_all(&dir).expect("cleanup"); |
| 913 | } |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | #[test] |
| 919 | fn the_mix_survives_a_save_and_an_open() { |
| 920 | use engine::project::{Lane, LaneKind}; |
| 921 | let dir = scratch("mix"); |
| 922 | let source = copy_in(&dir, "test_av.mp4"); |
| 923 | let mut saved = PlaybackSession::open(&source).expect("open the fixture"); |
| 924 | let a2 = saved.add_lane(LaneKind::Audio); |
| 925 | assert!(saved.set_lane_gain_db(Lane::A1, -6.0)); |
| 926 | assert!(saved.set_lane_gain_db(a2, 3.0)); |
| 927 | let limiter = engine::limiter::Limiter { |
| 928 | ceiling_db: -2.0, |
| 929 | on: true, |
| 930 | }; |
| 931 | assert!(saved.set_limiter(limiter)); |
| 932 | let path = dir.join("mix.edith"); |
| 933 | saved.save_project(&path).expect("save"); |
| 934 | |
| 935 | let mut loaded = PlaybackSession::open_project(&path).expect("open the project"); |
| 936 | assert_eq!(loaded.lane_gain_db(Lane::A1), -6.0, "A1's fader"); |
| 937 | assert_eq!(loaded.lane_gain_db(a2), 3.0, "A2's own, not A1's"); |
| 938 | assert_eq!(loaded.limiter(), limiter); |
| 939 | assert!(!loaded.undo(), "a loaded mix is not an undo step"); |
| 940 | |
| 941 | let again = dir.join("again.edith"); |
| 942 | loaded |
| 943 | .save_project(&again) |
| 944 | .expect("save the loaded project"); |
| 945 | assert_eq!( |
| 946 | std::fs::read(&path).unwrap(), |
| 947 | std::fs::read(&again).unwrap(), |
| 948 | "save -> load -> save is not a fixed point" |
| 949 | ); |
| 950 | } |
| 951 | |
| 952 | |
| 953 | |
| 954 | #[test] |
| 955 | fn a_duck_survives_a_save_and_an_open() { |
| 956 | use engine::duck::Duck; |
| 957 | use engine::project::{Lane, LaneKind}; |
| 958 | let dir = scratch("duck"); |
| 959 | let source = copy_in(&dir, "test_av.mp4"); |
| 960 | let mut saved = PlaybackSession::open(&source).expect("open the fixture"); |
| 961 | let a2 = saved.add_lane(LaneKind::Audio); |
| 962 | let duck = Duck { |
| 963 | under: 0, |
| 964 | depth_db: -15.0, |
| 965 | threshold_db: -35.0, |
| 966 | attack_ms: 50.0, |
| 967 | release_ms: 600.0, |
| 968 | }; |
| 969 | |
| 970 | |
| 971 | assert!(saved.set_lane_duck(a2, Some(duck)), "ducked under A1"); |
| 972 | let path = dir.join("duck.edith"); |
| 973 | saved.save_project(&path).expect("save"); |
| 974 | |
| 975 | let mut loaded = PlaybackSession::open_project(&path).expect("open the project"); |
| 976 | assert_eq!( |
| 977 | loaded.lane_duck(a2), |
| 978 | Some(duck), |
| 979 | "the same numbers come back" |
| 980 | ); |
| 981 | assert_eq!(loaded.lane_duck(Lane::A1), None, "and A1 is not ducked"); |
| 982 | assert!(!loaded.undo(), "a loaded duck is not an undo step"); |
| 983 | let again = dir.join("again.edith"); |
| 984 | loaded |
| 985 | .save_project(&again) |
| 986 | .expect("save the loaded project"); |
| 987 | assert_eq!( |
| 988 | std::fs::read(&path).unwrap(), |
| 989 | std::fs::read(&again).unwrap(), |
| 990 | "save -> load -> save is not a fixed point" |
| 991 | ); |
| 992 | } |
| 993 | |
| 994 | |
| 995 | |
| 996 | |
| 997 | |
| 998 | #[test] |
| 999 | fn the_tone_map_preset_survives_a_save_and_an_open() { |
| 1000 | use engine::tonemap::Preset; |
| 1001 | let dir = scratch("tone"); |
| 1002 | let source = copy_in(&dir, "test_av.mp4"); |
| 1003 | let mut saved = PlaybackSession::open(&source).expect("open the fixture"); |
| 1004 | assert_eq!(saved.tone(), Preset::Reference, "nobody has picked yet"); |
| 1005 | assert!(saved.set_tone(Preset::Vivid)); |
| 1006 | let path = dir.join("tone.edith"); |
| 1007 | saved.save_project(&path).expect("save"); |
| 1008 | |
| 1009 | let mut loaded = PlaybackSession::open_project(&path).expect("open the project"); |
| 1010 | assert_eq!(loaded.tone(), Preset::Vivid); |
| 1011 | assert!(!loaded.undo(), "a loaded rendition is not an undo step"); |
| 1012 | |
| 1013 | let again = dir.join("again.edith"); |
| 1014 | loaded |
| 1015 | .save_project(&again) |
| 1016 | .expect("save the loaded project"); |
| 1017 | assert_eq!( |
| 1018 | std::fs::read(&path).unwrap(), |
| 1019 | std::fs::read(&again).unwrap(), |
| 1020 | "save -> load -> save is not a fixed point" |
| 1021 | ); |
| 1022 | |
| 1023 | |
| 1024 | |
| 1025 | let old = dir.join("old.edith"); |
| 1026 | std::fs::write( |
| 1027 | &old, |
| 1028 | "edith 10\nplayhead 0\nresolution 1920 1080\nsource 0 test_av.mp4\n\ |
| 1029 | video 1 0 0 24 0 - - - fit 1000\naudio 1 0 0 24 0 - - - fit 1000\n", |
| 1030 | ) |
| 1031 | .expect("write a v10 project"); |
| 1032 | let older = PlaybackSession::open_project(&old).expect("open the v10 project"); |
| 1033 | assert_eq!(older.tone(), Preset::Reference); |
| 1034 | } |
| 1035 | |
| 1036 | |
| 1037 | |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 | |
| 1042 | #[test] |
| 1043 | fn a_song_only_project_comes_back_at_the_rate_it_names() { |
| 1044 | let dir = scratch("song_fps"); |
| 1045 | copy_in(&dir, "test_tone.mp3"); |
| 1046 | let path = dir.join("song.edith"); |
| 1047 | std::fs::write( |
| 1048 | &path, |
| 1049 | "edith 10\nplayhead 0\nresolution 1920 1080\nfps 24.0\nsource 0 test_tone.mp3\n\ |
| 1050 | video 1\naudio 1 0 0 24 0 - - - fit 1000\n", |
| 1051 | ) |
| 1052 | .expect("write a v9 song project"); |
| 1053 | let loaded = PlaybackSession::open_project(&path).expect("a song-only project opens"); |
| 1054 | assert_eq!(loaded.meta().frame_rate, 24.0, "the rate the file names"); |
| 1055 | assert_eq!(loaded.timeline_duration(), 1.0, "one second at 24 fps"); |
| 1056 | |
| 1057 | |
| 1058 | |
| 1059 | let old = dir.join("song8.edith"); |
| 1060 | std::fs::write( |
| 1061 | &old, |
| 1062 | "edith 8\nplayhead 0\nresolution 1920 1080\nsource 0 test_tone.mp3\n\ |
| 1063 | video 1\naudio 1 0 0 24 0 - - - fit 1000\n", |
| 1064 | ) |
| 1065 | .expect("write a v8 song project"); |
| 1066 | let loaded = PlaybackSession::open_project(&old).expect("a v8 song project opens"); |
| 1067 | assert_eq!(loaded.meta().frame_rate, 30.0, "the canvas rate, as before"); |
| 1068 | } |
| 1069 | |
| 1070 | |
| 1071 | |
| 1072 | |
| 1073 | |
| 1074 | |
| 1075 | |
| 1076 | |
| 1077 | |
| 1078 | |
| 1079 | |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | #[test] |
| 1085 | fn a_caption_window_no_project_can_hold_is_refused_by_name() { |
| 1086 | let dir = scratch("caption_window"); |
| 1087 | let media = copy_in(&dir, "test_av.mp4"); |
| 1088 | let subs = PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 1089 | .join("tests/data/test_subs.srt") |
| 1090 | .canonicalize() |
| 1091 | .expect("the subtitle fixture"); |
| 1092 | |
| 1093 | |
| 1094 | |
| 1095 | let ok = dir.join("window_ok.edith"); |
| 1096 | std::fs::write( |
| 1097 | &ok, |
| 1098 | format!( |
| 1099 | "edith 24\nplayhead 0\nresolution 1280 720\nsource 0 {}\nsubtitle - {}\n\ |
| 1100 | video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n\ |
| 1101 | sub 1 0 30 0 0 30000000\n", |
| 1102 | media.display(), |
| 1103 | subs.display(), |
| 1104 | ), |
| 1105 | ) |
| 1106 | .expect("write"); |
| 1107 | let mut control = PlaybackSession::open_project(&ok).expect("a 30s caption window opens"); |
| 1108 | assert_eq!(control.sub_lane(Lane::S1)[0].out_us, 30_000_000); |
| 1109 | |
| 1110 | |
| 1111 | assert!( |
| 1112 | control.cut_at(0.5), |
| 1113 | "the playhead splits the caption under it" |
| 1114 | ); |
| 1115 | assert_eq!( |
| 1116 | control.sub_lane(Lane::S1).len(), |
| 1117 | 2, |
| 1118 | "the split cut the caption in two" |
| 1119 | ); |
| 1120 | control.undo(); |
| 1121 | control |
| 1122 | .cut_regions(&[(0, 10)], &[Lane::S1]) |
| 1123 | .expect("a ripple across the caption, scoped to its own lane"); |
| 1124 | let after = control.sub_lane(Lane::S1); |
| 1125 | assert_eq!(after.len(), 1, "the caption's tail is still there"); |
| 1126 | assert_eq!( |
| 1127 | (after[0].start, after[0].frames), |
| 1128 | (0, 20), |
| 1129 | "and it closed the hole the cut left" |
| 1130 | ); |
| 1131 | |
| 1132 | |
| 1133 | |
| 1134 | let huge = dir.join("window_huge.edith"); |
| 1135 | std::fs::write( |
| 1136 | &huge, |
| 1137 | format!( |
| 1138 | "edith 24\nplayhead 0\nresolution 1280 720\nsource 0 {}\nsubtitle - {}\n\ |
| 1139 | video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n\ |
| 1140 | sub 1 0 30 0 0 9223372036854775807\n", |
| 1141 | media.display(), |
| 1142 | subs.display(), |
| 1143 | ), |
| 1144 | ) |
| 1145 | .expect("write"); |
| 1146 | let err = PlaybackSession::open_project(&huge) |
| 1147 | .err() |
| 1148 | .unwrap_or_else(|| { |
| 1149 | panic!( |
| 1150 | "a caption window of {}us loaded, and the first split across it \ |
| 1151 | panics in SubClip::window_at", |
| 1152 | i64::MAX |
| 1153 | ) |
| 1154 | }) |
| 1155 | .to_string(); |
| 1156 | assert!( |
| 1157 | err.contains("window") && err.contains("9223372036854775807"), |
| 1158 | "the refusal names the window it is refusing, and the value: {err}" |
| 1159 | ); |
| 1160 | assert!(err.starts_with("line 7"), "and which line said it: {err}"); |
| 1161 | |
| 1162 | |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | let mut session = PlaybackSession::open(&media).expect("open the fixture"); |
| 1167 | session |
| 1168 | .import_subtitles(&subs) |
| 1169 | .expect("the fixture's one track"); |
| 1170 | let s1 = session.add_lane(engine::project::LaneKind::Subtitle); |
| 1171 | let err = session |
| 1172 | .place_sub( |
| 1173 | s1, |
| 1174 | 0, |
| 1175 | engine::project::SubClip { |
| 1176 | start: 0, |
| 1177 | frames: 30, |
| 1178 | track: 0, |
| 1179 | in_us: 0, |
| 1180 | out_us: i64::MAX, |
| 1181 | link: None, |
| 1182 | }, |
| 1183 | ) |
| 1184 | .expect_err("a window no project can hold is refused by name, not clamped") |
| 1185 | .to_string(); |
| 1186 | assert!( |
| 1187 | err.contains("window") && err.contains(&i64::MAX.to_string()), |
| 1188 | "the placement refusal names the window and the value: {err}" |
| 1189 | ); |
| 1190 | assert!( |
| 1191 | session.sub_lane(s1).is_empty(), |
| 1192 | "and a refusal places nothing: {:?}", |
| 1193 | session.sub_lane(s1) |
| 1194 | ); |
| 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | |
| 1199 | |
| 1200 | |
| 1201 | |
| 1202 | |
| 1203 | |
| 1204 | fn long_srt(dir: &Path, hours: u32) -> PathBuf { |
| 1205 | let path = dir.join(format!("subs_{hours}h.srt")); |
| 1206 | std::fs::write( |
| 1207 | &path, |
| 1208 | format!( |
| 1209 | "1\n00:00:00,500 --> 00:00:01,500\nfirst line\n\n\ |
| 1210 | 2\n00:00:01,600 --> {hours}:00:00,000\nlast line of a long recording\n" |
| 1211 | ), |
| 1212 | ) |
| 1213 | .expect("write a long subtitle track"); |
| 1214 | path |
| 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | |
| 1219 | |
| 1220 | |
| 1221 | |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | |
| 1228 | #[test] |
| 1229 | fn a_trim_grown_to_the_offered_room_saves_and_reopens() { |
| 1230 | use engine::project::{Edge, MAX_WINDOW_US, SubClip}; |
| 1231 | |
| 1232 | let dir = scratch("caption_growth"); |
| 1233 | let media = copy_in(&dir, "test_av.mp4"); |
| 1234 | |
| 1235 | |
| 1236 | let subs = long_srt(&dir, 960); |
| 1237 | |
| 1238 | let mut session = PlaybackSession::open(&media).expect("open the fixture"); |
| 1239 | session |
| 1240 | .import_subtitles(&subs) |
| 1241 | .expect("a 40-day subtitle track imports"); |
| 1242 | let s1 = session.add_lane(engine::project::LaneKind::Subtitle); |
| 1243 | session |
| 1244 | .place_sub( |
| 1245 | s1, |
| 1246 | 60, |
| 1247 | SubClip { |
| 1248 | start: 0, |
| 1249 | frames: 90, |
| 1250 | track: 0, |
| 1251 | in_us: 0, |
| 1252 | out_us: 30_000_000, |
| 1253 | link: None, |
| 1254 | }, |
| 1255 | ) |
| 1256 | .expect("a 30s window places"); |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | let (_, last) = session |
| 1262 | .trim_sub_room(s1, 0, Edge::End) |
| 1263 | .expect("a room for a caption that is there"); |
| 1264 | session |
| 1265 | .trim_sub(s1, 0, Edge::End, last) |
| 1266 | .expect("the trim to its own offered room"); |
| 1267 | |
| 1268 | let grown = session.sub_lane(s1)[0]; |
| 1269 | assert!( |
| 1270 | (grown.out_us - grown.in_us) <= MAX_WINDOW_US, |
| 1271 | "trimming to the offered room gave a {}us window, past the {}us ceiling", |
| 1272 | grown.out_us - grown.in_us, |
| 1273 | MAX_WINDOW_US |
| 1274 | ); |
| 1275 | |
| 1276 | let saved = dir.join("grown.edith"); |
| 1277 | session.save_project(&saved).expect("save"); |
| 1278 | let reopened = PlaybackSession::open_project(&saved) |
| 1279 | .expect("a project the editor wrote must open again -- that is the whole claim"); |
| 1280 | let back = reopened.sub_lane(s1)[0]; |
| 1281 | assert_eq!( |
| 1282 | (back.in_us, back.out_us), |
| 1283 | (grown.in_us, grown.out_us), |
| 1284 | "and the window came back as it was saved" |
| 1285 | ); |
| 1286 | } |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | |
| 1291 | |
| 1292 | |
| 1293 | #[test] |
| 1294 | fn a_caption_over_a_day_of_track_places_and_round_trips() { |
| 1295 | use engine::project::MAX_WINDOW_US; |
| 1296 | |
| 1297 | let dir = scratch("caption_long_track"); |
| 1298 | let media = copy_in(&dir, "test_av.mp4"); |
| 1299 | let subs = long_srt(&dir, 25); |
| 1300 | let whole_track_us = 25i64 * 60 * 60 * 1_000_000; |
| 1301 | assert!( |
| 1302 | whole_track_us > 86_400_000_000, |
| 1303 | "the fixture must really be over a day, or this test proves nothing" |
| 1304 | ); |
| 1305 | assert!( |
| 1306 | whole_track_us < MAX_WINDOW_US, |
| 1307 | "and comfortably under the ceiling, or the test is not about the ceiling" |
| 1308 | ); |
| 1309 | |
| 1310 | let mut session = PlaybackSession::open(&media).expect("open the fixture"); |
| 1311 | assert_eq!( |
| 1312 | session |
| 1313 | .import_subtitles(&subs) |
| 1314 | .expect("a 25-hour track imports"), |
| 1315 | 1, |
| 1316 | "one track" |
| 1317 | ); |
| 1318 | let s1 = session.add_lane(engine::project::LaneKind::Subtitle); |
| 1319 | |
| 1320 | let fps = session.meta().frame_rate; |
| 1321 | session |
| 1322 | .place_sub( |
| 1323 | s1, |
| 1324 | 0, |
| 1325 | engine::project::SubClip { |
| 1326 | start: 0, |
| 1327 | frames: ((whole_track_us as f64) * fps / 1e6).round() as u32, |
| 1328 | track: 0, |
| 1329 | in_us: 0, |
| 1330 | out_us: whole_track_us, |
| 1331 | link: None, |
| 1332 | }, |
| 1333 | ) |
| 1334 | .expect("a caption over a 25-hour recording places -- that is the claim"); |
| 1335 | |
| 1336 | let saved = dir.join("long.edith"); |
| 1337 | session.save_project(&saved).expect("save"); |
| 1338 | let reopened = PlaybackSession::open_project(&saved).expect("and reopens"); |
| 1339 | assert_eq!( |
| 1340 | reopened.sub_lane(s1)[0].out_us, |
| 1341 | whole_track_us, |
| 1342 | "the whole window survived the round trip" |
| 1343 | ); |
| 1344 | } |
| 1345 | |
| 1346 | |
| 1347 | |
| 1348 | |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | |
| 1355 | |
| 1356 | |
| 1357 | |
| 1358 | #[test] |
| 1359 | fn a_group_trim_carries_its_sibling_no_further_than_the_ceiling() { |
| 1360 | use engine::project::{Edge, LaneKind, MAX_WINDOW_US, SubClip}; |
| 1361 | |
| 1362 | let dir = scratch("caption_group_growth"); |
| 1363 | let media = copy_in(&dir, "test_av.mp4"); |
| 1364 | let subs = long_srt(&dir, 960); |
| 1365 | let day = 24 * 60 * 60 * 1_000_000i64; |
| 1366 | |
| 1367 | let mut session = PlaybackSession::open(&media).expect("open the fixture"); |
| 1368 | session |
| 1369 | .import_subtitles(&subs) |
| 1370 | .expect("a 40-day track imports"); |
| 1371 | let s1 = session.add_lane(LaneKind::Subtitle); |
| 1372 | let s2 = session.add_lane(LaneKind::Subtitle); |
| 1373 | let caption = |in_us| SubClip { |
| 1374 | start: 0, |
| 1375 | frames: 90, |
| 1376 | track: 0, |
| 1377 | in_us, |
| 1378 | out_us: in_us + 30_000_000, |
| 1379 | link: None, |
| 1380 | }; |
| 1381 | session |
| 1382 | .place_sub(s1, 60, caption(0)) |
| 1383 | .expect("the dragged caption places"); |
| 1384 | session |
| 1385 | .place_sub(s2, 60, caption(20 * day)) |
| 1386 | .expect("its sibling, 20 days into the track"); |
| 1387 | session |
| 1388 | .group_all(&[(s1, 0), (s2, 0)]) |
| 1389 | .expect("the two captions into one group"); |
| 1390 | |
| 1391 | |
| 1392 | |
| 1393 | let (_, last) = session |
| 1394 | .trim_sub_room(s1, 0, Edge::End) |
| 1395 | .expect("a room for the dragged caption"); |
| 1396 | session |
| 1397 | .trim_sub(s1, 0, Edge::End, last) |
| 1398 | .expect("the drag commits"); |
| 1399 | |
| 1400 | let dragged = session.sub_lane(s1)[0]; |
| 1401 | assert_eq!( |
| 1402 | dragged.out_us - dragged.in_us, |
| 1403 | MAX_WINDOW_US, |
| 1404 | "the dragged caption stops exactly at the ceiling, which is the room it was offered" |
| 1405 | ); |
| 1406 | let sibling = session.sub_lane(s2)[0]; |
| 1407 | assert!( |
| 1408 | (sibling.out_us - sibling.in_us) <= MAX_WINDOW_US, |
| 1409 | "the group carried the sibling to a {}us window, past the {}us ceiling -- \ |
| 1410 | the dragged caption's own clamp does not reach here", |
| 1411 | sibling.out_us - sibling.in_us, |
| 1412 | MAX_WINDOW_US |
| 1413 | ); |
| 1414 | |
| 1415 | let saved = dir.join("group.edith"); |
| 1416 | session.save_project(&saved).expect("save"); |
| 1417 | PlaybackSession::open_project(&saved).expect("and the file the editor wrote reopens"); |
| 1418 | } |
| 1419 | |
| 1420 | |
| 1421 | |
| 1422 | |
| 1423 | |
| 1424 | |
| 1425 | |
| 1426 | |
| 1427 | |
| 1428 | #[test] |
| 1429 | fn a_rejoin_of_two_legal_windows_stays_inside_the_ceiling() { |
| 1430 | use engine::project::{MAX_WINDOW_US, SubClip}; |
| 1431 | |
| 1432 | let dir = scratch("caption_rejoin"); |
| 1433 | let media = copy_in(&dir, "test_av.mp4"); |
| 1434 | let subs = long_srt(&dir, 960); |
| 1435 | let twenty_days = 20 * 24 * 60 * 60 * 1_000_000i64; |
| 1436 | |
| 1437 | let mut session = PlaybackSession::open(&media).expect("open the fixture"); |
| 1438 | session |
| 1439 | .import_subtitles(&subs) |
| 1440 | .expect("a 40-day track imports"); |
| 1441 | let s1 = session.add_lane(engine::project::LaneKind::Subtitle); |
| 1442 | |
| 1443 | |
| 1444 | |
| 1445 | for (at, frames, in_us) in [(0u32, 10_000u32, 0i64), (10_000, 10_000, twenty_days)] { |
| 1446 | session |
| 1447 | .place_sub( |
| 1448 | s1, |
| 1449 | at, |
| 1450 | SubClip { |
| 1451 | start: 0, |
| 1452 | frames, |
| 1453 | track: 0, |
| 1454 | in_us, |
| 1455 | out_us: in_us + twenty_days, |
| 1456 | link: None, |
| 1457 | }, |
| 1458 | ) |
| 1459 | .unwrap_or_else(|e| panic!("a 20-day half at {at} places: {e}")); |
| 1460 | } |
| 1461 | let halves: Vec<i64> = session |
| 1462 | .sub_lane(s1) |
| 1463 | .iter() |
| 1464 | .map(|s| s.out_us - s.in_us) |
| 1465 | .collect(); |
| 1466 | assert!( |
| 1467 | halves.iter().all(|&w| w <= MAX_WINDOW_US), |
| 1468 | "both halves must be legal for this to be about the join: {halves:?}" |
| 1469 | ); |
| 1470 | |
| 1471 | |
| 1472 | |
| 1473 | let at_secs = 10_000.0 / session.meta().frame_rate; |
| 1474 | assert!( |
| 1475 | session.regroup_at(at_secs), |
| 1476 | "the two halves rejoin -- the inverse of the split that made them" |
| 1477 | ); |
| 1478 | let joined = &session.sub_lane(s1)[0]; |
| 1479 | assert!( |
| 1480 | (joined.out_us - joined.in_us) <= MAX_WINDOW_US, |
| 1481 | "the rejoin summed two {}us windows into {}us, past the {}us ceiling", |
| 1482 | MAX_WINDOW_US / 2, |
| 1483 | joined.out_us - joined.in_us, |
| 1484 | MAX_WINDOW_US |
| 1485 | ); |
| 1486 | |
| 1487 | let saved = dir.join("rejoined.edith"); |
| 1488 | session.save_project(&saved).expect("save"); |
| 1489 | PlaybackSession::open_project(&saved).expect("and the file the editor wrote reopens"); |
| 1490 | } |
| 1491 | |
| 1492 | |
| 1493 | |
| 1494 | |
| 1495 | |
| 1496 | |
| 1497 | |
| 1498 | |
| 1499 | |
| 1500 | #[test] |
| 1501 | fn a_head_drag_no_further_than_the_ceiling() { |
| 1502 | use engine::project::{Edge, MAX_WINDOW_US, SubClip}; |
| 1503 | |
| 1504 | let dir = scratch("caption_head_drag"); |
| 1505 | let media = copy_in(&dir, "test_av.mp4"); |
| 1506 | let subs = long_srt(&dir, 960); |
| 1507 | let day = 24 * 60 * 60 * 1_000_000i64; |
| 1508 | |
| 1509 | let mut session = PlaybackSession::open(&media).expect("open the fixture"); |
| 1510 | session |
| 1511 | .import_subtitles(&subs) |
| 1512 | .expect("a 40-day track imports"); |
| 1513 | let s1 = session.add_lane(engine::project::LaneKind::Subtitle); |
| 1514 | |
| 1515 | |
| 1516 | session |
| 1517 | .place_sub( |
| 1518 | s1, |
| 1519 | 90_000_000, |
| 1520 | SubClip { |
| 1521 | start: 0, |
| 1522 | frames: 900, |
| 1523 | track: 0, |
| 1524 | in_us: 365 * day, |
| 1525 | out_us: 365 * day + 30_000_000, |
| 1526 | link: None, |
| 1527 | }, |
| 1528 | ) |
| 1529 | .expect("a year-deep caption places"); |
| 1530 | |
| 1531 | |
| 1532 | |
| 1533 | |
| 1534 | let (lo, _) = session |
| 1535 | .trim_sub_room(s1, 0, Edge::Start) |
| 1536 | .expect("a head room"); |
| 1537 | session |
| 1538 | .trim_sub(s1, 0, Edge::Start, lo) |
| 1539 | .expect("the head drag commits"); |
| 1540 | |
| 1541 | let dragged = session.sub_lane(s1)[0]; |
| 1542 | assert!( |
| 1543 | (dragged.out_us - dragged.in_us) <= MAX_WINDOW_US, |
| 1544 | "a head drag onto a year-deep caption gave a {}us window, past the {}us ceiling", |
| 1545 | dragged.out_us - dragged.in_us, |
| 1546 | MAX_WINDOW_US |
| 1547 | ); |
| 1548 | |
| 1549 | let saved = dir.join("head.edith"); |
| 1550 | session.save_project(&saved).expect("save"); |
| 1551 | PlaybackSession::open_project(&saved).expect("and the file the editor wrote reopens"); |
| 1552 | } |
| 1553 | |
| 1554 | |
| 1555 | |
| 1556 | |
| 1557 | #[test] |
| 1558 | fn the_lane_switches_survive_a_save_and_an_open() { |
| 1559 | use engine::project::LaneKind; |
| 1560 | let dir = scratch("switches"); |
| 1561 | let source = copy_in(&dir, "test_av.mp4"); |
| 1562 | let mut saved = PlaybackSession::open(&source).expect("open the fixture"); |
| 1563 | let v2 = saved.add_lane(LaneKind::Video); |
| 1564 | assert!(saved.set_lane_hidden(v2, true), "a video lane hides"); |
| 1565 | assert!(saved.set_lane_muted(Lane::A1, true), "an audio lane mutes"); |
| 1566 | assert!(saved.set_lane_locked(Lane::A1, true), "any lane locks"); |
| 1567 | let path = dir.join("switches.edith"); |
| 1568 | saved.save_project(&path).expect("save"); |
| 1569 | let text = std::fs::read_to_string(&path).expect("read back"); |
| 1570 | assert!(text.starts_with("edith 30\n"), "{text}"); |
| 1571 | assert!(text.contains("\nflags video 2 hidden\n"), "{text}"); |
| 1572 | assert!(text.contains("\nflags audio 1 muted locked\n"), "{text}"); |
| 1573 | |
| 1574 | let mut loaded = PlaybackSession::open_project(&path).expect("open the project"); |
| 1575 | assert!(loaded.lane_hidden(v2), "V2 is still hidden"); |
| 1576 | assert!(!loaded.lane_hidden(Lane::V1), "and V1 is not"); |
| 1577 | assert!(loaded.lane_muted(Lane::A1), "A1 is still muted"); |
| 1578 | assert!(loaded.lane_locked(Lane::A1), "and still locked"); |
| 1579 | assert!(!loaded.undo(), "a loaded switch is not an undo step"); |
| 1580 | |
| 1581 | let again = dir.join("again.edith"); |
| 1582 | loaded |
| 1583 | .save_project(&again) |
| 1584 | .expect("save the loaded project"); |
| 1585 | assert_eq!( |
| 1586 | std::fs::read(&path).unwrap(), |
| 1587 | std::fs::read(&again).unwrap(), |
| 1588 | "save -> load -> save is not a fixed point" |
| 1589 | ); |
| 1590 | } |
| 1591 | |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | #[test] |
| 1596 | fn a_version_23_project_opens_with_every_lane_showing_and_audible() { |
| 1597 | let dir = scratch("v23_switches"); |
| 1598 | copy_in(&dir, "test_av.mp4"); |
| 1599 | let path = dir.join("v23.edith"); |
| 1600 | let text = "edith 23\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ |
| 1601 | video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n\ |
| 1602 | audio 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n"; |
| 1603 | std::fs::write(&path, text).expect("write a v23 file"); |
| 1604 | |
| 1605 | let loaded = PlaybackSession::open_project(&path).expect("a v23 project opens"); |
| 1606 | assert!(!loaded.lane_hidden(Lane::V1)); |
| 1607 | assert!(!loaded.lane_muted(Lane::A1)); |
| 1608 | assert!(!loaded.lane_locked(Lane::A1)); |
| 1609 | let again = dir.join("again.edith"); |
| 1610 | loaded.save_project(&again).expect("save"); |
| 1611 | assert_eq!( |
| 1612 | std::fs::read_to_string(&again).expect("read back"), |
| 1613 | text.replace("edith 23", "edith 30"), |
| 1614 | "the same project, at the current version, with no switch line" |
| 1615 | ); |
| 1616 | } |
| 1617 | |
| 1618 | |
| 1619 | |
| 1620 | |
| 1621 | #[test] |
| 1622 | fn a_retyped_cue_saves_reopens_and_undoes_in_one_step() { |
| 1623 | let dir = scratch("cue_text"); |
| 1624 | let mut session = PlaybackSession::open(copy_in(&dir, "test_av.mp4")).expect("open"); |
| 1625 | session.set_gain(0.0); |
| 1626 | let srt = dir.join("subs.srt"); |
| 1627 | std::fs::write( |
| 1628 | &srt, |
| 1629 | "1\n00:00:01,000 --> 00:00:02,000\nFirst\n\n2\n00:00:03,000 --> 00:00:04,000\nSecond\n\n", |
| 1630 | ) |
| 1631 | .expect("write the subtitle file"); |
| 1632 | assert_eq!(session.import_subtitles(&srt).expect("import"), 1); |
| 1633 | assert_eq!(session.subtitles()[0].cues.len(), 2, "two cues in the file"); |
| 1634 | |
| 1635 | let typed = "Ça va?\nback\\slash"; |
| 1636 | assert!(session.set_cue_text(0, 1, typed)); |
| 1637 | assert_eq!(session.subtitles()[0].cues[1].text, typed); |
| 1638 | assert!( |
| 1639 | !session.set_cue_text(0, 1, typed), |
| 1640 | "the same words are no edit" |
| 1641 | ); |
| 1642 | assert!(!session.set_cue_text(0, 9, "x"), "a cue that is not there"); |
| 1643 | |
| 1644 | let path = dir.join("cues.edith"); |
| 1645 | session.save_project(&path).expect("save"); |
| 1646 | let text = std::fs::read_to_string(&path).expect("read back"); |
| 1647 | assert!( |
| 1648 | text.contains("cue 0 1 Ça va?\\nback\\\\slash\n"), |
| 1649 | "the override reached the file:\n{text}" |
| 1650 | ); |
| 1651 | |
| 1652 | let loaded = PlaybackSession::open_project(&path).expect("reopen"); |
| 1653 | assert_eq!( |
| 1654 | loaded.subtitles()[0].cues[1].text, |
| 1655 | typed, |
| 1656 | "the typed words come back" |
| 1657 | ); |
| 1658 | assert_eq!( |
| 1659 | loaded.subtitles()[0].cues[0].text, |
| 1660 | "First", |
| 1661 | "the rest is the file's" |
| 1662 | ); |
| 1663 | |
| 1664 | loaded.save_project(&path).expect("re-save"); |
| 1665 | let again = PlaybackSession::open_project(&path).expect("reopen the re-save"); |
| 1666 | assert_eq!( |
| 1667 | again.subtitles()[0].cues[1].text, |
| 1668 | typed, |
| 1669 | "a re-save keeps the override" |
| 1670 | ); |
| 1671 | |
| 1672 | assert!(session.undo(), "one step back takes the retype"); |
| 1673 | assert_eq!(session.subtitles()[0].cues[1].text, "Second"); |
| 1674 | std::fs::remove_dir_all(&dir).expect("cleanup"); |
| 1675 | } |
| 1676 | |
| 1677 | |
| 1678 | |
| 1679 | |
| 1680 | |
| 1681 | #[test] |
| 1682 | fn an_added_cue_saves_reopens_in_place_and_undoes_in_one_step() { |
| 1683 | let dir = scratch("cue_add"); |
| 1684 | let mut session = PlaybackSession::open(copy_in(&dir, "test_av.mp4")).expect("open"); |
| 1685 | session.set_gain(0.0); |
| 1686 | let srt = dir.join("subs.srt"); |
| 1687 | std::fs::write( |
| 1688 | &srt, |
| 1689 | "1\n00:00:01,000 --> 00:00:02,000\nFirst\n\n2\n00:00:03,000 --> 00:00:04,000\nSecond\n\n", |
| 1690 | ) |
| 1691 | .expect("write the subtitle file"); |
| 1692 | assert_eq!(session.import_subtitles(&srt).expect("import"), 1); |
| 1693 | |
| 1694 | let at = session |
| 1695 | .add_cue(0, 2_200_000, 2_800_000, "Added\nline two", false) |
| 1696 | .expect("a gap between the two cues takes a cue"); |
| 1697 | assert_eq!(at, 1, "sorted by start, so it lands between the two"); |
| 1698 | assert!( |
| 1699 | session.add_cue(0, 1_500_000, 2_500_000, "Clash", false).is_err(), |
| 1700 | "an overlap is refused without overwrite" |
| 1701 | ); |
| 1702 | assert_eq!(session.subtitles()[0].cues.len(), 3, "the refusal changed nothing"); |
| 1703 | |
| 1704 | let path = dir.join("cues_add.edith"); |
| 1705 | session.save_project(&path).expect("save"); |
| 1706 | let text = std::fs::read_to_string(&path).expect("read back"); |
| 1707 | assert!( |
| 1708 | text.contains("cueadd 0 2200000 2800000 Added\\nline two\n"), |
| 1709 | "the added cue reached the file:\n{text}" |
| 1710 | ); |
| 1711 | |
| 1712 | let loaded = PlaybackSession::open_project(&path).expect("reopen"); |
| 1713 | let cues = loaded.subtitles()[0].cues.clone(); |
| 1714 | assert_eq!(cues.len(), 3, "the added cue is back among the file's two"); |
| 1715 | assert_eq!( |
| 1716 | (cues[0].text.as_str(), cues[1].text.as_str(), cues[2].text.as_str()), |
| 1717 | ("First", "Added\nline two", "Second") |
| 1718 | ); |
| 1719 | assert_eq!((cues[1].start_us, cues[1].end_us), (2_200_000, 2_800_000)); |
| 1720 | |
| 1721 | |
| 1722 | loaded.save_project(&path).expect("re-save"); |
| 1723 | let mut again = PlaybackSession::open_project(&path).expect("reopen the re-save"); |
| 1724 | assert_eq!(again.subtitles()[0].cues.len(), 3, "the re-save keeps the added cue"); |
| 1725 | again.add_cue(0, 2_500_000, 2_900_000, "Over", true).expect("overwrite replaces the cue it overlaps"); |
| 1726 | let texts: Vec<String> = again.subtitles()[0].cues.iter().map(|c| c.text.clone()).collect(); |
| 1727 | assert_eq!(texts, ["First", "Over", "Second"], "the added cue it overlapped is gone"); |
| 1728 | assert!(again.undo(), "one step back takes the overwrite"); |
| 1729 | assert_eq!( |
| 1730 | again.subtitles()[0].cues.iter().map(|c| c.text.as_str()).collect::<Vec<_>>(), |
| 1731 | ["First", "Added\nline two", "Second"], |
| 1732 | "and brings the replaced cue back" |
| 1733 | ); |
| 1734 | |
| 1735 | assert!(session.undo(), "one step back takes the add"); |
| 1736 | assert_eq!(session.subtitles()[0].cues.len(), 2, "the file's two cues again"); |
| 1737 | std::fs::remove_dir_all(&dir).expect("cleanup"); |
| 1738 | } |
| 1739 | |
| 1740 | #[test] |
| 1741 | fn an_empty_project_takes_a_clip_and_comes_back_the_same() { |
| 1742 | let dir = scratch("empty"); |
| 1743 | let media = copy_in(&dir, "test_av.mp4"); |
| 1744 | let mut session = PlaybackSession::empty(640, 360, 25.0).expect("an empty timeline"); |
| 1745 | assert!(session.is_empty(), "nothing on any lane yet"); |
| 1746 | assert_eq!(session.timeline_duration(), 0.0); |
| 1747 | session.set_gain(0.0); |
| 1748 | session.import(&media).expect("import"); |
| 1749 | assert!( |
| 1750 | session |
| 1751 | .place_stream_at(0.0, &media, 0, None) |
| 1752 | .expect("place") |
| 1753 | ); |
| 1754 | let file = dir.join("empty.edith"); |
| 1755 | session.save_project(&file).expect("save"); |
| 1756 | let back = PlaybackSession::open_project(&file).expect("reopen"); |
| 1757 | assert_eq!(back.resolution(), (640, 360)); |
| 1758 | assert_eq!(back.sources().len(), 1); |
| 1759 | assert_eq!(back.clip_spans(), session.clip_spans()); |
| 1760 | assert!( |
| 1761 | back.timeline_duration() > 4.5, |
| 1762 | "{}", |
| 1763 | back.timeline_duration() |
| 1764 | ); |
| 1765 | } |
| 1766 | |
| 1767 | |
| 1768 | |
| 1769 | |
| 1770 | #[test] |
| 1771 | fn titles_survive_a_save_and_an_open() { |
| 1772 | use engine::project::Title; |
| 1773 | use engine::text::{Outline, Place, TextStyle}; |
| 1774 | let dir = scratch("titles"); |
| 1775 | let source = copy_in(&dir, "test_av.mp4"); |
| 1776 | let mut saved = PlaybackSession::open(&source).expect("open the fixture"); |
| 1777 | let card = Title { |
| 1778 | start: 150, |
| 1779 | frames: 90, |
| 1780 | text: "Episode 17\n100% \\ done".into(), |
| 1781 | style: TextStyle { |
| 1782 | size: 80, |
| 1783 | outline: Outline::Thick, |
| 1784 | boxed: false, |
| 1785 | place: Place::Centre, |
| 1786 | ..TextStyle::default() |
| 1787 | }, |
| 1788 | fade_in: 10, |
| 1789 | fade_out: 5, |
| 1790 | in_anim: Default::default(), |
| 1791 | out_anim: Default::default(), |
| 1792 | anim_frames: 0, |
| 1793 | keys: Vec::new(), |
| 1794 | }; |
| 1795 | let lower = Title { |
| 1796 | start: 60, |
| 1797 | frames: 120, |
| 1798 | text: "Jane Doe \u{2014} Engineer".into(), |
| 1799 | style: TextStyle::default(), |
| 1800 | fade_in: 0, |
| 1801 | fade_out: 0, |
| 1802 | in_anim: Default::default(), |
| 1803 | out_anim: Default::default(), |
| 1804 | anim_frames: 0, |
| 1805 | keys: Vec::new(), |
| 1806 | }; |
| 1807 | saved.add_title(card.clone()).expect("the card is added"); |
| 1808 | saved |
| 1809 | .add_title(lower.clone()) |
| 1810 | .expect("the lower third is added"); |
| 1811 | assert_eq!( |
| 1812 | saved.titles(), |
| 1813 | [lower.clone(), card.clone()], |
| 1814 | "sorted by start" |
| 1815 | ); |
| 1816 | let path = dir.join("titles.edith"); |
| 1817 | saved.save_project(&path).expect("save"); |
| 1818 | |
| 1819 | let mut loaded = PlaybackSession::open_project(&path).expect("open the project"); |
| 1820 | assert_eq!(loaded.titles(), [lower, card], "the same titles come back"); |
| 1821 | assert!(!loaded.undo(), "a loaded title is not an undo step"); |
| 1822 | let again = dir.join("again.edith"); |
| 1823 | loaded |
| 1824 | .save_project(&again) |
| 1825 | .expect("save the loaded project"); |
| 1826 | assert_eq!( |
| 1827 | std::fs::read(&path).unwrap(), |
| 1828 | std::fs::read(&again).unwrap(), |
| 1829 | "save -> load -> save is not a fixed point" |
| 1830 | ); |
| 1831 | } |
| 1832 | |
| 1833 | |
| 1834 | |
| 1835 | #[test] |
| 1836 | fn a_title_look_survives_a_save_and_an_open_as_v49() { |
| 1837 | use engine::project::Title; |
| 1838 | use engine::text::{Align, HPlace, Outline, Place, TextStyle, Weight}; |
| 1839 | let dir = scratch("title_look"); |
| 1840 | let source = copy_in(&dir, "test_av.mp4"); |
| 1841 | let mut plain = PlaybackSession::open(&source).expect("open the fixture"); |
| 1842 | let mk = |style: TextStyle| Title { start: 30, frames: 60, text: "Jane\nDirector".into(), style, fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0, keys: Vec::new() }; |
| 1843 | plain.add_title(mk(TextStyle::default())).expect("added"); |
| 1844 | let p0 = dir.join("plain.edith"); |
| 1845 | plain.save_project(&p0).expect("save"); |
| 1846 | let text = std::fs::read_to_string(&p0).unwrap(); |
| 1847 | assert!(!text.starts_with("edith 49") && !text.contains("titlestyle"), "{}", text.lines().next().unwrap()); |
| 1848 | |
| 1849 | let look = TextStyle { |
| 1850 | outline: Outline::None, |
| 1851 | place: Place::Bottom, |
| 1852 | hplace: HPlace::Left, |
| 1853 | align: Align::Left, |
| 1854 | weight: Weight::Bold, |
| 1855 | ink: [255, 204, 0], |
| 1856 | box_color: [17, 34, 51, 200], |
| 1857 | ..TextStyle::default() |
| 1858 | }; |
| 1859 | let mut saved = PlaybackSession::open(&source).expect("open the fixture"); |
| 1860 | saved.add_title(mk(look.clone())).expect("added"); |
| 1861 | let path = dir.join("look.edith"); |
| 1862 | saved.save_project(&path).expect("save"); |
| 1863 | let text = std::fs::read_to_string(&path).unwrap(); |
| 1864 | assert!(text.starts_with("edith 49\n"), "{}", text.lines().next().unwrap()); |
| 1865 | let loaded = PlaybackSession::open_project(&path).expect("open the project"); |
| 1866 | assert_eq!(loaded.titles()[0].style, look); |
| 1867 | |
| 1868 | let old = text.replacen("edith 49", "edith 48", 1); |
| 1869 | let old_path = dir.join("old.edith"); |
| 1870 | std::fs::write(&old_path, old).unwrap(); |
| 1871 | assert!(PlaybackSession::open_project(&old_path).is_err()); |
| 1872 | let again = dir.join("again.edith"); |
| 1873 | loaded.save_project(&again).expect("save the loaded project"); |
| 1874 | assert_eq!(std::fs::read(&path).unwrap(), std::fs::read(&again).unwrap()); |
| 1875 | } |
| 1876 | |
| 1877 | |
| 1878 | |
| 1879 | |
| 1880 | |
| 1881 | #[test] |
| 1882 | fn a_clip_gain_survives_a_save_and_an_open() { |
| 1883 | use engine::project::{Lane, LaneKind}; |
| 1884 | let dir = scratch("clip_gain"); |
| 1885 | let source = copy_in(&dir, "test_av.mp4"); |
| 1886 | let mut saved = PlaybackSession::open(&source).expect("open the fixture"); |
| 1887 | assert!( |
| 1888 | saved.cut_at(2.0), |
| 1889 | "two clips on A1, so the index means something" |
| 1890 | ); |
| 1891 | let a1 = Lane::new(LaneKind::Audio, 0); |
| 1892 | assert!(saved.set_clip_gain(a1, 0, -6.0), "the first clip down 6 dB"); |
| 1893 | assert!(saved.set_clip_gain(a1, 1, 3.0), "the second up 3 dB"); |
| 1894 | assert!( |
| 1895 | !saved.set_clip_gain(Lane::V1, 0, -6.0), |
| 1896 | "a picture has no gain" |
| 1897 | ); |
| 1898 | let path = dir.join("clip_gain.edith"); |
| 1899 | saved.save_project(&path).expect("save"); |
| 1900 | |
| 1901 | let text = std::fs::read_to_string(&path).expect("read back"); |
| 1902 | assert!(text.starts_with("edith 30\n"), "written as version 29"); |
| 1903 | assert!(text.contains("clipgain audio 1 0 -6\n"), "{text}"); |
| 1904 | assert!(text.contains("clipgain audio 1 1 3\n"), "{text}"); |
| 1905 | assert_eq!( |
| 1906 | text.matches("clipgain ").count(), |
| 1907 | 2, |
| 1908 | "unity is never written" |
| 1909 | ); |
| 1910 | |
| 1911 | let mut loaded = PlaybackSession::open_project(&path).expect("open the project"); |
| 1912 | assert_eq!(loaded.clip_gain_of(a1, 0), Some(-6.0)); |
| 1913 | assert_eq!(loaded.clip_gain_of(a1, 1), Some(3.0)); |
| 1914 | assert_eq!( |
| 1915 | loaded.clip_gain_of(Lane::V1, 0), |
| 1916 | Some(0.0), |
| 1917 | "a picture is unity" |
| 1918 | ); |
| 1919 | assert!(!loaded.undo(), "a loaded gain is not an undo step"); |
| 1920 | let again = dir.join("again.edith"); |
| 1921 | loaded |
| 1922 | .save_project(&again) |
| 1923 | .expect("save the loaded project"); |
| 1924 | assert_eq!( |
| 1925 | std::fs::read(&path).unwrap(), |
| 1926 | std::fs::read(&again).unwrap(), |
| 1927 | "save -> load -> save is not a fixed point" |
| 1928 | ); |
| 1929 | } |
| 1930 | |
| 1931 | |
| 1932 | |
| 1933 | #[test] |
| 1934 | fn a_gain_envelope_saves_reopens_and_undoes_in_one_step() { |
| 1935 | let dir = scratch("gain_keys"); |
| 1936 | let mut session = PlaybackSession::open(copy_in(&dir, "test_av.mp4")).expect("open"); |
| 1937 | let a1 = Lane::new(LaneKind::Audio, 0); |
| 1938 | let flat = dir.join("flat.edith"); |
| 1939 | session.save_project(&flat).expect("save a flat project"); |
| 1940 | assert!( |
| 1941 | !std::fs::read_to_string(&flat) |
| 1942 | .expect("read") |
| 1943 | .contains("gainkeys"), |
| 1944 | "a clip with no points writes no gainkeys line" |
| 1945 | ); |
| 1946 | |
| 1947 | assert!(session.set_gain_keys( |
| 1948 | a1, |
| 1949 | 0, |
| 1950 | vec![GainKey::new(0, 0.0), GainKey::new(30, -20.0),], |
| 1951 | )); |
| 1952 | assert!(session.add_gain_key(a1, 0, GainKey::new(60, -6.5))); |
| 1953 | let path = dir.join("keys.edith"); |
| 1954 | session.save_project(&path).expect("save"); |
| 1955 | let text = std::fs::read_to_string(&path).expect("read back"); |
| 1956 | assert!(text.starts_with("edith 30\n"), "the current version"); |
| 1957 | assert!( |
| 1958 | text.contains("gainkeys audio 1 0 0:0 30:-20 60:-6.5\n"), |
| 1959 | "one line for the clip's points: {text}" |
| 1960 | ); |
| 1961 | |
| 1962 | let reopened = PlaybackSession::open_project(&path).expect("reopen"); |
| 1963 | assert_eq!( |
| 1964 | reopened.gain_keys_of(a1, 0), |
| 1965 | &[ |
| 1966 | GainKey::new(0, 0.0), |
| 1967 | GainKey::new(30, -20.0), |
| 1968 | GainKey::new(60, -6.5), |
| 1969 | ] |
| 1970 | ); |
| 1971 | |
| 1972 | assert!(session.remove_gain_key(a1, 0, 60)); |
| 1973 | assert!(session.undo(), "the removal is one undo"); |
| 1974 | assert_eq!(session.gain_keys_of(a1, 0).len(), 3, "the point is back"); |
| 1975 | } |
| 1976 | |
| 1977 | |
| 1978 | |
| 1979 | #[test] |
| 1980 | fn a_version_27_project_loads_flat_and_refuses_a_gainkeys_line() { |
| 1981 | let dir = scratch("v27_gain_keys"); |
| 1982 | copy_in(&dir, "test_av.mp4"); |
| 1983 | let path = dir.join("old.edith"); |
| 1984 | let text = "edith 27\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ |
| 1985 | video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n\ |
| 1986 | audio 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n\ |
| 1987 | clipgain audio 1 0 -6\n"; |
| 1988 | std::fs::write(&path, text).expect("write a v27 file"); |
| 1989 | let loaded = PlaybackSession::open_project(&path).expect("a v27 project opens"); |
| 1990 | assert!( |
| 1991 | loaded |
| 1992 | .gain_keys_of(Lane::new(LaneKind::Audio, 0), 0) |
| 1993 | .is_empty() |
| 1994 | ); |
| 1995 | assert_eq!( |
| 1996 | loaded.clip_gain_of(Lane::new(LaneKind::Audio, 0), 0), |
| 1997 | Some(-6.0) |
| 1998 | ); |
| 1999 | |
| 2000 | let refused = dir.join("refused.edith"); |
| 2001 | std::fs::write( |
| 2002 | &refused, |
| 2003 | text.replace("clipgain audio 1 0 -6\n", "gainkeys audio 1 0 0:-6\n"), |
| 2004 | ) |
| 2005 | .expect("write"); |
| 2006 | let err = PlaybackSession::open_project(&refused) |
| 2007 | .err() |
| 2008 | .expect("refused"); |
| 2009 | assert!(err.to_string().contains("gainkeys"), "{err}"); |
| 2010 | } |
| 2011 | |
| 2012 | |
| 2013 | |
| 2014 | |
| 2015 | #[test] |
| 2016 | fn the_notes_and_the_still_length_survive_a_save_and_an_open() { |
| 2017 | let dir = scratch("notes"); |
| 2018 | let source = copy_in(&dir, "test_av.mp4"); |
| 2019 | let mut saved = PlaybackSession::open(&source).expect("open the fixture"); |
| 2020 | assert_eq!((saved.notes(), saved.still_secs()), ("", 5.0), "nothing picked yet"); |
| 2021 | let notes = "Cut the intro.\nTitle card: \"Day 2\" \\ tbd\r\n"; |
| 2022 | assert!(saved.set_notes(notes)); |
| 2023 | assert!(!saved.set_notes(notes), "the same text changes nothing"); |
| 2024 | assert!(saved.set_still_secs(2.5)); |
| 2025 | let path = dir.join("notes.edith"); |
| 2026 | saved.save_project(&path).expect("save"); |
| 2027 | |
| 2028 | let mut loaded = PlaybackSession::open_project(&path).expect("open the project"); |
| 2029 | assert_eq!(loaded.notes(), notes); |
| 2030 | assert_eq!(loaded.still_secs(), 2.5); |
| 2031 | assert!(!loaded.undo(), "loaded notes and a loaded still length are not undo steps"); |
| 2032 | let again = dir.join("again.edith"); |
| 2033 | loaded.save_project(&again).expect("save the loaded project"); |
| 2034 | assert_eq!( |
| 2035 | std::fs::read(&path).unwrap(), |
| 2036 | std::fs::read(&again).unwrap(), |
| 2037 | "save -> load -> save is not a fixed point" |
| 2038 | ); |
| 2039 | |
| 2040 | |
| 2041 | assert!(loaded.set_notes("changed")); |
| 2042 | assert!(loaded.undo()); |
| 2043 | assert_eq!(loaded.notes(), notes); |
| 2044 | assert!(loaded.set_still_secs(9.0)); |
| 2045 | assert!(loaded.undo()); |
| 2046 | assert_eq!(loaded.still_secs(), 2.5); |
| 2047 | |
| 2048 | |
| 2049 | assert!(loaded.set_still_secs(10_000.0)); |
| 2050 | assert_eq!(loaded.still_secs(), 600.0); |
| 2051 | |
| 2052 | |
| 2053 | |
| 2054 | let plain = dir.join("plain.edith"); |
| 2055 | PlaybackSession::open(&source) |
| 2056 | .expect("open the fixture") |
| 2057 | .save_project(&plain) |
| 2058 | .expect("save a plain project"); |
| 2059 | let text = std::fs::read_to_string(&plain).expect("read it back"); |
| 2060 | let (_, body) = text.split_once('\n').expect("a header line"); |
| 2061 | let old = dir.join("old.edith"); |
| 2062 | std::fs::write(&old, format!("edith 51\n{body}")).expect("write a v51 project"); |
| 2063 | let older = PlaybackSession::open_project(&old).expect("open the v51 project"); |
| 2064 | assert_eq!((older.notes(), older.still_secs()), ("", 5.0)); |
| 2065 | } |