tone 15.2.13 → 15.3.1

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.
Files changed (63) hide show
  1. package/Tone/core/clock/Transport.test.ts +60 -60
  2. package/Tone/core/clock/Transport.ts +4 -4
  3. package/Tone/core/clock/TransportEvent.test.ts +4 -4
  4. package/Tone/core/clock/TransportEvent.ts +2 -2
  5. package/Tone/core/clock/TransportRepeatEvent.test.ts +4 -4
  6. package/Tone/core/clock/TransportRepeatEvent.ts +1 -1
  7. package/Tone/core/context/BaseContext.ts +4 -4
  8. package/Tone/core/context/Context.test.ts +8 -8
  9. package/Tone/core/context/Context.ts +14 -10
  10. package/Tone/core/context/Destination.test.ts +2 -2
  11. package/Tone/core/context/Destination.ts +3 -3
  12. package/Tone/core/context/DummyContext.ts +4 -4
  13. package/Tone/core/context/Listener.test.ts +2 -2
  14. package/Tone/core/context/Listener.ts +3 -2
  15. package/Tone/core/context/ToneWithContext.ts +1 -1
  16. package/Tone/core/index.ts +0 -3
  17. package/Tone/core/util/Draw.test.ts +4 -4
  18. package/Tone/core/util/Draw.ts +2 -2
  19. package/Tone/fromContext.ts +8 -8
  20. package/Tone/index.test.ts +9 -9
  21. package/Tone/index.ts +20 -16
  22. package/Tone/signal/SyncedSignal.ts +1 -1
  23. package/Tone/source/buffer/Player.test.ts +236 -0
  24. package/Tone/source/buffer/Player.ts +100 -1
  25. package/Tone/version.ts +1 -1
  26. package/build/Tone.js +1 -1
  27. package/build/Tone.js.map +1 -1
  28. package/build/esm/core/clock/Transport.d.ts +1 -1
  29. package/build/esm/core/clock/Transport.js +4 -4
  30. package/build/esm/core/clock/Transport.js.map +1 -1
  31. package/build/esm/core/clock/TransportEvent.d.ts +2 -2
  32. package/build/esm/core/clock/TransportEvent.js +1 -1
  33. package/build/esm/core/clock/TransportRepeatEvent.d.ts +1 -1
  34. package/build/esm/core/context/BaseContext.d.ts +4 -4
  35. package/build/esm/core/context/Context.d.ts +4 -4
  36. package/build/esm/core/context/Context.js +8 -6
  37. package/build/esm/core/context/Context.js.map +1 -1
  38. package/build/esm/core/context/Destination.d.ts +1 -1
  39. package/build/esm/core/context/Destination.js +3 -3
  40. package/build/esm/core/context/Destination.js.map +1 -1
  41. package/build/esm/core/context/DummyContext.d.ts +4 -4
  42. package/build/esm/core/context/Listener.d.ts +2 -1
  43. package/build/esm/core/context/Listener.js +3 -2
  44. package/build/esm/core/context/Listener.js.map +1 -1
  45. package/build/esm/core/context/ToneWithContext.d.ts +1 -1
  46. package/build/esm/core/context/ToneWithContext.js +1 -1
  47. package/build/esm/core/index.js +0 -2
  48. package/build/esm/core/index.js.map +1 -1
  49. package/build/esm/core/util/Draw.d.ts +1 -1
  50. package/build/esm/core/util/Draw.js +2 -2
  51. package/build/esm/core/util/Draw.js.map +1 -1
  52. package/build/esm/fromContext.d.ts +8 -8
  53. package/build/esm/index.d.ts +25 -21
  54. package/build/esm/index.js +8 -8
  55. package/build/esm/index.js.map +1 -1
  56. package/build/esm/signal/SyncedSignal.d.ts +1 -1
  57. package/build/esm/signal/SyncedSignal.js +1 -1
  58. package/build/esm/source/buffer/Player.d.ts +28 -0
  59. package/build/esm/source/buffer/Player.js +86 -1
  60. package/build/esm/source/buffer/Player.js.map +1 -1
  61. package/build/esm/version.js +1 -1
  62. package/build/esm/version.js.map +1 -1
  63. package/package.json +2 -8
@@ -2,13 +2,13 @@ import { expect } from "chai";
2
2
 
3
3
  import { ConstantOutput } from "../../../test/helper/ConstantOutput.js";
4
4
  import { Offline } from "../../../test/helper/Offline.js";
5
- import { TransportClass } from "../clock/Transport.js";
5
+ import { TransportInstance } from "../clock/Transport.js";
6
6
  import { getContext } from "../Global.js";
7
- import { DrawClass } from "../util/Draw.js";
7
+ import { DrawInstance } from "../util/Draw.js";
8
8
  import { createAudioContext } from "./AudioContext.js";
9
9
  import { Context } from "./Context.js";
10
- import { DestinationClass } from "./Destination.js";
11
- import { ListenerClass } from "./Listener.js";
10
+ import { DestinationInstance } from "./Destination.js";
11
+ import { ListenerInstance } from "./Listener.js";
12
12
  import { connect } from "./ToneAudioNode.js";
13
13
 
14
14
  describe("Context", () => {
@@ -19,9 +19,9 @@ describe("Context", () => {
19
19
  const ctxDraw = context.draw;
20
20
  const ctxTransport = context.transport;
21
21
  const ctxListener = context.listener;
22
- expect(context.destination).is.instanceOf(DestinationClass);
23
- expect(context.draw).is.instanceOf(DrawClass);
24
- expect(context.listener).is.instanceOf(ListenerClass);
22
+ expect(context.destination).is.instanceOf(DestinationInstance);
23
+ expect(context.draw).is.instanceOf(DrawInstance);
24
+ expect(context.listener).is.instanceOf(ListenerInstance);
25
25
  await context.close();
26
26
  expect(ctxDest.disposed).to.be.true;
27
27
  expect(ctxDraw.disposed).to.be.true;
@@ -214,7 +214,7 @@ describe("Context", () => {
214
214
 
215
215
  it("is invoked in the offline context", () => {
216
216
  return Offline((context) => {
217
- const transport = new TransportClass({ context });
217
+ const transport = new TransportInstance({ context });
218
218
  transport.context.setTimeout(() => {
219
219
  expect(transport.now()).to.be.closeTo(0.01, 0.005);
220
220
  }, 0.01);
@@ -1,10 +1,10 @@
1
1
  import { Ticker, TickerClockSource } from "../clock/Ticker.js";
2
- import type { TransportClass as Transport } from "../clock/Transport.js";
2
+ import type { TransportInstance as Transport } from "../clock/Transport.js";
3
3
  import { Seconds } from "../type/Units.js";
4
4
  import { isAudioContext } from "../util/AdvancedTypeCheck.js";
5
5
  import { assert } from "../util/Debug.js";
6
6
  import { optionsFromArguments } from "../util/Defaults.js";
7
- import type { DrawClass as Draw } from "../util/Draw.js";
7
+ import type { DrawInstance as Draw } from "../util/Draw.js";
8
8
  import { Timeline } from "../util/Timeline.js";
9
9
  import { isDefined } from "../util/TypeCheck.js";
10
10
  import {
@@ -14,8 +14,8 @@ import {
14
14
  } from "./AudioContext.js";
15
15
  import { BaseContext, ContextLatencyHint } from "./BaseContext.js";
16
16
  import { closeContext, initializeContext } from "./ContextInitialization.js";
17
- import type { DestinationClass as Destination } from "./Destination.js";
18
- import type { ListenerClass as Listener } from "./Listener.js";
17
+ import type { DestinationInstance as Destination } from "./Destination.js";
18
+ import type { ListenerInstance as Listener } from "./Listener.js";
19
19
 
20
20
  export interface ContextOptions {
21
21
  clockSource: TickerClockSource;
@@ -117,12 +117,16 @@ export class Context extends BaseContext {
117
117
  // custom context provided, latencyHint unknown (unless explicitly provided in options)
118
118
  this._latencyHint = arguments[0]?.latencyHint || "";
119
119
  } else {
120
- this._context = createAudioContext(options.sampleRate ? {
121
- latencyHint: options.latencyHint,
122
- sampleRate: options.sampleRate,
123
- } : {
124
- latencyHint: options.latencyHint,
125
- });
120
+ this._context = createAudioContext(
121
+ options.sampleRate
122
+ ? {
123
+ latencyHint: options.latencyHint,
124
+ sampleRate: options.sampleRate,
125
+ }
126
+ : {
127
+ latencyHint: options.latencyHint,
128
+ }
129
+ );
126
130
  this._latencyHint = options.latencyHint;
127
131
  }
128
132
 
@@ -5,11 +5,11 @@ import { Offline } from "../../../test/helper/Offline.js";
5
5
  import { PassAudio } from "../../../test/helper/PassAudio.js";
6
6
  import { Oscillator } from "../../source/oscillator/Oscillator.js";
7
7
  import { getContext } from "../Global.js";
8
- import { DestinationClass } from "./Destination.js";
8
+ import { DestinationInstance } from "./Destination.js";
9
9
 
10
10
  describe("Destination", () => {
11
11
  it("creates itself on the context", () => {
12
- expect(getContext().destination).instanceOf(DestinationClass);
12
+ expect(getContext().destination).instanceOf(DestinationInstance);
13
13
  });
14
14
 
15
15
  it("can be muted and unmuted", () => {
@@ -30,7 +30,7 @@ interface DestinationOptions extends ToneAudioNodeOptions {
30
30
  * oscillator.toDestination();
31
31
  * @category Core
32
32
  */
33
- export class DestinationClass extends ToneAudioNode<DestinationOptions> {
33
+ export class DestinationInstance extends ToneAudioNode<DestinationOptions> {
34
34
  readonly name: string = "Destination";
35
35
 
36
36
  input: Volume = new Volume({ context: this.context });
@@ -49,7 +49,7 @@ export class DestinationClass extends ToneAudioNode<DestinationOptions> {
49
49
  constructor(options: Partial<DestinationOptions>);
50
50
  constructor() {
51
51
  const options = optionsFromArguments(
52
- DestinationClass.getDefaults(),
52
+ DestinationInstance.getDefaults(),
53
53
  arguments
54
54
  );
55
55
  super(options);
@@ -133,7 +133,7 @@ export class DestinationClass extends ToneAudioNode<DestinationOptions> {
133
133
  //-------------------------------------
134
134
 
135
135
  onContextInit((context) => {
136
- context.destination = new DestinationClass({ context });
136
+ context.destination = new DestinationInstance({ context });
137
137
  });
138
138
 
139
139
  onContextClose((context) => {
@@ -1,10 +1,10 @@
1
- import type { TransportClass as Transport } from "../clock/Transport.js";
1
+ import type { TransportInstance as Transport } from "../clock/Transport.js";
2
2
  import { Seconds } from "../type/Units.js";
3
- import type { DrawClass as Draw } from "../util/Draw.js";
3
+ import type { DrawInstance as Draw } from "../util/Draw.js";
4
4
  import { AnyAudioContext } from "./AudioContext.js";
5
5
  import { BaseContext } from "./BaseContext.js";
6
- import type { DestinationClass as Destination } from "./Destination.js";
7
- import type { ListenerClass as Listener } from "./Listener.js";
6
+ import type { DestinationInstance as Destination } from "./Destination.js";
7
+ import type { ListenerInstance as Listener } from "./Listener.js";
8
8
 
9
9
  export class DummyContext extends BaseContext {
10
10
  //---------------------------
@@ -2,11 +2,11 @@ import { expect } from "chai";
2
2
 
3
3
  import { Offline } from "../../../test/helper/Offline.js";
4
4
  import { getContext } from "../Global.js";
5
- import { ListenerClass } from "./Listener.js";
5
+ import { ListenerInstance } from "./Listener.js";
6
6
 
7
7
  describe("Listener", () => {
8
8
  it("creates itself on the context", () => {
9
- expect(getContext().listener).instanceOf(ListenerClass);
9
+ expect(getContext().listener).instanceOf(ListenerInstance);
10
10
  });
11
11
 
12
12
  it("can get and set values as an object", () => {
@@ -19,8 +19,9 @@ export interface ListenerOptions extends ToneAudioNodeOptions {
19
19
  * with {@link Panner3D} makes up the Web Audio API's 3D panning system. Panner3D allows you
20
20
  * to place sounds in 3D and Listener allows you to navigate the 3D sound environment from
21
21
  * a first-person perspective. There is only one listener per audio context.
22
+ * @category Core
22
23
  */
23
- export class ListenerClass extends ToneAudioNode<ListenerOptions> {
24
+ export class ListenerInstance extends ToneAudioNode<ListenerOptions> {
24
25
  readonly name: string = "Listener";
25
26
 
26
27
  /**
@@ -108,7 +109,7 @@ export class ListenerClass extends ToneAudioNode<ListenerOptions> {
108
109
  //-------------------------------------
109
110
 
110
111
  onContextInit((context) => {
111
- context.listener = new ListenerClass({ context });
112
+ context.listener = new ListenerInstance({ context });
112
113
  });
113
114
 
114
115
  onContextClose((context) => {
@@ -110,7 +110,7 @@ export abstract class ToneWithContext<
110
110
 
111
111
  /**
112
112
  * Convert the incoming time to seconds.
113
- * This is calculated against the current {@link TransportClass} bpm
113
+ * This is calculated against the current {@link TransportInstance} bpm
114
114
  * @example
115
115
  * const gain = new Tone.Gain();
116
116
  * setInterval(() => console.log(gain.toSeconds("4n")), 100);
@@ -1,10 +1,7 @@
1
1
  export * from "./clock/Clock.js";
2
- // export * from "./clock/Transport";
3
-
4
2
  export * from "./context/BaseContext.js";
5
3
  export * from "./context/Context.js";
6
4
  export * from "./context/Delay.js";
7
- // export * from "./context/Destination";
8
5
  export * from "./context/Gain.js";
9
6
  export * from "./context/Offline.js";
10
7
  export * from "./context/OfflineContext.js";
@@ -1,6 +1,6 @@
1
1
  import { expect } from "chai";
2
2
 
3
- import { DrawClass } from "./Draw.js";
3
+ import { DrawInstance } from "./Draw.js";
4
4
 
5
5
  describe("Draw", () => {
6
6
  const originalRAF = window.requestAnimationFrame;
@@ -15,7 +15,7 @@ describe("Draw", () => {
15
15
  });
16
16
 
17
17
  it("can schedule a callback at a AudioContext time", (done) => {
18
- const draw = new DrawClass();
18
+ const draw = new DrawInstance();
19
19
  const scheduledTime = draw.now() + 0.2;
20
20
  draw.schedule(() => {
21
21
  expect(draw.context.currentTime).to.be.closeTo(scheduledTime, 0.05);
@@ -25,7 +25,7 @@ describe("Draw", () => {
25
25
  });
26
26
 
27
27
  it("can schedule multiple callbacks", (done) => {
28
- const draw = new DrawClass();
28
+ const draw = new DrawInstance();
29
29
  let callbackCount = 0;
30
30
  const firstEvent = draw.now() + 0.1;
31
31
  draw.schedule(() => {
@@ -50,7 +50,7 @@ describe("Draw", () => {
50
50
  });
51
51
 
52
52
  it("can cancel scheduled events", (done) => {
53
- const draw = new DrawClass();
53
+ const draw = new DrawInstance();
54
54
  let callbackCount = 0;
55
55
  draw.schedule(() => {
56
56
  callbackCount++;
@@ -31,7 +31,7 @@ interface DrawEvent extends TimelineEvent {
31
31
  * Tone.Transport.start();
32
32
  * @category Core
33
33
  */
34
- export class DrawClass extends ToneWithContext<ToneWithContextOptions> {
34
+ export class DrawInstance extends ToneWithContext<ToneWithContextOptions> {
35
35
  readonly name: string = "Draw";
36
36
 
37
37
  /**
@@ -122,7 +122,7 @@ export class DrawClass extends ToneWithContext<ToneWithContextOptions> {
122
122
  //-------------------------------------
123
123
 
124
124
  onContextInit((context) => {
125
- context.draw = new DrawClass({ context });
125
+ context.draw = new DrawInstance({ context });
126
126
  });
127
127
 
128
128
  onContextClose((context) => {
@@ -1,15 +1,15 @@
1
1
  import * as Classes from "./classes.js";
2
- import { TransportClass } from "./core/clock/Transport.js";
2
+ import { TransportInstance } from "./core/clock/Transport.js";
3
3
  import { Context } from "./core/context/Context.js";
4
- import { DestinationClass } from "./core/context/Destination.js";
5
- import { ListenerClass } from "./core/context/Listener.js";
4
+ import { DestinationInstance } from "./core/context/Destination.js";
5
+ import { ListenerInstance } from "./core/context/Listener.js";
6
6
  import { FrequencyClass } from "./core/type/Frequency.js";
7
7
  import { MidiClass } from "./core/type/Midi.js";
8
8
  import { TicksClass } from "./core/type/Ticks.js";
9
9
  import { TimeClass } from "./core/type/Time.js";
10
10
  import { TransportTimeClass } from "./core/type/TransportTime.js";
11
11
  import { omitFromObject } from "./core/util/Defaults.js";
12
- import { DrawClass } from "./core/util/Draw.js";
12
+ import { DrawInstance } from "./core/util/Draw.js";
13
13
  import { isDefined, isFunction } from "./core/util/TypeCheck.js";
14
14
 
15
15
  type ClassesWithoutSingletons = Omit<
@@ -22,10 +22,10 @@ type ClassesWithoutSingletons = Omit<
22
22
  * to the same context and contains a singleton Transport and Destination node.
23
23
  */
24
24
  type ToneObject = {
25
- Transport: TransportClass;
26
- Destination: DestinationClass;
27
- Listener: ListenerClass;
28
- Draw: DrawClass;
25
+ Transport: TransportInstance;
26
+ Destination: DestinationInstance;
27
+ Listener: ListenerInstance;
28
+ Draw: DrawInstance;
29
29
  context: Context;
30
30
  now: () => number;
31
31
  immediate: () => number;
@@ -1,9 +1,9 @@
1
1
  import { expect } from "chai";
2
2
 
3
- import { TransportClass } from "./core/clock/Transport.js";
3
+ import { TransportInstance } from "./core/clock/Transport.js";
4
4
  import { Context } from "./core/context/Context.js";
5
- import { DestinationClass } from "./core/context/Destination.js";
6
- import { DrawClass } from "./core/util/Draw.js";
5
+ import { DestinationInstance } from "./core/context/Destination.js";
6
+ import { DrawInstance } from "./core/util/Draw.js";
7
7
  import * as Tone from "./index.js";
8
8
 
9
9
  describe("Tone", () => {
@@ -15,16 +15,16 @@ describe("Tone", () => {
15
15
  });
16
16
 
17
17
  it("exports the global singletons", () => {
18
- expect(Tone.Destination).to.be.an.instanceOf(DestinationClass);
19
- expect(Tone.Draw).to.be.an.instanceOf(DrawClass);
20
- expect(Tone.Transport).to.be.an.instanceOf(TransportClass);
18
+ expect(Tone.Destination).to.be.an.instanceOf(DestinationInstance);
19
+ expect(Tone.Draw).to.be.an.instanceOf(DrawInstance);
20
+ expect(Tone.Transport).to.be.an.instanceOf(TransportInstance);
21
21
  expect(Tone.context).to.be.an.instanceOf(Context);
22
22
  });
23
23
 
24
24
  it("exports the global singleton getters", () => {
25
- expect(Tone.getDestination()).to.be.an.instanceOf(DestinationClass);
26
- expect(Tone.getDraw()).to.be.an.instanceOf(DrawClass);
27
- expect(Tone.getTransport()).to.be.an.instanceOf(TransportClass);
25
+ expect(Tone.getDestination()).to.be.an.instanceOf(DestinationInstance);
26
+ expect(Tone.getDraw()).to.be.an.instanceOf(DrawInstance);
27
+ expect(Tone.getTransport()).to.be.an.instanceOf(TransportInstance);
28
28
  });
29
29
 
30
30
  it("can start the global context", () => {
package/Tone/index.ts CHANGED
@@ -6,10 +6,14 @@ import { getContext } from "./core/Global.js";
6
6
  export { start } from "./core/Global.js";
7
7
  import { Seconds } from "./core/type/Units.js";
8
8
  export { supported } from "./core/context/AudioContext.js";
9
- import type { TransportClass } from "./core/clock/Transport.js";
10
- import type { DestinationClass } from "./core/context/Destination.js";
11
- import type { ListenerClass } from "./core/context/Listener.js";
12
- import type { DrawClass } from "./core/util/Draw.js";
9
+ import type { TransportInstance } from "./core/clock/Transport.js";
10
+ export type { TransportInstance } from "./core/clock/Transport.js";
11
+ import type { DestinationInstance } from "./core/context/Destination.js";
12
+ export type { DestinationInstance } from "./core/context/Destination.js";
13
+ import type { ListenerInstance } from "./core/context/Listener.js";
14
+ export type { ListenerInstance } from "./core/context/Listener.js";
15
+ import type { DrawInstance } from "./core/util/Draw.js";
16
+ export type { DrawInstance } from "./core/util/Draw.js";
13
17
 
14
18
  /**
15
19
  * The current audio context time of the global {@link BaseContext}.
@@ -31,7 +35,7 @@ export function immediate(): Seconds {
31
35
 
32
36
  /**
33
37
  * The Transport object belonging to the global Tone.js Context.
34
- * @see {@link TransportClass}
38
+ * @see {@link TransportInstance}
35
39
  * @category Core
36
40
  * @deprecated Use {@link getTransport} instead
37
41
  */
@@ -39,16 +43,16 @@ export const Transport = getContext().transport;
39
43
 
40
44
  /**
41
45
  * The Transport object belonging to the global Tone.js Context.
42
- * @see {@link TransportClass}
46
+ * @see {@link TransportInstance}
43
47
  * @category Core
44
48
  */
45
- export function getTransport(): TransportClass {
49
+ export function getTransport(): TransportInstance {
46
50
  return getContext().transport;
47
51
  }
48
52
 
49
53
  /**
50
54
  * The Destination (output) belonging to the global Tone.js Context.
51
- * @see {@link DestinationClass}
55
+ * @see {@link DestinationInstance}
52
56
  * @category Core
53
57
  * @deprecated Use {@link getDestination} instead
54
58
  */
@@ -61,31 +65,31 @@ export const Master = getContext().destination;
61
65
 
62
66
  /**
63
67
  * The Destination (output) belonging to the global Tone.js Context.
64
- * @see {@link DestinationClass}
68
+ * @see {@link DestinationInstance}
65
69
  * @category Core
66
70
  */
67
- export function getDestination(): DestinationClass {
71
+ export function getDestination(): DestinationInstance {
68
72
  return getContext().destination;
69
73
  }
70
74
 
71
75
  /**
72
- * The {@link ListenerClass} belonging to the global Tone.js Context.
76
+ * The {@link ListenerInstance} belonging to the global Tone.js Context.
73
77
  * @category Core
74
78
  * @deprecated Use {@link getListener} instead
75
79
  */
76
80
  export const Listener = getContext().listener;
77
81
 
78
82
  /**
79
- * The {@link ListenerClass} belonging to the global Tone.js Context.
83
+ * The {@link ListenerInstance} belonging to the global Tone.js Context.
80
84
  * @category Core
81
85
  */
82
- export function getListener(): ListenerClass {
86
+ export function getListener(): ListenerInstance {
83
87
  return getContext().listener;
84
88
  }
85
89
 
86
90
  /**
87
91
  * Draw is used to synchronize the draw frame with the Transport's callbacks.
88
- * @see {@link DrawClass}
92
+ * @see {@link DrawInstance}
89
93
  * @category Core
90
94
  * @deprecated Use {@link getDraw} instead
91
95
  */
@@ -94,10 +98,10 @@ export const Draw = getContext().draw;
94
98
  /**
95
99
  * Get the singleton attached to the global context.
96
100
  * Draw is used to synchronize the draw frame with the Transport's callbacks.
97
- * @see {@link DrawClass}
101
+ * @see {@link DrawInstance}
98
102
  * @category Core
99
103
  */
100
- export function getDraw(): DrawClass {
104
+ export function getDraw(): DrawInstance {
101
105
  return getContext().draw;
102
106
  }
103
107
 
@@ -15,7 +15,7 @@ import { Signal, SignalOptions } from "./Signal.js";
15
15
  import { ToneConstantSource } from "./ToneConstantSource.js";
16
16
 
17
17
  /**
18
- * Adds the ability to synchronize the signal to the {@link TransportClass}
18
+ * Adds the ability to synchronize the signal to the {@link TransportInstance}
19
19
  * @category Signal
20
20
  */
21
21
  export class SyncedSignal<