tone 15.5.20 → 15.5.21
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/Tone/core/Global.test.ts +19 -0
- package/Tone/core/Global.ts +11 -32
- package/Tone/core/context/GlobalContext.ts +34 -0
- package/Tone/core/context/OfflineContext.ts +1 -1
- package/Tone/core/context/ToneAudioBuffer.ts +1 -1
- package/Tone/version.ts +1 -1
- package/build/Tone.js +1 -1
- package/build/Tone.js.map +1 -1
- package/build/esm/core/Global.d.ts +2 -5
- package/build/esm/core/Global.js +8 -26
- package/build/esm/core/Global.js.map +1 -1
- package/build/esm/core/context/GlobalContext.d.ts +15 -0
- package/build/esm/core/context/GlobalContext.js +30 -0
- package/build/esm/core/context/GlobalContext.js.map +1 -0
- package/build/esm/core/context/OfflineContext.js +1 -1
- package/build/esm/core/context/OfflineContext.js.map +1 -1
- package/build/esm/core/context/ToneAudioBuffer.js +1 -1
- package/build/esm/core/context/ToneAudioBuffer.js.map +1 -1
- package/build/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
|
|
3
|
+
import { Context } from "./context/Context.js";
|
|
4
|
+
import { getContext, setContext } from "./Global.js";
|
|
5
|
+
|
|
6
|
+
describe("Global", () => {
|
|
7
|
+
it("can setContext with disposeOld = true", () => {
|
|
8
|
+
const origContext = getContext();
|
|
9
|
+
const toneContext = new Context();
|
|
10
|
+
|
|
11
|
+
setContext(toneContext);
|
|
12
|
+
expect(getContext()).to.equal(toneContext);
|
|
13
|
+
|
|
14
|
+
setContext(origContext, true);
|
|
15
|
+
|
|
16
|
+
expect(getContext()).to.equal(origContext);
|
|
17
|
+
expect(toneContext.disposed).to.be.true;
|
|
18
|
+
});
|
|
19
|
+
});
|
package/Tone/core/Global.ts
CHANGED
|
@@ -1,39 +1,18 @@
|
|
|
1
1
|
import { version } from "../version.js";
|
|
2
|
-
import {
|
|
3
|
-
AnyAudioContext,
|
|
4
|
-
hasAudioContext,
|
|
5
|
-
theWindow,
|
|
6
|
-
} from "./context/AudioContext.js";
|
|
2
|
+
import { AnyAudioContext, theWindow } from "./context/AudioContext.js";
|
|
7
3
|
import { BaseContext } from "./context/BaseContext.js";
|
|
8
4
|
import { Context } from "./context/Context.js";
|
|
9
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
getContext,
|
|
7
|
+
setContext as _setContext,
|
|
8
|
+
} from "./context/GlobalContext.js";
|
|
10
9
|
import { OfflineContext } from "./context/OfflineContext.js";
|
|
11
10
|
import {
|
|
12
11
|
isAudioContext,
|
|
13
12
|
isOfflineAudioContext,
|
|
14
13
|
} from "./util/AdvancedTypeCheck.js";
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
* This dummy context is used to avoid throwing immediate errors when importing in Node.js
|
|
18
|
-
*/
|
|
19
|
-
const dummyContext = new DummyContext();
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The global audio context which is getable and assignable through
|
|
23
|
-
* getContext and setContext
|
|
24
|
-
*/
|
|
25
|
-
let globalContext: BaseContext = dummyContext;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Returns the default system-wide {@link Context}
|
|
29
|
-
* @category Core
|
|
30
|
-
*/
|
|
31
|
-
export function getContext(): BaseContext {
|
|
32
|
-
if (globalContext === dummyContext && hasAudioContext) {
|
|
33
|
-
setContext(new Context());
|
|
34
|
-
}
|
|
35
|
-
return globalContext;
|
|
36
|
-
}
|
|
15
|
+
export { getContext };
|
|
37
16
|
|
|
38
17
|
/**
|
|
39
18
|
* Set the default audio context
|
|
@@ -46,15 +25,15 @@ export function setContext(
|
|
|
46
25
|
disposeOld = false
|
|
47
26
|
): void {
|
|
48
27
|
if (disposeOld) {
|
|
49
|
-
|
|
28
|
+
getContext().dispose();
|
|
50
29
|
}
|
|
51
30
|
|
|
52
31
|
if (isAudioContext(context)) {
|
|
53
|
-
|
|
32
|
+
_setContext(new Context(context));
|
|
54
33
|
} else if (isOfflineAudioContext(context)) {
|
|
55
|
-
|
|
34
|
+
_setContext(new OfflineContext(context));
|
|
56
35
|
} else {
|
|
57
|
-
|
|
36
|
+
_setContext(context);
|
|
58
37
|
}
|
|
59
38
|
}
|
|
60
39
|
|
|
@@ -72,7 +51,7 @@ export function setContext(
|
|
|
72
51
|
* @category Core
|
|
73
52
|
*/
|
|
74
53
|
export function start(): Promise<void> {
|
|
75
|
-
return
|
|
54
|
+
return getContext().resume();
|
|
76
55
|
}
|
|
77
56
|
|
|
78
57
|
/**
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { hasAudioContext } from "./AudioContext.js";
|
|
2
|
+
import { BaseContext } from "./BaseContext.js";
|
|
3
|
+
import { Context } from "./Context.js";
|
|
4
|
+
import { DummyContext } from "./DummyContext.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This dummy context is used to avoid throwing immediate errors when importing in Node.js
|
|
8
|
+
*/
|
|
9
|
+
export const dummyContext: BaseContext = new DummyContext();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The global audio context which is getable and assignable through
|
|
13
|
+
* getContext and setContext
|
|
14
|
+
*/
|
|
15
|
+
let globalContext: BaseContext = dummyContext;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the default system-wide {@link Context}.
|
|
19
|
+
* Auto-initializes a real Context in browser environments.
|
|
20
|
+
*/
|
|
21
|
+
export function getContext(): BaseContext {
|
|
22
|
+
if (globalContext === dummyContext && hasAudioContext) {
|
|
23
|
+
globalContext = new Context();
|
|
24
|
+
}
|
|
25
|
+
return globalContext;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Set the global context directly. Unlike the richer `setContext` in Global.ts,
|
|
30
|
+
* this only accepts a {@link BaseContext} — no native AudioContext wrapping.
|
|
31
|
+
*/
|
|
32
|
+
export function setContext(context: BaseContext): void {
|
|
33
|
+
globalContext = context;
|
|
34
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createOfflineAudioContext } from "../context/AudioContext.js";
|
|
2
2
|
import { Context } from "../context/Context.js";
|
|
3
|
-
import { getContext, setContext } from "../Global.js";
|
|
4
3
|
import { Seconds } from "../type/Units.js";
|
|
5
4
|
import { isOfflineAudioContext } from "../util/AdvancedTypeCheck.js";
|
|
5
|
+
import { getContext, setContext } from "./GlobalContext.js";
|
|
6
6
|
import { ToneAudioBuffer } from "./ToneAudioBuffer.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { getContext } from "../Global.js";
|
|
2
1
|
import { Tone } from "../Tone.js";
|
|
3
2
|
import { Samples, Seconds } from "../type/Units.js";
|
|
4
3
|
import { assert } from "../util/Debug.js";
|
|
5
4
|
import { optionsFromArguments } from "../util/Defaults.js";
|
|
6
5
|
import { noOp } from "../util/Interface.js";
|
|
7
6
|
import { isArray, isNumber, isString } from "../util/TypeCheck.js";
|
|
7
|
+
import { getContext } from "./GlobalContext.js";
|
|
8
8
|
|
|
9
9
|
interface ToneAudioBufferOptions {
|
|
10
10
|
url?: string | AudioBuffer | ToneAudioBuffer;
|
package/Tone/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version: string = "15.5.
|
|
1
|
+
export const version: string = "15.5.21";
|