1 | import { version } from "../version.js";
|
2 | import { hasAudioContext, theWindow, } from "./context/AudioContext.js";
|
3 | import { Context } from "./context/Context.js";
|
4 | import { DummyContext } from "./context/DummyContext.js";
|
5 | import { OfflineContext } from "./context/OfflineContext.js";
|
6 | import { isAudioContext, isOfflineAudioContext, } from "./util/AdvancedTypeCheck.js";
|
7 |
|
8 |
|
9 |
|
10 | const dummyContext = new DummyContext();
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | let globalContext = dummyContext;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export function getContext() {
|
21 | if (globalContext === dummyContext && hasAudioContext) {
|
22 | setContext(new Context());
|
23 | }
|
24 | return globalContext;
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | export function setContext(context, disposeOld = false) {
|
33 | if (disposeOld) {
|
34 | globalContext.dispose();
|
35 | }
|
36 | if (isAudioContext(context)) {
|
37 | globalContext = new Context(context);
|
38 | }
|
39 | else if (isOfflineAudioContext(context)) {
|
40 | globalContext = new OfflineContext(context);
|
41 | }
|
42 | else {
|
43 | globalContext = context;
|
44 | }
|
45 | }
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | export function start() {
|
60 | return globalContext.resume();
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 | if (theWindow && !theWindow.TONE_SILENCE_LOGGING) {
|
66 | let prefix = "v";
|
67 | if (version === "dev") {
|
68 | prefix = "";
|
69 | }
|
70 | const printString = ` * Tone.js ${prefix}${version} * `;
|
71 |
|
72 | console.log(`%c${printString}`, "background: #000; color: #fff");
|
73 | }
|
74 |
|
\ | No newline at end of file |