@webmusic/kernel 0.1.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/LICENSE +21 -0
- package/README.md +435 -0
- package/dist/audio-context.cjs +10 -0
- package/dist/audio-context.cjs.map +1 -0
- package/dist/audio-context.d.cts +13 -0
- package/dist/audio-context.d.ts +13 -0
- package/dist/audio-context.js +10 -0
- package/dist/audio-context.js.map +1 -0
- package/dist/build-receipt.json +7 -0
- package/dist/chunk-3INDOVUC.cjs +134 -0
- package/dist/chunk-3INDOVUC.cjs.map +1 -0
- package/dist/chunk-53YD73OY.js +162 -0
- package/dist/chunk-53YD73OY.js.map +1 -0
- package/dist/chunk-7ZTZZ5PN.cjs +25 -0
- package/dist/chunk-7ZTZZ5PN.cjs.map +1 -0
- package/dist/chunk-BR63OD53.cjs +1 -0
- package/dist/chunk-BR63OD53.cjs.map +1 -0
- package/dist/chunk-C3YWUZW3.cjs +57 -0
- package/dist/chunk-C3YWUZW3.cjs.map +1 -0
- package/dist/chunk-FJLY3RWZ.js +134 -0
- package/dist/chunk-FJLY3RWZ.js.map +1 -0
- package/dist/chunk-GO4N5T27.js +94 -0
- package/dist/chunk-GO4N5T27.js.map +1 -0
- package/dist/chunk-HOKRTYPV.js +199 -0
- package/dist/chunk-HOKRTYPV.js.map +1 -0
- package/dist/chunk-HY2YIL75.js +16 -0
- package/dist/chunk-HY2YIL75.js.map +1 -0
- package/dist/chunk-HZQX4J2J.cjs +199 -0
- package/dist/chunk-HZQX4J2J.cjs.map +1 -0
- package/dist/chunk-ILKEVUJ3.js +57 -0
- package/dist/chunk-ILKEVUJ3.js.map +1 -0
- package/dist/chunk-JNXB74G3.cjs +987 -0
- package/dist/chunk-JNXB74G3.cjs.map +1 -0
- package/dist/chunk-N6KU2HYA.js +25 -0
- package/dist/chunk-N6KU2HYA.js.map +1 -0
- package/dist/chunk-PXG64RU4.js +25 -0
- package/dist/chunk-PXG64RU4.js.map +1 -0
- package/dist/chunk-SM5YPDDI.cjs +162 -0
- package/dist/chunk-SM5YPDDI.cjs.map +1 -0
- package/dist/chunk-TEM2I2NN.js +1 -0
- package/dist/chunk-TEM2I2NN.js.map +1 -0
- package/dist/chunk-UMTPJ76S.cjs +94 -0
- package/dist/chunk-UMTPJ76S.cjs.map +1 -0
- package/dist/chunk-VVZX7DQ6.cjs +254 -0
- package/dist/chunk-VVZX7DQ6.cjs.map +1 -0
- package/dist/chunk-VY6WWZSW.cjs +16 -0
- package/dist/chunk-VY6WWZSW.cjs.map +1 -0
- package/dist/chunk-WNFGDB7B.js +254 -0
- package/dist/chunk-WNFGDB7B.js.map +1 -0
- package/dist/chunk-XBJBY4J5.js +987 -0
- package/dist/chunk-XBJBY4J5.js.map +1 -0
- package/dist/chunk-ZMU72HJS.cjs +25 -0
- package/dist/chunk-ZMU72HJS.cjs.map +1 -0
- package/dist/effect.cjs +2 -0
- package/dist/effect.cjs.map +1 -0
- package/dist/effect.d.cts +19 -0
- package/dist/effect.d.ts +19 -0
- package/dist/effect.js +2 -0
- package/dist/effect.js.map +1 -0
- package/dist/elements.cjs +24 -0
- package/dist/elements.cjs.map +1 -0
- package/dist/elements.d.cts +76 -0
- package/dist/elements.d.ts +76 -0
- package/dist/elements.js +24 -0
- package/dist/elements.js.map +1 -0
- package/dist/events.cjs +8 -0
- package/dist/events.cjs.map +1 -0
- package/dist/events.d.cts +36 -0
- package/dist/events.d.ts +36 -0
- package/dist/events.js +8 -0
- package/dist/events.js.map +1 -0
- package/dist/index.cjs +77 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/dist/meter.cjs +12 -0
- package/dist/meter.cjs.map +1 -0
- package/dist/meter.d.cts +76 -0
- package/dist/meter.d.ts +76 -0
- package/dist/meter.js +12 -0
- package/dist/meter.js.map +1 -0
- package/dist/player.cjs +16 -0
- package/dist/player.cjs.map +1 -0
- package/dist/player.d.cts +49 -0
- package/dist/player.d.ts +49 -0
- package/dist/player.js +16 -0
- package/dist/player.js.map +1 -0
- package/dist/sync.cjs +12 -0
- package/dist/sync.cjs.map +1 -0
- package/dist/sync.d.cts +304 -0
- package/dist/sync.d.ts +304 -0
- package/dist/sync.js +12 -0
- package/dist/sync.js.map +1 -0
- package/dist/tick.cjs +10 -0
- package/dist/tick.cjs.map +1 -0
- package/dist/tick.d.cts +48 -0
- package/dist/tick.d.ts +48 -0
- package/dist/tick.js +10 -0
- package/dist/tick.js.map +1 -0
- package/dist/transport.cjs +8 -0
- package/dist/transport.cjs.map +1 -0
- package/dist/transport.d.cts +114 -0
- package/dist/transport.d.ts +114 -0
- package/dist/transport.js +8 -0
- package/dist/transport.js.map +1 -0
- package/dist/worker.cjs +10 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.cts +49 -0
- package/dist/worker.d.ts +49 -0
- package/dist/worker.js +10 -0
- package/dist/worker.js.map +1 -0
- package/package.json +164 -0
package/dist/sync.d.cts
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { TransportClockReader } from './transport.cjs';
|
|
2
|
+
import { TickSourceOptions } from './tick.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Master role: the transport whose clock is the group's timeline. Everything
|
|
6
|
+
* is on the master's own position axis (for a score player: nominal score
|
|
7
|
+
* seconds; for a clip player: clip seconds).
|
|
8
|
+
*/
|
|
9
|
+
interface SyncMasterTransport {
|
|
10
|
+
/**
|
|
11
|
+
* Start the transport. `when` (optional, absolute reference-clock seconds)
|
|
12
|
+
* proposes an ARMED start: a master supporting scheduled starts arms its
|
|
13
|
+
* clock there so followers can join at the very same instant. Masters
|
|
14
|
+
* without the capability ignore the argument and start immediately — the
|
|
15
|
+
* group detects which happened by observing `clock.holding`, never
|
|
16
|
+
* through a declared flag.
|
|
17
|
+
*/
|
|
18
|
+
play(when?: number): Promise<void> | void;
|
|
19
|
+
pause(): void;
|
|
20
|
+
stop(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Seek to a position on the master's axis. A returned promise settles
|
|
23
|
+
* once the seek has been applied and any mid-playback restart attempted;
|
|
24
|
+
* the group awaits it before re-anchoring followers. The promise MAY
|
|
25
|
+
* resolve with the transport left paused when the restart failed — the
|
|
26
|
+
* group treats that as a failed resume: it pauses the followers, settles
|
|
27
|
+
* into the paused state and reports 'resume after seek' through
|
|
28
|
+
* {@link TransportGroupOptions.onOperationError}. While playing, the
|
|
29
|
+
* group passes a proposed re-entry time the same way {@link play} does.
|
|
30
|
+
*/
|
|
31
|
+
seekPosition(position: number, when?: number): void | Promise<void>;
|
|
32
|
+
setRate?(rate: number): void;
|
|
33
|
+
/** Current position on the master's axis. */
|
|
34
|
+
readonly position: number;
|
|
35
|
+
/** Read-only transport clock (master position axis). REQUIRED — wrap a
|
|
36
|
+
* clockless transport in {@link MirrorClockMaster}. */
|
|
37
|
+
readonly clock: TransportClockReader;
|
|
38
|
+
/**
|
|
39
|
+
* Optional pre-drift-check reconciliation hook (adapters). Called once
|
|
40
|
+
* per drift check with the current reference time; returning 'stalled'
|
|
41
|
+
* tells the group the master stopped on its own (the adapter has already
|
|
42
|
+
* paused its clock) — the group then wraps or settles exactly as for an
|
|
43
|
+
* observed master stop.
|
|
44
|
+
*/
|
|
45
|
+
reconcile?(now: number): 'ok' | 'stalled';
|
|
46
|
+
dispose?(): void;
|
|
47
|
+
}
|
|
48
|
+
/** Follower role: a transport that can join the master's timeline. */
|
|
49
|
+
interface SyncFollowerTransport {
|
|
50
|
+
/**
|
|
51
|
+
* Start playback. `when` (optional, absolute reference-clock seconds) is
|
|
52
|
+
* the scheduled start the join dance relies on: the follower MUST honor
|
|
53
|
+
* it sample-accurately for gapless joins (a follower that starts
|
|
54
|
+
* immediately instead will sit one lead-in ahead and be re-corrected
|
|
55
|
+
* forever by the drift monitor).
|
|
56
|
+
*/
|
|
57
|
+
play(when?: number): Promise<void> | void;
|
|
58
|
+
pause(): void;
|
|
59
|
+
stop(): void;
|
|
60
|
+
seek(position: number): void;
|
|
61
|
+
setRate?(rate: number): void;
|
|
62
|
+
/** Current position on the follower's own axis. */
|
|
63
|
+
readonly position: number;
|
|
64
|
+
/** Whether the follower is running, when it can say (optional). */
|
|
65
|
+
readonly running?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Read-only clock on the follower's own axis, when the transport has one.
|
|
68
|
+
* When present, the drift monitor reads position and running state from
|
|
69
|
+
* it instead of sampling `position`/`running`.
|
|
70
|
+
*/
|
|
71
|
+
readonly clock?: TransportClockReader;
|
|
72
|
+
dispose?(): void;
|
|
73
|
+
}
|
|
74
|
+
/** Per-follower registration options. */
|
|
75
|
+
interface FollowerOptions {
|
|
76
|
+
/** Follower position corresponding to master position zero. Default 0. */
|
|
77
|
+
offsetSeconds?: number;
|
|
78
|
+
/** Positive affine scale: local position = offsetSeconds + master position × positionScale.
|
|
79
|
+
* The follower's playback rate is scaled by the same factor. Default 1.
|
|
80
|
+
* This is a constant map, not nonlinear warping. */
|
|
81
|
+
positionScale?: number;
|
|
82
|
+
/** Local loop bounds for a transport ALREADY configured to loop natively.
|
|
83
|
+
* The group maps join/seek positions and drift into this phase; it does not
|
|
84
|
+
* configure or schedule that native loop. Positions before the loop end
|
|
85
|
+
* retain their intro; at/past the end they wrap into [start, end). */
|
|
86
|
+
loop?: SyncLoopRegion;
|
|
87
|
+
}
|
|
88
|
+
interface TransportGroupOptions {
|
|
89
|
+
/** Scheduling headroom before followers join, in seconds. Default 0.06. */
|
|
90
|
+
leadInSeconds?: number;
|
|
91
|
+
/** Re-join a follower when |follower − expected| exceeds this. Default 0.03 s. */
|
|
92
|
+
driftToleranceSeconds?: number;
|
|
93
|
+
/** Drift check cadence. Default 250 ms. 0 disables the monitor. */
|
|
94
|
+
driftCheckIntervalMs?: number;
|
|
95
|
+
/** Loop region on the master axis; also settable live via {@link TransportGroup.setLoop}. */
|
|
96
|
+
loop?: SyncLoopRegion | null;
|
|
97
|
+
/** Injectable tick source options (tests; custom hosting). */
|
|
98
|
+
tick?: TickSourceOptions;
|
|
99
|
+
/**
|
|
100
|
+
* Observer for failures of the group's own fire-and-forget operations
|
|
101
|
+
* (drift and rate re-joins, loop wraps, pause/stop reconciliation). Those
|
|
102
|
+
* run behind the command queue with no caller promise to reject, and on
|
|
103
|
+
* failure they settle the group into a paused state — without an observer
|
|
104
|
+
* that settlement is silent. Observer exceptions are swallowed.
|
|
105
|
+
*/
|
|
106
|
+
onOperationError?: (operation: string, error: unknown) => void;
|
|
107
|
+
}
|
|
108
|
+
/** A loop region on the master position axis. */
|
|
109
|
+
interface SyncLoopRegion {
|
|
110
|
+
startSeconds: number;
|
|
111
|
+
endSeconds: number;
|
|
112
|
+
}
|
|
113
|
+
/** Commands accepted by the group's single authority. Positions use the master's
|
|
114
|
+
* stable content axis, never a duration divided by the current playback rate. */
|
|
115
|
+
type TransportCommand = {
|
|
116
|
+
readonly type: 'play' | 'pause' | 'stop';
|
|
117
|
+
} | {
|
|
118
|
+
readonly type: 'seek';
|
|
119
|
+
readonly position: number;
|
|
120
|
+
} | {
|
|
121
|
+
readonly type: 'rate';
|
|
122
|
+
readonly rate: number;
|
|
123
|
+
} | {
|
|
124
|
+
readonly type: 'loop';
|
|
125
|
+
readonly loop: SyncLoopRegion | null;
|
|
126
|
+
};
|
|
127
|
+
/** Coherent observation at one reference-clock instant. This is a snapshot,
|
|
128
|
+
* not a display timer; read again or use clock.positionAt for moving positions. */
|
|
129
|
+
interface TransportSnapshot {
|
|
130
|
+
readonly revision: number;
|
|
131
|
+
readonly referenceTime: number;
|
|
132
|
+
readonly position: number;
|
|
133
|
+
readonly rate: number;
|
|
134
|
+
readonly paused: boolean;
|
|
135
|
+
readonly holding: boolean;
|
|
136
|
+
readonly loop: Readonly<SyncLoopRegion> | null;
|
|
137
|
+
readonly pending: boolean;
|
|
138
|
+
readonly disposed: boolean;
|
|
139
|
+
}
|
|
140
|
+
interface TransportCommit {
|
|
141
|
+
readonly revision: number;
|
|
142
|
+
readonly command: TransportCommand;
|
|
143
|
+
/** A newer command or disposal supersedes this operation's authority. */
|
|
144
|
+
readonly status: 'committed' | 'superseded';
|
|
145
|
+
readonly snapshot: TransportSnapshot;
|
|
146
|
+
}
|
|
147
|
+
/** Invalidation precedes participant commands, settlement follows their
|
|
148
|
+
* asynchronous work. Engines retract/re-arm through their existing commands;
|
|
149
|
+
* this observer protocol does not inject a shared writable clock. */
|
|
150
|
+
type TransportEvent = {
|
|
151
|
+
readonly type: 'snapshot';
|
|
152
|
+
readonly snapshot: TransportSnapshot;
|
|
153
|
+
} | {
|
|
154
|
+
readonly type: 'reconcile';
|
|
155
|
+
readonly operation: string;
|
|
156
|
+
readonly phase: 'invalidate' | 'settled';
|
|
157
|
+
readonly snapshot: TransportSnapshot;
|
|
158
|
+
} | {
|
|
159
|
+
readonly type: 'operation-error';
|
|
160
|
+
readonly operation: string;
|
|
161
|
+
readonly error: unknown;
|
|
162
|
+
readonly snapshot: TransportSnapshot;
|
|
163
|
+
} | {
|
|
164
|
+
readonly type: 'invalidate';
|
|
165
|
+
readonly revision: number;
|
|
166
|
+
readonly command: TransportCommand;
|
|
167
|
+
readonly snapshot: TransportSnapshot;
|
|
168
|
+
} | {
|
|
169
|
+
readonly type: 'commit';
|
|
170
|
+
readonly commit: TransportCommit;
|
|
171
|
+
readonly snapshot: TransportSnapshot;
|
|
172
|
+
} | {
|
|
173
|
+
readonly type: 'error';
|
|
174
|
+
readonly revision: number;
|
|
175
|
+
readonly command: TransportCommand;
|
|
176
|
+
readonly error: unknown;
|
|
177
|
+
readonly snapshot: TransportSnapshot;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Drives one master transport and N schedulable followers as a single
|
|
181
|
+
* transport. Positions are on the MASTER's axis; each follower runs
|
|
182
|
+
* `offsetSeconds` ahead of the master's zero. The reference clock is
|
|
183
|
+
* injected (`now`), so the group itself is Web-Audio-free and testable
|
|
184
|
+
* against any monotonic time source.
|
|
185
|
+
*/
|
|
186
|
+
declare class TransportGroup {
|
|
187
|
+
#private;
|
|
188
|
+
constructor(master: SyncMasterTransport, now: () => number, options?: TransportGroupOptions);
|
|
189
|
+
/** The group timeline: a read-through to the master's own clock. */
|
|
190
|
+
get clock(): TransportClockReader;
|
|
191
|
+
/** Current position on the master axis. */
|
|
192
|
+
get position(): number;
|
|
193
|
+
/** Read one coherent state on the master's stable position axis. */
|
|
194
|
+
get snapshot(): TransportSnapshot;
|
|
195
|
+
/** Register before synchronously delivering the initial snapshot. Observer
|
|
196
|
+
* failures are contained. Unsubscribe never stops borrowed playback. */
|
|
197
|
+
subscribe(listener: (event: TransportEvent) => void): () => void;
|
|
198
|
+
/** Submit a command and await its actual participant settlement. Failures
|
|
199
|
+
* reject and emit an error; superseded work cannot claim a committed result.
|
|
200
|
+
* Pause/stop take effect synchronously and await any late-start reconciliation.
|
|
201
|
+
* Call this authority exclusively while coordinating a session. */
|
|
202
|
+
dispatch(command: TransportCommand): Promise<TransportCommit>;
|
|
203
|
+
/**
|
|
204
|
+
* Register a follower. While the group is playing, the follower joins the
|
|
205
|
+
* running timeline on the next scheduled join.
|
|
206
|
+
*/
|
|
207
|
+
addFollower(transport: SyncFollowerTransport, options?: FollowerOptions): void;
|
|
208
|
+
/**
|
|
209
|
+
* Remove a follower from the group (the transport itself is left as-is,
|
|
210
|
+
* still playing if it was; the caller owns its lifecycle from here).
|
|
211
|
+
* Returns false when the transport was not a member.
|
|
212
|
+
*/
|
|
213
|
+
removeFollower(transport: SyncFollowerTransport): boolean;
|
|
214
|
+
/** Number of registered followers. */
|
|
215
|
+
get followerCount(): number;
|
|
216
|
+
/**
|
|
217
|
+
* Set (or clear) a loop region on the master axis, live. The wrap runs
|
|
218
|
+
* through {@link seek}, so it inherits the shared re-entry origin; the
|
|
219
|
+
* boundary is detected by a worker-backed tick watcher, so the wrap
|
|
220
|
+
* instant may trail the boundary by the watcher/preparation delay and lead-in.
|
|
221
|
+
* Browser throttling means this is not a bounded timing guarantee.
|
|
222
|
+
*/
|
|
223
|
+
setLoop(loop: SyncLoopRegion | null): void;
|
|
224
|
+
get loop(): SyncLoopRegion | null;
|
|
225
|
+
/**
|
|
226
|
+
* Start master and followers on one shared origin. The group proposes
|
|
227
|
+
* `now + leadInSeconds` to the master; one that supports scheduled starts
|
|
228
|
+
* arms there and every follower joins at that very instant. A master that
|
|
229
|
+
* ignores the proposal starts immediately and followers join a lead-in
|
|
230
|
+
* later, offset-matched to its anchor.
|
|
231
|
+
*/
|
|
232
|
+
play(): Promise<void>;
|
|
233
|
+
pause(): void;
|
|
234
|
+
stop(): void;
|
|
235
|
+
/**
|
|
236
|
+
* Seek master and followers to a master-axis position. While playing, the
|
|
237
|
+
* group proposes a shared re-entry origin exactly as {@link play} does
|
|
238
|
+
* and re-joins the followers there, so all sides come back in together.
|
|
239
|
+
* Loop wraps run through this path and inherit the same shared origin.
|
|
240
|
+
*/
|
|
241
|
+
seek(position: number): Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* Set the playback rate on the master and every follower. Followers
|
|
244
|
+
* re-join immediately on the shared clock. NOTE: the group does not clamp
|
|
245
|
+
* the rate beyond finite-and-positive — a domain wrapper owns any shared
|
|
246
|
+
* range its transports require.
|
|
247
|
+
*/
|
|
248
|
+
setRate(rate: number): void;
|
|
249
|
+
dispose(): void;
|
|
250
|
+
/**
|
|
251
|
+
* One drift check: every follower is measured against the master clock,
|
|
252
|
+
* and each one out of tolerance is re-joined on the shared clock (the
|
|
253
|
+
* same scheduled-start dance as {@link play}). Returns the largest
|
|
254
|
+
* absolute drift observed (0 with no followers or while holding off).
|
|
255
|
+
*/
|
|
256
|
+
checkDrift(): number;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Minimal command surface a clockless transport must offer so
|
|
260
|
+
* {@link MirrorClockMaster} can adapt it into the master role.
|
|
261
|
+
*/
|
|
262
|
+
interface ClocklessMasterTransport {
|
|
263
|
+
play(when?: number): Promise<void> | void;
|
|
264
|
+
pause(): void;
|
|
265
|
+
stop(): void;
|
|
266
|
+
seekPosition(position: number, when?: number): void | Promise<void>;
|
|
267
|
+
setRate?(rate: number): void;
|
|
268
|
+
readonly position: number;
|
|
269
|
+
dispose?(): void;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Adapts a transport WITHOUT a readable clock into the required-clock
|
|
273
|
+
* master role by dead-reckoning a mirror TransportClock across the command
|
|
274
|
+
* surface, and reconciling the reckoning against the transport's actual
|
|
275
|
+
* position on every drift check:
|
|
276
|
+
*
|
|
277
|
+
* - two identical position samples while the mirror advanced past the
|
|
278
|
+
* tolerance mean the transport stopped on its own (ended, clamped at its
|
|
279
|
+
* duration, paused out of band) — the adapter pauses the mirror and
|
|
280
|
+
* reports 'stalled', which the group treats as a master stop;
|
|
281
|
+
* - a moving transport that diverged from the extrapolation (refused or
|
|
282
|
+
* clamped rate, tempo automation) re-anchors the mirror so drift is
|
|
283
|
+
* measured against the transport, not the reckoning.
|
|
284
|
+
*
|
|
285
|
+
* This is the ONE home of the sampled fallback the score↔audio bridge used
|
|
286
|
+
* to interleave through its clocked path.
|
|
287
|
+
*/
|
|
288
|
+
declare class MirrorClockMaster implements SyncMasterTransport {
|
|
289
|
+
#private;
|
|
290
|
+
constructor(inner: ClocklessMasterTransport, now: () => number, options?: {
|
|
291
|
+
reconcileToleranceSeconds?: number;
|
|
292
|
+
});
|
|
293
|
+
get clock(): TransportClockReader;
|
|
294
|
+
get position(): number;
|
|
295
|
+
play(when?: number): Promise<void>;
|
|
296
|
+
pause(): void;
|
|
297
|
+
stop(): void;
|
|
298
|
+
seekPosition(position: number, when?: number): Promise<void>;
|
|
299
|
+
setRate(rate: number): void;
|
|
300
|
+
reconcile(now: number): 'ok' | 'stalled';
|
|
301
|
+
dispose(): void;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export { type ClocklessMasterTransport, type FollowerOptions, MirrorClockMaster, type SyncFollowerTransport, type SyncLoopRegion, type SyncMasterTransport, type TransportCommand, type TransportCommit, type TransportEvent, TransportGroup, type TransportGroupOptions, type TransportSnapshot };
|
package/dist/sync.d.ts
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { TransportClockReader } from './transport.js';
|
|
2
|
+
import { TickSourceOptions } from './tick.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Master role: the transport whose clock is the group's timeline. Everything
|
|
6
|
+
* is on the master's own position axis (for a score player: nominal score
|
|
7
|
+
* seconds; for a clip player: clip seconds).
|
|
8
|
+
*/
|
|
9
|
+
interface SyncMasterTransport {
|
|
10
|
+
/**
|
|
11
|
+
* Start the transport. `when` (optional, absolute reference-clock seconds)
|
|
12
|
+
* proposes an ARMED start: a master supporting scheduled starts arms its
|
|
13
|
+
* clock there so followers can join at the very same instant. Masters
|
|
14
|
+
* without the capability ignore the argument and start immediately — the
|
|
15
|
+
* group detects which happened by observing `clock.holding`, never
|
|
16
|
+
* through a declared flag.
|
|
17
|
+
*/
|
|
18
|
+
play(when?: number): Promise<void> | void;
|
|
19
|
+
pause(): void;
|
|
20
|
+
stop(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Seek to a position on the master's axis. A returned promise settles
|
|
23
|
+
* once the seek has been applied and any mid-playback restart attempted;
|
|
24
|
+
* the group awaits it before re-anchoring followers. The promise MAY
|
|
25
|
+
* resolve with the transport left paused when the restart failed — the
|
|
26
|
+
* group treats that as a failed resume: it pauses the followers, settles
|
|
27
|
+
* into the paused state and reports 'resume after seek' through
|
|
28
|
+
* {@link TransportGroupOptions.onOperationError}. While playing, the
|
|
29
|
+
* group passes a proposed re-entry time the same way {@link play} does.
|
|
30
|
+
*/
|
|
31
|
+
seekPosition(position: number, when?: number): void | Promise<void>;
|
|
32
|
+
setRate?(rate: number): void;
|
|
33
|
+
/** Current position on the master's axis. */
|
|
34
|
+
readonly position: number;
|
|
35
|
+
/** Read-only transport clock (master position axis). REQUIRED — wrap a
|
|
36
|
+
* clockless transport in {@link MirrorClockMaster}. */
|
|
37
|
+
readonly clock: TransportClockReader;
|
|
38
|
+
/**
|
|
39
|
+
* Optional pre-drift-check reconciliation hook (adapters). Called once
|
|
40
|
+
* per drift check with the current reference time; returning 'stalled'
|
|
41
|
+
* tells the group the master stopped on its own (the adapter has already
|
|
42
|
+
* paused its clock) — the group then wraps or settles exactly as for an
|
|
43
|
+
* observed master stop.
|
|
44
|
+
*/
|
|
45
|
+
reconcile?(now: number): 'ok' | 'stalled';
|
|
46
|
+
dispose?(): void;
|
|
47
|
+
}
|
|
48
|
+
/** Follower role: a transport that can join the master's timeline. */
|
|
49
|
+
interface SyncFollowerTransport {
|
|
50
|
+
/**
|
|
51
|
+
* Start playback. `when` (optional, absolute reference-clock seconds) is
|
|
52
|
+
* the scheduled start the join dance relies on: the follower MUST honor
|
|
53
|
+
* it sample-accurately for gapless joins (a follower that starts
|
|
54
|
+
* immediately instead will sit one lead-in ahead and be re-corrected
|
|
55
|
+
* forever by the drift monitor).
|
|
56
|
+
*/
|
|
57
|
+
play(when?: number): Promise<void> | void;
|
|
58
|
+
pause(): void;
|
|
59
|
+
stop(): void;
|
|
60
|
+
seek(position: number): void;
|
|
61
|
+
setRate?(rate: number): void;
|
|
62
|
+
/** Current position on the follower's own axis. */
|
|
63
|
+
readonly position: number;
|
|
64
|
+
/** Whether the follower is running, when it can say (optional). */
|
|
65
|
+
readonly running?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Read-only clock on the follower's own axis, when the transport has one.
|
|
68
|
+
* When present, the drift monitor reads position and running state from
|
|
69
|
+
* it instead of sampling `position`/`running`.
|
|
70
|
+
*/
|
|
71
|
+
readonly clock?: TransportClockReader;
|
|
72
|
+
dispose?(): void;
|
|
73
|
+
}
|
|
74
|
+
/** Per-follower registration options. */
|
|
75
|
+
interface FollowerOptions {
|
|
76
|
+
/** Follower position corresponding to master position zero. Default 0. */
|
|
77
|
+
offsetSeconds?: number;
|
|
78
|
+
/** Positive affine scale: local position = offsetSeconds + master position × positionScale.
|
|
79
|
+
* The follower's playback rate is scaled by the same factor. Default 1.
|
|
80
|
+
* This is a constant map, not nonlinear warping. */
|
|
81
|
+
positionScale?: number;
|
|
82
|
+
/** Local loop bounds for a transport ALREADY configured to loop natively.
|
|
83
|
+
* The group maps join/seek positions and drift into this phase; it does not
|
|
84
|
+
* configure or schedule that native loop. Positions before the loop end
|
|
85
|
+
* retain their intro; at/past the end they wrap into [start, end). */
|
|
86
|
+
loop?: SyncLoopRegion;
|
|
87
|
+
}
|
|
88
|
+
interface TransportGroupOptions {
|
|
89
|
+
/** Scheduling headroom before followers join, in seconds. Default 0.06. */
|
|
90
|
+
leadInSeconds?: number;
|
|
91
|
+
/** Re-join a follower when |follower − expected| exceeds this. Default 0.03 s. */
|
|
92
|
+
driftToleranceSeconds?: number;
|
|
93
|
+
/** Drift check cadence. Default 250 ms. 0 disables the monitor. */
|
|
94
|
+
driftCheckIntervalMs?: number;
|
|
95
|
+
/** Loop region on the master axis; also settable live via {@link TransportGroup.setLoop}. */
|
|
96
|
+
loop?: SyncLoopRegion | null;
|
|
97
|
+
/** Injectable tick source options (tests; custom hosting). */
|
|
98
|
+
tick?: TickSourceOptions;
|
|
99
|
+
/**
|
|
100
|
+
* Observer for failures of the group's own fire-and-forget operations
|
|
101
|
+
* (drift and rate re-joins, loop wraps, pause/stop reconciliation). Those
|
|
102
|
+
* run behind the command queue with no caller promise to reject, and on
|
|
103
|
+
* failure they settle the group into a paused state — without an observer
|
|
104
|
+
* that settlement is silent. Observer exceptions are swallowed.
|
|
105
|
+
*/
|
|
106
|
+
onOperationError?: (operation: string, error: unknown) => void;
|
|
107
|
+
}
|
|
108
|
+
/** A loop region on the master position axis. */
|
|
109
|
+
interface SyncLoopRegion {
|
|
110
|
+
startSeconds: number;
|
|
111
|
+
endSeconds: number;
|
|
112
|
+
}
|
|
113
|
+
/** Commands accepted by the group's single authority. Positions use the master's
|
|
114
|
+
* stable content axis, never a duration divided by the current playback rate. */
|
|
115
|
+
type TransportCommand = {
|
|
116
|
+
readonly type: 'play' | 'pause' | 'stop';
|
|
117
|
+
} | {
|
|
118
|
+
readonly type: 'seek';
|
|
119
|
+
readonly position: number;
|
|
120
|
+
} | {
|
|
121
|
+
readonly type: 'rate';
|
|
122
|
+
readonly rate: number;
|
|
123
|
+
} | {
|
|
124
|
+
readonly type: 'loop';
|
|
125
|
+
readonly loop: SyncLoopRegion | null;
|
|
126
|
+
};
|
|
127
|
+
/** Coherent observation at one reference-clock instant. This is a snapshot,
|
|
128
|
+
* not a display timer; read again or use clock.positionAt for moving positions. */
|
|
129
|
+
interface TransportSnapshot {
|
|
130
|
+
readonly revision: number;
|
|
131
|
+
readonly referenceTime: number;
|
|
132
|
+
readonly position: number;
|
|
133
|
+
readonly rate: number;
|
|
134
|
+
readonly paused: boolean;
|
|
135
|
+
readonly holding: boolean;
|
|
136
|
+
readonly loop: Readonly<SyncLoopRegion> | null;
|
|
137
|
+
readonly pending: boolean;
|
|
138
|
+
readonly disposed: boolean;
|
|
139
|
+
}
|
|
140
|
+
interface TransportCommit {
|
|
141
|
+
readonly revision: number;
|
|
142
|
+
readonly command: TransportCommand;
|
|
143
|
+
/** A newer command or disposal supersedes this operation's authority. */
|
|
144
|
+
readonly status: 'committed' | 'superseded';
|
|
145
|
+
readonly snapshot: TransportSnapshot;
|
|
146
|
+
}
|
|
147
|
+
/** Invalidation precedes participant commands, settlement follows their
|
|
148
|
+
* asynchronous work. Engines retract/re-arm through their existing commands;
|
|
149
|
+
* this observer protocol does not inject a shared writable clock. */
|
|
150
|
+
type TransportEvent = {
|
|
151
|
+
readonly type: 'snapshot';
|
|
152
|
+
readonly snapshot: TransportSnapshot;
|
|
153
|
+
} | {
|
|
154
|
+
readonly type: 'reconcile';
|
|
155
|
+
readonly operation: string;
|
|
156
|
+
readonly phase: 'invalidate' | 'settled';
|
|
157
|
+
readonly snapshot: TransportSnapshot;
|
|
158
|
+
} | {
|
|
159
|
+
readonly type: 'operation-error';
|
|
160
|
+
readonly operation: string;
|
|
161
|
+
readonly error: unknown;
|
|
162
|
+
readonly snapshot: TransportSnapshot;
|
|
163
|
+
} | {
|
|
164
|
+
readonly type: 'invalidate';
|
|
165
|
+
readonly revision: number;
|
|
166
|
+
readonly command: TransportCommand;
|
|
167
|
+
readonly snapshot: TransportSnapshot;
|
|
168
|
+
} | {
|
|
169
|
+
readonly type: 'commit';
|
|
170
|
+
readonly commit: TransportCommit;
|
|
171
|
+
readonly snapshot: TransportSnapshot;
|
|
172
|
+
} | {
|
|
173
|
+
readonly type: 'error';
|
|
174
|
+
readonly revision: number;
|
|
175
|
+
readonly command: TransportCommand;
|
|
176
|
+
readonly error: unknown;
|
|
177
|
+
readonly snapshot: TransportSnapshot;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Drives one master transport and N schedulable followers as a single
|
|
181
|
+
* transport. Positions are on the MASTER's axis; each follower runs
|
|
182
|
+
* `offsetSeconds` ahead of the master's zero. The reference clock is
|
|
183
|
+
* injected (`now`), so the group itself is Web-Audio-free and testable
|
|
184
|
+
* against any monotonic time source.
|
|
185
|
+
*/
|
|
186
|
+
declare class TransportGroup {
|
|
187
|
+
#private;
|
|
188
|
+
constructor(master: SyncMasterTransport, now: () => number, options?: TransportGroupOptions);
|
|
189
|
+
/** The group timeline: a read-through to the master's own clock. */
|
|
190
|
+
get clock(): TransportClockReader;
|
|
191
|
+
/** Current position on the master axis. */
|
|
192
|
+
get position(): number;
|
|
193
|
+
/** Read one coherent state on the master's stable position axis. */
|
|
194
|
+
get snapshot(): TransportSnapshot;
|
|
195
|
+
/** Register before synchronously delivering the initial snapshot. Observer
|
|
196
|
+
* failures are contained. Unsubscribe never stops borrowed playback. */
|
|
197
|
+
subscribe(listener: (event: TransportEvent) => void): () => void;
|
|
198
|
+
/** Submit a command and await its actual participant settlement. Failures
|
|
199
|
+
* reject and emit an error; superseded work cannot claim a committed result.
|
|
200
|
+
* Pause/stop take effect synchronously and await any late-start reconciliation.
|
|
201
|
+
* Call this authority exclusively while coordinating a session. */
|
|
202
|
+
dispatch(command: TransportCommand): Promise<TransportCommit>;
|
|
203
|
+
/**
|
|
204
|
+
* Register a follower. While the group is playing, the follower joins the
|
|
205
|
+
* running timeline on the next scheduled join.
|
|
206
|
+
*/
|
|
207
|
+
addFollower(transport: SyncFollowerTransport, options?: FollowerOptions): void;
|
|
208
|
+
/**
|
|
209
|
+
* Remove a follower from the group (the transport itself is left as-is,
|
|
210
|
+
* still playing if it was; the caller owns its lifecycle from here).
|
|
211
|
+
* Returns false when the transport was not a member.
|
|
212
|
+
*/
|
|
213
|
+
removeFollower(transport: SyncFollowerTransport): boolean;
|
|
214
|
+
/** Number of registered followers. */
|
|
215
|
+
get followerCount(): number;
|
|
216
|
+
/**
|
|
217
|
+
* Set (or clear) a loop region on the master axis, live. The wrap runs
|
|
218
|
+
* through {@link seek}, so it inherits the shared re-entry origin; the
|
|
219
|
+
* boundary is detected by a worker-backed tick watcher, so the wrap
|
|
220
|
+
* instant may trail the boundary by the watcher/preparation delay and lead-in.
|
|
221
|
+
* Browser throttling means this is not a bounded timing guarantee.
|
|
222
|
+
*/
|
|
223
|
+
setLoop(loop: SyncLoopRegion | null): void;
|
|
224
|
+
get loop(): SyncLoopRegion | null;
|
|
225
|
+
/**
|
|
226
|
+
* Start master and followers on one shared origin. The group proposes
|
|
227
|
+
* `now + leadInSeconds` to the master; one that supports scheduled starts
|
|
228
|
+
* arms there and every follower joins at that very instant. A master that
|
|
229
|
+
* ignores the proposal starts immediately and followers join a lead-in
|
|
230
|
+
* later, offset-matched to its anchor.
|
|
231
|
+
*/
|
|
232
|
+
play(): Promise<void>;
|
|
233
|
+
pause(): void;
|
|
234
|
+
stop(): void;
|
|
235
|
+
/**
|
|
236
|
+
* Seek master and followers to a master-axis position. While playing, the
|
|
237
|
+
* group proposes a shared re-entry origin exactly as {@link play} does
|
|
238
|
+
* and re-joins the followers there, so all sides come back in together.
|
|
239
|
+
* Loop wraps run through this path and inherit the same shared origin.
|
|
240
|
+
*/
|
|
241
|
+
seek(position: number): Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* Set the playback rate on the master and every follower. Followers
|
|
244
|
+
* re-join immediately on the shared clock. NOTE: the group does not clamp
|
|
245
|
+
* the rate beyond finite-and-positive — a domain wrapper owns any shared
|
|
246
|
+
* range its transports require.
|
|
247
|
+
*/
|
|
248
|
+
setRate(rate: number): void;
|
|
249
|
+
dispose(): void;
|
|
250
|
+
/**
|
|
251
|
+
* One drift check: every follower is measured against the master clock,
|
|
252
|
+
* and each one out of tolerance is re-joined on the shared clock (the
|
|
253
|
+
* same scheduled-start dance as {@link play}). Returns the largest
|
|
254
|
+
* absolute drift observed (0 with no followers or while holding off).
|
|
255
|
+
*/
|
|
256
|
+
checkDrift(): number;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Minimal command surface a clockless transport must offer so
|
|
260
|
+
* {@link MirrorClockMaster} can adapt it into the master role.
|
|
261
|
+
*/
|
|
262
|
+
interface ClocklessMasterTransport {
|
|
263
|
+
play(when?: number): Promise<void> | void;
|
|
264
|
+
pause(): void;
|
|
265
|
+
stop(): void;
|
|
266
|
+
seekPosition(position: number, when?: number): void | Promise<void>;
|
|
267
|
+
setRate?(rate: number): void;
|
|
268
|
+
readonly position: number;
|
|
269
|
+
dispose?(): void;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Adapts a transport WITHOUT a readable clock into the required-clock
|
|
273
|
+
* master role by dead-reckoning a mirror TransportClock across the command
|
|
274
|
+
* surface, and reconciling the reckoning against the transport's actual
|
|
275
|
+
* position on every drift check:
|
|
276
|
+
*
|
|
277
|
+
* - two identical position samples while the mirror advanced past the
|
|
278
|
+
* tolerance mean the transport stopped on its own (ended, clamped at its
|
|
279
|
+
* duration, paused out of band) — the adapter pauses the mirror and
|
|
280
|
+
* reports 'stalled', which the group treats as a master stop;
|
|
281
|
+
* - a moving transport that diverged from the extrapolation (refused or
|
|
282
|
+
* clamped rate, tempo automation) re-anchors the mirror so drift is
|
|
283
|
+
* measured against the transport, not the reckoning.
|
|
284
|
+
*
|
|
285
|
+
* This is the ONE home of the sampled fallback the score↔audio bridge used
|
|
286
|
+
* to interleave through its clocked path.
|
|
287
|
+
*/
|
|
288
|
+
declare class MirrorClockMaster implements SyncMasterTransport {
|
|
289
|
+
#private;
|
|
290
|
+
constructor(inner: ClocklessMasterTransport, now: () => number, options?: {
|
|
291
|
+
reconcileToleranceSeconds?: number;
|
|
292
|
+
});
|
|
293
|
+
get clock(): TransportClockReader;
|
|
294
|
+
get position(): number;
|
|
295
|
+
play(when?: number): Promise<void>;
|
|
296
|
+
pause(): void;
|
|
297
|
+
stop(): void;
|
|
298
|
+
seekPosition(position: number, when?: number): Promise<void>;
|
|
299
|
+
setRate(rate: number): void;
|
|
300
|
+
reconcile(now: number): 'ok' | 'stalled';
|
|
301
|
+
dispose(): void;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export { type ClocklessMasterTransport, type FollowerOptions, MirrorClockMaster, type SyncFollowerTransport, type SyncLoopRegion, type SyncMasterTransport, type TransportCommand, type TransportCommit, type TransportEvent, TransportGroup, type TransportGroupOptions, type TransportSnapshot };
|
package/dist/sync.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MirrorClockMaster,
|
|
3
|
+
TransportGroup
|
|
4
|
+
} from "./chunk-XBJBY4J5.js";
|
|
5
|
+
import "./chunk-FJLY3RWZ.js";
|
|
6
|
+
import "./chunk-53YD73OY.js";
|
|
7
|
+
import "./chunk-PXG64RU4.js";
|
|
8
|
+
export {
|
|
9
|
+
MirrorClockMaster,
|
|
10
|
+
TransportGroup
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=sync.js.map
|
package/dist/sync.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/tick.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk3INDOVUCcjs = require('./chunk-3INDOVUC.cjs');
|
|
5
|
+
require('./chunk-7ZTZZ5PN.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.MAX_TIMER_DELAY_MS = _chunk3INDOVUCcjs.MAX_TIMER_DELAY_MS; exports.createTickSource = _chunk3INDOVUCcjs.createTickSource;
|
|
10
|
+
//# sourceMappingURL=tick.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/mamingchen/GitHub/public/WebMusic/platform/kernel/dist/tick.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACF,iIAAC","file":"/Users/mamingchen/GitHub/public/WebMusic/platform/kernel/dist/tick.cjs"}
|