diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index b831785..392c9d5 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -220,6 +220,11 @@ struct Player { /// focused, and does nothing to the keymap once it is not. pub(crate) dock_filter: String, pub(crate) dock_filter_edit: bool, + /// Type-to-filter on the KEYS tab. Owned the same way the Sources filter + /// is, except KEYS captures letters the moment the tab is showing -- the + /// list is a lookup, and a letter that still fired a spine action while + /// it was up is why search felt missing. + pub(crate) keys_filter: String, /// Which of the four sort chips is showing (MOCK-SPEC "Dock" §3). /// What is known about each source's audio, taken once and kept. Keyed on /// the path *and stream* -- two streams of one file are two envelopes -- and @@ -961,6 +966,7 @@ fn main() { dock_src_active: ui::dock_stance::load(), dock_filter: String::new(), dock_filter_edit: false, + keys_filter: String::new(), waves: HashMap::new(), thumbs: HashMap::new(), proxies: HashMap::new(), diff --git a/crates/app/src/menus.rs b/crates/app/src/menus.rs index 49997bc..7d0f97d 100644 --- a/crates/app/src/menus.rs +++ b/crates/app/src/menus.rs @@ -211,7 +211,7 @@ impl RowItem { /// action a stroke already reaches -- the menu is a second way *to* the actions /// and never a second version of them -- so both the label and the hint come /// out of the keymap registry and the two can never disagree. -pub(crate) const MENU_ITEMS: [ActionId; 17] = [ +pub(crate) const MENU_ITEMS: [ActionId; 20] = [ ActionId::Cut, // The cut machinery (DESIGN.md §6) on the very clip it is about: the // trims and the loop-trim were strokes the spine rail listed and nothing @@ -242,18 +242,20 @@ pub(crate) const MENU_ITEMS: [ActionId; 17] = [ ActionId::Visualizer, ActionId::Speed, ActionId::Fit, + // The group trio used to live only on chords + ctrl-click. A right-click + // that cannot group is a missing pointer door (the same class Fit and + // Redo shipped as). Dimmed in place when the selection cannot. + ActionId::Group, + ActionId::Detach, + ActionId::Regroup, // Last, under the rule line the render draws before the first of them // (DESIGN §9): the two that take the clip off the lane. ActionId::Delete, ActionId::Lift, ]; -// Not rows, and deliberately: the group trio (`Group`, `Detach`, `Regroup`) -// is the ctrl-click grammar plus its chords -- a group is made by picking the -// halves and taking it apart the same way -- and the mute is the *mix's*, -// which the transport already carries a button for. A clip menu is what this -// clip can be told (DESIGN §9, "Never a junk drawer"); those are told to the -// selection and to the project. +// Mute stays off this list: it is the mix's, which the transport already +// carries a button for. /// What a right-click on the bench itself offers -- the ruler and the empty /// stretch under the lanes. The verbs of the *timeline*: walking its cuts at @@ -319,6 +321,7 @@ pub(crate) fn destructive(action: ActionId) -> bool { /// A list rather than a loop inside the render, so the card and /// `every_action_is_on_the_actions_card` read the *same* order: an action that /// reaches no row fails a test instead of quietly becoming pointer-unreachable. +#[derive(Clone, Copy, Debug)] pub(crate) enum KeyRow { Head(keymap::Category), /// Click its label to do it, click its stroke to change that stroke. @@ -353,6 +356,53 @@ pub(crate) fn keys_rows() -> Vec { rows } +/// The KEYS tab's type-to-filter: keep a heading only when one of its rows +/// still matches, match a row on its label or its chord. +pub(crate) fn keys_rows_matching(query: &str, keymap: &keymap::Keymap) -> Vec { + let q = query.trim().to_ascii_lowercase(); + if q.is_empty() { + return keys_rows(); + } + let rows = keys_rows(); + let mut out = Vec::new(); + let mut i = 0; + while i < rows.len() { + match rows[i] { + KeyRow::Head(cat) => { + let mut kids = Vec::new(); + i += 1; + while i < rows.len() && !matches!(rows[i], KeyRow::Head(_)) { + if key_row_hits(&rows[i], &q, keymap) { + kids.push(rows[i]); + } + i += 1; + } + if !kids.is_empty() { + out.push(KeyRow::Head(cat)); + out.extend(kids); + } + } + _ => i += 1, + } + } + out +} + +fn key_row_hits(row: &KeyRow, q: &str, keymap: &keymap::Keymap) -> bool { + match *row { + KeyRow::Head(c) => c.label().to_ascii_lowercase().contains(q), + KeyRow::Act(a) => { + a.label().to_ascii_lowercase().contains(q) + || keymap.display(a).to_ascii_lowercase().contains(q) + } + KeyRow::Fixed(i) => { + let f = &keymap::FIXED[i]; + f.label.to_ascii_lowercase().contains(q) + || f.chord.to_ascii_lowercase().contains(q) + } + } +} + /// The character a stroke types into the actions card's search box, if it types /// one. gpui reports a printable key as itself and the space bar by name /// (platform.rs:866), and everything else -- the arrows, the function keys -- diff --git a/crates/app/src/oracle.rs b/crates/app/src/oracle.rs index c5195b2..720945d 100644 --- a/crates/app/src/oracle.rs +++ b/crates/app/src/oracle.rs @@ -240,9 +240,8 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { ActionId::Visualizer if ctx.image => Enable::Hidden("this clip is a still"), ActionId::Visualizer if ctx.no_sound => Enable::Hidden("this clip has no sound"), ActionId::Visualizer => match ctx.clip { - Some((_, lane)) if lane.kind == LaneKind::Audio => Enable::Yes, - Some(_) => Enable::Hidden("this clip is picture"), - None => Enable::No("select an audio clip"), + Some(_) => Enable::Yes, + None => Enable::No("select a clip with sound"), }, ActionId::Silence | ActionId::Mix if ctx.no_sound => { Enable::Hidden("this clip has no sound") diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index 22ac27f..3d02e7f 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -1372,6 +1372,7 @@ impl Player { /// "the" card and closing all of them are the same act. pub(crate) fn close_card(&mut self) { self.keys_open = false; + self.keys_filter.clear(); self.settings_open = false; self.export_open = false; // The two things typed *into* the export moment go with it: a field diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index 98f8f6e..42967bb 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -140,7 +140,7 @@ impl Player { return; } let Some((lane, idx)) = self.selected.anchor() else { - self.notify_user("NO VISUALIZER — select an audio clip".into()); + self.notify_user("NO VISUALIZER — select a clip with sound".into()); cx.notify(); return; }; @@ -151,13 +151,8 @@ impl Player { return; } Some(session) => { - if lane.kind != LaneKind::Audio { - self.notify_user("NO VISUALIZER — select an audio clip".into()); - cx.notify(); - return; - } let Some(clip) = session.lane_clips(lane).get(idx).copied() else { - self.notify_user("NO VISUALIZER — select an audio clip".into()); + self.notify_user("NO VISUALIZER — select a clip with sound".into()); cx.notify(); return; }; @@ -166,11 +161,6 @@ impl Player { cx.notify(); return; }; - if !engine::is_audio(&src.path) { - self.notify_user("NO VISUALIZER — this clip is not a sound file".into()); - cx.notify(); - return; - } session.place_visualizer( clip.start, &src.path, @@ -194,6 +184,25 @@ impl Player { cx.notify(); } + pub(crate) fn toggle_viz_flag(&mut self, bit: u8, cx: &mut Context) { + let Some((lane, idx)) = self.selected.anchor() else { + return; + }; + let Some(session) = &mut self.session else { + return; + }; + let Some(clip) = session.lane_clips(lane).get(idx).copied() else { + return; + }; + if clip.visualizer & 1 == 0 { + return; + } + if session.set_visualizer(lane, idx, clip.visualizer ^ bit) { + self.reset_after_reseek(); + } + cx.notify(); + } + /// Takes a library row's file out of the list, which is the one thing a row /// can lose. Refused in the engine's own words while clips still play from /// it -- and those words name the lanes holding them, so the refusal says diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index 8aed8d1..fcd90af 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -173,7 +173,7 @@ fn the_stances_key_guard_does_not_swallow_a_bare_export_before_the_oracle_is_ask /// fails, which is the only way that stays true as the editor grows. #[test] fn every_action_is_on_the_actions_card() { - use keymap::{ActionId, Category, Keymap}; + use keymap::{ActionId, Category}; let rows = keys_rows(); let listed: Vec = rows .iter() @@ -214,7 +214,7 @@ fn every_action_is_on_the_actions_card() { ); // Both columns say something: the label does the action, the stroke // beside it changes that stroke, and neither may read blank. - let keymap = Keymap::defaults(); + let keymap = keymap::Keymap::defaults(); for action in ActionId::ALL { assert!(!action.label().is_empty(), "{action:?}"); assert_ne!(keymap.display(action), "unbound", "{action:?}"); @@ -238,6 +238,16 @@ fn only_a_printable_stroke_types_into_the_search() { } } +#[test] +fn keys_search_keeps_matching_rows_and_drops_empty_heads() { + let km = keymap::Keymap::defaults(); + let cut = keys_rows_matching("cut", &km); + assert!(cut.iter().any(|r| matches!(r, KeyRow::Act(ActionId::Cut)))); + assert!(!cut.iter().any(|r| matches!(r, KeyRow::Act(ActionId::Play)))); + assert!(cut.iter().any(|r| matches!(r, KeyRow::Head(_)))); + assert!(keys_rows_matching("xyzzy-no-such", &km).is_empty()); +} + #[test] fn the_keybindings_card_fits_the_smallest_window() { // The row list is capped and scrolls, so the card's height no longer @@ -1372,6 +1382,7 @@ fn a_duration_row_shows_only_for_a_transition_and_its_room_is_the_successors() { fade_in, fade_out, transition_out, + visualizer: 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 797f8bf..6f328ec 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -335,11 +335,13 @@ fn a_caption_is_deleted_by_the_same_row_and_stroke_every_box_is() { menu_items(cap), vec![ ActionId::Paste, + ActionId::Group, + ActionId::Detach, // Below the rule line the render draws before it, like every // other row that takes something away (DESIGN §9). ActionId::Delete, ], - "the caption's menu is its removal and the one global row left", + "the caption's menu is its removal, the group pair, and paste", ); // ...and the same reading with a clip under it is the clip menu, untouched: // the flag is off wherever a `Clip` was clicked. @@ -628,6 +630,7 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 30, in_frame: 0, out_frame: 60, @@ -759,7 +762,7 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { // silence scan is, because it opens on the half it is grouped with. let picture = menu(v1, false, 60); assert!(!picture.contains(&ActionId::Equalizer), "{picture:?}"); - assert!(!picture.contains(&ActionId::Visualizer), "{picture:?}"); + assert!(picture.contains(&ActionId::Visualizer), "{picture:?}"); assert!(picture.contains(&ActionId::Color)); assert!(picture.contains(&ActionId::Fit)); assert!(picture.contains(&ActionId::Silence)); @@ -1062,6 +1065,7 @@ fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 30, in_frame: 0, out_frame: 60, @@ -1793,6 +1797,7 @@ fn a_copied_clip_is_renumbered_or_dropped_when_a_row_leaves_the_library() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: 30, @@ -1945,6 +1950,7 @@ fn trim_to_playhead_needs_a_subject_cut_with_the_playhead_on_it() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 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 5c8b048..980869c 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -746,6 +746,7 @@ fn a_drop_moves_the_clip_that_was_picked_up_not_its_old_index() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame: 0, out_frame: 30, @@ -2584,23 +2585,6 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() { accelerator for cycling that existing selection, not a new door -- legacy had no \ toolbar button for it either", ), - // The group trio: a group is *made* with the pointer already -- - // ctrl-click the halves and the grammar is the selection itself - // (DESIGN §9) -- so a row per verb in the clip menu was three rows - // saying what the click had already said. Chords and KEYS rows keep - // them reachable. - ( - ActionId::Group, - "made by ctrl-clicking the halves: the selection is the grammar", - ), - ( - ActionId::Detach, - "made by ctrl-clicking the halves: the selection is the grammar", - ), - ( - ActionId::Regroup, - "made by ctrl-clicking the halves: the selection is the grammar", - ), // The keyboard's own trim: `^[` and `^]` do with a stroke what the // pointer does by dragging the clip edge to the spot it wants, and // that drag is the door -- a menu row for it would be a second name @@ -3271,7 +3255,7 @@ fn the_keys_list_is_dock_body_state_not_a_tab() { "the keys list draws no KEYS head in the dock body" ); assert!( - dock.contains("fn keys_tab(") && dock.contains("keys_rows()"), + dock.contains("fn keys_tab(") && dock.contains("keys_rows_matching("), "the KEYS tab draws something other than the action registry" ); assert!( @@ -3580,6 +3564,7 @@ fn the_cut_readout_counts_from_the_playhead() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame: 0, out_frame: len, diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 098c271..0d1364f 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -25,7 +25,7 @@ use super::{ clipboard_after_remove, color_snap, containers, destructive, enable, enable_lane, envelope, eq_card_w, eq_freq, eq_freq_label, eq_graph_h, eq_spectrum, eq_x, eq_y, estimated_bytes, export_path, export_settings, format_refusal, fps_choices, fps_label, frac_along, frac_down, - frame_at, frame_rate_ladder, histogram, inserted_band, is_project, keymap, keys_rows, lanes_h, + frame_at, frame_rate_ladder, histogram, inserted_band, is_project, keymap, keys_rows, keys_rows_matching, lanes_h, lane_items, marked, menu_at, menu_items, menu_rows_h, next_container, normalise, nothing_to_play, notice_tone, panel_h, parse_budget, project_path, range_word, proxies_to_start, push_notice, px_below, retarget, row_enable, row_items, scrub_due, secs_label, should_resync, silence_rate, size_label, diff --git a/crates/app/src/tests/view.rs b/crates/app/src/tests/view.rs index baa14b0..c83d34d 100644 --- a/crates/app/src/tests/view.rs +++ b/crates/app/src/tests/view.rs @@ -157,6 +157,7 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 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 b258332..460a36d 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -888,6 +888,7 @@ mod drop_landing_tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 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 2c897fe..d7a89a5 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -1187,6 +1187,71 @@ fn transition_row(player: &Player, cx: &mut Context) -> Option) -> impl IntoElement { + let flags = 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) + }); + let Some(flags) = flags else { + return div().id("dock-viz-styles"); + }; + let bit = |id: &'static str, label_text: &'static str, bit: u8, on: bool| { + let style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); + div() + .id(id) + .flex_none() + .h(px(CONTROL_H)) + .px(px(8.)) + .flex() + .items_center() + .cursor_pointer() + .text_color(rgb(if on { INK1() } else { INK3() })) + .font(style.font) + .text_size(style.size) + .children(hitmap::control(id, label_text, true)) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.toggle_viz_flag(bit, cx); + })) + .child(if on { + format!("· {label_text}") + } else { + label_text.to_string() + }) + .into_any_element() + }; + div() + .id("dock-viz-styles") + .flex_none() + .flex() + .flex_col() + .gap(px(2.)) + .child(bit( + "dock-viz-outline", + "Outline", + engine::decode::VIZ_OUTLINE, + flags & engine::decode::VIZ_OUTLINE != 0, + )) + .child(bit( + "dock-viz-smooth", + "Smooth", + engine::decode::VIZ_SMOOTH, + flags & engine::decode::VIZ_SMOOTH != 0, + )) + .child(bit( + "dock-viz-fast", + "Fast", + engine::decode::VIZ_FAST, + flags & engine::decode::VIZ_FAST != 0, + )) + .child(bit( + "dock-viz-tint", + "Colour", + engine::decode::VIZ_TINT, + flags & engine::decode::VIZ_TINT != 0, + )) +} + fn clip_tab( player: &Player, width: f32, @@ -1301,7 +1366,8 @@ fn clip_tab( false, player, cx.listener(|this, _: &ClickEvent, _, cx| this.cycle_fit(cx)), - )), + )) + .child(viz_style_verbs(player, cx)), ) .children(transition_row(player, cx)) .child( @@ -1416,7 +1482,23 @@ fn keys_tab(player: &Player, cx: &mut Context) -> impl IntoElement { // The list no longer wears a tab, so it says its own name the way // every other dock body section does -- MEDIA / IMPORT's head. .child(section_head("KEYS")) - .children(keys_rows().into_iter().map(|row| match row { + .child({ + let style = mono(type_scale::CHORD_METADATA_MAX_PX, FontWeight::MEDIUM); + let filter_text: SharedString = player.keys_filter.clone().into(); + div() + .id("dock-keys-filter") + .flex_none() + .cursor_text() + .font(style.font) + .text_size(style.size) + .text_color(rgb(INK1())) + .children(hitmap::control("dock.keys-filter", "Filter keys", true)) + .child(match player.keys_filter.is_empty() { + true => "⌕".to_string(), + false => format!("⌕ {filter_text}"), + }) + }) + .children(keys_rows_matching(&player.keys_filter, &player.keymap).into_iter().map(|row| match row { KeyRow::Head(category) => div() .flex_none() .pt(px(4.)) diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index 915ca16..3c7bcd6 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -1012,10 +1012,26 @@ pub(crate) fn render( // the third): only when no card is up, so escape still shuts a // card first -- the KEYS tab is a dock tab now, not an overlay, // and nothing about it owns the keyboard. - if key == "escape" && this.keys_open && !this.card_open() { - this.keys_open = false; - cx.notify(); - return; + if this.keys_open && !this.card_open() { + if key == "escape" { + if this.keys_filter.is_empty() { + this.keys_open = false; + } else { + this.keys_filter.clear(); + } + cx.notify(); + return; + } + if key == "backspace" { + this.keys_filter.pop(); + cx.notify(); + return; + } + if let Some(c) = typed(key) { + this.keys_filter.push(c); + cx.notify(); + return; + } } // The dock's Sources filter (MOCK-SPEC "Dock" §2), the same door // legacy `render.rs` gives it: owns the keyboard only while it diff --git a/crates/engine/examples/bench.rs b/crates/engine/examples/bench.rs index 31f41de..9e5fc6c 100644 --- a/crates/engine/examples/bench.rs +++ b/crates/engine/examples/bench.rs @@ -863,6 +863,7 @@ fn export_bench(path: &Path, seat: &str, out_dir: &Path) { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 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 a6abe0b..f8bcdbb 100644 --- a/crates/engine/src/decode.rs +++ b/crates/engine/src/decode.rs @@ -628,6 +628,7 @@ impl DecodeSession { color: ColorParams, transform: TransformParams, canvas: Composer, + flags: u8, ) -> crate::Result { let (tx, rx) = sync_channel(2); let cancel = Arc::new(AtomicBool::new(false)); @@ -678,7 +679,7 @@ impl DecodeSession { return; } let t = f64::from(start_frame + index) / fps; - let (y, u, v) = visualizer_i420(&peaks, t, width, height); + let (y, u, v) = visualizer_i420(&peaks, t, width, height, flags); let frame = render.frame(start_frame + index, &y, &u, &v, width, height); if tx.send(frame).is_err() { return; // caller moved on @@ -1408,6 +1409,10 @@ fn rgb_to_i420(rgb: &[u8], width: usize, height: usize) -> (Vec, Vec, Ve /// caller that decodes them ([`DecodeSession::open_visualizer`], preview and /// export both) and the painter that reads them. pub(crate) const VIZ_BUCKETS_PER_SEC: u32 = 60; +pub const VIZ_OUTLINE: u8 = 1 << 1; +pub const VIZ_SMOOTH: u8 = 1 << 2; +pub const VIZ_FAST: u8 = 1 << 3; +pub const VIZ_TINT: u8 = 1 << 4; /// How much sound one visualizer frame shows, centered on the frame's own /// time: two seconds, so a glance reads the shape of the around-now rather @@ -1430,6 +1435,7 @@ pub(crate) fn visualizer_i420( t_secs: f64, width: u32, height: u32, + flags: u8, ) -> (Vec, Vec, Vec) { // Even dims, like every canvas this engine composes at: an odd caller is // shaved rather than handed chroma math it did not ask about. @@ -1438,8 +1444,8 @@ pub(crate) fn visualizer_i420( let (w, h) = (width as usize, height as usize); let (cw, ch) = crate::scale::chroma_dims(w, h); let mut y = vec![16u8; w * h]; - let u = vec![128u8; cw * ch]; - let v = vec![128u8; cw * ch]; + let mut u = vec![128u8; cw * ch]; + let mut v = vec![128u8; cw * ch]; let center = h / 2; let duration = peaks.len() as f64 / f64::from(VIZ_BUCKETS_PER_SEC); if peaks.is_empty() || !t_secs.is_finite() || !(0.0..=duration).contains(&t_secs) { @@ -1449,16 +1455,19 @@ pub(crate) fn visualizer_i420( return (y, u, v); } let per_sec = f64::from(VIZ_BUCKETS_PER_SEC); + let window = if flags & VIZ_FAST != 0 { 0.4 } else { VIZ_WINDOW_SECS }; // The window, clamped to the peaks that exist: a frame near either end // looks past the file's edge, and draws the part of the window that is // real rather than padding it out. - let first = (((t_secs - VIZ_WINDOW_SECS / 2.0).max(0.0) * per_sec).floor() as usize) + let first = (((t_secs - window / 2.0).max(0.0) * per_sec).floor() as usize) .min(peaks.len() - 1); - let last = ((((t_secs + VIZ_WINDOW_SECS / 2.0).min(duration) * per_sec).ceil() as usize) + let last = ((((t_secs + window / 2.0).min(duration) * per_sec).ceil() as usize) .clamp(first + 1, peaks.len())) .min(peaks.len()); let span = (last - first) as f64; let scale = center as f32; + let smooth = flags & VIZ_SMOOTH != 0; + let outline = flags & VIZ_OUTLINE != 0; for col in 0..w { // The buckets this column draws: at least one, whatever the window's // width is against the picture's -- a short clip stretches, a long @@ -1467,8 +1476,13 @@ pub(crate) fn visualizer_i420( let b1 = first + (((col + 1) as f64 * span / w as f64).ceil() as usize) .clamp(b0 - first + 1, last - first); + let (s0, s1) = if smooth { + (b0.saturating_sub(1), (b1 + 1).min(peaks.len())) + } else { + (b0, b1) + }; let (mut lo, mut hi) = (f32::INFINITY, f32::NEG_INFINITY); - for &(min, max) in &peaks[b0..b1] { + for &(min, max) in &peaks[s0..s1] { lo = lo.min(min); hi = hi.max(max); } @@ -1477,8 +1491,28 @@ pub(crate) fn visualizer_i420( let bottom = (scale - lo * scale).round(); let top = (top as isize).clamp(0, h as isize - 1) as usize; let bottom = (bottom as isize).clamp(top as isize, h as isize - 1) as usize; - for row in top..=bottom { - y[row * w + col] = 220; + if outline { + y[top * w + col] = 220; + y[bottom * w + col] = 220; + } else { + for row in top..=bottom { + y[row * w + col] = 220; + } + } + } + if flags & VIZ_TINT != 0 { + // Cyan on the ink, black stays black: chroma follows luma so a + // grade still reaches the bars around it. + for cy in 0..ch { + for cx in 0..cw { + let ink = y[cy * 2 * w + cx * 2] > 16 + || y[cy * 2 * w + cx * 2 + 1] > 16 + || y[(cy * 2 + 1).min(h - 1) * w + cx * 2] > 16; + if ink { + u[cy * cw + cx] = 80; + v[cy * cw + cx] = 80; + } + } } } (y, u, v) diff --git a/crates/engine/src/edith.rs b/crates/engine/src/edith.rs index 37ef4de..13043d3 100644 --- a/crates/engine/src/edith.rs +++ b/crates/engine/src/edith.rs @@ -31,7 +31,7 @@ //! ([`crate::PlaybackSession::set_frame_rate`]), and the *only* thing that says //! so once one was, since every clip number in the file is counted in it. //! Printed so it reads back bit-exactly. A file without one (every dialect -//! before v9) means "whatever the scaffolding source runs at", which is what +//! before v9) means 0"whatever the scaffolding source runs at", which is what //! such a project always was and is an answer only a project holding a video has //! ([`crate::PlaybackSession::open_project`]). //! @@ -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 @@ -134,7 +134,9 @@ //! ([`crate::project::Clip::transition_out`], `0` for a hard cut), and last of //! all the transform line it is placed, sized, turned and cropped by, on top //! of everything its fit policy already did (`-` for a clip left at its fit -//! policy's own spot, [`crate::project::Clip::transform`]). +//! policy's own spot, [`crate::project::Clip::transform`]), and a visualizer +//! flags byte (`0` for an ordinary picture, bit 0 for a waveform of the +//! source's sound, the rest outline/smooth/fast/tint). //! Timeline placement is //! explicit, so a *gap* is simply a stretch no line covers -- there is nothing //! to write for one, and nothing that can disagree about its length. The `` @@ -203,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 v20. An older +//! names -- and saving any of them writes v21. 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 @@ -240,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 20"; +const MAGIC: &[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"; const MAGIC_V17: &[u8] = b"edith 17"; @@ -592,7 +595,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, @@ -602,6 +605,7 @@ fn emit( c.fade_in, c.fade_out, c.transition_out, + c.visualizer, ) .as_bytes(), ); @@ -644,8 +648,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 per-clip visualizer flags... + let v21 = first == MAGIC; // The one that carries a per-clip transform (position/scale/rotate/crop)... - let v20 = first == MAGIC; + let v20 = v21 || first == MAGIC_V20; // ...the one that carries a per-clip cross-dissolve into its successor... let v19 = v20 || first == MAGIC_V19; // ...the one that carries a per-clip fade envelope... @@ -1046,6 +1052,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: queued, in_frame: number(f[0], n)?, out_frame: number(f[1], n)?, @@ -1176,7 +1183,8 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { + usize::from(v8) + 2 * usize::from(v18) + usize::from(v19) - + usize::from(v20); + + usize::from(v20) + + usize::from(v21); let f = fields(rest, want, "clip", n)?; let in_frame = number(f[1], n)?; let out_frame = number(f[2], n)?; @@ -1191,6 +1199,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { fade_in: number(f.get(9).copied().unwrap_or(b"0"), n)?.min(frames), 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, start: number(f[0], n)?, in_frame, out_frame, @@ -1620,7 +1629,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 20\n")); + assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 21\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() @@ -2039,6 +2048,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame, out_frame, @@ -2098,10 +2108,10 @@ mod tests { let bytes = flat(&dir, &sources, &lanes, 12); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 20\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 21\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 -\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 -\n\ - audio 1 0 0 30 0 0 - - fit 1000 0 0 0 -\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", "the file under the project directory is written relative to it, \ each with the audio stream it plays" ); @@ -2135,9 +2145,9 @@ mod tests { let bytes = flat(&dir, &sources, &lanes, 7); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 20\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\ - video 1 0 0 30 0 4 - - fit 1000 0 0 0 -\naudio 1\n\ - video 2 40 0 10 0 - - - fit 1000 0 0 0 -\naudio 2 0 0 30 0 4 - - fit 1000 0 0 0 -\n", + "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", "an empty lane is a line of its own; everything else is its clips" ); let back = parse(&bytes, &dir).expect("parse"); @@ -2224,6 +2234,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, eq: Some(0), ..clip(0, 0, 30, 0, Some(0)) }, @@ -2231,6 +2242,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, eq: Some(1), ..clip(30, 10, 20, 0, None) }, @@ -2240,6 +2252,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, eq: Some(0), ..clip(0, 0, 30, 0, Some(0)) }, @@ -2247,6 +2260,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, eq: Some(2), ..clip(30, 0, 10, 0, None) }, @@ -2255,12 +2269,12 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 20\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 21\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 -\nvideo 1 30 10 20 0 - 1 - fit 1000 0 0 0 -\n\ - audio 1 0 0 30 0 0 0 - fit 1000 0 0 0 -\naudio 1 30 0 10 0 - 2 - fit 1000 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", "the table comes before the clips, and a clip names a line of it" ); @@ -2332,6 +2346,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, color: Some(0), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2341,6 +2356,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, color: Some(1), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2352,6 +2368,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, color: Some(0), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2361,6 +2378,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, color: Some(2), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2371,12 +2389,12 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 20\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 21\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 -\nvideo 1 30 10 20 0 - - 1 fit 1000 0 0 0 -\n\ - audio 1 0 0 30 0 0 - 0 fit 1000 0 0 0 -\naudio 1 30 0 10 0 - - 2 fit 1000 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", "the table comes before the clips, and a clip names a line of it" ); @@ -2436,9 +2454,9 @@ mod tests { (1280, 720), old.playhead )), - "edith 20\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 21\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 -\naudio 1 0 0 30 0 0 - - fit 1000 0 0 0 -\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" ); } @@ -2454,6 +2472,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame, out_frame, @@ -2478,9 +2497,9 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 20\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ - video 1 0 0 30 0 - - - fit 2000 0 0 0 -\nvideo 1 15 30 40 0 - - - fit 250 0 0 0 -\n\ - audio 1 0 0 30 0 - - - fit 2000 0 0 0 -\n", + "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", "the rate is the clip line's last field, in thousandths" ); let back = parse(&bytes, &dir).expect("parse"); @@ -2507,8 +2526,8 @@ mod tests { (1280, 720), old.playhead )), - "edith 20\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ - video 1 0 0 30 0 0 - - fit 1000 0 0 0 -\naudio 1 0 0 30 0 0 - - fit 1000 0 0 0 -\n" + "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" ); // 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"; @@ -2541,6 +2560,7 @@ mod tests { fade_in: 5, fade_out: 7, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: 30, @@ -2556,8 +2576,8 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 20\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ - video 1 0 0 30 0 - - - fit 1000 5 7 0 -\n", + "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", "the fades are the clip line's last two fields" ); let back = parse(&bytes, &dir).expect("parse"); @@ -2592,6 +2612,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 9, + visualizer: 0, start: 0, in_frame: 0, out_frame: 30, @@ -2607,8 +2628,8 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 20\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ - video 1 0 0 30 0 - - - fit 1000 0 0 9 -\n", + "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", "the dissolve is the clip line's own last field" ); let back = parse(&bytes, &dir).expect("parse"); @@ -2679,6 +2700,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, transform: Some(0), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2688,6 +2710,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, transform: Some(1), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2699,6 +2722,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, transform: Some(0), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2708,6 +2732,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, transform: Some(2), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -2737,12 +2762,12 @@ mod tests { ); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 20\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 21\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\nvideo 1 30 10 20 0 - - - fit 1000 0 0 0 1\n\ - audio 1 0 0 30 0 0 - - fit 1000 0 0 0 0\naudio 1 30 0 10 0 - - - fit 1000 0 0 0 2\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", "the table comes before the clips, and a clip names a line of it" ); @@ -2817,10 +2842,10 @@ mod tests { ); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 20\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\ + "edith 21\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 -\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 -\n\ - audio 2 0 0 30 0 - - - fit 1000 0 0 0 -\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\ 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" ); @@ -2849,8 +2874,8 @@ mod tests { (1280, 720), old.playhead )), - "edith 20\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ - video 1 0 0 30 0 - - - fit 1000 0 0 0 -\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 -\n" + "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" ); // Each of the three refuses by name, on its own line. @@ -3013,10 +3038,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 20\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 21\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 -\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 -\n\ - audio 1 0 0 30 0 0 - - fit 1000 0 0 0 -\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" ); // An empty lane's line is still the whole of that lane, eq or no eq. let empty = parse( @@ -3066,10 +3091,10 @@ mod tests { let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); assert_eq!( String::from_utf8_lossy(&v5), - "edith 20\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 21\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 -\nvideo 1 30 10 20 1 1 - - fit 1000 0 0 0 -\n\ - audio 1 0 0 30 0 0 - - fit 1000 0 0 0 -\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", "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" ); @@ -3098,7 +3123,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 20\n")); + assert!(v5.starts_with(b"edith 21\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. @@ -3209,8 +3234,8 @@ mod tests { let bytes = std::fs::read(&path).expect("read back"); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 20\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\ - video 1 0 0 30 0 - - - fit 1000 0 0 0 -\naudio 1 0 0 30 0 - - - fit 1000 0 0 0 -\n" + "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" ); // Loading rejoins the *given* directory, so the file is reached by the // way the project was opened -- the same file, through the link, still @@ -3254,10 +3279,10 @@ mod tests { #[test] fn a_wrong_first_line_is_refused_by_name() { let dir = PathBuf::from("/proj"); - let err = parse(b"edith 21\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir) + let err = parse(b"edith 22\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir) .unwrap_err() .to_string(); - assert_eq!(err, "line 1: unsupported version 21"); + assert_eq!(err, "line 1: unsupported version 22"); 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 cf6fc2f..48749a1 100644 --- a/crates/engine/src/export.rs +++ b/crates/engine/src/export.rs @@ -2760,7 +2760,8 @@ fn run( let want = untouched.then(|| encoder.dma_want(meta)).flatten(); // Opened at the file's own frame, which is the only place the // file's numbering is used -- the span's are the timeline's. - let pictures = if crate::is_audio(&entry.path) { + let flags = project.composite_visualizer_at(span.start); + let pictures = if crate::is_audio(&entry.path) || flags & 1 != 0 { ClipDecoder::visualizer( &entry.path, entry.audio_stream, @@ -2768,6 +2769,7 @@ fn run( meta.width, meta.height, meta.frame_rate, + flags, )? } else { ClipDecoder::open(&entry.path, rate.source_at(in_frame), want)? @@ -2826,7 +2828,9 @@ fn run( Ok(Dissolve { window, tail_start: span.len - window, - decoder: if crate::is_audio(&entry.path) { + decoder: if crate::is_audio(&entry.path) + || project.composite_visualizer_at(b_start) & 1 != 0 + { ClipDecoder::visualizer( &entry.path, entry.audio_stream, @@ -2834,6 +2838,7 @@ fn run( meta.width, meta.height, meta.frame_rate, + project.composite_visualizer_at(b_start), )? } else { ClipDecoder::open(&entry.path, b_rate.source_at(b_in_frame), None)? @@ -4418,6 +4423,7 @@ enum ClipDecoder { height: u32, fps: f64, next: u32, + flags: u8, y: Vec, u: Vec, v: Vec, @@ -4530,6 +4536,7 @@ impl ClipDecoder { width: u32, height: u32, fps: f64, + flags: u8, ) -> crate::Result { let peaks = crate::waveform::peaks(path, stream, crate::decode::VIZ_BUCKETS_PER_SEC) .ok() @@ -4542,6 +4549,7 @@ impl ClipDecoder { height, fps, next: start_frame, + flags, y: Vec::new(), u: Vec::new(), v: Vec::new(), @@ -4562,12 +4570,13 @@ impl ClipDecoder { height, fps, next, + flags, y, u, v, } => { let (yy, uu, vv) = - crate::decode::visualizer_i420(peaks, f64::from(*next) / *fps, *width, *height); + crate::decode::visualizer_i420(peaks, f64::from(*next) / *fps, *width, *height, *flags); *y = yy; *u = uu; *v = vv; diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 687679e..e663583 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -707,6 +707,7 @@ impl PlaybackSession { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: meta.frame_count, @@ -797,6 +798,7 @@ impl PlaybackSession { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: place_frames(meta.frame_count, IMAGE_ONLY_RATE), @@ -1835,7 +1837,9 @@ impl PlaybackSession { start, from: Some((source, in_frame)), .. - }) if crate::is_audio(&self.project.sources()[source].path) => { + }) if crate::is_audio(&self.project.sources()[source].path) + || self.project.composite_visualizer_at(start) & 1 != 0 => + { let (path, stream) = { let src = &self.project.sources()[source]; (src.path.clone(), src.audio_stream) @@ -1859,6 +1863,7 @@ impl PlaybackSession { self.meta.height, self.project.composite_fit_at(start), ), + self.project.composite_visualizer_at(start), ) .inspect_err(|e| { eprintln!("timeline frame {start}: visualizer open failed: {e}") @@ -2970,6 +2975,12 @@ impl PlaybackSession { self.edit(Dirty::Picture, |p| p.set_fit(lane, idx, fit)) } + /// Waveform flags on a visualizer clip. Reseeks like a grade: the + /// painter reads them on the next picture. + pub fn set_visualizer(&mut self, lane: Lane, idx: usize, flags: u8) -> bool { + self.edit(Dirty::Picture, |p| p.set_visualizer(lane, idx, flags)) + } + /// 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 { @@ -3101,6 +3112,7 @@ impl PlaybackSession { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: match image { @@ -3270,13 +3282,6 @@ impl PlaybackSession { out_frame: u32, onto: Option, ) -> crate::Result { - if !crate::is_audio(path) { - return Err(format!( - "{} is not audio: a visualizer needs a sound file", - path.display() - ) - .into()); - } if out_frame <= in_frame { return Err("visualizer clip is empty".into()); } @@ -3301,6 +3306,7 @@ impl PlaybackSession { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 1, start: 0, in_frame, out_frame, diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 31d946c..24824bd 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -456,6 +456,11 @@ pub struct Clip { /// trusting this field alone, exactly as a stored fade is trusted only /// 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. + pub visualizer: u8, } impl Clip { @@ -941,6 +946,7 @@ impl Project { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: frame_count.max(1), @@ -1340,6 +1346,7 @@ impl Project { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame: 0, out_frame: frame_count.max(1), @@ -2628,6 +2635,18 @@ impl Project { true } + /// Waveform style flags on the clip at `idx` of `lane`. Bit 0 marks it + /// a visualizer; the rest are outline/smooth/fast/tint. `false` (no + /// history) for an index that is not there. + pub fn set_visualizer(&mut self, lane: Lane, idx: usize, flags: u8) -> bool { + if idx >= self.lane(lane).len() { + return false; + } + self.snapshot(); + self.lane_mut(lane).expect("checked above")[idx].visualizer = flags; + 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. @@ -3007,6 +3026,14 @@ impl Project { .map_or(FitPolicy::default(), |(lane, idx)| self.fit_of(lane, idx)) } + /// Waveform flags of the topmost video clip at `timeline_frame`, or 0 + /// over a gap / a picture that is not a visualizer. + pub fn composite_visualizer_at(&self, timeline_frame: u32) -> u8 { + self.composite_clip_at(timeline_frame) + .map(|(lane, idx)| self.lane(lane)[idx].visualizer) + .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. @@ -5683,6 +5710,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame, out_frame, @@ -7193,6 +7221,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 100, out_frame: 102, @@ -7269,6 +7298,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, source: wav, ..PASTED }; @@ -7983,6 +8013,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame, out_frame, @@ -9091,6 +9122,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, eq: Some(i), ..video[0] }] @@ -9133,6 +9165,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, color: Some(i), fit: FitPolicy::default(), speed: Speed::NORMAL, @@ -9197,6 +9230,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame, out_frame, @@ -9995,6 +10029,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame: start, out_frame: end, diff --git a/crates/engine/src/proxy.rs b/crates/engine/src/proxy.rs index f443d78..3eaf28b 100644 --- a/crates/engine/src/proxy.rs +++ b/crates/engine/src/proxy.rs @@ -559,6 +559,7 @@ fn started( fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 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 0fa0925..88ca142 100644 --- a/crates/engine/src/silence.rs +++ b/crates/engine/src/silence.rs @@ -322,6 +322,7 @@ mod tests { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame, out_frame, diff --git a/crates/engine/src/sweep.rs b/crates/engine/src/sweep.rs index 1e48a0a..79b1bd0 100644 --- a/crates/engine/src/sweep.rs +++ b/crates/engine/src/sweep.rs @@ -69,6 +69,7 @@ fn clip(start: u32, in_frame: u32, out_frame: u32) -> Clip { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame, out_frame, diff --git a/crates/engine/tests/audio_export.rs b/crates/engine/tests/audio_export.rs index ca1ba1f..53694d0 100644 --- a/crates/engine/tests/audio_export.rs +++ b/crates/engine/tests/audio_export.rs @@ -64,6 +64,7 @@ fn mixed_project() -> Project { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame: 0, out_frame: 30, @@ -90,6 +91,7 @@ fn mixed_project() -> Project { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: 90, @@ -339,6 +341,7 @@ fn a_still_and_a_song_export_as_an_mp4_with_sound() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: frames, @@ -408,6 +411,7 @@ fn a_fader_is_one_tracks_own_and_the_limiter_holds_the_sum() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: 30, @@ -649,6 +653,7 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: 60, @@ -667,6 +672,7 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: 60, @@ -727,6 +733,7 @@ fn a_silent_clip_exports_as_silence_over_its_own_span() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame: 0, out_frame: 30, @@ -824,6 +831,7 @@ fn a_51_ac3_source_round_trips_through_a_wav() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: 30, @@ -957,6 +965,7 @@ fn a_fade_in_reaches_the_exported_audio() { fade_in: 45, // 1.5 s at 30 fps fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: 90, // 3.0 s at 30 fps @@ -1042,6 +1051,7 @@ fn a_split_and_crossfaded_clip_has_no_muted_interior() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame, out_frame, @@ -1148,6 +1158,7 @@ fn a_mono_timeline_exports_as_dual_mono_ogg() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 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 6f3d58d..7705786 100644 --- a/crates/engine/tests/audio_files.rs +++ b/crates/engine/tests/audio_files.rs @@ -420,6 +420,7 @@ fn a_silent_first_source_does_not_stop_the_scan_for_one_with_sound() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: meta1.frame_count, @@ -651,6 +652,7 @@ fn place_visualizer_puts_a_waveform_on_a_video_lane() { ); let video = session.lane_clips(Lane::V1); assert_eq!(video.len(), 1); + assert_eq!(video[0].visualizer & 1, 1, "the clip is marked a waveform"); assert_eq!(video[0].source, audio.source); assert_eq!( (video[0].in_frame, video[0].out_frame), @@ -683,11 +685,53 @@ fn place_visualizer_puts_a_waveform_on_a_video_lane() { drop(session); let reloaded = PlaybackSession::open_project(&project).expect("reload visualizer project"); assert_eq!(reloaded.lane_clips(Lane::V1).len(), 1); + assert_eq!(reloaded.lane_clips(Lane::V1)[0].visualizer & 1, 1); assert_eq!(reloaded.lane_clips(Lane::A1).len(), 1); drop(reloaded); let _ = std::fs::remove_dir_all(&dir); } +#[test] +fn place_visualizer_paints_a_video_file_soundtrack() { + let dir = Scratch::dir("ve_av_viz"); + let film = { + let to = dir.join("test_av.mp4"); + std::fs::copy(asset("test_av.mp4"), &to).expect("copy"); + to + }; + let mut session = open(&film); + let picture = session.lane_clips(Lane::V1)[0]; + let before = session.lane_clips(Lane::V1).len(); + assert!( + session + .place_visualizer(picture.end(), &film, 0, picture.in_frame, picture.out_frame, None) + .expect("place visualizer of a film"), + "placed" + ); + let video = session.lane_clips(Lane::V1); + assert_eq!(video.len(), before + 1); + let viz = *video.last().unwrap(); + assert_eq!(viz.visualizer & 1, 1); + assert_eq!((viz.in_frame, viz.out_frame), (picture.in_frame, picture.out_frame)); + session.seek(f64::from(viz.start) / 30.0 + 0.5); + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(15); + let mut saw = false; + let mut frames = 0u32; + while std::time::Instant::now() < deadline && frames < 45 { + if let Some(frame) = session.try_frame() { + frames += 1; + if frame.bgra.chunks_exact(4).any(|p| p[0] > 32 || p[1] > 32 || p[2] > 32) { + saw = true; + break; + } + } else { + std::thread::sleep(std::time::Duration::from_millis(10)); + } + } + assert!(saw, "film soundtrack visualizer stayed black after {frames} pictures"); + let _ = std::fs::remove_dir_all(&dir); +} + /// ...and the door the editor itself had onto that same broken project: a copy /// of the song pasted from the clipboard used to land on `V1` as well as `A1`, /// where it decodes to nothing -- and the save it wrote was refused on the way diff --git a/crates/engine/tests/eq_audio.rs b/crates/engine/tests/eq_audio.rs index cb513ff..8078bf2 100644 --- a/crates/engine/tests/eq_audio.rs +++ b/crates/engine/tests/eq_audio.rs @@ -57,6 +57,7 @@ fn clip(start: u32, source: usize, frames: u32) -> Clip { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame: 0, out_frame: frames, diff --git a/crates/engine/tests/export.rs b/crates/engine/tests/export.rs index a023e4a..5220daf 100644 --- a/crates/engine/tests/export.rs +++ b/crates/engine/tests/export.rs @@ -240,6 +240,7 @@ fn exports_at_the_project_resolution_with_the_watched_geometry() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start, in_frame: 0, out_frame: 10, @@ -327,6 +328,7 @@ fn exports_the_audio_stream_the_timeline_plays() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 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 06f3008..03cd6d3 100644 --- a/crates/engine/tests/lanes.rs +++ b/crates/engine/tests/lanes.rs @@ -237,6 +237,7 @@ fn the_mp4_copy_follows_the_lane_that_holds_the_sound() { let clip = Clip { fade_in: 0, transition_out: 0, + visualizer: 0, fade_out: 0, start: 0, in_frame: 0, @@ -304,6 +305,7 @@ fn two_audio_lanes_are_summed() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 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 994f3ec..fc827f0 100644 --- a/crates/engine/tests/opus_export.rs +++ b/crates/engine/tests/opus_export.rs @@ -85,6 +85,7 @@ fn project(video: &Path, sound: &Path, sound_in: u32) -> Project { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame, out_frame, @@ -469,6 +470,7 @@ fn a_copied_picture_names_the_sound_it_was_written_with() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame, diff --git a/crates/engine/tests/silence.rs b/crates/engine/tests/silence.rs index 755bb3a..d2d49cd 100644 --- a/crates/engine/tests/silence.rs +++ b/crates/engine/tests/silence.rs @@ -141,6 +141,7 @@ fn speed_mode_refuses_a_clip_that_laps_over_a_silence() { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: 20, @@ -180,6 +181,7 @@ fn whole(source: usize, frames: u32) -> Clip { fade_in: 0, fade_out: 0, transition_out: 0, + visualizer: 0, start: 0, in_frame: 0, out_frame: frames,