@dawcore/transport 0.0.12 → 0.0.14
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 +41 -10
- package/dist/index.d.mts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +73 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -57,6 +57,8 @@ var Scheduler = class {
|
|
|
57
57
|
this._loopStart = 0;
|
|
58
58
|
// integer ticks
|
|
59
59
|
this._loopEnd = 0;
|
|
60
|
+
// integer ticks
|
|
61
|
+
this._playEnd = null;
|
|
60
62
|
this._tempoMap = tempoMap;
|
|
61
63
|
this._lookahead = options.lookahead ?? 0.2;
|
|
62
64
|
this._onLoop = options.onLoop;
|
|
@@ -91,6 +93,14 @@ var Scheduler = class {
|
|
|
91
93
|
const endTick = this._tempoMap.secondsToTicks(endSec);
|
|
92
94
|
this.setLoop(enabled, startTick, endTick);
|
|
93
95
|
}
|
|
96
|
+
/** Hard end bound (ticks) for non-loop playback: the lookahead window never
|
|
97
|
+
* generates events at or beyond this tick, so audio (metronome clicks, clips)
|
|
98
|
+
* can't be scheduled past the playback end and sound a beat into the next
|
|
99
|
+
* (nonexistent) bar. Null = unbounded. Set from Transport.play()'s endTime; the
|
|
100
|
+
* loop path is unaffected (loopEnd already bounds it). */
|
|
101
|
+
setPlayEnd(endTick) {
|
|
102
|
+
this._playEnd = endTick == null ? null : Math.round(endTick);
|
|
103
|
+
}
|
|
94
104
|
/** Reset scheduling cursor. Takes seconds (from Clock), converts to ticks. */
|
|
95
105
|
reset(timeSeconds) {
|
|
96
106
|
this._rightEdge = this._tempoMap.secondsToTicks(timeSeconds);
|
|
@@ -123,9 +133,10 @@ var Scheduler = class {
|
|
|
123
133
|
}
|
|
124
134
|
return;
|
|
125
135
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this._rightEdge
|
|
136
|
+
const bound = this._playEnd !== null && targetTick > this._playEnd ? this._playEnd : targetTick;
|
|
137
|
+
if (bound > this._rightEdge) {
|
|
138
|
+
this._generateAndConsume(this._rightEdge, bound);
|
|
139
|
+
this._rightEdge = bound;
|
|
129
140
|
}
|
|
130
141
|
}
|
|
131
142
|
_generateAndConsume(fromTick, toTick) {
|
|
@@ -674,6 +685,8 @@ var MeterMap = class {
|
|
|
674
685
|
// src/audio/master-node.ts
|
|
675
686
|
var MasterNode = class {
|
|
676
687
|
constructor(audioContext) {
|
|
688
|
+
this._destination = null;
|
|
689
|
+
this._effectsInput = null;
|
|
677
690
|
this._gainNode = audioContext.createGain();
|
|
678
691
|
}
|
|
679
692
|
get input() {
|
|
@@ -682,6 +695,37 @@ var MasterNode = class {
|
|
|
682
695
|
get output() {
|
|
683
696
|
return this._gainNode;
|
|
684
697
|
}
|
|
698
|
+
/** Connect the master output to its final destination (audioContext.destination) */
|
|
699
|
+
connectOutput(destination) {
|
|
700
|
+
this._destination = destination;
|
|
701
|
+
this._gainNode.connect(destination);
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Insert an effects chain between the master gain and the destination.
|
|
705
|
+
* Only the destination edge is severed (targeted disconnect), so parallel
|
|
706
|
+
* taps on the master output (analyzers, recorders) keep working.
|
|
707
|
+
* The caller is responsible for routing the chain's output onward.
|
|
708
|
+
*/
|
|
709
|
+
connectEffects(effectsInput) {
|
|
710
|
+
if (this._effectsInput) {
|
|
711
|
+
this._gainNode.disconnect(this._effectsInput);
|
|
712
|
+
} else if (this._destination) {
|
|
713
|
+
this._gainNode.disconnect(this._destination);
|
|
714
|
+
}
|
|
715
|
+
this._gainNode.connect(effectsInput);
|
|
716
|
+
this._effectsInput = effectsInput;
|
|
717
|
+
}
|
|
718
|
+
/** Remove the effects chain and restore direct routing to the destination */
|
|
719
|
+
disconnectEffects() {
|
|
720
|
+
if (!this._effectsInput) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
this._gainNode.disconnect(this._effectsInput);
|
|
724
|
+
if (this._destination) {
|
|
725
|
+
this._gainNode.connect(this._destination);
|
|
726
|
+
}
|
|
727
|
+
this._effectsInput = null;
|
|
728
|
+
}
|
|
685
729
|
setVolume(value) {
|
|
686
730
|
this._gainNode.gain.value = value;
|
|
687
731
|
}
|
|
@@ -691,6 +735,8 @@ var MasterNode = class {
|
|
|
691
735
|
} catch (err) {
|
|
692
736
|
console.warn("[waveform-playlist] MasterNode.dispose: error disconnecting: " + String(err));
|
|
693
737
|
}
|
|
738
|
+
this._destination = null;
|
|
739
|
+
this._effectsInput = null;
|
|
694
740
|
}
|
|
695
741
|
};
|
|
696
742
|
|
|
@@ -1284,6 +1330,9 @@ var _Transport = class _Transport {
|
|
|
1284
1330
|
const currentTime = this._clock.getTime();
|
|
1285
1331
|
this._scheduler.reset(currentTime);
|
|
1286
1332
|
this._endTime = endTime;
|
|
1333
|
+
this._scheduler.setPlayEnd(
|
|
1334
|
+
endTime !== void 0 ? this._tempoMap.secondsToTicks(endTime) : null
|
|
1335
|
+
);
|
|
1287
1336
|
this._clock.start();
|
|
1288
1337
|
const currentTick = this._tempoMap.secondsToTicks(currentTime);
|
|
1289
1338
|
this._clipPlayer.onPositionJump(currentTick);
|
|
@@ -1317,6 +1366,7 @@ var _Transport = class _Transport {
|
|
|
1317
1366
|
this._silenceAll();
|
|
1318
1367
|
this._playing = false;
|
|
1319
1368
|
this._endTime = void 0;
|
|
1369
|
+
this._scheduler.setPlayEnd(null);
|
|
1320
1370
|
if (wasPlaying) {
|
|
1321
1371
|
this._emit("stop");
|
|
1322
1372
|
}
|
|
@@ -1335,12 +1385,14 @@ var _Transport = class _Transport {
|
|
|
1335
1385
|
this._clock.seekTo(time);
|
|
1336
1386
|
this._scheduler.reset(time);
|
|
1337
1387
|
this._endTime = void 0;
|
|
1388
|
+
this._scheduler.setPlayEnd(null);
|
|
1338
1389
|
if (wasPlaying && !wasCountingIn) {
|
|
1339
1390
|
this._clock.start();
|
|
1340
1391
|
const seekTick = this._tempoMap.secondsToTicks(time);
|
|
1341
1392
|
this._clipPlayer.onPositionJump(seekTick);
|
|
1342
1393
|
this._timer.start();
|
|
1343
1394
|
}
|
|
1395
|
+
this._emit("seek", { seconds: time });
|
|
1344
1396
|
}
|
|
1345
1397
|
getCurrentTime() {
|
|
1346
1398
|
if (this._countingIn) {
|
|
@@ -1650,6 +1702,20 @@ var _Transport = class _Transport {
|
|
|
1650
1702
|
get masterOutputNode() {
|
|
1651
1703
|
return this._masterNode.output;
|
|
1652
1704
|
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Insert an effects chain on the master bus, between the master gain and
|
|
1707
|
+
* audioContext.destination. Accepts any AudioNode chain (Tone.js effects,
|
|
1708
|
+
* WAM plugins, native nodes). The caller is responsible for connecting the
|
|
1709
|
+
* chain's output to audioContext.destination. Calling again replaces the
|
|
1710
|
+
* previous chain. Parallel taps on `masterOutputNode` are unaffected.
|
|
1711
|
+
*/
|
|
1712
|
+
connectMasterOutput(node) {
|
|
1713
|
+
this._masterNode.connectEffects(node);
|
|
1714
|
+
}
|
|
1715
|
+
/** Remove the master effects chain and restore direct routing to audioContext.destination. */
|
|
1716
|
+
disconnectMasterOutput() {
|
|
1717
|
+
this._masterNode.disconnectEffects();
|
|
1718
|
+
}
|
|
1653
1719
|
// --- Events ---
|
|
1654
1720
|
on(event, cb) {
|
|
1655
1721
|
if (!this._listeners.has(event)) {
|
|
@@ -1703,7 +1769,7 @@ var _Transport = class _Transport {
|
|
|
1703
1769
|
}
|
|
1704
1770
|
_initAudioGraph(audioContext) {
|
|
1705
1771
|
this._masterNode = new MasterNode(audioContext);
|
|
1706
|
-
this._masterNode.
|
|
1772
|
+
this._masterNode.connectOutput(audioContext.destination);
|
|
1707
1773
|
const toAudioTime = (transportTime) => this._clock.toAudioTime(transportTime);
|
|
1708
1774
|
this._clipPlayer = new ClipPlayer(
|
|
1709
1775
|
audioContext,
|
|
@@ -1758,6 +1824,9 @@ var _Transport = class _Transport {
|
|
|
1758
1824
|
this._countingIn = true;
|
|
1759
1825
|
this._playing = true;
|
|
1760
1826
|
this._endTime = endTime;
|
|
1827
|
+
this._scheduler.setPlayEnd(
|
|
1828
|
+
endTime !== void 0 ? this._tempoMap.secondsToTicks(endTime) : null
|
|
1829
|
+
);
|
|
1761
1830
|
const playPositionTick = this._tempoMap.secondsToTicks(currentTime);
|
|
1762
1831
|
const meter = this._meterMap.getMeter(playPositionTick);
|
|
1763
1832
|
const totalBeats = meter.numerator * this._countInBars;
|