diff options
Diffstat (limited to 'examples/micscope/src')
| -rw-r--r-- | examples/micscope/src/main.zig | 11 |
1 files changed, 7 insertions, 4 deletions
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| { |
