@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/tick.d.cts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Minimal Worker surface the tick source needs (a real `Worker` satisfies it). */
|
|
2
|
+
interface TickWorkerLike {
|
|
3
|
+
postMessage(message: unknown): void;
|
|
4
|
+
terminate(): void;
|
|
5
|
+
addEventListener(type: 'message', listener: (event: {
|
|
6
|
+
data: unknown;
|
|
7
|
+
}) => void): void;
|
|
8
|
+
/**
|
|
9
|
+
* Worker failure notification. Constructing a `Worker` succeeds before its
|
|
10
|
+
* script is fetched, so a CSP/network failure surfaces only as this event —
|
|
11
|
+
* the tick source listens and falls back to a main-thread interval.
|
|
12
|
+
*/
|
|
13
|
+
addEventListener(type: 'error', listener: (event: unknown) => void): void;
|
|
14
|
+
}
|
|
15
|
+
interface TickSourceOptions {
|
|
16
|
+
/** Tick cadence in milliseconds. Default 25. */
|
|
17
|
+
intervalMs?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Injectable worker factory (tests; custom hosting). Return null to force
|
|
20
|
+
* the main-thread fallback. Default: an inline-Blob interval worker where
|
|
21
|
+
* supported, else null.
|
|
22
|
+
*/
|
|
23
|
+
createWorker?: () => TickWorkerLike | null;
|
|
24
|
+
}
|
|
25
|
+
interface TickSource {
|
|
26
|
+
/** Start delivering ticks. Replaces any previous callback. Idempotent. */
|
|
27
|
+
start(onTick: () => void): void;
|
|
28
|
+
/** Stop delivering ticks; the source can be started again. */
|
|
29
|
+
stop(): void;
|
|
30
|
+
readonly running: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* True when ticks come from a dedicated worker (throttle-resistant).
|
|
33
|
+
* Flips to false if the worker fails asynchronously and the source falls
|
|
34
|
+
* back to a main-thread interval.
|
|
35
|
+
*/
|
|
36
|
+
readonly workerBacked: boolean;
|
|
37
|
+
/** Stop and release the worker. The source cannot be restarted after. */
|
|
38
|
+
dispose(): void;
|
|
39
|
+
}
|
|
40
|
+
/** Largest delay accepted by browser/Node integer timer implementations. */
|
|
41
|
+
declare const MAX_TIMER_DELAY_MS = 2147483647;
|
|
42
|
+
/**
|
|
43
|
+
* Create a {@link TickSource}. Worker-backed where possible, main-thread
|
|
44
|
+
* `setInterval` otherwise — same surface either way.
|
|
45
|
+
*/
|
|
46
|
+
declare function createTickSource(options?: TickSourceOptions): TickSource;
|
|
47
|
+
|
|
48
|
+
export { MAX_TIMER_DELAY_MS, type TickSource, type TickSourceOptions, type TickWorkerLike, createTickSource };
|
package/dist/tick.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Minimal Worker surface the tick source needs (a real `Worker` satisfies it). */
|
|
2
|
+
interface TickWorkerLike {
|
|
3
|
+
postMessage(message: unknown): void;
|
|
4
|
+
terminate(): void;
|
|
5
|
+
addEventListener(type: 'message', listener: (event: {
|
|
6
|
+
data: unknown;
|
|
7
|
+
}) => void): void;
|
|
8
|
+
/**
|
|
9
|
+
* Worker failure notification. Constructing a `Worker` succeeds before its
|
|
10
|
+
* script is fetched, so a CSP/network failure surfaces only as this event —
|
|
11
|
+
* the tick source listens and falls back to a main-thread interval.
|
|
12
|
+
*/
|
|
13
|
+
addEventListener(type: 'error', listener: (event: unknown) => void): void;
|
|
14
|
+
}
|
|
15
|
+
interface TickSourceOptions {
|
|
16
|
+
/** Tick cadence in milliseconds. Default 25. */
|
|
17
|
+
intervalMs?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Injectable worker factory (tests; custom hosting). Return null to force
|
|
20
|
+
* the main-thread fallback. Default: an inline-Blob interval worker where
|
|
21
|
+
* supported, else null.
|
|
22
|
+
*/
|
|
23
|
+
createWorker?: () => TickWorkerLike | null;
|
|
24
|
+
}
|
|
25
|
+
interface TickSource {
|
|
26
|
+
/** Start delivering ticks. Replaces any previous callback. Idempotent. */
|
|
27
|
+
start(onTick: () => void): void;
|
|
28
|
+
/** Stop delivering ticks; the source can be started again. */
|
|
29
|
+
stop(): void;
|
|
30
|
+
readonly running: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* True when ticks come from a dedicated worker (throttle-resistant).
|
|
33
|
+
* Flips to false if the worker fails asynchronously and the source falls
|
|
34
|
+
* back to a main-thread interval.
|
|
35
|
+
*/
|
|
36
|
+
readonly workerBacked: boolean;
|
|
37
|
+
/** Stop and release the worker. The source cannot be restarted after. */
|
|
38
|
+
dispose(): void;
|
|
39
|
+
}
|
|
40
|
+
/** Largest delay accepted by browser/Node integer timer implementations. */
|
|
41
|
+
declare const MAX_TIMER_DELAY_MS = 2147483647;
|
|
42
|
+
/**
|
|
43
|
+
* Create a {@link TickSource}. Worker-backed where possible, main-thread
|
|
44
|
+
* `setInterval` otherwise — same surface either way.
|
|
45
|
+
*/
|
|
46
|
+
declare function createTickSource(options?: TickSourceOptions): TickSource;
|
|
47
|
+
|
|
48
|
+
export { MAX_TIMER_DELAY_MS, type TickSource, type TickSourceOptions, type TickWorkerLike, createTickSource };
|
package/dist/tick.js
ADDED
package/dist/tick.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkSM5YPDDIcjs = require('./chunk-SM5YPDDI.cjs');
|
|
4
|
+
require('./chunk-7ZTZZ5PN.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
exports.TransportClock = _chunkSM5YPDDIcjs.TransportClock;
|
|
8
|
+
//# sourceMappingURL=transport.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/mamingchen/GitHub/public/WebMusic/platform/kernel/dist/transport.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACF,0DAAC","file":"/Users/mamingchen/GitHub/public/WebMusic/platform/kernel/dist/transport.cjs"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** Immutable snapshot of a transport anchor. All numbers, unit-agnostic. */
|
|
2
|
+
interface TransportClockState {
|
|
3
|
+
/** Reference-clock timestamp of the anchor. */
|
|
4
|
+
readonly originTime: number;
|
|
5
|
+
/** Timeline position at `originTime`. */
|
|
6
|
+
readonly originPosition: number;
|
|
7
|
+
/** Finite and > 0; position advances `rate`× reference time. */
|
|
8
|
+
readonly rate: number;
|
|
9
|
+
readonly paused: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Affine mapping between an external monotonic reference clock (any number
|
|
13
|
+
* domain — `AudioContext.currentTime`, `performance.now()/1000`, a test
|
|
14
|
+
* counter) and a timeline position. Pure: never reads a real clock unless
|
|
15
|
+
* `now` is injected; every mutator takes the current reference time
|
|
16
|
+
* explicitly.
|
|
17
|
+
*
|
|
18
|
+
* position(t) = paused ? originPosition
|
|
19
|
+
* : originPosition + (t - originTime) * rate
|
|
20
|
+
*
|
|
21
|
+
* The semantics mirror the two engines this abstracts: re-anchor math is the
|
|
22
|
+
* score scheduler's retune (capture position, reset both anchors) and
|
|
23
|
+
* BufferEngine's setRate; pause folds elapsed time into `originPosition`.
|
|
24
|
+
* Loop/wrap is deliberately OUT of scope — consumers implement it as
|
|
25
|
+
* `seekTo(loopStart, t)`, which is exactly what the engines do today.
|
|
26
|
+
* Negative times and positions pass through unclamped; clamping to a
|
|
27
|
+
* duration is domain policy. Every anchor mutator rejects non-finite
|
|
28
|
+
* numbers: a NaN reference time or position would silently poison the
|
|
29
|
+
* anchor and every later `positionAt` read, with no error at the source.
|
|
30
|
+
*/
|
|
31
|
+
declare class TransportClock {
|
|
32
|
+
#private;
|
|
33
|
+
/** @param now Optional reference clock enabling the zero-arg `position` getter. */
|
|
34
|
+
constructor(now?: () => number);
|
|
35
|
+
get state(): TransportClockState;
|
|
36
|
+
get rate(): number;
|
|
37
|
+
get paused(): boolean;
|
|
38
|
+
/** Current position via the injected `now()` clock. Throws when none was injected. */
|
|
39
|
+
get position(): number;
|
|
40
|
+
/**
|
|
41
|
+
* True when a {@link startAt} start is armed. The flag is cleared by the
|
|
42
|
+
* next {@link start} or {@link pause} — NOT by the origin time passing —
|
|
43
|
+
* so callers combining it with {@link TransportClockState.originTime}
|
|
44
|
+
* should treat "holding and origin still in the future" as the pre-roll
|
|
45
|
+
* condition (positionAt handles this internally either way).
|
|
46
|
+
*/
|
|
47
|
+
get holding(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Position at reference time `t`. While paused this is constant. `t` before
|
|
50
|
+
* the anchor yields positions before it (possibly negative) — callers clamp
|
|
51
|
+
* to their own domain — EXCEPT after {@link startAt}, where the position
|
|
52
|
+
* holds at the armed origin position through the pre-roll (mirroring how a
|
|
53
|
+
* scheduled `source.start(when)` sounds nothing before `when`).
|
|
54
|
+
*/
|
|
55
|
+
positionAt(t: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* Inverse of {@link positionAt}. Throws RangeError while paused: no
|
|
58
|
+
* reference time maps to a position when the transport is frozen — guard
|
|
59
|
+
* with {@link paused} before calling. While a {@link startAt} start is
|
|
60
|
+
* armed, positions before the armed origin position also throw: the
|
|
61
|
+
* position holds through the pre-roll and never passes below the origin,
|
|
62
|
+
* so no reference time maps to them (extrapolating backwards would return
|
|
63
|
+
* a time whose {@link positionAt} is NOT the requested position).
|
|
64
|
+
*/
|
|
65
|
+
timeAt(position: number): number;
|
|
66
|
+
/**
|
|
67
|
+
* Anchor at `(t, position ?? current position)` and unpause. Re-anchoring
|
|
68
|
+
* while already playing is idempotent for the position at `t`.
|
|
69
|
+
*/
|
|
70
|
+
start(t: number, position?: number): void;
|
|
71
|
+
/**
|
|
72
|
+
* Arm a SCHEDULED start: anchor at a (typically future) reference time and
|
|
73
|
+
* unpause, with the position holding at `position` until `t` arrives —
|
|
74
|
+
* the clock-side mirror of a sample-accurate `play(when)`. Transitions
|
|
75
|
+
* during the pre-roll keep the armed origin: {@link setRate} changes the
|
|
76
|
+
* slope after `t` without collapsing the hold, {@link seekTo} re-arms the
|
|
77
|
+
* held position, and {@link pause} cancels the pending start.
|
|
78
|
+
*/
|
|
79
|
+
startAt(t: number, position: number): void;
|
|
80
|
+
/** Fold elapsed time into the anchor; `positionAt()` is constant afterwards. */
|
|
81
|
+
pause(t: number): void;
|
|
82
|
+
/**
|
|
83
|
+
* Re-anchor at a new position; preserves the paused/playing state. During
|
|
84
|
+
* an armed pre-roll the scheduled origin time is kept (the pending start
|
|
85
|
+
* stays pending at the new position).
|
|
86
|
+
*/
|
|
87
|
+
seekTo(position: number, t: number): void;
|
|
88
|
+
/**
|
|
89
|
+
* Re-anchor so the position is continuous across the rate change:
|
|
90
|
+
* `originPosition = positionAt(t); originTime = t; rate = r`.
|
|
91
|
+
* Throws RangeError unless `r` is finite and > 0.
|
|
92
|
+
*/
|
|
93
|
+
setRate(r: number, t: number): void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Read-only view of a {@link TransportClock} — what a transport OWNER exposes
|
|
97
|
+
* to consumers (the sync bridge, views) so they can anchor against the clock
|
|
98
|
+
* without being able to re-anchor it.
|
|
99
|
+
*/
|
|
100
|
+
type TransportClockReader = Pick<TransportClock, 'state' | 'rate' | 'paused' | 'holding' | 'positionAt' | 'timeAt'>;
|
|
101
|
+
/**
|
|
102
|
+
* Monotonic non-decreasing map between a musical position axis (quarters,
|
|
103
|
+
* beats — the consumer defines the unit) and media seconds. Implementations
|
|
104
|
+
* should be total over all reals (extrapolate past the ends); they MAY clamp
|
|
105
|
+
* negative inputs, and MAY quantize (the score family's TimeMap quantizes the
|
|
106
|
+
* inverse to 1/480 quarter), so round-trips are only approximate and only on
|
|
107
|
+
* `[0, duration]`.
|
|
108
|
+
*/
|
|
109
|
+
interface TimelineMapping {
|
|
110
|
+
positionToSeconds(position: number): number;
|
|
111
|
+
secondsToPosition(seconds: number): number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { type TimelineMapping, TransportClock, type TransportClockReader, type TransportClockState };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** Immutable snapshot of a transport anchor. All numbers, unit-agnostic. */
|
|
2
|
+
interface TransportClockState {
|
|
3
|
+
/** Reference-clock timestamp of the anchor. */
|
|
4
|
+
readonly originTime: number;
|
|
5
|
+
/** Timeline position at `originTime`. */
|
|
6
|
+
readonly originPosition: number;
|
|
7
|
+
/** Finite and > 0; position advances `rate`× reference time. */
|
|
8
|
+
readonly rate: number;
|
|
9
|
+
readonly paused: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Affine mapping between an external monotonic reference clock (any number
|
|
13
|
+
* domain — `AudioContext.currentTime`, `performance.now()/1000`, a test
|
|
14
|
+
* counter) and a timeline position. Pure: never reads a real clock unless
|
|
15
|
+
* `now` is injected; every mutator takes the current reference time
|
|
16
|
+
* explicitly.
|
|
17
|
+
*
|
|
18
|
+
* position(t) = paused ? originPosition
|
|
19
|
+
* : originPosition + (t - originTime) * rate
|
|
20
|
+
*
|
|
21
|
+
* The semantics mirror the two engines this abstracts: re-anchor math is the
|
|
22
|
+
* score scheduler's retune (capture position, reset both anchors) and
|
|
23
|
+
* BufferEngine's setRate; pause folds elapsed time into `originPosition`.
|
|
24
|
+
* Loop/wrap is deliberately OUT of scope — consumers implement it as
|
|
25
|
+
* `seekTo(loopStart, t)`, which is exactly what the engines do today.
|
|
26
|
+
* Negative times and positions pass through unclamped; clamping to a
|
|
27
|
+
* duration is domain policy. Every anchor mutator rejects non-finite
|
|
28
|
+
* numbers: a NaN reference time or position would silently poison the
|
|
29
|
+
* anchor and every later `positionAt` read, with no error at the source.
|
|
30
|
+
*/
|
|
31
|
+
declare class TransportClock {
|
|
32
|
+
#private;
|
|
33
|
+
/** @param now Optional reference clock enabling the zero-arg `position` getter. */
|
|
34
|
+
constructor(now?: () => number);
|
|
35
|
+
get state(): TransportClockState;
|
|
36
|
+
get rate(): number;
|
|
37
|
+
get paused(): boolean;
|
|
38
|
+
/** Current position via the injected `now()` clock. Throws when none was injected. */
|
|
39
|
+
get position(): number;
|
|
40
|
+
/**
|
|
41
|
+
* True when a {@link startAt} start is armed. The flag is cleared by the
|
|
42
|
+
* next {@link start} or {@link pause} — NOT by the origin time passing —
|
|
43
|
+
* so callers combining it with {@link TransportClockState.originTime}
|
|
44
|
+
* should treat "holding and origin still in the future" as the pre-roll
|
|
45
|
+
* condition (positionAt handles this internally either way).
|
|
46
|
+
*/
|
|
47
|
+
get holding(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Position at reference time `t`. While paused this is constant. `t` before
|
|
50
|
+
* the anchor yields positions before it (possibly negative) — callers clamp
|
|
51
|
+
* to their own domain — EXCEPT after {@link startAt}, where the position
|
|
52
|
+
* holds at the armed origin position through the pre-roll (mirroring how a
|
|
53
|
+
* scheduled `source.start(when)` sounds nothing before `when`).
|
|
54
|
+
*/
|
|
55
|
+
positionAt(t: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* Inverse of {@link positionAt}. Throws RangeError while paused: no
|
|
58
|
+
* reference time maps to a position when the transport is frozen — guard
|
|
59
|
+
* with {@link paused} before calling. While a {@link startAt} start is
|
|
60
|
+
* armed, positions before the armed origin position also throw: the
|
|
61
|
+
* position holds through the pre-roll and never passes below the origin,
|
|
62
|
+
* so no reference time maps to them (extrapolating backwards would return
|
|
63
|
+
* a time whose {@link positionAt} is NOT the requested position).
|
|
64
|
+
*/
|
|
65
|
+
timeAt(position: number): number;
|
|
66
|
+
/**
|
|
67
|
+
* Anchor at `(t, position ?? current position)` and unpause. Re-anchoring
|
|
68
|
+
* while already playing is idempotent for the position at `t`.
|
|
69
|
+
*/
|
|
70
|
+
start(t: number, position?: number): void;
|
|
71
|
+
/**
|
|
72
|
+
* Arm a SCHEDULED start: anchor at a (typically future) reference time and
|
|
73
|
+
* unpause, with the position holding at `position` until `t` arrives —
|
|
74
|
+
* the clock-side mirror of a sample-accurate `play(when)`. Transitions
|
|
75
|
+
* during the pre-roll keep the armed origin: {@link setRate} changes the
|
|
76
|
+
* slope after `t` without collapsing the hold, {@link seekTo} re-arms the
|
|
77
|
+
* held position, and {@link pause} cancels the pending start.
|
|
78
|
+
*/
|
|
79
|
+
startAt(t: number, position: number): void;
|
|
80
|
+
/** Fold elapsed time into the anchor; `positionAt()` is constant afterwards. */
|
|
81
|
+
pause(t: number): void;
|
|
82
|
+
/**
|
|
83
|
+
* Re-anchor at a new position; preserves the paused/playing state. During
|
|
84
|
+
* an armed pre-roll the scheduled origin time is kept (the pending start
|
|
85
|
+
* stays pending at the new position).
|
|
86
|
+
*/
|
|
87
|
+
seekTo(position: number, t: number): void;
|
|
88
|
+
/**
|
|
89
|
+
* Re-anchor so the position is continuous across the rate change:
|
|
90
|
+
* `originPosition = positionAt(t); originTime = t; rate = r`.
|
|
91
|
+
* Throws RangeError unless `r` is finite and > 0.
|
|
92
|
+
*/
|
|
93
|
+
setRate(r: number, t: number): void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Read-only view of a {@link TransportClock} — what a transport OWNER exposes
|
|
97
|
+
* to consumers (the sync bridge, views) so they can anchor against the clock
|
|
98
|
+
* without being able to re-anchor it.
|
|
99
|
+
*/
|
|
100
|
+
type TransportClockReader = Pick<TransportClock, 'state' | 'rate' | 'paused' | 'holding' | 'positionAt' | 'timeAt'>;
|
|
101
|
+
/**
|
|
102
|
+
* Monotonic non-decreasing map between a musical position axis (quarters,
|
|
103
|
+
* beats — the consumer defines the unit) and media seconds. Implementations
|
|
104
|
+
* should be total over all reals (extrapolate past the ends); they MAY clamp
|
|
105
|
+
* negative inputs, and MAY quantize (the score family's TimeMap quantizes the
|
|
106
|
+
* inverse to 1/480 quarter), so round-trips are only approximate and only on
|
|
107
|
+
* `[0, duration]`.
|
|
108
|
+
*/
|
|
109
|
+
interface TimelineMapping {
|
|
110
|
+
positionToSeconds(position: number): number;
|
|
111
|
+
secondsToPosition(seconds: number): number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { type TimelineMapping, TransportClock, type TransportClockReader, type TransportClockState };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/worker.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkC3YWUZW3cjs = require('./chunk-C3YWUZW3.cjs');
|
|
5
|
+
require('./chunk-7ZTZZ5PN.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.createRequestTracker = _chunkC3YWUZW3cjs.createRequestTracker; exports.dedicatedWorkerScope = _chunkC3YWUZW3cjs.dedicatedWorkerScope;
|
|
10
|
+
//# sourceMappingURL=worker.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/mamingchen/GitHub/public/WebMusic/platform/kernel/dist/worker.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACF,6IAAC","file":"/Users/mamingchen/GitHub/public/WebMusic/platform/kernel/dist/worker.cjs"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Minimal Worker surface the client needs (a real `Worker` satisfies it). */
|
|
2
|
+
interface WorkerLike {
|
|
3
|
+
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
4
|
+
terminate(): void;
|
|
5
|
+
addEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
|
|
6
|
+
addEventListener(type: 'error', listener: (event: ErrorEvent) => void): void;
|
|
7
|
+
}
|
|
8
|
+
/** Pending-request registry correlating worker responses by id. */
|
|
9
|
+
interface RequestTracker<T> {
|
|
10
|
+
/** Register a new request; returns its id and the promise to hand out. */
|
|
11
|
+
add(): {
|
|
12
|
+
id: number;
|
|
13
|
+
promise: Promise<T>;
|
|
14
|
+
};
|
|
15
|
+
/** Settle the request with the given id. Returns false for unknown ids. */
|
|
16
|
+
resolve(id: number, value: T): boolean;
|
|
17
|
+
/** Reject the request with the given id. Returns false for unknown ids. */
|
|
18
|
+
reject(id: number, error: unknown): boolean;
|
|
19
|
+
/** Reject every pending request (worker crashed / disposed). */
|
|
20
|
+
rejectAll(error: unknown): void;
|
|
21
|
+
/** Number of in-flight requests. */
|
|
22
|
+
readonly size: number;
|
|
23
|
+
}
|
|
24
|
+
/** Create a {@link RequestTracker}. Pure bookkeeping, no worker involved. */
|
|
25
|
+
declare function createRequestTracker<T>(): RequestTracker<T>;
|
|
26
|
+
/** The dedicated-worker global surface a runtime needs to register itself. */
|
|
27
|
+
interface DedicatedWorkerScope {
|
|
28
|
+
addEventListener(type: 'message', listener: (event: {
|
|
29
|
+
data: unknown;
|
|
30
|
+
}) => void): void;
|
|
31
|
+
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
32
|
+
onmessage?: ((event: {
|
|
33
|
+
data: unknown;
|
|
34
|
+
}) => void) | null;
|
|
35
|
+
}
|
|
36
|
+
interface WorkerScopeGlobals {
|
|
37
|
+
WorkerGlobalScope?: unknown;
|
|
38
|
+
DedicatedWorkerGlobalScope?: unknown;
|
|
39
|
+
self?: unknown;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The current global scope when it is a real dedicated worker, else
|
|
43
|
+
* `undefined`. Guard a worker runtime's registration on this.
|
|
44
|
+
*
|
|
45
|
+
* @param globals Injectable global object (tests); defaults to `globalThis`.
|
|
46
|
+
*/
|
|
47
|
+
declare function dedicatedWorkerScope(globals?: WorkerScopeGlobals): DedicatedWorkerScope | undefined;
|
|
48
|
+
|
|
49
|
+
export { type DedicatedWorkerScope, type RequestTracker, type WorkerLike, createRequestTracker, dedicatedWorkerScope };
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Minimal Worker surface the client needs (a real `Worker` satisfies it). */
|
|
2
|
+
interface WorkerLike {
|
|
3
|
+
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
4
|
+
terminate(): void;
|
|
5
|
+
addEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
|
|
6
|
+
addEventListener(type: 'error', listener: (event: ErrorEvent) => void): void;
|
|
7
|
+
}
|
|
8
|
+
/** Pending-request registry correlating worker responses by id. */
|
|
9
|
+
interface RequestTracker<T> {
|
|
10
|
+
/** Register a new request; returns its id and the promise to hand out. */
|
|
11
|
+
add(): {
|
|
12
|
+
id: number;
|
|
13
|
+
promise: Promise<T>;
|
|
14
|
+
};
|
|
15
|
+
/** Settle the request with the given id. Returns false for unknown ids. */
|
|
16
|
+
resolve(id: number, value: T): boolean;
|
|
17
|
+
/** Reject the request with the given id. Returns false for unknown ids. */
|
|
18
|
+
reject(id: number, error: unknown): boolean;
|
|
19
|
+
/** Reject every pending request (worker crashed / disposed). */
|
|
20
|
+
rejectAll(error: unknown): void;
|
|
21
|
+
/** Number of in-flight requests. */
|
|
22
|
+
readonly size: number;
|
|
23
|
+
}
|
|
24
|
+
/** Create a {@link RequestTracker}. Pure bookkeeping, no worker involved. */
|
|
25
|
+
declare function createRequestTracker<T>(): RequestTracker<T>;
|
|
26
|
+
/** The dedicated-worker global surface a runtime needs to register itself. */
|
|
27
|
+
interface DedicatedWorkerScope {
|
|
28
|
+
addEventListener(type: 'message', listener: (event: {
|
|
29
|
+
data: unknown;
|
|
30
|
+
}) => void): void;
|
|
31
|
+
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
32
|
+
onmessage?: ((event: {
|
|
33
|
+
data: unknown;
|
|
34
|
+
}) => void) | null;
|
|
35
|
+
}
|
|
36
|
+
interface WorkerScopeGlobals {
|
|
37
|
+
WorkerGlobalScope?: unknown;
|
|
38
|
+
DedicatedWorkerGlobalScope?: unknown;
|
|
39
|
+
self?: unknown;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The current global scope when it is a real dedicated worker, else
|
|
43
|
+
* `undefined`. Guard a worker runtime's registration on this.
|
|
44
|
+
*
|
|
45
|
+
* @param globals Injectable global object (tests); defaults to `globalThis`.
|
|
46
|
+
*/
|
|
47
|
+
declare function dedicatedWorkerScope(globals?: WorkerScopeGlobals): DedicatedWorkerScope | undefined;
|
|
48
|
+
|
|
49
|
+
export { type DedicatedWorkerScope, type RequestTracker, type WorkerLike, createRequestTracker, dedicatedWorkerScope };
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webmusic/kernel",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Domain-neutral WebMusic contracts and utilities for events, elements, workers, metering and synchronized playback.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"default": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"./events": {
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/events.d.ts",
|
|
24
|
+
"default": "./dist/events.js"
|
|
25
|
+
},
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./dist/events.d.cts",
|
|
28
|
+
"default": "./dist/events.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"./element": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/elements.d.ts",
|
|
34
|
+
"default": "./dist/elements.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/elements.d.cts",
|
|
38
|
+
"default": "./dist/elements.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./worker": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/worker.d.ts",
|
|
44
|
+
"default": "./dist/worker.js"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./dist/worker.d.cts",
|
|
48
|
+
"default": "./dist/worker.cjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"./audio-context": {
|
|
52
|
+
"import": {
|
|
53
|
+
"types": "./dist/audio-context.d.ts",
|
|
54
|
+
"default": "./dist/audio-context.js"
|
|
55
|
+
},
|
|
56
|
+
"require": {
|
|
57
|
+
"types": "./dist/audio-context.d.cts",
|
|
58
|
+
"default": "./dist/audio-context.cjs"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"./player": {
|
|
62
|
+
"import": {
|
|
63
|
+
"types": "./dist/player.d.ts",
|
|
64
|
+
"default": "./dist/player.js"
|
|
65
|
+
},
|
|
66
|
+
"require": {
|
|
67
|
+
"types": "./dist/player.d.cts",
|
|
68
|
+
"default": "./dist/player.cjs"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"./effect": {
|
|
72
|
+
"import": {
|
|
73
|
+
"types": "./dist/effect.d.ts",
|
|
74
|
+
"default": "./dist/effect.js"
|
|
75
|
+
},
|
|
76
|
+
"require": {
|
|
77
|
+
"types": "./dist/effect.d.cts",
|
|
78
|
+
"default": "./dist/effect.cjs"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"./meter": {
|
|
82
|
+
"import": {
|
|
83
|
+
"types": "./dist/meter.d.ts",
|
|
84
|
+
"default": "./dist/meter.js"
|
|
85
|
+
},
|
|
86
|
+
"require": {
|
|
87
|
+
"types": "./dist/meter.d.cts",
|
|
88
|
+
"default": "./dist/meter.cjs"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"./transport": {
|
|
92
|
+
"import": {
|
|
93
|
+
"types": "./dist/transport.d.ts",
|
|
94
|
+
"default": "./dist/transport.js"
|
|
95
|
+
},
|
|
96
|
+
"require": {
|
|
97
|
+
"types": "./dist/transport.d.cts",
|
|
98
|
+
"default": "./dist/transport.cjs"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"./tick": {
|
|
102
|
+
"import": {
|
|
103
|
+
"types": "./dist/tick.d.ts",
|
|
104
|
+
"default": "./dist/tick.js"
|
|
105
|
+
},
|
|
106
|
+
"require": {
|
|
107
|
+
"types": "./dist/tick.d.cts",
|
|
108
|
+
"default": "./dist/tick.cjs"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"./sync": {
|
|
112
|
+
"import": {
|
|
113
|
+
"types": "./dist/sync.d.ts",
|
|
114
|
+
"default": "./dist/sync.js"
|
|
115
|
+
},
|
|
116
|
+
"require": {
|
|
117
|
+
"types": "./dist/sync.d.cts",
|
|
118
|
+
"default": "./dist/sync.cjs"
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"./package.json": "./package.json"
|
|
122
|
+
},
|
|
123
|
+
"scripts": {
|
|
124
|
+
"build": "tsup src/index.ts src/events.ts src/elements.ts src/worker.ts src/audio-context.ts src/player.ts src/effect.ts src/meter.ts src/transport.ts src/tick.ts src/sync.ts --tsconfig tsconfig.build.json --format esm,cjs --splitting --dts --sourcemap --clean && node ../../scripts/package-artifacts.mjs --write",
|
|
125
|
+
"test": "vitest run",
|
|
126
|
+
"typecheck": "tsc --noEmit",
|
|
127
|
+
"prepack": "node ../../scripts/package-artifacts.mjs"
|
|
128
|
+
},
|
|
129
|
+
"devDependencies": {
|
|
130
|
+
"tsup": "^8.5.0",
|
|
131
|
+
"typescript": "^5.4.0",
|
|
132
|
+
"vitest": "^4.1.11"
|
|
133
|
+
},
|
|
134
|
+
"license": "MIT",
|
|
135
|
+
"publishConfig": {
|
|
136
|
+
"access": "public"
|
|
137
|
+
},
|
|
138
|
+
"author": "mrsteamedbun",
|
|
139
|
+
"engines": {
|
|
140
|
+
"node": ">=22"
|
|
141
|
+
},
|
|
142
|
+
"files": [
|
|
143
|
+
"dist",
|
|
144
|
+
"README.md",
|
|
145
|
+
"LICENSE"
|
|
146
|
+
],
|
|
147
|
+
"repository": {
|
|
148
|
+
"type": "git",
|
|
149
|
+
"url": "git+https://github.com/koperative-lab/WebMusic.git",
|
|
150
|
+
"directory": "platform/kernel"
|
|
151
|
+
},
|
|
152
|
+
"homepage": "https://github.com/koperative-lab/WebMusic/tree/main/platform/kernel#readme",
|
|
153
|
+
"bugs": {
|
|
154
|
+
"url": "https://github.com/koperative-lab/WebMusic/issues"
|
|
155
|
+
},
|
|
156
|
+
"keywords": [
|
|
157
|
+
"music",
|
|
158
|
+
"web-audio",
|
|
159
|
+
"transport",
|
|
160
|
+
"typescript",
|
|
161
|
+
"webmusic",
|
|
162
|
+
"kernel"
|
|
163
|
+
]
|
|
164
|
+
}
|