@dawcore/transport 0.0.13 → 0.0.15
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/README.md +24 -8
- package/dist/index.d.mts +504 -43
- package/dist/index.d.ts +504 -43
- package/dist/index.js +1048 -238
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1044 -237
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# @dawcore/transport
|
|
2
2
|
|
|
3
|
-
Native Web Audio transport for multi-track
|
|
3
|
+
Native Web Audio transport for the dawcore family — multi-track scheduling, looping, tempo automation, time signatures, and metronome. No Tone.js, zero npm dependencies.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- **Native Web Audio** — No Tone.js, no `standardized-audio-context`. Direct `AudioContext` with full `sampleRate` and `latencyHint` control.
|
|
8
|
-
- **Sliding window scheduler** — Schedules audio 200ms ahead
|
|
8
|
+
- **Sliding window scheduler** — Schedules audio 200ms ahead, driven by a Web Worker timer so playback keeps running in a hidden tab (rAF stops there; main-thread timers throttle).
|
|
9
9
|
- **Dual timeline** — Sample-absolute positions for audio clips, PPQN tick positions for metronome/MIDI.
|
|
10
10
|
- **Built-in metronome** — Beat-grid click scheduling with accent on beat 1. Default synthesized click sounds out of the box.
|
|
11
11
|
- **Count-in (pre-roll)** — Configurable bars of click sounds before playback begins. Beat-by-beat events for UI countdown.
|
|
@@ -172,6 +172,8 @@ transport.connectMasterOutput(compressor);
|
|
|
172
172
|
transport.disconnectMasterOutput();
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
+
**Note:** `ClipTrack.effects` (the Tone.js-oriented per-track effects function used by `@waveform-playlist/playout`) is not read by `NativePlayoutAdapter` — it's silently ignored. Use `connectTrackOutput`/`connectMasterOutput` for effects with the native transport, or use `TonePlayoutAdapter` if a track still relies on `ClipTrack.effects`.
|
|
176
|
+
|
|
175
177
|
## API
|
|
176
178
|
|
|
177
179
|
### Transport
|
|
@@ -198,6 +200,9 @@ new Transport(audioContext: AudioContext, options?: TransportOptions)
|
|
|
198
200
|
- `stop()` — Stop and reset to beginning
|
|
199
201
|
- `seek(time)` — Jump to a position (works during playback)
|
|
200
202
|
- `getCurrentTime()` — Current transport position in seconds
|
|
203
|
+
- `getCurrentFrame(): ContextFrame` — the same position in whole AudioContext frames (elapsed time is counted in whole frames; context readings are snapped to the 128-frame render lattice). `ContextFrame` is branded separately from `Sample` because the SampleTimeline may run at a different `sampleRate` than the context
|
|
204
|
+
- `getCurrentSample(): Sample` — the same position in SampleTimeline samples (the `sampleRate` option's rate), rounded once
|
|
205
|
+
- `rebaseCount` (getter) — how many backward AudioContext clock readings were absorbed (see the `discontinuity` event)
|
|
201
206
|
- `isPlaying()` — Whether transport is playing
|
|
202
207
|
|
|
203
208
|
**Tracks:**
|
|
@@ -214,18 +219,21 @@ new Transport(audioContext: AudioContext, options?: TransportOptions)
|
|
|
214
219
|
- `setMasterVolume(volume)`
|
|
215
220
|
|
|
216
221
|
**Loop:**
|
|
217
|
-
- `setLoop(enabled, startTick: Tick, endTick: Tick)` — Set loop region in ticks (primary API)
|
|
218
|
-
- `setLoopSeconds(enabled, start, end)` — Set loop region in seconds (convenience)
|
|
219
|
-
- `setLoopSamples(enabled, startSample: Sample, endSample: Sample)` — Set loop region in samples (convenience)
|
|
222
|
+
- `setLoop(enabled, startTick: Tick, endTick: Tick)` — Set loop region in ticks (primary API). Throws when `enabled` and the range is non-finite, empty or inverted; the previous loop stays in force.
|
|
223
|
+
- `setLoopSeconds(enabled, start, end)` — Set loop region in seconds (convenience, same validation)
|
|
224
|
+
- `setLoopSamples(enabled, startSample: Sample, endSample: Sample)` — Set loop region in samples (convenience, same validation)
|
|
220
225
|
|
|
221
226
|
**Tempo & Meter:**
|
|
222
227
|
- `setTempo(bpm, atTick?, options?)` / `getTempo(atTick?: Tick)` — options: `{ interpolation: 'step' | 'linear' | { type: 'curve', slope } }`. Returns `boolean`: a defaulted `atTick` is the single-BPM convenience path and is refused (with a warning) when the tempo map has more than one entry — pass an explicit `atTick` to modify a tempo curve.
|
|
223
228
|
- `removeTempo(atTick: Tick)` — remove the tempo entry at a tick (the tick-0 entry cannot be removed)
|
|
224
229
|
- `clearTempos()` — remove all tempo entries
|
|
230
|
+
- `tempoMap` (getter) — the current `TempoMap`. It is an immutable value: every edit that changes the map swaps in a new one, so a reference you hold keeps converting with the tempo it had. `TempoMap` itself exposes `withTempo(bpm, atTick?, options?)`, `withoutTempo(atTick)`, `withoutTempos()` (each returns a new map) and `entries` (frozen, tick-ordered, with cumulative `secondsAtTick`).
|
|
225
231
|
- `setMeter(numerator, denominator, atTick?: Tick)` / `getMeter(atTick?: Tick)`
|
|
226
232
|
- `removeMeter(atTick: Tick)` / `clearMeters()`
|
|
227
233
|
- `barToTick(bar): Tick` / `tickToBar(tick: Tick)`
|
|
228
|
-
- `timeToTick(seconds): Tick` / `tickToTime(tick:
|
|
234
|
+
- `timeToTick(seconds): Tick` / `tickToTime(tick: number)` — `timeToTick` is the integer tick (`TempoMap.secondsToTicks` rounds the exact value once); `tickToTime` accepts an integer or fractional tick position
|
|
235
|
+
- `timeToTickExact(seconds): number` — fractional tick position, for sub-tick placement (e.g. a recorded note between ticks before quantising); `tickToTime` accepts it back. The same pairing exists one layer down: `TempoMap.secondsToTicks` / `secondsToTicksExact`, `SampleTimeline.samplesToTicks` / `samplesToTicksExact` (rounding happens once, in the integer variant), and `TempoMap.secondsToBeats` is continuous.
|
|
236
|
+
- `quantizeTick(tick, subdivision, { mode?, strength? }): Tick` — snap a (possibly fractional) tick to the meter grid. `subdivision`: `{ ticks: n }`, `{ note: 8, dotted?, triplet? }` (PPQN-independent), `'bar'` or `'beat'`; `mode`: `'nearest'` (default, ties go up) | `'next'` (ceiling) | `'previous'` (floor) — all idempotent, a tick already on a line stays (unlike Tone's strict `nextSubdivision`; pass `tick + 1` with `'next'` for the following line); `strength` 0–1. A fractional tick within 1e-6 of a line counts as on it. Grid lines restart at each bar line, so odd meters stay aligned. Also exported standalone as `quantizeTick(meterMap, …)`.
|
|
229
237
|
|
|
230
238
|
**Metronome:**
|
|
231
239
|
- `setMetronomeEnabled(enabled)`
|
|
@@ -247,11 +255,15 @@ new Transport(audioContext: AudioContext, options?: TransportOptions)
|
|
|
247
255
|
|
|
248
256
|
**Events:**
|
|
249
257
|
- `on(event, callback)` / `off(event, callback)`
|
|
250
|
-
- Events: `play`, `pause`, `stop`, `seek`, `loop`, `tempochange`, `meterchange`, `countIn`, `countInEnd`
|
|
258
|
+
- Events: `play`, `pause`, `stop`, `ended`, `seek`, `loop`, `tick`, `tempochange`, `meterchange`, `countIn`, `countInEnd`, `discontinuity`, `error`
|
|
259
|
+
- `tick` — `{ seconds }`: one scheduler tick advanced the timeline (every `timerIntervalMs`, default 25 ms, while playing; driven by the Worker timer so it keeps its cadence in a hidden tab). For consumers that must poll the playhead for state the transport does not announce (e.g. a tempo-map boundary crossed mid-playback); UI position updates should still use `requestAnimationFrame`
|
|
260
|
+
- `ended` — a bounded `play(start, end)` reached `end` and the transport stopped itself; fires right after `stop` (so a handler may restart playback), never for a consumer `stop()`/`pause()`/`seek()`
|
|
261
|
+
- `discontinuity` — `{ seconds, shiftSeconds }`: the AudioContext clock went backwards while playing (defensive; the spec makes it monotonic). The position was held (`seconds` is what `getCurrentTime()` reports) and, outside a count-in, scheduled audio re-created from it; during a count-in the already-armed clicks are dropped. Diagnostics only — with no subscriber the first occurrence is warned to the console
|
|
251
262
|
- `seek` payload: `{ seconds: number }`
|
|
252
263
|
- `tempochange` payload: `{ bpm: number, atTick: Tick }`
|
|
253
264
|
- `meterchange` payload: `{ numerator: number, denominator: number, atTick: Tick }`
|
|
254
265
|
- `countIn` payload: `{ beat: number, totalBeats: number }`
|
|
266
|
+
- `error` payload: `SchedulerListenerError`, discriminated on `phase` — `{ phase: 'generate', fromTick, toTick }`, `{ phase: 'consume', event }` or `{ phase: 'positionJump', tick }`, each with `listener` and `error`. A scheduler listener (clip player, metronome, count-in, or your own) threw; the scheduler skipped it and kept going. Delivered on a microtask after the scheduler window completes. With no `error` subscriber at delivery time the failure goes to `console.warn` instead (once per listener and failure kind).
|
|
255
267
|
|
|
256
268
|
**Cleanup:**
|
|
257
269
|
- `dispose()` — Stop playback, disconnect all nodes, remove listeners
|
|
@@ -268,7 +280,11 @@ Implements `PlayoutAdapter` from `@waveform-playlist/engine`. All methods delega
|
|
|
268
280
|
- `adapter.ppqn` — Tick resolution, read by the engine on construction
|
|
269
281
|
- `adapter.masterOutputNode` — Master gain node for parallel taps (analyzers, recorders)
|
|
270
282
|
- `adapter.init()` — Resumes a suspended AudioContext and waits for the hardware pipeline to warm up (Safari needs this before clips scheduled at time 0 play on time)
|
|
271
|
-
- `setTempo(bpm, atTick?)`, `setMeter(numerator, denominator, atTick?)`, `ticksToSeconds(tick)`, `secondsToTicks(seconds)` — tempo/meter surface the engine uses for tick-based timeline math
|
|
283
|
+
- `setTempo(bpm, atTick?)`, `setMeter(numerator, denominator, atTick?)`, `ticksToSeconds(tick)`, `secondsToTicks(seconds)`, `secondsToTicksExact(seconds)` — tempo/meter surface the engine uses for tick-based timeline math
|
|
284
|
+
|
|
285
|
+
### Advanced (Low-Level Building Blocks)
|
|
286
|
+
|
|
287
|
+
For consumers assembling a custom scheduler or embedding transport internals elsewhere, the layers underneath `Transport` are also exported: `Clock`, `Scheduler`, `Timer`, `SampleTimeline`, `TempoMap`, `MeterMap`, `MasterNode`, `TrackNode`, `ClipPlayer`, `MetronomePlayer`. See [`src/index.ts`](https://github.com/naomiaro/waveform-playlist/blob/main/packages/transport/src/index.ts) for the full export list — most consumers only need `Transport` and `NativePlayoutAdapter`.
|
|
272
288
|
|
|
273
289
|
## Examples
|
|
274
290
|
|