@msb235/blits 0.3.0 → 0.5.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 (102) hide show
  1. package/CHANGELOG.md +314 -0
  2. package/README.md +3 -2
  3. package/dist/bare.d.ts +29 -0
  4. package/dist/bare.js +105 -0
  5. package/dist/blend.d.ts +34 -0
  6. package/dist/blend.js +102 -0
  7. package/dist/book.d.ts +53 -0
  8. package/dist/book.js +218 -0
  9. package/dist/chain.d.ts +22 -0
  10. package/dist/chain.js +150 -0
  11. package/dist/channels.d.ts +2 -0
  12. package/dist/channels.js +3 -1
  13. package/dist/clock.d.ts +50 -3
  14. package/dist/clock.js +102 -9
  15. package/dist/clone.d.ts +7 -0
  16. package/dist/clone.js +57 -0
  17. package/dist/columns.d.ts +29 -0
  18. package/dist/columns.js +183 -0
  19. package/dist/crowd.d.ts +128 -0
  20. package/dist/crowd.js +354 -0
  21. package/dist/cue.d.ts +3 -0
  22. package/dist/cue.js +115 -0
  23. package/dist/due.d.ts +12 -0
  24. package/dist/due.js +93 -0
  25. package/dist/fade.d.ts +19 -0
  26. package/dist/fade.js +133 -0
  27. package/dist/fill.d.ts +42 -0
  28. package/dist/fill.js +381 -0
  29. package/dist/fold.d.ts +51 -0
  30. package/dist/fold.js +475 -0
  31. package/dist/gather.d.ts +24 -0
  32. package/dist/gather.js +186 -0
  33. package/dist/handle.d.ts +31 -0
  34. package/dist/handle.js +56 -0
  35. package/dist/held.d.ts +14 -0
  36. package/dist/held.js +117 -0
  37. package/dist/history.d.ts +22 -0
  38. package/dist/history.js +149 -0
  39. package/dist/hosts.d.ts +16 -0
  40. package/dist/hosts.js +178 -0
  41. package/dist/index.d.ts +1 -1
  42. package/dist/keyrows.d.ts +36 -0
  43. package/dist/keyrows.js +138 -0
  44. package/dist/lane.d.ts +210 -0
  45. package/dist/lane.js +187 -0
  46. package/dist/lanes.d.ts +143 -122
  47. package/dist/lanes.js +236 -742
  48. package/dist/locus.d.ts +40 -0
  49. package/dist/locus.js +89 -0
  50. package/dist/marks.d.ts +12 -0
  51. package/dist/marks.js +80 -0
  52. package/dist/meet.d.ts +16 -0
  53. package/dist/meet.js +113 -0
  54. package/dist/mixer.d.ts +244 -169
  55. package/dist/mixer.js +321 -1793
  56. package/dist/motion.d.ts +104 -19
  57. package/dist/motion.js +448 -180
  58. package/dist/move.d.ts +9 -0
  59. package/dist/move.js +190 -0
  60. package/dist/named.d.ts +12 -0
  61. package/dist/named.js +39 -0
  62. package/dist/numbers.d.ts +18 -6
  63. package/dist/numbers.js +59 -31
  64. package/dist/owed.d.ts +24 -0
  65. package/dist/owed.js +51 -0
  66. package/dist/owner.d.ts +43 -0
  67. package/dist/owner.js +117 -0
  68. package/dist/pace.d.ts +40 -0
  69. package/dist/pace.js +113 -0
  70. package/dist/patch.d.ts +51 -10
  71. package/dist/patch.js +140 -45
  72. package/dist/place.d.ts +20 -0
  73. package/dist/place.js +196 -0
  74. package/dist/project.d.ts +4 -0
  75. package/dist/project.js +233 -0
  76. package/dist/pull.d.ts +5 -0
  77. package/dist/pull.js +175 -0
  78. package/dist/qualify.d.ts +31 -0
  79. package/dist/qualify.js +345 -0
  80. package/dist/relink.d.ts +25 -0
  81. package/dist/relink.js +59 -0
  82. package/dist/rows.d.ts +33 -0
  83. package/dist/rows.js +282 -0
  84. package/dist/sample.d.ts +21 -0
  85. package/dist/sample.js +232 -0
  86. package/dist/signals.d.ts +12 -9
  87. package/dist/signals.js +8 -5
  88. package/dist/store.d.ts +10 -3
  89. package/dist/store.js +44 -9
  90. package/dist/strays.d.ts +21 -0
  91. package/dist/strays.js +84 -0
  92. package/dist/tweened.d.ts +11 -0
  93. package/dist/tweened.js +48 -0
  94. package/dist/types.d.ts +261 -42
  95. package/dist/unreached.d.ts +5 -0
  96. package/dist/unreached.js +24 -0
  97. package/dist/voice.d.ts +240 -0
  98. package/dist/voice.js +322 -0
  99. package/dist/weigh.d.ts +26 -0
  100. package/dist/weigh.js +89 -0
  101. package/docs/schema.html +151 -46
  102. package/package.json +5 -2
package/dist/lanes.d.ts CHANGED
@@ -1,20 +1,13 @@
1
- import type { Subject, Voice } from './mixer.js';
1
+ import type { Column } from './columns.js';
2
+ import { type Crowd, row } from './crowd.js';
3
+ import { call, foldKeys, one, parting, readKeyed, reset, run, signalled, subjectAt } from './fill.js';
4
+ import { fold, foldDelta, foldInto, foldRun, gather } from './gather.js';
5
+ import { type Lane, type Laned, type Locus } from './lane.js';
6
+ import type { Watcher } from './motion.js';
7
+ import { type absent, Numbers } from './numbers.js';
8
+ import { Owed } from './owed.js';
2
9
  import type { Channel } from './types.js';
3
- /** What qualifying needs of one voice: whether its patch and spec can run on a lane, and its channels. */
4
- export interface Candidate {
5
- readonly id: number;
6
- readonly fits: boolean;
7
- readonly slots: readonly number[];
8
- }
9
- /**
10
- * Which channels run as lanes and which voices run on them: the fixed point where every voice
11
- * writing a laned channel fits and writes only laned channels. Only channels some laned voice
12
- * writes are laned.
13
- */
14
- export declare function qualify(numeric: readonly boolean[], voices: readonly Candidate[]): {
15
- channels: boolean[];
16
- voices: Set<number>;
17
- };
10
+ import type { Subject, Voice } from './voice.js';
18
11
  /** What a lane fill asks of the mix it belongs to. */
19
12
  export interface LaneHost<I, O> {
20
13
  readonly voices: readonly Voice<I, O>[];
@@ -22,14 +15,26 @@ export interface LaneHost<I, O> {
22
15
  readonly names: readonly string[];
23
16
  /** Whether a voice's patch and spec can run on a lane, its channels aside. */
24
17
  fits(voice: Voice<I, O>): boolean;
25
- /** The voice's record for a subject this probe has already linked it to. */
26
- meet(voice: Voice<I, O>, subject: I): Subject<unknown>;
18
+ /** The voice's record for a subject this probe has already linked it to, from `head` if there. */
19
+ meet(voice: Voice<I, O>, subject: I, head: Subject<unknown> | null, slot: number): Subject<unknown>;
20
+ /** The number `slot` was let go of, to be handed to another subject. */
21
+ forgot(slot: number): void;
27
22
  /** The voices whose `subjects` name the subject, in voice order. */
28
23
  naming(subject: I): readonly Voice<I, O>[] | undefined;
24
+ /** The subject's number, -1 where it has none yet. */
25
+ slotOf(subject: I): number;
29
26
  /** The voice's own fade for a subject whose delay ran out at `since`. */
30
27
  envelope(voice: Voice<I, O>, since: number): number;
28
+ /** What a subject's own ramp out of the voice leaves of its weight, 0..1. */
29
+ parting(voice: Voice<I, O>, subject: I): number;
31
30
  /** Fills the voice's setting and the send target for a call to its patch. */
32
31
  ready(voice: Voice<I, O>, subject: I, held: Subject<unknown>, elapsed: number, pass: number, weight: number): void;
32
+ /**
33
+ * A voice with a signal weight: the signal's value for a subject the general path has met, before
34
+ * the fade and ramp `weighed` applies, with the setting filled in for the call; makes the voice
35
+ * stateful if the signal keeps state. `slot` is the subject's number.
36
+ */
37
+ signal(voice: Voice<I, O>, subject: I, held: Subject<unknown>, elapsed: number, pass: number, slot: number): number;
33
38
  /** Sets `reading.horizon` for the voice and a subject delayed `delay` voice ms. */
34
39
  horizon(voice: Voice<I, O>, delay: number): void;
35
40
  /** Whether the mix keeps history, so a record a patch call changed may need a copy kept. */
@@ -39,39 +44,49 @@ export interface LaneHost<I, O> {
39
44
  /** A patch call left kept state on a record: the voice is stateful from now on. */
40
45
  kept(voice: Voice<I, O>): void;
41
46
  }
42
- /** One channel `pull` writes: where in the kit, how many numbers a subject, and its rest. */
43
- export interface Column {
44
- key: string;
45
- slot: number;
46
- axes: number;
47
- out: Float64Array;
48
- /** The rest, clamped, or NaN for a channel with none. */
49
- rest: Float64Array;
50
- bounds: readonly [number, number] | undefined;
51
- }
52
- export declare function clampRun(out: Float64Array, at: number, n: number, [lo, hi]: readonly [number, number]): void;
53
47
  /**
54
48
  * The lanes of one mix: subject numbers, which channels and voices run on lanes, and the values a
55
49
  * frame's fill leaves for probes to copy.
56
50
  */
57
- export declare class Lanes<I, O> {
58
- private readonly host;
59
- private readonly numbers;
60
- private lanes;
61
- /** The lanes a fill visits: every lane but the solo ones. */
62
- private runs;
51
+ export declare class Lanes<I, O> implements Watcher {
52
+ readonly host: LaneHost<I, O>;
53
+ readonly numbers: Numbers<I>;
54
+ lanes: Lane<I, O>[];
63
55
  /** The lanes over every subject that have started playing, by epoch. */
64
- private dense;
65
- private readonly byId;
66
- private laned;
56
+ dense: Lane<I, O>[];
57
+ readonly byId: Map<number, Lane<I, O>>;
58
+ /** The crowds of single-subject motion voices, one per channel, and which holds each voice. */
59
+ crowds: Crowd<I, O>[];
60
+ readonly crowdOf: Map<number, Crowd<I, O>>;
61
+ /** Whether two crowds share a channel, so their rows must interleave in voice order. */
62
+ overlap: boolean;
63
+ /** The loci whose voices are on lanes, every member of each on one. */
64
+ loci: Locus<I, O>[];
65
+ /** While a fill gathers a locus: that locus and the member gathering, where folds go instead. */
66
+ into: Locus<I, O> | null;
67
+ intoId: number;
68
+ readonly lawsByKey: Map<string, Float64Array<ArrayBufferLike>>;
69
+ lastLaw: Float64Array | null;
70
+ /** The lanes the last `meet` gave a position, and whether it placed a crowd row. */
71
+ readonly met: number[];
72
+ metCrowd: boolean;
73
+ /** By subject number, the laned voices its probes fold on the general path this fill. */
74
+ readonly owed: Owed;
75
+ laned: Laned[];
67
76
  /** By kit slot, the laned channel there. */
68
- private bySlot;
77
+ bySlot: (Laned | undefined)[];
69
78
  /** By kit slot, whether a fill leaves the channel's values for probes to copy. */
70
79
  readonly copies: boolean[];
71
80
  /** Whether every voice in the mix is on a lane, so a filled subject has nothing left to fold. */
72
81
  whole: boolean;
73
- private cap;
74
- private epochs;
82
+ cap: number;
83
+ epochs: number;
84
+ /** The latest epoch of a lane over every subject, which every subject meets on its next probe. */
85
+ wide: number;
86
+ /** Voices that joined, started or left since the last qualify, settled at the next probe. */
87
+ touched: Voice<I, O>[];
88
+ /** The highest voice id the last qualify or settling of `touched` considered. */
89
+ known: number;
75
90
  /**
76
91
  * Per subject number, `SLOT` numbers side by side, so a probe reads one place in memory: which
77
92
  * fill last wrote it (0 for none); the latest lane epoch a probe of it has checked it against;
@@ -79,129 +94,135 @@ export declare class Lanes<I, O> {
79
94
  * at its last probe read from the lanes and at its last probe folded by the general path, with
80
95
  * the fill the former read, which say whether a lane or a record holds what `weightOf` reports.
81
96
  */
82
- private per;
83
- private fills;
84
- private probes;
97
+ per: Float64Array<ArrayBuffer>;
98
+ fills: number;
99
+ probes: number;
85
100
  /**
86
101
  * Each subject by number as last probed, held from that probe until the next fill uses it, so a
87
102
  * fill rarely looks one up through its weak reference, which costs on every look. A host that
88
103
  * stops syncing keeps at most one frame's probed subjects alive until its next fill, and none
89
104
  * once no lane remains.
90
105
  */
91
- private subjects;
106
+ subjects: (I | typeof absent | undefined)[];
92
107
  /** Whether a probe has held a subject since the last fill let them go. */
93
- private holding;
108
+ holding: boolean;
94
109
  /** While a fill runs, so a probe a patch makes from inside it takes the general path. */
95
- private filling;
110
+ filling: boolean;
96
111
  /**
97
112
  * Numbers a fill left to the general path: handed out while it ran, or with a voice whose call
98
113
  * the general path has to make.
99
114
  */
100
- private readonly late;
101
- private keeps;
102
- private now;
103
- private filledAt;
115
+ readonly late: number[];
116
+ /**
117
+ * What `writeLater` and `pullRun` have queued, for one set of columns, as runs: each run's first
118
+ * lane slot, the row it goes to, and how many subjects follow both one apart.
119
+ */
120
+ queueSlots: Int32Array<ArrayBuffer>;
121
+ queueRows: Int32Array<ArrayBuffer>;
122
+ queueCounts: Int32Array<ArrayBuffer>;
123
+ queued: number;
124
+ queuedFor: readonly Column[] | null;
125
+ keeps: boolean;
126
+ now: number;
127
+ filledAt: number;
104
128
  /** `reading.moved` at the last fill, so a retarget or push between two probes refills. */
105
- private moved;
129
+ moved: number;
106
130
  /** The `now` of the latest probe, and the probe count before its first, to tell a probe this frame. */
107
- private frameAt;
108
- private frameProbes;
131
+ frameAt: number;
132
+ frameProbes: number;
109
133
  /** The probe counts the last frame with a probe began and ended at, which lanes go idle by. */
110
- private lastFrom;
111
- private lastTo;
134
+ lastFrom: number;
135
+ lastTo: number;
112
136
  /** Set when a frame's first probe arrives, so its first fill decides which lanes go idle. */
113
- private fresh;
137
+ fresh: boolean;
114
138
  /** Subjects probed this frame and in the last frame with a probe, counted once each. */
115
- private distinct;
116
- private lastDistinct;
139
+ distinct: number;
140
+ lastDistinct: number;
117
141
  /** Numbered subjects alive. */
118
- private live;
119
- private filledVersion;
120
- private qualifiedVersion;
142
+ live: number;
143
+ filledVersion: number;
144
+ qualifiedVersion: number;
121
145
  constructor(host: LaneHost<I, O>);
122
146
  /** A change that may move a voice on or off its lane: qualify again, then fill again. */
123
147
  invalidate(): void;
124
148
  /** A change to a laned voice's weight or clock between probes: fill again. */
125
149
  refill(): void;
150
+ /**
151
+ * A voice joined, started playing or left: the next probe takes it on or off its crowd where it
152
+ * can, and qualifies again where it cannot.
153
+ */
154
+ touch(voice: Voice<I, O>): void;
126
155
  /** Numbers a subject the mix sees for the first time. */
127
156
  number(subject: I): number;
128
157
  release(slot: number): void;
158
+ /** A voice faded a subject out of itself alone: its lane lets the subject's position go. */
159
+ part(id: number, slot: number): void;
160
+ /** A voice brought a subject back: its next probe meets every lane again, as it met them first. */
161
+ rejoin(slot: number): void;
129
162
  /**
130
163
  * A laned voice's weight for a subject at the last frame a probe read it from the lane; undefined
131
164
  * where the subject's record holds it instead, because its last probe took the general path or
132
165
  * the voice is not on a lane.
133
166
  */
134
167
  weightOf(id: number, slot: number): number | undefined;
135
- private reported;
168
+ reported(lane: Lane<I, O>, slot: number): number | undefined;
136
169
  /**
137
170
  * Fills the lanes once a frame, and says whether this probe of a subject reads its values from
138
171
  * them. One that a lane has not met yet, newly numbered or newly reached, takes the general path
139
172
  * this frame, which is where it is first seen; so does one probed from inside a fill.
140
173
  */
141
- prepare(slot: number, subject: I, now: number, version: number): boolean;
142
- private general;
174
+ prepare(slot: number, subject: I, now: number, version: number, head: Subject<unknown> | null): boolean;
175
+ /** Whether this frame's lanes are filled and nothing since asks `begin` to look again. */
176
+ filled(now: number, version: number): boolean;
177
+ /**
178
+ * What a probe does before its subject, once a frame's lanes are settled: qualifies and fills as
179
+ * needed. Says whether the subject takes the general path or the lanes are filled.
180
+ */
181
+ begin(now: number, version: number): number;
182
+ general(slot: number): false;
143
183
  /** Whether a probe has read the subject since the frame began, on either path. */
144
- private probedThisFrame;
184
+ probedThisFrame(slot: number): boolean;
185
+ /** Whether the subject at `slot` reads some laned voice from the general path this fill. */
186
+ owes(slot: number): boolean;
187
+ /** Whether the subject at `slot` reads laned voice `id` from the general path this fill. */
188
+ owesVoice(slot: number, id: number): boolean;
189
+ /** The weight the general path gave a voice the subject at `slot` owes, as `weightOf` reports. */
190
+ paid(id: number, slot: number, w: number): void;
145
191
  /**
146
- * Writes a subject's values into each column at subject `n`'s places, for a probe that reads from
147
- * the lanes while every voice is on one: a channel no lane holds is at rest.
192
+ * Whether a subject's laned values are at their channels' rest, as `atRest` reads the pose `copy`
193
+ * would write: each number within 1e-9 of its rest.
148
194
  */
149
- write(slot: number, columns: readonly Column[], n: number): void;
195
+ rests(slot: number): boolean;
150
196
  /** Writes a subject's laned values into a pose, each array channel into a new array. */
151
197
  copy(slot: number, pose: Record<string, unknown>): void;
198
+ forget(slot: number): void;
199
+ grow(size: number): void;
152
200
  /**
153
- * Gives a probed subject a position on every lane that started playing since the subject was last
154
- * checked and that reaches it. True when any did, so the probe takes the general path.
155
- */
156
- private meet;
157
- /** Counts an idle lane more or fewer reaching a subject. */
158
- private reach;
159
- private forget;
160
- private grow;
161
- private requalify;
162
- /** Hands a voice back to the general path, with the weights `weightOf` reports kept on its records. */
163
- private leave;
164
- private fillAll;
165
- /**
166
- * Sets a lane idle or busy by the share of its subjects probed in the last frame that had a probe,
167
- * read from about 256 of them a prime stride apart, from an offset that moves each frame, so a host
168
- * probing every second or third subject is not read as probing all or none. Both paths give the
169
- * same values, so this only picks the cheaper.
201
+ * A laned voice's patch is about to change subject `s`'s stretch: a crowd copies it again at the
202
+ * next fill, and a lane keeps the sample the old one gave.
170
203
  */
171
- private pace;
172
- private flip;
173
- /** Leaves a lane's subjects to the general path until it wakes, keeping what `weightOf` reports. */
174
- private rest;
175
- private wake;
176
- private subjectAt;
177
- /** One voice's contribution to every subject it plays on. */
178
- private run;
179
- private one;
180
- /**
181
- * A motion voice's value for a subject, sampled from the patch's state as its `at` would, but only
182
- * where that sample changes nothing: one with a change to stamp, commit or let go of goes to the
183
- * general path, which samples it if and when a probe asks, as it would with no lanes. A probe
184
- * this frame already read keeps the value it read, as the general path's record would.
185
- */
186
- private move;
187
- /** The delta a motion voice's last sample for position `p` made, built from `samples`. */
188
- private sampled;
189
- /**
190
- * A probe this frame read a motion voice's value for the subject from an earlier fill: write onto
191
- * its record what the general path's sample would have, so a later read this frame reuses it.
192
- */
193
- private settle;
194
- /** For a keys voice: the delta's value for each channel it writes, read once per phase. */
195
- private gather;
196
- /** Folds what `gather` read into a subject's laned values. */
197
- private fold;
198
- /**
199
- * Folds a delta a patch returned into a subject's laned values. The first few channels are read
200
- * at a site of their own, which in most mixes sees one channel name and stays fast, where one
201
- * site reading every name in turn slows every read.
202
- */
203
- private foldDelta;
204
- /** Folds a motion sample's axes, kept apart from `foldInto` so neither reads two array kinds. */
205
- private foldRun;
206
- private foldInto;
204
+ stretchChanged(id: number, s: number): void;
205
+ /** Something on a voice changed: a crowd copies it again at the next fill. */
206
+ voiceChanged(id: number): void;
207
+ }
208
+ declare const methods: {
209
+ row: typeof row;
210
+ signalled: typeof signalled;
211
+ parting: typeof parting;
212
+ subjectAt: typeof subjectAt;
213
+ reset: typeof reset;
214
+ run: typeof run;
215
+ one: typeof one;
216
+ foldKeys: typeof foldKeys;
217
+ readKeyed: typeof readKeyed;
218
+ call: typeof call;
219
+ gather: typeof gather;
220
+ fold: typeof fold;
221
+ foldDelta: typeof foldDelta;
222
+ foldRun: typeof foldRun;
223
+ foldInto: typeof foldInto;
224
+ };
225
+ type Methods = typeof methods;
226
+ export interface Lanes<I, O> extends Methods {
207
227
  }
228
+ export {};