@msb235/blits 0.2.1 → 0.4.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.
@@ -0,0 +1,353 @@
1
+ import { type Numeric } from './channels.js';
2
+ import type { Subject, Voice } from './mixer.js';
3
+ import { type Motions } from './motion.js';
4
+ import type { Channel } from './types.js';
5
+ /** What qualifying needs of one voice: whether its patch and spec can run on a lane, and its channels. */
6
+ export interface Candidate {
7
+ readonly id: number;
8
+ readonly fits: boolean;
9
+ readonly slots: readonly number[];
10
+ }
11
+ /**
12
+ * Which channels run as lanes and which voices run on them: the fixed point where every voice
13
+ * writing a laned channel fits and writes only laned channels. Only channels some laned voice
14
+ * writes are laned.
15
+ */
16
+ export declare function qualify(numeric: readonly boolean[], voices: readonly Candidate[]): {
17
+ channels: boolean[];
18
+ voices: Set<number>;
19
+ };
20
+ /** What a lane fill asks of the mix it belongs to. */
21
+ export interface LaneHost<I, O> {
22
+ readonly voices: readonly Voice<I, O>[];
23
+ readonly channels: readonly Channel<unknown>[];
24
+ readonly names: readonly string[];
25
+ /** Whether a voice's patch and spec can run on a lane, its channels aside. */
26
+ fits(voice: Voice<I, O>): boolean;
27
+ /** The voice's record for a subject this probe has already linked it to. */
28
+ meet(voice: Voice<I, O>, subject: I): Subject<unknown>;
29
+ /** The voices whose `subjects` name the subject, in voice order. */
30
+ naming(subject: I): readonly Voice<I, O>[] | undefined;
31
+ /** The subject's number, -1 where it has none yet. */
32
+ slotOf(subject: I): number;
33
+ /** The voice's own fade for a subject whose delay ran out at `since`. */
34
+ envelope(voice: Voice<I, O>, since: number): number;
35
+ /** What a subject's own ramp out of the voice leaves of its weight, 0..1. */
36
+ parting(voice: Voice<I, O>, subject: I): number;
37
+ /** Fills the voice's setting and the send target for a call to its patch. */
38
+ ready(voice: Voice<I, O>, subject: I, held: Subject<unknown>, elapsed: number, pass: number, weight: number): void;
39
+ /** Sets `reading.horizon` for the voice and a subject delayed `delay` voice ms. */
40
+ horizon(voice: Voice<I, O>, delay: number): void;
41
+ /** Whether the mix keeps history, so a record a patch call changed may need a copy kept. */
42
+ readonly keeps: boolean;
43
+ /** After a patch call, keeps history of a record that grew kept state. */
44
+ after(voice: Voice<I, O>, held: Subject<unknown>): void;
45
+ /** A patch call left kept state on a record: the voice is stateful from now on. */
46
+ kept(voice: Voice<I, O>): void;
47
+ }
48
+ /** One laned channel: its arithmetic, and every numbered subject's folded value, `axes` per subject. */
49
+ interface Laned {
50
+ name: string;
51
+ /** Its value is a number, its rest a number; otherwise an array, which `vec(1)` is too. */
52
+ scalar: boolean;
53
+ op: Numeric['op'];
54
+ rest: number;
55
+ axes: number;
56
+ values: Float64Array;
57
+ /** An array channel's rest, which a copy starts from as the general path's does. */
58
+ start: readonly number[];
59
+ }
60
+ /** One channel `pull` writes: where in the kit, how many numbers a subject, and its rest. */
61
+ export interface Column {
62
+ key: string;
63
+ slot: number;
64
+ axes: number;
65
+ out: Float64Array;
66
+ /** The rest, clamped, or NaN for a channel with none. */
67
+ rest: Float64Array;
68
+ bounds: readonly [number, number] | undefined;
69
+ }
70
+ export declare function clampRun(out: Float64Array, at: number, n: number, [lo, hi]: readonly [number, number]): void;
71
+ /**
72
+ * Where a motion voice's per-subject numbers live, by position: a lane of one voice, or the crowd
73
+ * of single-subject motion voices, whose positions each belong to a voice of their own.
74
+ */
75
+ export interface Positions<I, O> {
76
+ /** `STRIDE` numbers per position. */
77
+ data: Float64Array;
78
+ /** Each position's last delta, built from its kept sample only when asked. */
79
+ deltas: (Record<string, unknown> | null)[];
80
+ /** Keeps a position's sample, `n` numbers from `xs`. */
81
+ keep(p: number, xs: Float64Array, n: number): void;
82
+ /** Reads a position's kept sample back into `xs`. */
83
+ kept(p: number, xs: Float64Array): void;
84
+ chans: Laned[];
85
+ voiceAt(p: number): Voice<I, O>;
86
+ motionAt(p: number): Motions<I> | undefined;
87
+ }
88
+ /**
89
+ * The lanes of one mix: subject numbers, which channels and voices run on lanes, and the values a
90
+ * frame's fill leaves for probes to copy.
91
+ */
92
+ export declare class Lanes<I, O> {
93
+ private readonly host;
94
+ private readonly numbers;
95
+ private lanes;
96
+ /** The lanes a fill visits: every lane but the solo ones. */
97
+ private runs;
98
+ /** The lanes over every subject that have started playing, by epoch. */
99
+ private dense;
100
+ private readonly byId;
101
+ /** The crowds of single-subject motion voices, one per channel, and which holds each voice. */
102
+ private crowds;
103
+ private readonly crowdOf;
104
+ private readonly lawsByKey;
105
+ private laned;
106
+ /** By kit slot, the laned channel there. */
107
+ private bySlot;
108
+ /** By kit slot, whether a fill leaves the channel's values for probes to copy. */
109
+ readonly copies: boolean[];
110
+ /** Whether every voice in the mix is on a lane, so a filled subject has nothing left to fold. */
111
+ whole: boolean;
112
+ private cap;
113
+ private epochs;
114
+ /** The latest epoch of a lane over every subject, which every subject meets on its next probe. */
115
+ private wide;
116
+ /** Voices that joined, started or left since the last qualify, settled at the next probe. */
117
+ private touched;
118
+ /** The highest voice id the last qualify or settling of `touched` considered. */
119
+ private known;
120
+ /**
121
+ * Per subject number, `SLOT` numbers side by side, so a probe reads one place in memory: which
122
+ * fill last wrote it (0 for none); the latest lane epoch a probe of it has checked it against;
123
+ * how many idle lanes reach it, since a probe reads lanes only where none do; and the probe count
124
+ * at its last probe read from the lanes and at its last probe folded by the general path, with
125
+ * the fill the former read, which say whether a lane or a record holds what `weightOf` reports.
126
+ */
127
+ private per;
128
+ private fills;
129
+ private probes;
130
+ /**
131
+ * Each subject by number as last probed, held from that probe until the next fill uses it, so a
132
+ * fill rarely looks one up through its weak reference, which costs on every look. A host that
133
+ * stops syncing keeps at most one frame's probed subjects alive until its next fill, and none
134
+ * once no lane remains.
135
+ */
136
+ private subjects;
137
+ /** Whether a probe has held a subject since the last fill let them go. */
138
+ private holding;
139
+ /** While a fill runs, so a probe a patch makes from inside it takes the general path. */
140
+ private filling;
141
+ /**
142
+ * Numbers a fill left to the general path: handed out while it ran, or with a voice whose call
143
+ * the general path has to make.
144
+ */
145
+ private readonly late;
146
+ /** What `writeLater` has queued: lane slots and the rows they go to, for one set of columns. */
147
+ private queueSlots;
148
+ private queueRows;
149
+ private queued;
150
+ private inOrder;
151
+ private queuedFor;
152
+ private keeps;
153
+ private now;
154
+ private filledAt;
155
+ /** `reading.moved` at the last fill, so a retarget or push between two probes refills. */
156
+ private moved;
157
+ /** The `now` of the latest probe, and the probe count before its first, to tell a probe this frame. */
158
+ private frameAt;
159
+ private frameProbes;
160
+ /** The probe counts the last frame with a probe began and ended at, which lanes go idle by. */
161
+ private lastFrom;
162
+ private lastTo;
163
+ /** Set when a frame's first probe arrives, so its first fill decides which lanes go idle. */
164
+ private fresh;
165
+ /** Subjects probed this frame and in the last frame with a probe, counted once each. */
166
+ private distinct;
167
+ private lastDistinct;
168
+ /** Numbered subjects alive. */
169
+ private live;
170
+ private filledVersion;
171
+ private qualifiedVersion;
172
+ constructor(host: LaneHost<I, O>);
173
+ /** A change that may move a voice on or off its lane: qualify again, then fill again. */
174
+ invalidate(): void;
175
+ /** A change to a laned voice's weight or clock between probes: fill again. */
176
+ refill(): void;
177
+ /**
178
+ * A voice joined, started playing or left: the next probe takes it on or off its crowd where it
179
+ * can, and qualifies again where it cannot.
180
+ */
181
+ touch(voice: Voice<I, O>): void;
182
+ /** Numbers a subject the mix sees for the first time. */
183
+ number(subject: I): number;
184
+ release(slot: number): void;
185
+ /** A voice faded a subject out of itself alone: its lane lets the subject's position go. */
186
+ part(id: number, slot: number): void;
187
+ /** Takes a crowd row off its subject, to be placed again if a probe meets it again. */
188
+ private unplace;
189
+ /** A voice brought a subject back: its next probe meets every lane again, as it met them first. */
190
+ rejoin(slot: number): void;
191
+ /**
192
+ * A laned voice's weight for a subject at the last frame a probe read it from the lane; undefined
193
+ * where the subject's record holds it instead, because its last probe took the general path or
194
+ * the voice is not on a lane.
195
+ */
196
+ weightOf(id: number, slot: number): number | undefined;
197
+ private reported;
198
+ /**
199
+ * Fills the lanes once a frame, and says whether this probe of a subject reads its values from
200
+ * them. One that a lane has not met yet, newly numbered or newly reached, takes the general path
201
+ * this frame, which is where it is first seen; so does one probed from inside a fill.
202
+ */
203
+ prepare(slot: number, subject: I, now: number, version: number): boolean;
204
+ /**
205
+ * For a `pull` of a list it read last time in the same order, with every voice on a lane, where
206
+ * `heads` holds each position's remembered chain head unless all are known current: what
207
+ * `prepare` and `writeLater` do for each subject from position `from`, while the subject reads
208
+ * from the lanes; returns the first position that does not, or the list's length.
209
+ */
210
+ pullRun(slots: Int32Array, list: readonly I[], was: readonly I[], heads: readonly ({
211
+ version: number;
212
+ } | undefined)[] | null, from: number, columns: readonly Column[], now: number, version: number): number;
213
+ /** Whether this frame's lanes are filled and nothing since asks `begin` to look again. */
214
+ private filled;
215
+ /**
216
+ * What a probe does before its subject, once a frame's lanes are settled: qualifies and fills as
217
+ * needed. Says whether the subject takes the general path, whether only solo lanes exist, so
218
+ * there is nothing to fill, or whether the lanes are filled.
219
+ */
220
+ private begin;
221
+ private general;
222
+ /** Whether a probe has read the subject since the frame began, on either path. */
223
+ private probedThisFrame;
224
+ /**
225
+ * Queues a subject's values for each column at subject `n`'s places, for a `pull` that reads
226
+ * from the lanes while every voice is on one; `flush` writes what is queued, column by column. A
227
+ * channel no lane holds is at rest. Anything queued is written before the lanes fill again.
228
+ */
229
+ writeLater(slot: number, columns: readonly Column[], n: number): void;
230
+ flush(): void;
231
+ /** Writes a subject's laned values into a pose, each array channel into a new array. */
232
+ copy(slot: number, pose: Record<string, unknown>): void;
233
+ /**
234
+ * Gives a probed subject a position on every lane that started playing since the subject was last
235
+ * checked and that reaches it. True when any did, so the probe takes the general path.
236
+ */
237
+ private meet;
238
+ /** Places a crowd voice's row on the subject a probe met, as `Lane.add` adds a position. */
239
+ private place;
240
+ /** Counts an idle lane more or fewer reaching a subject. */
241
+ private reach;
242
+ private forget;
243
+ private grow;
244
+ private requalify;
245
+ /**
246
+ * Rebuilds the crowds from the voices that belong in one, in voice order: a voice already in a
247
+ * crowd keeps its row's numbers, a new one gets a row a probe will place, and a voice no longer in
248
+ * one is handed back to the general path, as a lane's voice is when it leaves.
249
+ */
250
+ private regroup;
251
+ /**
252
+ * Gives a voice the next row of its channel's crowd, made if there is none: a copy of the row it
253
+ * had in `from` at `at`, or a new one. `old` holds the crowds being replaced, whose idle state a
254
+ * new crowd on the same channel keeps. Rows stay in voice order only because voices join in it.
255
+ */
256
+ private join;
257
+ /**
258
+ * A voice starts playing on a lane or crowd: its epoch. Every subject meets a voice over all of
259
+ * them on its next probe; a voice naming its subjects marks only those.
260
+ */
261
+ private open;
262
+ /**
263
+ * Takes the voices `touch` named on or off their crowds, each as it now stands; false at the
264
+ * first that cannot be, which needs a qualify: one that leaves a lane or the general path, which
265
+ * may open a channel, or one that joins anything but a crowd on a laned channel. Neither a voice
266
+ * that fits joining laned channels nor a laned one leaving moves the fixed point `qualify` finds.
267
+ * False too once a crowd is more than half empty rows, which a qualify rebuilds without.
268
+ */
269
+ private retouch;
270
+ /** A crowd voice left: its row stays, empty, until the crowds are next rebuilt. */
271
+ private bury;
272
+ private copyRow;
273
+ private newRow;
274
+ /** A patch's law, as the one array every crowd row with the same law shares. */
275
+ private lawOf;
276
+ /** A crowd voice's patch changed a stretch: its copy is read again at the next fill. */
277
+ private touchedCrowd;
278
+ /** Something on a voice changed: a crowd copies it again at the next fill. */
279
+ voiceChanged(id: number): void;
280
+ /** Hands a crowd voice back to the general path, as `leave` does a lane's. */
281
+ private leaveCrowd;
282
+ /** A crowd row's weight as `reported` reads a lane position's. */
283
+ private reportedRow;
284
+ /** Hands a voice back to the general path, with the weights `weightOf` reports kept on its records. */
285
+ private leave;
286
+ private fillAll;
287
+ /**
288
+ * Sets a lane idle or busy by the share of its subjects probed in the last frame that had a probe,
289
+ * read from about 256 of them a prime stride apart, from an offset that moves each frame, so a host
290
+ * probing every second or third subject is not read as probing all or none. Both paths give the
291
+ * same values, so this only picks the cheaper.
292
+ */
293
+ private pace;
294
+ private flip;
295
+ /** Leaves a lane's subjects to the general path until it wakes, keeping what `weightOf` reports. */
296
+ private rest;
297
+ private wake;
298
+ private subjectAt;
299
+ /** One voice's contribution to every subject it plays on. */
300
+ private run;
301
+ private one;
302
+ /** Reads a keys voice's stops at `phase` into `delta`, interpolating into the reader's `scratch`. */
303
+ private readKeyed;
304
+ /** Calls a stateless fn voice's patch for a subject its general path has met, and folds the delta. */
305
+ private call;
306
+ /** Runs every crowd's rows whose voices come before voice `id`, from where each crowd reached. */
307
+ private crowdsUpTo;
308
+ /**
309
+ * A crowd's rows from its cursor up to voice `id`: what `runMotion` does for a lane's subjects,
310
+ * reading each row's voice and stretch from `hot`, and through `move` for whatever `hot` cannot
311
+ * answer, as `runMotion` does.
312
+ */
313
+ private runCrowd;
314
+ /** A keys or fn row's contribution, as `one` makes a lane position's. */
315
+ private row;
316
+ /** Copies what a fill reads of a crowd row's voice into `hot`; returns the row's flags. */
317
+ private copyVoice;
318
+ /** Copies a crowd row's current stretch from its patch into `hot`; returns the row's flags. */
319
+ private copyStretch;
320
+ /**
321
+ * A motion voice's fill: what `one` and `move` do for each subject, in one loop for the common
322
+ * case, a subject not yet probed this frame with nothing pending, and through `move` for the rest.
323
+ */
324
+ private runMotion;
325
+ /**
326
+ * A motion voice's value for a subject, sampled from the patch's state as its `at` would, but only
327
+ * where that sample changes nothing: one with a change to stamp, commit or let go of goes to the
328
+ * general path, which samples it if and when a probe asks, as it would with no lanes. A probe
329
+ * this frame already read keeps the value it read, as the general path's record would.
330
+ */
331
+ private move;
332
+ /** The delta a motion voice's last sample for position `p` made, built from `samples`. */
333
+ private sampled;
334
+ /**
335
+ * A probe this frame read a motion voice's value for the subject from an earlier fill: write onto
336
+ * its record what the general path's sample would have, so a later read this frame reuses it.
337
+ */
338
+ private settle;
339
+ /** For a keys voice: the delta's value for each channel it writes, read once per phase. */
340
+ private gather;
341
+ /** Folds what `gather` read into a subject's laned values. */
342
+ private fold;
343
+ /**
344
+ * Folds a delta a patch returned into a subject's laned values. The first few channels are read
345
+ * at a site of their own, which in most mixes sees one channel name and stays fast, where one
346
+ * site reading every name in turn slows every read.
347
+ */
348
+ private foldDelta;
349
+ /** Folds a motion sample's axes, kept apart from `foldInto` so neither reads two array kinds. */
350
+ private foldRun;
351
+ private foldInto;
352
+ }
353
+ export {};