@webmusic/bridge 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,11 +1,7 @@
1
- var __typeError = (msg) => {
2
- throw TypeError(msg);
3
- };
4
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
1
+ import {
2
+ createWebMusicProjectPlugins,
3
+ registerAudioParticipant
4
+ } from "./chunk-XQXQSBVS.js";
9
5
 
10
6
  // src/mapping.ts
11
7
  import { Rational, TimeMap } from "@webmusic/score";
@@ -59,352 +55,10 @@ function timeMapFromBeatGrid(grid) {
59
55
  ]);
60
56
  }
61
57
 
62
- // src/sync.ts
63
- import {
64
- MirrorClockMaster,
65
- TransportGroup
66
- } from "@webmusic/kernel/sync";
67
- import { createWebAudioContext } from "@webmusic/kernel/audio-context";
58
+ // src/render.ts
68
59
  import { createAudioClip } from "@webmusic/audio";
69
- import { AudioClipPlayer } from "@webmusic/audio/play/headless";
70
- import { ScorePlayer } from "@webmusic/score/play/headless";
71
60
  import { renderScoreToBuffer } from "@webmusic/score/play";
72
-
73
- // src/owned-context.ts
74
- var ownedContexts = /* @__PURE__ */ new WeakMap();
75
- function ownContext(owner, context, onOperationError) {
76
- ownedContexts.set(owner, { context, onOperationError });
77
- }
78
- function releaseOwnedContext(owner) {
79
- const owned = ownedContexts.get(owner);
80
- if (!owned) return;
81
- ownedContexts.delete(owner);
82
- closeContext(owned.context, owned.onOperationError);
83
- }
84
- function closeContext(context, onOperationError) {
85
- const report = (error) => {
86
- try {
87
- onOperationError?.("context.close", error);
88
- } catch {
89
- }
90
- };
91
- try {
92
- void context.close().catch(report);
93
- } catch (error) {
94
- report(error);
95
- }
96
- }
97
-
98
- // src/factory-clip-options.ts
99
- function validatedClipOffsetSeconds(value) {
100
- const offset = value ?? 0;
101
- if (!Number.isFinite(offset) || offset < 0) {
102
- throw new RangeError("clipOffsetSeconds must be finite and >= 0.");
103
- }
104
- return offset;
105
- }
106
- function assertFactoryClipOptions(factory, clip, options) {
107
- const input = options;
108
- if (input?.loop !== void 0) {
109
- throw new RangeError(
110
- `${factory} does not accept clipOptions.loop: native clip looping does not expose the wrapped group axis. Use ScoreAudioSync.setLoop to loop both transports together.`
111
- );
112
- }
113
- if (input?.rate !== void 0) {
114
- throw new RangeError(
115
- `${factory} does not accept clipOptions.rate: the shared rate is owned by the transport group. Use ScoreAudioSync.setRate to change it on both transports.`
116
- );
117
- }
118
- if (input?.engine !== void 0 && input.engine !== "buffer") {
119
- throw new RangeError(
120
- `${factory} always uses the buffer engine (only it supplies the required scheduled clock); got engine '${String(input.engine)}'. Construct the players and ScoreAudioSync directly to use another clip transport.`
121
- );
122
- }
123
- if (input?.mediaAdapterFactory !== void 0) {
124
- throw new RangeError(
125
- `${factory} always uses the buffer engine; mediaAdapterFactory does not apply.`
126
- );
127
- }
128
- if (!clip.hasSamples) {
129
- throw new RangeError(
130
- `${factory} requires a clip with decoded samples: the buffer engine cannot play a streaming (URL-only) clip. Decode the audio when loading it, or render a matched backing track with renderScoreToClip.`
131
- );
132
- }
133
- }
134
-
135
- // src/render-provenance.ts
136
- var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@webmusic/bridge/render-provenance-v1");
137
- function renderProvenance(create) {
138
- let registry = Reflect.get(globalThis, REGISTRY_KEY);
139
- if (registry === void 0 && create) {
140
- registry = /* @__PURE__ */ new WeakMap();
141
- Object.defineProperty(globalThis, REGISTRY_KEY, {
142
- value: registry,
143
- enumerable: false,
144
- writable: false,
145
- configurable: false
146
- });
147
- }
148
- return registry;
149
- }
150
- function recordRenderProvenance(clip, score, tempoScale, hasTail) {
151
- renderProvenance(true).set(clip, { score, tempoScale, hasTail });
152
- }
153
- function assertRenderedClipAlignment(factory, score, clip, expandRepeats = false) {
154
- const provenance = renderProvenance(false)?.get(clip);
155
- if (!provenance) return;
156
- if (provenance.score !== score) {
157
- throw new RangeError(
158
- `${factory} cannot pair a Bridge-rendered clip with a different Score instance. Render this score again with renderScoreToClip(), or use an ordinary clip if your application owns the alignment.`
159
- );
160
- }
161
- if (expandRepeats) {
162
- throw new RangeError(
163
- `${factory} cannot expand repeats only in ScorePlayer for a Bridge-rendered clip: the score and clip would follow different timelines. Call expandRepeats(score) first, then renderScoreToClip(expandedScore) and pair that same expanded Score instance without scoreOptions.expandRepeats.`
164
- );
165
- }
166
- if (provenance.tempoScale !== 1) {
167
- throw new RangeError(
168
- `${factory} cannot pair a clip rendered with a tempo override: its audio seconds do not match the score-seconds axis. Render at the score tempo, then change both players with sync.setRate().`
169
- );
170
- }
171
- if (factory === "createSyncedPlayback" && provenance.hasTail) {
172
- throw new RangeError(
173
- "createSyncedPlayback cannot play the tail of a clip rendered from the same score: the score master stops at its natural end. Use createAudioMasteredPlayback(score, clip) to play the complete render, or render with tailSeconds: 0."
174
- );
175
- }
176
- }
177
-
178
- // src/sync.ts
179
- var MIN_SHARED_PLAYBACK_RATE = 0.25;
180
- var MAX_SHARED_PLAYBACK_RATE = 4;
181
- var _group, _score, _disposed, _ScoreAudioSync_instances, assertActive_fn;
182
- var ScoreAudioSync = class {
183
- constructor(score, clip, context, options = {}) {
184
- __privateAdd(this, _ScoreAudioSync_instances);
185
- __privateAdd(this, _group);
186
- __privateAdd(this, _score);
187
- __privateAdd(this, _disposed, false);
188
- __privateSet(this, _score, score);
189
- const clipOffset = validatedClipOffsetSeconds(options.clipOffsetSeconds);
190
- const now = () => context.currentTime;
191
- const commands = {
192
- play: (when) => score.play(when),
193
- pause: () => score.pause(),
194
- stop: () => score.stop(),
195
- seekPosition: (position, when) => score.seekNominal(position, when),
196
- setRate: (rate) => score.setRate?.(rate),
197
- get position() {
198
- return score.nominalSeconds;
199
- },
200
- dispose: () => score.dispose?.()
201
- };
202
- const mirror = new MirrorClockMaster(commands, now, {
203
- reconcileToleranceSeconds: options.driftToleranceSeconds ?? 0.03
204
- });
205
- const master = {
206
- play: (when) => mirror.play(when),
207
- pause: () => mirror.pause(),
208
- stop: () => mirror.stop(),
209
- seekPosition: (position, when) => mirror.seekPosition(position, when),
210
- setRate: (rate) => mirror.setRate(rate),
211
- get position() {
212
- return score.nominalSeconds;
213
- },
214
- get clock() {
215
- return score.clock ?? mirror.clock;
216
- },
217
- // Dead reckoning is only meaningful while the transport has no clock of
218
- // its own; once it exposes one the group reads the truth directly and
219
- // the group's own master-stop check covers the stall case.
220
- reconcile: (at) => score.clock ? "ok" : mirror.reconcile(at),
221
- dispose: () => mirror.dispose()
222
- };
223
- const follower = {
224
- play: (when) => clip.play(when),
225
- pause: () => clip.pause(),
226
- stop: () => clip.stop(),
227
- seek: (position) => clip.seek(position),
228
- setRate: (rate) => clip.setRate?.(rate),
229
- get position() {
230
- return clip.seconds;
231
- },
232
- get running() {
233
- return clip.playing;
234
- },
235
- get clock() {
236
- return clip.clock;
237
- },
238
- dispose: () => clip.dispose?.()
239
- };
240
- __privateSet(this, _group, new TransportGroup(master, now, {
241
- leadInSeconds: options.leadInSeconds,
242
- driftToleranceSeconds: options.driftToleranceSeconds,
243
- driftCheckIntervalMs: options.driftCheckIntervalMs,
244
- loop: options.loop,
245
- tick: options.tick,
246
- onOperationError: options.onOperationError
247
- }));
248
- __privateGet(this, _group).addFollower(follower, { offsetSeconds: clipOffset });
249
- }
250
- /**
251
- * The shared transport clock (nominal score seconds): a read-through to the
252
- * score transport's own clock when it has one, else the kernel mirror. The
253
- * sync never mutates a transport-owned clock.
254
- */
255
- get clock() {
256
- return __privateGet(this, _group).clock;
257
- }
258
- /** Coherent state on the nominal master-seconds axis. */
259
- get snapshot() {
260
- return __privateGet(this, _group).snapshot;
261
- }
262
- /** Subscribe before receiving the current snapshot. Detaching the observer
263
- * does not stop either player. Subsequent events describe command invalidation,
264
- * committed/superseded settlement, errors and disposal. */
265
- subscribe(listener) {
266
- __privateMethod(this, _ScoreAudioSync_instances, assertActive_fn).call(this);
267
- return __privateGet(this, _group).subscribe(listener);
268
- }
269
- /** Await a command's participant settlement. Seek positions and loop bounds
270
- * are nominal master seconds; rate never changes that coordinate system.
271
- * The shared 0.25–4 rate range also applies to this command surface. */
272
- dispatch(command) {
273
- __privateMethod(this, _ScoreAudioSync_instances, assertActive_fn).call(this);
274
- if (command.type === "rate") assertSharedRate(command.rate);
275
- return __privateGet(this, _group).dispatch(command);
276
- }
277
- /**
278
- * Set (or clear) a loop region on the score-seconds axis, live. The wrap
279
- * runs through {@link seek}, so it inherits the shared re-entry origin:
280
- * both transports leave the boundary together on one audio-clock instant,
281
- * with no score-only opening on each cycle. A worker-backed tick watcher
282
- * detects the boundary, so the wrap INSTANT still trails the true boundary
283
- * by watcher delivery, preparation and lead-in delays; browser throttling
284
- * prevents a fixed upper bound. Landing the wrap on
285
- * the boundary itself needs the scheduler to commit notes across it (or
286
- * the clip to loop natively), which is a separate design.
287
- */
288
- setLoop(loop) {
289
- __privateMethod(this, _ScoreAudioSync_instances, assertActive_fn).call(this);
290
- __privateGet(this, _group).setLoop(loop);
291
- }
292
- get loop() {
293
- return __privateGet(this, _group).loop;
294
- }
295
- /** Current transport position in nominal score seconds. */
296
- get seconds() {
297
- return __privateGet(this, _score).nominalSeconds;
298
- }
299
- /**
300
- * Start both transports on one shared audio-clock origin. The sync
301
- * proposes `now + leadInSeconds` to the score master; one that supports
302
- * scheduled starts arms there and the clip joins at that very instant, so
303
- * with buffer-engine playback both make their first sound together. A
304
- * master that ignores the proposal starts immediately and the clip joins
305
- * a lead-in later, offset-matched to its anchor, exactly as before.
306
- */
307
- async play() {
308
- __privateMethod(this, _ScoreAudioSync_instances, assertActive_fn).call(this);
309
- return __privateGet(this, _group).play();
310
- }
311
- pause() {
312
- if (__privateGet(this, _disposed)) return;
313
- __privateGet(this, _group).pause();
314
- }
315
- stop() {
316
- if (__privateGet(this, _disposed)) return;
317
- __privateGet(this, _group).stop();
318
- }
319
- /**
320
- * Seek both transports to a score-seconds position. While playing, the
321
- * sync proposes a shared re-entry origin exactly as {@link play} does and
322
- * then re-joins the clip there, so both sides come back in together
323
- * instead of the score resuming a lead-in ahead of the clip. Loop wraps
324
- * run through this path and inherit the same shared origin.
325
- */
326
- async seek(scoreSeconds) {
327
- __privateMethod(this, _ScoreAudioSync_instances, assertActive_fn).call(this);
328
- if (!Number.isFinite(scoreSeconds) || scoreSeconds < 0) {
329
- throw new RangeError("scoreSeconds must be finite and >= 0.");
330
- }
331
- return __privateGet(this, _group).seek(scoreSeconds);
332
- }
333
- /**
334
- * Set the shared playback rate on both transports. The score scheduler's
335
- * retune is synchronous, so the clip re-joins immediately on the audio
336
- * clock. The group owns the session command; each engine retains its own
337
- * transport clock until shared-instance injection is implemented.
338
- */
339
- setRate(rate) {
340
- __privateMethod(this, _ScoreAudioSync_instances, assertActive_fn).call(this);
341
- assertSharedRate(rate);
342
- __privateGet(this, _group).setRate(rate);
343
- }
344
- dispose() {
345
- if (__privateGet(this, _disposed)) return;
346
- __privateSet(this, _disposed, true);
347
- try {
348
- __privateGet(this, _group).dispose();
349
- } finally {
350
- releaseOwnedContext(this);
351
- }
352
- }
353
- /**
354
- * One drift check. Corrections re-join on the audio clock (the same
355
- * scheduled-start dance as {@link play}) rather than command-level seeking,
356
- * so a correction lands sample-accurately instead of chasing the score by
357
- * one JS-tick each time.
358
- */
359
- checkDrift() {
360
- __privateMethod(this, _ScoreAudioSync_instances, assertActive_fn).call(this);
361
- return __privateGet(this, _group).checkDrift();
362
- }
363
- };
364
- _group = new WeakMap();
365
- _score = new WeakMap();
366
- _disposed = new WeakMap();
367
- _ScoreAudioSync_instances = new WeakSet();
368
- assertActive_fn = function() {
369
- if (__privateGet(this, _disposed)) throw new Error("ScoreAudioSync has been disposed.");
370
- };
371
- function createSyncedPlayback(score, clip, options = {}) {
372
- const clipOptions = options.clipOptions;
373
- assertFactoryClipOptions("createSyncedPlayback", clip, clipOptions);
374
- const clipOffsetSeconds = validatedClipOffsetSeconds(options.clipOffsetSeconds);
375
- const scoreOptions = options.scoreOptions;
376
- assertRenderedClipAlignment("createSyncedPlayback", score, clip, scoreOptions?.expandRepeats);
377
- assertInitialScoreTempo(score, scoreOptions?.tempo);
378
- const context = options.context ?? createWebAudioContext("Web Audio is not available. Pass an existing AudioContext in options.context.");
379
- let scorePlayer;
380
- let clipPlayer;
381
- try {
382
- scorePlayer = new ScorePlayer(score, { ...scoreOptions, audioContext: context });
383
- clipPlayer = new AudioClipPlayer(clip, {
384
- ...clipOptions,
385
- audioContext: context,
386
- // Only the buffer engine can join sample-accurately.
387
- engine: "buffer"
388
- });
389
- const sync = new ScoreAudioSync(scorePlayer, clipPlayer, context, {
390
- ...options,
391
- clipOffsetSeconds
392
- });
393
- if (!options.context) ownContext(sync, context, options.onOperationError);
394
- return { sync, scorePlayer, clipPlayer };
395
- } catch (error) {
396
- for (const player of [clipPlayer, scorePlayer]) {
397
- try {
398
- player?.dispose();
399
- } catch {
400
- }
401
- }
402
- if (!options.context) closeContext(context, options.onOperationError);
403
- throw error;
404
- }
405
- }
406
61
  async function renderScoreToClip(score, options) {
407
- const baseTempo = score.timeMap.tempi[0]?.bpm ?? 120;
408
62
  const tempo = options?.tempo;
409
63
  if (tempo !== void 0 && (!Number.isFinite(tempo) || tempo <= 0)) {
410
64
  throw new RangeError("renderScoreToClip tempo must be finite and > 0.");
@@ -418,148 +72,74 @@ async function renderScoreToClip(score, options) {
418
72
  for (let channel = 0; channel < buffer.numberOfChannels; channel++) {
419
73
  channelData.push(buffer.getChannelData(channel));
420
74
  }
421
- const clip = createAudioClip({ channelData, sampleRate: buffer.sampleRate });
422
- recordRenderProvenance(clip, score, tempo === void 0 ? 1 : tempo / baseTempo, tail === void 0 || tail > 0);
423
- return clip;
424
- }
425
- function assertInitialScoreTempo(score, tempo) {
426
- if (tempo === void 0) return;
427
- const baseTempo = score.timeMap.tempi[0]?.bpm ?? 120;
428
- const rate = tempo / baseTempo;
429
- if (!Number.isFinite(rate) || rate < MIN_SHARED_PLAYBACK_RATE || rate > MAX_SHARED_PLAYBACK_RATE) {
430
- throw new RangeError(
431
- `scoreOptions.tempo must set an initial shared rate between ${MIN_SHARED_PLAYBACK_RATE} and ${MAX_SHARED_PLAYBACK_RATE} times the score tempo.`
432
- );
433
- }
434
- }
435
- function assertSharedRate(rate) {
436
- if (!Number.isFinite(rate) || rate < MIN_SHARED_PLAYBACK_RATE || rate > MAX_SHARED_PLAYBACK_RATE) {
437
- throw new RangeError(`rate must be finite and between ${MIN_SHARED_PLAYBACK_RATE} and ${MAX_SHARED_PLAYBACK_RATE}.`);
438
- }
75
+ return createAudioClip({ channelData, sampleRate: buffer.sampleRate });
439
76
  }
440
77
 
441
- // src/audio-master.ts
442
- import { createWebAudioContext as createWebAudioContext2 } from "@webmusic/kernel/audio-context";
443
- import { AudioClipPlayer as AudioClipPlayer2 } from "@webmusic/audio/play/headless";
444
- import { ScorePlayer as ScorePlayer2 } from "@webmusic/score/play/headless";
445
- function offsetClockView(clock, offset) {
446
- if (offset === 0) return clock;
447
- return {
448
- get state() {
449
- const state = clock.state;
450
- return { ...state, originPosition: state.originPosition + offset };
451
- },
452
- get rate() {
453
- return clock.rate;
454
- },
455
- get paused() {
456
- return clock.paused;
457
- },
458
- get holding() {
459
- return clock.holding;
460
- },
461
- positionAt: (t) => clock.positionAt(t) + offset,
462
- timeAt: (position) => clock.timeAt(position - offset)
463
- };
464
- }
465
- function clipAsMaster(clip) {
466
- return {
467
- play: (when) => clip.play(when),
468
- pause: () => clip.pause(),
469
- stop: () => clip.stop(),
470
- seekNominal: (seconds, when) => {
471
- if (when === void 0 || !clip.playing) {
472
- clip.seek(seconds);
473
- return;
474
- }
475
- clip.pause();
476
- clip.seek(seconds);
477
- return clip.play(when);
478
- },
479
- setRate: (rate) => clip.setRate(rate),
480
- get nominalSeconds() {
481
- return clip.seconds;
482
- },
483
- get clock() {
484
- return clip.clock;
485
- },
486
- dispose: () => clip.dispose()
487
- };
488
- }
489
- function scoreAsFollower(score, options = {}) {
490
- const offset = validatedClipOffsetSeconds(options.clipOffsetSeconds);
491
- let requested = 0;
492
- return {
493
- play: (when) => {
494
- if (when !== void 0 && requested < 0) {
495
- return score.play(when + -requested / score.rate);
78
+ // src/session.ts
79
+ import { AudioPlayer } from "@webmusic/audio/play/headless";
80
+ import { ModuleAudioEnvironment, ModuleContext, routeModuleOutput } from "@webmusic/kernel/module";
81
+ import { SessionTransport } from "@webmusic/kernel/session";
82
+ import { ScorePlayerModule } from "@webmusic/score/play/headless";
83
+ function createScoreAudioSession(score, clip, options = {}) {
84
+ const audio = new ModuleAudioEnvironment(options.context ? { context: options.context } : {});
85
+ const session = new SessionTransport(() => audio.peek()?.currentTime ?? 0, {
86
+ ...options.leadInSeconds !== void 0 ? { leadInSeconds: options.leadInSeconds } : {},
87
+ onOperationError: options.onOperationError
88
+ });
89
+ const context = new ModuleContext({ id: "score-audio-session", audio, session });
90
+ let scoreModule;
91
+ let clipPlayer;
92
+ let participant;
93
+ let route;
94
+ let disposed = false;
95
+ const dispose = () => {
96
+ if (disposed) return;
97
+ disposed = true;
98
+ let failure;
99
+ for (const release of [
100
+ () => participant?.release(),
101
+ () => route?.release(),
102
+ () => clipPlayer?.dispose(),
103
+ () => scoreModule?.dispose(),
104
+ () => session.dispose(),
105
+ () => audio.dispose()
106
+ ]) {
107
+ try {
108
+ release();
109
+ } catch (error) {
110
+ failure ?? (failure = error);
496
111
  }
497
- return score.play(when);
498
- },
499
- pause: () => score.pause(),
500
- stop: () => {
501
- requested = 0;
502
- score.stop();
503
- },
504
- // The sync only ever seeks a follower it has just paused, and a paused
505
- // seekNominal applies its re-anchor synchronously before resolving.
506
- seek: (seconds) => {
507
- requested = seconds - offset;
508
- void score.seekNominal(requested);
509
- },
510
- setRate: (rate) => score.setRate(rate),
511
- get seconds() {
512
- return score.nominalSeconds + offset;
513
- },
514
- get playing() {
515
- return score.isPlaying();
516
- },
517
- get clock() {
518
- return offsetClockView(score.clock, offset);
519
- },
520
- dispose: () => score.dispose()
112
+ }
113
+ if (failure !== void 0) throw failure;
521
114
  };
522
- }
523
- function createAudioMasteredPlayback(score, clip, options = {}) {
524
- const clipOptions = options.clipOptions;
525
- assertFactoryClipOptions("createAudioMasteredPlayback", clip, clipOptions);
526
- const clipOffsetSeconds = validatedClipOffsetSeconds(options.clipOffsetSeconds);
527
- const scoreOptions = options.scoreOptions;
528
- assertRenderedClipAlignment("createAudioMasteredPlayback", score, clip, scoreOptions?.expandRepeats);
529
- if (scoreOptions?.tempo !== void 0) {
530
- throw new RangeError(
531
- "createAudioMasteredPlayback does not accept scoreOptions.tempo: the audio master owns the shared rate. Change both players with sync.setRate()."
532
- );
533
- }
534
- const context = options.context ?? createWebAudioContext2("Web Audio is not available. Pass an existing AudioContext in options.context.");
535
- let scorePlayer;
536
- let clipPlayer;
537
115
  try {
538
- scorePlayer = new ScorePlayer2(score, { ...scoreOptions, audioContext: context });
539
- clipPlayer = new AudioClipPlayer2(clip, {
540
- ...clipOptions,
541
- audioContext: context,
542
- engine: "buffer"
543
- });
544
- const sync = new ScoreAudioSync(
545
- clipAsMaster(clipPlayer),
546
- scoreAsFollower(scorePlayer, { clipOffsetSeconds }),
116
+ scoreModule = new ScorePlayerModule(score, {
117
+ id: "score",
547
118
  context,
548
- // The follower adapter already translates the offset onto the clip axis.
549
- { ...options, clipOffsetSeconds: 0 }
550
- );
551
- if (!options.context) ownContext(sync, context, options.onOperationError);
552
- return { sync, scorePlayer, clipPlayer };
553
- } catch (error) {
554
- for (const player of [clipPlayer, scorePlayer]) {
555
- try {
556
- player?.dispose();
557
- } catch {
119
+ synth: options.synth,
120
+ offsetSeconds: options.scoreOffsetSeconds,
121
+ positionScale: options.scorePositionScale,
122
+ onError: (error) => options.onOperationError?.("score", error)
123
+ });
124
+ const player = new AudioPlayer(clip, { moduleContext: context });
125
+ clipPlayer = player;
126
+ participant = registerAudioParticipant(session, player, {
127
+ offsetSeconds: options.clipOffsetSeconds,
128
+ positionScale: options.clipPositionScale,
129
+ prepare: async () => {
130
+ await player.preload();
131
+ if (disposed) throw new Error("Score/Audio Session was disposed during preparation.");
132
+ if (!route) route = routeModuleOutput(context, { id: "clip", getPort: () => player.outputPort }, player.outputPort);
558
133
  }
134
+ });
135
+ } catch (error) {
136
+ try {
137
+ dispose();
138
+ } catch {
559
139
  }
560
- if (!options.context) closeContext(context, options.onOperationError);
561
140
  throw error;
562
141
  }
142
+ return Object.freeze({ session, context, scoreModule, clipPlayer, dispose });
563
143
  }
564
144
 
565
145
  // src/transcription.ts
@@ -707,13 +287,11 @@ export {
707
287
  DEFAULT_MAX_MAPPED_BEATS,
708
288
  DEFAULT_MAX_TRANSCRIPTION_MEASURES,
709
289
  DEFAULT_MAX_TRANSCRIPTION_NOTES,
710
- ScoreAudioSync,
711
290
  beatGridFromTimeMap,
712
- clipAsMaster,
713
- createAudioMasteredPlayback,
714
- createSyncedPlayback,
291
+ createScoreAudioSession,
292
+ createWebMusicProjectPlugins,
293
+ registerAudioParticipant,
715
294
  renderScoreToClip,
716
- scoreAsFollower,
717
295
  scoreFromTranscription,
718
296
  timeMapFromBeatGrid
719
297
  };