mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-27 20:13:07 +00:00
Merge pull request #880 from WofWca/set-context-dispose-old
improvement: add `disposeOld` parameter to `setContext`
This commit is contained in:
commit
fba6c14d75
1 changed files with 7 additions and 1 deletions
|
@ -30,9 +30,15 @@ export function getContext(): BaseContext {
|
|||
|
||||
/**
|
||||
* Set the default audio context
|
||||
* @param context
|
||||
* @param disposeOld Pass `true` if you don't need the old context to dispose it.
|
||||
* @category Core
|
||||
*/
|
||||
export function setContext(context: BaseContext | AnyAudioContext): void {
|
||||
export function setContext(context: BaseContext | AnyAudioContext, disposeOld = false): void {
|
||||
if (disposeOld) {
|
||||
globalContext.dispose();
|
||||
}
|
||||
|
||||
if (isAudioContext(context)) {
|
||||
globalContext = new Context(context);
|
||||
} else if (isOfflineAudioContext(context)) {
|
||||
|
|
Loading…
Reference in a new issue