Merge branch 'worktree-agent-a761fe7ed9039142a'
Browse files at this commit8 changed files +738 -122
- crates/app/src/main.rs +2 -0
- crates/engine/src/edith.rs +299 -63
- crates/engine/src/playback.rs +5 -3
- crates/engine/src/project.rs +375 -42
- crates/engine/tests/audio_export.rs +3 -0
- crates/engine/tests/export.rs +2 -0
- crates/engine/tests/lanes.rs +5 -2
- crates/engine/tests/saveload.rs +47 -12
crates/app/src/main.rsmodified+2 -0
| @@ -3460,6 +3460,7 @@ mod tests { | |||
| 3460 | source, | 3460 | source, |
| 3461 | link: None, | 3461 | link: None, |
| 3462 | eq: None, | 3462 | eq: None, |
| 3463 | + color: None, | ||
| 3463 | } | 3464 | } |
| 3464 | } | 3465 | } |
| 3465 | 3466 | ||
| @@ -3650,6 +3651,7 @@ mod tests { | |||
| 3650 | source: 0, | 3651 | source: 0, |
| 3651 | link: None, | 3652 | link: None, |
| 3652 | eq: None, | 3653 | eq: None, |
| 3654 | + color: None, | ||
| 3653 | }; | 3655 | }; |
| 3654 | assert_eq!(clip.end(), 90); | 3656 | assert_eq!(clip.end(), 90); |
| 3655 | // Cut splits from inside only: neither edge has anything to split off. | 3657 | // Cut splits from inside only: neither edge has anything to split off. |
crates/engine/src/edith.rsmodified+299 -63
| @@ -1,14 +1,15 @@ | |||
| 1 | //! The project file: a line of text per thing, and nothing else. | 1 | //! The project file: a line of text per thing, and nothing else. |
| 2 | //! | 2 | //! |
| 3 | //! ```text | 3 | //! ```text |
| 4 | -//! edith 5 | 4 | +//! edith 6 |
| 5 | //! playhead 90 | 5 | //! playhead 90 |
| 6 | //! source 0 test_av.mp4 | 6 | //! source 0 test_av.mp4 |
| 7 | //! source 1 /elsewhere/test_av2.mp4 | 7 | //! source 1 /elsewhere/test_av2.mp4 |
| 8 | //! eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk | 8 | //! eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk |
| 9 | -//! video 1 0 0 120 0 0 0 | 9 | +//! color 0.1:1.2:0.9:-0.3 |
| 10 | -//! audio 1 0 0 120 0 0 0 | 10 | +//! video 1 0 0 120 0 0 0 0 |
| 11 | -//! video 2 120 0 120 1 - - | 11 | +//! audio 1 0 0 120 0 0 0 - |
| 12 | +//! video 2 120 0 120 1 - - - | ||
| 12 | //! audio 2 | 13 | //! audio 2 |
| 13 | //! ``` | 14 | //! ``` |
| 14 | //! | 15 | //! |
| @@ -26,29 +27,35 @@ | |||
| 26 | //! setting like any other. The numbers are printed to round trip bit-exactly; | 27 | //! setting like any other. The numbers are printed to round trip bit-exactly; |
| 27 | //! anything not finite is refused, here and at [`crate::Project::set_eq`]. | 28 | //! anything not finite is refused, here and at [`crate::Project::set_eq`]. |
| 28 | //! | 29 | //! |
| 29 | -//! A lane line is `<kind> <lane> <start> <in> <out> <source> <link> <eq>`: | 30 | +//! A colour line is `color <brightness>:<contrast>:<saturation>:<tint>` |
| 30 | -//! which lane the clip is on -- its kind and its 1-based number among the lanes | 31 | +//! ([`crate::color::ColorParams`]), named by position exactly as an eq line is |
| 31 | -//! of that kind, the [`crate::project::Lane::label`] a header column shows -- | 32 | +//! -- the first colour line is color 0 -- printed and refused by the same rules. |
| 32 | -//! then where the clip sits on the timeline, the half-open source range it | 33 | +//! |
| 33 | -//! plays, the file it plays from, its group id, and the eq line it plays | 34 | +//! A lane line is `<kind> <lane> <start> <in> <out> <source> <link> <eq> |
| 34 | -//! through (`-` for neither). Timeline placement is explicit, so a *gap* is | 35 | +//! <color>`: which lane the clip is on -- its kind and its 1-based number among |
| 35 | -//! simply a stretch no line covers -- there is nothing to write for one, and | 36 | +//! the lanes of that kind, the [`crate::project::Lane::label`] a header column |
| 36 | -//! nothing that can disagree about its length. | 37 | +//! shows -- then where the clip sits on the timeline, the half-open source range |
| 38 | +//! it plays, the file it plays from, its group id, the eq line it plays through | ||
| 39 | +//! and the colour line it is graded by (`-` for none of them). Timeline | ||
| 40 | +//! placement is explicit, so a *gap* is simply a stretch no line covers -- there | ||
| 41 | +//! is nothing to write for one, and nothing that can disagree about its length. | ||
| 37 | //! | 42 | //! |
| 38 | //! A lane is declared by the clips on it, in the order the lanes are displayed | 43 | //! A lane is declared by the clips on it, in the order the lanes are displayed |
| 39 | //! in; a lane holding *nothing* has a bare `<kind> <lane>` line instead, which | 44 | //! in; a lane holding *nothing* has a bare `<kind> <lane>` line instead, which |
| 40 | //! is the only way an empty lane could still be there on the way back. A lane | 45 | //! is the only way an empty lane could still be there on the way back. A lane |
| 41 | //! number may not skip one of its kind. | 46 | //! number may not skip one of its kind. |
| 42 | //! | 47 | //! |
| 43 | -//! **Version 4** was this without the eq lines and without the clip's eq field. | 48 | +//! **Version 5** was this without the colour lines and without the clip's colour |
| 44 | -//! **Version 3** was that without the lane number, and held one video lane and | 49 | +//! field. **Version 4** was that without the eq lines and without the clip's eq |
| 45 | -//! one audio lane, no more. **Version 2** wrote `source <path>` as well, which | 50 | +//! field. **Version 3** was that without the lane number, and held one video |
| 46 | -//! is this file's stream 0 -- one per file, whichever audio track came first. | 51 | +//! lane and one audio lane, no more. **Version 2** wrote `source <path>` as |
| 47 | -//! **Version 1** wrote that and one lane, queued end to end: `clip <in> <out> | 52 | +//! well, which is this file's stream 0 -- one per file, whichever audio track |
| 48 | -//! <source>`. All four still load -- a v1 file's clips are laid out | 53 | +//! came first. **Version 1** wrote that and one lane, queued end to end: `clip |
| 54 | +//! <in> <out> <source>`. All five still load -- a v1 file's clips are laid out | ||
| 49 | //! cumulatively and copied onto both lanes as one group each, which is exactly | 55 | //! cumulatively and copied onto both lanes as one group each, which is exactly |
| 50 | -//! what a v1 timeline meant, and an older file simply equalizes nothing -- and | 56 | +//! what a v1 timeline meant, and an older file simply equalizes and grades |
| 51 | -//! saving any of them writes v5. An older reader refuses a newer file by name. | 57 | +//! nothing -- and saving any of them writes v6. An older reader refuses a newer |
| 58 | +//! file by name. | ||
| 52 | //! | 59 | //! |
| 53 | //! Text because an edit list is a few integers and a path, and a path is | 60 | //! Text because an edit list is a few integers and a path, and a path is |
| 54 | //! *bytes* on this platform -- a JSON string would have to lossily decode one. | 61 | //! *bytes* on this platform -- a JSON string would have to lossily decode one. |
| @@ -74,12 +81,14 @@ use std::io::Write; | |||
| 74 | use std::os::unix::ffi::{OsStrExt, OsStringExt}; | 81 | use std::os::unix::ffi::{OsStrExt, OsStringExt}; |
| 75 | use std::path::{Path, PathBuf}; | 82 | use std::path::{Path, PathBuf}; |
| 76 | 83 | ||
| 84 | +use crate::color::ColorParams; | ||
| 77 | use crate::eq::{Band, BandKind, EqParams}; | 85 | use crate::eq::{Band, BandKind, EqParams}; |
| 78 | use crate::project::{Clip, Lane, LaneKind, Source}; | 86 | use crate::project::{Clip, Lane, LaneKind, Source}; |
| 79 | 87 | ||
| 80 | /// What [`save`] writes. Read support goes back to `edith 1`; see the module | 88 | /// What [`save`] writes. Read support goes back to `edith 1`; see the module |
| 81 | /// docs for what those dialects looked like. | 89 | /// docs for what those dialects looked like. |
| 82 | -const MAGIC: &[u8] = b"edith 5"; | 90 | +const MAGIC: &[u8] = b"edith 6"; |
| 91 | +const MAGIC_V5: &[u8] = b"edith 5"; | ||
| 83 | const MAGIC_V4: &[u8] = b"edith 4"; | 92 | const MAGIC_V4: &[u8] = b"edith 4"; |
| 84 | const MAGIC_V3: &[u8] = b"edith 3"; | 93 | const MAGIC_V3: &[u8] = b"edith 3"; |
| 85 | const MAGIC_V2: &[u8] = b"edith 2"; | 94 | const MAGIC_V2: &[u8] = b"edith 2"; |
| @@ -99,16 +108,20 @@ pub struct Document { | |||
| 99 | /// The equalizer table [`Clip::eq`] indexes into, in file order. Empty for | 108 | /// The equalizer table [`Clip::eq`] indexes into, in file order. Empty for |
| 100 | /// every dialect before v5. | 109 | /// every dialect before v5. |
| 101 | pub eq: Vec<EqParams>, | 110 | pub eq: Vec<EqParams>, |
| 111 | + /// The colour table [`Clip::color`] indexes into, in file order. Empty for | ||
| 112 | + /// every dialect before v6. | ||
| 113 | + pub color: Vec<ColorParams>, | ||
| 102 | pub playhead: u32, | 114 | pub playhead: u32, |
| 103 | } | 115 | } |
| 104 | 116 | ||
| 105 | -/// Writes the project to `path`, atomically. `sources` and `eq` should already | 117 | +/// Writes the project to `path`, atomically. `sources`, `eq` and `color` should |
| 106 | -/// be orphan-free ([`crate::Project::without_orphan_sources`]). | 118 | +/// already be orphan-free ([`crate::Project::without_orphan_sources`]). |
| 107 | pub fn save( | 119 | pub fn save( |
| 108 | path: &Path, | 120 | path: &Path, |
| 109 | sources: &[Source], | 121 | sources: &[Source], |
| 110 | lanes: &[(LaneKind, Vec<Clip>)], | 122 | lanes: &[(LaneKind, Vec<Clip>)], |
| 111 | eq: &[EqParams], | 123 | eq: &[EqParams], |
| 124 | + color: &[ColorParams], | ||
| 112 | playhead: u32, | 125 | playhead: u32, |
| 113 | ) -> crate::Result<()> { | 126 | ) -> crate::Result<()> { |
| 114 | let dir = project_dir(path); | 127 | let dir = project_dir(path); |
| @@ -121,7 +134,7 @@ pub fn save( | |||
| 121 | // the second one puts the name itself there. | 134 | // the second one puts the name itself there. |
| 122 | let result = std::fs::File::create(&part) | 135 | let result = std::fs::File::create(&part) |
| 123 | .and_then(|mut f| { | 136 | .and_then(|mut f| { |
| 124 | - f.write_all(&emit(&dir, sources, lanes, eq, playhead))?; | 137 | + f.write_all(&emit(&dir, sources, lanes, eq, color, playhead))?; |
| 125 | f.sync_all() | 138 | f.sync_all() |
| 126 | }) | 139 | }) |
| 127 | .and_then(|()| std::fs::rename(&part, path)) | 140 | .and_then(|()| std::fs::rename(&part, path)) |
| @@ -156,6 +169,7 @@ fn emit( | |||
| 156 | sources: &[Source], | 169 | sources: &[Source], |
| 157 | lanes: &[(LaneKind, Vec<Clip>)], | 170 | lanes: &[(LaneKind, Vec<Clip>)], |
| 158 | eq: &[EqParams], | 171 | eq: &[EqParams], |
| 172 | + color: &[ColorParams], | ||
| 159 | playhead: u32, | 173 | playhead: u32, |
| 160 | ) -> Vec<u8> { | 174 | ) -> Vec<u8> { |
| 161 | let mut out = Vec::new(); | 175 | let mut out = Vec::new(); |
| @@ -186,6 +200,16 @@ fn emit( | |||
| 186 | } | 200 | } |
| 187 | out.push(b'\n'); | 201 | out.push(b'\n'); |
| 188 | } | 202 | } |
| 203 | + // ...and the colour table, for the same reason and by the same rules. | ||
| 204 | + for p in color { | ||
| 205 | + out.extend_from_slice( | ||
| 206 | + format!( | ||
| 207 | + "color {:?}:{:?}:{:?}:{:?}\n", | ||
| 208 | + p.brightness, p.contrast, p.saturation, p.tint | ||
| 209 | + ) | ||
| 210 | + .as_bytes(), | ||
| 211 | + ); | ||
| 212 | + } | ||
| 189 | // Lane by lane rather than interleaved by time: a lane reads as a list, the | 213 | // Lane by lane rather than interleaved by time: a lane reads as a list, the |
| 190 | // parser gets its sortedness check for free from the order it is in, and | 214 | // parser gets its sortedness check for free from the order it is in, and |
| 191 | // the lanes come back out in the order they are displayed in. | 215 | // the lanes come back out in the order they are displayed in. |
| @@ -209,9 +233,10 @@ fn emit( | |||
| 209 | for c in clips { | 233 | for c in clips { |
| 210 | let link = c.link.map_or("-".to_string(), |l| l.to_string()); | 234 | let link = c.link.map_or("-".to_string(), |l| l.to_string()); |
| 211 | let eq = c.eq.map_or("-".to_string(), |e| e.to_string()); | 235 | let eq = c.eq.map_or("-".to_string(), |e| e.to_string()); |
| 236 | + let color = c.color.map_or("-".to_string(), |e| e.to_string()); | ||
| 212 | out.extend_from_slice( | 237 | out.extend_from_slice( |
| 213 | format!( | 238 | format!( |
| 214 | - "{keyword} {ord} {} {} {} {} {link} {eq}\n", | 239 | + "{keyword} {ord} {} {} {} {} {link} {eq} {color}\n", |
| 215 | c.start, c.in_frame, c.out_frame, c.source | 240 | c.start, c.in_frame, c.out_frame, c.source |
| 216 | ) | 241 | ) |
| 217 | .as_bytes(), | 242 | .as_bytes(), |
| @@ -231,8 +256,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | |||
| 231 | // The dialects that wrote a source line without its stream field. Reading | 256 | // The dialects that wrote a source line without its stream field. Reading |
| 232 | // one is the whole of what "an old project still opens" means here. | 257 | // one is the whole of what "an old project still opens" means here. |
| 233 | let streamless = v1 || first == MAGIC_V2; | 258 | let streamless = v1 || first == MAGIC_V2; |
| 234 | - // The one that carries equalizer settings... | 259 | + // The one that carries colour grades... |
| 235 | - let v5 = first == MAGIC; | 260 | + let v6 = first == MAGIC; |
| 261 | + // ...the ones that carry equalizer settings... | ||
| 262 | + let v5 = v6 || first == MAGIC_V5; | ||
| 236 | // ...and the ones that number their lanes. Every older one held two. | 263 | // ...and the ones that number their lanes. Every older one held two. |
| 237 | let numbered = v5 || first == MAGIC_V4; | 264 | let numbered = v5 || first == MAGIC_V4; |
| 238 | if !numbered && !streamless && first != MAGIC_V3 { | 265 | if !numbered && !streamless && first != MAGIC_V3 { |
| @@ -252,8 +279,9 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | |||
| 252 | } else { | 279 | } else { |
| 253 | vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, Vec::new())] | 280 | vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, Vec::new())] |
| 254 | }, | 281 | }, |
| 255 | - // Nothing before v5 equalizes anything. | 282 | + // Nothing before v5 equalizes anything, and nothing before v6 grades. |
| 256 | eq: Vec::new(), | 283 | eq: Vec::new(), |
| 284 | + color: Vec::new(), | ||
| 257 | playhead: 0, | 285 | playhead: 0, |
| 258 | }; | 286 | }; |
| 259 | let mut playhead_seen = false; | 287 | let mut playhead_seen = false; |
| @@ -324,6 +352,24 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | |||
| 324 | }; | 352 | }; |
| 325 | doc.eq.push(EqParams { bands }); | 353 | doc.eq.push(EqParams { bands }); |
| 326 | } | 354 | } |
| 355 | + b"color" if v6 => { | ||
| 356 | + if doc.lanes.iter().any(|(_, clips)| !clips.is_empty()) { | ||
| 357 | + return Err(format!("line {n}: color after a clip").into()); | ||
| 358 | + } | ||
| 359 | + let f = fields(rest, 1, "color", n)?; | ||
| 360 | + let parts: Vec<&[u8]> = f[0].split(|&b| b == b':').collect(); | ||
| 361 | + if parts.len() != 4 { | ||
| 362 | + return Err( | ||
| 363 | + format!("line {n}: color wants 4 fields, found {}", parts.len()).into(), | ||
| 364 | + ); | ||
| 365 | + } | ||
| 366 | + doc.color.push(ColorParams { | ||
| 367 | + brightness: float(parts[0], n)?, | ||
| 368 | + contrast: float(parts[1], n)?, | ||
| 369 | + saturation: float(parts[2], n)?, | ||
| 370 | + tint: float(parts[3], n)?, | ||
| 371 | + }); | ||
| 372 | + } | ||
| 327 | // v1: one lane, no placement, no groups. Every clip becomes one | 373 | // v1: one lane, no placement, no groups. Every clip becomes one |
| 328 | // grouped video+audio pair laid where the queue reached, which is | 374 | // grouped video+audio pair laid where the queue reached, which is |
| 329 | // what the file always meant. | 375 | // what the file always meant. |
| @@ -337,6 +383,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | |||
| 337 | source: number(f[2], n)? as usize, | 383 | source: number(f[2], n)? as usize, |
| 338 | link: Some(doc.lanes[0].1.len() as u32), | 384 | link: Some(doc.lanes[0].1.len() as u32), |
| 339 | eq: None, | 385 | eq: None, |
| 386 | + color: None, | ||
| 340 | }, | 387 | }, |
| 341 | &doc, | 388 | &doc, |
| 342 | n, | 389 | n, |
| @@ -366,8 +413,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | |||
| 366 | if numbered && rest.is_empty() { | 413 | if numbered && rest.is_empty() { |
| 367 | continue; | 414 | continue; |
| 368 | } | 415 | } |
| 369 | - // v5 grew the eq field; every older dialect ends at the link. | 416 | + // v6 grew the colour field and v5 the eq one; every older |
| 370 | - let f = fields(rest, if v5 { 6 } else { 5 }, "clip", n)?; | 417 | + // dialect ends at the link. |
| 418 | + let want = 5 + usize::from(v5) + usize::from(v6); | ||
| 419 | + let f = fields(rest, want, "clip", n)?; | ||
| 371 | let clip = check( | 420 | let clip = check( |
| 372 | Clip { | 421 | Clip { |
| 373 | start: number(f[0], n)?, | 422 | start: number(f[0], n)?, |
| @@ -378,20 +427,8 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | |||
| 378 | b"-" => None, | 427 | b"-" => None, |
| 379 | field => Some(number(field, n)?), | 428 | field => Some(number(field, n)?), |
| 380 | }, | 429 | }, |
| 381 | - eq: match f.get(5).copied() { | 430 | + eq: table_index(f.get(5).copied(), doc.eq.len(), "eq", n)?, |
| 382 | - None | Some(b"-") => None, | 431 | + color: table_index(f.get(6).copied(), doc.color.len(), "color", n)?, |
| 383 | - Some(field) => { | ||
| 384 | - let i = number(field, n)?; | ||
| 385 | - if i as usize >= doc.eq.len() || i > u32::from(u16::MAX) { | ||
| 386 | - return Err(format!( | ||
| 387 | - "line {n}: clip names eq {i} of {}", | ||
| 388 | - doc.eq.len() | ||
| 389 | - ) | ||
| 390 | - .into()); | ||
| 391 | - } | ||
| 392 | - Some(i as u16) | ||
| 393 | - } | ||
| 394 | - }, | ||
| 395 | }, | 432 | }, |
| 396 | &doc, | 433 | &doc, |
| 397 | n, | 434 | n, |
| @@ -507,6 +544,26 @@ fn check(clip: Clip, doc: &Document, line: usize) -> crate::Result<Clip> { | |||
| 507 | Ok(clip) | 544 | Ok(clip) |
| 508 | } | 545 | } |
| 509 | 546 | ||
| 547 | +/// A clip's `<eq>` or `<color>` field: `-` (or a dialect that has no such field | ||
| 548 | +/// at all), or a line of a table that is already declared. Refused by the name | ||
| 549 | +/// of what it points at, so the message reads as the file does. | ||
| 550 | +fn table_index( | ||
| 551 | + field: Option<&[u8]>, | ||
| 552 | + len: usize, | ||
| 553 | + what: &str, | ||
| 554 | + line: usize, | ||
| 555 | +) -> crate::Result<Option<u16>> { | ||
| 556 | + let field = match field { | ||
| 557 | + None | Some(b"-") => return Ok(None), | ||
| 558 | + Some(field) => field, | ||
| 559 | + }; | ||
| 560 | + let i = number(field, line)?; | ||
| 561 | + if i as usize >= len || i > u32::from(u16::MAX) { | ||
| 562 | + return Err(format!("line {line}: clip names {what} {i} of {len}").into()); | ||
| 563 | + } | ||
| 564 | + Ok(Some(i as u16)) | ||
| 565 | +} | ||
| 566 | + | ||
| 510 | /// One `<frequency>:<gain>:<Q>:<shape>` field of an eq line. | 567 | /// One `<frequency>:<gain>:<Q>:<shape>` field of an eq line. |
| 511 | fn band(field: &[u8], line: usize) -> crate::Result<Band> { | 568 | fn band(field: &[u8], line: usize) -> crate::Result<Band> { |
| 512 | let parts: Vec<&[u8]> = field.split(|&b| b == b':').collect(); | 569 | let parts: Vec<&[u8]> = field.split(|&b| b == b':').collect(); |
| @@ -609,6 +666,7 @@ mod tests { | |||
| 609 | source, | 666 | source, |
| 610 | link, | 667 | link, |
| 611 | eq: None, | 668 | eq: None, |
| 669 | + color: None, | ||
| 612 | } | 670 | } |
| 613 | } | 671 | } |
| 614 | 672 | ||
| @@ -620,7 +678,7 @@ mod tests { | |||
| 620 | lanes: &[(LaneKind, Vec<Clip>)], | 678 | lanes: &[(LaneKind, Vec<Clip>)], |
| 621 | playhead: u32, | 679 | playhead: u32, |
| 622 | ) -> Vec<u8> { | 680 | ) -> Vec<u8> { |
| 623 | - emit(dir, sources, lanes, &[], playhead) | 681 | + emit(dir, sources, lanes, &[], &[], playhead) |
| 624 | } | 682 | } |
| 625 | 683 | ||
| 626 | /// Two sources, one under the project's own directory and one not, a clip | 684 | /// Two sources, one under the project's own directory and one not, a clip |
| @@ -658,8 +716,8 @@ mod tests { | |||
| 658 | let bytes = flat(&dir, &sources, &lanes, 12); | 716 | let bytes = flat(&dir, &sources, &lanes, 12); |
| 659 | assert_eq!( | 717 | assert_eq!( |
| 660 | String::from_utf8_lossy(&bytes), | 718 | String::from_utf8_lossy(&bytes), |
| 661 | - "edith 5\nplayhead 12\nsource 0 a.mp4\nsource 2 /elsewhere/b.mp4\n\ | 719 | + "edith 6\nplayhead 12\nsource 0 a.mp4\nsource 2 /elsewhere/b.mp4\n\ |
| 662 | - video 1 0 0 30 0 0 -\nvideo 1 30 10 20 1 1 -\naudio 1 0 0 30 0 0 -\n", | 720 | + video 1 0 0 30 0 0 - -\nvideo 1 30 10 20 1 1 - -\naudio 1 0 0 30 0 0 - -\n", |
| 663 | "the file under the project directory is written relative to it, \ | 721 | "the file under the project directory is written relative to it, \ |
| 664 | each with the audio stream it plays" | 722 | each with the audio stream it plays" |
| 665 | ); | 723 | ); |
| @@ -693,8 +751,8 @@ mod tests { | |||
| 693 | let bytes = flat(&dir, &sources, &lanes, 7); | 751 | let bytes = flat(&dir, &sources, &lanes, 7); |
| 694 | assert_eq!( | 752 | assert_eq!( |
| 695 | String::from_utf8_lossy(&bytes), | 753 | String::from_utf8_lossy(&bytes), |
| 696 | - "edith 5\nplayhead 7\nsource 0 a.mp4\n\ | 754 | + "edith 6\nplayhead 7\nsource 0 a.mp4\n\ |
| 697 | - video 1 0 0 30 0 4 -\naudio 1\nvideo 2 40 0 10 0 - -\naudio 2 0 0 30 0 4 -\n", | 755 | + video 1 0 0 30 0 4 - -\naudio 1\nvideo 2 40 0 10 0 - - -\naudio 2 0 0 30 0 4 - -\n", |
| 698 | "an empty lane is a line of its own; everything else is its clips" | 756 | "an empty lane is a line of its own; everything else is its clips" |
| 699 | ); | 757 | ); |
| 700 | let back = parse(&bytes, &dir).expect("parse"); | 758 | let back = parse(&bytes, &dir).expect("parse"); |
| @@ -800,15 +858,15 @@ mod tests { | |||
| 800 | }, | 858 | }, |
| 801 | ], | 859 | ], |
| 802 | ); | 860 | ); |
| 803 | - let bytes = emit(&dir, &sources, &lanes, &eq, 0); | 861 | + let bytes = emit(&dir, &sources, &lanes, &eq, &[], 0); |
| 804 | assert_eq!( | 862 | assert_eq!( |
| 805 | String::from_utf8_lossy(&bytes), | 863 | String::from_utf8_lossy(&bytes), |
| 806 | - "edith 5\nplayhead 0\nsource 0 a.mp4\n\ | 864 | + "edith 6\nplayhead 0\nsource 0 a.mp4\n\ |
| 807 | eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ | 865 | eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ |
| 808 | eq 16777215.0:-0.1:3.918315e-39:hs\n\ | 866 | eq 16777215.0:-0.1:3.918315e-39:hs\n\ |
| 809 | eq\n\ | 867 | eq\n\ |
| 810 | - video 1 0 0 30 0 0 0\nvideo 1 30 10 20 0 - 1\n\ | 868 | + video 1 0 0 30 0 0 0 -\nvideo 1 30 10 20 0 - 1 -\n\ |
| 811 | - audio 1 0 0 30 0 0 0\naudio 1 30 0 10 0 - 2\n", | 869 | + audio 1 0 0 30 0 0 0 -\naudio 1 30 0 10 0 - 2 -\n", |
| 812 | "the table comes before the clips, and a clip names a line of it" | 870 | "the table comes before the clips, and a clip names a line of it" |
| 813 | ); | 871 | ); |
| 814 | 872 | ||
| @@ -834,7 +892,177 @@ mod tests { | |||
| 834 | } | 892 | } |
| 835 | } | 893 | } |
| 836 | assert_eq!(back.eq.len(), 3, "the empty cascade is an entry of its own"); | 894 | assert_eq!(back.eq.len(), 3, "the empty cascade is an entry of its own"); |
| 837 | - assert_eq!(emit(&dir, &back.sources, &back.lanes, &back.eq, 0), bytes); | 895 | + assert_eq!( |
| 896 | + emit(&dir, &back.sources, &back.lanes, &back.eq, &back.color, 0), | ||
| 897 | + bytes | ||
| 898 | + ); | ||
| 899 | + } | ||
| 900 | + | ||
| 901 | + /// The whole of the v6 bump, the eq test's twin: the clips name a shared | ||
| 902 | + /// colour table, the bytes are the ones documented at the top of this file, | ||
| 903 | + /// and every f32 comes back *bit* for bit, so a re-save is the same file. | ||
| 904 | + #[test] | ||
| 905 | + fn colours_round_trip_bit_exactly_and_are_shared() { | ||
| 906 | + let dir = PathBuf::from("/proj"); | ||
| 907 | + let sources = vec![source("/proj/a.mp4", 0)]; | ||
| 908 | + let color = vec![ | ||
| 909 | + ColorParams { | ||
| 910 | + brightness: 0.1, | ||
| 911 | + contrast: 1.2, | ||
| 912 | + saturation: 0.9, | ||
| 913 | + tint: -0.3, | ||
| 914 | + }, | ||
| 915 | + // The awkward ones again: all 24 mantissa bits, an exponential | ||
| 916 | + // spelling, a subnormal and a negative zero -- and the identity, | ||
| 917 | + // which is a setting like any other. | ||
| 918 | + ColorParams { | ||
| 919 | + brightness: -0.000_000_1, | ||
| 920 | + contrast: 16_777_215.0, | ||
| 921 | + saturation: f32::MIN_POSITIVE / 3.0, | ||
| 922 | + tint: -0.0, | ||
| 923 | + }, | ||
| 924 | + ColorParams::default(), | ||
| 925 | + ]; | ||
| 926 | + // Two clips share entry 0, so it is written once; one clip is ungraded. | ||
| 927 | + let lanes = two( | ||
| 928 | + vec![ | ||
| 929 | + Clip { | ||
| 930 | + color: Some(0), | ||
| 931 | + ..clip(0, 0, 30, 0, Some(0)) | ||
| 932 | + }, | ||
| 933 | + Clip { | ||
| 934 | + color: Some(1), | ||
| 935 | + ..clip(30, 10, 20, 0, None) | ||
| 936 | + }, | ||
| 937 | + ], | ||
| 938 | + vec![ | ||
| 939 | + Clip { | ||
| 940 | + color: Some(0), | ||
| 941 | + ..clip(0, 0, 30, 0, Some(0)) | ||
| 942 | + }, | ||
| 943 | + Clip { | ||
| 944 | + color: Some(2), | ||
| 945 | + ..clip(30, 0, 10, 0, None) | ||
| 946 | + }, | ||
| 947 | + ], | ||
| 948 | + ); | ||
| 949 | + let bytes = emit(&dir, &sources, &lanes, &[], &color, 0); | ||
| 950 | + assert_eq!( | ||
| 951 | + String::from_utf8_lossy(&bytes), | ||
| 952 | + "edith 6\nplayhead 0\nsource 0 a.mp4\n\ | ||
| 953 | + color 0.1:1.2:0.9:-0.3\n\ | ||
| 954 | + color -1e-7:16777215.0:3.918315e-39:-0.0\n\ | ||
| 955 | + color 0.0:1.0:1.0:0.0\n\ | ||
| 956 | + video 1 0 0 30 0 0 - 0\nvideo 1 30 10 20 0 - - 1\n\ | ||
| 957 | + audio 1 0 0 30 0 0 - 0\naudio 1 30 0 10 0 - - 2\n", | ||
| 958 | + "the table comes before the clips, and a clip names a line of it" | ||
| 959 | + ); | ||
| 960 | + | ||
| 961 | + let back = parse(&bytes, &dir).expect("parse"); | ||
| 962 | + assert_eq!(back.lanes, lanes, "every clip keeps the colour it named"); | ||
| 963 | + for (i, (got, want)) in back.color.iter().zip(&color).enumerate() { | ||
| 964 | + assert_eq!( | ||
| 965 | + ( | ||
| 966 | + got.brightness.to_bits(), | ||
| 967 | + got.contrast.to_bits(), | ||
| 968 | + got.saturation.to_bits(), | ||
| 969 | + got.tint.to_bits() | ||
| 970 | + ), | ||
| 971 | + ( | ||
| 972 | + want.brightness.to_bits(), | ||
| 973 | + want.contrast.to_bits(), | ||
| 974 | + want.saturation.to_bits(), | ||
| 975 | + want.tint.to_bits() | ||
| 976 | + ), | ||
| 977 | + "color {i} came back as other bits" | ||
| 978 | + ); | ||
| 979 | + } | ||
| 980 | + assert_eq!(back.color.len(), 3); | ||
| 981 | + assert_eq!( | ||
| 982 | + emit(&dir, &back.sources, &back.lanes, &back.eq, &back.color, 0), | ||
| 983 | + bytes | ||
| 984 | + ); | ||
| 985 | + } | ||
| 986 | + | ||
| 987 | + /// A v5 file is a v6 one that grades nothing: it loads with its equalizers | ||
| 988 | + /// intact, and re-saving it writes the new magic and a `-` colour field. | ||
| 989 | + #[test] | ||
| 990 | + fn a_v5_file_grades_nothing() { | ||
| 991 | + let dir = PathBuf::from("/proj"); | ||
| 992 | + let v5 = b"edith 5\nplayhead 3\nsource 0 a.mp4\neq 80.0:-3.0:0.707:ls\n\ | ||
| 993 | + video 1 0 0 30 0 0 0\naudio 1 0 0 30 0 0 -\n"; | ||
| 994 | + let old = parse(v5, &dir).expect("v5 parses"); | ||
| 995 | + assert!(old.color.is_empty(), "nothing before v6 grades anything"); | ||
| 996 | + assert_eq!(old.eq.len(), 1, "...and its equalizers are untouched"); | ||
| 997 | + assert_eq!(old.lanes[0].1[0].eq, Some(0)); | ||
| 998 | + assert!(old.lanes[0].1[0].color.is_none()); | ||
| 999 | + assert_eq!( | ||
| 1000 | + String::from_utf8_lossy(&emit( | ||
| 1001 | + &dir, | ||
| 1002 | + &old.sources, | ||
| 1003 | + &old.lanes, | ||
| 1004 | + &old.eq, | ||
| 1005 | + &old.color, | ||
| 1006 | + old.playhead | ||
| 1007 | + )), | ||
| 1008 | + "edith 6\nplayhead 3\nsource 0 a.mp4\neq 80.0:-3.0:0.707:ls\n\ | ||
| 1009 | + video 1 0 0 30 0 0 0 -\naudio 1 0 0 30 0 0 - -\n" | ||
| 1010 | + ); | ||
| 1011 | + } | ||
| 1012 | + | ||
| 1013 | + /// The refusals the colour grammar adds, each naming its line. | ||
| 1014 | + #[test] | ||
| 1015 | + fn a_malformed_colour_names_its_line() { | ||
| 1016 | + let dir = PathBuf::from("/proj"); | ||
| 1017 | + let head = "edith 6\nsource 0 a.mp4\n"; | ||
| 1018 | + for (file, want) in [ | ||
| 1019 | + ( | ||
| 1020 | + format!("{head}color 0.0:1.0:1.0\nvideo 1 0 0 5 0 - - 0\n"), | ||
| 1021 | + "line 3: color wants 4 fields, found 3", | ||
| 1022 | + ), | ||
| 1023 | + ( | ||
| 1024 | + format!("{head}color 0.0:1.0:1.0:0.0 0.0:1.0:1.0:0.0\nvideo 1 0 0 5 0 - - 0\n"), | ||
| 1025 | + "line 3: color wants 1 fields, found 2", | ||
| 1026 | + ), | ||
| 1027 | + ( | ||
| 1028 | + format!("{head}color 0.0:warm:1.0:0.0\nvideo 1 0 0 5 0 - - 0\n"), | ||
| 1029 | + "line 3: \"warm\" is not a number", | ||
| 1030 | + ), | ||
| 1031 | + // The two values the format cannot write and read back as itself. | ||
| 1032 | + ( | ||
| 1033 | + format!("{head}color inf:1.0:1.0:0.0\nvideo 1 0 0 5 0 - - 0\n"), | ||
| 1034 | + "line 3: \"inf\" is not a number", | ||
| 1035 | + ), | ||
| 1036 | + ( | ||
| 1037 | + format!("{head}color 0.0:1.0:1.0:NaN\nvideo 1 0 0 5 0 - - 0\n"), | ||
| 1038 | + "line 3: \"NaN\" is not a number", | ||
| 1039 | + ), | ||
| 1040 | + ( | ||
| 1041 | + format!("{head}color 0.0:1.0:1.0:0.0\nvideo 1 0 0 5 0 - - 1\n"), | ||
| 1042 | + "line 4: clip names color 1 of 1", | ||
| 1043 | + ), | ||
| 1044 | + ( | ||
| 1045 | + format!("{head}video 1 0 0 5 0 - - 0\n"), | ||
| 1046 | + "line 3: clip names color 0 of 0", | ||
| 1047 | + ), | ||
| 1048 | + // A clip's colour field is not optional in v6, and the table has to | ||
| 1049 | + // be declared before the clip that names it. | ||
| 1050 | + ( | ||
| 1051 | + format!("{head}video 1 0 0 5 0 - -\n"), | ||
| 1052 | + "line 3: clip wants 7 fields, found 6", | ||
| 1053 | + ), | ||
| 1054 | + ( | ||
| 1055 | + format!("{head}video 1 0 0 5 0 - - -\ncolor 0.0:1.0:1.0:0.0\n"), | ||
| 1056 | + "line 4: color after a clip", | ||
| 1057 | + ), | ||
| 1058 | + // ...and a colour line in a file that predates them is a corrupt one. | ||
| 1059 | + ( | ||
| 1060 | + "edith 5\nsource 0 a.mp4\ncolor 0.0:1.0:1.0:0.0\nvideo 1 0 0 5 0 - -\n".to_string(), | ||
| 1061 | + "line 3: unknown keyword \"color\"", | ||
| 1062 | + ), | ||
| 1063 | + ] { | ||
| 1064 | + assert_eq!(parse(file.as_bytes(), &dir).unwrap_err().to_string(), want); | ||
| 1065 | + } | ||
| 838 | } | 1066 | } |
| 839 | 1067 | ||
| 840 | /// The refusals the eq grammar adds, each naming its line. | 1068 | /// The refusals the eq grammar adds, each naming its line. |
| @@ -910,8 +1138,8 @@ mod tests { | |||
| 910 | assert!(old.eq.is_empty(), "nothing before v5 equalizes anything"); | 1138 | assert!(old.eq.is_empty(), "nothing before v5 equalizes anything"); |
| 911 | assert_eq!( | 1139 | assert_eq!( |
| 912 | String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)), | 1140 | String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)), |
| 913 | - "edith 5\nplayhead 12\nsource 0 a.mp4\nsource 2 /elsewhere/b.mp4\n\ | 1141 | + "edith 6\nplayhead 12\nsource 0 a.mp4\nsource 2 /elsewhere/b.mp4\n\ |
| 914 | - video 1 0 0 30 0 0 -\nvideo 1 30 10 20 1 1 -\naudio 1 0 0 30 0 0 -\n" | 1142 | + video 1 0 0 30 0 0 - -\nvideo 1 30 10 20 1 1 - -\naudio 1 0 0 30 0 0 - -\n" |
| 915 | ); | 1143 | ); |
| 916 | // An empty lane's line is still the whole of that lane, eq or no eq. | 1144 | // An empty lane's line is still the whole of that lane, eq or no eq. |
| 917 | let empty = parse( | 1145 | let empty = parse( |
| @@ -961,8 +1189,8 @@ mod tests { | |||
| 961 | let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); | 1189 | let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); |
| 962 | assert_eq!( | 1190 | assert_eq!( |
| 963 | String::from_utf8_lossy(&v5), | 1191 | String::from_utf8_lossy(&v5), |
| 964 | - "edith 5\nplayhead 12\nsource 0 a.mp4\nsource 0 /elsewhere/b.mp4\n\ | 1192 | + "edith 6\nplayhead 12\nsource 0 a.mp4\nsource 0 /elsewhere/b.mp4\n\ |
| 965 | - video 1 0 0 30 0 0 -\nvideo 1 30 10 20 1 1 -\naudio 1 0 0 30 0 0 -\n", | 1193 | + video 1 0 0 30 0 0 - -\nvideo 1 30 10 20 1 1 - -\naudio 1 0 0 30 0 0 - -\n", |
| 966 | "a re-saved v2 project differs only by its version, the lane \ | 1194 | "a re-saved v2 project differs only by its version, the lane \ |
| 967 | numbers, the streams it always meant and an equalizer it has none of" | 1195 | numbers, the streams it always meant and an equalizer it has none of" |
| 968 | ); | 1196 | ); |
| @@ -990,7 +1218,7 @@ mod tests { | |||
| 990 | assert_eq!(back.playhead, 5); | 1218 | assert_eq!(back.playhead, 5); |
| 991 | // Saved again it is v5, and that round-trips to the same document. | 1219 | // Saved again it is v5, and that round-trips to the same document. |
| 992 | let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); | 1220 | let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); |
| 993 | - assert!(v5.starts_with(b"edith 5\n")); | 1221 | + assert!(v5.starts_with(b"edith 6\n")); |
| 994 | let again = parse(&v5, &dir).expect("v5 parses"); | 1222 | let again = parse(&v5, &dir).expect("v5 parses"); |
| 995 | assert_eq!(again.lanes, back.lanes); | 1223 | assert_eq!(again.lanes, back.lanes); |
| 996 | // A dialect may not be mixed: lane lines under v1, `clip` under v2. | 1224 | // A dialect may not be mixed: lane lines under v1, `clip` under v2. |
| @@ -1079,11 +1307,19 @@ mod tests { | |||
| 1079 | path: source, | 1307 | path: source, |
| 1080 | audio_stream: 1, | 1308 | audio_stream: 1, |
| 1081 | }; | 1309 | }; |
| 1082 | - save(&path, &[entry], &two(one.to_vec(), one.to_vec()), &[], 0).expect("save"); | 1310 | + save( |
| 1311 | + &path, | ||
| 1312 | + &[entry], | ||
| 1313 | + &two(one.to_vec(), one.to_vec()), | ||
| 1314 | + &[], | ||
| 1315 | + &[], | ||
| 1316 | + 0, | ||
| 1317 | + ) | ||
| 1318 | + .expect("save"); | ||
| 1083 | let bytes = std::fs::read(&path).expect("read back"); | 1319 | let bytes = std::fs::read(&path).expect("read back"); |
| 1084 | assert_eq!( | 1320 | assert_eq!( |
| 1085 | String::from_utf8_lossy(&bytes), | 1321 | String::from_utf8_lossy(&bytes), |
| 1086 | - "edith 5\nplayhead 0\nsource 1 a.mp4\nvideo 1 0 0 30 0 - -\naudio 1 0 0 30 0 - -\n" | 1322 | + "edith 6\nplayhead 0\nsource 1 a.mp4\nvideo 1 0 0 30 0 - - -\naudio 1 0 0 30 0 - - -\n" |
| 1087 | ); | 1323 | ); |
| 1088 | // Loading rejoins the *given* directory, so the file is reached by the | 1324 | // Loading rejoins the *given* directory, so the file is reached by the |
| 1089 | // way the project was opened -- the same file, through the link, still | 1325 | // way the project was opened -- the same file, through the link, still |
| @@ -1127,10 +1363,10 @@ mod tests { | |||
| 1127 | #[test] | 1363 | #[test] |
| 1128 | fn a_wrong_first_line_is_refused_by_name() { | 1364 | fn a_wrong_first_line_is_refused_by_name() { |
| 1129 | let dir = PathBuf::from("/proj"); | 1365 | let dir = PathBuf::from("/proj"); |
| 1130 | - let err = parse(b"edith 6\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir) | 1366 | + let err = parse(b"edith 7\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir) |
| 1131 | .unwrap_err() | 1367 | .unwrap_err() |
| 1132 | .to_string(); | 1368 | .to_string(); |
| 1133 | - assert_eq!(err, "line 1: unsupported version 6"); | 1369 | + assert_eq!(err, "line 1: unsupported version 7"); |
| 1134 | for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] { | 1370 | for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] { |
| 1135 | assert_eq!( | 1371 | assert_eq!( |
| 1136 | parse(junk, &dir).unwrap_err().to_string(), | 1372 | parse(junk, &dir).unwrap_err().to_string(), |
crates/engine/src/playback.rsmodified+5 -3
| @@ -246,7 +246,7 @@ impl PlaybackSession { | |||
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | let playhead = doc.playhead; | 248 | let playhead = doc.playhead; |
| 249 | - let project = Project::from_parts(doc.sources, doc.lanes, doc.eq)?; | 249 | + let project = Project::from_parts(doc.sources, doc.lanes, doc.eq, doc.color)?; |
| 250 | let span = project.composite_span_at(0).expect("never empty"); | 250 | let span = project.composite_span_at(0).expect("never empty"); |
| 251 | // Last, because it is the one thing here that cannot be taken back: the | 251 | // Last, because it is the one thing here that cannot be taken back: the |
| 252 | // feeder thread outlives the `Audio` value (it holds its own clones) and | 252 | // feeder thread outlives the `Audio` value (it holds its own clones) and |
| @@ -300,10 +300,10 @@ impl PlaybackSession { | |||
| 300 | /// [`crate::edith`]). Sources no clip plays from are left out, and the | 300 | /// [`crate::edith`]). Sources no clip plays from are left out, and the |
| 301 | /// playhead is saved with it so a reopened project resumes where it stood. | 301 | /// playhead is saved with it so a reopened project resumes where it stood. |
| 302 | pub fn save_project(&self, path: &Path) -> crate::Result<()> { | 302 | pub fn save_project(&self, path: &Path) -> crate::Result<()> { |
| 303 | - let (sources, lanes, eq) = self.project.without_orphan_sources(); | 303 | + let (sources, lanes, eq, color) = self.project.without_orphan_sources(); |
| 304 | let playhead = secs_to_frame(self.now(), self.meta.frame_rate) | 304 | let playhead = secs_to_frame(self.now(), self.meta.frame_rate) |
| 305 | .min(self.project.timeline_frames().saturating_sub(1)); | 305 | .min(self.project.timeline_frames().saturating_sub(1)); |
| 306 | - crate::edith::save(path, &sources, &lanes, &eq, playhead) | 306 | + crate::edith::save(path, &sources, &lanes, &eq, &color, playhead) |
| 307 | } | 307 | } |
| 308 | 308 | ||
| 309 | /// The next decoded frame, its `index` rewritten from a source frame to a | 309 | /// The next decoded frame, its `index` rewritten from a source frame to a |
| @@ -538,6 +538,7 @@ impl PlaybackSession { | |||
| 538 | source, | 538 | source, |
| 539 | link: None, | 539 | link: None, |
| 540 | eq: None, | 540 | eq: None, |
| 541 | + color: None, | ||
| 541 | }; | 542 | }; |
| 542 | // Which lane a source may land on is decided here and only here, so a | 543 | // Which lane a source may land on is decided here and only here, so a |
| 543 | // front-end never has to make the same call twice: a file with no | 544 | // front-end never has to make the same call twice: a file with no |
| @@ -645,6 +646,7 @@ impl PlaybackSession { | |||
| 645 | source, | 646 | source, |
| 646 | link: None, | 647 | link: None, |
| 647 | eq: None, | 648 | eq: None, |
| 649 | + color: None, | ||
| 648 | }, | 650 | }, |
| 649 | ); | 651 | ); |
| 650 | // Same reason as a video import: the running audio worker's segment | 652 | // Same reason as a video import: the running audio worker's segment |
crates/engine/src/project.rsmodified+375 -42
| @@ -55,9 +55,16 @@ | |||
| 55 | //! index the clip had. Only a *save* prunes the table | 55 | //! index the clip had. Only a *save* prunes the table |
| 56 | //! ([`Project::without_orphan_sources`]), for the reason an undone import | 56 | //! ([`Project::without_orphan_sources`]), for the reason an undone import |
| 57 | //! leaves its source entry behind: an index handed out is an index forever. | 57 | //! leaves its source entry behind: an index handed out is an index forever. |
| 58 | +//! | ||
| 59 | +//! Its colour grade is a third such table ([`Clip::color`], | ||
| 60 | +//! [`Project::set_color`]) and behaves in every way like the equalizer one -- | ||
| 61 | +//! shared by equal settings, inherited by both halves of a split, pruned only at | ||
| 62 | +//! a save. An index rather than the four floats themselves for the same reason: | ||
| 63 | +//! twenty clips graded alike name one entry, and the file writes it once. | ||
| 58 | 64 | ||
| 59 | use std::path::{Path, PathBuf}; | 65 | use std::path::{Path, PathBuf}; |
| 60 | 66 | ||
| 67 | +use crate::color::ColorParams; | ||
| 61 | use crate::eq::EqParams; | 68 | use crate::eq::EqParams; |
| 62 | 69 | ||
| 63 | /// A half-open `[in_frame, out_frame)` range of frames of source | 70 | /// A half-open `[in_frame, out_frame)` range of frames of source |
| @@ -83,6 +90,11 @@ pub struct Clip { | |||
| 83 | /// plain assignment. The table is append-only within a session, so an index | 90 | /// plain assignment. The table is append-only within a session, so an index |
| 84 | /// on a clipboard clip or inside an undo snapshot can never dangle. | 91 | /// on a clipboard clip or inside an undo snapshot can never dangle. |
| 85 | pub eq: Option<u16>, | 92 | pub eq: Option<u16>, |
| 93 | + /// Index into the project's colour table | ||
| 94 | + /// ([`Project::color_of`]/[`Project::set_color`]), or `None` for a clip that | ||
| 95 | + /// plays ungraded. An index for [`Clip::eq`]'s reason, and with the same | ||
| 96 | + /// promises: `Copy`, append-only within a session, never dangling. | ||
| 97 | + pub color: Option<u16>, | ||
| 86 | } | 98 | } |
| 87 | 99 | ||
| 88 | impl Clip { | 100 | impl Clip { |
| @@ -214,9 +226,15 @@ impl Span { | |||
| 214 | } | 226 | } |
| 215 | 227 | ||
| 216 | /// What a save writes and a load takes back: the sources, every lane in | 228 | /// What a save writes and a load takes back: the sources, every lane in |
| 217 | -/// display order with its kind, and the equalizer table their clips index into | 229 | +/// display order with its kind, and the equalizer and colour tables their clips |
| 218 | -/// -- [`Project::without_orphan_sources`] out, [`Project::from_parts`] in. | 230 | +/// index into -- [`Project::without_orphan_sources`] out, |
| 219 | -pub type Parts = (Vec<Source>, Vec<(LaneKind, Vec<Clip>)>, Vec<EqParams>); | 231 | +/// [`Project::from_parts`] in. |
| 232 | +pub type Parts = ( | ||
| 233 | + Vec<Source>, | ||
| 234 | + Vec<(LaneKind, Vec<Clip>)>, | ||
| 235 | + Vec<EqParams>, | ||
| 236 | + Vec<ColorParams>, | ||
| 237 | +); | ||
| 220 | 238 | ||
| 221 | /// The edit list plus its undo history. | 239 | /// The edit list plus its undo history. |
| 222 | #[derive(Clone, Debug)] | 240 | #[derive(Clone, Debug)] |
| @@ -228,6 +246,8 @@ pub struct Project { | |||
| 228 | lanes: Vec<LaneData>, | 246 | lanes: Vec<LaneData>, |
| 229 | /// Append-only, exactly as `sources` is: what [`Clip::eq`] indexes into. | 247 | /// Append-only, exactly as `sources` is: what [`Clip::eq`] indexes into. |
| 230 | eq: Vec<EqParams>, | 248 | eq: Vec<EqParams>, |
| 249 | + /// The same, for [`Clip::color`]. | ||
| 250 | + color: Vec<ColorParams>, | ||
| 231 | /// Snapshots pushed *before* each successful edit; `undo` pops one. The | 251 | /// Snapshots pushed *before* each successful edit; `undo` pops one. The |
| 232 | /// whole lane list, so adding a lane undoes as well. | 252 | /// whole lane list, so adding a lane undoes as well. |
| 233 | history: Vec<Vec<LaneData>>, | 253 | history: Vec<Vec<LaneData>>, |
| @@ -249,6 +269,7 @@ impl Project { | |||
| 249 | source: 0, | 269 | source: 0, |
| 250 | link: Some(0), | 270 | link: Some(0), |
| 251 | eq: None, | 271 | eq: None, |
| 272 | + color: None, | ||
| 252 | }; | 273 | }; |
| 253 | Self { | 274 | Self { |
| 254 | // A file is opened on its first audio stream: nothing has picked | 275 | // A file is opened on its first audio stream: nothing has picked |
| @@ -256,6 +277,7 @@ impl Project { | |||
| 256 | sources: vec![Source::new(path, 0)], | 277 | sources: vec![Source::new(path, 0)], |
| 257 | lanes: LaneData::two_lanes(vec![clip], vec![clip]), | 278 | lanes: LaneData::two_lanes(vec![clip], vec![clip]), |
| 258 | eq: Vec::new(), | 279 | eq: Vec::new(), |
| 280 | + color: Vec::new(), | ||
| 259 | history: Vec::new(), | 281 | history: Vec::new(), |
| 260 | next_link: 1, | 282 | next_link: 1, |
| 261 | } | 283 | } |
| @@ -268,17 +290,22 @@ impl Project { | |||
| 268 | /// [`Project::undo`] is `false` until the first edit of the new session. | 290 | /// [`Project::undo`] is `false` until the first edit of the new session. |
| 269 | /// This is the one door untrusted parts come in through, so every invariant | 291 | /// This is the one door untrusted parts come in through, so every invariant |
| 270 | /// every other constructor keeps is checked here, by name and in release: | 292 | /// every other constructor keeps is checked here, by name and in release: |
| 271 | - /// every lane empty, an empty clip, a clip naming a source (or an equalizer) | 293 | + /// every lane empty, an empty clip, a clip naming a source (or an equalizer, |
| 272 | - /// that is not there, a clip whose end overflows, a lane that is unsorted or | 294 | + /// or a colour) that is not there, a clip whose end overflows, a lane that is |
| 273 | - /// self-overlapping, and the grouping rules of [`Clip::link`] below. | 295 | + /// unsorted or self-overlapping, and the grouping rules of [`Clip::link`] |
| 296 | + /// below. | ||
| 274 | pub fn from_parts( | 297 | pub fn from_parts( |
| 275 | sources: Vec<Source>, | 298 | sources: Vec<Source>, |
| 276 | lanes: Vec<(LaneKind, Vec<Clip>)>, | 299 | lanes: Vec<(LaneKind, Vec<Clip>)>, |
| 277 | eq: Vec<EqParams>, | 300 | eq: Vec<EqParams>, |
| 301 | + color: Vec<ColorParams>, | ||
| 278 | ) -> crate::Result<Self> { | 302 | ) -> crate::Result<Self> { |
| 279 | if let Some(bad) = eq.iter().position(|p| !finite(p)) { | 303 | if let Some(bad) = eq.iter().position(|p| !finite(p)) { |
| 280 | return Err(format!("eq {bad} holds a band that is not a finite number").into()); | 304 | return Err(format!("eq {bad} holds a band that is not a finite number").into()); |
| 281 | } | 305 | } |
| 306 | + if let Some(bad) = color.iter().position(|p| !color_finite(p)) { | ||
| 307 | + return Err(format!("color {bad} holds a value that is not a finite number").into()); | ||
| 308 | + } | ||
| 282 | if lanes.iter().all(|(_, clips)| clips.is_empty()) { | 309 | if lanes.iter().all(|(_, clips)| clips.is_empty()) { |
| 283 | return Err("every lane is empty: that is not a project".into()); | 310 | return Err("every lane is empty: that is not a project".into()); |
| 284 | } | 311 | } |
| @@ -321,6 +348,15 @@ impl Project { | |||
| 321 | ) | 348 | ) |
| 322 | .into()); | 349 | .into()); |
| 323 | } | 350 | } |
| 351 | + if c.color.is_some_and(|i| usize::from(i) >= color.len()) { | ||
| 352 | + return Err(format!( | ||
| 353 | + "{name} clip at {} names color {} of {}", | ||
| 354 | + c.start, | ||
| 355 | + c.color.unwrap_or_default(), | ||
| 356 | + color.len() | ||
| 357 | + ) | ||
| 358 | + .into()); | ||
| 359 | + } | ||
| 324 | } | 360 | } |
| 325 | if !sorted_disjoint(&data.clips) { | 361 | if !sorted_disjoint(&data.clips) { |
| 326 | return Err(format!("the {name} lane is out of order or overlaps itself").into()); | 362 | return Err(format!("the {name} lane is out of order or overlaps itself").into()); |
| @@ -342,6 +378,7 @@ impl Project { | |||
| 342 | .collect(), | 378 | .collect(), |
| 343 | lanes, | 379 | lanes, |
| 344 | eq, | 380 | eq, |
| 381 | + color, | ||
| 345 | history: Vec::new(), | 382 | history: Vec::new(), |
| 346 | next_link, | 383 | next_link, |
| 347 | }) | 384 | }) |
| @@ -453,6 +490,7 @@ impl Project { | |||
| 453 | source, | 490 | source, |
| 454 | link: Some(self.new_link()), | 491 | link: Some(self.new_link()), |
| 455 | eq: None, | 492 | eq: None, |
| 493 | + color: None, | ||
| 456 | }; | 494 | }; |
| 457 | for data in &mut self.lanes { | 495 | for data in &mut self.lanes { |
| 458 | data.clips.push(clip); | 496 | data.clips.push(clip); |
| @@ -469,11 +507,12 @@ impl Project { | |||
| 469 | /// emits the same bytes. | 507 | /// emits the same bytes. |
| 470 | /// | 508 | /// |
| 471 | /// Every lane comes out, in display order and with its kind: that is what a | 509 | /// Every lane comes out, in display order and with its kind: that is what a |
| 472 | - /// v5 `.edith` holds (empty lanes included) and what [`Project::from_parts`] | 510 | + /// v6 `.edith` holds (empty lanes included) and what [`Project::from_parts`] |
| 473 | /// takes back. | 511 | /// takes back. |
| 474 | /// | 512 | /// |
| 475 | - /// The equalizer table is pruned the same way and for the same reason: an | 513 | + /// The equalizer and colour tables are pruned the same way and for the same |
| 476 | - /// undone [`set_eq`](Project::set_eq) leaves settings nothing plays behind, | 514 | + /// reason: an undone [`set_eq`](Project::set_eq) or |
| 515 | + /// [`set_color`](Project::set_color) leaves settings nothing plays behind, | ||
| 477 | /// and this is the one moment they can go -- the indexes that survive it are | 516 | /// and this is the one moment they can go -- the indexes that survive it are |
| 478 | /// only the ones a clip names. | 517 | /// only the ones a clip names. |
| 479 | pub fn without_orphan_sources(&self) -> Parts { | 518 | pub fn without_orphan_sources(&self) -> Parts { |
| @@ -481,6 +520,8 @@ impl Project { | |||
| 481 | let mut sources = Vec::new(); | 520 | let mut sources = Vec::new(); |
| 482 | let mut moved_eq = vec![None; self.eq.len()]; | 521 | let mut moved_eq = vec![None; self.eq.len()]; |
| 483 | let mut eq = Vec::new(); | 522 | let mut eq = Vec::new(); |
| 523 | + let mut moved_color = vec![None; self.color.len()]; | ||
| 524 | + let mut color = Vec::new(); | ||
| 484 | let mut lanes = self.lanes.clone(); | 525 | let mut lanes = self.lanes.clone(); |
| 485 | for c in lanes.iter_mut().flat_map(|l| &mut l.clips) { | 526 | for c in lanes.iter_mut().flat_map(|l| &mut l.clips) { |
| 486 | let old = c.source; | 527 | let old = c.source; |
| @@ -503,11 +544,23 @@ impl Project { | |||
| 503 | } | 544 | } |
| 504 | }); | 545 | }); |
| 505 | } | 546 | } |
| 547 | + if let Some(old) = c.color.map(usize::from) { | ||
| 548 | + c.color = Some(match moved_color[old] { | ||
| 549 | + Some(new) => new, | ||
| 550 | + None => { | ||
| 551 | + color.push(self.color[old]); | ||
| 552 | + let new = (color.len() - 1) as u16; | ||
| 553 | + moved_color[old] = Some(new); | ||
| 554 | + new | ||
| 555 | + } | ||
| 556 | + }); | ||
| 557 | + } | ||
| 506 | } | 558 | } |
| 507 | ( | 559 | ( |
| 508 | sources, | 560 | sources, |
| 509 | lanes.into_iter().map(|l| (l.kind, l.clips)).collect(), | 561 | lanes.into_iter().map(|l| (l.kind, l.clips)).collect(), |
| 510 | eq, | 562 | eq, |
| 563 | + color, | ||
| 511 | ) | 564 | ) |
| 512 | } | 565 | } |
| 513 | 566 | ||
| @@ -557,6 +610,46 @@ impl Project { | |||
| 557 | true | 610 | true |
| 558 | } | 611 | } |
| 559 | 612 | ||
| 613 | + /// How the clip at `idx` of `lane` is graded, or `None` for one that plays | ||
| 614 | + /// ungraded (and for an index that is not there) -- what the renderer and | ||
| 615 | + /// the export ask before they call [`crate::color::apply_yuv`]. | ||
| 616 | + pub fn color_of(&self, lane: Lane, idx: usize) -> Option<&ColorParams> { | ||
| 617 | + self.color | ||
| 618 | + .get(usize::from(self.lane(lane).get(idx)?.color?)) | ||
| 619 | + } | ||
| 620 | + | ||
| 621 | + /// Give the clip at `idx` of `lane` this colour grade, or `None` to take it | ||
| 622 | + /// off. [`Project::set_eq`]'s twin in every respect: one undo step, `false` | ||
| 623 | + /// (and no history) for an index that is not there or a value that is not | ||
| 624 | + /// finite, and equal settings share a table entry. | ||
| 625 | + pub fn set_color(&mut self, lane: Lane, idx: usize, params: Option<ColorParams>) -> bool { | ||
| 626 | + if idx >= self.lane(lane).len() { | ||
| 627 | + return false; | ||
| 628 | + } | ||
| 629 | + let slot = match params { | ||
| 630 | + None => None, | ||
| 631 | + Some(params) => { | ||
| 632 | + if !color_finite(¶ms) { | ||
| 633 | + return false; | ||
| 634 | + } | ||
| 635 | + Some(match self.color.iter().position(|p| *p == params) { | ||
| 636 | + Some(at) => at as u16, | ||
| 637 | + // ponytail: the 65535th *distinct* grade of one session is | ||
| 638 | + // refused rather than silently aliased, exactly as `set_eq` | ||
| 639 | + // refuses the 65535th curve; same upgrade path. | ||
| 640 | + None if self.color.len() >= usize::from(u16::MAX) => return false, | ||
| 641 | + None => { | ||
| 642 | + self.color.push(params); | ||
| 643 | + (self.color.len() - 1) as u16 | ||
| 644 | + } | ||
| 645 | + }) | ||
| 646 | + } | ||
| 647 | + }; | ||
| 648 | + self.snapshot(); | ||
| 649 | + self.lane_mut(lane).expect("checked above")[idx].color = slot; | ||
| 650 | + true | ||
| 651 | + } | ||
| 652 | + | ||
| 560 | /// Length of the timeline in frames: where the *last* lane runs out. A lane | 653 | /// Length of the timeline in frames: where the *last* lane runs out. A lane |
| 561 | /// that ends early is a trailing gap in that lane, not a shorter timeline. | 654 | /// that ends early is a trailing gap in that lane, not a shorter timeline. |
| 562 | pub fn timeline_frames(&self) -> u32 { | 655 | pub fn timeline_frames(&self) -> u32 { |
| @@ -1085,6 +1178,16 @@ fn finite(params: &EqParams) -> bool { | |||
| 1085 | .all(|b| b.freq_hz.is_finite() && b.gain_db.is_finite() && b.q.is_finite()) | 1178 | .all(|b| b.freq_hz.is_finite() && b.gain_db.is_finite() && b.q.is_finite()) |
| 1086 | } | 1179 | } |
| 1087 | 1180 | ||
| 1181 | +/// The same for a colour grade: [`crate::color`] itself falls back to identity | ||
| 1182 | +/// on a non-finite value, but a value that cannot be written and read back as | ||
| 1183 | +/// itself has no business reaching the model. | ||
| 1184 | +fn color_finite(p: &ColorParams) -> bool { | ||
| 1185 | + p.brightness.is_finite() | ||
| 1186 | + && p.contrast.is_finite() | ||
| 1187 | + && p.saturation.is_finite() | ||
| 1188 | + && p.tint.is_finite() | ||
| 1189 | +} | ||
| 1190 | + | ||
| 1088 | fn sorted_disjoint(clips: &[Clip]) -> bool { | 1191 | fn sorted_disjoint(clips: &[Clip]) -> bool { |
| 1089 | clips.iter().all(|c| c.out_frame > c.in_frame) | 1192 | clips.iter().all(|c| c.out_frame > c.in_frame) |
| 1090 | && clips.windows(2).all(|w| w[0].end() <= w[1].start) | 1193 | && clips.windows(2).all(|w| w[0].end() <= w[1].start) |
| @@ -1222,6 +1325,7 @@ mod tests { | |||
| 1222 | source, | 1325 | source, |
| 1223 | link: None, | 1326 | link: None, |
| 1224 | eq: None, | 1327 | eq: None, |
| 1328 | + color: None, | ||
| 1225 | } | 1329 | } |
| 1226 | } | 1330 | } |
| 1227 | 1331 | ||
| @@ -1238,6 +1342,15 @@ mod tests { | |||
| 1238 | } | 1342 | } |
| 1239 | } | 1343 | } |
| 1240 | 1344 | ||
| 1345 | + /// A recognisable colour grade, `n` telling two of them apart -- [`band_at`] | ||
| 1346 | + /// for the colour table. | ||
| 1347 | + fn grade_at(n: u32) -> ColorParams { | ||
| 1348 | + ColorParams { | ||
| 1349 | + brightness: f64::from(n) as f32 * 0.05, | ||
| 1350 | + ..Default::default() | ||
| 1351 | + } | ||
| 1352 | + } | ||
| 1353 | + | ||
| 1241 | /// The `V1`, `A1` lane list a two-lane load hands [`Project::from_parts`]. | 1354 | /// The `V1`, `A1` lane list a two-lane load hands [`Project::from_parts`]. |
| 1242 | fn two(video: Vec<Clip>, audio: Vec<Clip>) -> Vec<(LaneKind, Vec<Clip>)> { | 1355 | fn two(video: Vec<Clip>, audio: Vec<Clip>) -> Vec<(LaneKind, Vec<Clip>)> { |
| 1243 | vec![(LaneKind::Video, video), (LaneKind::Audio, audio)] | 1356 | vec![(LaneKind::Video, video), (LaneKind::Audio, audio)] |
| @@ -1416,6 +1529,7 @@ mod tests { | |||
| 1416 | source: 0, | 1529 | source: 0, |
| 1417 | link: None, | 1530 | link: None, |
| 1418 | eq: None, | 1531 | eq: None, |
| 1532 | + color: None, | ||
| 1419 | }; | 1533 | }; |
| 1420 | 1534 | ||
| 1421 | #[test] | 1535 | #[test] |
| @@ -1833,9 +1947,10 @@ mod tests { | |||
| 1833 | // Import a second file, undo it: source 1 is now an orphan. | 1947 | // Import a second file, undo it: source 1 is now an orphan. |
| 1834 | let mut p = two_sources(); | 1948 | let mut p = two_sources(); |
| 1835 | assert!(p.undo()); | 1949 | assert!(p.undo()); |
| 1836 | - let (sources, lanes, eq) = p.without_orphan_sources(); | 1950 | + let (sources, lanes, eq, color) = p.without_orphan_sources(); |
| 1837 | assert_eq!(sources, vec![Source::new(FILE, 0)], "the orphan is gone"); | 1951 | assert_eq!(sources, vec![Source::new(FILE, 0)], "the orphan is gone"); |
| 1838 | assert!(eq.is_empty(), "and a project with no equalizer writes none"); | 1952 | assert!(eq.is_empty(), "and a project with no equalizer writes none"); |
| 1953 | + assert!(color.is_empty(), "nor a colour it never graded with"); | ||
| 1839 | assert_eq!( | 1954 | assert_eq!( |
| 1840 | lanes, | 1955 | lanes, |
| 1841 | two(three().clips().to_vec(), three().lane(Lane::A1).to_vec()), | 1956 | two(three().clips().to_vec(), three().lane(Lane::A1).to_vec()), |
| @@ -1848,7 +1963,7 @@ mod tests { | |||
| 1848 | assert_eq!(p.import(FILE2, 0), 1); | 1963 | assert_eq!(p.import(FILE2, 0), 1); |
| 1849 | assert_eq!(p.import("/nonexistent/c.mp4", 0), 2); | 1964 | assert_eq!(p.import("/nonexistent/c.mp4", 0), 2); |
| 1850 | assert!(p.append_clip(2, 4)); | 1965 | assert!(p.append_clip(2, 4)); |
| 1851 | - let (sources, lanes, eq) = p.without_orphan_sources(); | 1966 | + let (sources, lanes, eq, color) = p.without_orphan_sources(); |
| 1852 | assert_eq!( | 1967 | assert_eq!( |
| 1853 | sources, | 1968 | sources, |
| 1854 | vec![Source::new(FILE, 0), Source::new("/nonexistent/c.mp4", 0)] | 1969 | vec![Source::new(FILE, 0), Source::new("/nonexistent/c.mp4", 0)] |
| @@ -1858,7 +1973,7 @@ mod tests { | |||
| 1858 | [0, 1] | 1973 | [0, 1] |
| 1859 | ); | 1974 | ); |
| 1860 | // ...and what comes out is loadable, with the same timeline. | 1975 | // ...and what comes out is loadable, with the same timeline. |
| 1861 | - let reloaded = Project::from_parts(sources, lanes, eq).expect("from_parts"); | 1976 | + let reloaded = Project::from_parts(sources, lanes, eq, color).expect("from_parts"); |
| 1862 | assert_eq!(reloaded.timeline_frames(), p.timeline_frames()); | 1977 | assert_eq!(reloaded.timeline_frames(), p.timeline_frames()); |
| 1863 | assert_eq!(reloaded.sources().len(), 2); | 1978 | assert_eq!(reloaded.sources().len(), 2); |
| 1864 | } | 1979 | } |
| @@ -1928,7 +2043,7 @@ mod tests { | |||
| 1928 | assert!(p.undo(), "back to the first setting"); | 2043 | assert!(p.undo(), "back to the first setting"); |
| 1929 | assert_eq!(p.eq_of(Lane::V1, 0), Some(&band_at(1))); | 2044 | assert_eq!(p.eq_of(Lane::V1, 0), Some(&band_at(1))); |
| 1930 | 2045 | ||
| 1931 | - let (_, lanes, eq) = p.without_orphan_sources(); | 2046 | + let (_, lanes, eq, _) = p.without_orphan_sources(); |
| 1932 | assert_eq!(eq, vec![band_at(1)], "what nothing plays is not written"); | 2047 | assert_eq!(eq, vec![band_at(1)], "what nothing plays is not written"); |
| 1933 | assert_eq!(lanes[0].1[0].eq, Some(0), "and the survivor renumbers"); | 2048 | assert_eq!(lanes[0].1[0].eq, Some(0), "and the survivor renumbers"); |
| 1934 | assert_eq!(lanes[0].1[1].eq, None); | 2049 | assert_eq!(lanes[0].1[1].eq, None); |
| @@ -1936,18 +2051,138 @@ mod tests { | |||
| 1936 | // One curve on three clips is one entry: settings that are equal share. | 2051 | // One curve on three clips is one entry: settings that are equal share. |
| 1937 | assert!(p.set_eq(Lane::V1, 1, Some(band_at(1)))); | 2052 | assert!(p.set_eq(Lane::V1, 1, Some(band_at(1)))); |
| 1938 | assert!(p.set_eq(Lane::A1, 2, Some(band_at(1)))); | 2053 | assert!(p.set_eq(Lane::A1, 2, Some(band_at(1)))); |
| 1939 | - let (_, lanes, eq) = p.without_orphan_sources(); | 2054 | + let (_, lanes, eq, _) = p.without_orphan_sources(); |
| 1940 | assert_eq!(eq.len(), 1, "equal settings share their entry"); | 2055 | assert_eq!(eq.len(), 1, "equal settings share their entry"); |
| 1941 | assert_eq!(lanes[1].1[2].eq, Some(0)); | 2056 | assert_eq!(lanes[1].1[2].eq, Some(0)); |
| 1942 | reloads(&p, "an equalizer that outlived an undo"); | 2057 | reloads(&p, "an equalizer that outlived an undo"); |
| 1943 | } | 2058 | } |
| 1944 | 2059 | ||
| 2060 | + /// [`an_equalizer_follows_the_clip_through_split_copy_and_undo`]'s twin: a | ||
| 2061 | + /// grade is the clip's, through every edit that copies a placement. | ||
| 2062 | + #[test] | ||
| 2063 | + fn a_colour_follows_the_clip_through_split_copy_and_undo() { | ||
| 2064 | + let mut p = three(); | ||
| 2065 | + assert!( | ||
| 2066 | + p.color_of(Lane::V1, 0).is_none(), | ||
| 2067 | + "a fresh clip is ungraded" | ||
| 2068 | + ); | ||
| 2069 | + assert!(p.set_color(Lane::V1, 0, Some(grade_at(2)))); | ||
| 2070 | + assert_eq!(p.color_of(Lane::V1, 0), Some(&grade_at(2))); | ||
| 2071 | + assert!( | ||
| 2072 | + p.color_of(Lane::A1, 0).is_none(), | ||
| 2073 | + "one clip, not the lane below" | ||
| 2074 | + ); | ||
| 2075 | + assert!( | ||
| 2076 | + p.eq_of(Lane::V1, 0).is_none(), | ||
| 2077 | + "and a grade is not an equalizer" | ||
| 2078 | + ); | ||
| 2079 | + | ||
| 2080 | + // Cutting a graded clip must not grade half of it: both halves inherit. | ||
| 2081 | + assert!(p.split(1)); | ||
| 2082 | + assert_eq!(p.color_of(Lane::V1, 0), Some(&grade_at(2))); | ||
| 2083 | + assert_eq!(p.color_of(Lane::V1, 1), Some(&grade_at(2))); | ||
| 2084 | + assert!( | ||
| 2085 | + p.color_of(Lane::V1, 2).is_none(), | ||
| 2086 | + "the clip after it is ungraded" | ||
| 2087 | + ); | ||
| 2088 | + | ||
| 2089 | + // A clipboard copy carries it -- onto another lane, at that. | ||
| 2090 | + let copied = p.lane(Lane::V1)[1]; | ||
| 2091 | + assert!(p.place(Lane::A1, 20, copied)); | ||
| 2092 | + assert_eq!(p.color_of(Lane::A1, 4), Some(&grade_at(2))); | ||
| 2093 | + assert!(p.undo()); | ||
| 2094 | + assert_eq!(p.lane(Lane::A1).len(), 4, "the placement came back off"); | ||
| 2095 | + | ||
| 2096 | + // ...and a change to one is one undo step, in both directions. | ||
| 2097 | + assert!(p.set_color(Lane::V1, 0, Some(grade_at(5)))); | ||
| 2098 | + assert_eq!(p.color_of(Lane::V1, 0), Some(&grade_at(5))); | ||
| 2099 | + assert!(p.undo()); | ||
| 2100 | + assert_eq!(p.color_of(Lane::V1, 0), Some(&grade_at(2))); | ||
| 2101 | + assert!( | ||
| 2102 | + p.set_color(Lane::V1, 0, None), | ||
| 2103 | + "and taking it off is an edit" | ||
| 2104 | + ); | ||
| 2105 | + assert!(p.color_of(Lane::V1, 0).is_none()); | ||
| 2106 | + assert!(p.undo()); | ||
| 2107 | + assert_eq!(p.color_of(Lane::V1, 0), Some(&grade_at(2))); | ||
| 2108 | + | ||
| 2109 | + // Two refusals, neither of which costs an undo step. | ||
| 2110 | + let nan = ColorParams { | ||
| 2111 | + contrast: f32::NAN, | ||
| 2112 | + ..grade_at(1) | ||
| 2113 | + }; | ||
| 2114 | + assert!( | ||
| 2115 | + !p.set_color(Lane::V1, 99, Some(grade_at(1))), | ||
| 2116 | + "no clip there" | ||
| 2117 | + ); | ||
| 2118 | + assert!(!p.set_color(Lane::V1, 0, Some(nan)), "not a finite value"); | ||
| 2119 | + assert_eq!(p.color_of(Lane::V1, 0), Some(&grade_at(2))); | ||
| 2120 | + assert!(p.undo()); | ||
| 2121 | + assert_eq!( | ||
| 2122 | + p.lane(Lane::V1).len(), | ||
| 2123 | + 3, | ||
| 2124 | + "one step back is before the split" | ||
| 2125 | + ); | ||
| 2126 | + assert!(p.undo()); | ||
| 2127 | + assert!( | ||
| 2128 | + p.color_of(Lane::V1, 0).is_none(), | ||
| 2129 | + "and the next is before the grade: the refusals pushed none" | ||
| 2130 | + ); | ||
| 2131 | + } | ||
| 2132 | + | ||
| 2133 | + /// The colour table is append-only within a session, exactly as the eq one | ||
| 2134 | + /// is -- and a save is where an undone grade goes. | ||
| 2135 | + #[test] | ||
| 2136 | + fn an_undone_colour_is_pruned_when_the_project_is_saved() { | ||
| 2137 | + let mut p = three(); | ||
| 2138 | + assert!(p.set_color(Lane::V1, 0, Some(grade_at(1)))); | ||
| 2139 | + assert!(p.set_color(Lane::V1, 0, Some(grade_at(2)))); | ||
| 2140 | + assert!(p.undo(), "back to the first grade"); | ||
| 2141 | + assert_eq!(p.color_of(Lane::V1, 0), Some(&grade_at(1))); | ||
| 2142 | + | ||
| 2143 | + let (_, lanes, _, color) = p.without_orphan_sources(); | ||
| 2144 | + assert_eq!( | ||
| 2145 | + color, | ||
| 2146 | + vec![grade_at(1)], | ||
| 2147 | + "what nothing plays is not written" | ||
| 2148 | + ); | ||
| 2149 | + assert_eq!(lanes[0].1[0].color, Some(0), "and the survivor renumbers"); | ||
| 2150 | + assert_eq!(lanes[0].1[1].color, None); | ||
| 2151 | + | ||
| 2152 | + // One grade on three clips is one entry: settings that are equal share. | ||
| 2153 | + assert!(p.set_color(Lane::V1, 1, Some(grade_at(1)))); | ||
| 2154 | + assert!(p.set_color(Lane::A1, 2, Some(grade_at(1)))); | ||
| 2155 | + let (_, lanes, _, color) = p.without_orphan_sources(); | ||
| 2156 | + assert_eq!(color.len(), 1, "equal grades share their entry"); | ||
| 2157 | + assert_eq!(lanes[1].1[2].color, Some(0)); | ||
| 2158 | + reloads(&p, "a colour that outlived an undo"); | ||
| 2159 | + | ||
| 2160 | + // An equalizer and a grade on one clip are two independent tables. | ||
| 2161 | + assert!(p.set_eq(Lane::V1, 0, Some(band_at(3)))); | ||
| 2162 | + let (_, lanes, eq, color) = p.without_orphan_sources(); | ||
| 2163 | + assert_eq!((eq.len(), color.len()), (1, 1)); | ||
| 2164 | + assert_eq!((lanes[0].1[0].eq, lanes[0].1[0].color), (Some(0), Some(0))); | ||
| 2165 | + } | ||
| 2166 | + | ||
| 2167 | + /// Not a claim about correctness but about cost: a clip is copied on every | ||
| 2168 | + /// paste, every undo snapshot and every lane clone, so its size is worth | ||
| 2169 | + /// knowing. The eq index fit the padding a `Copy` clip already had; the | ||
| 2170 | + /// colour one did not, and the struct grew a word. | ||
| 2171 | + #[test] | ||
| 2172 | + fn a_clip_is_still_a_small_copy() { | ||
| 2173 | + assert_eq!( | ||
| 2174 | + std::mem::size_of::<Clip>(), | ||
| 2175 | + 40, | ||
| 2176 | + "Clip changed size -- 32 before the colour index, 40 after" | ||
| 2177 | + ); | ||
| 2178 | + } | ||
| 2179 | + | ||
| 1945 | #[test] | 2180 | #[test] |
| 1946 | fn from_parts_has_no_history_and_checks_the_invariants() { | 2181 | fn from_parts_has_no_history_and_checks_the_invariants() { |
| 1947 | - let (sources, lanes, eq) = three().without_orphan_sources(); | 2182 | + let (sources, lanes, eq, color) = three().without_orphan_sources(); |
| 1948 | let (video, audio) = (lanes[0].1.clone(), lanes[1].1.clone()); | 2183 | let (video, audio) = (lanes[0].1.clone(), lanes[1].1.clone()); |
| 1949 | - let mut p = | 2184 | + let mut p = Project::from_parts(sources.clone(), lanes.clone(), eq.clone(), color.clone()) |
| 1950 | - Project::from_parts(sources.clone(), lanes.clone(), eq.clone()).expect("valid parts"); | 2185 | + .expect("valid parts"); |
| 1951 | assert_eq!(p.clips(), three().clips()); | 2186 | assert_eq!(p.clips(), three().clips()); |
| 1952 | assert!(!p.undo(), "a loaded project has nothing to undo"); | 2187 | assert!(!p.undo(), "a loaded project has nothing to undo"); |
| 1953 | assert!(p.split(4), "...and is editable from there"); | 2188 | assert!(p.split(4), "...and is editable from there"); |
| @@ -1955,13 +2190,24 @@ mod tests { | |||
| 1955 | 2190 | ||
| 1956 | // A lane may be empty; every lane may not, and neither may no lane. | 2191 | // A lane may be empty; every lane may not, and neither may no lane. |
| 1957 | assert!( | 2192 | assert!( |
| 1958 | - Project::from_parts(sources.clone(), two(video.clone(), Vec::new()), Vec::new()) | 2193 | + Project::from_parts( |
| 1959 | - .is_ok() | 2194 | + sources.clone(), |
| 2195 | + two(video.clone(), Vec::new()), | ||
| 2196 | + Vec::new(), | ||
| 2197 | + Vec::new(), | ||
| 2198 | + ) | ||
| 2199 | + .is_ok() | ||
| 1960 | ); | 2200 | ); |
| 1961 | assert!( | 2201 | assert!( |
| 1962 | - Project::from_parts(sources.clone(), two(Vec::new(), Vec::new()), Vec::new()).is_err() | 2202 | + Project::from_parts( |
| 2203 | + sources.clone(), | ||
| 2204 | + two(Vec::new(), Vec::new()), | ||
| 2205 | + Vec::new(), | ||
| 2206 | + Vec::new(), | ||
| 2207 | + ) | ||
| 2208 | + .is_err() | ||
| 1963 | ); | 2209 | ); |
| 1964 | - assert!(Project::from_parts(sources.clone(), Vec::new(), Vec::new()).is_err()); | 2210 | + assert!(Project::from_parts(sources.clone(), Vec::new(), Vec::new(), Vec::new()).is_err()); |
| 1965 | let bad: [Vec<Clip>; 5] = [ | 2211 | let bad: [Vec<Clip>; 5] = [ |
| 1966 | vec![clip(0, 0, 3, 1)], // source that is not there | 2212 | vec![clip(0, 0, 3, 1)], // source that is not there |
| 1967 | vec![clip(0, 3, 3, 0)], // empty clip | 2213 | vec![clip(0, 3, 3, 0)], // empty clip |
| @@ -1971,15 +2217,21 @@ mod tests { | |||
| 1971 | ]; | 2217 | ]; |
| 1972 | for clips in bad { | 2218 | for clips in bad { |
| 1973 | assert!( | 2219 | assert!( |
| 1974 | - Project::from_parts(sources.clone(), two(clips.clone(), Vec::new()), Vec::new()) | 2220 | + Project::from_parts( |
| 1975 | - .is_err(), | 2221 | + sources.clone(), |
| 2222 | + two(clips.clone(), Vec::new()), | ||
| 2223 | + Vec::new(), | ||
| 2224 | + Vec::new(), | ||
| 2225 | + ) | ||
| 2226 | + .is_err(), | ||
| 1976 | "{clips:?}" | 2227 | "{clips:?}" |
| 1977 | ); | 2228 | ); |
| 1978 | assert!( | 2229 | assert!( |
| 1979 | Project::from_parts( | 2230 | Project::from_parts( |
| 1980 | sources.clone(), | 2231 | sources.clone(), |
| 1981 | two(video.clone(), clips.clone()), | 2232 | two(video.clone(), clips.clone()), |
| 1982 | - Vec::new() | 2233 | + Vec::new(), |
| 2234 | + Vec::new(), | ||
| 1983 | ) | 2235 | ) |
| 1984 | .is_err() | 2236 | .is_err() |
| 1985 | ); | 2237 | ); |
| @@ -1992,7 +2244,8 @@ mod tests { | |||
| 1992 | (LaneKind::Audio, audio.clone()), | 2244 | (LaneKind::Audio, audio.clone()), |
| 1993 | (LaneKind::Video, clips), | 2245 | (LaneKind::Video, clips), |
| 1994 | ], | 2246 | ], |
| 1995 | - Vec::new() | 2247 | + Vec::new(), |
| 2248 | + Vec::new(), | ||
| 1996 | ) | 2249 | ) |
| 1997 | .is_err() | 2250 | .is_err() |
| 1998 | ); | 2251 | ); |
| @@ -2005,17 +2258,76 @@ mod tests { | |||
| 2005 | ..video[0] | 2258 | ..video[0] |
| 2006 | }] | 2259 | }] |
| 2007 | }; | 2260 | }; |
| 2008 | - assert!(Project::from_parts(sources.clone(), two(eqd(0), Vec::new()), Vec::new()).is_err()); | 2261 | + assert!( |
| 2262 | + Project::from_parts( | ||
| 2263 | + sources.clone(), | ||
| 2264 | + two(eqd(0), Vec::new()), | ||
| 2265 | + Vec::new(), | ||
| 2266 | + Vec::new(), | ||
| 2267 | + ) | ||
| 2268 | + .is_err() | ||
| 2269 | + ); | ||
| 2009 | let mut nan = band_at(1); | 2270 | let mut nan = band_at(1); |
| 2010 | nan.bands[0].freq_hz = f32::NAN; | 2271 | nan.bands[0].freq_hz = f32::NAN; |
| 2011 | - assert!(Project::from_parts(sources.clone(), two(eqd(0), Vec::new()), vec![nan]).is_err()); | 2272 | + assert!( |
| 2012 | - let loaded = | 2273 | + Project::from_parts( |
| 2013 | - Project::from_parts(sources.clone(), two(eqd(0), Vec::new()), vec![band_at(1)]) | 2274 | + sources.clone(), |
| 2014 | - .expect("an eq the table holds"); | 2275 | + two(eqd(0), Vec::new()), |
| 2276 | + vec![nan], | ||
| 2277 | + Vec::new(), | ||
| 2278 | + ) | ||
| 2279 | + .is_err() | ||
| 2280 | + ); | ||
| 2281 | + let loaded = Project::from_parts( | ||
| 2282 | + sources.clone(), | ||
| 2283 | + two(eqd(0), Vec::new()), | ||
| 2284 | + vec![band_at(1)], | ||
| 2285 | + Vec::new(), | ||
| 2286 | + ) | ||
| 2287 | + .expect("an eq the table holds"); | ||
| 2015 | assert_eq!(loaded.eq_of(Lane::V1, 0), Some(&band_at(1))); | 2288 | assert_eq!(loaded.eq_of(Lane::V1, 0), Some(&band_at(1))); |
| 2016 | 2289 | ||
| 2290 | + // The same two refusals for a colour, at the same door. | ||
| 2291 | + let graded = |i: u16| { | ||
| 2292 | + vec![Clip { | ||
| 2293 | + color: Some(i), | ||
| 2294 | + ..video[0] | ||
| 2295 | + }] | ||
| 2296 | + }; | ||
| 2297 | + assert!( | ||
| 2298 | + Project::from_parts( | ||
| 2299 | + sources.clone(), | ||
| 2300 | + two(graded(0), Vec::new()), | ||
| 2301 | + Vec::new(), | ||
| 2302 | + Vec::new(), | ||
| 2303 | + ) | ||
| 2304 | + .is_err(), | ||
| 2305 | + "a colour index no entry answers" | ||
| 2306 | + ); | ||
| 2307 | + assert!( | ||
| 2308 | + Project::from_parts( | ||
| 2309 | + sources.clone(), | ||
| 2310 | + two(graded(0), Vec::new()), | ||
| 2311 | + Vec::new(), | ||
| 2312 | + vec![ColorParams { | ||
| 2313 | + tint: f32::NAN, | ||
| 2314 | + ..grade_at(1) | ||
| 2315 | + }], | ||
| 2316 | + ) | ||
| 2317 | + .is_err(), | ||
| 2318 | + "a value the file format could not have written" | ||
| 2319 | + ); | ||
| 2320 | + let loaded = Project::from_parts( | ||
| 2321 | + sources.clone(), | ||
| 2322 | + two(graded(0), Vec::new()), | ||
| 2323 | + Vec::new(), | ||
| 2324 | + vec![grade_at(1)], | ||
| 2325 | + ) | ||
| 2326 | + .expect("a colour the table holds"); | ||
| 2327 | + assert_eq!(loaded.color_of(Lane::V1, 0), Some(&grade_at(1))); | ||
| 2328 | + | ||
| 2017 | // Group ids survive a load, and the next split gets a fresh one. | 2329 | // Group ids survive a load, and the next split gets a fresh one. |
| 2018 | - let mut p = Project::from_parts(sources, lanes, eq).expect("valid parts"); | 2330 | + let mut p = Project::from_parts(sources, lanes, eq, color).expect("valid parts"); |
| 2019 | assert!(p.split(4)); | 2331 | assert!(p.split(4)); |
| 2020 | assert!(p.clips().iter().all(|c| c.link.is_some())); | 2332 | assert!(p.clips().iter().all(|c| c.link.is_some())); |
| 2021 | } | 2333 | } |
| @@ -2038,11 +2350,12 @@ mod tests { | |||
| 2038 | source: 0, | 2350 | source: 0, |
| 2039 | link: Some(link), | 2351 | link: Some(link), |
| 2040 | eq: None, | 2352 | eq: None, |
| 2353 | + color: None, | ||
| 2041 | }; | 2354 | }; |
| 2042 | 2355 | ||
| 2043 | // The door: named errors, one per cause. | 2356 | // The door: named errors, one per cause. |
| 2044 | let err = |video: Vec<Clip>, audio: Vec<Clip>| { | 2357 | let err = |video: Vec<Clip>, audio: Vec<Clip>| { |
| 2045 | - Project::from_parts(sources.clone(), two(video, audio), Vec::new()) | 2358 | + Project::from_parts(sources.clone(), two(video, audio), Vec::new(), Vec::new()) |
| 2046 | .expect_err("refused") | 2359 | .expect_err("refused") |
| 2047 | .to_string() | 2360 | .to_string() |
| 2048 | }; | 2361 | }; |
| @@ -2059,9 +2372,9 @@ mod tests { | |||
| 2059 | // A one-sided link is *not* an error: it is what a lift leaves behind. | 2372 | // A one-sided link is *not* an error: it is what a lift leaves behind. |
| 2060 | let mut p = Project::single(FILE, 9); | 2373 | let mut p = Project::single(FILE, 9); |
| 2061 | assert!(p.lift(Lane::A1, 0)); | 2374 | assert!(p.lift(Lane::A1, 0)); |
| 2062 | - let (sources, lanes, eq) = p.clone().without_orphan_sources(); | 2375 | + let (sources, lanes, eq, color) = p.clone().without_orphan_sources(); |
| 2063 | assert!( | 2376 | assert!( |
| 2064 | - Project::from_parts(sources, lanes, eq).is_ok(), | 2377 | + Project::from_parts(sources, lanes, eq, color).is_ok(), |
| 2065 | "a lifted lane's project has to load again" | 2378 | "a lifted lane's project has to load again" |
| 2066 | ); | 2379 | ); |
| 2067 | 2380 | ||
| @@ -2163,7 +2476,7 @@ mod tests { | |||
| 2163 | .unwrap_or(&clip(0, 0, 5, 0)); | 2476 | .unwrap_or(&clip(0, 0, 5, 0)); |
| 2164 | let lane = if next(2) == 0 { Lane::V1 } else { Lane::A1 }; | 2477 | let lane = if next(2) == 0 { Lane::V1 } else { Lane::A1 }; |
| 2165 | let idx = next(4) as usize; | 2478 | let idx = next(4) as usize; |
| 2166 | - let _ = match next(11) { | 2479 | + let _ = match next(13) { |
| 2167 | 0 => p.split(frame), | 2480 | 0 => p.split(frame), |
| 2168 | 1 => p.regroup(frame), | 2481 | 1 => p.regroup(frame), |
| 2169 | 2 => p.lift(lane, idx), | 2482 | 2 => p.lift(lane, idx), |
| @@ -2177,6 +2490,10 @@ mod tests { | |||
| 2177 | // orphans must not come back out of the prune. | 2490 | // orphans must not come back out of the prune. |
| 2178 | 8 => p.set_eq(lane, idx, Some(band_at(next(4)))), | 2491 | 8 => p.set_eq(lane, idx, Some(band_at(next(4)))), |
| 2179 | 9 => p.set_eq(lane, idx, None), | 2492 | 9 => p.set_eq(lane, idx, None), |
| 2493 | + // ...and a colour grade in the same mix, for the same | ||
| 2494 | + // reason: it rides on the clip and its orphans must go. | ||
| 2495 | + 10 => p.set_color(lane, idx, Some(grade_at(next(4)))), | ||
| 2496 | + 11 => p.set_color(lane, idx, None), | ||
| 2180 | _ => p.append_clip(0, 1 + next(9)), | 2497 | _ => p.append_clip(0, 1 + next(9)), |
| 2181 | }; | 2498 | }; |
| 2182 | reloads(&p, &format!("seed {seed}, step {step}")); | 2499 | reloads(&p, &format!("seed {seed}, step {step}")); |
| @@ -2188,8 +2505,8 @@ mod tests { | |||
| 2188 | /// handed back to the constructor a load goes through -- every lane of them, | 2505 | /// handed back to the constructor a load goes through -- every lane of them, |
| 2189 | /// and the reloaded timeline has to be the same lanes in the same order. | 2506 | /// and the reloaded timeline has to be the same lanes in the same order. |
| 2190 | fn reloads(p: &Project, what: &str) { | 2507 | fn reloads(p: &Project, what: &str) { |
| 2191 | - let (sources, lanes, eq) = p.clone().without_orphan_sources(); | 2508 | + let (sources, lanes, eq, color) = p.clone().without_orphan_sources(); |
| 2192 | - match Project::from_parts(sources, lanes, eq) { | 2509 | + match Project::from_parts(sources, lanes, eq, color) { |
| 2193 | Err(e) => panic!("{what}: saved but would not load: {e}\n{:?}", p.lanes), | 2510 | Err(e) => panic!("{what}: saved but would not load: {e}\n{:?}", p.lanes), |
| 2194 | Ok(back) => { | 2511 | Ok(back) => { |
| 2195 | assert_eq!(back.lanes(), p.lanes(), "{what}: the lane list changed"); | 2512 | assert_eq!(back.lanes(), p.lanes(), "{what}: the lane list changed"); |
| @@ -2212,6 +2529,19 @@ mod tests { | |||
| 2212 | .collect() | 2529 | .collect() |
| 2213 | }; | 2530 | }; |
| 2214 | assert_eq!(eqs(&back), eqs(p), "{what}: the equalizers changed"); | 2531 | assert_eq!(eqs(&back), eqs(p), "{what}: the equalizers changed"); |
| 2532 | + // The colour table renumbers in the same prune, so the same | ||
| 2533 | + // claim: the params a clip names, not the index it names them by. | ||
| 2534 | + let colors = |p: &Project| -> Vec<Vec<Option<ColorParams>>> { | ||
| 2535 | + p.lanes() | ||
| 2536 | + .into_iter() | ||
| 2537 | + .map(|l| { | ||
| 2538 | + (0..p.lane(l).len()) | ||
| 2539 | + .map(|i| p.color_of(l, i).copied()) | ||
| 2540 | + .collect() | ||
| 2541 | + }) | ||
| 2542 | + .collect() | ||
| 2543 | + }; | ||
| 2544 | + assert_eq!(colors(&back), colors(p), "{what}: the colours changed"); | ||
| 2215 | } | 2545 | } |
| 2216 | } | 2546 | } |
| 2217 | } | 2547 | } |
| @@ -2367,6 +2697,7 @@ mod tests { | |||
| 2367 | source: 0, | 2697 | source: 0, |
| 2368 | link: Some(link), | 2698 | link: Some(link), |
| 2369 | eq: None, | 2699 | eq: None, |
| 2700 | + color: None, | ||
| 2370 | }; | 2701 | }; |
| 2371 | let lanes = vec![ | 2702 | let lanes = vec![ |
| 2372 | LaneData { | 2703 | LaneData { |
| @@ -2399,6 +2730,7 @@ mod tests { | |||
| 2399 | source: 0, | 2730 | source: 0, |
| 2400 | link: Some(link), | 2731 | link: Some(link), |
| 2401 | eq: None, | 2732 | eq: None, |
| 2733 | + color: None, | ||
| 2402 | }; | 2734 | }; |
| 2403 | // V1, A1, V2, A2 -- one take over [0, 4) on all four. | 2735 | // V1, A1, V2, A2 -- one take over [0, 4) on all four. |
| 2404 | let kinds = [ | 2736 | let kinds = [ |
| @@ -2446,7 +2778,7 @@ mod tests { | |||
| 2446 | let v2 = p.add_lane(LaneKind::Video); | 2778 | let v2 = p.add_lane(LaneKind::Video); |
| 2447 | assert!(p.place(v2, 4, clip(0, 20, 32, 0))); | 2779 | assert!(p.place(v2, 4, clip(0, 20, 32, 0))); |
| 2448 | let a2 = p.add_lane(LaneKind::Audio); | 2780 | let a2 = p.add_lane(LaneKind::Audio); |
| 2449 | - let (sources, lanes, eq) = p.without_orphan_sources(); | 2781 | + let (sources, lanes, eq, color) = p.without_orphan_sources(); |
| 2450 | assert_eq!( | 2782 | assert_eq!( |
| 2451 | lanes.iter().map(|(k, _)| *k).collect::<Vec<_>>(), | 2783 | lanes.iter().map(|(k, _)| *k).collect::<Vec<_>>(), |
| 2452 | [ | 2784 | [ |
| @@ -2460,7 +2792,7 @@ mod tests { | |||
| 2460 | assert_eq!(lanes[2].1, p.lane(v2), "V2's clips are written"); | 2792 | assert_eq!(lanes[2].1, p.lane(v2), "V2's clips are written"); |
| 2461 | assert!(lanes[3].1.is_empty(), "and the empty A2 is still a lane"); | 2793 | assert!(lanes[3].1.is_empty(), "and the empty A2 is still a lane"); |
| 2462 | // ...and all four load again as the same four. | 2794 | // ...and all four load again as the same four. |
| 2463 | - let back = Project::from_parts(sources, lanes, eq).expect("four lanes load"); | 2795 | + let back = Project::from_parts(sources, lanes, eq, color).expect("four lanes load"); |
| 2464 | assert_eq!(back.lanes(), p.lanes()); | 2796 | assert_eq!(back.lanes(), p.lanes()); |
| 2465 | assert_eq!(back.lane(a2), p.lane(a2)); | 2797 | assert_eq!(back.lane(a2), p.lane(a2)); |
| 2466 | 2798 | ||
| @@ -2542,7 +2874,7 @@ mod tests { | |||
| 2542 | (LaneKind::Video, vec![clip(10, 5, 15, 1)]), | 2874 | (LaneKind::Video, vec![clip(10, 5, 15, 1)]), |
| 2543 | (LaneKind::Audio, vec![clip(0, 0, 30, 0)]), | 2875 | (LaneKind::Audio, vec![clip(0, 0, 30, 0)]), |
| 2544 | ]; | 2876 | ]; |
| 2545 | - let p = Project::from_parts(sources, lanes, vec![]).expect("valid parts"); | 2877 | + let p = Project::from_parts(sources, lanes, vec![], vec![]).expect("valid parts"); |
| 2546 | assert_eq!( | 2878 | assert_eq!( |
| 2547 | p.composite_spans_from(0), | 2879 | p.composite_spans_from(0), |
| 2548 | vec![ | 2880 | vec![ |
| @@ -2583,7 +2915,7 @@ mod tests { | |||
| 2583 | (LaneKind::Video, vec![clip(10, 0, 10, 1)]), | 2915 | (LaneKind::Video, vec![clip(10, 0, 10, 1)]), |
| 2584 | (LaneKind::Audio, vec![clip(0, 0, 30, 0)]), | 2916 | (LaneKind::Audio, vec![clip(0, 0, 30, 0)]), |
| 2585 | ]; | 2917 | ]; |
| 2586 | - let p = Project::from_parts(sources, holed, vec![]).expect("valid parts"); | 2918 | + let p = Project::from_parts(sources, holed, vec![], vec![]).expect("valid parts"); |
| 2587 | assert_eq!( | 2919 | assert_eq!( |
| 2588 | p.composite_spans_from(0), | 2920 | p.composite_spans_from(0), |
| 2589 | vec![ | 2921 | vec![ |
| @@ -2627,7 +2959,7 @@ mod tests { | |||
| 2627 | (LaneKind::Audio, vec![clip(15, 0, 15, 1)]), | 2959 | (LaneKind::Audio, vec![clip(15, 0, 15, 1)]), |
| 2628 | (LaneKind::Audio, Vec::new()), | 2960 | (LaneKind::Audio, Vec::new()), |
| 2629 | ]; | 2961 | ]; |
| 2630 | - let p = Project::from_parts(sources, lanes, vec![]).expect("valid parts"); | 2962 | + let p = Project::from_parts(sources, lanes, vec![], vec![]).expect("valid parts"); |
| 2631 | let lists = p.audio_segments_from(0, FPS); | 2963 | let lists = p.audio_segments_from(0, FPS); |
| 2632 | assert_eq!(lists.len(), 2, "the empty lane is not mixed in"); | 2964 | assert_eq!(lists.len(), 2, "the empty lane is not mixed in"); |
| 2633 | assert_eq!(lists[0], p.segments_from(0, FPS), "A1 is unchanged"); | 2965 | assert_eq!(lists[0], p.segments_from(0, FPS), "A1 is unchanged"); |
| @@ -2643,6 +2975,7 @@ mod tests { | |||
| 2643 | (LaneKind::Audio, Vec::new()), | 2975 | (LaneKind::Audio, Vec::new()), |
| 2644 | ], | 2976 | ], |
| 2645 | vec![], | 2977 | vec![], |
| 2978 | + vec![], | ||
| 2646 | ) | 2979 | ) |
| 2647 | .expect("valid parts"); | 2980 | .expect("valid parts"); |
| 2648 | assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]); | 2981 | assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]); |
crates/engine/tests/audio_export.rsmodified+3 -0
| @@ -65,6 +65,7 @@ fn mixed_project() -> Project { | |||
| 65 | source, | 65 | source, |
| 66 | link: None, | 66 | link: None, |
| 67 | eq: None, | 67 | eq: None, |
| 68 | + color: None, | ||
| 68 | }; | 69 | }; |
| 69 | Project::from_parts( | 70 | Project::from_parts( |
| 70 | vec![ | 71 | vec![ |
| @@ -84,11 +85,13 @@ fn mixed_project() -> Project { | |||
| 84 | source: 0, | 85 | source: 0, |
| 85 | link: None, | 86 | link: None, |
| 86 | eq: None, | 87 | eq: None, |
| 88 | + color: None, | ||
| 87 | }], | 89 | }], |
| 88 | ), | 90 | ), |
| 89 | (LaneKind::Audio, vec![clip(0, 0), clip(60, 1)]), | 91 | (LaneKind::Audio, vec![clip(0, 0), clip(60, 1)]), |
| 90 | ], | 92 | ], |
| 91 | Vec::new(), | 93 | Vec::new(), |
| 94 | + Vec::new(), | ||
| 92 | ) | 95 | ) |
| 93 | .expect("a two-source project with a hole in the audio lane") | 96 | .expect("a two-source project with a hole in the audio lane") |
| 94 | } | 97 | } |
crates/engine/tests/export.rsmodified+2 -0
| @@ -192,6 +192,7 @@ fn exports_the_audio_stream_the_timeline_plays() { | |||
| 192 | source: 0, | 192 | source: 0, |
| 193 | link: Some(0), | 193 | link: Some(0), |
| 194 | eq: None, | 194 | eq: None, |
| 195 | + color: None, | ||
| 195 | }; | 196 | }; |
| 196 | // Stream 1 is the 22.05 kHz mono French track; stream 0 is 44.1 kHz | 197 | // Stream 1 is the 22.05 kHz mono French track; stream 0 is 44.1 kHz |
| 197 | // stereo. A project may only hold streams that agree, so this timeline is | 198 | // stereo. A project may only hold streams that agree, so this timeline is |
| @@ -206,6 +207,7 @@ fn exports_the_audio_stream_the_timeline_plays() { | |||
| 206 | (engine::project::LaneKind::Audio, vec![whole]), | 207 | (engine::project::LaneKind::Audio, vec![whole]), |
| 207 | ], | 208 | ], |
| 208 | Vec::new(), | 209 | Vec::new(), |
| 210 | + Vec::new(), | ||
| 209 | ) | 211 | ) |
| 210 | .expect("a one-source project on stream 1"); | 212 | .expect("a one-source project on stream 1"); |
| 211 | let out = out_path("stream1"); | 213 | let out = out_path("stream1"); |
crates/engine/tests/lanes.rsmodified+5 -2
| @@ -236,6 +236,7 @@ fn the_mp4_copy_follows_the_lane_that_holds_the_sound() { | |||
| 236 | source: 0, | 236 | source: 0, |
| 237 | link: None, | 237 | link: None, |
| 238 | eq: None, | 238 | eq: None, |
| 239 | + color: None, | ||
| 239 | }; | 240 | }; |
| 240 | let project = Project::from_parts( | 241 | let project = Project::from_parts( |
| 241 | vec![Source::new(&source, 0)], | 242 | vec![Source::new(&source, 0)], |
| @@ -245,6 +246,7 @@ fn the_mp4_copy_follows_the_lane_that_holds_the_sound() { | |||
| 245 | (LaneKind::Audio, vec![clip]), | 246 | (LaneKind::Audio, vec![clip]), |
| 246 | ], | 247 | ], |
| 247 | vec![], | 248 | vec![], |
| 249 | + vec![], | ||
| 248 | ) | 250 | ) |
| 249 | .expect("valid parts"); | 251 | .expect("valid parts"); |
| 250 | assert_eq!( | 252 | assert_eq!( |
| @@ -293,12 +295,13 @@ fn two_audio_lanes_are_summed() { | |||
| 293 | source: 0, | 295 | source: 0, |
| 294 | link: None, | 296 | link: None, |
| 295 | eq: None, | 297 | eq: None, |
| 298 | + color: None, | ||
| 296 | }; | 299 | }; |
| 297 | let a2 = project.add_lane(LaneKind::Audio); | 300 | let a2 = project.add_lane(LaneKind::Audio); |
| 298 | assert!(project.place(a2, TOP_IN, doubled), "place the second lane"); | 301 | assert!(project.place(a2, TOP_IN, doubled), "place the second lane"); |
| 299 | - let (sources, lanes, eq) = project.without_orphan_sources(); | 302 | + let (sources, lanes, eq, color) = project.without_orphan_sources(); |
| 300 | assert_eq!(lanes.len(), 3, "V1, A1 and the new A2"); | 303 | assert_eq!(lanes.len(), 3, "V1, A1 and the new A2"); |
| 301 | - let project = Project::from_parts(sources, lanes, eq).expect("valid parts"); | 304 | + let project = Project::from_parts(sources, lanes, eq, color).expect("valid parts"); |
| 302 | 305 | ||
| 303 | let (meta, _) = engine::demux::Demuxer::open(&asset("test_av.mp4")).unwrap(); | 306 | let (meta, _) = engine::demux::Demuxer::open(&asset("test_av.mp4")).unwrap(); |
| 304 | let wav = |name: &str, project: Project| { | 307 | let wav = |name: &str, project: Project| { |
crates/engine/tests/saveload.rsmodified+47 -12
| @@ -126,9 +126,9 @@ fn shape(session: &PlaybackSession) -> (Vec<(f64, f64, usize)>, Vec<Source>, f64 | |||
| 126 | 126 | ||
| 127 | /// The version-1 promise: a file written before the lanes existed still opens, | 127 | /// The version-1 promise: a file written before the lanes existed still opens, |
| 128 | /// as one grouped video+audio pair per clip laid end to end, and saving it | 128 | /// as one grouped video+audio pair per clip laid end to end, and saving it |
| 129 | -/// again writes version 5 -- which reopens as the same timeline. | 129 | +/// again writes version 6 -- which reopens as the same timeline. |
| 130 | #[test] | 130 | #[test] |
| 131 | -fn a_version_1_project_loads_fully_grouped_and_saves_as_version_5() { | 131 | +fn a_version_1_project_loads_fully_grouped_and_saves_as_version_6() { |
| 132 | let dir = scratch("v1"); | 132 | let dir = scratch("v1"); |
| 133 | copy_in(&dir, "test_av.mp4"); | 133 | copy_in(&dir, "test_av.mp4"); |
| 134 | let path = dir.join("old.edith"); | 134 | let path = dir.join("old.edith"); |
| @@ -156,11 +156,11 @@ fn a_version_1_project_loads_fully_grouped_and_saves_as_version_5() { | |||
| 156 | "playhead kept" | 156 | "playhead kept" |
| 157 | ); | 157 | ); |
| 158 | 158 | ||
| 159 | - // Saved again it is v5, and v5 round-trips to the same timeline. | 159 | + // Saved again it is v6, and v6 round-trips to the same timeline. |
| 160 | let v2 = dir.join("new.edith"); | 160 | let v2 = dir.join("new.edith"); |
| 161 | loaded.save_project(&v2).expect("save"); | 161 | loaded.save_project(&v2).expect("save"); |
| 162 | let text = std::fs::read_to_string(&v2).expect("read back"); | 162 | let text = std::fs::read_to_string(&v2).expect("read back"); |
| 163 | - assert!(text.starts_with("edith 5\n"), "{text}"); | 163 | + assert!(text.starts_with("edith 6\n"), "{text}"); |
| 164 | assert_eq!( | 164 | assert_eq!( |
| 165 | text.lines().filter(|l| l.starts_with("video ")).count(), | 165 | text.lines().filter(|l| l.starts_with("video ")).count(), |
| 166 | 2, | 166 | 2, |
| @@ -237,21 +237,23 @@ fn a_version_4_project_holds_more_than_two_lanes() { | |||
| 237 | ); | 237 | ); |
| 238 | assert_eq!(loaded.timeline_duration(), 60.0 / loaded.meta().frame_rate); | 238 | assert_eq!(loaded.timeline_duration(), 60.0 / loaded.meta().frame_rate); |
| 239 | 239 | ||
| 240 | - // ...and saving it writes the v5 twin of what it read: the lane list, its | 240 | + // ...and saving it writes the v6 twin of what it read: the lane list, its |
| 241 | - // order and the empty lane all survive, each clip now saying it plays flat. | 241 | + // order and the empty lane all survive, each clip now saying it plays flat |
| 242 | + // and ungraded. | ||
| 242 | let again = dir.join("again.edith"); | 243 | let again = dir.join("again.edith"); |
| 243 | loaded.save_project(&again).expect("save"); | 244 | loaded.save_project(&again).expect("save"); |
| 244 | assert_eq!( | 245 | assert_eq!( |
| 245 | std::fs::read_to_string(&again).expect("read back"), | 246 | std::fs::read_to_string(&again).expect("read back"), |
| 246 | - "edith 5\nplayhead 0\nsource 0 test_av.mp4\n\ | 247 | + "edith 6\nplayhead 0\nsource 0 test_av.mp4\n\ |
| 247 | - video 1 0 0 30 0 3 -\naudio 1\nvideo 2 40 0 20 0 - -\naudio 2 0 0 30 0 3 -\n", | 248 | + video 1 0 0 30 0 3 - -\naudio 1\nvideo 2 40 0 20 0 - - -\naudio 2 0 0 30 0 3 - -\n", |
| 248 | - "a four-lane project is written as it was read, one version on" | 249 | + "a four-lane project is written as it was read, two versions on" |
| 249 | ); | 250 | ); |
| 250 | } | 251 | } |
| 251 | 252 | ||
| 252 | /// What version 5 is for: a clip carries equalizer settings, the file names | 253 | /// What version 5 is for: a clip carries equalizer settings, the file names |
| 253 | /// them once for however many clips share them, and the whole thing survives | 254 | /// them once for however many clips share them, and the whole thing survives |
| 254 | -/// the engine's own door -- open, save, byte for byte the file it read. | 255 | +/// the engine's own door -- open, save, every curve and index of it intact one |
| 256 | +/// version on. | ||
| 255 | #[test] | 257 | #[test] |
| 256 | fn a_version_5_project_carries_per_clip_equalizers() { | 258 | fn a_version_5_project_carries_per_clip_equalizers() { |
| 257 | let dir = scratch("v5_eq"); | 259 | let dir = scratch("v5_eq"); |
| @@ -271,11 +273,44 @@ fn a_version_5_project_carries_per_clip_equalizers() { | |||
| 271 | loaded.save_project(&again).expect("save"); | 273 | loaded.save_project(&again).expect("save"); |
| 272 | assert_eq!( | 274 | assert_eq!( |
| 273 | std::fs::read_to_string(&again).expect("read back"), | 275 | std::fs::read_to_string(&again).expect("read back"), |
| 274 | - text, | 276 | + "edith 6\nplayhead 0\nsource 0 test_av.mp4\n\ |
| 277 | + eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ | ||
| 278 | + eq 12000.0:6.25:0.5:hs\n\ | ||
| 279 | + video 1 0 0 30 0 - 0 -\nvideo 1 30 30 60 0 - 1 -\n\ | ||
| 280 | + audio 1 0 0 30 0 - 0 -\naudio 1 30 30 60 0 - - -\n", | ||
| 275 | "the equalizer table and every clip's index survive a round trip" | 281 | "the equalizer table and every clip's index survive a round trip" |
| 276 | ); | 282 | ); |
| 277 | } | 283 | } |
| 278 | 284 | ||
| 285 | +/// What version 6 is for, the same claim one version on: a clip carries a | ||
| 286 | +/// colour grade beside its equalizer, the file names each once for however many | ||
| 287 | +/// clips share it, and the whole thing comes back out byte for byte. | ||
| 288 | +#[test] | ||
| 289 | +fn a_version_6_project_carries_per_clip_colours() { | ||
| 290 | + let dir = scratch("v6_color"); | ||
| 291 | + copy_in(&dir, "test_av.mp4"); | ||
| 292 | + let path = dir.join("color.edith"); | ||
| 293 | + // Two clips on one grade, one on another, one ungraded -- and an equalizer | ||
| 294 | + // on a clip that is graded too, so the two tables are seen not to collide. | ||
| 295 | + let text = "edith 6\nplayhead 0\nsource 0 test_av.mp4\n\ | ||
| 296 | + eq 80.0:-3.0:0.707:ls\n\ | ||
| 297 | + color 0.1:1.2:0.9:-0.3\n\ | ||
| 298 | + color -0.25:1.0:0.0:0.5\n\ | ||
| 299 | + video 1 0 0 30 0 - 0 0\nvideo 1 30 30 60 0 - - 1\n\ | ||
| 300 | + audio 1 0 0 30 0 - - 0\naudio 1 30 30 60 0 - - -\n"; | ||
| 301 | + std::fs::write(&path, text).expect("write a v6 file"); | ||
| 302 | + | ||
| 303 | + let loaded = PlaybackSession::open_project(&path).expect("a v6 project opens"); | ||
| 304 | + assert_eq!(loaded.lane_clips(engine::project::Lane::V1).len(), 2); | ||
| 305 | + let again = dir.join("again.edith"); | ||
| 306 | + loaded.save_project(&again).expect("save"); | ||
| 307 | + assert_eq!( | ||
| 308 | + std::fs::read_to_string(&again).expect("read back"), | ||
| 309 | + text, | ||
| 310 | + "the colour table and every clip's index survive a round trip" | ||
| 311 | + ); | ||
| 312 | +} | ||
| 313 | + | ||
| 279 | #[test] | 314 | #[test] |
| 280 | fn a_saved_project_reopens_as_the_same_timeline() { | 315 | fn a_saved_project_reopens_as_the_same_timeline() { |
| 281 | let dir = scratch("round_trip"); | 316 | let dir = scratch("round_trip"); |
| @@ -487,7 +522,7 @@ fn malformed_files_are_numbered_errors_and_never_panics() { | |||
| 487 | 522 | ||
| 488 | for (text, want) in [ | 523 | for (text, want) in [ |
| 489 | ( | 524 | ( |
| 490 | - "edith 6\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - -\n", | 525 | + "edith 7\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - -\n", |
| 491 | "line 1", | 526 | "line 1", |
| 492 | ), | 527 | ), |
| 493 | // An eq index the table does not hold, and a band shape there is none. | 528 | // An eq index the table does not hold, and a band shape there is none. |