summaryrefslogtreecommitdiff
path: root/examples/micscope/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 00:38:45 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commita1ae80096bd69ee7d92ea9e4564e960d8553395e (patch)
treecfe107a5c2338ebd46892f27158c7de1b1fd9db9 /examples/micscope/test
parentf2829440b0f933422e1da5394870505d3c2d67d6 (diff)
downloadsketchbook-a1ae80096bd69ee7d92ea9e4564e960d8553395e.tar.gz
sketchbook-a1ae80096bd69ee7d92ea9e4564e960d8553395e.zip
micscope off the Store, its takes files written through Host.appendFile
The library could read a file and not write one, so micscope kept its takes in the Store: a tape appended every frame while recording, which a save of 64 MiB could not hold (under six minutes of 48 kHz audio, and micscope allows ten-minute takes). Now a sketch has one call that writes: f.host.appendFile(name, bytes) appends to `<state>.<name>`, beside the state file (in .sketchbook/ under `zig build run`), creating it, and returns the file's path for readFile, or "" when nothing was written. It is pointer and length in, a C-callconv entry in the vtable like newSound. Only draw and command have a host, so a write is not replayed, like sound. The web host writes nothing and returns "". readFile still maps a file once, so what is appended after is not in what it returned. A scripted --fresh run works on `<state>.<pid>`; the files it appends to are `<state>.<pid>.<name>`, and the exit now moves every file of the run (found by that prefix in the state's directory) to the given name, or removes them for an export, where it moved the state and its store by two fixed suffixes. micscope: State lists the takes (sk.List(Take, 64): id, source) and the counter, next_id; `update` adds a take when recording starts and removes one on delete. Each take's samples are `take-<id>.f32` (mono f32 at the host's rate), appended to by draw as it records and by `open`, which also puts them straight into Session (the web keeps no files). Session holds the tape (every take's samples, read from their files once a process) and a clip per take (start, len, and heard, the playhead, which a restart no longer keeps); draw makes the tape follow State: a take State lost leaves it, one it lacks is read from its file. A deleted take's file stays, so a seek back finds it again; after a jump (start, seek, load, set, reload) draw moves next_id past take files already written (--fresh keeps them, and a seek back finds the future's) with a `next-id N` command. Gone: the Store, the remove request, the `takes N` command that told State the Store's count, adoptTape. Old micscope.state.store files are not read: their takes stay in them. README: appendFile among the host calls, a paragraph on it, and the private run's appended files. Tests: zig build test, 164/164 steps, 133/133 tests (one new: appendFile appends beside the state and names the file). micscope's zig build test, 67/67 steps, 10/10 tests; transport.script reads `takes.len`, loses the miscounted-takes check with its mechanism, and gains a deleted take read back from its file after `load` and the counter moved past written files. Pictures: the four scripts' 18 screenshots before and after, compared by pixel: the differences are where two runs of one build differ by themselves (playheads, the microphone's take lengths, the live view). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'examples/micscope/test')
-rw-r--r--examples/micscope/test/record.script10
-rw-r--r--examples/micscope/test/transport.script22
2 files changed, 20 insertions, 12 deletions
diff --git a/examples/micscope/test/record.script b/examples/micscope/test/record.script
index 2750a18..843d802 100644
--- a/examples/micscope/test/record.script
+++ b/examples/micscope/test/record.script
@@ -1,9 +1,9 @@
# Records (from whatever microphone the host gives a headless run) into a
# new take, stops, and plays it back.
-expect takes 0
+expect takes.len 0
key r
expect transport.value recording
-expect takes 1
+expect takes.len 1
frames 60
screenshot .zig-cache/micscope/recording.png
key r
@@ -13,11 +13,11 @@ expect transport.value forward
frames 10
# Each recording is another take; opening a file while recording ends it.
key r
-expect takes 2
+expect takes.len 2
expect selected 1
console open test/sweep.wav
expect transport.value stopped
-expect takes 3
+expect takes.len 3
frames 2
-expect takes 3
+expect takes.len 3
screenshot .zig-cache/micscope/strip.png
diff --git a/examples/micscope/test/transport.script b/examples/micscope/test/transport.script
index f821a03..2015682 100644
--- a/examples/micscope/test/transport.script
+++ b/examples/micscope/test/transport.script
@@ -2,7 +2,7 @@
# 16 kHz) over a quiet 440 Hz tone.
console open test/sweep.wav
frames 2
-expect takes 1
+expect takes.len 1
expect selected 0
expect transport.value stopped
key right
@@ -36,7 +36,7 @@ frames 30
screenshot .zig-cache/micscope/played.png
# A second take goes under the first and is selected; up is older.
console open test/sweep.wav
-expect takes 2
+expect takes.len 2
expect selected 1
key up
expect selected 0
@@ -47,14 +47,22 @@ click 400 150
expect selected 0
frames 2
screenshot .zig-cache/micscope/two-takes.png
-# Deleting it leaves the second.
+# Deleting it leaves the second. Its file stays: going back to before the
+# deletion reads it again.
+console save two
key delete
-expect takes 1
+expect takes.len 1
expect selected 0
-# State that miscounts the takes is told by draw.
-console set takes 0
+console load two
frames 2
-expect takes 1
+expect takes.len 2
+key delete
+expect takes.len 1
+# A counter that names a take file already written (--fresh keeps the
+# files; a seek back finds the future's) is moved past it by draw.
+console set next_id 1
+frames 2
+expect next_id 3
# More takes than fit: the camera follows the bottom until the wheel pans
# it, then 0 shows the whole strip.
console open test/sweep.wav