@msb235/blits 0.6.0 → 0.7.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.
- package/CHANGELOG.md +136 -0
- package/README.md +31 -7
- package/dist/bare.js +7 -1
- package/dist/book.d.ts +7 -0
- package/dist/book.js +35 -4
- package/dist/chain.d.ts +2 -1
- package/dist/chain.js +7 -3
- package/dist/channels.d.ts +12 -19
- package/dist/channels.js +18 -118
- package/dist/clock.d.ts +9 -2
- package/dist/clock.js +10 -2
- package/dist/closed.d.ts +15 -0
- package/dist/closed.js +144 -0
- package/dist/color.d.ts +61 -0
- package/dist/color.js +229 -0
- package/dist/columns.js +2 -1
- package/dist/crowd.d.ts +1 -1
- package/dist/crowd.js +4 -1
- package/dist/cue.d.ts +2 -0
- package/dist/cue.js +78 -27
- package/dist/due.js +3 -0
- package/dist/fade.d.ts +13 -0
- package/dist/fade.js +55 -4
- package/dist/fill.d.ts +1 -1
- package/dist/fill.js +15 -8
- package/dist/fit.d.ts +144 -0
- package/dist/fit.js +181 -0
- package/dist/fold.d.ts +3 -3
- package/dist/fold.js +18 -11
- package/dist/gather.d.ts +6 -0
- package/dist/gather.js +18 -0
- package/dist/handle.d.ts +27 -2
- package/dist/handle.js +60 -11
- package/dist/held.js +4 -0
- package/dist/history.d.ts +15 -2
- package/dist/history.js +54 -9
- package/dist/hosts.d.ts +2 -2
- package/dist/hosts.js +18 -5
- package/dist/index.d.ts +8 -2
- package/dist/index.js +5 -1
- package/dist/lane.d.ts +1 -1
- package/dist/lanes.d.ts +32 -9
- package/dist/lanes.js +53 -24
- package/dist/locus.d.ts +3 -3
- package/dist/locus.js +1 -1
- package/dist/marks.d.ts +3 -0
- package/dist/marks.js +80 -12
- package/dist/meet.d.ts +3 -2
- package/dist/meet.js +15 -3
- package/dist/mixer.d.ts +52 -36
- package/dist/mixer.js +148 -86
- package/dist/motion.d.ts +2 -199
- package/dist/motion.js +2 -652
- package/dist/motions.d.ts +266 -0
- package/dist/motions.js +724 -0
- package/dist/move.d.ts +1 -1
- package/dist/move.js +23 -7
- package/dist/owner.d.ts +1 -1
- package/dist/owner.js +3 -3
- package/dist/pace.d.ts +2 -0
- package/dist/pace.js +8 -0
- package/dist/pack.d.ts +31 -0
- package/dist/pack.js +65 -0
- package/dist/paging.d.ts +63 -0
- package/dist/paging.js +110 -0
- package/dist/patch.d.ts +3 -0
- package/dist/patch.js +2 -0
- package/dist/place.js +74 -25
- package/dist/project.d.ts +7 -4
- package/dist/project.js +117 -78
- package/dist/pull.js +4 -3
- package/dist/qualify.js +4 -2
- package/dist/revive.d.ts +58 -0
- package/dist/revive.js +158 -0
- package/dist/sample.d.ts +1 -1
- package/dist/sample.js +6 -1
- package/dist/seek.d.ts +3 -0
- package/dist/seek.js +311 -0
- package/dist/spans.d.ts +29 -0
- package/dist/spans.js +165 -0
- package/dist/strays.d.ts +1 -1
- package/dist/strays.js +21 -0
- package/dist/tape.d.ts +21 -0
- package/dist/tape.js +65 -0
- package/dist/ticker.d.ts +28 -3
- package/dist/ticker.js +3 -0
- package/dist/transport.d.ts +121 -0
- package/dist/transport.js +271 -0
- package/dist/types.d.ts +404 -38
- package/dist/unpage.d.ts +8 -0
- package/dist/unpage.js +163 -0
- package/dist/voice.d.ts +73 -7
- package/dist/voice.js +116 -4
- package/dist/weigh.js +2 -2
- package/docs/schema.html +120 -31
- package/package.json +2 -1
package/dist/mixer.js
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { blended, blendOf, laneRead, shareKept } from './blend.js';
|
|
2
|
-
import { aims, chain, linkable } from './chain.js';
|
|
2
|
+
import { aims, chain, linkable, relink } from './chain.js';
|
|
3
3
|
import { lerpInto } from './channels.js';
|
|
4
4
|
import { cue } from './cue.js';
|
|
5
5
|
import { beginFade, parting } from './fade.js';
|
|
6
|
-
import { apply, baseFor, clamp, fold, folded, foldLoci, foldWith,
|
|
6
|
+
import { apply, baseFor, clamp, contribution, fold, folded, foldLoci, foldWith, isRest, keyed, linked, near, owedBy, passes, read, slopeFor, tick, } from './fold.js';
|
|
7
7
|
import { held, shownOf, sinceOf, unreachedOf } from './held.js';
|
|
8
|
+
import { leave, releasing } from './history.js';
|
|
8
9
|
import { book, laneHost } from './hosts.js';
|
|
9
10
|
import { Lanes } from './lanes.js';
|
|
10
11
|
import { foldLocus } from './locus.js';
|
|
11
12
|
import { listed } from './marks.js';
|
|
12
|
-
import {
|
|
13
|
+
import { nextFrame } from './move.js';
|
|
13
14
|
import { ownerPatch } from './owner.js';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { project } from './project.js';
|
|
15
|
+
import { Keys } from './paging.js';
|
|
16
|
+
import { projectAll } from './project.js';
|
|
17
17
|
import { keep, pull } from './pull.js';
|
|
18
18
|
import { Steps } from './relink.js';
|
|
19
|
+
import { Outs } from './revive.js';
|
|
20
|
+
import { seek } from './seek.js';
|
|
21
|
+
import { Fitting, refit } from './spans.js';
|
|
19
22
|
import { Store } from './store.js';
|
|
23
|
+
import { record } from './tape.js';
|
|
24
|
+
import { announce, Transport } from './transport.js';
|
|
20
25
|
import { none } from './voice.js';
|
|
21
26
|
import { base, capped, fadeOf, horizonFor, ownedBy, ownerBase, prime, weigh, weighOwned, } from './weigh.js';
|
|
22
27
|
// biome-ignore lint/suspicious/noUnsafeDeclarationMerging: every member of `Methods` is installed below
|
|
@@ -37,31 +42,20 @@ export class Mixer {
|
|
|
37
42
|
* a projection reading back, the copy in force then.
|
|
38
43
|
*/
|
|
39
44
|
hostLog = [];
|
|
40
|
-
/**
|
|
41
|
-
* Marks the host announced on a score: `at` in host time, so the mix's rate never moves one, and
|
|
42
|
-
* NaN until the next sync for one announced as now before any sync; `made` is the mix time it was
|
|
43
|
-
* announced, for a read back to know what was known.
|
|
44
|
-
*/
|
|
45
|
-
announced = [];
|
|
46
45
|
hostThen;
|
|
47
46
|
/** Each subject's last two poses and when they were probed, for `from: 'current'`. */
|
|
48
47
|
pose = new Store();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
/** The clock this mix plays on, which also holds its tape and the marks announced on it. */
|
|
49
|
+
transport;
|
|
50
|
+
/** Its place among the mixes on its transport, in the order they joined. */
|
|
51
|
+
slot = -1;
|
|
52
|
+
/** Taken off its transport, so it takes no more calls until a seek puts it back. */
|
|
53
|
+
dropped = false;
|
|
54
|
+
name;
|
|
56
55
|
/** This mix's frame among every mix's: moved by a sync, and by a control change or drop within one. */
|
|
57
56
|
frame = nextFrame();
|
|
58
|
-
offset = 0;
|
|
59
|
-
/** The mix's own rate; null while it has never been set, when mix time is host time. */
|
|
60
|
-
pace = null;
|
|
61
57
|
/** Pending voices whose start the host gave, by its host time, kept where the rate puts it. */
|
|
62
58
|
pins = null;
|
|
63
|
-
last = Number.NaN;
|
|
64
|
-
rebasing = false;
|
|
65
59
|
wantsPose = false;
|
|
66
60
|
/** The pose `pull` folds a subject into where it cannot read straight from the lanes. */
|
|
67
61
|
scratch;
|
|
@@ -94,10 +88,13 @@ export class Mixer {
|
|
|
94
88
|
if (this.stirred)
|
|
95
89
|
return;
|
|
96
90
|
this.stirred = true;
|
|
91
|
+
if (this.syncing)
|
|
92
|
+
return;
|
|
97
93
|
const fns = this.stirFns;
|
|
98
|
-
if (fns !== null
|
|
94
|
+
if (fns !== null)
|
|
99
95
|
for (const fn of [...fns])
|
|
100
96
|
fn();
|
|
97
|
+
this.transport.woke();
|
|
101
98
|
}
|
|
102
99
|
onWake(fn) {
|
|
103
100
|
if (this.stirFns === null)
|
|
@@ -149,7 +146,7 @@ export class Mixer {
|
|
|
149
146
|
};
|
|
150
147
|
send = (event) => {
|
|
151
148
|
const { voice, subject } = this.sending;
|
|
152
|
-
if (voice === null || this.projecting)
|
|
149
|
+
if (voice === null || this.projecting || voice.setting.timestamp <= this.sentTo)
|
|
153
150
|
return;
|
|
154
151
|
this.sent.push({
|
|
155
152
|
timestamp: voice.setting.timestamp,
|
|
@@ -159,7 +156,9 @@ export class Mixer {
|
|
|
159
156
|
event,
|
|
160
157
|
});
|
|
161
158
|
};
|
|
162
|
-
/** The
|
|
159
|
+
/** The moment a seek went back to: what is stepped again up to it was sent the first time. */
|
|
160
|
+
sentTo = Number.NEGATIVE_INFINITY;
|
|
161
|
+
/** The weight `contribution` found besides the delta, read by the caller at once. */
|
|
163
162
|
w = 0;
|
|
164
163
|
names;
|
|
165
164
|
channels;
|
|
@@ -175,8 +174,14 @@ export class Mixer {
|
|
|
175
174
|
handles = null;
|
|
176
175
|
/** What `book` made, still booking; null while there is none. */
|
|
177
176
|
bookers = null;
|
|
177
|
+
/** The fit a span being cued takes, which `cue` hands its voice. */
|
|
178
|
+
fitting = null;
|
|
178
179
|
/** Every owner still in the mix, null until one is cued. */
|
|
179
180
|
owners = null;
|
|
181
|
+
/** With a history store, the key each subject is paged under; null without one. */
|
|
182
|
+
keys = null;
|
|
183
|
+
/** With a history store, the voices it paged out whose handles are still held; null without one. */
|
|
184
|
+
outs = null;
|
|
180
185
|
constructor(kit, opts) {
|
|
181
186
|
this.kit = kit;
|
|
182
187
|
this.opts = opts;
|
|
@@ -188,6 +193,75 @@ export class Mixer {
|
|
|
188
193
|
this.slotOf.set(k, i);
|
|
189
194
|
});
|
|
190
195
|
this.lanes = opts.lanes === false ? null : new Lanes(laneHost(this));
|
|
196
|
+
this.name = opts.name;
|
|
197
|
+
const shared = opts.transport;
|
|
198
|
+
if (shared !== undefined) {
|
|
199
|
+
if (opts.history !== undefined)
|
|
200
|
+
throw new Error('blits: a mix on a transport keeps the history the transport keeps, not its own');
|
|
201
|
+
this.opts = { ...opts, history: shared.history };
|
|
202
|
+
this.transport = shared;
|
|
203
|
+
}
|
|
204
|
+
else
|
|
205
|
+
this.transport = new Transport(opts.history, false);
|
|
206
|
+
if (this.transport.pager !== null) {
|
|
207
|
+
this.keys = new Keys(opts.keyOf);
|
|
208
|
+
this.outs = new Outs();
|
|
209
|
+
if (shared !== undefined)
|
|
210
|
+
named(shared, opts.name);
|
|
211
|
+
}
|
|
212
|
+
this.transport.join(this);
|
|
213
|
+
}
|
|
214
|
+
/** Throws where the clock is a shared transport's, which only the transport moves. */
|
|
215
|
+
own(what) {
|
|
216
|
+
if (this.transport.shared)
|
|
217
|
+
throw new Error(`blits: ${this.name ?? 'this mix'} plays on a transport, so ${what} goes to the transport`);
|
|
218
|
+
return this.transport;
|
|
219
|
+
}
|
|
220
|
+
// The transport's clock, read and written as the mix's own by every module that moves it.
|
|
221
|
+
get now() {
|
|
222
|
+
return this.transport.now;
|
|
223
|
+
}
|
|
224
|
+
set now(v) {
|
|
225
|
+
this.transport.now = v;
|
|
226
|
+
}
|
|
227
|
+
get u() {
|
|
228
|
+
return this.transport.u;
|
|
229
|
+
}
|
|
230
|
+
set u(v) {
|
|
231
|
+
this.transport.u = v;
|
|
232
|
+
}
|
|
233
|
+
get offset() {
|
|
234
|
+
return this.transport.offset;
|
|
235
|
+
}
|
|
236
|
+
set offset(v) {
|
|
237
|
+
this.transport.offset = v;
|
|
238
|
+
}
|
|
239
|
+
get pace() {
|
|
240
|
+
return this.transport.pace;
|
|
241
|
+
}
|
|
242
|
+
set pace(v) {
|
|
243
|
+
this.transport.pace = v;
|
|
244
|
+
}
|
|
245
|
+
get announced() {
|
|
246
|
+
return this.transport.announced;
|
|
247
|
+
}
|
|
248
|
+
set announced(v) {
|
|
249
|
+
this.transport.announced = v;
|
|
250
|
+
}
|
|
251
|
+
get nextId() {
|
|
252
|
+
return this.transport.nextId;
|
|
253
|
+
}
|
|
254
|
+
set nextId(v) {
|
|
255
|
+
this.transport.nextId = v;
|
|
256
|
+
}
|
|
257
|
+
get last() {
|
|
258
|
+
return this.transport.last;
|
|
259
|
+
}
|
|
260
|
+
get tape() {
|
|
261
|
+
return this.transport.tape;
|
|
262
|
+
}
|
|
263
|
+
get replaying() {
|
|
264
|
+
return this.transport.replaying;
|
|
191
265
|
}
|
|
192
266
|
get reduced() {
|
|
193
267
|
const r = this.opts.reduce;
|
|
@@ -197,6 +271,7 @@ export class Mixer {
|
|
|
197
271
|
return this.opts.band ?? { on: 0.6, off: 0.4 };
|
|
198
272
|
}
|
|
199
273
|
cue(spec) {
|
|
274
|
+
this.attached();
|
|
200
275
|
const engine = this.opts.engine ?? mixer;
|
|
201
276
|
if (!engine.runs.has(spec.patch.form))
|
|
202
277
|
throw new Error(`blits: engine ${engine.name} does not run ${spec.patch.form} patches`);
|
|
@@ -218,38 +293,19 @@ export class Mixer {
|
|
|
218
293
|
throw new Error('blits: an owner does not loop: a pass would have to restart its children');
|
|
219
294
|
return this.cue({ ...spec, patch: ownerPatch });
|
|
220
295
|
}
|
|
221
|
-
|
|
222
|
-
this.
|
|
296
|
+
span(spec) {
|
|
297
|
+
this.fitting = new Fitting(spec);
|
|
223
298
|
try {
|
|
224
|
-
this.
|
|
299
|
+
const handle = this.owns(spec);
|
|
300
|
+
refit(this, this.owners?.find((v) => v.handle === handle));
|
|
301
|
+
return handle;
|
|
225
302
|
}
|
|
226
303
|
finally {
|
|
227
|
-
this.
|
|
304
|
+
this.fitting = null;
|
|
228
305
|
}
|
|
229
306
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
this.offset += timestamp - this.last;
|
|
233
|
-
this.rebasing = false;
|
|
234
|
-
this.last = timestamp;
|
|
235
|
-
const u = timestamp - this.offset;
|
|
236
|
-
const pace = this.pace;
|
|
237
|
-
const now = pace === null ? u : pace.sync(u);
|
|
238
|
-
const later = u !== this.u;
|
|
239
|
-
const still = later && now === this.now;
|
|
240
|
-
this.u = u;
|
|
241
|
-
// Host time moving while the mix clock stands still lands what waits on host time or the host.
|
|
242
|
-
if (now !== this.now || (later && pace !== null && waits(this)))
|
|
243
|
-
move(this, now);
|
|
244
|
-
// It is a frame too, which asks every weight signal again, so one reading input follows it.
|
|
245
|
-
if (still) {
|
|
246
|
-
this.frame = nextFrame();
|
|
247
|
-
this.lanes?.refill();
|
|
248
|
-
}
|
|
249
|
-
const bookers = this.bookers;
|
|
250
|
-
if (bookers !== null)
|
|
251
|
-
for (const b of bookers)
|
|
252
|
-
b.sync();
|
|
307
|
+
sync(timestamp) {
|
|
308
|
+
this.own('sync').sync(timestamp);
|
|
253
309
|
}
|
|
254
310
|
book(opts) {
|
|
255
311
|
return book(this, opts);
|
|
@@ -265,20 +321,25 @@ export class Mixer {
|
|
|
265
321
|
pull(subjects, into) {
|
|
266
322
|
pull(this, subjects, into);
|
|
267
323
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
324
|
+
seek(time) {
|
|
325
|
+
if (this.projecting)
|
|
326
|
+
throw new Error('blits: a projection does not seek');
|
|
327
|
+
seek(this.own('seek'), time);
|
|
328
|
+
}
|
|
329
|
+
prepare(time) {
|
|
330
|
+
return this.own('prepare').prepare(time);
|
|
331
|
+
}
|
|
332
|
+
project(time) {
|
|
333
|
+
return projectAll(this.transport, time).of(this);
|
|
271
334
|
}
|
|
272
335
|
announce(name, opts = {}) {
|
|
273
|
-
|
|
274
|
-
this.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
order: this.nextId++,
|
|
281
|
-
});
|
|
336
|
+
this.attached();
|
|
337
|
+
announce(this.transport, name, opts, this.slot, this.name);
|
|
338
|
+
}
|
|
339
|
+
/** Throws for a mix taken off its transport. */
|
|
340
|
+
attached() {
|
|
341
|
+
if (this.dropped)
|
|
342
|
+
throw new Error(`blits: ${this.name ?? 'this mix'} was dropped from its transport`);
|
|
282
343
|
}
|
|
283
344
|
marks(from, to) {
|
|
284
345
|
return listed(this, from, to).map(({ order: _, ...m }) => m);
|
|
@@ -316,7 +377,7 @@ export class Mixer {
|
|
|
316
377
|
return true;
|
|
317
378
|
}
|
|
318
379
|
rebase() {
|
|
319
|
-
this.
|
|
380
|
+
this.own('rebase').rebase();
|
|
320
381
|
}
|
|
321
382
|
voices(tag) {
|
|
322
383
|
const out = [];
|
|
@@ -341,25 +402,13 @@ export class Mixer {
|
|
|
341
402
|
return this.cued.every((v) => this.still(v, this.now));
|
|
342
403
|
}
|
|
343
404
|
get rate() {
|
|
344
|
-
return this.
|
|
405
|
+
return this.transport.rate;
|
|
345
406
|
}
|
|
346
407
|
set rate(r) {
|
|
347
|
-
this.ramp(r, 0);
|
|
408
|
+
this.own('rate').ramp(r, 0);
|
|
348
409
|
}
|
|
349
410
|
ramp(rate, over) {
|
|
350
|
-
|
|
351
|
-
throw new RangeError(`blits: a mix's rate is a finite number, 0 or more, not ${rate}`);
|
|
352
|
-
if (this.pace === null) {
|
|
353
|
-
this.pace = new Pace(this.opts.history !== undefined);
|
|
354
|
-
// Until now mix time was host time, so a pending voice's start is the host time it was given.
|
|
355
|
-
for (const v of this.cued)
|
|
356
|
-
if (v.state === 'pending' && !v.placing && v.owner === null && v.spec.start !== undefined)
|
|
357
|
-
pin(this, v, v.start);
|
|
358
|
-
}
|
|
359
|
-
const history = this.opts.history;
|
|
360
|
-
const reach = history === undefined ? Number.NEGATIVE_INFINITY : this.now - history.ms;
|
|
361
|
-
this.pace.change(this.u, rate, over, reach);
|
|
362
|
-
this.stir();
|
|
411
|
+
this.own('ramp').ramp(rate, over);
|
|
363
412
|
}
|
|
364
413
|
/** Whether a voice will change no pose from `now` on, short of a change made to it. */
|
|
365
414
|
still(voice, now) {
|
|
@@ -380,6 +429,7 @@ export class Mixer {
|
|
|
380
429
|
mute(opts) {
|
|
381
430
|
for (const voice of this.cued)
|
|
382
431
|
beginFade(this, voice, { over: opts?.over });
|
|
432
|
+
record(this, 'mute', () => this.mute(opts));
|
|
383
433
|
}
|
|
384
434
|
drop(subject) {
|
|
385
435
|
this.frame = nextFrame();
|
|
@@ -397,9 +447,11 @@ export class Mixer {
|
|
|
397
447
|
this.stir();
|
|
398
448
|
// A record of it is only in a voice over every subject, one naming it, or one gone; a ramp out
|
|
399
449
|
// of a voice that does not name it is in `parters`, and a patch's own state in `motions`.
|
|
450
|
+
const kept = releasing(this);
|
|
400
451
|
const forget = (voice) => {
|
|
452
|
+
leave(this, voice, subject, voice.subjects.get(subject));
|
|
401
453
|
voice.subjects.delete(subject);
|
|
402
|
-
voice.motion?.release(subject);
|
|
454
|
+
voice.motion?.release(subject, ...kept);
|
|
403
455
|
voice.parts?.delete(subject);
|
|
404
456
|
voice.parted?.delete(subject);
|
|
405
457
|
voice.blend?.of.reads.delete(subject);
|
|
@@ -427,10 +479,11 @@ export class Mixer {
|
|
|
427
479
|
const strays = this.strays.get(subject);
|
|
428
480
|
if (strays !== undefined)
|
|
429
481
|
for (const motion of strays)
|
|
430
|
-
motion.release(subject);
|
|
482
|
+
motion.release(subject, ...kept);
|
|
431
483
|
this.strays.delete(subject);
|
|
432
484
|
for (const motion of this.strayAll)
|
|
433
|
-
motion.release(subject);
|
|
485
|
+
motion.release(subject, ...kept);
|
|
486
|
+
record(this, 'drop', () => this.drop(subject));
|
|
434
487
|
}
|
|
435
488
|
drain(tag) {
|
|
436
489
|
const all = this.sent;
|
|
@@ -491,7 +544,7 @@ const methods = {
|
|
|
491
544
|
owedBy,
|
|
492
545
|
foldLoci,
|
|
493
546
|
read,
|
|
494
|
-
|
|
547
|
+
contribution,
|
|
495
548
|
keyed,
|
|
496
549
|
tick,
|
|
497
550
|
apply,
|
|
@@ -514,6 +567,7 @@ const methods = {
|
|
|
514
567
|
shareKept,
|
|
515
568
|
parting,
|
|
516
569
|
chain,
|
|
570
|
+
relink,
|
|
517
571
|
linkable,
|
|
518
572
|
aims,
|
|
519
573
|
held,
|
|
@@ -525,6 +579,14 @@ const methods = {
|
|
|
525
579
|
};
|
|
526
580
|
for (const [name, value] of Object.entries(methods))
|
|
527
581
|
Object.defineProperty(Mixer.prototype, name, { value, writable: true, configurable: true });
|
|
582
|
+
/** Refuses a mix joining a transport with a store unnamed, or under a name history still keys records by. */
|
|
583
|
+
function named(transport, name) {
|
|
584
|
+
if (name === undefined)
|
|
585
|
+
throw new Error('blits: a mix on a transport whose history has a store needs a name, which its records are keyed by');
|
|
586
|
+
const taken = [...transport.members, ...transport.dropped.map((d) => d.mix)];
|
|
587
|
+
if (taken.some((m) => m.name === name))
|
|
588
|
+
throw new Error(`blits: a mix named ${name} is already on this transport, or a seek could bring it back`);
|
|
589
|
+
}
|
|
528
590
|
/**
|
|
529
591
|
* The one that ships: every form on the CPU, probed per subject on demand.
|
|
530
592
|
*
|
package/dist/motion.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Easing,
|
|
1
|
+
import { Motions } from './motions.js';
|
|
2
|
+
import type { Easing, Patch } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* A number, or one number per axis.
|
|
5
5
|
*
|
|
@@ -22,32 +22,6 @@ export interface Motion<V extends Value = number> {
|
|
|
22
22
|
/** Units per second. */
|
|
23
23
|
velocity: V;
|
|
24
24
|
}
|
|
25
|
-
interface Change {
|
|
26
|
-
/**
|
|
27
|
-
* Voice ms it takes effect at; absent, until the subject's next read stamps it with that read's
|
|
28
|
-
* time, for one made while no frame had met the subject.
|
|
29
|
-
*/
|
|
30
|
-
at?: number;
|
|
31
|
-
to?: number[];
|
|
32
|
-
v?: number[];
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* The mix playing a patch, asked with its voice's id: an owner and an id, where a pair of closures
|
|
36
|
-
* cost two functions, their contexts and a weak reference per voice.
|
|
37
|
-
*/
|
|
38
|
-
export interface MotionOwner {
|
|
39
|
-
/** The subject's voice time at the mix's latest frame; NaN where no frame of the voice met it. */
|
|
40
|
-
frame(id: number, subject: unknown): number;
|
|
41
|
-
/** Brings a subject the voice faded out back to it, so a change is not made for nothing. */
|
|
42
|
-
revive(id: number, subject: unknown): void;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* What a mix keeping copies of a patch's stretches is told, with its id and the subject's number,
|
|
46
|
-
* before one changes.
|
|
47
|
-
*/
|
|
48
|
-
export interface Watcher {
|
|
49
|
-
stretchChanged(id: number, s: number): void;
|
|
50
|
-
}
|
|
51
25
|
/**
|
|
52
26
|
* A patch whose motion is a closed form per subject, so it lands in the same place at any frame
|
|
53
27
|
* rate, and whose changes mid-flight start from where the subject is and how fast it moves.
|
|
@@ -68,177 +42,6 @@ export type Moving<I, O, V extends Value> = Patch<I, O, void> & {
|
|
|
68
42
|
*/
|
|
69
43
|
push(subject: I, velocity: V, at?: number): void;
|
|
70
44
|
};
|
|
71
|
-
interface Shape<I> {
|
|
72
|
-
from: (subject: I) => number[];
|
|
73
|
-
/** How fast each axis starts moving, given where it starts: still unless the options say. */
|
|
74
|
-
velocity: (subject: I, x: number[]) => number[];
|
|
75
|
-
/** Where it heads when released from `x` at `v`, given where it was heading. */
|
|
76
|
-
aim: (x: number[], v: number[], was: number[] | null, subject: I) => number[];
|
|
77
|
-
/** `[form, settle, k1, k2, k3]`. */
|
|
78
|
-
law: readonly number[];
|
|
79
|
-
/** Whether a subject's value is a number rather than an array. */
|
|
80
|
-
scalar: (subject: I) => boolean;
|
|
81
|
-
/** Whether every subject's value is a number; undefined where that depends on the subject. */
|
|
82
|
-
scalarEvery(): boolean | undefined;
|
|
83
|
-
/** A tween's easing, which its law cannot hold; undefined, but present, on every other shape. */
|
|
84
|
-
ease: Curve | undefined;
|
|
85
|
-
/** A tween's seconds for a stretch the subject starts now; undefined, but present, on the rest. */
|
|
86
|
-
ms: ((subject: I) => number) | undefined;
|
|
87
|
-
/** The patch's kind and constants, as `Patch.motion` reports them. */
|
|
88
|
-
spec(): MotionSpec;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* A motion patch's subjects: the stretch each is playing, in one flat array by a number the patch
|
|
92
|
-
* gives it, with earlier stretches a read back may reach and changes not yet applied beside them.
|
|
93
|
-
* The one copy, read by `at` and by a mix's lane alike.
|
|
94
|
-
*
|
|
95
|
-
* After the law, each subject's run of `stride` numbers is its release time, its flags, a tween's
|
|
96
|
-
* seconds for the stretch, then `x0`, `v0` and `to` per axis. A live sample reads this one buffer and nothing else the patch owns: at
|
|
97
|
-
* 10k springs of one subject each, a buffer per field, a map lookup per sample and the law in an
|
|
98
|
-
* object of its own took a call from 130 ns to 490.
|
|
99
|
-
*/
|
|
100
|
-
export declare class Motions<I> {
|
|
101
|
-
private readonly shape;
|
|
102
|
-
private readonly numbers;
|
|
103
|
-
/** Numbers by subject once a second is numbered: till then the one subject is found by `numbers`. */
|
|
104
|
-
private readonly slots;
|
|
105
|
-
/** Axes per subject; -1 until the first subject sets it. */
|
|
106
|
-
n: number;
|
|
107
|
-
private cap;
|
|
108
|
-
private stride;
|
|
109
|
-
/**
|
|
110
|
-
* The law, then each subject's run; empty until the first subject, the law read from `shape`.
|
|
111
|
-
* Read outside, at `bareAt`, and written only here.
|
|
112
|
-
*/
|
|
113
|
-
runs: Float64Array<ArrayBuffer>;
|
|
114
|
-
/**
|
|
115
|
-
* Where `sample` leaves a subject's position and velocity, per axis. Shared by every patch, so
|
|
116
|
-
* read it before the next sample.
|
|
117
|
-
*/
|
|
118
|
-
xs: Float64Array<ArrayBuffer>;
|
|
119
|
-
vs: Float64Array<ArrayBuffer>;
|
|
120
|
-
/**
|
|
121
|
-
* By subject number, changes not yet applied and earlier stretches a read back may reach: null
|
|
122
|
-
* until a subject first has one, since many patches are never changed. Each starts with room for
|
|
123
|
-
* one: an empty array written at 0 reserves 17, and most patches have one subject.
|
|
124
|
-
*/
|
|
125
|
-
private pending;
|
|
126
|
-
private older;
|
|
127
|
-
/**
|
|
128
|
-
* The mix playing the patch and its voice's id, which an untimed change and a `read` with no time
|
|
129
|
-
* ask for the latest frame. Set by the mix that cues the patch, and cleared when its voice retires.
|
|
130
|
-
*/
|
|
131
|
-
owner: MotionOwner | null;
|
|
132
|
-
ownerId: number;
|
|
133
|
-
/** Whether the channel it was cued on holds a number; undefined until it is cued. */
|
|
134
|
-
private holdsNumber;
|
|
135
|
-
private channel;
|
|
136
|
-
/**
|
|
137
|
-
* Records what the channel the patch is cued on holds, refusing a value of the other kind: at once
|
|
138
|
-
* where every subject's value is one kind, else on the first sample of a subject whose value is not.
|
|
139
|
-
*/
|
|
140
|
-
cuedOn(channel: string, holdsNumber: boolean): void;
|
|
141
|
-
private frame;
|
|
142
|
-
constructor(shape: Shape<I>);
|
|
143
|
-
/** The patch's number for `subject`, made with its first stretch on first ask. */
|
|
144
|
-
slot(subject: I): number;
|
|
145
|
-
/** The patch's number for `subject`, undefined where it has none. */
|
|
146
|
-
private known;
|
|
147
|
-
/** Forgets a subject, so a later ask starts it afresh from `from`. */
|
|
148
|
-
release(subject: I): void;
|
|
149
|
-
/**
|
|
150
|
-
* Told, with `watchId`, whenever a subject's stretch or what is pending for it changes, so a mix
|
|
151
|
-
* keeping a copy of it knows to read it again. Set by the mix, cleared when its voice retires. An
|
|
152
|
-
* owner and an id, where a callback cost a closure and its context per patch.
|
|
153
|
-
*/
|
|
154
|
-
watcher: Watcher | null;
|
|
155
|
-
watchId: number;
|
|
156
|
-
/** The easing a tween's stretches follow; undefined for every other shape. */
|
|
157
|
-
get ease(): Curve | undefined;
|
|
158
|
-
/** The patch's kind and constants. */
|
|
159
|
-
spec(): MotionSpec;
|
|
160
|
-
/** A copy of the patch's law, `[form, settle, k1, k2, k3]`. */
|
|
161
|
-
law(): Float64Array;
|
|
162
|
-
/** Whether `law` holds this patch's law, number for number, as `Object.is` compares them. */
|
|
163
|
-
hasLaw(law: Float64Array): boolean;
|
|
164
|
-
/**
|
|
165
|
-
* Copies subject `s`'s current stretch into `out` from `o` as its release time, its seconds, then
|
|
166
|
-
* `x0`, `v0` and `to` per axis; false, copying nothing, while it has a change pending or an
|
|
167
|
-
* earlier stretch kept, which only `sample` handles.
|
|
168
|
-
*/
|
|
169
|
-
stretchInto(s: number, out: Float64Array, o: number): boolean;
|
|
170
|
-
/** Whether subject `s`'s value is a number rather than an array. */
|
|
171
|
-
scalar(s: number): boolean;
|
|
172
|
-
/** The value `at` hands the mix: the first axis for a number, a fresh array otherwise. */
|
|
173
|
-
value(s: number, xs: Float64Array): number | number[];
|
|
174
|
-
/**
|
|
175
|
-
* Position and velocity at voice time `t` into `xo` and `vo`, a tween's velocity left at 0. A live
|
|
176
|
-
* read stamps every untimed change with `t` and commits every change due by then, in time order;
|
|
177
|
-
* a projection's read applies the timed ones to a copy and commits nothing.
|
|
178
|
-
*/
|
|
179
|
-
sample(s: number, t: number, xo: Float64Array, vo: Float64Array): void;
|
|
180
|
-
/**
|
|
181
|
-
* Where subject `s`'s run starts in `runs` (its release time, then flags, seconds, `x0`, `v0`
|
|
182
|
-
* and `to`) while it has nothing pending and no earlier stretch kept; -1 for any other.
|
|
183
|
-
*/
|
|
184
|
-
bareAt(s: number): number;
|
|
185
|
-
/**
|
|
186
|
-
* A live `sample` at `t` for a subject with nothing pending and no earlier stretch kept, true
|
|
187
|
-
* then; false, writing nothing, for any other, which `quiet` and `sample` take instead.
|
|
188
|
-
*/
|
|
189
|
-
sampleBare(s: number, t: number, xo: Float64Array, vo: Float64Array): boolean;
|
|
190
|
-
/**
|
|
191
|
-
* Whether every subject has landed on its target at its voice time at the latest frame, as a
|
|
192
|
-
* sample there would find; one with a change waiting has not. Commits nothing.
|
|
193
|
-
*/
|
|
194
|
-
landed(): boolean;
|
|
195
|
-
/**
|
|
196
|
-
* Whether a live `sample` at `t` would leave the subject's state as it is: nothing to stamp or
|
|
197
|
-
* commit by then, and nothing older than `reading.horizon` to let go of.
|
|
198
|
-
*/
|
|
199
|
-
quiet(s: number, t: number): boolean;
|
|
200
|
-
/** Position and velocity at `at`, default the latest frame; undefined until there is one. */
|
|
201
|
-
read(subject: I, at?: number): {
|
|
202
|
-
x: Float64Array;
|
|
203
|
-
v: Float64Array;
|
|
204
|
-
s: number;
|
|
205
|
-
} | undefined;
|
|
206
|
-
/**
|
|
207
|
-
* Queues a retarget or push, untimed at the latest frame, for `subject`'s next read past its time.
|
|
208
|
-
* The queue keeps the changes with a time in time order, ahead of any still waiting for one.
|
|
209
|
-
*/
|
|
210
|
-
change(subject: I, c: Change): void;
|
|
211
|
-
/** Files a change with a time after every one due by then, ahead of those still waiting for one. */
|
|
212
|
-
private queue;
|
|
213
|
-
/** Every change due by `t` applied to a copy of the stretch playing then, committing nothing. */
|
|
214
|
-
private peek;
|
|
215
|
-
private check;
|
|
216
|
-
private flag;
|
|
217
|
-
forget(s: number): void;
|
|
218
|
-
/** Where subject `s`'s run starts in `runs`. */
|
|
219
|
-
base(s: number): number;
|
|
220
|
-
private grow;
|
|
221
|
-
private write;
|
|
222
|
-
/** The stretch subject `s` is playing now, as an object. */
|
|
223
|
-
private latest;
|
|
224
|
-
/** The stretch playing at voice time `t`: the latest released by then, else the first. */
|
|
225
|
-
private playing;
|
|
226
|
-
private applied;
|
|
227
|
-
private commit;
|
|
228
|
-
private insert;
|
|
229
|
-
/** Lets go of stretches older than the one in force at `reading.horizon`. */
|
|
230
|
-
private prune;
|
|
231
|
-
private evaluateSegment;
|
|
232
|
-
private evaluate;
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* A stretch `t` voice ms into it, released at `at` from `x0` moving at `v0` toward `to` (each read
|
|
236
|
-
* from its offset), into `xo` and `vo`: the one copy of the closed forms, which `law` (a patch's
|
|
237
|
-
* `[form, settle, k1, k2, k3]`, the head of a patch's buffer or a copy of it) picks between. A tween reads `ease` and
|
|
238
|
-
* `ms`, the stretch's length, dividing in milliseconds so a boundary lands exactly; every other
|
|
239
|
-
* form ignores them.
|
|
240
|
-
*/
|
|
241
|
-
export declare function closed(law: Float64Array, ease: Curve | undefined, n: number, at: number, ms: number, x0: ArrayLike<number>, x: number, v0: ArrayLike<number>, v: number, to: ArrayLike<number>, g: number, t: number, xo: Float64Array, vo: Float64Array): boolean;
|
|
242
45
|
/** The state behind a `'motion'` patch, for an engine that reads it directly. */
|
|
243
46
|
export declare function motionOf<I>(p: object): Motions<I> | undefined;
|
|
244
47
|
interface Common<I, V extends Value> {
|