@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.d.mts CHANGED
@@ -212,6 +212,7 @@ declare class Scheduler<T extends SchedulerEvent> {
212
212
  private _loopEnabled;
213
213
  private _loopStart;
214
214
  private _loopEnd;
215
+ private _playEnd;
215
216
  private _onLoop;
216
217
  private _tempoMap;
217
218
  constructor(tempoMap: TempoMap, options?: SchedulerOptions);
@@ -221,6 +222,12 @@ declare class Scheduler<T extends SchedulerEvent> {
221
222
  setLoop(enabled: boolean, startTick: Tick, endTick: Tick): void;
222
223
  /** Convenience — converts seconds to ticks via TempoMap */
223
224
  setLoopSeconds(enabled: boolean, startSec: number, endSec: number): void;
225
+ /** Hard end bound (ticks) for non-loop playback: the lookahead window never
226
+ * generates events at or beyond this tick, so audio (metronome clicks, clips)
227
+ * can't be scheduled past the playback end and sound a beat into the next
228
+ * (nonexistent) bar. Null = unbounded. Set from Transport.play()'s endTime; the
229
+ * loop path is unaffected (loopEnd already bounds it). */
230
+ setPlayEnd(endTick: Tick | null): void;
224
231
  /** Reset scheduling cursor. Takes seconds (from Clock), converts to ticks. */
225
232
  reset(timeSeconds: number): void;
226
233
  /** Advance the scheduling window. Takes seconds (from Clock), converts to ticks. */
package/dist/index.d.ts CHANGED
@@ -212,6 +212,7 @@ declare class Scheduler<T extends SchedulerEvent> {
212
212
  private _loopEnabled;
213
213
  private _loopStart;
214
214
  private _loopEnd;
215
+ private _playEnd;
215
216
  private _onLoop;
216
217
  private _tempoMap;
217
218
  constructor(tempoMap: TempoMap, options?: SchedulerOptions);
@@ -221,6 +222,12 @@ declare class Scheduler<T extends SchedulerEvent> {
221
222
  setLoop(enabled: boolean, startTick: Tick, endTick: Tick): void;
222
223
  /** Convenience — converts seconds to ticks via TempoMap */
223
224
  setLoopSeconds(enabled: boolean, startSec: number, endSec: number): void;
225
+ /** Hard end bound (ticks) for non-loop playback: the lookahead window never
226
+ * generates events at or beyond this tick, so audio (metronome clicks, clips)
227
+ * can't be scheduled past the playback end and sound a beat into the next
228
+ * (nonexistent) bar. Null = unbounded. Set from Transport.play()'s endTime; the
229
+ * loop path is unaffected (loopEnd already bounds it). */
230
+ setPlayEnd(endTick: Tick | null): void;
224
231
  /** Reset scheduling cursor. Takes seconds (from Clock), converts to ticks. */
225
232
  reset(timeSeconds: number): void;
226
233
  /** Advance the scheduling window. Takes seconds (from Clock), converts to ticks. */
package/dist/index.js CHANGED
@@ -94,6 +94,8 @@ var Scheduler = class {
94
94
  this._loopStart = 0;
95
95
  // integer ticks
96
96
  this._loopEnd = 0;
97
+ // integer ticks
98
+ this._playEnd = null;
97
99
  this._tempoMap = tempoMap;
98
100
  this._lookahead = options.lookahead ?? 0.2;
99
101
  this._onLoop = options.onLoop;
@@ -128,6 +130,14 @@ var Scheduler = class {
128
130
  const endTick = this._tempoMap.secondsToTicks(endSec);
129
131
  this.setLoop(enabled, startTick, endTick);
130
132
  }
133
+ /** Hard end bound (ticks) for non-loop playback: the lookahead window never
134
+ * generates events at or beyond this tick, so audio (metronome clicks, clips)
135
+ * can't be scheduled past the playback end and sound a beat into the next
136
+ * (nonexistent) bar. Null = unbounded. Set from Transport.play()'s endTime; the
137
+ * loop path is unaffected (loopEnd already bounds it). */
138
+ setPlayEnd(endTick) {
139
+ this._playEnd = endTick == null ? null : Math.round(endTick);
140
+ }
131
141
  /** Reset scheduling cursor. Takes seconds (from Clock), converts to ticks. */
132
142
  reset(timeSeconds) {
133
143
  this._rightEdge = this._tempoMap.secondsToTicks(timeSeconds);
@@ -160,9 +170,10 @@ var Scheduler = class {
160
170
  }
161
171
  return;
162
172
  }
163
- if (targetTick > this._rightEdge) {
164
- this._generateAndConsume(this._rightEdge, targetTick);
165
- this._rightEdge = targetTick;
173
+ const bound = this._playEnd !== null && targetTick > this._playEnd ? this._playEnd : targetTick;
174
+ if (bound > this._rightEdge) {
175
+ this._generateAndConsume(this._rightEdge, bound);
176
+ this._rightEdge = bound;
166
177
  }
167
178
  }
168
179
  _generateAndConsume(fromTick, toTick) {
@@ -1356,6 +1367,9 @@ var _Transport = class _Transport {
1356
1367
  const currentTime = this._clock.getTime();
1357
1368
  this._scheduler.reset(currentTime);
1358
1369
  this._endTime = endTime;
1370
+ this._scheduler.setPlayEnd(
1371
+ endTime !== void 0 ? this._tempoMap.secondsToTicks(endTime) : null
1372
+ );
1359
1373
  this._clock.start();
1360
1374
  const currentTick = this._tempoMap.secondsToTicks(currentTime);
1361
1375
  this._clipPlayer.onPositionJump(currentTick);
@@ -1389,6 +1403,7 @@ var _Transport = class _Transport {
1389
1403
  this._silenceAll();
1390
1404
  this._playing = false;
1391
1405
  this._endTime = void 0;
1406
+ this._scheduler.setPlayEnd(null);
1392
1407
  if (wasPlaying) {
1393
1408
  this._emit("stop");
1394
1409
  }
@@ -1407,6 +1422,7 @@ var _Transport = class _Transport {
1407
1422
  this._clock.seekTo(time);
1408
1423
  this._scheduler.reset(time);
1409
1424
  this._endTime = void 0;
1425
+ this._scheduler.setPlayEnd(null);
1410
1426
  if (wasPlaying && !wasCountingIn) {
1411
1427
  this._clock.start();
1412
1428
  const seekTick = this._tempoMap.secondsToTicks(time);
@@ -1845,6 +1861,9 @@ var _Transport = class _Transport {
1845
1861
  this._countingIn = true;
1846
1862
  this._playing = true;
1847
1863
  this._endTime = endTime;
1864
+ this._scheduler.setPlayEnd(
1865
+ endTime !== void 0 ? this._tempoMap.secondsToTicks(endTime) : null
1866
+ );
1848
1867
  const playPositionTick = this._tempoMap.secondsToTicks(currentTime);
1849
1868
  const meter = this._meterMap.getMeter(playPositionTick);
1850
1869
  const totalBeats = meter.numerator * this._countInBars;