events use Transport.getTicksAtTime for greater accuracy

This commit is contained in:
Yotam Mann 2018-02-27 17:04:30 -05:00
parent 5a04a72d34
commit 36beb6c5f8
2 changed files with 7 additions and 6 deletions

View file

@ -75,7 +75,7 @@ define(["Tone/core/Tone", "Tone/core/TransportEvent", "Tone/type/Ticks"], functi
*/
Tone.TransportRepeatEvent.prototype.invoke = function(time){
//create more events if necessary
this._createEvents();
this._createEvents(time);
//call the super class
Tone.TransportEvent.prototype.invoke.call(this, time);
};
@ -84,9 +84,9 @@ define(["Tone/core/Tone", "Tone/core/TransportEvent", "Tone/type/Ticks"], functi
* Push more events onto the timeline to keep up with the position of the timeline
* @private
*/
Tone.TransportRepeatEvent.prototype._createEvents = function(){
Tone.TransportRepeatEvent.prototype._createEvents = function(time){
// schedule the next event
var ticks = this.Transport.ticks;
var ticks = this.Transport.getTicksAtTime(time);
if (ticks >= this.time && ticks >= this._nextTick &&
this._nextTick + this._interval < this.time + this.duration){
this._nextTick += this._interval;
@ -99,11 +99,11 @@ define(["Tone/core/Tone", "Tone/core/TransportEvent", "Tone/type/Ticks"], functi
* Push more events onto the timeline to keep up with the position of the timeline
* @private
*/
Tone.TransportRepeatEvent.prototype._restart = function(){
Tone.TransportRepeatEvent.prototype._restart = function(time){
this.Transport.clear(this._currentId);
this.Transport.clear(this._nextId);
var ticks = this.Transport.ticks;
this._nextTick = this.time;
var ticks = this.Transport.getTicksAtTime(time);
if (ticks > this.time){
this._nextTick = this.time + Math.ceil((ticks - this.time) / this._interval) * this._interval;
}

View file

@ -291,7 +291,8 @@ define(["Tone/core/Tone", "Tone/core/Transport", "Tone/type/Type", "Tone/core/Ti
* @private
*/
Tone.Event.prototype._tick = function(time){
if (!this.mute && this._state.getValueAtTime(Tone.Transport.ticks) === Tone.State.Started){
var ticks = Tone.Transport.getTicksAtTime(time);
if (!this.mute && this._state.getValueAtTime(ticks) === Tone.State.Started){
if (this.probability < 1 && Math.random() > this.probability){
return;
}