From 75628b53e868f2749eb849e55533d76e020a0874 Mon Sep 17 00:00:00 2001 From: Hidde de Jong Date: Sun, 31 Jan 2016 14:45:34 +0100 Subject: [PATCH 1/2] fixed start offset in Tone.Part, now behaves like Tone.Player --- Tone/event/Part.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Tone/event/Part.js b/Tone/event/Part.js index 768e1de6..1f4e0236 100644 --- a/Tone/event/Part.js +++ b/Tone/event/Part.js @@ -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){ From 523634106cfd141c8c830c2f2ca7329cdfce0b05 Mon Sep 17 00:00:00 2001 From: Hidde de Jong Date: Sun, 31 Jan 2016 23:05:03 +0100 Subject: [PATCH 2/2] added test for starting Tone.Part with an offset before loopStart --- test/event/Part.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/event/Part.js b/test/event/Part.js index 57efbcce..91f3a3f8 100644 --- a/test/event/Part.js +++ b/test/event/Part.js @@ -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(){