Tone.js/Tone/core/TimelineState.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-04-18 04:36:08 +00:00
define(["Tone/core/Tone", "Tone/core/Timeline", "Tone/type/Type"], function (Tone) {
2015-08-17 02:21:54 +00:00
2015-10-21 16:11:19 +00:00
"use strict";
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 {Number} time The time to query.
2015-08-17 02:21:54 +00:00
* @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 {Number} time The time to query.
2015-08-17 02:21:54 +00:00
*/
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" : time
2015-08-17 02:21:54 +00:00
});
};
2015-08-18 20:28:55 +00:00
return Tone.TimelineState;
2015-08-17 02:21:54 +00:00
});