2015-08-17 00:31:11 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/core/Clock", "Tone/signal/Signal",
|
|
|
|
"Tone/signal/Multiply", "Tone/core/Types", "Tone/core/EventEmitter"],
|
2014-06-16 00:59:49 +00:00
|
|
|
function(Tone){
|
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
/**
|
2015-06-14 05:45:12 +00:00
|
|
|
* @class Oscillator-based transport allows for timing musical events.
|
|
|
|
* Supports tempo curves and time changes. A single transport is created
|
|
|
|
* on initialization. Unlike browser-based timing (setInterval, requestAnimationFrame)
|
|
|
|
* Tone.Transport timing events pass in the exact time of the scheduled event
|
|
|
|
* in the argument of the callback function. Pass that time value to the object
|
2015-06-20 19:50:57 +00:00
|
|
|
* you're scheduling. <br><br>
|
|
|
|
* A single transport is created for you when the library is initialized.
|
2014-06-16 00:59:49 +00:00
|
|
|
*
|
2015-08-17 00:31:11 +00:00
|
|
|
* @extends {Tone.EventEmitter}
|
2015-06-20 19:50:57 +00:00
|
|
|
* @singleton
|
2015-06-14 05:45:12 +00:00
|
|
|
* @example
|
|
|
|
* //repeated event every 8th note
|
|
|
|
* Tone.Transport.setInterval(function(time){
|
|
|
|
* //do something with the time
|
|
|
|
* }, "8n");
|
|
|
|
* @example
|
|
|
|
* //one time event 1 second in the future
|
|
|
|
* Tone.Transport.setTimeout(function(time){
|
|
|
|
* //do something with the time
|
|
|
|
* }, 1);
|
|
|
|
* @example
|
|
|
|
* //event fixed to the Transports timeline.
|
|
|
|
* Tone.Transport.setTimeline(function(time){
|
|
|
|
* //do something with the time
|
|
|
|
* }, "16:0:0");
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2014-09-11 02:37:57 +00:00
|
|
|
Tone.Transport = function(){
|
2014-06-16 00:59:49 +00:00
|
|
|
|
2015-08-17 00:31:11 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// LOOPING
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the transport loops or not.
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
this.loop = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The loop start position in ticks
|
|
|
|
* @type {Ticks}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._loopStart = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The loop end position in ticks
|
|
|
|
* @type {Ticks}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._loopEnd = 0;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// CLOCK/TEMPO
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pulses per quarter is the number of ticks per quarter note.
|
|
|
|
* @private
|
|
|
|
* @type {Number}
|
|
|
|
*/
|
|
|
|
this._ppq = TransportConstructor.defaults.PPQ;
|
|
|
|
|
2014-06-17 22:46:24 +00:00
|
|
|
/**
|
|
|
|
* watches the main oscillator for timing ticks
|
2014-07-30 17:54:55 +00:00
|
|
|
* initially starts at 120bpm
|
2014-06-17 22:46:24 +00:00
|
|
|
* @private
|
2014-07-30 17:54:55 +00:00
|
|
|
* @type {Tone.Clock}
|
2014-06-17 22:46:24 +00:00
|
|
|
*/
|
2015-02-21 19:05:12 +00:00
|
|
|
this._clock = new Tone.Clock(0, this._processTick.bind(this));
|
2015-05-05 19:36:06 +00:00
|
|
|
this._clock.onended = this._onended.bind(this);
|
2014-04-11 23:17:01 +00:00
|
|
|
|
2014-06-18 19:10:18 +00:00
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* The Beats Per Minute of the Transport.
|
2015-06-13 23:50:39 +00:00
|
|
|
* @type {BPM}
|
|
|
|
* @signal
|
2015-06-20 19:50:57 +00:00
|
|
|
* @example
|
|
|
|
* Tone.Transport.bpm.value = 80;
|
|
|
|
* //ramp the bpm to 120 over 10 seconds
|
|
|
|
* Tone.Transport.bpm.rampTo(120, 10);
|
2015-02-21 19:05:12 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
this.bpm = new Tone.Signal(TransportConstructor.defaults.bpm, Tone.Type.BPM);
|
2015-02-21 19:05:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the signal scalar
|
|
|
|
* @type {Tone.Multiply}
|
|
|
|
* @private
|
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
this._bpmMult = new Tone.Multiply(1/60 * this._ppq);
|
2015-02-21 19:05:12 +00:00
|
|
|
|
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* The time signature, or more accurately the numerator
|
|
|
|
* of the time signature over a denominator of 4.
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
2014-06-18 19:10:18 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
this._timeSignature = TransportConstructor.defaults.timeSignature;
|
2015-02-21 19:05:12 +00:00
|
|
|
|
|
|
|
//connect it all up
|
|
|
|
this.bpm.chain(this._bpmMult, this._clock.frequency);
|
2015-08-17 00:31:11 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// TIMELINE EVENTS
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The scheduled events.
|
|
|
|
* @type {Array}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._timeline = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current position along the scheduledEvents array.
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._timelinePosition = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Repeated events
|
|
|
|
* @type {Array}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._repeatedEvents = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Events that occur once
|
|
|
|
* @type {Array}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._onceEvents = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The elapsed ticks.
|
|
|
|
* @type {Ticks}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._ticks = 0;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// STATE TIMING
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The next time the state is started.
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._nextStart = Infinity;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The next time the state is stopped.
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._nextStop = Infinity;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The next time the state is paused.
|
|
|
|
* @type {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._nextPause = Infinity;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// SWING
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The subdivision of the swing
|
|
|
|
* @type {Ticks}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._swingTicks = this.toTicks(TransportConstructor.defaults.swingSubdivision, TransportConstructor.defaults.bpm, TransportConstructor.defaults.timeSignature);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The swing amount
|
|
|
|
* @type {NormalRange}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._swingAmount = 0;
|
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
|
|
|
|
2015-08-17 00:31:11 +00:00
|
|
|
Tone.extend(Tone.Transport, Tone.EventEmitter);
|
2014-06-16 00:59:49 +00:00
|
|
|
|
2015-02-24 03:14:22 +00:00
|
|
|
/**
|
|
|
|
* the defaults
|
|
|
|
* @type {Object}
|
|
|
|
* @const
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
Tone.Transport.defaults = {
|
|
|
|
"bpm" : 120,
|
|
|
|
"swing" : 0,
|
|
|
|
"swingSubdivision" : "16n",
|
|
|
|
"timeSignature" : 4,
|
|
|
|
"loopStart" : 0,
|
2015-08-17 00:31:11 +00:00
|
|
|
"loopEnd" : "4m",
|
|
|
|
"PPQ" : 48
|
2015-02-24 03:14:22 +00:00
|
|
|
};
|
|
|
|
|
2015-02-21 19:05:12 +00:00
|
|
|
/**
|
|
|
|
* All of the synced Signals
|
|
|
|
* @private
|
2015-06-14 00:56:41 +00:00
|
|
|
* @type {Array}
|
2015-02-21 19:05:12 +00:00
|
|
|
*/
|
|
|
|
var SyncedSignals = [];
|
|
|
|
|
2014-04-06 00:47:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2014-07-30 17:54:55 +00:00
|
|
|
// TICKS
|
2014-04-06 00:47:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
/**
|
2014-07-30 17:54:55 +00:00
|
|
|
* called on every tick
|
|
|
|
* @param {number} tickTime clock relative tick time
|
|
|
|
* @private
|
|
|
|
*/
|
2014-09-11 02:37:57 +00:00
|
|
|
Tone.Transport.prototype._processTick = function(tickTime){
|
2015-08-17 00:31:11 +00:00
|
|
|
//handle swing
|
|
|
|
if (this._swingAmount > 0 &&
|
|
|
|
this._ticks % this._ppq !== 0 && //not on a downbeat
|
|
|
|
this._ticks % this._swingTicks === 0){
|
|
|
|
//add some swing
|
|
|
|
tickTime += this.ticksToSeconds(this._swingTicks) * this._swingAmount;
|
|
|
|
}
|
|
|
|
//fire the next tick events if their time has come
|
|
|
|
for (var i = this._timelinePosition; i < this._timeline.length; i++){
|
|
|
|
var evnt = this._timeline[i];
|
|
|
|
if (evnt.tick <= this._ticks){
|
|
|
|
this._timelinePosition++;
|
|
|
|
if (evnt.tick === this._ticks){
|
|
|
|
evnt.callback(tickTime);
|
|
|
|
}
|
|
|
|
} else if (evnt.tick > this._ticks){
|
|
|
|
break;
|
2014-09-25 03:46:57 +00:00
|
|
|
}
|
2015-08-17 00:31:11 +00:00
|
|
|
}
|
|
|
|
//process the repeated events
|
|
|
|
for (var j = this._repeatedEvents.length - 1; j >= 0; j--) {
|
|
|
|
var repeatEvnt = this._repeatedEvents[j];
|
|
|
|
if (this._ticks >= repeatEvnt.startTick){
|
|
|
|
if ((this._ticks - repeatEvnt.startTick) % repeatEvnt.interval === 0){
|
|
|
|
repeatEvnt.callback(tickTime);
|
2014-09-14 19:34:17 +00:00
|
|
|
}
|
2014-04-06 00:47:59 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-17 00:31:11 +00:00
|
|
|
//process the single occurrence events
|
|
|
|
while(this._onceEvents.length > 0 && this._onceEvents[0].tick > this._ticks){
|
|
|
|
if (this._onceEvents[0].tick === this._ticks){
|
|
|
|
this._onceEvents.shift().callback(tickTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//increment the tick counter and check for loops
|
|
|
|
this._ticks++;
|
|
|
|
if (this.loop){
|
|
|
|
if (this._ticks === this._loopEnd){
|
|
|
|
this._setTicks(this._loopStart);
|
|
|
|
}
|
|
|
|
}
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
2014-03-19 21:25:33 +00:00
|
|
|
|
2014-07-30 17:54:55 +00:00
|
|
|
/**
|
|
|
|
* jump to a specific tick in the timeline
|
|
|
|
* updates the timeline callbacks
|
|
|
|
*
|
|
|
|
* @param {number} ticks the tick to jump to
|
|
|
|
* @private
|
|
|
|
*/
|
2014-09-11 02:37:57 +00:00
|
|
|
Tone.Transport.prototype._setTicks = function(ticks){
|
2015-08-17 00:31:11 +00:00
|
|
|
this._ticks = ticks;
|
|
|
|
for (var i = 0; i < this._timeline.length; i++){
|
|
|
|
var evnt = this._timeline[i];
|
|
|
|
if (evnt.tick >= ticks){
|
|
|
|
this._timelinePosition = i;
|
2014-04-06 00:47:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
2014-03-19 21:25:33 +00:00
|
|
|
|
2014-04-06 00:47:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-08-17 00:31:11 +00:00
|
|
|
// SCHEDULE
|
2014-06-16 00:59:49 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2014-03-19 21:25:33 +00:00
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* Schedule an event along the timeline.
|
|
|
|
* @param {TimelineEvent} event
|
|
|
|
* @param {Time} time
|
|
|
|
* @return {Number} The id of the event which can be used for canceling the event.
|
2015-02-28 04:24:51 +00:00
|
|
|
* @example
|
2015-08-17 00:31:11 +00:00
|
|
|
* //trigger the callback when the Transport reaches the desired time
|
|
|
|
* Tone.Transport.schedule(function(time){
|
2014-09-11 17:38:41 +00:00
|
|
|
* envelope.triggerAttack(time);
|
2015-08-17 00:31:11 +00:00
|
|
|
* }, "128i");
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
Tone.Transport.prototype.schedule = function(callback, time){
|
|
|
|
var event = new TimelineEvent(callback, this.toTicks(time));
|
|
|
|
//put it in the right spot
|
|
|
|
for (var i = 0, len = this._timeline.length; i<len; i++){
|
|
|
|
var testEvnt = this._timeline[i];
|
|
|
|
if (testEvnt.tick > event.tick){
|
|
|
|
this._timeline.splice(i, 0, event);
|
|
|
|
return event;
|
2014-04-06 00:47:59 +00:00
|
|
|
}
|
2014-03-19 21:25:33 +00:00
|
|
|
}
|
2015-08-17 00:31:11 +00:00
|
|
|
//otherwise push it on the end
|
|
|
|
this._timeline.push(event);
|
|
|
|
return event.id;
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
2014-04-06 00:47:59 +00:00
|
|
|
|
2014-06-18 20:45:25 +00:00
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* Schedule a repeated event along the timeline.
|
|
|
|
* @param {Function} callback The callback to invoke.
|
|
|
|
* @param {Time} interval The duration between successive
|
|
|
|
* callbacks.
|
|
|
|
* @param {Time=} startTime When along the timeline the events should
|
|
|
|
* start being invoked.
|
|
|
|
* @return {Number} The ID of the scheduled event. Use this to cancel
|
|
|
|
* the event.
|
2014-06-18 20:45:25 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
Tone.Transport.prototype.scheduleRepeat = function(callback, interval, startTime){
|
|
|
|
var event = new RepeatEvent(callback, this.toTicks(interval), this.toTicks(startTime));
|
|
|
|
this._repeatedEvents.push(event);
|
|
|
|
return event.id;
|
2014-06-18 20:45:25 +00:00
|
|
|
};
|
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* Schedule an event that will be removed after it is invoked
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
Tone.Transport.prototype.scheduleOnce = function(callback, time){
|
|
|
|
var event = new TimelineEvent(callback, this.toTicks(time));
|
2014-04-06 00:47:59 +00:00
|
|
|
//put it in the right spot
|
2015-08-17 00:31:11 +00:00
|
|
|
for (var i = 0, len = this._onceEvents.length; i<len; i++){
|
|
|
|
var testEvnt = this._onceEvents[i];
|
|
|
|
if (testEvnt.tick > event.tick){
|
|
|
|
this._onceEvents.splice(i, 0, event);
|
|
|
|
return event;
|
2014-06-16 00:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//otherwise push it on the end
|
2015-08-17 00:31:11 +00:00
|
|
|
this._onceEvents.push(event);
|
|
|
|
return event.id;
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* Cancel the passed in event.
|
|
|
|
* @param {TimelineEvent} event The event to cancel.
|
|
|
|
* @returns {Boolean} true if the event was removed, false otherwise.
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
Tone.Transport.prototype.cancel = function(eventId){
|
|
|
|
for (var i = 0; i < this._timeline.length; i++){
|
|
|
|
if (this._timeline[i].id === eventId){
|
|
|
|
this._timeline[i].callback = null;
|
|
|
|
this._timeline.splice(i, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var j = 0; j < this._repeatedEvents.length; j++){
|
|
|
|
if (this._repeatedEvents[j].id === eventId){
|
|
|
|
this._repeatedEvents[j].callback = null;
|
|
|
|
this._repeatedEvents.splice(j, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var k = 0; k < this._onceEvents.length; k++){
|
|
|
|
if (this._onceEvents[k].id === eventId){
|
|
|
|
this._onceEvents[k].callback = null;
|
|
|
|
this._onceEvents.splice(k, 1);
|
2014-06-16 00:59:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2014-06-18 20:45:25 +00:00
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* Remove scheduled events from the timeline after
|
|
|
|
* the given time. Repeated events will be removed
|
|
|
|
* if their startTime is after the given time
|
|
|
|
* @param {Time} [after=0] Clear all events after
|
|
|
|
* this time.
|
|
|
|
* @returns {Tone.Transport} this
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
Tone.Transport.prototype.clear = function(after){
|
|
|
|
after = this.defaultArg(after, 0);
|
|
|
|
after = this.toTicks(after);
|
|
|
|
for (var i = 0, len = this._timeline.length; i<len; i++){
|
|
|
|
var testEvnt = this._timeline[i];
|
|
|
|
if (testEvnt.tick > after){
|
|
|
|
this._timeline = this._timeline.slice(0, i);
|
|
|
|
break;
|
2014-04-06 00:47:59 +00:00
|
|
|
}
|
2014-03-19 21:25:33 +00:00
|
|
|
}
|
2015-08-17 00:31:11 +00:00
|
|
|
//remove all of the repeat events after the
|
|
|
|
return this;
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
|
|
|
|
2015-08-17 00:31:11 +00:00
|
|
|
/*
|
|
|
|
* @static
|
|
|
|
* @private
|
|
|
|
* @type {Number}
|
|
|
|
*/
|
|
|
|
var EventIds = 0;
|
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* @class A Transport Event
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
var TimelineEvent = function(callback, tick){
|
|
|
|
//add this to the transport timeline
|
|
|
|
this.id = EventIds++;
|
|
|
|
this.callback = callback;
|
|
|
|
this.tick = tick;
|
|
|
|
this.stopTick = Infinity;
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
2014-04-06 00:47:59 +00:00
|
|
|
|
2014-06-18 20:45:25 +00:00
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* @class A repeating event
|
2014-06-18 20:45:25 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
var RepeatEvent = function(callback, interval, startTick){
|
|
|
|
//add this to the transport timeline
|
|
|
|
this.id = EventIds++;
|
|
|
|
this.callback = callback;
|
|
|
|
this.startTick = startTick;
|
|
|
|
this.interval = interval;
|
|
|
|
this.stopTick = Infinity;
|
2014-06-18 20:45:25 +00:00
|
|
|
};
|
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-08-17 00:31:11 +00:00
|
|
|
// QUANTIZATION
|
2014-06-16 00:59:49 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-12-01 03:40:07 +00:00
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* Returns the time of the next beat.
|
2014-12-01 03:40:07 +00:00
|
|
|
* @param {string} [subdivision="4n"]
|
|
|
|
* @return {number} the time in seconds of the next subdivision
|
|
|
|
*/
|
|
|
|
Tone.Transport.prototype.nextBeat = function(subdivision){
|
|
|
|
subdivision = this.defaultArg(subdivision, "4n");
|
2015-07-14 01:58:20 +00:00
|
|
|
var tickNum = this.toTicks(subdivision);
|
2014-12-01 03:40:07 +00:00
|
|
|
var remainingTicks = (transportTicks % tickNum);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-04-06 00:47:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// START/STOP/PAUSE
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-17 00:31:11 +00:00
|
|
|
/**
|
|
|
|
* Returns the playback state of the source, either "started", "stopped", or "paused"
|
|
|
|
* @type {String}
|
|
|
|
* @readOnly
|
|
|
|
* @memberOf Tone.State#
|
|
|
|
* @name state
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Tone.Transport.prototype, "state", {
|
|
|
|
get : function(){
|
|
|
|
return this._stateAtTime(this.now());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the state of the source at the specified time.
|
|
|
|
* @param {Time} time
|
|
|
|
* @return {Tone.Transport}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Tone.Transport.prototype._stateAtTime = function(time){
|
|
|
|
if (this._nextStart <= time && this._nextStop > time && this._nextPause > time){
|
|
|
|
return Tone.State.Started;
|
|
|
|
} else if (this._nextStop <= time){
|
|
|
|
return Tone.State.Stopped;
|
|
|
|
} else if (this._nextPause <= time){
|
|
|
|
return Tone.State.Paused;
|
|
|
|
} else {
|
|
|
|
return Tone.State.Stopped;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* Start the transport and all sources synced to the transport.
|
|
|
|
* @param {Time} [time=now] The time when the transport should start.
|
|
|
|
* @param {Time=} offset The timeline offset to start the transport.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Transport} this
|
2015-06-20 19:50:57 +00:00
|
|
|
* @example
|
|
|
|
* //start the transport in one second starting at beginning of the 5th measure.
|
|
|
|
* Tone.Transport.start("+1", "4:0:0");
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2014-10-02 17:22:44 +00:00
|
|
|
Tone.Transport.prototype.start = function(time, offset){
|
2015-08-17 00:31:11 +00:00
|
|
|
time = this.toSeconds(time);
|
|
|
|
if (this._stateAtTime(time) !== Tone.State.Started){
|
|
|
|
this._nextStart = time;
|
|
|
|
this._nextStop = Infinity;
|
|
|
|
this._nextPause = Infinity;
|
|
|
|
offset = this.defaultArg(offset, this._ticks);
|
|
|
|
//set the offset
|
|
|
|
this._setTicks(this.toTicks(offset));
|
|
|
|
//call start on each of the synced structures
|
|
|
|
// this.trigger("start", time, offset);
|
|
|
|
//start the clock
|
|
|
|
this._clock.start(time);
|
2014-06-18 05:35:34 +00:00
|
|
|
}
|
2015-01-06 04:33:05 +00:00
|
|
|
return this;
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* Stop the transport and all sources synced to the transport.
|
|
|
|
* @param {Time} [time=now] The time when the transport should stop.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Transport} this
|
2015-06-20 19:50:57 +00:00
|
|
|
* @example
|
|
|
|
* Tone.Transport.stop();
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2014-09-11 02:37:57 +00:00
|
|
|
Tone.Transport.prototype.stop = function(time){
|
2015-08-17 00:31:11 +00:00
|
|
|
time = this.toSeconds(time);
|
|
|
|
if (this._stateAtTime(time) !== Tone.State.Stopped){
|
|
|
|
this._nextStop = time;
|
|
|
|
this._clock.stop(time);
|
|
|
|
//clear the tick events
|
|
|
|
this.clear(time);
|
|
|
|
// this.trigger("stop", time);
|
2014-09-14 19:34:17 +00:00
|
|
|
} else {
|
2015-01-05 03:25:16 +00:00
|
|
|
this._onended();
|
2014-06-18 05:35:34 +00:00
|
|
|
}
|
2015-01-06 04:33:05 +00:00
|
|
|
return this;
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
|
|
|
|
2014-09-14 19:34:17 +00:00
|
|
|
/**
|
|
|
|
* invoked when the transport is stopped
|
|
|
|
* @private
|
|
|
|
*/
|
2015-01-05 03:25:16 +00:00
|
|
|
Tone.Transport.prototype._onended = function(){
|
2014-09-14 19:34:17 +00:00
|
|
|
this._setTicks(0);
|
|
|
|
};
|
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* Pause the transport and all sources synced to the transport.
|
|
|
|
* @param {Time} [time=now]
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Transport} this
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2014-09-11 02:37:57 +00:00
|
|
|
Tone.Transport.prototype.pause = function(time){
|
2015-08-17 00:31:11 +00:00
|
|
|
time = this.toSeconds(time);
|
|
|
|
if (this._stateAtTime(time) === Tone.State.Started){
|
|
|
|
this._nextPause = time;
|
|
|
|
this._clock.stop(time);
|
|
|
|
// this.trigger("pause", time);
|
2014-06-18 19:10:18 +00:00
|
|
|
}
|
2015-01-06 04:33:05 +00:00
|
|
|
return this;
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
2014-03-19 21:25:33 +00:00
|
|
|
|
2014-04-06 00:47:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2014-04-11 23:17:01 +00:00
|
|
|
// SETTERS/GETTERS
|
2014-04-06 00:47:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* The time signature as just the numerator over 4.
|
2015-02-21 19:05:12 +00:00
|
|
|
* For example 4/4 would be just 4 and 6/8 would be 3.
|
|
|
|
* @memberOf Tone.Transport#
|
|
|
|
* @type {number}
|
|
|
|
* @name timeSignature
|
2015-06-20 19:50:57 +00:00
|
|
|
* @example
|
|
|
|
* //common time
|
|
|
|
* Tone.Transport.timeSignature = 4;
|
|
|
|
* // 7/8
|
|
|
|
* Tone.Transport.timeSignature = 3.5;
|
2015-02-21 19:05:12 +00:00
|
|
|
*/
|
|
|
|
Object.defineProperty(Tone.Transport.prototype, "timeSignature", {
|
|
|
|
get : function(){
|
2015-08-17 00:31:11 +00:00
|
|
|
return this._timeSignature;
|
2015-02-21 19:05:12 +00:00
|
|
|
},
|
2015-08-17 00:31:11 +00:00
|
|
|
set : function(timeSig){
|
|
|
|
if (Array.isArray(timeSig)){
|
|
|
|
timeSig = (timeSig[0] / timeSig[1]) * 4;
|
|
|
|
}
|
|
|
|
this._timeSignature = timeSig;
|
2015-02-10 21:33:18 +00:00
|
|
|
}
|
2015-02-21 19:05:12 +00:00
|
|
|
});
|
2014-06-16 00:59:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* When the Tone.Transport.loop = true, this is the starting position of the loop.
|
2015-02-21 19:05:12 +00:00
|
|
|
* @memberOf Tone.Transport#
|
2015-06-14 00:20:36 +00:00
|
|
|
* @type {Time}
|
2015-02-21 19:05:12 +00:00
|
|
|
* @name loopStart
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Tone.Transport.prototype, "loopStart", {
|
|
|
|
get : function(){
|
2015-08-17 00:31:11 +00:00
|
|
|
return this.ticksToSeconds(this._loopStart);
|
2015-02-21 19:05:12 +00:00
|
|
|
},
|
|
|
|
set : function(startPosition){
|
2015-08-17 00:31:11 +00:00
|
|
|
this._loopStart = this.toTicks(startPosition);
|
2015-02-21 19:05:12 +00:00
|
|
|
}
|
|
|
|
});
|
2014-06-16 00:59:49 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* When the Tone.Transport.loop = true, this is the ending position of the loop.
|
2015-02-21 19:05:12 +00:00
|
|
|
* @memberOf Tone.Transport#
|
2015-06-14 00:20:36 +00:00
|
|
|
* @type {Time}
|
2015-02-21 19:05:12 +00:00
|
|
|
* @name loopEnd
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Tone.Transport.prototype, "loopEnd", {
|
|
|
|
get : function(){
|
2015-08-17 00:31:11 +00:00
|
|
|
return this.ticksToSeconds(this._loopEnd);
|
2015-02-21 19:05:12 +00:00
|
|
|
},
|
|
|
|
set : function(endPosition){
|
2015-08-17 00:31:11 +00:00
|
|
|
this._loopEnd = this.toTicks(endPosition);
|
2015-02-21 19:05:12 +00:00
|
|
|
}
|
|
|
|
});
|
2014-06-16 00:59:49 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* Set the loop start and stop at the same time.
|
2015-06-14 00:20:36 +00:00
|
|
|
* @param {Time} startPosition
|
|
|
|
* @param {Time} endPosition
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Transport} this
|
2015-06-20 19:50:57 +00:00
|
|
|
* @example
|
|
|
|
* //loop over the first measure
|
|
|
|
* Tone.Transport.setLoopPoints(0, "1m");
|
|
|
|
* Tone.Transport.loop = true;
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2014-09-11 02:37:57 +00:00
|
|
|
Tone.Transport.prototype.setLoopPoints = function(startPosition, endPosition){
|
2015-02-21 19:05:12 +00:00
|
|
|
this.loopStart = startPosition;
|
|
|
|
this.loopEnd = endPosition;
|
2015-01-06 04:33:05 +00:00
|
|
|
return this;
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
|
|
|
|
2014-09-25 03:46:57 +00:00
|
|
|
/**
|
2015-02-21 19:05:12 +00:00
|
|
|
* The swing value. Between 0-1 where 1 equal to
|
|
|
|
* the note + half the subdivision.
|
|
|
|
* @memberOf Tone.Transport#
|
2015-06-14 00:20:36 +00:00
|
|
|
* @type {NormalRange}
|
2015-02-21 19:05:12 +00:00
|
|
|
* @name swing
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Tone.Transport.prototype, "swing", {
|
|
|
|
get : function(){
|
2015-08-17 00:31:11 +00:00
|
|
|
return this._swingAmount * 2;
|
2015-02-21 19:05:12 +00:00
|
|
|
},
|
|
|
|
set : function(amount){
|
|
|
|
//scale the values to a normal range
|
2015-08-17 00:31:11 +00:00
|
|
|
this._swingAmount = amount * 0.5;
|
2015-02-21 19:05:12 +00:00
|
|
|
}
|
|
|
|
});
|
2014-09-25 03:46:57 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-21 19:05:12 +00:00
|
|
|
* Set the subdivision which the swing will be applied to.
|
|
|
|
* The default values is a 16th note. Value must be less
|
|
|
|
* than a quarter note.
|
2014-09-30 03:42:56 +00:00
|
|
|
*
|
2015-02-21 19:05:12 +00:00
|
|
|
* @memberOf Tone.Transport#
|
2015-06-14 00:20:36 +00:00
|
|
|
* @type {Time}
|
2015-02-21 19:05:12 +00:00
|
|
|
* @name swingSubdivision
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Tone.Transport.prototype, "swingSubdivision", {
|
|
|
|
get : function(){
|
2015-08-17 00:31:11 +00:00
|
|
|
return this.toNotation(this._swingTicks + "i");
|
2015-02-21 19:05:12 +00:00
|
|
|
},
|
|
|
|
set : function(subdivision){
|
2015-08-17 00:31:11 +00:00
|
|
|
this._swingTicks = this.toTicks(subdivision);
|
2015-02-21 19:05:12 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Transport's position in MEASURES:BEATS:SIXTEENTHS.
|
|
|
|
* Setting the value will jump to that position right away.
|
|
|
|
*
|
|
|
|
* @memberOf Tone.Transport#
|
2015-06-20 19:50:57 +00:00
|
|
|
* @type {TransportTime}
|
2015-02-21 19:05:12 +00:00
|
|
|
* @name position
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Tone.Transport.prototype, "position", {
|
|
|
|
get : function(){
|
2015-08-17 00:31:11 +00:00
|
|
|
var quarters = this.ticks / this._ppq;
|
|
|
|
var measures = Math.floor(quarters / this._timeSignature);
|
|
|
|
var sixteenths = ((quarters % 1) * 4).toFixed(3);
|
|
|
|
quarters = Math.floor(quarters) % this._timeSignature;
|
2015-02-21 19:05:12 +00:00
|
|
|
var progress = [measures, quarters, sixteenths];
|
|
|
|
return progress.join(":");
|
|
|
|
},
|
|
|
|
set : function(progress){
|
2015-07-14 01:58:20 +00:00
|
|
|
var ticks = this.toTicks(progress);
|
2015-02-21 19:05:12 +00:00
|
|
|
this._setTicks(ticks);
|
|
|
|
}
|
|
|
|
});
|
2014-09-25 03:46:57 +00:00
|
|
|
|
2015-08-17 00:31:11 +00:00
|
|
|
/**
|
|
|
|
* The transports current tick position.
|
|
|
|
*
|
|
|
|
* @memberOf Tone.Transport#
|
|
|
|
* @type {Ticks}
|
|
|
|
* @name ticks
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Tone.Transport.prototype, "ticks", {
|
|
|
|
get : function(){
|
|
|
|
return this._ticks;
|
|
|
|
},
|
|
|
|
set : function(t){
|
|
|
|
//should also trigger whatever is on this tick
|
|
|
|
this._setTicks(t);
|
|
|
|
//clear everything after that tick
|
|
|
|
//trigger a tick to get everyone on the same page
|
|
|
|
// this._trigger("scrub", this._ticks);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pulses Per Quarter note. This is the smallest resolution
|
|
|
|
* the Transport timing supports. This should be set once
|
|
|
|
* on initialization and not set again. Changing this value
|
|
|
|
* after other objects have been created can cause problems.
|
|
|
|
*
|
|
|
|
* @memberOf Tone.Transport#
|
|
|
|
* @type {Number}
|
|
|
|
* @name PPQ
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Tone.Transport.prototype, "PPQ", {
|
|
|
|
get : function(){
|
|
|
|
return this._ppq;
|
|
|
|
},
|
|
|
|
set : function(ppq){
|
|
|
|
this._ppq = ppq;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SYNCING
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-17 00:31:11 +00:00
|
|
|
/**
|
|
|
|
* Sync a source to the transport so that
|
|
|
|
* @param {Tone.Source} source the source to sync to the transport
|
|
|
|
* @param {Time} delay (optionally) start the source with a delay from the transport
|
|
|
|
* @returns {Tone.Transport} this
|
|
|
|
* @example
|
|
|
|
* Tone.Transport.syncSource(player, "1m");
|
|
|
|
* Tone.Transport.start();
|
|
|
|
* //the player will start 1 measure after the transport starts
|
|
|
|
*/
|
|
|
|
Tone.Transport.prototype.syncStructure = function(struct){
|
|
|
|
this._structures.push(struct);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2014-06-25 16:47:47 +00:00
|
|
|
/**
|
|
|
|
* Sync a source to the transport so that
|
|
|
|
* @param {Tone.Source} source the source to sync to the transport
|
2015-06-14 00:20:36 +00:00
|
|
|
* @param {Time} delay (optionally) start the source with a delay from the transport
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Transport} this
|
2015-06-20 19:50:57 +00:00
|
|
|
* @example
|
|
|
|
* Tone.Transport.syncSource(player, "1m");
|
|
|
|
* Tone.Transport.start();
|
|
|
|
* //the player will start 1 measure after the transport starts
|
2014-06-25 16:47:47 +00:00
|
|
|
*/
|
2014-09-11 02:37:57 +00:00
|
|
|
Tone.Transport.prototype.syncSource = function(source, startDelay){
|
2014-06-25 16:47:47 +00:00
|
|
|
SyncedSources.push({
|
|
|
|
source : source,
|
|
|
|
delay : this.toSeconds(this.defaultArg(startDelay, 0))
|
|
|
|
});
|
2015-01-06 04:33:05 +00:00
|
|
|
return this;
|
2014-06-25 16:47:47 +00:00
|
|
|
};
|
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* Unsync the source from the transport. See Tone.Transport.syncSource.
|
2014-06-16 00:59:49 +00:00
|
|
|
*
|
2014-06-18 21:39:05 +00:00
|
|
|
* @param {Tone.Source} source [description]
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Transport} this
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2014-09-11 02:37:57 +00:00
|
|
|
Tone.Transport.prototype.unsyncSource = function(source){
|
2014-06-25 16:47:47 +00:00
|
|
|
for (var i = 0; i < SyncedSources.length; i++){
|
|
|
|
if (SyncedSources[i].source === source){
|
|
|
|
SyncedSources.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
2015-01-06 04:33:05 +00:00
|
|
|
return this;
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
|
|
|
|
2014-07-30 17:54:55 +00:00
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* Attaches the signal to the tempo control signal so that
|
2014-07-30 17:54:55 +00:00
|
|
|
* any changes in the tempo will change the signal in the same
|
2015-02-21 19:05:12 +00:00
|
|
|
* ratio.
|
2014-07-30 17:54:55 +00:00
|
|
|
*
|
|
|
|
* @param {Tone.Signal} signal
|
2015-02-21 19:05:12 +00:00
|
|
|
* @param {number=} ratio Optionally pass in the ratio between
|
|
|
|
* the two signals. Otherwise it will be computed
|
|
|
|
* based on their current values.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Transport} this
|
2014-07-30 17:54:55 +00:00
|
|
|
*/
|
2015-02-21 19:05:12 +00:00
|
|
|
Tone.Transport.prototype.syncSignal = function(signal, ratio){
|
|
|
|
if (!ratio){
|
|
|
|
//get the sync ratio
|
|
|
|
if (signal._value.value !== 0){
|
|
|
|
ratio = signal._value.value / this.bpm.value;
|
|
|
|
} else {
|
|
|
|
ratio = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var ratioSignal = this.context.createGain();
|
|
|
|
ratioSignal.gain.value = ratio;
|
|
|
|
this.bpm.chain(ratioSignal, signal._value);
|
|
|
|
SyncedSignals.push({
|
|
|
|
"ratio" : ratioSignal,
|
|
|
|
"signal" : signal,
|
|
|
|
"initial" : signal._value.value
|
|
|
|
});
|
|
|
|
signal._value.value = 0;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* Unsyncs a previously synced signal from the transport's control.
|
|
|
|
* See Tone.Transport.syncSignal.
|
2015-02-21 19:05:12 +00:00
|
|
|
* @param {Tone.Signal} signal
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Transport} this
|
2015-02-21 19:05:12 +00:00
|
|
|
*/
|
|
|
|
Tone.Transport.prototype.unsyncSignal = function(signal){
|
|
|
|
for (var i = 0; i < SyncedSignals.length; i++){
|
|
|
|
var syncedSignal = SyncedSignals[i];
|
|
|
|
if (syncedSignal.signal === signal){
|
|
|
|
syncedSignal.ratio.disconnect();
|
|
|
|
syncedSignal.signal._value.value = syncedSignal.initial;
|
|
|
|
SyncedSignals.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
2015-01-06 04:33:05 +00:00
|
|
|
return this;
|
2014-07-30 17:54:55 +00:00
|
|
|
};
|
2014-03-19 21:25:33 +00:00
|
|
|
|
2014-09-11 17:38:41 +00:00
|
|
|
/**
|
2015-06-20 19:50:57 +00:00
|
|
|
* Clean up.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Transport} this
|
2015-06-20 19:50:57 +00:00
|
|
|
* @private
|
2014-09-11 17:38:41 +00:00
|
|
|
*/
|
|
|
|
Tone.Transport.prototype.dispose = function(){
|
|
|
|
this._clock.dispose();
|
|
|
|
this._clock = null;
|
2015-02-21 19:05:12 +00:00
|
|
|
this.bpm.dispose();
|
|
|
|
this.bpm = null;
|
|
|
|
this._bpmMult.dispose();
|
|
|
|
this._bpmMult = null;
|
2015-01-06 04:33:05 +00:00
|
|
|
return this;
|
2014-09-11 17:38:41 +00:00
|
|
|
};
|
|
|
|
|
2014-04-06 00:47:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-08-17 00:31:11 +00:00
|
|
|
// DEPRECATED FUNCTIONS
|
|
|
|
// (will be removed in r7)
|
2014-04-06 00:47:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-06-16 00:59:49 +00:00
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* @deprecated Use Tone.scheduleRepeat instead.
|
|
|
|
* Set a callback for a recurring event.
|
|
|
|
* @param {function} callback
|
|
|
|
* @param {Time} interval
|
|
|
|
* @return {number} the id of the interval
|
|
|
|
* @example
|
|
|
|
* //triggers a callback every 8th note with the exact time of the event
|
|
|
|
* Tone.Transport.setInterval(function(time){
|
|
|
|
* envelope.triggerAttack(time);
|
|
|
|
* }, "8n");
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
Tone.Transport.prototype.setInterval = function(callback, interval){
|
|
|
|
console.warn("This method is deprecated. Use Tone.Transport.scheduleRepeat instead.");
|
|
|
|
return Tone.Transport.scheduleRepeat(callback, interval);
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* @deprecated Use Tone.cancel instead.
|
|
|
|
* Stop and ongoing interval.
|
|
|
|
* @param {number} intervalID The ID of interval to remove. The interval
|
|
|
|
* ID is given as the return value in Tone.Transport.setInterval.
|
|
|
|
* @return {boolean} true if the event was removed
|
2014-06-16 00:59:49 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
Tone.Transport.prototype.clearInterval = function(id){
|
|
|
|
console.warn("This method is deprecated. Use Tone.Transport.cancel instead.");
|
|
|
|
return Tone.Transport.cancel(id);
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
2014-03-20 03:59:38 +00:00
|
|
|
|
2014-06-16 05:44:00 +00:00
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* @deprecated Use Tone.Note instead.
|
|
|
|
* Set a timeout to occur after time from now. NB: the transport must be
|
|
|
|
* running for this to be triggered. All timeout events are cleared when the
|
|
|
|
* transport is stopped.
|
2014-06-23 18:20:16 +00:00
|
|
|
*
|
2015-08-17 00:31:11 +00:00
|
|
|
* @param {function} callback
|
|
|
|
* @param {Time} time The time (from now) that the callback will be invoked.
|
|
|
|
* @return {number} The id of the timeout.
|
|
|
|
* @example
|
|
|
|
* //trigger an event to happen 1 second from now
|
|
|
|
* Tone.Transport.setTimeout(function(time){
|
|
|
|
* player.start(time);
|
|
|
|
* }, 1)
|
2014-06-16 05:44:00 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
Tone.Transport.prototype.setTimeout = function(callback, timeout){
|
|
|
|
console.warn("This method is deprecated. Use Tone.Transport.scheduleOnce instead.");
|
|
|
|
return Tone.Transport.scheduleOnce(callback, timeout);
|
2014-06-16 00:59:49 +00:00
|
|
|
};
|
|
|
|
|
2014-06-16 05:44:00 +00:00
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* @deprecated Use Tone.Note instead.
|
|
|
|
* Clear a timeout using it's ID.
|
|
|
|
* @param {number} intervalID The ID of timeout to remove. The timeout
|
|
|
|
* ID is given as the return value in Tone.Transport.setTimeout.
|
|
|
|
* @return {boolean} true if the timeout was removed
|
2015-07-14 01:58:20 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
Tone.Transport.prototype.clearTimeout = function(id){
|
|
|
|
console.warn("This method is deprecated. Use Tone.Transport.cancel instead.");
|
|
|
|
return Tone.Transport.cancel(id);
|
2015-07-14 01:58:20 +00:00
|
|
|
};
|
2014-04-11 23:17:01 +00:00
|
|
|
|
2014-06-16 05:44:00 +00:00
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* @deprecated Use Tone.Note instead.
|
|
|
|
* Timeline events are synced to the timeline of the Tone.Transport.
|
|
|
|
* Unlike Timeout, Timeline events will restart after the
|
|
|
|
* Tone.Transport has been stopped and restarted.
|
2014-06-23 18:20:16 +00:00
|
|
|
*
|
2015-08-17 00:31:11 +00:00
|
|
|
* @param {function} callback
|
|
|
|
* @param {Time} time
|
|
|
|
* @return {number} the id for clearing the transportTimeline event
|
|
|
|
* @example
|
|
|
|
* //trigger the start of a part on the 16th measure
|
|
|
|
* Tone.Transport.setTimeline(function(time){
|
|
|
|
* part.start(time);
|
|
|
|
* }, "16m");
|
2015-02-26 16:26:23 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
Tone.Transport.prototype.setTimeline = function(callback, time){
|
|
|
|
console.warn("This method is deprecated. Use Tone.Transport.schedule instead.");
|
|
|
|
return Tone.Transport.schedule(callback, time);
|
2014-06-17 22:46:24 +00:00
|
|
|
};
|
2014-04-11 23:17:01 +00:00
|
|
|
|
2015-07-14 01:58:20 +00:00
|
|
|
/**
|
2015-08-17 00:31:11 +00:00
|
|
|
* @deprecated Use Tone.Note instead.
|
|
|
|
* Clear the timeline event.
|
|
|
|
* @param {number} id
|
|
|
|
* @return {boolean} true if it was removed
|
2015-07-14 01:58:20 +00:00
|
|
|
*/
|
2015-08-17 00:31:11 +00:00
|
|
|
Tone.Transport.prototype.clearTimeline = function(id){
|
|
|
|
console.warn("This method is deprecated. Use Tone.Transport.cancel instead.");
|
|
|
|
return Tone.Transport.cancel(id);
|
2015-07-14 01:58:20 +00:00
|
|
|
};
|
|
|
|
|
2015-08-17 00:31:11 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// INITIALIZATION
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2014-06-16 05:44:00 +00:00
|
|
|
|
2014-09-14 19:34:17 +00:00
|
|
|
var TransportConstructor = Tone.Transport;
|
2014-08-29 20:36:31 +00:00
|
|
|
|
2014-07-30 17:54:55 +00:00
|
|
|
Tone._initAudioContext(function(){
|
2014-10-16 04:49:31 +00:00
|
|
|
if (typeof Tone.Transport === "function"){
|
|
|
|
//a single transport object
|
|
|
|
Tone.Transport = new Tone.Transport();
|
|
|
|
} else {
|
|
|
|
//stop the clock
|
|
|
|
Tone.Transport.stop();
|
2015-08-17 00:31:11 +00:00
|
|
|
//get the previous values
|
|
|
|
var prevSettings = Tone.Transport.get();
|
|
|
|
//destory the old transport
|
|
|
|
Tone.Transport.dispose();
|
2014-10-16 04:49:31 +00:00
|
|
|
//make new Transport insides
|
|
|
|
TransportConstructor.call(Tone.Transport);
|
2015-08-17 00:31:11 +00:00
|
|
|
//set the previous config
|
|
|
|
Tone.Transport.set(prevSettings);
|
2014-10-16 04:49:31 +00:00
|
|
|
}
|
2014-07-30 17:54:55 +00:00
|
|
|
});
|
2014-06-17 22:46:24 +00:00
|
|
|
|
2014-04-06 00:47:59 +00:00
|
|
|
return Tone.Transport;
|
|
|
|
});
|