tone 14.8.44 → 14.8.46

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.
@@ -141,7 +141,7 @@ export class Envelope extends ToneAudioNode<EnvelopeOptions> {
141
141
  /**
142
142
  * The automation curve type for the decay
143
143
  */
144
- private _decayCurve!: BasicEnvelopeCurve;
144
+ private _decayCurve!: InternalEnvelopeCurve;
145
145
 
146
146
  /**
147
147
  * The automation curve type for the release
@@ -322,12 +322,11 @@ export class Envelope extends ToneAudioNode<EnvelopeOptions> {
322
322
  * env.triggerAttack();
323
323
  * }, 1, 1);
324
324
  */
325
- get decayCurve(): BasicEnvelopeCurve {
326
- return this._decayCurve;
325
+ get decayCurve(): EnvelopeCurve {
326
+ return this._getCurve(this._decayCurve, "Out");
327
327
  }
328
328
  set decayCurve(curve) {
329
- assert(["linear", "exponential"].some(c => c === curve), `Invalid envelope curve: ${curve}`);
330
- this._decayCurve = curve;
329
+ this._setCurve("_decayCurve", "Out", curve);
331
330
  }
332
331
 
333
332
  /**
@@ -475,7 +474,7 @@ export class Envelope extends ToneAudioNode<EnvelopeOptions> {
475
474
  }
476
475
 
477
476
  /**
478
- * Render the envelope curve to an array of the given length.
477
+ * Render the envelope curve to an array of the given length.
479
478
  * Good for visualizing the envelope curve. Rescales the duration of the
480
479
  * envelope to fit the length.
481
480
  */
@@ -1,6 +1,8 @@
1
1
  import { TimeClass } from "../../core/type/Time";
2
2
  import { PlaybackState } from "../../core/util/StateTimeline";
3
3
  import { TimelineValue } from "../../core/util/TimelineValue";
4
+ import { ToneAudioNode } from "../../core/context/ToneAudioNode";
5
+ import { Pow } from "../../signal/Pow";
4
6
  import { Signal } from "../../signal/Signal";
5
7
  import {
6
8
  onContextClose,
@@ -58,7 +60,7 @@ type TransportEventNames =
58
60
  interface SyncedSignalEvent {
59
61
  signal: Signal;
60
62
  initial: number;
61
- ratio: Gain;
63
+ nodes: ToneAudioNode<any>[];
62
64
  }
63
65
 
64
66
  type TransportCallback = (time: Seconds) => void;
@@ -582,7 +584,7 @@ export class Transport
582
584
  }
583
585
 
584
586
  /**
585
- * The Transport's position in seconds
587
+ * The Transport's position in seconds.
586
588
  * Setting the value will jump to that position right away.
587
589
  */
588
590
  get seconds(): Seconds {
@@ -611,7 +613,7 @@ export class Transport
611
613
  }
612
614
 
613
615
  /**
614
- * The transports current tick position.
616
+ * The Transport's current tick position.
615
617
  */
616
618
  get ticks(): Ticks {
617
619
  return this._clock.ticks;
@@ -707,25 +709,45 @@ export class Transport
707
709
  * Otherwise it will be computed based on their current values.
708
710
  */
709
711
  syncSignal(signal: Signal<any>, ratio?: number): this {
712
+ const now = this.now();
713
+ let source : TickParam<"bpm"> | ToneAudioNode<any> = this.bpm;
714
+ let sourceValue = 1 / (60 / source.getValueAtTime(now) / this.PPQ);
715
+ let nodes : ToneAudioNode<any>[] = [];
716
+ // If the signal is in the time domain, sync it to the reciprocal of
717
+ // the tempo instead of the tempo.
718
+ if (signal.units === "time") {
719
+ // The input to Pow should be in the range [1 / 4096, 1], where
720
+ // where 4096 is half of the buffer size of Pow's waveshaper.
721
+ // Pick a scaling factor based on the initial tempo that ensures
722
+ // that the initial input is in this range, while leaving room for
723
+ // tempo changes.
724
+ const scaleFactor = 1 / 64 / sourceValue;
725
+ const scaleBefore = new Gain(scaleFactor);
726
+ const reciprocal = new Pow(-1);
727
+ const scaleAfter = new Gain(scaleFactor);
728
+ // @ts-ignore
729
+ source.chain(scaleBefore, reciprocal, scaleAfter);
730
+ source = scaleAfter;
731
+ sourceValue = 1 / sourceValue;
732
+ nodes = [scaleBefore, reciprocal, scaleAfter];
733
+ }
710
734
  if (!ratio) {
711
735
  // get the sync ratio
712
- const now = this.now();
713
736
  if (signal.getValueAtTime(now) !== 0) {
714
- const bpm = this.bpm.getValueAtTime(now);
715
- const computedFreq = 1 / (60 / bpm / this.PPQ);
716
- ratio = signal.getValueAtTime(now) / computedFreq;
737
+ ratio = signal.getValueAtTime(now) / sourceValue;
717
738
  } else {
718
739
  ratio = 0;
719
740
  }
720
741
  }
721
742
  const ratioSignal = new Gain(ratio);
722
743
  // @ts-ignore
723
- this.bpm.connect(ratioSignal);
744
+ source.connect(ratioSignal);
724
745
  // @ts-ignore
725
746
  ratioSignal.connect(signal._param);
747
+ nodes.push(ratioSignal);
726
748
  this._syncedSignals.push({
727
749
  initial: signal.value,
728
- ratio: ratioSignal,
750
+ nodes: nodes,
729
751
  signal,
730
752
  });
731
753
  signal.value = 0;
@@ -740,7 +762,7 @@ export class Transport
740
762
  for (let i = this._syncedSignals.length - 1; i >= 0; i--) {
741
763
  const syncedSignal = this._syncedSignals[i];
742
764
  if (syncedSignal.signal === signal) {
743
- syncedSignal.ratio.dispose();
765
+ syncedSignal.nodes.forEach((node) => node.dispose());
744
766
  syncedSignal.signal.value = syncedSignal.initial;
745
767
  this._syncedSignals.splice(i, 1);
746
768
  }
@@ -480,6 +480,15 @@ describe("Signal", () => {
480
480
  }, 10);
481
481
  });
482
482
 
483
+ it("keeps the ratio of a time signal when the bpm changes", () => {
484
+ return ConstantOutput(({ transport }) => {
485
+ transport.bpm.value = 120;
486
+ const sig = new Signal("4n", "time").toDestination();
487
+ transport.syncSignal(sig);
488
+ transport.bpm.value = 240;
489
+ }, 0.25);
490
+ });
491
+
483
492
  it("outputs 0 when the signal is 0", () => {
484
493
  return ConstantOutput(({ transport }) => {
485
494
  transport.bpm.value = 120;
package/Tone/version.ts CHANGED
@@ -1 +1 @@
1
- export const version: string = "14.8.44";
1
+ export const version: string = "14.8.46";