2015-09-04 20:48:21 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/core/Timeline", "Tone/core/Type"], function (Tone) {
|
2015-08-17 02:21:54 +00:00
|
|
|
|
|
|
|
/**
|
2015-08-18 20:28:55 +00:00
|
|
|
* @class A Timeline State. Provides the methods: <code>setStateAtTime("state", time)</code>
|
2015-08-17 02:21:54 +00:00
|
|
|
* and <code>getStateAtTime(time)</code>.
|
|
|
|
*
|
2015-08-18 20:28:55 +00:00
|
|
|
* @extends {Tone.Timeline}
|
|
|
|
* @param {String} initial The initial state of the TimelineState.
|
2015-08-17 02:21:54 +00:00
|
|
|
* Defaults to <code>undefined</code>
|
|
|
|
*/
|
2015-08-18 20:28:55 +00:00
|
|
|
Tone.TimelineState = function(initial){
|
2015-08-17 02:21:54 +00:00
|
|
|
|
2015-08-18 20:28:55 +00:00
|
|
|
Tone.Timeline.call(this);
|
2015-08-17 02:21:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The initial state
|
|
|
|
* @private
|
|
|
|
* @type {String}
|
|
|
|
*/
|
|
|
|
this._initial = initial;
|
|
|
|
};
|
|
|
|
|
2015-08-18 20:28:55 +00:00
|
|
|
Tone.extend(Tone.TimelineState, Tone.Timeline);
|
2015-08-17 02:21:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the scheduled state scheduled before or at
|
|
|
|
* the given time.
|
|
|
|
* @param {Time} time The time to query.
|
|
|
|
* @return {String} The name of the state input in setStateAtTime.
|
|
|
|
*/
|
2015-08-18 20:28:55 +00:00
|
|
|
Tone.TimelineState.prototype.getStateAtTime = function(time){
|
2015-08-17 05:02:06 +00:00
|
|
|
var event = this.getEvent(time);
|
2015-08-17 02:21:54 +00:00
|
|
|
if (event !== null){
|
|
|
|
return event.state;
|
|
|
|
} else {
|
|
|
|
return this._initial;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the scheduled state scheduled before or at
|
|
|
|
* the given time.
|
|
|
|
* @param {String} state The name of the state to set.
|
|
|
|
* @param {Time} time The time to query.
|
|
|
|
*/
|
2015-08-18 20:28:55 +00:00
|
|
|
Tone.TimelineState.prototype.setStateAtTime = function(state, time){
|
2015-08-17 05:02:06 +00:00
|
|
|
this.addEvent({
|
2015-08-17 02:21:54 +00:00
|
|
|
"state" : state,
|
|
|
|
"time" : this.toSeconds(time)
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-18 20:28:55 +00:00
|
|
|
return Tone.TimelineState;
|
2015-08-17 02:21:54 +00:00
|
|
|
});
|