From e383e89653875c6f31d275fc3c3ada1ad0fd3c4d Mon Sep 17 00:00:00 2001 From: lucasegen <281051305+lucasegen@users.noreply.github.com> Date: Tue, 20 Oct 2026 12:13:27 +0200 Subject: [PATCH 1/2] Draw the playback cursor neutral and keep red for recording The Edit window drew the playhead red whenever the transport ran. Red now means recording only: plain playback uses its own neutral grey, the new `Tokens::playback` (rgb 140,140,142 on Dark, 110,113,119 on Light), which reads over clips and the rulers. It is not the insertion colour (230 on Dark, 35,36,40 on Light): the edit cursor can stand beside the moving line, and the two must never read as the same line. A test pins a contrast of at least 2.5:1 between them and 3:1 of the line on the lanes, in both themes. `Tokens::playhead` stays red, for the record line and for the Sampler's "S" marker. The Universe overview line follows the same rule. Conflict note: open PR #111 (persistent playhead) goes the other way and draws the red playhead at rest too. It rewrites the same lines of `overlay()` and `universe()`, and it already conflicts with main, so it needs a rebase and a decision on the colour before either lands. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/edit_window.rs | 75 ++++++++++++++++++++++++++++++- crates/ui-egui/src/theme.rs | 5 +++ 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/edit_window.rs b/crates/ui-egui/src/edit_window.rs index 7e24a4c7..49a0378b 100644 --- a/crates/ui-egui/src/edit_window.rs +++ b/crates/ui-egui/src/edit_window.rs @@ -142,7 +142,10 @@ fn universe(app: &mut SoundApp, ui: &mut Ui) { ui.painter().rect_stroke(vr, 2.0, Stroke::new(1.5, Tokens::current().universe_view), StrokeKind::Outside); if app.is_playing() { let x = r.min.x + app.position() as f32 / total * r.width(); - ui.painter().line_segment([pos2(x, r.min.y), pos2(x, r.max.y)], Stroke::new(1.0, Tokens::current().playhead)); + ui.painter().line_segment( + [pos2(x, r.min.y), pos2(x, r.max.y)], + Stroke::new(1.0, playhead_colour(&Tokens::current(), app.engine.transport.recording)), + ); } let resp = ui.interact(r, ui.id().with("universe"), Sense::click_and_drag()); if let Some(p) = resp.interact_pointer_pos() @@ -2657,6 +2660,12 @@ fn follow_update( (false, Some(pos)) } +/// The playback cursor is red only while recording; plain playback draws it in its own neutral +/// grey, apart from the insertion colour of the edit cursor that stands beside it. +fn playhead_colour(t: &Tokens, recording: bool) -> Color32 { + if recording { t.playhead } else { t.playback } +} + /// Selection overlay, insertion point and playhead across rulers and tracks. /// While playing, auto-scroll keeps the playhead in view for the follow /// modes (`page`/`continuous`/`center`) — but any outside view move (a manual @@ -2714,7 +2723,7 @@ fn overlay(app: &mut SoundApp, ui: &mut Ui, tl: Rect, area: Rect) { } if app.is_playing() { let x = x_of(s, tl, app.position()); - painter.line_segment([pos2(x, area.min.y), pos2(x, area.max.y)], Stroke::new(1.5, t.playhead)); + painter.line_segment([pos2(x, area.min.y), pos2(x, area.max.y)], Stroke::new(1.5, playhead_colour(&t, app.engine.transport.recording))); // Session reads first (owned copies), then the layout mutation: the // two borrow disjoint fields. let pos = app.position(); @@ -2820,6 +2829,68 @@ mod tests { assert_eq!(follow_update(false, true, false, 9_000, 9_000, None, true, 96_000), (false, None)); } + #[test] + fn playhead_is_red_only_while_recording() { + for t in [Tokens::DARK, Tokens::LIGHT] { + assert_eq!(playhead_colour(&t, true), t.playhead); + assert_eq!(playhead_colour(&t, false), t.playback); + assert_ne!(t.playback, t.playhead, "plain playback must not read as the record line"); + } + } + + /// WCAG contrast ratio between two colours (1 = identical, 21 = black on white). + fn contrast(a: Color32, b: Color32) -> f32 { + let lum = |c: Color32| { + let lin = |v: u8| { + let v = f32::from(v) / 255.0; + if v <= 0.04045 { v / 12.92 } else { ((v + 0.055) / 1.055).powf(2.4) } + }; + 0.2126 * lin(c.r()) + 0.7152 * lin(c.g()) + 0.0722 * lin(c.b()) + }; + let (hi, lo) = (lum(a).max(lum(b)), lum(a).min(lum(b))); + (hi + 0.05) / (lo + 0.05) + } + + /// The edit cursor stands still beside the moving playback line while playing: in both themes + /// they must be two clearly different greys, and the line must still read on the lanes. + #[test] + fn the_playback_line_is_set_apart_from_the_insertion_point_in_both_themes() { + for (name, t) in [("dark", Tokens::DARK), ("light", Tokens::LIGHT)] { + let apart = contrast(t.playback, t.insertion); + assert!(apart >= 2.5, "{name}: playback {:?} and insertion {:?} are only {apart:.2}:1 apart", t.playback, t.insertion); + let reads = contrast(t.playback, t.playlist_bg); + assert!(reads >= 3.0, "{name}: the playback line is only {reads:.2}:1 on the lanes"); + } + } + + /// The colour `overlay` gives the full-height playback line (width 1.5) in this transport state. + fn playback_line_colour(recording: bool) -> Option { + use egui::{Rect, pos2}; + let _palette = crate::theme::lock_test_palette(); + let mut app = SoundApp::new(soundcraft_engine::Engine::default(), None, crate::Services::default()); + app.engine.session_mut().edit.zoom.samples_per_px = 1_000.0; + app.engine.transport.playing = true; + app.engine.transport.recording = recording; + app.engine.transport.position = 80_000; + let tl = Rect::from_min_max(pos2(100.0, 100.0), pos2(900.0, 500.0)); + let area = Rect::from_min_max(pos2(100.0, 50.0), tl.max); + let ctx = egui::Context::default(); + let mut output = ctx.run_ui(egui::RawInput::default(), |ui| overlay(&mut app, ui, tl, area)); + output.textures_delta.clear(); + output.shapes.iter().find_map(|s| match &s.shape { + Shape::LineSegment { points, stroke } if points[0].x == 180.0 && stroke.width == 1.5 => Some(stroke.color), + _ => None, + }) + } + + #[test] + fn overlay_draws_the_playback_line_neutral_and_the_record_line_red() { + let _palette = crate::theme::lock_test_palette(); + let t = Tokens::current(); + assert_eq!(playback_line_colour(false), Some(t.playback)); + assert_eq!(playback_line_colour(true), Some(t.playhead)); + } + fn harness(n: usize) -> Harness<'static, SoundApp> { let mut engine = soundcraft_engine::Engine::default(); engine.execute("track.new", &json!({"count": n})).unwrap(); diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs index 0cf5b9bd..00e6d099 100644 --- a/crates/ui-egui/src/theme.rs +++ b/crates/ui-egui/src/theme.rs @@ -143,6 +143,9 @@ pub struct Tokens { pub selection: Color32, pub playhead: Color32, pub insertion: Color32, + /// The playback line while the transport runs without recording: a mid grey, set well apart + /// from `insertion` (the edit cursor stands beside it while playing) in both themes. + pub playback: Color32, pub solo: Color32, pub mute: Color32, pub rec: Color32, @@ -253,6 +256,7 @@ impl Tokens { selection: Color32::from_rgba_premultiplied(40, 70, 110, 110), playhead: Color32::from_rgb(232, 60, 50), insertion: Color32::from_rgb(230, 230, 230), + playback: Color32::from_rgb(140, 140, 142), solo: Color32::from_rgb(222, 196, 52), mute: Color32::from_rgb(232, 148, 40), rec: Color32::from_rgb(214, 52, 46), @@ -338,6 +342,7 @@ impl Tokens { selection: Color32::from_rgba_premultiplied(100, 145, 205, 90), playhead: Color32::from_rgb(210, 48, 42), insertion: Color32::from_rgb(35, 36, 40), + playback: Color32::from_rgb(110, 113, 119), solo: Color32::from_rgb(178, 145, 20), mute: Color32::from_rgb(194, 106, 22), rec: Color32::from_rgb(190, 42, 38), From 4f99e2a68614824bbbe711bf469fe2ba79f18678 Mon Sep 17 00:00:00 2001 From: lucasegen <281051305+lucasegen@users.noreply.github.com> Date: Wed, 28 Oct 2026 19:06:53 +0100 Subject: [PATCH 2/2] Edge the Universe's playback line so it reads over every track colour The Universe paints clips in their raw track colours, and the neutral playback line is as light as some of them (1.1:1 over the first one in the dark theme): a dark edge on each side keeps it visible. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/edit_window/universe.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/edit_window/universe.rs b/crates/ui-egui/src/edit_window/universe.rs index 302a58c9..fa73e0ed 100644 --- a/crates/ui-egui/src/edit_window/universe.rs +++ b/crates/ui-egui/src/edit_window/universe.rs @@ -83,10 +83,11 @@ pub(super) fn universe(app: &mut SoundApp, ui: &mut Ui) { ui.painter().rect_stroke(vr, 2.0, Stroke::new(1.5, Tokens::current().universe_view), StrokeKind::Outside); if app.is_playing() { let x = r.min.x + app.position() as f32 / total * r.width(); - ui.painter().line_segment( - [pos2(x, r.min.y), pos2(x, r.max.y)], - Stroke::new(1.0, playhead_colour(&Tokens::current(), app.engine.transport.recording)), - ); + let line = [pos2(x, r.min.y), pos2(x, r.max.y)]; + // The Universe paints clips in their raw track colours, some as light as the neutral playback line: a dark + // edge on each side keeps it readable over all of them. + ui.painter().line_segment(line, Stroke::new(3.0, Color32::from_black_alpha(160))); + ui.painter().line_segment(line, Stroke::new(1.0, playhead_colour(&Tokens::current(), app.engine.transport.recording))); } let resp = ui.interact(r, ui.scope_id().with("universe"), Sense::click_and_drag()); if let Some(p) = resp.interact_pointer_pos()