Tone.js/Tone/core/TimelineState.js

57 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>
2016-12-19 03:14:14 +00:00
* and <code>getValueAtTime(time)</code>.
2015-08-17 02:21:54 +00:00
*
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.
*/
2016-12-19 03:14:14 +00:00
Tone.TimelineState.prototype.getValueAtTime = function(time){
var event = this.get(time);
2015-08-17 02:21:54 +00:00
if (event !== null){
return event.state;
} else {
return this._initial;
}
};
/**
2017-06-21 14:22:10 +00:00
* Add a state to the timeline.
2015-08-17 02:21:54 +00:00
* @param {String} state The name of the state to set.
* @param {Number} time The time to query.
2017-06-21 14:22:10 +00:00
* @returns {Tone.TimelineState} this
2015-08-17 02:21:54 +00:00
*/
2015-08-18 20:28:55 +00:00
Tone.TimelineState.prototype.setStateAtTime = function(state, time){
this.add({
2015-08-17 02:21:54 +00:00
"state" : state,
"time" : time
2015-08-17 02:21:54 +00:00
});
2017-06-21 14:22:10 +00:00
return this;
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
});