summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/micscope/README.md5
-rw-r--r--examples/micscope/src/main.zig11
2 files changed, 10 insertions, 6 deletions
diff --git a/examples/micscope/README.md b/examples/micscope/README.md
index c02318c..e917bf0 100644
--- a/examples/micscope/README.md
+++ b/examples/micscope/README.md
@@ -151,7 +151,8 @@ addresses as QR codes, for phones).
Each take is a file of its samples (mono 32-bit floats at the host's
rate), `micscope.state.take-<id>.f32` beside the state (in `.sketchbook/`
under `zig build run`), written as it records (`Host.appendFile`). State
-lists the takes, so they are still there after a restart. A deleted take's
-file stays: a seek back finds it again. Takes stop at ten minutes; the
+lists the takes, so they are still there after a restart. A take starts
+its file empty (`Host.writeFile`). A deleted take's file stays: a seek
+back, or any mark from before the delete, finds it again. Takes stop at ten minutes; the
strip holds 64. A `micscope.state.store` from before is not read: its takes
stay in it.
diff --git a/examples/micscope/src/main.zig b/examples/micscope/src/main.zig
index ba7d678..99aac76 100644
--- a/examples/micscope/src/main.zig
+++ b/examples/micscope/src/main.zig
@@ -486,7 +486,8 @@ fn panBy(s: *State, pixels: f32, in: *const sk.Input) void {
}
/// Deletes the selected take and selects the one above it. Its file stays:
-/// the host deletes no files, and a seek back finds it again.
+/// any keyframe or mark from before the delete brings the take back, and
+/// neither the sketch nor the host can tell when none is left.
fn remove(s: *State, in: *const sk.Input) void {
const n = s.takes.count();
const index = @min(s.selected, n - 1);
@@ -539,7 +540,7 @@ pub fn command(s: *State, ss: *Session, c: *sk.Console, line: []const u8) !bool
try ss.tape.appendSlice(c.session, kept);
try ss.clips.appendBounded(.{ .id = take.id, .start = ss.tape.items.len - kept.len, .len = kept.len });
var file: [32]u8 = undefined;
- _ = c.host.appendFile(try std.fmt.bufPrint(&file, "take-{d}.f32", .{take.id}), std.mem.sliceAsBytes(kept));
+ _ = c.host.writeFile(try std.fmt.bufPrint(&file, "take-{d}.f32", .{take.id}), std.mem.sliceAsBytes(kept));
try s.takes.appendBounded(take);
s.next_id += 1;
s.selected = s.takes.count() - 1;
@@ -571,13 +572,15 @@ pub fn draw(s: *const State, ss: *Session, f: *sk.Frame) void {
while (f.host.readFile(f.host.appendFile(f.format("take-{d}.f32", .{id}), &.{})).len > 0) id += 1;
if (id != s.next_id) f.run(f.format("next-id {d}", .{id}));
}
- readTakes(s, ss, f);
-
// Requests from State. Any of them, or another take selected, flushes
// what is queued, so the cursor restarts from what was heard.
const transport = ss.transport.take(s.transport);
const seek = ss.seek.take(s.seek);
const takes = s.takes.constSlice();
+ // A take that begins here (not one a jump brought) starts its file
+ // empty, whatever a file of its id held.
+ if (transport == .recording and writing and !in.jumped and takes.len > 0) _ = f.host.writeFile(f.format("take-{d}.f32", .{takes[takes.len - 1].id}), &.{});
+ readTakes(s, ss, f);
const selected: ?*Clip = if (takes.len > 0) clipOf(ss, takes[@min(s.selected, takes.len - 1)].id) else null;
var queued: usize = in.stream(stream).queued;
if (selected) |t| {