@dawcore/transport 0.0.13 → 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/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
- if (targetTick > this._rightEdge) {
127
- this._generateAndConsume(this._rightEdge, targetTick);
128
- this._rightEdge = targetTick;
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) {
@@ -1319,6 +1330,9 @@ var _Transport = class _Transport {
1319
1330
  const currentTime = this._clock.getTime();
1320
1331
  this._scheduler.reset(currentTime);
1321
1332
  this._endTime = endTime;
1333
+ this._scheduler.setPlayEnd(
1334
+ endTime !== void 0 ? this._tempoMap.secondsToTicks(endTime) : null
1335
+ );
1322
1336
  this._clock.start();
1323
1337
  const currentTick = this._tempoMap.secondsToTicks(currentTime);
1324
1338
  this._clipPlayer.onPositionJump(currentTick);
@@ -1352,6 +1366,7 @@ var _Transport = class _Transport {
1352
1366
  this._silenceAll();
1353
1367
  this._playing = false;
1354
1368
  this._endTime = void 0;
1369
+ this._scheduler.setPlayEnd(null);
1355
1370
  if (wasPlaying) {
1356
1371
  this._emit("stop");
1357
1372
  }
@@ -1370,6 +1385,7 @@ var _Transport = class _Transport {
1370
1385
  this._clock.seekTo(time);
1371
1386
  this._scheduler.reset(time);
1372
1387
  this._endTime = void 0;
1388
+ this._scheduler.setPlayEnd(null);
1373
1389
  if (wasPlaying && !wasCountingIn) {
1374
1390
  this._clock.start();
1375
1391
  const seekTick = this._tempoMap.secondsToTicks(time);
@@ -1808,6 +1824,9 @@ var _Transport = class _Transport {
1808
1824
  this._countingIn = true;
1809
1825
  this._playing = true;
1810
1826
  this._endTime = endTime;
1827
+ this._scheduler.setPlayEnd(
1828
+ endTime !== void 0 ? this._tempoMap.secondsToTicks(endTime) : null
1829
+ );
1811
1830
  const playPositionTick = this._tempoMap.secondsToTicks(currentTime);
1812
1831
  const meter = this._meterMap.getMeter(playPositionTick);
1813
1832
  const totalBeats = meter.numerator * this._countInBars;