Fixes Part loop toggle
This commit is contained in:
tboie 2019-04-12 10:44:24 -04:00 committed by Yotam Mann
parent aa92ea6162
commit bcd22b0463
2 changed files with 38 additions and 2 deletions

View file

@ -358,7 +358,7 @@ Tone.Part.prototype._tick = function(time, value){
* @private
*/
Tone.Part.prototype._testLoopBoundries = function(event){
if (event.startOffset < this._loopStart || event.startOffset >= this._loopEnd){
if (this._loop && (event.startOffset < this._loopStart || event.startOffset >= this._loopEnd)){
event.cancel(0);
} else if (event.state === Tone.State.Stopped){
//reschedule it if it's stopped

View file

@ -422,7 +422,7 @@ describe("Part", function(){
context("Looping", function(){
it("can be set to loop", function(){
it("can be set using a boolean as an argument when created", function(){
var callCount = 0;
return Offline(function(Transport){
new Part({
@ -439,6 +439,42 @@ describe("Part", function(){
});
});
it("can be toggled off using a boolean", function(){
var callCount = 0;
return Offline(function(Transport){
var part = new Part({
"loopEnd" : 0.2,
"loop" : true,
"callback" : function(){
callCount++;
},
"events" : [[0, 1], [0.1, 2]]
}).start(0);
part.loop = false;
Transport.start();
}, 0.55).then(function(){
expect(callCount).to.equal(2);
});
});
it("can be toggled on using a boolean", function(){
var callCount = 0;
return Offline(function(Transport){
var part = new Part({
"loopEnd" : 0.2,
"loop" : false,
"callback" : function(){
callCount++;
},
"events" : [[0, 1], [0.1, 2]]
}).start(0);
part.loop = true;
Transport.start();
}, 0.55).then(function(){
expect(callCount).to.equal(6);
});
});
it("can be set to loop at a specific interval", function(){
var invoked = false;
return Offline(function(Transport){