tone 14.8.45 → 14.8.47

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 CHANGED
@@ -12,22 +12,24 @@ Tone.js is a Web Audio framework for creating interactive music in the browser.
12
12
 
13
13
  # Installation
14
14
 
15
- To install the latest stable version.
15
+ There are two ways to incorporate Tone.js into a proejct. First, it can be installed locally into a project using `npm`:
16
16
 
17
17
  ```bash
18
- npm install tone
18
+ npm install tone // Install the latest stable version
19
+ npm install tone@next // Or, alternatively, use the 'next' version
19
20
  ```
20
21
 
21
- Or to install the 'next' version
22
+ Add Tone.js to a project using the JavaScript `import` syntax:
22
23
 
23
- ```bash
24
- npm install tone@next
24
+ ```js
25
+ import * as Tone from 'tone';
25
26
  ```
26
27
 
27
- To import Tone.js:
28
+ Tone.js is also hosted at unpkg.com. It can be added directly within an HTML document, as long as it precedes any project scripts. [See the example here](https://github.com/Tonejs/Tone.js/blob/master/examples/simpleHtml.html) for more details.
28
29
 
29
- ```js
30
- import * as Tone from 'tone'
30
+ ```html
31
+ <script src="http://unpkg.com/tone"></script>
32
+ <script src="myScript.js"></script>
31
33
  ```
32
34
 
33
35
  # Hello Tone
@@ -4,7 +4,7 @@ import { MeterBase, MeterBaseOptions } from "./MeterBase";
4
4
  export type DCMeterOptions = MeterBaseOptions;
5
5
 
6
6
  /**
7
- * DCMeter gets the raw value of the input signal at the current time.
7
+ * DCMeter gets the raw value of the input signal at the current time. See also {@link Meter}.
8
8
  *
9
9
  * @example
10
10
  * const meter = new Tone.DCMeter();
@@ -14,6 +14,9 @@ export interface MeterOptions extends MeterBaseOptions {
14
14
  /**
15
15
  * Meter gets the [RMS](https://en.wikipedia.org/wiki/Root_mean_square)
16
16
  * of an input signal. It can also get the raw value of the input signal.
17
+ * Setting `normalRange` to `true` will covert the output to a range of
18
+ * 0-1. See an example using a graphical display
19
+ * [here](https://tonejs.github.io/examples/meter). See also {@link DCMeter}.
17
20
  *
18
21
  * @example
19
22
  * const meter = new Tone.Meter();
@@ -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;
@@ -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.45";
1
+ export const version: string = "14.8.47";