tone 14.9.13 → 14.9.15

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
@@ -1,13 +1,11 @@
1
- Tone.js
2
- =========
1
+ # Tone.js
3
2
 
4
3
  [![codecov](https://codecov.io/gh/Tonejs/Tone.js/branch/dev/graph/badge.svg)](https://codecov.io/gh/Tonejs/Tone.js)
5
4
 
6
-
7
5
  Tone.js is a Web Audio framework for creating interactive music in the browser. The architecture of Tone.js aims to be familiar to both musicians and audio programmers creating web-based audio applications. On the high-level, Tone offers common DAW (digital audio workstation) features like a global transport for synchronizing and scheduling events as well as prebuilt synths and effects. Additionally, Tone provides high-performance building blocks to create your own synthesizers, effects, and complex control signals.
8
6
 
9
- * [API](https://tonejs.github.io/docs/)
10
- * [Examples](https://tonejs.github.io/examples/)
7
+ - [API](https://tonejs.github.io/docs/)
8
+ - [Examples](https://tonejs.github.io/examples/)
11
9
 
12
10
  # Installation
13
11
 
@@ -21,7 +19,7 @@ npm install tone@next // Or, alternatively, use the 'next' version
21
19
  Add Tone.js to a project using the JavaScript `import` syntax:
22
20
 
23
21
  ```js
24
- import * as Tone from 'tone';
22
+ import * as Tone from "tone";
25
23
  ```
26
24
 
27
25
  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.
@@ -40,46 +38,46 @@ const synth = new Tone.Synth().toDestination();
40
38
  synth.triggerAttackRelease("C4", "8n");
41
39
  ```
42
40
 
43
- #### Tone.Synth
41
+ ## Tone.Synth
44
42
 
45
43
  `Tone.Synth` is a basic synthesizer with a single oscillator and an ADSR envelope.
46
44
 
47
- #### triggerAttack / triggerRelease
45
+ ### triggerAttack / triggerRelease
48
46
 
49
47
  `triggerAttack` starts the note (the amplitude is rising), and `triggerRelease` is when the amplitude is going back to 0 (i.e. **note off**).
50
48
 
51
49
  ```javascript
52
50
  const synth = new Tone.Synth().toDestination();
53
- const now = Tone.now()
51
+ const now = Tone.now();
54
52
  // trigger the attack immediately
55
- synth.triggerAttack("C4", now)
53
+ synth.triggerAttack("C4", now);
56
54
  // wait one second before triggering the release
57
- synth.triggerRelease(now + 1)
55
+ synth.triggerRelease(now + 1);
58
56
  ```
59
57
 
60
- #### triggerAttackRelease
58
+ ### triggerAttackRelease
61
59
 
62
60
  `triggerAttackRelease` is a combination of `triggerAttack` and `triggerRelease`
63
61
 
64
- The first argument to the note which can either be a frequency in hertz (like `440`) or as "pitch-octave" notation (like `"D#2"`).
62
+ The first argument to the note which can either be a frequency in hertz (like `440`) or as "pitch-octave" notation (like `"D#2"`).
65
63
 
66
- The second argument is the duration that the note is held. This value can either be in seconds, or as a [tempo-relative value](https://github.com/Tonejs/Tone.js/wiki/Time).
64
+ The second argument is the duration that the note is held. This value can either be in seconds, or as a [tempo-relative value](https://github.com/Tonejs/Tone.js/wiki/Time).
67
65
 
68
66
  The third (optional) argument of `triggerAttackRelease` is _when_ along the AudioContext time the note should play. It can be used to schedule events in the future.
69
67
 
70
68
  ```javascript
71
69
  const synth = new Tone.Synth().toDestination();
72
- const now = Tone.now()
73
- synth.triggerAttackRelease("C4", "8n", now)
74
- synth.triggerAttackRelease("E4", "8n", now + 0.5)
75
- synth.triggerAttackRelease("G4", "8n", now + 1)
70
+ const now = Tone.now();
71
+ synth.triggerAttackRelease("C4", "8n", now);
72
+ synth.triggerAttackRelease("E4", "8n", now + 0.5);
73
+ synth.triggerAttackRelease("G4", "8n", now + 1);
76
74
  ```
77
75
 
78
- #### Time
76
+ ## Time
79
77
 
80
78
  Web Audio has advanced, sample accurate scheduling capabilities. The AudioContext time is what the Web Audio API uses to schedule events, starts at 0 when the page loads and counts up in **seconds**.
81
79
 
82
- `Tone.now()` gets the current time of the AudioContext.
80
+ `Tone.now()` gets the current time of the AudioContext.
83
81
 
84
82
  ```javascript
85
83
  setInterval(() => console.log(Tone.now()), 100);
@@ -91,21 +89,21 @@ Tone.js abstracts away the AudioContext time. Instead of defining all values in
91
89
 
92
90
  # Starting Audio
93
91
 
94
- **IMPORTANT**: Browsers will not play _any_ audio until a user clicks something (like a play button). Run your Tone.js code only after calling `Tone.start()` from a event listener which is triggered by a user action such as "click" or "keydown".
92
+ **IMPORTANT**: Browsers will not play _any_ audio until a user clicks something (like a play button). Run your Tone.js code only after calling `Tone.start()` from a event listener which is triggered by a user action such as "click" or "keydown".
95
93
 
96
94
  `Tone.start()` returns a promise, the audio will be ready only after that promise is resolved. Scheduling or playing audio before the AudioContext is running will result in silence or incorrect scheduling.
97
95
 
98
96
  ```javascript
99
97
  //attach a click listener to a play button
100
- document.querySelector('button')?.addEventListener('click', async () => {
101
- await Tone.start()
102
- console.log('audio is ready')
103
- })
104
- ```
98
+ document.querySelector("button")?.addEventListener("click", async () => {
99
+ await Tone.start();
100
+ console.log("audio is ready");
101
+ });
102
+ ```
105
103
 
106
104
  # Scheduling
107
105
 
108
- ### Transport
106
+ ## Transport
109
107
 
110
108
  `Tone.getTransport()` returns the main timekeeper. Unlike the AudioContext clock, it can be started, stopped, looped and adjusted on the fly. You can think of it like the arrangement view in a Digital Audio Workstation.
111
109
 
@@ -116,72 +114,76 @@ Multiple events and parts can be arranged and synchronized along the Transport.
116
114
  const synthA = new Tone.FMSynth().toDestination();
117
115
  const synthB = new Tone.AMSynth().toDestination();
118
116
  //play a note every quarter-note
119
- const loopA = new Tone.Loop(time => {
117
+ const loopA = new Tone.Loop((time) => {
120
118
  synthA.triggerAttackRelease("C2", "8n", time);
121
119
  }, "4n").start(0);
122
120
  //play another note every off quarter-note, by starting it "8n"
123
- const loopB = new Tone.Loop(time => {
121
+ const loopB = new Tone.Loop((time) => {
124
122
  synthB.triggerAttackRelease("C4", "8n", time);
125
123
  }, "4n").start("8n");
126
124
  // all loops start when the Transport is started
127
- Tone.getTransport().start()
125
+ Tone.getTransport().start();
126
+ // ramp up to 800 bpm over 10 seconds
127
+ Tone.getTransport().bpm.rampTo(800, 10);
128
128
  ```
129
129
 
130
130
  Since Javascript callbacks are **not precisely timed**, the sample-accurate time of the event is passed into the callback function. **Use this time value to schedule the events**.
131
131
 
132
132
  # Instruments
133
133
 
134
- There are numerous synths to choose from including `Tone.FMSynth`, `Tone.AMSynth` and `Tone.NoiseSynth`.
134
+ There are numerous synths to choose from including `Tone.FMSynth`, `Tone.AMSynth` and `Tone.NoiseSynth`.
135
135
 
136
- All of these instruments are **monophonic** (single voice) which means that they can only play one note at a time.
136
+ All of these instruments are **monophonic** (single voice) which means that they can only play one note at a time.
137
137
 
138
- To create a **polyphonic** synthesizer, use `Tone.PolySynth`, which accepts a monophonic synth as its first parameter and automatically handles the note allocation so you can pass in multiple notes. The API is similar to the monophonic synths, except `triggerRelease` must be given a note or array of notes.
138
+ To create a **polyphonic** synthesizer, use `Tone.PolySynth`, which accepts a monophonic synth as its first parameter and automatically handles the note allocation so you can pass in multiple notes. The API is similar to the monophonic synths, except `triggerRelease` must be given a note or array of notes.
139
139
 
140
140
  ```javascript
141
- //pass in some initial values for the filter and filter envelope
142
141
  const synth = new Tone.PolySynth(Tone.Synth).toDestination();
143
- const now = Tone.now()
142
+ const now = Tone.now();
144
143
  synth.triggerAttack("D4", now);
145
144
  synth.triggerAttack("F4", now + 0.5);
146
145
  synth.triggerAttack("A4", now + 1);
147
- synth.triggerAttack("C4", now + 1.5);
148
- synth.triggerAttack("E4", now + 2);
149
- synth.triggerRelease(["D4", "F4", "A4", "C4", "E4"], now + 4);
146
+ synth.triggerAttack("C5", now + 1.5);
147
+ synth.triggerAttack("E5", now + 2);
148
+ synth.triggerRelease(["D4", "F4", "A4", "C5", "E5"], now + 4);
150
149
  ```
151
150
 
152
151
  # Samples
153
152
 
154
- Sound generation is not limited to synthesized sounds. You can also load a sample and play that back in a number of ways. `Tone.Player` is one way to load and play back an audio file.
153
+ Sound generation is not limited to synthesized sounds. You can also load a sample and play that back in a number of ways. `Tone.Player` is one way to load and play back an audio file.
155
154
 
156
155
  ```javascript
157
- const player = new Tone.Player("https://tonejs.github.io/audio/berklee/gong_1.mp3").toDestination();
156
+ const player = new Tone.Player(
157
+ "https://tonejs.github.io/audio/berklee/gong_1.mp3"
158
+ ).toDestination();
158
159
  Tone.loaded().then(() => {
159
160
  player.start();
160
161
  });
161
162
  ```
162
163
 
163
- `Tone.loaded()` returns a promise which resolves when _all_ audio files are loaded. It's a helpful shorthand instead of waiting on each individual audio buffer's `onload` event to resolve.
164
+ `Tone.loaded()` returns a promise which resolves when _all_ audio files are loaded. It's a helpful shorthand instead of waiting on each individual audio buffer's `onload` event to resolve.
164
165
 
165
- ## Sampler
166
+ ## Tone.Sampler
166
167
 
167
- Multiple samples can also be combined into an instrument. If you have audio files organized by note, `Tone.Sampler` will pitch shift the samples to fill in gaps between notes. So for example, if you only have every 3rd note on a piano sampled, you could turn that into a full piano sample.
168
+ Multiple samples can also be combined into an instrument. If you have audio files organized by note, `Tone.Sampler` will pitch shift the samples to fill in gaps between notes. So for example, if you only have every 3rd note on a piano sampled, you could turn that into a full piano sample.
168
169
 
169
170
  Unlike the other synths, Tone.Sampler is polyphonic so doesn't need to be passed into Tone.PolySynth
170
171
 
171
172
  ```javascript
172
173
  const sampler = new Tone.Sampler({
173
174
  urls: {
174
- "C4": "C4.mp3",
175
+ C4: "C4.mp3",
175
176
  "D#4": "Ds4.mp3",
176
177
  "F#4": "Fs4.mp3",
177
- "A4": "A4.mp3",
178
+ A4: "A4.mp3",
178
179
  },
180
+ release: 1,
179
181
  baseUrl: "https://tonejs.github.io/audio/salamander/",
180
182
  }).toDestination();
181
183
 
182
184
  Tone.loaded().then(() => {
183
- sampler.triggerAttackRelease(["Eb4", "G4", "Bb4"], 0.5);
184
- })
185
+ sampler.triggerAttackRelease(["Eb4", "G4", "Bb4"], 4);
186
+ });
185
187
  ```
186
188
 
187
189
  # Effects
@@ -193,22 +195,35 @@ const player = new Tone.Player({
193
195
  url: "https://tonejs.github.io/audio/berklee/gurgling_theremin_1.mp3",
194
196
  loop: true,
195
197
  autostart: true,
196
- })
198
+ });
197
199
  //create a distortion effect
198
200
  const distortion = new Tone.Distortion(0.4).toDestination();
199
201
  //connect a player to the distortion
200
202
  player.connect(distortion);
201
203
  ```
202
204
 
203
- The connection routing is very flexible. For example, you can connect multiple sources to the same effect and then route the effect through a network of other effects either serially or in parallel.
205
+ The connection routing is flexible, connections can run serially or in parallel.
206
+
207
+ ```javascript
208
+ const player = new Tone.Player({
209
+ url: "https://tonejs.github.io/audio/drum-samples/loops/ominous.mp3",
210
+ autostart: true,
211
+ });
212
+ const filter = new Tone.Filter(400, "lowpass").toDestination();
213
+ const feedbackDelay = new Tone.FeedbackDelay(0.125, 0.5).toDestination();
214
+
215
+ // connect the player to the feedback delay and filter in parallel
216
+ player.connect(filter);
217
+ player.connect(feedbackDelay);
218
+ ```
204
219
 
205
- `Tone.Gain` is very useful in creating complex routing.
220
+ Multiple nodes can be connected to the same input enabling sources to share effects. `Tone.Gain` is useful utility node for creating complex routing.
206
221
 
207
222
  # Signals
208
223
 
209
224
  Like the underlying Web Audio API, Tone.js is built with audio-rate signal control over nearly everything. This is a powerful feature which allows for sample-accurate synchronization and scheduling of parameters.
210
225
 
211
- `Signal` properties have a few built in methods for creating automation curves.
226
+ `Signal` properties have a few built in methods for creating automation curves.
212
227
 
213
228
  For example, the `frequency` parameter on `Oscillator` is a Signal so you can create a smooth ramp from one frequency to another.
214
229
 
@@ -216,8 +231,10 @@ For example, the `frequency` parameter on `Oscillator` is a Signal so you can cr
216
231
  const osc = new Tone.Oscillator().toDestination();
217
232
  // start at "C4"
218
233
  osc.frequency.value = "C4";
219
- // ramp to "C5" over 2 seconds
220
- osc.frequency.rampTo("C5", 2)
234
+ // ramp to "C2" over 2 seconds
235
+ osc.frequency.rampTo("C2", 2);
236
+ // start the oscillator for 2 seconds
237
+ osc.start().stop("+3");
221
238
  ```
222
239
 
223
240
  # AudioContext
@@ -230,13 +247,13 @@ To use MIDI files, you'll first need to convert them into a JSON format which To
230
247
 
231
248
  # Performance
232
249
 
233
- Tone.js makes extensive use of the native Web Audio Nodes such as the GainNode and WaveShaperNode for all signal processing, which enables Tone.js to work well on both desktop and mobile browsers.
250
+ Tone.js makes extensive use of the native Web Audio Nodes such as the GainNode and WaveShaperNode for all signal processing, which enables Tone.js to work well on both desktop and mobile browsers.
234
251
 
235
252
  [This wiki](https://github.com/Tonejs/Tone.js/wiki/Performance) article has some suggestions related to performance for best practices.
236
253
 
237
254
  # Testing
238
255
 
239
- Tone.js runs an extensive test suite using [mocha](https://mochajs.org/) and [chai](http://chaijs.com/) with nearly 100% coverage. Passing builds on the 'dev' branch are published on npm as `tone@next`.
256
+ Tone.js runs an extensive test suite using [mocha](https://mochajs.org/) and [chai](http://chaijs.com/) with nearly 100% coverage. Passing builds on the 'dev' branch are published on npm as `tone@next`.
240
257
 
241
258
  # Contributing
242
259
 
@@ -246,9 +263,9 @@ If you have questions (or answers) that are not necessarily bugs/issues, please
246
263
 
247
264
  # References and Inspiration
248
265
 
249
- * [Many of Chris Wilson's Repositories](https://github.com/cwilso)
250
- * [Many of Mohayonao's Repositories](https://github.com/mohayonao)
251
- * [The Spec](http://webaudio.github.io/web-audio-api/)
252
- * [Sound on Sound - Synth Secrets](http://www.soundonsound.com/sos/may99/articles/synthsec.htm)
253
- * [Miller Puckette - Theory and Techniques of Electronic Music](http://msp.ucsd.edu/techniques.htm)
254
- * [standardized-audio-context](https://github.com/chrisguttandin/standardized-audio-context)
266
+ - [Many of Chris Wilson's Repositories](https://github.com/cwilso)
267
+ - [Many of Mohayonao's Repositories](https://github.com/mohayonao)
268
+ - [The Spec](http://webaudio.github.io/web-audio-api/)
269
+ - [Sound on Sound - Synth Secrets](http://www.soundonsound.com/sos/may99/articles/synthsec.htm)
270
+ - [Miller Puckette - Theory and Techniques of Electronic Music](http://msp.ucsd.edu/techniques.htm)
271
+ - [standardized-audio-context](https://github.com/chrisguttandin/standardized-audio-context)
package/Tone/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { getContext, setContext } from "./core/Global";
2
- import { BaseContext } from "./core/context/BaseContext";
2
+ import { Context } from "./core/context/Context";
3
3
  export * from "./classes";
4
4
  export * from "./version";
5
5
  import { getContext } from "./core/Global";
@@ -10,7 +10,7 @@ export { supported } from "./core/context/AudioContext";
10
10
 
11
11
  /**
12
12
  * The current audio context time of the global {@link BaseContext}.
13
- * @see {@link BaseContext.now}
13
+ * @see {@link Context.now}
14
14
  * @category Core
15
15
  */
16
16
  export function now(): Seconds {
@@ -18,8 +18,8 @@ export function now(): Seconds {
18
18
  }
19
19
 
20
20
  /**
21
- * The current audio context time of the global {@link BaseContext} without the {@link BaseContext.lookAhead}
22
- * @see {@link BaseContext.immediate}
21
+ * The current audio context time of the global {@link Context} without the {@link Context.lookAhead}
22
+ * @see {@link Context.immediate}
23
23
  * @category Core
24
24
  */
25
25
  export function immediate(): Seconds {
@@ -100,7 +100,7 @@ export function getDraw(): import("./core/util/Draw").DrawClass {
100
100
 
101
101
  /**
102
102
  * A reference to the global context
103
- * @see {@link BaseContext}
103
+ * @see {@link Context}
104
104
  * @deprecated Use {@link getContext} instead
105
105
  */
106
106
  export const context = getContext();
package/Tone/version.ts CHANGED
@@ -1 +1 @@
1
- export const version: string = "14.9.13";
1
+ export const version: string = "14.9.15";