Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion apps/studio/src/recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,18 @@ impl RecordingScreen {
self.error = Some(e.to_string());
}
}
if hud_button(ui, next(&mut x, BTN, 2.0), "marker", |p, r| icon_glyph(p, r, crate::widgets::Icon::Flag, 14.0), "Add a marker (a split point)").clicked() {
// a marker starts a chapter in the project; the count shows each press landed
let marked = rec.markers().len();
let flag = next(&mut x, BTN, 2.0);
let tip = if marked == 0 { "Start a chapter here".to_string() } else { format!("Start a chapter here ({} marked)", marked) };
if hud_button(ui, flag, "marker", |p, r| icon_glyph(p, r, crate::widgets::Icon::Flag, 14.0), &tip).clicked() {
rec.add_marker();
}
if marked > 0 {
let c = pos2(flag.right() - 5.0, flag.top() + 5.0);
painter.circle_filled(c, 6.5, pal.accent);
painter.text(c, Align2::CENTER_CENTER, marked.min(99).to_string(), FontId::proportional(9.5), Color32::WHITE);
}
if hud_button(ui, next(&mut x, BTN, 2.0), "restart", |p, r| icon_glyph(p, r, crate::widgets::Icon::Restart, 15.0), "Start over").clicked() {
restart = true;
}
Expand Down
29 changes: 29 additions & 0 deletions crates/sf-session/src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ pub fn create_project_from_recording(recording_dir: &Path, opts: CreateOptions)
}
}
}
// markers set while recording start chapters (the agent or the Chapters page names them)
let chapters = chapters_from_markers(&opts.markers_ms, duration);
if !chapters.is_empty() {
use sf_project::SceneChaptersExt;
scene.set_chapters(chapters);
}
let markers: Vec<serde_json::Value> = opts
.markers_ms
.iter()
Expand All @@ -126,6 +132,19 @@ pub fn create_project_from_recording(recording_dir: &Path, opts: CreateOptions)
Ok(pkg)
}

/// Chapters from markers set while recording (ms of the recording): one at the start, then one
/// at each marker. Markers in the first or last second, or within a second of the one before,
/// add nothing. No markers, no chapters.
pub fn chapters_from_markers(markers_ms: &[f64], duration_ms: f64) -> Vec<sf_project::Chapter> {
let mut at: Vec<f64> = markers_ms.iter().copied().filter(|m| m.is_finite() && *m >= 1000.0 && *m <= duration_ms - 1000.0).collect();
at.sort_by(f64::total_cmp);
at.dedup_by(|b, a| *b - *a < 1000.0);
if at.is_empty() {
return vec![];
}
std::iter::once(0.0).chain(at).enumerate().map(|(i, ms)| sf_project::Chapter::new(format!("Chapter {}", i + 1), ms, None)).collect()
}

fn chrono_iso(unix_ms: f64) -> String {
let secs = (unix_ms / 1000.0).floor() as i64;
let nanos = ((unix_ms / 1000.0 - secs as f64) * 1e9) as u32;
Expand Down Expand Up @@ -192,4 +211,14 @@ mod tests {
assert_eq!(cfg.output.padding_ratio01, 0.1);
assert_eq!(cfg.styles.screen_border_radius, 16.0);
}

#[test]
fn markers_start_chapters() {
let ch = chapters_from_markers(&[30_000.0, 500.0, 30_400.0, 90_000.0, 119_600.0], 120_000.0);
let at: Vec<(String, f64)> = ch.iter().map(|c| (c.title.clone(), c.source_ms)).collect();
// the start, then 30 s and 90 s: too early, too close and too late markers add nothing
assert_eq!(at, vec![("Chapter 1".to_string(), 0.0), ("Chapter 2".into(), 30_000.0), ("Chapter 3".into(), 90_000.0)]);
assert!(chapters_from_markers(&[], 120_000.0).is_empty());
assert!(chapters_from_markers(&[200.0], 120_000.0).is_empty());
}
}
Loading