mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-15 08:17:07 +00:00
using resume instead of ready
This commit is contained in:
parent
45e40a8498
commit
a1e782df4a
2 changed files with 17 additions and 17 deletions
|
@ -82,6 +82,10 @@ define(["Tone/core/Tone", "Tone/core/Emitter", "Tone/core/Timeline", "Tone/shim/
|
|||
|
||||
this.on("tick", this._timeoutLoop.bind(this));
|
||||
|
||||
//forward state change events
|
||||
this._context.addEventListener("statechange", function(e){
|
||||
this.emit("statechange", e);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
Tone.extend(Tone.Context, Tone.Emitter);
|
||||
|
@ -132,20 +136,16 @@ define(["Tone/core/Tone", "Tone/core/Emitter", "Tone/core/Timeline", "Tone/shim/
|
|||
};
|
||||
|
||||
/**
|
||||
* Promise which is invoked when the context is running.
|
||||
* Tries to resume the context if it's not started.
|
||||
* Starts the audio context from a suspended state. This is required
|
||||
* to initially start the AudioContext.
|
||||
* @return {Promise}
|
||||
*/
|
||||
Tone.Context.prototype.ready = function(){
|
||||
return new Promise(function(done){
|
||||
if (this._context.state === "running"){
|
||||
done();
|
||||
} else {
|
||||
this._context.resume().then(function(){
|
||||
done();
|
||||
});
|
||||
}
|
||||
}.bind(this));
|
||||
Tone.Context.prototype.resume = function(){
|
||||
if (this._context.state !== "running"){
|
||||
return this._context.resume();
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -61,7 +61,7 @@ define(["helper/Test", "Tone/core/Context", "Tone/core/Tone", "helper/Offline",
|
|||
var ctx;
|
||||
beforeEach(function(){
|
||||
ctx = new Context();
|
||||
return ctx.ready();
|
||||
return ctx.resume();
|
||||
});
|
||||
|
||||
afterEach(function(){
|
||||
|
@ -105,7 +105,7 @@ define(["helper/Test", "Tone/core/Context", "Tone/core/Tone", "helper/Offline",
|
|||
var ctx;
|
||||
beforeEach(function(){
|
||||
ctx = new Context();
|
||||
return ctx.ready();
|
||||
return ctx.resume();
|
||||
});
|
||||
|
||||
afterEach(function(){
|
||||
|
@ -174,8 +174,8 @@ define(["helper/Test", "Tone/core/Context", "Tone/core/Tone", "helper/Offline",
|
|||
Tone.context = new Context();
|
||||
});
|
||||
|
||||
it("invokes the ready promise", function(){
|
||||
return Tone.context.ready();
|
||||
it("invokes the resume promise", function(){
|
||||
return Tone.context.resume();
|
||||
});
|
||||
|
||||
it("invokes init when a new context is set", function(done){
|
||||
|
@ -208,7 +208,7 @@ define(["helper/Test", "Tone/core/Context", "Tone/core/Tone", "helper/Offline",
|
|||
var ctx;
|
||||
beforeEach(function(){
|
||||
ctx = new Context();
|
||||
return ctx.ready();
|
||||
return ctx.resume();
|
||||
});
|
||||
|
||||
afterEach(function(){
|
||||
|
|
Loading…
Reference in a new issue