summaryrefslogtreecommitdiff
path: root/examples/live/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 06:10:20 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit8dc369f343fda8f54756376728f4690386c20a69 (patch)
tree984ee97d6645c99a26a710a7bc343c441e6f3631 /examples/live/src
parenta4d1e3131499c17bd6f73e65154aa0c2b31c62b3 (diff)
downloadsketchbook-8dc369f343fda8f54756376728f4690386c20a69.tar.gz
sketchbook-8dc369f343fda8f54756376728f4690386c20a69.zip
examples/live: the scripted proof, a session played back and sought
test/live.script now ends with the run's own session replayed: `play session 0` from its start, then `seek` to the two moments marked as they happened (the gradient just typed, and the end after an edit, a broken line and its mend). At each, the State equals the mark leaf by leaf (`expect-snapshot`: the text, both tapes, the problem, the time), and at the first the screenshot equals the live one over the text and the picture (0,0 1000x600, without the scope and the status line). `stop` then goes on live from that moment: the typed program, before its edit. What a script could not do: a `record` clip ends at the first mark (Console.zig's `save` stops it), so the clip cannot be marked while it is made: the session is replayed instead. A mark is State before its frame's tick, so its time is the printed time less a frame, and `seek MS` lands on the last frame at or before MS: the script seeks 5 ms past each mark's time (272 and 488). The sound at a jump: `want` counted the queue the clear is about to drop, so a seek starved the device for a frame; now it counts from empty. And the block after a jump crosses from the old tape at where the device was (the clock less what was queued) to the tape at the new time (Synth.old_start). Not measured: a capture records every block made, including the tail the jump drops, so it cannot show what was heard across a seek. zig build test: 68 of 68 steps, 6 of 6 tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'examples/live/src')
-rw-r--r--examples/live/src/Lang.zig6
-rw-r--r--examples/live/src/main.zig13
-rw-r--r--examples/live/src/probe.zig1
3 files changed, 14 insertions, 6 deletions
diff --git a/examples/live/src/Lang.zig b/examples/live/src/Lang.zig
index 4f3c3bf..484de54 100644
--- a/examples/live/src/Lang.zig
+++ b/examples/live/src/Lang.zig
@@ -484,10 +484,12 @@ pub const Synth = extern struct {
/// Samples in the block.
count: u32,
fade: u32,
- /// The block's first sample, seconds.
+ /// The block's first sample, seconds; the old tape's, which differs
+ /// after a jump (a seek: the old tape where the device was).
start: f32,
+ old_start: f32,
rate: f32,
- pad: [2]f32 = .{ 0, 0 },
+ pad: f32 = 0,
pub const glsl = .{ .uniform = .{ .set = 2, .instance = "u" } };
};
diff --git a/examples/live/src/main.zig b/examples/live/src/main.zig
index 13f89be..965152a 100644
--- a/examples/live/src/main.zig
+++ b/examples/live/src/main.zig
@@ -166,16 +166,20 @@ fn sound(s: *const State, ss: *Session, f: *sk.Frame) void {
ss.block = f.host.newBuffer(max_block * @sizeOf(f32));
ss.tapes = f.host.newBuffer(2 * @sizeOf(Lang.Tape.Code));
}
- // A jump is heard at once: what was queued from before it is dropped.
+ // A jump is heard at once: what was queued from before it is dropped,
+ // and the block crosses from where the device was to the new time.
+ const rate: f64 = @floatFromInt(in.sample_rate);
+ var queued = in.stream(stream).queued;
+ const was = ss.clock - @as(f64, @floatFromInt(queued)) / rate;
if (in.jumped) {
ss.clock = s.time;
+ queued = 0;
f.audio(stream, &.{}, .{ .clear = true });
}
- const rate: f64 = @floatFromInt(in.sample_rate);
- const want: u32 = @min(in.lead -| in.stream(stream).queued, max_block);
+ const want: u32 = @min(in.lead -| queued, max_block);
if (want > 0) {
const new = std.mem.sliceAsBytes(s.out.slice());
- const changed = !std.mem.eql(u8, new, std.mem.sliceAsBytes(ss.heard.slice()));
+ const changed = in.jumped or !std.mem.eql(u8, new, std.mem.sliceAsBytes(ss.heard.slice()));
const tapes = f.scratch.create([2]Lang.Tape.Code) catch return;
tapes.* = .{ s.out.code, ss.heard.code };
f.upload(ss.tapes, 0, std.mem.asBytes(tapes));
@@ -190,6 +194,7 @@ fn sound(s: *const State, ss: *Session, f: *sk.Frame) void {
.count = want,
.fade = if (changed and s.crossfade) want else 0,
.start = @floatCast(ss.clock),
+ .old_start = @floatCast(if (in.jumped) was else ss.clock),
.rate = @floatCast(rate),
}),
.groups = .{ (want + 63) / 64, 1, 1 },
diff --git a/examples/live/src/probe.zig b/examples/live/src/probe.zig
index 1e2970c..4f816b2 100644
--- a/examples/live/src/probe.zig
+++ b/examples/live/src/probe.zig
@@ -123,6 +123,7 @@ pub fn draw(ss: *Session, f: *sk.Frame) void {
.count = k.count,
.fade = if (k.fade) k.count else 0,
.start = ss.time,
+ .old_start = ss.time,
.rate = 48000,
}),
.groups = .{ (k.count + 63) / 64, 1, 1 },