UNPKG

2.5 kBJavaScriptView Raw
1/**
2 * Tone.js
3 * @author Yotam Mann
4 * @license http://opensource.org/licenses/MIT MIT License
5 * @copyright 2014-2024 Yotam Mann
6 */
7import { version } from "../version.js";
8import { theWindow } from "./context/AudioContext.js";
9import { log } from "./util/Debug.js";
10/**
11 * Tone is the base class of all other classes.
12 *
13 * @category Core
14 * @constructor
15 */
16export class Tone {
17 constructor() {
18 //-------------------------------------
19 // DEBUGGING
20 //-------------------------------------
21 /**
22 * Set this debug flag to log all events that happen in this class.
23 */
24 this.debug = false;
25 //-------------------------------------
26 // DISPOSING
27 //-------------------------------------
28 /**
29 * Indicates if the instance was disposed
30 */
31 this._wasDisposed = false;
32 }
33 /**
34 * Returns all of the default options belonging to the class.
35 */
36 static getDefaults() {
37 return {};
38 }
39 /**
40 * Prints the outputs to the console log for debugging purposes.
41 * Prints the contents only if either the object has a property
42 * called `debug` set to true, or a variable called TONE_DEBUG_CLASS
43 * is set to the name of the class.
44 * @example
45 * const osc = new Tone.Oscillator();
46 * // prints all logs originating from this oscillator
47 * osc.debug = true;
48 * // calls to start/stop will print in the console
49 * osc.start();
50 */
51 log(...args) {
52 // if the object is either set to debug = true
53 // or if there is a string on the Tone.global.with the class name
54 if (this.debug ||
55 (theWindow && this.toString() === theWindow.TONE_DEBUG_CLASS)) {
56 log(this, ...args);
57 }
58 }
59 /**
60 * disconnect and dispose.
61 */
62 dispose() {
63 this._wasDisposed = true;
64 return this;
65 }
66 /**
67 * Indicates if the instance was disposed. 'Disposing' an
68 * instance means that all of the Web Audio nodes that were
69 * created for the instance are disconnected and freed for garbage collection.
70 */
71 get disposed() {
72 return this._wasDisposed;
73 }
74 /**
75 * Convert the class to a string
76 * @example
77 * const osc = new Tone.Oscillator();
78 * console.log(osc.toString());
79 */
80 toString() {
81 return this.name;
82 }
83}
84/**
85 * The version number semver
86 */
87Tone.version = version;
88//# sourceMappingURL=Tone.js.map
\No newline at end of file