@dawcore/transport 0.0.11 → 0.0.12

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
@@ -147,12 +147,21 @@ declare class TempoMap {
147
147
  * in secondsToTicks) — reject it at the boundary instead. */
148
148
  private static _validateBpm;
149
149
  getTempo(atTick?: Tick): number;
150
+ /** Number of tempo entries in the map. Always >= 1 — the tick-0 entry is
151
+ * permanent. Used by Transport.setTempo to detect multi-entry maps. */
152
+ get entryCount(): number;
150
153
  setTempo(bpm: number, atTick?: Tick, options?: SetTempoOptions): void;
151
154
  ticksToSeconds(ticks: Tick): number;
152
155
  secondsToTicks(seconds: number): Tick;
153
156
  beatsToSeconds(beats: number): number;
154
157
  secondsToBeats(seconds: number): number;
155
158
  clearTempos(): void;
159
+ /** Remove the tempo entry at exactly `atTick`, if one exists. The tick-0
160
+ * entry is permanent (a map must always have a tempo) — removing it is a
161
+ * no-op, matching removeMeter's treatment of the initial meter. The
162
+ * seconds cache is recomputed from the removal point, the same partial
163
+ * update setTempo uses. */
164
+ removeTempo(atTick: Tick): void;
156
165
  /** Get the interpolated BPM at a tick position */
157
166
  private _getTempoAt;
158
167
  private _ticksToSecondsInternal;
@@ -448,13 +457,21 @@ declare class Transport {
448
457
  setLoopSeconds(enabled: boolean, startSec: number, endSec: number): void;
449
458
  /** Convenience — sets loop in samples */
450
459
  setLoopSamples(enabled: boolean, startSample: Sample, endSample: Sample): void;
451
- setTempo(bpm: number, atTick?: Tick, options?: SetTempoOptions): void;
460
+ /** Returns true when the tempo was applied, false when a defaulted (no
461
+ * atTick) write was refused because the tempo map has multiple entries —
462
+ * pass an explicit atTick to modify a multi-entry map (#407). */
463
+ setTempo(bpm: number, atTick?: Tick, options?: SetTempoOptions): boolean;
452
464
  getTempo(atTick?: Tick): number;
453
465
  setMeter(numerator: number, denominator: number, atTick?: Tick): void;
454
466
  getMeter(atTick?: Tick): MeterSignature;
455
467
  removeMeter(atTick: Tick): void;
456
468
  clearMeters(): void;
457
469
  clearTempos(): void;
470
+ /** Remove the tempo entry at exactly `atTick` (tick 0 is permanent — a
471
+ * no-op, like removeMeter's initial entry). Mirrors setTempo's loop-cache
472
+ * invalidation and event; the emitted bpm is the tempo now in force at
473
+ * the removed position. */
474
+ removeTempo(atTick: Tick): void;
458
475
  barToTick(bar: number): Tick;
459
476
  tickToBar(tick: Tick): number;
460
477
  /** Convert transport time (seconds) to tick position, using the tempo map. */
@@ -519,7 +536,7 @@ declare class NativePlayoutAdapter implements PlayoutAdapter {
519
536
  setCountInMode(mode: CountInMode): void;
520
537
  setRecording(recording: boolean): void;
521
538
  isCountingIn(): boolean;
522
- setTempo(bpm: number, atTick?: number): void;
539
+ setTempo(bpm: number, atTick?: number): boolean;
523
540
  setMeter(numerator: number, denominator: number, atTick?: number): void;
524
541
  ticksToSeconds(tick: number): number;
525
542
  secondsToTicks(seconds: number): number;
package/dist/index.d.ts CHANGED
@@ -147,12 +147,21 @@ declare class TempoMap {
147
147
  * in secondsToTicks) — reject it at the boundary instead. */
148
148
  private static _validateBpm;
149
149
  getTempo(atTick?: Tick): number;
150
+ /** Number of tempo entries in the map. Always >= 1 — the tick-0 entry is
151
+ * permanent. Used by Transport.setTempo to detect multi-entry maps. */
152
+ get entryCount(): number;
150
153
  setTempo(bpm: number, atTick?: Tick, options?: SetTempoOptions): void;
151
154
  ticksToSeconds(ticks: Tick): number;
152
155
  secondsToTicks(seconds: number): Tick;
153
156
  beatsToSeconds(beats: number): number;
154
157
  secondsToBeats(seconds: number): number;
155
158
  clearTempos(): void;
159
+ /** Remove the tempo entry at exactly `atTick`, if one exists. The tick-0
160
+ * entry is permanent (a map must always have a tempo) — removing it is a
161
+ * no-op, matching removeMeter's treatment of the initial meter. The
162
+ * seconds cache is recomputed from the removal point, the same partial
163
+ * update setTempo uses. */
164
+ removeTempo(atTick: Tick): void;
156
165
  /** Get the interpolated BPM at a tick position */
157
166
  private _getTempoAt;
158
167
  private _ticksToSecondsInternal;
@@ -448,13 +457,21 @@ declare class Transport {
448
457
  setLoopSeconds(enabled: boolean, startSec: number, endSec: number): void;
449
458
  /** Convenience — sets loop in samples */
450
459
  setLoopSamples(enabled: boolean, startSample: Sample, endSample: Sample): void;
451
- setTempo(bpm: number, atTick?: Tick, options?: SetTempoOptions): void;
460
+ /** Returns true when the tempo was applied, false when a defaulted (no
461
+ * atTick) write was refused because the tempo map has multiple entries —
462
+ * pass an explicit atTick to modify a multi-entry map (#407). */
463
+ setTempo(bpm: number, atTick?: Tick, options?: SetTempoOptions): boolean;
452
464
  getTempo(atTick?: Tick): number;
453
465
  setMeter(numerator: number, denominator: number, atTick?: Tick): void;
454
466
  getMeter(atTick?: Tick): MeterSignature;
455
467
  removeMeter(atTick: Tick): void;
456
468
  clearMeters(): void;
457
469
  clearTempos(): void;
470
+ /** Remove the tempo entry at exactly `atTick` (tick 0 is permanent — a
471
+ * no-op, like removeMeter's initial entry). Mirrors setTempo's loop-cache
472
+ * invalidation and event; the emitted bpm is the tempo now in force at
473
+ * the removed position. */
474
+ removeTempo(atTick: Tick): void;
458
475
  barToTick(bar: number): Tick;
459
476
  tickToBar(tick: Tick): number;
460
477
  /** Convert transport time (seconds) to tick position, using the tempo map. */
@@ -519,7 +536,7 @@ declare class NativePlayoutAdapter implements PlayoutAdapter {
519
536
  setCountInMode(mode: CountInMode): void;
520
537
  setRecording(recording: boolean): void;
521
538
  isCountingIn(): boolean;
522
- setTempo(bpm: number, atTick?: number): void;
539
+ setTempo(bpm: number, atTick?: number): boolean;
523
540
  setMeter(numerator: number, denominator: number, atTick?: number): void;
524
541
  ticksToSeconds(tick: number): number;
525
542
  secondsToTicks(seconds: number): number;
package/dist/index.js CHANGED
@@ -249,7 +249,7 @@ var SampleTimeline = class {
249
249
  "[waveform-playlist] SampleTimeline: tempoMap not set \u2014 call setTempoMap() first"
250
250
  );
251
251
  }
252
- return this._tempoMap.secondsToTicks(samples / this._sampleRate);
252
+ return Math.round(this._tempoMap.secondsToTicks(samples / this._sampleRate));
253
253
  }
254
254
  };
255
255
 
@@ -280,6 +280,11 @@ var TempoMap = class _TempoMap {
280
280
  getTempo(atTick = 0) {
281
281
  return this._getTempoAt(atTick);
282
282
  }
283
+ /** Number of tempo entries in the map. Always >= 1 — the tick-0 entry is
284
+ * permanent. Used by Transport.setTempo to detect multi-entry maps. */
285
+ get entryCount() {
286
+ return this._entries.length;
287
+ }
283
288
  setTempo(bpm, atTick = 0, options) {
284
289
  _TempoMap._validateBpm(bpm);
285
290
  const interpolation = options?.interpolation ?? "step";
@@ -358,6 +363,18 @@ var TempoMap = class _TempoMap {
358
363
  const first = this._entries[0];
359
364
  this._entries = [{ tick: 0, bpm: first.bpm, interpolation: "step", secondsAtTick: 0 }];
360
365
  }
366
+ /** Remove the tempo entry at exactly `atTick`, if one exists. The tick-0
367
+ * entry is permanent (a map must always have a tempo) — removing it is a
368
+ * no-op, matching removeMeter's treatment of the initial meter. The
369
+ * seconds cache is recomputed from the removal point, the same partial
370
+ * update setTempo uses. */
371
+ removeTempo(atTick) {
372
+ if (atTick === 0) return;
373
+ const i = this._entries.findIndex((e) => e.tick === atTick);
374
+ if (i === -1) return;
375
+ this._entries = [...this._entries.slice(0, i), ...this._entries.slice(i + 1)];
376
+ this._recomputeCache(i);
377
+ }
361
378
  /** Get the interpolated BPM at a tick position */
362
379
  _getTempoAt(atTick) {
363
380
  const entryIndex = this._entryIndexAt(atTick);
@@ -683,6 +700,11 @@ var MeterMap = class {
683
700
  "[waveform-playlist] MeterMap: denominator must be a power of 2 (1-32), got " + denominator
684
701
  );
685
702
  }
703
+ if (!Number.isInteger(this._ppqn * 4 / denominator)) {
704
+ throw new Error(
705
+ "[waveform-playlist] MeterMap: ppqn (" + this._ppqn + ") * 4 is not divisible by denominator (" + denominator + ") \u2014 bar boundaries would fall on fractional ticks"
706
+ );
707
+ }
686
708
  }
687
709
  };
688
710
 
@@ -1526,12 +1548,22 @@ var _Transport = class _Transport {
1526
1548
  this._emit("loop");
1527
1549
  }
1528
1550
  // --- Tempo ---
1551
+ /** Returns true when the tempo was applied, false when a defaulted (no
1552
+ * atTick) write was refused because the tempo map has multiple entries —
1553
+ * pass an explicit atTick to modify a multi-entry map (#407). */
1529
1554
  setTempo(bpm, atTick, options) {
1555
+ if (atTick === void 0 && this._tempoMap.entryCount > 1) {
1556
+ console.warn(
1557
+ "[waveform-playlist] Transport.setTempo: refusing defaulted tick-0 write of " + bpm + " BPM \u2014 the tempo map has " + this._tempoMap.entryCount + " entries. Pass an explicit atTick to modify a multi-entry tempo map."
1558
+ );
1559
+ return false;
1560
+ }
1530
1561
  this._tempoMap.setTempo(bpm, atTick, options);
1531
1562
  if (this._loopEnabled) {
1532
1563
  this._loopStartSeconds = this._tempoMap.ticksToSeconds(this._loopStartTick);
1533
1564
  }
1534
1565
  this._emit("tempochange", { bpm, atTick: atTick ?? 0 });
1566
+ return true;
1535
1567
  }
1536
1568
  getTempo(atTick) {
1537
1569
  return this._tempoMap.getTempo(atTick);
@@ -1569,6 +1601,17 @@ var _Transport = class _Transport {
1569
1601
  }
1570
1602
  this._emit("tempochange", { bpm: this._tempoMap.getTempo(), atTick: 0 });
1571
1603
  }
1604
+ /** Remove the tempo entry at exactly `atTick` (tick 0 is permanent — a
1605
+ * no-op, like removeMeter's initial entry). Mirrors setTempo's loop-cache
1606
+ * invalidation and event; the emitted bpm is the tempo now in force at
1607
+ * the removed position. */
1608
+ removeTempo(atTick) {
1609
+ this._tempoMap.removeTempo(atTick);
1610
+ if (this._loopEnabled) {
1611
+ this._loopStartSeconds = this._tempoMap.ticksToSeconds(this._loopStartTick);
1612
+ }
1613
+ this._emit("tempochange", { bpm: this._tempoMap.getTempo(atTick), atTick });
1614
+ }
1572
1615
  barToTick(bar) {
1573
1616
  return this._meterMap.barToTick(bar);
1574
1617
  }
@@ -1941,7 +1984,7 @@ var NativePlayoutAdapter = class {
1941
1984
  return this._transport.isCountingIn();
1942
1985
  }
1943
1986
  setTempo(bpm, atTick) {
1944
- this._transport.setTempo(bpm, atTick !== void 0 ? atTick : void 0);
1987
+ return this._transport.setTempo(bpm, atTick !== void 0 ? atTick : void 0);
1945
1988
  }
1946
1989
  setMeter(numerator, denominator, atTick) {
1947
1990
  this._transport.setMeter(