@dawcore/transport 0.0.15 → 0.0.16-next.1

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.mjs CHANGED
@@ -1288,62 +1288,92 @@ var MasterNode = class {
1288
1288
  };
1289
1289
 
1290
1290
  // src/audio/track-node.ts
1291
+ import { createPanStage } from "@waveform-playlist/core";
1292
+ var PREFIX = "[waveform-playlist] ";
1291
1293
  var TrackNode = class {
1292
- constructor(id, audioContext) {
1293
- this._destination = null;
1294
- this._effectsInput = null;
1294
+ constructor(id, audioContext, sourceChannelCount = 1) {
1295
+ this._effects = null;
1295
1296
  this.id = id;
1297
+ this._inputNode = audioContext.createGain();
1296
1298
  this._volumeNode = audioContext.createGain();
1297
- this._panNode = audioContext.createStereoPanner();
1298
- this._panNode.channelCount = 2;
1299
+ this._panStage = createPanStage(audioContext, 0, sourceChannelCount);
1299
1300
  this._muteNode = audioContext.createGain();
1300
- this._volumeNode.connect(this._panNode);
1301
- this._panNode.connect(this._muteNode);
1301
+ this._inputNode.connect(this._volumeNode);
1302
+ this._volumeNode.connect(this._panStage.input);
1303
+ this._panStage.output.connect(this._muteNode);
1302
1304
  }
1303
- /** Where clip sources connect */
1305
+ /** Where clip sources connect (pre-fader, pre-effects). */
1304
1306
  get input() {
1305
- return this._volumeNode;
1307
+ return this._inputNode;
1306
1308
  }
1307
1309
  /** Connect this track's output to a destination (master node) */
1308
1310
  connectOutput(destination) {
1309
- this._destination = destination;
1310
1311
  this._muteNode.connect(destination);
1311
1312
  }
1312
1313
  setVolume(value) {
1313
1314
  this._volumeNode.gain.value = value;
1314
1315
  }
1315
1316
  setPan(value) {
1316
- this._panNode.pan.value = value;
1317
+ this._panStage.setPan(value);
1318
+ }
1319
+ /** Select the pan law from the track's source material: 1 = mono law
1320
+ * (−3 dB per side at centre), 2+ = stereo law (unity at centre). */
1321
+ setSourceChannelCount(sourceChannelCount) {
1322
+ this._panStage.setSourceChannelCount(sourceChannelCount);
1317
1323
  }
1318
1324
  setMute(muted) {
1319
1325
  this._muteNode.gain.value = muted ? 0 : 1;
1320
1326
  }
1321
- connectEffects(effectsInput) {
1322
- if (this._effectsInput) {
1323
- this.disconnectEffects();
1324
- }
1325
- this._muteNode.disconnect();
1326
- this._muteNode.connect(effectsInput);
1327
- this._effectsInput = effectsInput;
1328
- }
1327
+ /**
1328
+ * Insert an effects chain between the track input and the fader:
1329
+ * `input → effectsInput … effectsOutput → volume`. The transport owns
1330
+ * BOTH edges — the caller only builds what lies between the two nodes
1331
+ * (pass the same node twice for a single-node effect). Replaces any
1332
+ * chain connected earlier.
1333
+ */
1334
+ connectEffects(effectsInput, effectsOutput) {
1335
+ this.disconnectEffects();
1336
+ this._inputNode.disconnect();
1337
+ this._inputNode.connect(effectsInput);
1338
+ effectsOutput.connect(this._volumeNode);
1339
+ this._effects = { input: effectsInput, output: effectsOutput };
1340
+ }
1341
+ /** Remove the effects chain and restore `input → volume`. No-op without one. */
1329
1342
  disconnectEffects() {
1330
- if (this._effectsInput && this._destination) {
1331
- this._muteNode.disconnect();
1332
- this._muteNode.connect(this._destination);
1333
- this._effectsInput = null;
1343
+ if (!this._effects) {
1344
+ return;
1334
1345
  }
1346
+ this._releaseEffectsReturn();
1347
+ this._inputNode.disconnect();
1348
+ this._inputNode.connect(this._volumeNode);
1349
+ this._effects = null;
1335
1350
  }
1336
1351
  dispose() {
1337
- for (const node of [this._volumeNode, this._panNode, this._muteNode]) {
1352
+ this._releaseEffectsReturn();
1353
+ this._effects = null;
1354
+ for (const node of [this._inputNode, this._volumeNode, this._muteNode]) {
1338
1355
  try {
1339
1356
  node.disconnect();
1340
1357
  } catch (err) {
1341
- console.warn(
1342
- "[waveform-playlist] TrackNode.dispose: error disconnecting node:",
1343
- String(err)
1344
- );
1358
+ console.warn(PREFIX + "TrackNode.dispose: error disconnecting node:", String(err));
1345
1359
  }
1346
1360
  }
1361
+ this._panStage.dispose();
1362
+ }
1363
+ /** Targeted disconnect of `effectsOutput → volume` — other consumers of
1364
+ * the chain's output (analyser taps) keep their edges. */
1365
+ _releaseEffectsReturn() {
1366
+ if (!this._effects) {
1367
+ return;
1368
+ }
1369
+ try {
1370
+ this._effects.output.disconnect(this._volumeNode);
1371
+ } catch (err) {
1372
+ console.warn(
1373
+ PREFIX + 'TrackNode: effects chain was already disconnected from track "' + this.id + '": ',
1374
+ String(err)
1375
+ );
1376
+ }
1347
1377
  }
1348
1378
  };
1349
1379
 
@@ -1662,6 +1692,9 @@ var MetronomePlayer = class {
1662
1692
  }
1663
1693
  };
1664
1694
 
1695
+ // src/transport.ts
1696
+ import { trackChannelCount } from "@waveform-playlist/core";
1697
+
1665
1698
  // src/audio/count-in-player.ts
1666
1699
  var CountInPlayer = class {
1667
1700
  constructor(audioContext, tempoMap, destination, toAudioTime) {
@@ -2102,7 +2135,7 @@ var _Transport = class _Transport {
2102
2135
  this._mutedTrackIds.clear();
2103
2136
  this._tracks = tracks;
2104
2137
  for (const track of tracks) {
2105
- const trackNode = new TrackNode(track.id, this._audioContext);
2138
+ const trackNode = new TrackNode(track.id, this._audioContext, trackChannelCount(track));
2106
2139
  trackNode.setVolume(track.volume);
2107
2140
  trackNode.setPan(track.pan);
2108
2141
  trackNode.connectOutput(this._masterNode.input);
@@ -2118,7 +2151,7 @@ var _Transport = class _Transport {
2118
2151
  this._clipPlayer.setTracks(tracks, this._trackNodes);
2119
2152
  }
2120
2153
  addTrack(track) {
2121
- const trackNode = new TrackNode(track.id, this._audioContext);
2154
+ const trackNode = new TrackNode(track.id, this._audioContext, trackChannelCount(track));
2122
2155
  trackNode.setVolume(track.volume);
2123
2156
  trackNode.setPan(track.pan);
2124
2157
  trackNode.connectOutput(this._masterNode.input);
@@ -2151,6 +2184,7 @@ var _Transport = class _Transport {
2151
2184
  if (node) {
2152
2185
  node.setVolume(track.volume);
2153
2186
  node.setPan(track.pan);
2187
+ node.setSourceChannelCount(trackChannelCount(track));
2154
2188
  }
2155
2189
  if (track.muted) {
2156
2190
  this._mutedTrackIds.add(trackId);
@@ -2387,18 +2421,30 @@ var _Transport = class _Transport {
2387
2421
  return this._countingIn;
2388
2422
  }
2389
2423
  // --- Effects Hook ---
2390
- connectTrackOutput(trackId, node) {
2424
+ /**
2425
+ * Insert an effects chain on a track, PRE-FADER: clip sources → `input` …
2426
+ * `output` → volume → pan → mute → master. Accepts any AudioNode chain
2427
+ * (native nodes, WAM plugins, Tone.js effects) — pass the same node twice
2428
+ * for a single-node effect. The transport owns both edges; do NOT connect
2429
+ * `output` to the master bus yourself (that would bypass the fader, pan
2430
+ * and mute). Calling again replaces the previous chain.
2431
+ *
2432
+ * `setTracks()` rebuilds every track node, dropping these hookups —
2433
+ * reconnect afterwards.
2434
+ */
2435
+ connectTrackEffects(trackId, input, output) {
2391
2436
  const trackNode = this._trackNodes.get(trackId);
2392
2437
  if (!trackNode) {
2393
- console.warn('[waveform-playlist] connectTrackOutput: unknown trackId "' + trackId + '"');
2438
+ console.warn('[waveform-playlist] connectTrackEffects: unknown trackId "' + trackId + '"');
2394
2439
  return;
2395
2440
  }
2396
- trackNode.connectEffects(node);
2441
+ trackNode.connectEffects(input, output);
2397
2442
  }
2398
- disconnectTrackOutput(trackId) {
2443
+ /** Remove a track's effects chain and restore its direct routing. */
2444
+ disconnectTrackEffects(trackId) {
2399
2445
  const trackNode = this._trackNodes.get(trackId);
2400
2446
  if (!trackNode) {
2401
- console.warn('[waveform-playlist] disconnectTrackOutput: unknown trackId "' + trackId + '"');
2447
+ console.warn('[waveform-playlist] disconnectTrackEffects: unknown trackId "' + trackId + '"');
2402
2448
  return;
2403
2449
  }
2404
2450
  trackNode.disconnectEffects();