diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index 40cd09b..a447aa8 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -223,7 +223,36 @@ impl Player { cx.notify(); } + pub(crate) fn viz_paint(&self) -> u32 { + self.selected + .anchor() + .and_then(|(lane, idx)| { + self.session + .as_ref()? + .lane_clips(lane) + .get(idx) + .map(|c| c.viz_paint) + }) + .unwrap_or(0) + } + pub(crate) fn set_viz_hue(&mut self, hue: u8, cx: &mut Context) { + self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_hue(p, hue)); + } + + pub(crate) fn set_viz_sat(&mut self, sat: u8, cx: &mut Context) { + self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_sat(p, sat)); + } + + pub(crate) fn set_viz_strands(&mut self, n: u8, cx: &mut Context) { + self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_strands(p, n)); + } + + pub(crate) fn set_viz_glow(&mut self, n: u8, cx: &mut Context) { + self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_glow(p, n)); + } + + fn set_viz_paint_with(&mut self, cx: &mut Context, f: impl FnOnce(u32) -> u32) { let Some((lane, idx)) = self.selected.anchor() else { return; }; @@ -236,8 +265,8 @@ impl Player { if clip.visualizer & 1 == 0 { return; } - let next = engine::decode::with_viz_hue(clip.visualizer, hue); - if next != clip.visualizer && session.set_visualizer(lane, idx, next) { + let next = f(clip.viz_paint); + if next != clip.viz_paint && session.set_viz_paint(lane, idx, next) { self.reset_after_reseek(); } cx.notify(); diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index fcd90af..a440981 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -1383,6 +1383,7 @@ fn a_duration_row_shows_only_for_a_transition_and_its_room_is_the_successors() { fade_out, transition_out, visualizer: 0, + viz_paint: 0, } } // A plain cut carries neither field, so the row has nothing to show. diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index 6f328ec..04ed625 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -631,6 +631,7 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 30, in_frame: 0, out_frame: 60, @@ -1066,6 +1067,7 @@ fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 30, in_frame: 0, out_frame: 60, @@ -1798,6 +1800,7 @@ fn a_copied_clip_is_renumbered_or_dropped_when_a_row_leaves_the_library() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: 30, @@ -1951,6 +1954,7 @@ fn trim_to_playhead_needs_a_subject_cut_with_the_playhead_on_it() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 100, in_frame: 0, out_frame: 60, diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 980869c..fa4a548 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -747,6 +747,7 @@ fn a_drop_moves_the_clip_that_was_picked_up_not_its_old_index() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame: 0, out_frame: 30, @@ -3565,6 +3566,7 @@ fn the_cut_readout_counts_from_the_playhead() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame: 0, out_frame: len, diff --git a/crates/app/src/tests/view.rs b/crates/app/src/tests/view.rs index c83d34d..0f46262 100644 --- a/crates/app/src/tests/view.rs +++ b/crates/app/src/tests/view.rs @@ -158,6 +158,7 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame: 0, out_frame: frames, diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index 460a36d..0dc5084 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -889,6 +889,7 @@ mod drop_landing_tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame: 0, out_frame: frames, diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index 989637e..394a7dc 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -189,7 +189,7 @@ fn dock_tab( .children(hitmap::control(id, label_text, true)) .child( div() - .font(style.font) + .font(style.font.clone()) .text_size(style.size) .text_color(rgb(if active { INK1() } else { INK3() })) .child(label_text), @@ -201,7 +201,7 @@ fn section_head(text: impl Into) -> impl IntoElement { let style = head(); div() .flex_none() - .font(style.font) + .font(style.font.clone()) .text_size(style.size) .text_color(rgb(INK3())) .child(text.into()) @@ -449,7 +449,7 @@ fn source_row( // usage moved down to the metadata line. .min_w(relative(0.6)) .truncate() - .font(style.font) + .font(style.font.clone()) .text_size(style.size) .text_color(rgb(INK1())) .child(name) @@ -526,7 +526,7 @@ fn source_row( div() .pl(px(14.)) .truncate() - .font(style.font) + .font(style.font.clone()) .text_size(style.size) .text_color(rgb(INK3())) .child(under) @@ -1022,7 +1022,7 @@ fn sources_tab( .id("dock-filter") .flex_none() .cursor_text() - .font(style.font) + .font(style.font.clone()) .text_size(style.size) .text_color(rgb(if player.dock_filter_edit { INK1() @@ -1059,7 +1059,7 @@ fn sources_tab( let style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); d.child( div() - .font(style.font) + .font(style.font.clone()) .text_size(style.size) .text_color(rgb(INK3())) // One noun for both empties -- nothing imported and @@ -1187,34 +1187,17 @@ fn transition_row(player: &Player, cx: &mut Context) -> Option) -> impl IntoElement { - let flags = player.selected.anchor().and_then(|(lane, idx)| { + let clip = player.selected.anchor().and_then(|(lane, idx)| { let session = player.session.as_ref()?; let clip = session.lane_clips(lane).get(idx)?; - (clip.visualizer & 1 != 0).then_some(clip.visualizer) + (clip.visualizer & 1 != 0).then_some(*clip) }); - let Some(flags) = flags else { + let Some(clip) = clip else { return div().id("dock-viz-styles"); }; + let flags = clip.visualizer; + let paint = clip.viz_paint; let pick = |id: &'static str, label_text: &'static str, style: u8, on: bool| { let row = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); div() @@ -1250,7 +1233,7 @@ fn viz_style_verbs(player: &Player, cx: &mut Context) -> impl IntoElemen .items_center() .cursor_pointer() .text_color(rgb(if on { INK1() } else { INK3() })) - .font(style.font) + .font(style.font.clone()) .text_size(style.size) .children(hitmap::control(id, label_text, true)) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { @@ -1299,82 +1282,168 @@ fn viz_style_verbs(player: &Player, cx: &mut Context) -> impl IntoElemen engine::decode::VIZ_FAST, flags & engine::decode::VIZ_FAST != 0, )) - .child(viz_hue_row(flags, cx)) + .child(viz_paint_knobs(paint, cx)) } -fn viz_hue_row(flags: u8, cx: &mut Context) -> impl IntoElement { - let hue = engine::decode::viz_hue(flags); - let style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); - let step = |id: &'static str, glyph: &'static str, by: i8, cx: &mut Context| { - div() - .id(id) - .flex() - .w(px(HIT_MIN)) - .h(px(HIT_MIN)) - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(DARK_RAISED())) - .cursor_pointer() - .children(hitmap::control(id, "Colour", true)) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - let cur = this - .selected - .anchor() - .and_then(|(lane, idx)| { - this.session - .as_ref()? - .lane_clips(lane) - .get(idx) - .map(|c| engine::decode::viz_hue(c.visualizer)) - }) - .unwrap_or(0); - this.set_viz_hue((cur as i16 + i16::from(by)).rem_euclid(16) as u8, cx); - })) - .child(glyph) - }; +fn viz_step( + id: &'static str, + glyph: &'static str, + cx: &mut Context, + f: impl Fn(&mut Player, &mut Context) + 'static + Copy, +) -> impl IntoElement { div() - .id("dock-viz-hue") - .flex_none() + .id(id) .flex() + .w(px(HIT_MIN)) + .h(px(HIT_MIN)) .items_center() + .justify_center() + .rounded(px(3.)) + .bg(rgb(DARK_RAISED())) + .cursor_pointer() + .children(hitmap::control(id, glyph, true)) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| f(this, cx))) + .child(glyph) +} + +fn viz_paint_knobs(paint: u32, cx: &mut Context) -> impl IntoElement { + let hue = engine::decode::viz_hue_ui(paint); + let sat = engine::decode::viz_sat_ui(paint); + let strands = engine::decode::viz_strands_of(paint); + let glow = engine::decode::viz_glow_of(paint); + let style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); + div() + .flex() + .flex_col() .gap(px(4.)) - .h(px(CONTROL_H)) .px(px(8.)) .child( div() - .font(style.font) - .text_size(style.size) - .text_color(rgb(INK2())) - .child("Colour"), + .id("dock-viz-hue") + .flex() + .items_center() + .gap(px(4.)) + .h(px(CONTROL_H)) + .child( + div() + .font(style.font.clone()) + .text_size(style.size) + .text_color(rgb(INK2())) + .child("Colour"), + ) + .child(viz_step("dock-viz-hue-minus", "−", cx, |this, cx| { + this.set_viz_hue(engine::decode::viz_hue_ui(this.viz_paint()).wrapping_sub(4), cx); + })) + .child( + div() + .id("dock-viz-hue-bar") + .flex_1() + .flex() + .h(px(14.)) + .children((0u8..64).map(|i| { + let h = i.saturating_mul(4); + let (r, g, b) = engine::decode::viz_ink_from_paint( + engine::decode::with_viz_paint_hue(paint, h), + ); + let color = (u32::from(r) << 16) | (u32::from(g) << 8) | u32::from(b); + div() + .id(("dock-viz-hue", u64::from(i))) + .flex_1() + .h_full() + .bg(rgb(color)) + .when(hue.abs_diff(h) < 3, |d| d.border_1().border_color(rgb(INK1()))) + .cursor_pointer() + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.set_viz_hue(h, cx); + })) + .into_any_element() + })), + ) + .child(viz_step("dock-viz-hue-plus", "+", cx, |this, cx| { + this.set_viz_hue(engine::decode::viz_hue_ui(this.viz_paint()).wrapping_add(4), cx); + })), ) - .child(step("dock-viz-hue-minus", "−", -1, cx)) .child( div() - .id("dock-viz-hue-swatches") - .flex_1() .flex() - .gap(px(2.)) - .children((0u8..16).map(|i| { - let (r, g, b) = engine::decode::viz_ink_rgb(i); - let color = (u32::from(r) << 16) | (u32::from(g) << 8) | u32::from(b); + .items_center() + .gap(px(4.)) + .h(px(CONTROL_H)) + .child( div() - .id(("dock-viz-hue", u64::from(i))) - .flex_1() - .h(px(14.)) - .min_w(px(8.)) - .rounded(px(2.)) - .bg(rgb(color)) - .when(i == hue, |d| d.border_1().border_color(rgb(INK1()))) - .cursor_pointer() - .children(hitmap::control(VIZ_HUE_IDS[i as usize], "Colour", true)) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.set_viz_hue(i, cx); - })) - .into_any_element() + .font(style.font.clone()) + .text_size(style.size) + .text_color(rgb(INK2())) + .child("Sat"), + ) + .child(viz_step("dock-viz-sat-minus", "−", cx, |this, cx| { + this.set_viz_sat(engine::decode::viz_sat_ui(this.viz_paint()).saturating_sub(16), cx); + })) + .child( + div() + .font(style.font.clone()) + .text_size(style.size) + .text_color(rgb(INK1())) + .child(format!("{sat}")), + ) + .child(viz_step("dock-viz-sat-plus", "+", cx, |this, cx| { + this.set_viz_sat(engine::decode::viz_sat_ui(this.viz_paint()).saturating_add(16).min(255), cx); + })), + ) + .child( + div() + .flex() + .items_center() + .gap(px(4.)) + .h(px(CONTROL_H)) + .child( + div() + .font(style.font.clone()) + .text_size(style.size) + .text_color(rgb(INK2())) + .child("Strands"), + ) + .child(viz_step("dock-viz-strands-minus", "−", cx, |this, cx| { + this.set_viz_strands(engine::decode::viz_strands_of(this.viz_paint()).saturating_sub(1).max(1), cx); + })) + .child( + div() + .font(style.font.clone()) + .text_size(style.size) + .text_color(rgb(INK1())) + .child(format!("{strands}")), + ) + .child(viz_step("dock-viz-strands-plus", "+", cx, |this, cx| { + this.set_viz_strands(engine::decode::viz_strands_of(this.viz_paint()).saturating_add(1).min(32), cx); + })), + ) + .child( + div() + .flex() + .items_center() + .gap(px(4.)) + .h(px(CONTROL_H)) + .child( + div() + .font(style.font.clone()) + .text_size(style.size) + .text_color(rgb(INK2())) + .child("Glow"), + ) + .child(viz_step("dock-viz-glow-minus", "−", cx, |this, cx| { + this.set_viz_glow(engine::decode::viz_glow_of(this.viz_paint()).saturating_sub(1), cx); + })) + .child( + div() + .font(style.font.clone()) + .text_size(style.size) + .text_color(rgb(INK1())) + .child(format!("{glow}")), + ) + .child(viz_step("dock-viz-glow-plus", "+", cx, |this, cx| { + this.set_viz_glow(engine::decode::viz_glow_of(this.viz_paint()).saturating_add(1).min(16), cx); })), ) - .child(step("dock-viz-hue-plus", "+", 1, cx)) } fn clip_tab( @@ -1614,7 +1683,7 @@ fn keys_tab(player: &Player, cx: &mut Context) -> impl IntoElement { .id("dock-keys-filter") .flex_none() .cursor_text() - .font(style.font) + .font(style.font.clone()) .text_size(style.size) .text_color(rgb(INK1())) .children(hitmap::control("dock.keys-filter", "Filter keys", true)) diff --git a/crates/engine/examples/bench.rs b/crates/engine/examples/bench.rs index 9e5fc6c..e3e2c99 100644 --- a/crates/engine/examples/bench.rs +++ b/crates/engine/examples/bench.rs @@ -864,6 +864,7 @@ fn export_bench(path: &Path, seat: &str, out_dir: &Path) { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame, out_frame: in_frame + span, diff --git a/crates/engine/src/decode.rs b/crates/engine/src/decode.rs index b31581d..ea0dc3b 100644 --- a/crates/engine/src/decode.rs +++ b/crates/engine/src/decode.rs @@ -56,6 +56,7 @@ pub enum Backend { /// A gap: black frames, nothing decoded at all. Gap, /// A waveform visualizer: the picture is painted from the audio's peaks + /// A waveform viz_paint: 0, /// ([`visualizer_i420`]), no decoder seat and no stream of pictures at all. Visualizer, } @@ -629,6 +630,7 @@ impl DecodeSession { transform: TransformParams, canvas: Composer, flags: u8, + paint: u32, ) -> crate::Result { let (tx, rx) = sync_channel(2); let cancel = Arc::new(AtomicBool::new(false)); @@ -679,7 +681,7 @@ impl DecodeSession { return; } let t = f64::from(start_frame + index) / fps; - let (y, u, v) = visualizer_i420(&peaks, t, width, height, flags); + let (y, u, v) = visualizer_i420(&peaks, t, width, height, flags, paint); let frame = render.frame(start_frame + index, &y, &u, &v, width, height); if tx.send(frame).is_err() { return; // caller moved on @@ -1444,6 +1446,65 @@ pub fn viz_ink_rgb(hue: u8) -> (u8, u8, u8) { hsv_to_rgb(212.0 + f32::from(hue & 15) * 22.5, 0.63, 0.84) } +pub fn viz_ink_from_paint(paint: u32) -> (u8, u8, u8) { + if paint == 0 { + return hsv_to_rgb(212.0, 0.63, 0.84); + } + let hue = (paint & 0xFF) as f32 * 360.0 / 256.0; + let sat_b = ((paint >> 8) & 0xFF) as u8; + let sat = if sat_b == 0 { 0.63 } else { f32::from(sat_b) / 255.0 }; + hsv_to_rgb(hue, sat, 0.84) +} + +pub fn viz_strands_of(paint: u32) -> u8 { + match ((paint >> 16) & 0xFF) as u8 { + 0 => 8, + n => n.clamp(1, 32), + } +} + +pub fn viz_glow_of(paint: u32) -> u8 { + match ((paint >> 24) & 0xFF) as u8 { + 0 => 2, + n => n.min(16), + } +} + +pub fn with_viz_paint_hue(paint: u32, hue: u8) -> u32 { + let sat = match (paint >> 8) & 0xFF { + 0 => 255, + s => s, + }; + (paint & !0xFF) | u32::from(hue) | (sat << 8) +} + +pub fn with_viz_paint_sat(paint: u32, sat: u8) -> u32 { + (paint & !(0xFF << 8)) | (u32::from(sat.max(1)) << 8) +} + +pub fn with_viz_paint_strands(paint: u32, n: u8) -> u32 { + (paint & !(0xFF << 16)) | (u32::from(n.clamp(1, 32)) << 16) +} + +pub fn with_viz_paint_glow(paint: u32, n: u8) -> u32 { + (paint & !(0xFF << 24)) | (u32::from(n.min(16)) << 24) +} + +pub fn viz_hue_ui(paint: u32) -> u8 { + if paint == 0 { 150 } else { (paint & 0xFF) as u8 } +} + +pub fn viz_sat_ui(paint: u32) -> u8 { + if paint == 0 { + 160 + } else { + match ((paint >> 8) & 0xFF) as u8 { + 0 => 160, + s => s, + } + } +} + fn hsv_to_rgb(h: f32, s: f32, v: f32) -> (u8, u8, u8) { let h = ((h % 360.0) + 360.0) % 360.0; let c = v * s; @@ -1607,6 +1668,7 @@ pub(crate) fn visualizer_i420( width: u32, height: u32, flags: u8, + paint: u32, ) -> (Vec, Vec, Vec) { let width = width & !1; let height = height & !1; @@ -1616,7 +1678,7 @@ pub(crate) fn visualizer_i420( let mut y = vec![bg_y; w * h]; let mut u = vec![bg_u; cw * ch]; let mut v = vec![bg_v; cw * ch]; - let (ink_r, ink_g, ink_b) = viz_ink_rgb(viz_hue(flags)); + let (ink_r, ink_g, ink_b) = viz_ink_from_paint(paint); let (ink_y, ink_u, ink_v) = rgb_yuv(ink_r as i32, ink_g as i32, ink_b as i32); let center = h as f32 / 2.0; let half = h as f32 * 0.42; @@ -1669,15 +1731,18 @@ pub(crate) fn visualizer_i420( let f = (pos - i as f64) as f32; sig[col] = signed(i) + (signed(i.saturating_add(1)) - signed(i)) * f; } - let peak = lo + // Whole-file peak, not the window's: a 2s window that gains or loses + // a loud hit used to rescale every column, so the same bump changed + // height as it entered and left the picture. + let peak = peaks .iter() - .zip(&hi) - .map(|(l, h)| l.abs().max(h.abs())) + .map(|&(l, h)| l.abs().max(h.abs())) .fold(0.0f32, f32::max); if peak > 1e-4 { for i in 0..w { lo[i] /= peak; hi[i] /= peak; + sig[i] /= peak; } } viz_smooth(&mut lo, &mut hi); @@ -1691,8 +1756,8 @@ pub(crate) fn visualizer_i420( for col in 0..w { let env = lo[col].abs().max(hi[col]).max(0.06); let x_phase = (col as f64 / w.max(1) as f64) * 2.15 * tau; - for s in 0..24 { - let frac = s as f32 / 23.0; + for s in 0..u32::from(viz_strands_of(paint)).max(1) { + let frac = s as f32 / (viz_strands_of(paint).max(2) as f32 - 1.0); let scale = 0.28 + 0.72 * frac; let wave = (x_phase + travel + s as f64 * 0.05).sin() as f32; let row = (center + half * env * scale * wave).round() as i32; @@ -1718,8 +1783,12 @@ pub(crate) fn visualizer_i420( let amp = (w.min(h) as f32) * 0.18; let tau = std::f32::consts::TAU; let steps = w.max(h) * 4; - for strand in 0..8u8 { - let (ir, ig, ib) = viz_ink_rgb(viz_hue(flags).wrapping_add(if strand < 4 { 0 } else { 8 })); + for strand in 0..viz_strands_of(paint) { + let (ir, ig, ib) = viz_ink_from_paint(if strand < viz_strands_of(paint) / 2 { + paint + } else { + with_viz_paint_hue(paint, viz_hue_ui(paint).wrapping_add(128)) + }); let (iy, iu, iv) = rgb_yuv(ir as i32, ig as i32, ib as i32); let scale = 0.65 + 0.35 * f32::from(strand % 4) / 3.0; let phase = f32::from(strand) * 0.35; @@ -2104,7 +2173,7 @@ mod tests { *p = (-a.abs(), a.abs()); } let flags = 1u8; - let (y, u, v) = visualizer_i420(&peaks, 1.0, 320, 180, flags); + let (y, u, v) = visualizer_i420(&peaks, 1.0, 320, 180, flags, 0); let ink = y.iter().filter(|&&p| p > 40).count(); assert!(ink > 200, "envelope missing: {ink}"); assert!(ink < y.len() * 9 / 10, "solid frame, not an envelope: {ink}"); @@ -2117,13 +2186,13 @@ mod tests { assert!(blue > 10, "default ink was not timeline blue: {blue}"); let ring = with_viz_style(flags, VIZ_STYLE_RING); - let (yr, _, _) = visualizer_i420(&peaks, 1.0, 320, 180, ring); + let (yr, _, _) = visualizer_i420(&peaks, 1.0, 320, 180, ring, 0); let ring_ink = yr.iter().filter(|&&p| p > 40).count(); assert!(ring_ink > 80, "ring missing: {ring_ink}"); assert!(ring_ink < ink, "ring should be a stroke, not a fill"); - let hue = with_viz_hue(flags, 8); - let (_, u2, v2) = visualizer_i420(&peaks, 1.0, 64, 32, hue); + let hue_paint = with_viz_paint_hue(0, 40); + let (_, u2, v2) = visualizer_i420(&peaks, 1.0, 64, 32, flags, hue_paint); let mut shifted = 0usize; for i in 0..u2.len() { if u2[i] < 120 && v2[i] > 130 { diff --git a/crates/engine/src/edith.rs b/crates/engine/src/edith.rs index 13043d3..c6575f5 100644 --- a/crates/engine/src/edith.rs +++ b/crates/engine/src/edith.rs @@ -118,7 +118,7 @@ //! its fit policy already placed. //! //! A lane line is ` -//! `: +//! `: //! which lane the clip is on -- its kind and its 1-based number //! among the lanes of that kind, the [`crate::project::Lane::label`] a header //! column shows -- then where the clip sits on the timeline, the half-open @@ -205,7 +205,7 @@ //! nothing, and an older one plays everything at real time, and an older one //! mixes flat, and an older one shows no subtitles, and an older one is shown //! in the reference rendition, and an older one places none of the words it -//! names -- and saving any of them writes v21. An older +//! names -- and saving any of them writes v22. An older //! reader refuses a newer file by name. //! //! Text because an edit list is a few integers and a path, and a path is @@ -242,7 +242,8 @@ use crate::transform::TransformParams; /// What [`save`] writes. Read support goes back to `edith 1`; see the module /// docs for what those dialects looked like. -const MAGIC: &[u8] = b"edith 21"; +const MAGIC: &[u8] = b"edith 22"; +const MAGIC_V21: &[u8] = b"edith 21"; const MAGIC_V20: &[u8] = b"edith 20"; const MAGIC_V19: &[u8] = b"edith 19"; const MAGIC_V18: &[u8] = b"edith 18"; @@ -595,7 +596,7 @@ fn emit( let transform = c.transform.map_or("-".to_string(), |e| e.to_string()); out.extend_from_slice( format!( - "{keyword} {ord} {} {} {} {} {link} {eq} {color} {} {} {} {} {} {transform} {}\n", + "{keyword} {ord} {} {} {} {} {link} {eq} {color} {} {} {} {} {} {transform} {} {}\n", c.start, c.in_frame, c.out_frame, @@ -606,6 +607,7 @@ fn emit( c.fade_out, c.transition_out, c.visualizer, + c.viz_paint, ) .as_bytes(), ); @@ -648,8 +650,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { // The dialects that wrote a source line without its stream field. Reading // one is the whole of what "an old project still opens" means here. let streamless = v1 || first == MAGIC_V2; + // The one that carries packed visualizer paint (hue/sat/strands/glow)... + let v22 = first == MAGIC; // The one that carries per-clip visualizer flags... - let v21 = first == MAGIC; + let v21 = v22 || first == MAGIC_V21; // The one that carries a per-clip transform (position/scale/rotate/crop)... let v20 = v21 || first == MAGIC_V20; // ...the one that carries a per-clip cross-dissolve into its successor... @@ -1053,6 +1057,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: queued, in_frame: number(f[0], n)?, out_frame: number(f[1], n)?, @@ -1184,7 +1189,8 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { + 2 * usize::from(v18) + usize::from(v19) + usize::from(v20) - + usize::from(v21); + + usize::from(v21) + + usize::from(v22); let f = fields(rest, want, "clip", n)?; let in_frame = number(f[1], n)?; let out_frame = number(f[2], n)?; @@ -1200,6 +1206,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { fade_out: number(f.get(10).copied().unwrap_or(b"0"), n)?.min(frames), transition_out: number(f.get(11).copied().unwrap_or(b"0"), n)?.min(frames), visualizer: number(f.get(13).copied().unwrap_or(b"0"), n)? as u8, + viz_paint: number(f.get(14).copied().unwrap_or(b"0"), n)? as u32, start: number(f[0], n)?, in_frame, out_frame, @@ -1629,7 +1636,7 @@ mod tests { video 1 0 0 30 0 - - - fit 1000\n"; let old = parse(v9, &dir).expect("v9 still loads"); assert_eq!(old.subtitles, Vec::new()); - assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 21\n")); + assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 22\n")); // ...and the line itself is not a v9 line: a dialect may not be mixed. let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir) .unwrap_err() @@ -2049,6 +2056,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame, out_frame, @@ -2108,10 +2116,10 @@ mod tests { let bytes = flat(&dir, &sources, &lanes, 12); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 21\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 22\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ source 2 /elsewhere/b.mp4\n\ - video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 - 0\n\ - audio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0\n", + video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 - 0 0\n\ + audio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\n", "the file under the project directory is written relative to it, \ each with the audio stream it plays" ); @@ -2145,9 +2153,9 @@ mod tests { let bytes = flat(&dir, &sources, &lanes, 7); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 21\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\ - video 1 0 0 30 0 4 - - fit 1000 0 0 0 - 0\naudio 1\n\ - video 2 40 0 10 0 - - - fit 1000 0 0 0 - 0\naudio 2 0 0 30 0 4 - - fit 1000 0 0 0 - 0\n", + "edith 22\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\ + video 1 0 0 30 0 4 - - fit 1000 0 0 0 - 0 0\naudio 1\n\ + video 2 40 0 10 0 - - - fit 1000 0 0 0 - 0 0\naudio 2 0 0 30 0 4 - - fit 1000 0 0 0 - 0 0\n", "an empty lane is a line of its own; everything else is its clips" ); let back = parse(&bytes, &dir).expect("parse"); @@ -2235,6 +2243,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, eq: Some(0), ..clip(0, 0, 30, 0, Some(0)) }, @@ -2243,6 +2252,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, eq: Some(1), ..clip(30, 10, 20, 0, None) }, @@ -2253,6 +2263,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, eq: Some(0), ..clip(0, 0, 30, 0, Some(0)) }, @@ -2261,6 +2272,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, eq: Some(2), ..clip(30, 0, 10, 0, None) }, @@ -2269,12 +2281,12 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 21\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ eq 16777215.0:-0.1:3.918315e-39:hs\n\ eq\n\ - video 1 0 0 30 0 0 0 - fit 1000 0 0 0 - 0\nvideo 1 30 10 20 0 - 1 - fit 1000 0 0 0 - 0\n\ - audio 1 0 0 30 0 0 0 - fit 1000 0 0 0 - 0\naudio 1 30 0 10 0 - 2 - fit 1000 0 0 0 - 0\n", + video 1 0 0 30 0 0 0 - fit 1000 0 0 0 - 0 0\nvideo 1 30 10 20 0 - 1 - fit 1000 0 0 0 - 0 0\n\ + audio 1 0 0 30 0 0 0 - fit 1000 0 0 0 - 0 0\naudio 1 30 0 10 0 - 2 - fit 1000 0 0 0 - 0 0\n", "the table comes before the clips, and a clip names a line of it" ); @@ -2347,6 +2359,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, color: Some(0), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2357,6 +2370,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, color: Some(1), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2369,6 +2383,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, color: Some(0), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2379,6 +2394,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, color: Some(2), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2389,12 +2405,12 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 21\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ color 0.1:1.2:0.9:-0.3\n\ color -1e-7:16777215.0:3.918315e-39:-0.0\n\ color 0.0:1.0:1.0:0.0\n\ - video 1 0 0 30 0 0 - 0 fit 1000 0 0 0 - 0\nvideo 1 30 10 20 0 - - 1 fit 1000 0 0 0 - 0\n\ - audio 1 0 0 30 0 0 - 0 fit 1000 0 0 0 - 0\naudio 1 30 0 10 0 - - 2 fit 1000 0 0 0 - 0\n", + video 1 0 0 30 0 0 - 0 fit 1000 0 0 0 - 0 0\nvideo 1 30 10 20 0 - - 1 fit 1000 0 0 0 - 0 0\n\ + audio 1 0 0 30 0 0 - 0 fit 1000 0 0 0 - 0 0\naudio 1 30 0 10 0 - - 2 fit 1000 0 0 0 - 0 0\n", "the table comes before the clips, and a clip names a line of it" ); @@ -2454,9 +2470,9 @@ mod tests { (1280, 720), old.playhead )), - "edith 21\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 22\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ eq 80.0:-3.0:0.707:ls\n\ - video 1 0 0 30 0 0 0 - fit 1000 0 0 0 - 0\naudio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0\n" + video 1 0 0 30 0 0 0 - fit 1000 0 0 0 - 0 0\naudio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\n" ); } @@ -2473,6 +2489,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame, out_frame, @@ -2497,9 +2514,9 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 21\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ - video 1 0 0 30 0 - - - fit 2000 0 0 0 - 0\nvideo 1 15 30 40 0 - - - fit 250 0 0 0 - 0\n\ - audio 1 0 0 30 0 - - - fit 2000 0 0 0 - 0\n", + "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + video 1 0 0 30 0 - - - fit 2000 0 0 0 - 0 0\nvideo 1 15 30 40 0 - - - fit 250 0 0 0 - 0 0\n\ + audio 1 0 0 30 0 - - - fit 2000 0 0 0 - 0 0\n", "the rate is the clip line's last field, in thousandths" ); let back = parse(&bytes, &dir).expect("parse"); @@ -2526,8 +2543,8 @@ mod tests { (1280, 720), old.playhead )), - "edith 21\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ - video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0\naudio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0\n" + "edith 22\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ + video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\naudio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\n" ); // A rate outside what the editor can set is a corrupt line, by name. let bad = b"edith 8\nsource 0 a.mp4\nvideo 1 0 0 30 0 - - - fit 9000\n"; @@ -2561,6 +2578,7 @@ mod tests { fade_out: 7, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: 30, @@ -2576,8 +2594,8 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 21\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ - video 1 0 0 30 0 - - - fit 1000 5 7 0 - 0\n", + "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + video 1 0 0 30 0 - - - fit 1000 5 7 0 - 0 0\n", "the fades are the clip line's last two fields" ); let back = parse(&bytes, &dir).expect("parse"); @@ -2613,6 +2631,7 @@ mod tests { fade_out: 0, transition_out: 9, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: 30, @@ -2628,8 +2647,8 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 21\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ - video 1 0 0 30 0 - - - fit 1000 0 0 9 - 0\n", + "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + video 1 0 0 30 0 - - - fit 1000 0 0 9 - 0 0\n", "the dissolve is the clip line's own last field" ); let back = parse(&bytes, &dir).expect("parse"); @@ -2701,6 +2720,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, transform: Some(0), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2711,6 +2731,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, transform: Some(1), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2723,6 +2744,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, transform: Some(0), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2733,6 +2755,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, transform: Some(2), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2762,12 +2785,12 @@ mod tests { ); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 21\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ transform 0.1:-0.2:1.5:90.0:0.1:0.0:0.0:0.05\n\ transform -1e-7:16777215.0:3.918315e-39:-0.0:0.0:0.0:0.0:0.0\n\ transform 0.0:0.0:1.0:0.0:0.0:0.0:0.0:0.0\n\ - video 1 0 0 30 0 0 - - fit 1000 0 0 0 0 0\nvideo 1 30 10 20 0 - - - fit 1000 0 0 0 1 0\n\ - audio 1 0 0 30 0 0 - - fit 1000 0 0 0 0 0\naudio 1 30 0 10 0 - - - fit 1000 0 0 0 2 0\n", + video 1 0 0 30 0 0 - - fit 1000 0 0 0 0 0 0\nvideo 1 30 10 20 0 - - - fit 1000 0 0 0 1 0 0\n\ + audio 1 0 0 30 0 0 - - fit 1000 0 0 0 0 0 0\naudio 1 30 0 10 0 - - - fit 1000 0 0 0 2 0 0\n", "the table comes before the clips, and a clip names a line of it" ); @@ -2842,10 +2865,10 @@ mod tests { ); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 21\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\ + "edith 22\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\ limiter -1.5 on\nsource 0 a.mp4\n\ - video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 - 0\n\ - audio 2 0 0 30 0 - - - fit 1000 0 0 0 - 0\n\ + video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n\ + audio 2 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n\ gain audio 1 3.0\ngain audio 2 -6.5\n", "the mix is lines of its own, the gains after the lanes they name" ); @@ -2874,8 +2897,8 @@ mod tests { (1280, 720), old.playhead )), - "edith 21\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ - video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 - 0\n" + "edith 22\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ + video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n" ); // Each of the three refuses by name, on its own line. @@ -3038,10 +3061,10 @@ mod tests { assert!(old.eq.is_empty(), "nothing before v5 equalizes anything"); assert_eq!( String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)), - "edith 21\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 22\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ source 2 /elsewhere/b.mp4\n\ - video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 - 0\n\ - audio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0\n" + video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 - 0 0\n\ + audio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\n" ); // An empty lane's line is still the whole of that lane, eq or no eq. let empty = parse( @@ -3091,10 +3114,10 @@ mod tests { let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); assert_eq!( String::from_utf8_lossy(&v5), - "edith 21\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 22\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ source 0 /elsewhere/b.mp4\n\ - video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 - 0\n\ - audio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0\n", + video 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 - 0 0\n\ + audio 1 0 0 30 0 0 - - fit 1000 0 0 0 - 0 0\n", "a re-saved v2 project differs only by its version, the lane \ numbers, the streams it always meant and an equalizer it has none of" ); @@ -3123,7 +3146,7 @@ mod tests { // Saved again it is the current version, which round-trips to the // same document. let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); - assert!(v5.starts_with(b"edith 21\n")); + assert!(v5.starts_with(b"edith 22\n")); let again = parse(&v5, &dir).expect("v5 parses"); assert_eq!(again.lanes, back.lanes); // A dialect may not be mixed: lane lines under v1, `clip` under v2. @@ -3234,8 +3257,8 @@ mod tests { let bytes = std::fs::read(&path).expect("read back"); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 21\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\ - video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 - 0\n" + "edith 22\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\ + video 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 - 0 0\n" ); // Loading rejoins the *given* directory, so the file is reached by the // way the project was opened -- the same file, through the link, still @@ -3279,10 +3302,10 @@ mod tests { #[test] fn a_wrong_first_line_is_refused_by_name() { let dir = PathBuf::from("/proj"); - let err = parse(b"edith 22\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir) + let err = parse(b"edith 23\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir) .unwrap_err() .to_string(); - assert_eq!(err, "line 1: unsupported version 22"); + assert_eq!(err, "line 1: unsupported version 23"); for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] { assert_eq!( parse(junk, &dir).unwrap_err().to_string(), diff --git a/crates/engine/src/export.rs b/crates/engine/src/export.rs index 48749a1..41411c3 100644 --- a/crates/engine/src/export.rs +++ b/crates/engine/src/export.rs @@ -2770,6 +2770,7 @@ fn run( meta.height, meta.frame_rate, flags, + project.composite_viz_paint_at(span.start), )? } else { ClipDecoder::open(&entry.path, rate.source_at(in_frame), want)? @@ -2839,6 +2840,7 @@ fn run( meta.height, meta.frame_rate, project.composite_visualizer_at(b_start), + project.composite_viz_paint_at(b_start), )? } else { ClipDecoder::open(&entry.path, b_rate.source_at(b_in_frame), None)? @@ -4424,6 +4426,7 @@ enum ClipDecoder { fps: f64, next: u32, flags: u8, + paint: u32, y: Vec, u: Vec, v: Vec, @@ -4537,6 +4540,7 @@ impl ClipDecoder { height: u32, fps: f64, flags: u8, + paint: u32, ) -> crate::Result { let peaks = crate::waveform::peaks(path, stream, crate::decode::VIZ_BUCKETS_PER_SEC) .ok() @@ -4550,6 +4554,7 @@ impl ClipDecoder { fps, next: start_frame, flags, + paint, y: Vec::new(), u: Vec::new(), v: Vec::new(), @@ -4571,12 +4576,13 @@ impl ClipDecoder { fps, next, flags, + paint, y, u, v, } => { let (yy, uu, vv) = - crate::decode::visualizer_i420(peaks, f64::from(*next) / *fps, *width, *height, *flags); + crate::decode::visualizer_i420(peaks, f64::from(*next) / *fps, *width, *height, *flags, *paint); *y = yy; *u = uu; *v = vv; diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index e663583..392b765 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -708,6 +708,7 @@ impl PlaybackSession { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: meta.frame_count, @@ -799,6 +800,7 @@ impl PlaybackSession { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: place_frames(meta.frame_count, IMAGE_ONLY_RATE), @@ -1864,6 +1866,7 @@ impl PlaybackSession { self.project.composite_fit_at(start), ), self.project.composite_visualizer_at(start), + self.project.composite_viz_paint_at(start), ) .inspect_err(|e| { eprintln!("timeline frame {start}: visualizer open failed: {e}") @@ -2981,6 +2984,10 @@ impl PlaybackSession { self.edit(Dirty::Picture, |p| p.set_visualizer(lane, idx, flags)) } + pub fn set_viz_paint(&mut self, lane: Lane, idx: usize, paint: u32) -> bool { + self.edit(Dirty::Picture, |p| p.set_viz_paint(lane, idx, paint)) + } + /// Timeline frames of ramp-up from silence at the start of the clip at /// `idx` of `lane`. `0` for an index that is not there. pub fn fade_in_of(&self, lane: Lane, idx: usize) -> u32 { @@ -3113,6 +3120,7 @@ impl PlaybackSession { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: match image { @@ -3307,6 +3315,7 @@ impl PlaybackSession { fade_out: 0, transition_out: 0, visualizer: 1, + viz_paint: 0, start: 0, in_frame, out_frame, diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 24824bd..644b4f9 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -457,10 +457,14 @@ pub struct Clip { /// because a clip's own length is checked beside it. pub transition_out: u32, /// Non-zero: this clip is a waveform of its source's sound, painted - /// onto a video lane. Bit 0 is the flag itself; 1 outline, 2 smooth, - /// 3 fast window, 4 tint. Zero is an ordinary picture. Older project - /// files have no field and mean zero. + /// onto a video lane. Bit 0 is the flag; bits 1-2 style; bit 3 fast. + /// Zero is an ordinary picture. Older project files have no field and + /// mean zero. pub visualizer: u8, + /// Packed look: hue 0-255, sat 0-255, strands 0-255, glow 0-255. + /// All-zero is the default (timeline azure, full sat, 8 strands, glow 2). + /// Older files have no field and mean zero. + pub viz_paint: u32, } impl Clip { @@ -947,6 +951,7 @@ impl Project { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: frame_count.max(1), @@ -1347,6 +1352,7 @@ impl Project { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame: 0, out_frame: frame_count.max(1), @@ -2647,6 +2653,15 @@ impl Project { true } + pub fn set_viz_paint(&mut self, lane: Lane, idx: usize, paint: u32) -> bool { + if idx >= self.lane(lane).len() { + return false; + } + self.snapshot(); + self.lane_mut(lane).expect("checked above")[idx].viz_paint = paint; + true + } + /// Timeline frames of ramp-up from silence at the start of the clip at /// `idx` of `lane`. `0` for an index that is not there, same as a clip /// that has none. @@ -3034,6 +3049,12 @@ impl Project { .unwrap_or(0) } + pub fn composite_viz_paint_at(&self, timeline_frame: u32) -> u32 { + self.composite_clip_at(timeline_frame) + .map(|(lane, idx)| self.lane(lane)[idx].viz_paint) + .unwrap_or(0) + } + /// [`spans_from`](Project::spans_from) over the composite: every stretch the /// viewer sees from `timeline_frame` to the end, in order. What an export /// encodes and what playback walks at a clip boundary. @@ -5711,6 +5732,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame, out_frame, @@ -7222,6 +7244,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 100, out_frame: 102, @@ -7299,6 +7322,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, source: wav, ..PASTED }; @@ -8014,6 +8038,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame, out_frame, @@ -9123,6 +9148,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, eq: Some(i), ..video[0] }] @@ -9166,6 +9192,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, color: Some(i), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -9231,6 +9258,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame, out_frame, @@ -10030,6 +10058,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame: start, out_frame: end, diff --git a/crates/engine/src/proxy.rs b/crates/engine/src/proxy.rs index 3eaf28b..9e48396 100644 --- a/crates/engine/src/proxy.rs +++ b/crates/engine/src/proxy.rs @@ -560,6 +560,7 @@ fn started( fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: meta.frame_count.max(1), diff --git a/crates/engine/src/silence.rs b/crates/engine/src/silence.rs index 88ca142..3691cb0 100644 --- a/crates/engine/src/silence.rs +++ b/crates/engine/src/silence.rs @@ -323,6 +323,7 @@ mod tests { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame, out_frame, diff --git a/crates/engine/src/sweep.rs b/crates/engine/src/sweep.rs index 79b1bd0..5ad811b 100644 --- a/crates/engine/src/sweep.rs +++ b/crates/engine/src/sweep.rs @@ -70,6 +70,7 @@ fn clip(start: u32, in_frame: u32, out_frame: u32) -> Clip { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame, out_frame, diff --git a/crates/engine/tests/audio_export.rs b/crates/engine/tests/audio_export.rs index 53694d0..5768258 100644 --- a/crates/engine/tests/audio_export.rs +++ b/crates/engine/tests/audio_export.rs @@ -65,6 +65,7 @@ fn mixed_project() -> Project { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame: 0, out_frame: 30, @@ -92,6 +93,7 @@ fn mixed_project() -> Project { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: 90, @@ -342,6 +344,7 @@ fn a_still_and_a_song_export_as_an_mp4_with_sound() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: frames, @@ -412,6 +415,7 @@ fn a_fader_is_one_tracks_own_and_the_limiter_holds_the_sum() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: 30, @@ -654,6 +658,7 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: 60, @@ -673,6 +678,7 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: 60, @@ -734,6 +740,7 @@ fn a_silent_clip_exports_as_silence_over_its_own_span() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame: 0, out_frame: 30, @@ -832,6 +839,7 @@ fn a_51_ac3_source_round_trips_through_a_wav() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: 30, @@ -966,6 +974,7 @@ fn a_fade_in_reaches_the_exported_audio() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: 90, // 3.0 s at 30 fps @@ -1052,6 +1061,7 @@ fn a_split_and_crossfaded_clip_has_no_muted_interior() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame, out_frame, @@ -1159,6 +1169,7 @@ fn a_mono_timeline_exports_as_dual_mono_ogg() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: 30, diff --git a/crates/engine/tests/audio_files.rs b/crates/engine/tests/audio_files.rs index 7705786..06ef38c 100644 --- a/crates/engine/tests/audio_files.rs +++ b/crates/engine/tests/audio_files.rs @@ -421,6 +421,7 @@ fn a_silent_first_source_does_not_stop_the_scan_for_one_with_sound() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: meta1.frame_count, diff --git a/crates/engine/tests/eq_audio.rs b/crates/engine/tests/eq_audio.rs index 8078bf2..f7127bf 100644 --- a/crates/engine/tests/eq_audio.rs +++ b/crates/engine/tests/eq_audio.rs @@ -58,6 +58,7 @@ fn clip(start: u32, source: usize, frames: u32) -> Clip { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame: 0, out_frame: frames, diff --git a/crates/engine/tests/export.rs b/crates/engine/tests/export.rs index 5220daf..fa876c4 100644 --- a/crates/engine/tests/export.rs +++ b/crates/engine/tests/export.rs @@ -241,6 +241,7 @@ fn exports_at_the_project_resolution_with_the_watched_geometry() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start, in_frame: 0, out_frame: 10, @@ -329,6 +330,7 @@ fn exports_the_audio_stream_the_timeline_plays() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: meta.frame_count, diff --git a/crates/engine/tests/lanes.rs b/crates/engine/tests/lanes.rs index 03cd6d3..9b8a65d 100644 --- a/crates/engine/tests/lanes.rs +++ b/crates/engine/tests/lanes.rs @@ -238,6 +238,7 @@ fn the_mp4_copy_follows_the_lane_that_holds_the_sound() { fade_in: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, fade_out: 0, start: 0, in_frame: 0, @@ -306,6 +307,7 @@ fn two_audio_lanes_are_summed() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: TOP_IN, in_frame: TOP_IN, out_frame: TOP_OUT, diff --git a/crates/engine/tests/opus_export.rs b/crates/engine/tests/opus_export.rs index fc827f0..b8e4bb3 100644 --- a/crates/engine/tests/opus_export.rs +++ b/crates/engine/tests/opus_export.rs @@ -86,6 +86,7 @@ fn project(video: &Path, sound: &Path, sound_in: u32) -> Project { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame, out_frame, @@ -471,6 +472,7 @@ fn a_copied_picture_names_the_sound_it_was_written_with() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame, diff --git a/crates/engine/tests/silence.rs b/crates/engine/tests/silence.rs index d2d49cd..5ddfce9 100644 --- a/crates/engine/tests/silence.rs +++ b/crates/engine/tests/silence.rs @@ -142,6 +142,7 @@ fn speed_mode_refuses_a_clip_that_laps_over_a_silence() { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: 20, @@ -182,6 +183,7 @@ fn whole(source: usize, frames: u32) -> Clip { fade_out: 0, transition_out: 0, visualizer: 0, + viz_paint: 0, start: 0, in_frame: 0, out_frame: frames,