@msb235/blits 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +12 -2
  3. package/dist/clock.d.ts +10 -0
  4. package/dist/clock.js +23 -0
  5. package/dist/clone.d.ts +5 -0
  6. package/dist/clone.js +7 -0
  7. package/dist/cue.js +5 -8
  8. package/dist/due.js +20 -13
  9. package/dist/everyone.js +3 -0
  10. package/dist/fade.d.ts +1 -0
  11. package/dist/fade.js +10 -4
  12. package/dist/fill.js +5 -0
  13. package/dist/fold.js +31 -25
  14. package/dist/frames.d.ts +21 -0
  15. package/dist/frames.js +59 -0
  16. package/dist/gone.d.ts +4 -4
  17. package/dist/gone.js +11 -10
  18. package/dist/handle.js +17 -9
  19. package/dist/held.d.ts +10 -0
  20. package/dist/held.js +28 -1
  21. package/dist/hosts.js +5 -1
  22. package/dist/keyfill.js +5 -1
  23. package/dist/locus.d.ts +4 -1
  24. package/dist/locus.js +14 -4
  25. package/dist/marks.js +4 -4
  26. package/dist/motion.d.ts +6 -3
  27. package/dist/motions.d.ts +5 -2
  28. package/dist/motions.js +3 -1
  29. package/dist/move.js +51 -14
  30. package/dist/origin.js +3 -2
  31. package/dist/owner.d.ts +2 -0
  32. package/dist/owner.js +10 -2
  33. package/dist/paging.js +1 -6
  34. package/dist/place.js +17 -3
  35. package/dist/project.d.ts +1 -1
  36. package/dist/project.js +12 -7
  37. package/dist/record.js +2 -1
  38. package/dist/revive.d.ts +2 -0
  39. package/dist/revive.js +2 -0
  40. package/dist/seek.js +4 -4
  41. package/dist/spans.d.ts +5 -4
  42. package/dist/spans.js +11 -10
  43. package/dist/stack.js +2 -2
  44. package/dist/strays.js +13 -5
  45. package/dist/transport.d.ts +2 -6
  46. package/dist/transport.js +7 -30
  47. package/dist/types/mix.d.ts +3 -2
  48. package/dist/types/patch.d.ts +7 -3
  49. package/dist/types/place.d.ts +4 -1
  50. package/dist/types/voice.d.ts +22 -4
  51. package/dist/unpage.d.ts +1 -1
  52. package/dist/unpage.js +3 -4
  53. package/dist/voice.d.ts +52 -0
  54. package/dist/voice.js +103 -2
  55. package/dist/warn.d.ts +2 -0
  56. package/dist/warn.js +17 -0
  57. package/dist/weigh.js +5 -0
  58. package/docs/schema.html +92 -29
  59. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -4,6 +4,101 @@ This package follows [semver](https://semver.org). Below 1.0.0, a breaking chang
4
4
  version and everything else the patch. Each release lists its changes as **Breaking**, **Added** and
5
5
  **Fixed**, and the release workflow refuses a tag with no section here.
6
6
 
7
+ ## 0.9.0
8
+
9
+ ### Breaking
10
+
11
+ - A stock `last()` channel in a locus takes its heaviest member's value, and the later cued of
12
+ two as heavy. It stepped through its members in cue order, so three voices at weights 0.3,
13
+ 0.3, and 0.4 showed the second. Two members read as before.
14
+ - A placement whose `end` comes before its start is an instant: the voice starts and ends at its
15
+ start, shows nothing, and warns once outside production. Its `end` mark was reported ahead of
16
+ its `start`, so a voice anchored after it started before it did, and with a `fade.out` it
17
+ showed a whole fade from its start. An `end` that leaves less room than `fade.out` now
18
+ shortens the fade to finish when asked, where the fade ran its whole length past it, and an
19
+ `out` before the start is reported at the start, where its fade always began.
20
+ - A `to` or `push` that brings back a subject faded out of its voice is made at the frame of
21
+ the call, as one for a subject never faded is. It was made at the subject's next read, so how
22
+ far the motion had got depended on when the host next probed the subject.
23
+ - A handle `seek` on a pending voice holds: the voice starts on time, already at the sought
24
+ position, and one freezing before shows that frame while it waits. The seek was taken from
25
+ the moment of the call, and lost outright when an anchor or the mix's rate moved the start.
26
+ - A rate of 0, a negative rate, or a ramp set on a pending voice applies from its start, as a
27
+ rate above 0 always did. At rate 0 the voice starts on time and holds its first frame, where
28
+ it stopped its clock short of its start for good and never showed.
29
+
30
+ - A voice playing backward ends where it starts. When its clock runs back to 0, `played`
31
+ resolves and it leaves over `fade.out`, showing its first frame through the fade, or holds
32
+ that frame where it freezes before; its `coast`, `out`, and `end` marks are there. A voice at
33
+ a rate below 0 showed nothing once past its start and never left the mix. A stateful patch
34
+ steps once more to the moment its subject reached its start.
35
+ - A voice cued at a rate below 0 with no `seek` starts at its end, where it started at 0 and
36
+ was over at once.
37
+ - A fade in counts from no earlier than its voice's start. A subject whose delay had already run
38
+ out when the voice started (a negative `stagger`, or a seek made in the frame of the cue)
39
+ came in with its fade partway or done.
40
+
41
+ ### Added
42
+
43
+ - `seek` on a cue: where in itself the voice starts, in voice ms.
44
+ - A voice with no end cued backward, a loop for good or a patch with no duration, plays from 0
45
+ into the pass before, with `setting.pass` and `setting.elapsed` below 0. It runs on the
46
+ general path.
47
+ - `handle.ramp` through 0 eases a voice into reverse, or out of it.
48
+ - `@msb235/blits-tone`, a package in `packages/tone` that drives Tone.js from a mix on the audio
49
+ clock. Its own changelog has what it does.
50
+
51
+ ### Fixed
52
+
53
+ - `project(mix.now)` reads what `probe` does. It landed what the next sync would, so after a
54
+ handle `seek` past a voice's end it showed the voice gone while the mix still showed its last
55
+ frame, and after a fade it placed a voice anchored on the faded one a frame early.
56
+ - A read back of a voice that was pending counts each subject's origin from the controls the
57
+ voice had then, not from where a later seek, rate, or anchor has since put it.
58
+
59
+ - A seek back inside `history.ms` plays the host's calls again when the mix's rate is above 1.
60
+ The tape was let go of by mix time while its calls are stamped in host time, so at rate 2 a call
61
+ made 250 ms of host time before a seek back was already gone and never played again.
62
+ - A voice taken out with a time already older than history reaches, such as `fade({ at })` given
63
+ a moment long past, comes back for a seek or a read back to before that call. It was forgotten
64
+ at the next sync, so `seek` and `project` to the frame before the call found no voice.
65
+ - A `HistoryStore` is told of every seek back through `cut`, as its doc says. It was told only
66
+ when the seek read records from the store, so a mark announced with a past `at`, paged at once,
67
+ stayed in the store after a seek back to before it was announced.
68
+ - A `color(last())` channel on a lane switches off when its voice's weight falls to 0, as it does
69
+ off lanes. A lane left it on, so a weight coming back inside the band (0.4 to 0.6 by default)
70
+ showed the color where a mix with `lanes: false` showed none.
71
+
72
+ - A span's children play from where the one before each ended, not from the frame that noticed
73
+ it. Each child leaving fitted the rest again from the sync's time, so the next started up to a
74
+ frame late and the rest sped up to make room: 200 children of 10 ms in a 2000 ms span, fitted
75
+ with none skipped at cue, had 199 skipped once synced every 16 ms. A read ahead never fitted
76
+ again, so `project` showed a child retimed by `faster` up to a frame ahead of the mix.
77
+
78
+ - A voice whose owner runs backward leaves over its `fade.out` from where it reached its start,
79
+ as one turned back by its own handle does. An owner run back to its start left at once and
80
+ took every voice it held with it, so a child with a 100 ms `fade.out` vanished in one frame
81
+ and listed no `coast`, `out`, or `end` mark. An owner at its start now stays for what it
82
+ holds and leaves with its last child.
83
+
84
+ - `setting.dt` is the gap since the subject was last sampled for a patch with no `step`, and for
85
+ a weight signal, as its doc says. It was the time since the subject's origin, growing every
86
+ frame: a mix synced at 16, 48, and 64 handed such a patch 16, 48, and 64, and now hands it 16,
87
+ 32, and 16.
88
+
89
+ ## 0.8.1
90
+
91
+ ### Fixed
92
+
93
+ - A frame under `history` costs what it did in 0.7.1 again. 0.8.0 added two costs to every frame:
94
+ a sync shifted the whole list of frames history can reach to let go of the oldest, 7,200 of
95
+ them at 60 fps under the default 120 s; and an object a voice gave a channel with no `rest` to
96
+ fold into, such as `last<Row>()`, was copied for every subject on every frame. The frames now
97
+ leave from the front without a shift, and such a channel's pose holds the patch's own object, as
98
+ in 0.7.1; an array is still copied. astv's motion bench on one machine, mean µs a frame over
99
+ two runs, 0.7.1, 0.8.0, then this: one window landing 6 text changes of 5 rows, 19.6, 28.8,
100
+ 19.5; its busy stage, 354.6, 402.2, 340.7; 10 flights a second, 6.4, 8.0, 6.6.
101
+
7
102
  ## 0.8.0
8
103
 
9
104
  ### Breaking
package/README.md CHANGED
@@ -116,9 +116,14 @@ state shared between subjects, a `step` that lands differently from the same sta
116
116
  [three.quarks](https://github.com/Alchemist0823/three.quarks) particles. It is published separately
117
117
  so the engine keeps no dependencies; its README says how it works.
118
118
 
119
+ `packages/tone` is `@msb235/blits-tone`, a driver that schedules a mix on the audio clock through
120
+ [Tone.js](https://tonejs.github.io): channels as parameter curves read ahead, and hits and marks at
121
+ their sample. It is published separately for the same reason, and its README says what it does not
122
+ do yet.
123
+
119
124
  ## Status
120
125
 
121
- v0.8.0, with five consumers. magicsmoke runs every fault on it, wod its wheel, tricks and
126
+ v0.9.0, with five consumers. magicsmoke runs every fault on it, wod its wheel, tricks and
122
127
  transitions, weasel its animator's tweens, sherpa its seams, and
123
128
  [klieg](https://github.com/orochi235/klieg) composes all three of its systems — letter motion,
124
129
  part effects, and the environment a sign is lit by — on a mix each.
@@ -135,7 +140,12 @@ Zero runtime dependencies, ESM only, types included.
135
140
 
136
141
  ```
137
142
  npm install
138
- npm run check # lint, typecheck, test
143
+ npm run check # lint, typecheck, test
144
+ npm run test:general # the tests again with lanes off
139
145
  ```
140
146
 
147
+ A lane is a channel the mix computes for every subject at once, and the general path is the same
148
+ fold made subject by subject. `test:general` turns lanes off in every mix that does not set `lanes`
149
+ itself, so the whole suite runs on the general path.
150
+
141
151
  MIT.
package/dist/clock.d.ts CHANGED
@@ -69,6 +69,16 @@ export interface Clock {
69
69
  export declare function elapsedWith(c: Clock, now: number): number;
70
70
  /** The time a clock reads `elapsed`, inverting `elapsedWith`; Infinity where it never will. */
71
71
  export declare function timeWith(c: Clock, elapsed: number): number;
72
+ /**
73
+ * The time a clock running back reads `elapsed`: `timeWith` for the clock that reads the negative
74
+ * of this one, which runs forward where this runs back.
75
+ */
76
+ export declare function backWith(c: Clock, elapsed: number): number;
77
+ /**
78
+ * The phase of a time before 0, for a loop with no first pass: where the pass before 0, and each
79
+ * one before that, would read it.
80
+ */
81
+ export declare function phaseBefore(elapsed: number, duration: number): number;
72
82
  /** A clock's rate at `now`. */
73
83
  export declare function rateWith(c: Clock, now: number): number;
74
84
  /** Moves a clock's anchor to `now`, carrying what is left of a ramp. */
package/dist/clock.js CHANGED
@@ -125,6 +125,29 @@ export function timeWith(c, elapsed) {
125
125
  return Number.POSITIVE_INFINITY;
126
126
  return c.anchorNow + r.over + (elapsed - atEnd) / r.to;
127
127
  }
128
+ /**
129
+ * The time a clock running back reads `elapsed`: `timeWith` for the clock that reads the negative
130
+ * of this one, which runs forward where this runs back.
131
+ */
132
+ export function backWith(c, elapsed) {
133
+ const r = c.ramp;
134
+ return timeWith({
135
+ anchorNow: c.anchorNow,
136
+ anchorElapsed: -c.anchorElapsed,
137
+ rate: -c.rate,
138
+ ramp: r === null ? null : { from: -r.from, to: -r.to, over: r.over },
139
+ }, -elapsed);
140
+ }
141
+ /**
142
+ * The phase of a time before 0, for a loop with no first pass: where the pass before 0, and each
143
+ * one before that, would read it.
144
+ */
145
+ export function phaseBefore(elapsed, duration) {
146
+ if (!(duration > 0))
147
+ return 0;
148
+ const into = elapsed % duration;
149
+ return (into < 0 ? into + duration : into) / duration;
150
+ }
128
151
  /** A clock's rate at `now`. */
129
152
  export function rateWith(c, now) {
130
153
  const r = c.ramp;
package/dist/clone.d.ts CHANGED
@@ -6,5 +6,10 @@
6
6
  export declare function clone<T>(v: T): T;
7
7
  /** A copy a fold may write into: arrays, typed arrays and plain objects copied, the rest as is. */
8
8
  export declare function copy(v: unknown): unknown;
9
+ /**
10
+ * A value that starts a channel no fold writes into: only `merged` touches it after, and that
11
+ * writes into arrays alone, so an object is the patch's own, not a copy made each frame.
12
+ */
13
+ export declare function first(v: unknown): unknown;
9
14
  /** Whether `copy` can copy `v` faithfully, when it is an object. */
10
15
  export declare function copyable(v: object): boolean;
package/dist/clone.js CHANGED
@@ -62,6 +62,13 @@ export function copy(v) {
62
62
  return v.slice();
63
63
  return plainObject(v) ? clone(v) : v;
64
64
  }
65
+ /**
66
+ * A value that starts a channel no fold writes into: only `merged` touches it after, and that
67
+ * writes into arrays alone, so an object is the patch's own, not a copy made each frame.
68
+ */
69
+ export function first(v) {
70
+ return Array.isArray(v) ? [...v] : v;
71
+ }
65
72
  /** Whether `copy` can copy `v` faithfully, when it is an object. */
66
73
  export function copyable(v) {
67
74
  return Array.isArray(v) || ArrayBuffer.isView(v) || plainObject(v);
package/dist/cue.js CHANGED
@@ -4,7 +4,7 @@ import { copyable } from './clone.js';
4
4
  import { schedule } from './due.js';
5
5
  import { shares } from './everyone.js';
6
6
  import { finiteRate, plainWeight, VoiceHandle } from './handle.js';
7
- import { reorigin } from './held.js';
7
+ import { begin } from './held.js';
8
8
  import { handle } from './hosts.js';
9
9
  import { motionOf } from './motion.js';
10
10
  import { adopt, ownerPatch, ownerReading } from './owner.js';
@@ -76,6 +76,8 @@ export function playable(mix, spec) {
76
76
  throw new RangeError(`blits: loop takes true, false or a whole number of passes, not ${loop}`);
77
77
  if (spec.rate !== undefined)
78
78
  finiteRate(spec.rate);
79
+ if (spec.seek !== undefined && !Number.isFinite(spec.seek))
80
+ throw new RangeError(`blits: a voice's seek is a finite number of ms, not ${spec.seek}`);
79
81
  if (typeof spec.weight === 'number')
80
82
  plainWeight(spec.weight);
81
83
  fitsKit(patch, mix.kit);
@@ -150,13 +152,8 @@ function enter(mix, voice) {
150
152
  mix.wantsPose = true;
151
153
  if (anchor) {
152
154
  place(mix);
153
- if (!Number.isNaN(mix.now) &&
154
- voice.state === 'pending' &&
155
- localNow(mix, voice) >= voice.start) {
156
- voice.state = 'live';
157
- reorigin(mix, voice, mix.now);
158
- changed(mix, voice);
159
- }
155
+ if (!Number.isNaN(mix.now) && voice.state === 'pending' && localNow(mix, voice) >= voice.start)
156
+ begin(mix, voice, mix.now);
160
157
  }
161
158
  if (owner?.fitting)
162
159
  refit(mix, owner);
package/dist/due.js CHANGED
@@ -20,6 +20,9 @@ function dueOf(mix, voice) {
20
20
  due = Math.min(due, back.at + (1 - back.from) * back.over);
21
21
  if (voice.state === 'pending')
22
22
  return Math.min(due, Number.isNaN(voice.start) ? due : voice.start);
23
+ // A ramp through 0 turns the clock around, which is looked for each frame until it has.
24
+ if (voice.turns)
25
+ return Number.NEGATIVE_INFINITY;
23
26
  if (voice.state === 'fading') {
24
27
  const out = voice.out;
25
28
  if (out === null || out.rest)
@@ -27,20 +30,24 @@ function dueOf(mix, voice) {
27
30
  return Math.min(due, out.at + out.over);
28
31
  }
29
32
  due = Math.min(due, voice.outAt);
30
- if (Number.isFinite(voice.span)) {
31
- const end = voice.span + voice.latest;
32
- // A frozen voice goes live again once its clock is back before its end: by a seek, by a
33
- // subject staggered later than any before, or by running backwards, which is checked each
34
- // frame while it can.
35
- if (voice.state === 'frozen') {
36
- if (voice.rate <= 0 || voice.ramp !== null)
37
- return Number.NEGATIVE_INFINITY;
38
- if (!Number.isNaN(mix.now) && voice.elapsedAt(mix.now) < end)
39
- return Number.NEGATIVE_INFINITY;
40
- }
41
- if (voice.state === 'live')
42
- due = Math.min(due, voice.timeAt(end));
33
+ if (voice.state === 'frozen') {
34
+ const at = Number.isNaN(mix.now) ? Number.NaN : voice.elapsedAt(mix.now);
35
+ // Frozen at its start, having run back to it, it stays while its rate is never above 0,
36
+ // until a handle or a subject staggered ahead of every other moves it.
37
+ const r = voice.ramp;
38
+ const never = r === null ? voice.rate <= 0 : r.from <= 0 && r.to <= 0;
39
+ if (never && !voice.beginless && at <= voice.soonest)
40
+ return due;
41
+ // Frozen at its end, it goes live again once its clock is back before it: by a seek, by a
42
+ // subject staggered later than any before, or by running back, which is checked each frame
43
+ // while it can.
44
+ if (voice.rate <= 0 || r !== null)
45
+ return Number.NEGATIVE_INFINITY;
46
+ if (at < voice.span + voice.latest)
47
+ return Number.NEGATIVE_INFINITY;
43
48
  }
49
+ if (voice.state === 'live')
50
+ due = Math.min(due, voice.endsAt());
44
51
  return due;
45
52
  }
46
53
  /** Files a voice in the due queue at its current due, replacing any entry it had. */
package/dist/everyone.js CHANGED
@@ -32,6 +32,7 @@ export function shares(mix, voice) {
32
32
  voice.holding === null &&
33
33
  voice.blend === null &&
34
34
  !voice.freezesBefore &&
35
+ !voice.beginless &&
35
36
  voice.slots.every((s) => {
36
37
  const channel = mix.channels[s];
37
38
  return channel.rest !== undefined && numericOf(channel)?.op !== 'last';
@@ -113,6 +114,8 @@ export function open(voice, rec, slot) {
113
114
  return;
114
115
  const stamps = voice.stamps;
115
116
  const o = slot * 2 /* Stamp.SIZE */;
117
+ // A subject never read counts its `dt` from the voice's origin, not another subject's last call.
118
+ rec.stepped = rec.since;
116
119
  if (stamps === null || o >= stamps.length) {
117
120
  rec.probed = Number.NaN;
118
121
  rec.seeks = 0;
package/dist/fade.d.ts CHANGED
@@ -21,6 +21,7 @@ export declare function beginFade<I, O>(mix: Mixer<I, O>, voice: Voice<I, O>, op
21
21
  over?: number;
22
22
  at?: 'rest';
23
23
  deadline?: number;
24
+ back?: boolean;
24
25
  }, at?: number): void;
25
26
  /**
26
27
  * Turns a fading voice around: it climbs back from where its fade out had got to, up the same
package/dist/fade.js CHANGED
@@ -104,7 +104,8 @@ export function beginFade(mix, voice, opts, at) {
104
104
  return;
105
105
  const over = mix.reduced ? 0 : (opts.over ?? voice.fade.out ?? 0);
106
106
  // A voice is linked into its subjects' chains once it plays, and a fading one plays.
107
- if (voice.state === 'pending')
107
+ const waiting = voice.state === 'pending';
108
+ if (waiting)
108
109
  changed(mix, voice);
109
110
  // A fade at rest marks each subject's record as it comes to rest, at its next read: one already
110
111
  // read this frame is read again, as after `touch`.
@@ -120,8 +121,11 @@ export function beginFade(mix, voice, opts, at) {
120
121
  rest: opts.at === 'rest',
121
122
  deadline: opts.deadline,
122
123
  };
124
+ if (opts.back)
125
+ voice.out.back = true;
123
126
  noted(mix, voice);
124
- if (opts.at === 'rest')
127
+ // A fade at rest, from a voice's start, or of a voice yet to start takes it off its lane.
128
+ if (opts.at === 'rest' || opts.back || waiting)
125
129
  mix.lanes?.invalidate();
126
130
  else
127
131
  mix.lanes?.refill();
@@ -190,7 +194,9 @@ export function retire(mix, voice, at) {
190
194
  // The record its setting last wrote to, which a retired voice no longer calls for.
191
195
  voice.keepOn = null;
192
196
  mix.retired.push(voice);
193
- voice.doneAt = at ?? (Number.isNaN(mix.now) ? Number.NEGATIVE_INFINITY : mix.now);
197
+ const now = Number.isNaN(mix.now) ? Number.NEGATIVE_INFINITY : mix.now;
198
+ voice.doneAt = at ?? now;
199
+ voice.decidedAt = now;
194
200
  voice.doneSeq = mix.transport.seq;
195
201
  // The frames up to this one showed it, though its fade ended before: it leaves the list now.
196
202
  mix.transport.settle();
@@ -209,6 +215,6 @@ export function retire(mix, voice, at) {
209
215
  // A child the fit skipped had no time in it, so the rest of the fit stands: fitting again
210
216
  // between siblings skipped together would play the ones still to leave.
211
217
  else if (span.fitting !== null && span.state !== 'done' && !voice.skipped)
212
- refit(mix, span);
218
+ refit(mix, span, voice.doneAt);
213
219
  }
214
220
  }
package/dist/fill.js CHANGED
@@ -3,6 +3,7 @@ import { passAt, phaseAt, same, silent, weighed } from './clock.js';
3
3
  import { flush } from './columns.js';
4
4
  import { crowdsUpTo, freshen } from './crowd.js';
5
5
  import { open as openRecord, shut as shutRecord } from './everyone.js';
6
+ import { unband } from './fold.js';
6
7
  import { foldLocus, gatherLocus } from './gather.js';
7
8
  import { runKeys } from './keyfill.js';
8
9
  import { frozenAt } from './lane.js';
@@ -301,6 +302,7 @@ export function one(lane, p, slot) {
301
302
  const elapsed = frozenAt(voice, elapsedNow - delay);
302
303
  if (!(elapsed >= 0)) {
303
304
  data[o + 2 /* Row.WEIGHT */] = 0;
305
+ unband(lane.records[p]);
304
306
  return false;
305
307
  }
306
308
  if (!lane.placed || !same(elapsed, lane.placedAt)) {
@@ -322,6 +324,7 @@ export function one(lane, p, slot) {
322
324
  arg[5 /* Arg.FADE */] = lane.fade;
323
325
  if (!this.signalled(voice, slot, lane.records[p])) {
324
326
  data[o + 2 /* Row.WEIGHT */] = 0;
327
+ unband(lane.records[p]);
325
328
  return false;
326
329
  }
327
330
  w = arg[0 /* Arg.WEIGHT */];
@@ -329,6 +332,8 @@ export function one(lane, p, slot) {
329
332
  else
330
333
  w = weighed(voice.weight, lane.fade, this.parting(voice, slot));
331
334
  data[o + 2 /* Row.WEIGHT */] = w;
335
+ if (!(w > 0))
336
+ unband(lane.records[p]);
332
337
  this.folding = lane;
333
338
  this.rec = lane.records[p] ?? null;
334
339
  if (voice.built !== null) {
package/dist/fold.js CHANGED
@@ -1,5 +1,5 @@
1
- import { frozenTime, passAt, phaseAt, silent } from './clock.js';
2
- import { copy as copyValue } from './clone.js';
1
+ import { passAt, phaseAt, phaseBefore, silent } from './clock.js';
2
+ import { copy as copyValue, first } from './clone.js';
3
3
  import { open as openRecord, shut as shutRecord, weighAt } from './everyone.js';
4
4
  import { recordHost, remember } from './history.js';
5
5
  import { stateful } from './hosts.js';
@@ -69,16 +69,15 @@ export function contribution(voice, subject, now, held) {
69
69
  return null;
70
70
  if (held.rebuilt !== voice.rebuilds)
71
71
  rebuild(this, voice, subject, now, held);
72
- const raw = voice.elapsedAt(now) - held.delay;
73
- // Not `raw < 0`: see `frozenTime` for the clock that reads NaN before its start.
74
- const early = !(raw >= 0);
75
- if (early && !voice.freezesBefore)
72
+ const raw = voice.rawAt(now, held.delay);
73
+ const early = voice.before(raw, now);
74
+ if (early && !voice.holdsFirst)
76
75
  return null;
77
- const elapsed = frozenTime(raw, voice.freezesBefore, voice.freezesAfter, voice.span);
76
+ const elapsed = voice.shownAt(raw);
78
77
  // A frozen subject's clock stands still at the edge it freezes at: -1 before, 1 after, 0 playing.
79
78
  const still = early ? -1 : voice.freezesAfter && raw > voice.span ? 1 : 0;
80
79
  const duration = voice.duration;
81
- const phase = phaseAt(elapsed, duration, voice.passes);
80
+ const phase = elapsed < 0 ? phaseBefore(elapsed, duration) : phaseAt(elapsed, duration, voice.passes);
82
81
  const pass = passAt(elapsed, duration, voice.passes);
83
82
  this.prime(voice, held, now, elapsed, pass);
84
83
  const setting = voice.setting;
@@ -102,20 +101,27 @@ export function contribution(voice, subject, now, held) {
102
101
  recordHost(this, now);
103
102
  reading.horizon = this.horizonFor(voice, held.delay, now);
104
103
  const tick = this.opts.stepMs;
105
- if (voice.patch.step && held.probed !== now && still >= 0) {
106
- // Frozen after, it steps once more to where its last pass ended, and no further.
107
- const to = still === 1 ? voice.timeAt(held.delay + voice.span) : now;
108
- if (held.stepped < held.since) {
109
- held.stepped = held.since;
110
- setting.dt = this.capped(now - held.since);
111
- }
112
- if (tick !== undefined && tick > 0 && !this.reducedNow)
113
- this.tick(voice, subject, held, tick, to);
114
- else if (still === 0 ? now !== held.stepped : to > held.stepped) {
115
- if (still === 1)
116
- setting.dt = this.capped(to - held.stepped);
117
- voice.patch.step(held.state, setting.dt, subject, setting);
118
- held.stepped = to;
104
+ if (voice.patch.step && held.probed !== now) {
105
+ // Frozen after, it steps once more to where its last pass ended, and no further; run back
106
+ // past its start, to where it reached it. Before a start it has yet to reach, it does not step.
107
+ const to = still === 0
108
+ ? now
109
+ : still === 1
110
+ ? voice.timeAt(held.delay + voice.span)
111
+ : voice.ranBackTo(held.delay, now);
112
+ if (!Number.isNaN(to)) {
113
+ if (held.stepped < held.since) {
114
+ held.stepped = held.since;
115
+ setting.dt = this.capped(now - held.since);
116
+ }
117
+ if (tick !== undefined && tick > 0 && !this.reducedNow)
118
+ this.tick(voice, subject, held, tick, to);
119
+ else if (still === 0 ? now !== held.stepped : to > held.stepped) {
120
+ if (still !== 0)
121
+ setting.dt = this.capped(to - held.stepped);
122
+ voice.patch.step(held.state, setting.dt, subject, setting);
123
+ held.stepped = to;
124
+ }
119
125
  }
120
126
  }
121
127
  let delta = null;
@@ -298,7 +304,7 @@ export function apply(pose, voice, held, delta, weight) {
298
304
  const on = this.passes(band === 0 ? undefined : band === 1, weight);
299
305
  bands[i] = on ? 1 : 2;
300
306
  if (on)
301
- pose[key] = pose[key] === undefined ? copy(value) : merged(channel, pose[key], value);
307
+ pose[key] = pose[key] === undefined ? first(value) : merged(channel, pose[key], value);
302
308
  }
303
309
  }
304
310
  /** Clamps every bounded channel of a folded pose into its range, in place. */
@@ -617,7 +623,7 @@ export function foldLoci(subject, pose, head, laned, dry, except, owed) {
617
623
  const passes = this.passes(band === 0 ? undefined : band === 1, w);
618
624
  on[slot] = passes ? 1 : 2;
619
625
  if (passes)
620
- pose[key] = pose[key] === undefined ? copy(value) : merged(channel, pose[key], value);
626
+ pose[key] = pose[key] === undefined ? first(value) : merged(channel, pose[key], value);
621
627
  }
622
628
  }
623
629
  return pose;
@@ -648,7 +654,7 @@ export function read(voice, subject, now, dry, held) {
648
654
  if (held.reaches && held.probed === now && held.delta && held.seeks === voice.seeks) {
649
655
  const setting = voice.setting;
650
656
  // The setting the probe that read the delta had, but for `dt`: a dry read advances nothing.
651
- const elapsed = frozenTime(voice.elapsedAt(now) - held.delay, voice.freezesBefore, voice.freezesAfter, voice.span);
657
+ const elapsed = voice.shownAt(voice.rawAt(now, held.delay));
652
658
  setting.timestamp = now;
653
659
  setting.dt = 0;
654
660
  setting.elapsed = elapsed;
@@ -0,0 +1,21 @@
1
+ import type { Frame } from './transport.js';
2
+ /**
3
+ * The frames a transport's history can still reach, oldest first. A frame leaves the front on
4
+ * most syncs, so the front is an index that moves and the array closes up only now and then.
5
+ */
6
+ export declare class Frames {
7
+ private list;
8
+ private head;
9
+ get length(): number;
10
+ push(frame: Frame): void;
11
+ /** Lets go of every frame before the last one at or before `reach`, giving each to `each`. */
12
+ shed(reach: number, each?: (frame: Frame) => void): void;
13
+ /**
14
+ * The frame a seek or read to mix time `t` lands on: the last one standing at or before `t`,
15
+ * since rate 0 can hold the clock at `t` for many.
16
+ */
17
+ at(t: number): Frame | undefined;
18
+ /** Every frame held, oldest first. */
19
+ all(): Frame[];
20
+ set(frames: Frame[]): void;
21
+ }
package/dist/frames.js ADDED
@@ -0,0 +1,59 @@
1
+ /** Past this many frames let go of at the front, the list is closed up, once they are half of it. */
2
+ const SLACK = 512;
3
+ /**
4
+ * The frames a transport's history can still reach, oldest first. A frame leaves the front on
5
+ * most syncs, so the front is an index that moves and the array closes up only now and then.
6
+ */
7
+ export class Frames {
8
+ list = [];
9
+ head = 0;
10
+ get length() {
11
+ return this.list.length - this.head;
12
+ }
13
+ push(frame) {
14
+ this.list.push(frame);
15
+ }
16
+ /** Lets go of every frame before the last one at or before `reach`, giving each to `each`. */
17
+ shed(reach, each) {
18
+ const list = this.list;
19
+ let head = this.head;
20
+ while (head + 1 < list.length && list[head + 1].at <= reach) {
21
+ each?.(list[head]);
22
+ head++;
23
+ }
24
+ if (head >= SLACK && head * 2 >= list.length) {
25
+ list.splice(0, head);
26
+ head = 0;
27
+ }
28
+ this.head = head;
29
+ }
30
+ /**
31
+ * The frame a seek or read to mix time `t` lands on: the last one standing at or before `t`,
32
+ * since rate 0 can hold the clock at `t` for many.
33
+ */
34
+ at(t) {
35
+ const list = this.list;
36
+ let lo = this.head;
37
+ let hi = list.length - 1;
38
+ let found;
39
+ while (lo <= hi) {
40
+ const mid = (lo + hi) >> 1;
41
+ const f = list[mid];
42
+ if (f.at <= t) {
43
+ found = f;
44
+ lo = mid + 1;
45
+ }
46
+ else
47
+ hi = mid - 1;
48
+ }
49
+ return found;
50
+ }
51
+ /** Every frame held, oldest first. */
52
+ all() {
53
+ return this.list.slice(this.head);
54
+ }
55
+ set(frames) {
56
+ this.list = frames;
57
+ this.head = 0;
58
+ }
59
+ }
package/dist/gone.d.ts CHANGED
@@ -13,7 +13,7 @@ export declare class GoneIndex<I, O> {
13
13
  count: number;
14
14
  general: Voice<I, O>[];
15
15
  named: Store<I, Voice<I, O>[]>;
16
- /** The latest `doneAt` in `of`, and how far any voice finished before one listed ahead of it. */
16
+ /** The latest `reachedTo` in `of`, and how far any voice's falls before one listed ahead of it. */
17
17
  latest: number;
18
18
  slack: number;
19
19
  }
@@ -25,8 +25,8 @@ export declare function goneIndex<I, O>(mix: Mixer<I, O>): GoneIndex<I, O>;
25
25
  */
26
26
  export declare function keepGone<I, O>(mix: Mixer<I, O>, keep: (v: Voice<I, O>) => boolean): void;
27
27
  /**
28
- * Lets go of the gone voices that finished before `reach`. Voices go in about the order they
29
- * finish, so only the front can hold one: past the point where a voice finished `slack` after
30
- * `reach`, none behind it finished before `reach`.
28
+ * Lets go of the gone voices no seek or read back to `reach` finds playing: those that finished
29
+ * before it, in a frame before it. Voices go in about that order, so only the front can hold one:
30
+ * past the point where a voice is reached `slack` after `reach`, none behind it falls before.
31
31
  */
32
32
  export declare function expireGone<I, O>(mix: Mixer<I, O>, reach: number): void;