mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 16:48:00 +00:00
Merge pull request #115 from hiddedejong/PartOffset
fixed start offset in Tone.Part, now behaves like Tone.Player
This commit is contained in:
commit
abc62d3962
2 changed files with 33 additions and 1 deletions
|
@ -146,7 +146,11 @@ define(["Tone/core/Tone", "Tone/event/Event", "Tone/core/Type", "Tone/core/Trans
|
|||
Tone.Part.prototype.start = function(time, offset){
|
||||
var ticks = this.toTicks(time);
|
||||
if (this._state.getStateAtTime(ticks) !== Tone.State.Started){
|
||||
offset = this.defaultArg(offset, 0);
|
||||
if (this._loop){
|
||||
offset = this.defaultArg(offset, this._loopStart);
|
||||
} else {
|
||||
offset = this.defaultArg(offset, 0);
|
||||
}
|
||||
offset = this.toTicks(offset);
|
||||
this._state.addEvent({
|
||||
"state" : Tone.State.Started,
|
||||
|
@ -177,6 +181,9 @@ define(["Tone/core/Tone", "Tone/event/Event", "Tone/core/Type", "Tone/core/Trans
|
|||
ticks += this._getLoopDuration();
|
||||
}
|
||||
event.start(ticks + "i");
|
||||
} else if (event.startOffset < this._loopStart && event.startOffset >= offset) {
|
||||
event.loop = false;
|
||||
event.start(ticks + "i");
|
||||
}
|
||||
} else {
|
||||
if (event.startOffset >= offset){
|
||||
|
|
|
@ -515,6 +515,31 @@ define(["helper/Basic", "Tone/event/Part", "Tone/core/Tone", "Tone/core/Transpor
|
|||
Tone.Transport.start();
|
||||
});
|
||||
|
||||
it("can start a loop with an offset before loop start", function(done){
|
||||
var iteration = 0;
|
||||
var part = new Part(function(time, number){
|
||||
if (iteration === 0){
|
||||
expect(number).to.equal(0);
|
||||
} else if (iteration === 1){
|
||||
expect(number).to.equal(1);
|
||||
} else if (iteration === 2){
|
||||
expect(number).to.equal(2);
|
||||
} else if (iteration === 3){
|
||||
expect(number).to.equal(1);
|
||||
} else if (iteration === 4){
|
||||
expect(number).to.equal(2);
|
||||
part.dispose();
|
||||
done();
|
||||
}
|
||||
iteration++;
|
||||
}, [[0, 0], [0.25, 1], [0.30, 2]]);
|
||||
part.loop = true;
|
||||
part.loopStart = 0.25;
|
||||
part.loopEnd = 0.5;
|
||||
part.start(0, 0);
|
||||
Tone.Transport.start();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
context("playbackRate", function(){
|
||||
|
|
Loading…
Reference in a new issue