Tone.js/Tone/core/SchedulableState.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-08-17 02:21:54 +00:00
define(["Tone/core/Tone", "Tone/core/Schedulable", "Tone/core/Types"], function (Tone) {
/**
* @class A Schedulable State. Provides the methods: <code>setStateAtTime("state", time)</code>
* and <code>getStateAtTime(time)</code>.
*
* @extends {Tone.Schedulable}
* @param {String} initial The initial state of the SchedulableState.
* Defaults to <code>undefined</code>
*/
Tone.SchedulableState = function(initial){
Tone.Schedulable.call(this);
/**
* The initial state
* @private
* @type {String}
*/
this._initial = initial;
};
Tone.extend(Tone.SchedulableState, Tone.Schedulable);
/**
* 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.
*/
Tone.SchedulableState.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.
*/
Tone.SchedulableState.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)
});
};
return Tone.SchedulableState;
});