Tone.js/Tone/source/Source.js

104 lines
2 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/core/Transport", "Tone/core/Master"], function(Tone){
"use strict";
2014-06-16 01:00:22 +00:00
/**
2014-07-20 22:17:24 +00:00
* @class Base class for sources.
* Sources have start/stop/pause and
* the ability to be synced to the
* start/stop/pause of Tone.Transport.
2014-06-19 05:40:16 +00:00
*
2014-06-16 01:00:22 +00:00
* @constructor
* @extends {Tone}
*/
Tone.Source = function(){
//unlike most ToneNodes, Sources only have an output and no input
Tone.call(this, 0, 1);
2014-06-19 05:40:16 +00:00
/**
* @type {Tone.Source.State}
2015-02-01 20:48:20 +00:00
* @readOnly
2014-06-19 05:40:16 +00:00
*/
this.state = Tone.Source.State.STOPPED;
2014-06-16 01:00:22 +00:00
};
Tone.extend(Tone.Source);
/**
* @abstract
* @param {Tone.Time} time
*/
Tone.Source.prototype.start = function(){};
/**
* @abstract
* @param {Tone.Time} time
*/
Tone.Source.prototype.stop = function(){};
2014-06-19 05:40:16 +00:00
2014-06-16 01:00:22 +00:00
/**
* @abstract
* @param {Tone.Time} time
*/
2014-06-19 05:40:16 +00:00
Tone.Source.prototype.pause = function(time){
//if there is no pause, just stop it
this.stop(time);
};
/**
* sync the source to the Transport
2014-06-25 16:47:47 +00:00
*
2014-12-02 06:42:08 +00:00
* @param {Tone.Time} [delay=0] delay time before starting the source
2014-06-19 05:40:16 +00:00
*/
2014-06-25 16:47:47 +00:00
Tone.Source.prototype.sync = function(delay){
2014-07-30 19:12:47 +00:00
Tone.Transport.syncSource(this, delay);
2014-06-19 05:40:16 +00:00
};
/**
* unsync the source to the Transport
*/
Tone.Source.prototype.unsync = function(){
2014-07-30 19:12:47 +00:00
Tone.Transport.unsyncSource(this);
2014-06-19 05:40:16 +00:00
};
2014-06-16 01:00:22 +00:00
/**
* gets the setVolume method from {@link Tone.Master}
* @method
2014-06-16 01:00:22 +00:00
*/
Tone.Source.prototype.setVolume = Tone.Master.setVolume;
2014-06-16 01:00:22 +00:00
/**
* gets the getVolume method from {@link Tone.Master}
* @method
*/
Tone.Source.prototype.getVolume = Tone.Master.getVolume;
/**
* clean up
* @private
*/
Tone.Source.prototype._dispose = function(){
this.state = null;
};
/**
* the volume of the source
* @memberOf Tone.Source#
* @type {number}
* @name volume
*/
Tone._defineGetterSetter(Tone.Source, "volume");
2014-06-19 05:40:16 +00:00
/**
* @enum {string}
*/
Tone.Source.State = {
STARTED : "started",
PAUSED : "paused",
STOPPED : "stopped",
SYNCED : "synced"
};
2014-06-16 01:00:22 +00:00
return Tone.Source;
});