Merge branch 'dev' of https://github.com/Tonejs/Tone.js into dev

This commit is contained in:
Yotam Mann 2018-06-20 10:37:54 -04:00
commit 56a13f2619
13 changed files with 213 additions and 33 deletions

View file

@ -115,6 +115,9 @@ define(["Tone/core/Tone", "Tone/source/TickSource", "Tone/core/TimelineState",
* @return {Tone.Clock} this
*/
Tone.Clock.prototype.start = function(time, offset){
//make sure the context is started
this.context.resume();
//start the loop
time = this.toSeconds(time);
if (this._state.getValueAtTime(time) !== Tone.State.Started){
this._state.setStateAtTime(Tone.State.Started, time);

View file

@ -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.onstatechange = 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();
}
};
/**

View file

@ -92,6 +92,9 @@ define(["Tone/core/Tone", "Tone/source/OmniOscillator", "Tone/instrument/Instrum
this.oscillator.frequency.exponentialRampToValueAtTime(note, time + this.toSeconds(this.pitchDecay));
this.envelope.triggerAttack(time, velocity);
this.oscillator.start(time);
if (this.envelope.sustain === 0){
this.oscillator.stop(time + this.envelope.attack + this.envelope.decay);
}
return this;
};

View file

@ -108,7 +108,9 @@ define(["Tone/core/Tone", "Tone/component/Volume", "Tone/core/AudioNode"], funct
var constraints = {
audio : {
"echoCancellation" : false,
"sampleRate" : this.context.sampleRate
"sampleRate" : this.context.sampleRate,
"noiseSuppression" : false,
"mozNoiseSuppression" : false,
}
};
if (device){

116
package-lock.json generated
View file

@ -6036,6 +6036,122 @@
}
}
},
"gulp-cli": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/gulp-cli/-/gulp-cli-2.0.1.tgz",
"integrity": "sha512-RxujJJdN8/O6IW2nPugl7YazhmrIEjmiVfPKrWt68r71UCaLKS71Hp0gpKT+F6qOUFtr7KqtifDKaAJPRVvMYQ==",
"dev": true,
"requires": {
"ansi-colors": "^1.0.1",
"archy": "^1.0.0",
"array-sort": "^1.0.0",
"color-support": "^1.1.3",
"concat-stream": "^1.6.0",
"copy-props": "^2.0.1",
"fancy-log": "^1.3.2",
"gulplog": "^1.0.0",
"interpret": "^1.1.0",
"isobject": "^3.0.1",
"liftoff": "^2.5.0",
"matchdep": "^2.0.0",
"mute-stdout": "^1.0.0",
"pretty-hrtime": "^1.0.0",
"replace-homedir": "^1.0.0",
"semver-greatest-satisfied-range": "^1.1.0",
"v8flags": "^3.0.1",
"yargs": "^7.1.0"
},
"dependencies": {
"camelcase": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-3.0.0.tgz",
"integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo=",
"dev": true
},
"cliui": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz",
"integrity": "sha1-EgYBU3qRbSmUD5NNo7SNWFo5IT0=",
"dev": true,
"requires": {
"string-width": "^1.0.1",
"strip-ansi": "^3.0.1",
"wrap-ansi": "^2.0.0"
}
},
"is-fullwidth-code-point": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"dev": true,
"requires": {
"number-is-nan": "^1.0.0"
}
},
"os-locale": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
"integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=",
"dev": true,
"requires": {
"lcid": "^1.0.0"
}
},
"string-width": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"dev": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
"strip-ansi": "^3.0.0"
}
},
"which-module": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/which-module/-/which-module-1.0.0.tgz",
"integrity": "sha1-u6Y8qGGUiZT/MHc2CJ47lgJsKk8=",
"dev": true
},
"y18n": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz",
"integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE=",
"dev": true
},
"yargs": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-7.1.0.tgz",
"integrity": "sha1-a6MY6xaWFyf10oT46gA+jWFU0Mg=",
"dev": true,
"requires": {
"camelcase": "^3.0.0",
"cliui": "^3.2.0",
"decamelize": "^1.1.1",
"get-caller-file": "^1.0.1",
"os-locale": "^1.4.0",
"read-pkg-up": "^1.0.1",
"require-directory": "^2.1.1",
"require-main-filename": "^1.0.1",
"set-blocking": "^2.0.0",
"string-width": "^1.0.2",
"which-module": "^1.0.0",
"y18n": "^3.2.1",
"yargs-parser": "^5.0.0"
}
},
"yargs-parser": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-5.0.0.tgz",
"integrity": "sha1-J17PDX/+Bcd+ZOfIbkzZS/DhIoo=",
"dev": true,
"requires": {
"camelcase": "^3.0.0"
}
}
}
},
"gulp-coveralls": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/gulp-coveralls/-/gulp-coveralls-0.1.4.tgz",

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -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(){

View file

@ -54,6 +54,30 @@ function(Test, Tone, PassAudio, Oscillator, Synth, Offline,
});
});
context("Debugging", function(){
it("logs when the class is set on the window", function(){
var originalLog = console.log;
var calls = 0;
console.log = function(){
calls++;
};
var osc = new Oscillator();
osc.debug = true;
osc.start().stop();
expect(calls).to.equal(2);
console.log = originalLog;
});
it("assert throws an error if the boolean is false", function(){
expect(function(){
var tone = new Tone();
tone.assert(false, "throws error");
}).throws(Error);
});
});
context("Type checking", function(){
it("can test if an argument is a undefined", function(){

View file

@ -14,6 +14,17 @@ function(MembraneSynth, Basic, InstrumentTest, CompareToFile){
}, "membraneSynth.wav", 0.5);
});
it("matches another file", function(){
return CompareToFile(function(){
var synth = new MembraneSynth({
envelope : {
sustain : 0
}
}).toMaster();
synth.triggerAttackRelease("C2", 0.1);
}, "membraneSynth2.wav", 0.5);
});
context("API", function(){
it("can get and set oscillator attributes", function(){

View file

@ -1,13 +1,34 @@
define(["Tone/instrument/PolySynth", "helper/Basic", "helper/InstrumentTests", "helper/OutputAudioStereo",
"Tone/instrument/Instrument", "helper/Test", "helper/OutputAudio", "Tone/instrument/MonoSynth", "helper/Offline",
"Tone/instrument/Sampler", "Tone/type/Frequency"],
function(PolySynth, Basic, InstrumentTests, OutputAudioStereo, Instrument, Test, OutputAudio, MonoSynth, Offline, Sampler, Frequency){
"Tone/instrument/Sampler", "Tone/type/Frequency", "helper/CompareToFile"],
function(PolySynth, Basic, InstrumentTests, OutputAudioStereo, Instrument, Test, OutputAudio, MonoSynth, Offline, Sampler, Frequency, CompareToFile){
describe("PolySynth", function(){
Basic(PolySynth);
InstrumentTests(PolySynth, "C4");
it("matches a file", function(){
return CompareToFile(function(){
var synth = new PolySynth(2).toMaster();
synth.triggerAttackRelease("C4", 0.2, 0);
synth.triggerAttackRelease("C4", 0.1, 0.1);
synth.triggerAttackRelease("E4", 0.1, 0.2);
synth.triggerAttackRelease("E4", 0.1, 0.3);
synth.triggerAttackRelease("G4", 0.1, 0.4);
synth.triggerAttackRelease("B4", 0.1, 0.4);
synth.triggerAttackRelease("C4", 0.2, 0.5);
}, "polySynth.wav", 0.4);
});
it("matches another file", function(){
return CompareToFile(function(){
var synth = new PolySynth(4).toMaster();
synth.triggerAttackRelease(["C4", "E4", "G4", "B4"], 0.2, 0);
synth.triggerAttackRelease(["C4", "E4", "G4", "B4"], 0.2, 0.3);
}, "polySynth2.wav", 0.6);
});
context("PolySynth Tests", function(){
it("extends Tone.Instrument", function(){

View file

@ -78,25 +78,25 @@ function(BasicTests, OscillatorNode, Offline, Frequency, Test, Meter, Supports,
osc.stop("+0.3");
var now = osc.now();
osc.onended = function(){
expect(osc.now() - now).to.be.within(0.25, 0.45);
expect(osc.now() - now).to.be.within(0.25, 0.5);
osc.dispose();
done();
};
});
it("invokes the onended callback only once in the online context", function(done){
var osc = new OscillatorNode();
osc.start("+0");
osc.stop("+0.1");
osc.stop("+0.2");
osc.stop("+0.3");
var now = osc.now();
osc.onended = function(){
expect(osc.now() - now).to.be.within(0.25, 0.45);
osc.dispose();
done();
};
});
var osc = new OscillatorNode();
osc.start("+0");
osc.stop("+0.1");
osc.stop("+0.2");
osc.stop("+0.3");
var now = osc.now();
osc.onended = function(){
expect(osc.now() - now).to.be.within(0.25, 0.5);
osc.dispose();
done();
};
});
}
it("invokes the onended callback in the offline context", function(done){