2014-12-19 21:27:50 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/core/Transport", "Tone/core/Master"], function(Tone){
|
2014-09-04 04:41:40 +00:00
|
|
|
|
|
|
|
"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(){
|
2014-11-04 06:21:42 +00:00
|
|
|
//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
|
|
|
/**
|
2014-12-19 21:27:50 +00:00
|
|
|
* gets the setVolume method from {@link Tone.Master}
|
|
|
|
* @method
|
2014-06-16 01:00:22 +00:00
|
|
|
*/
|
2014-12-19 21:27:50 +00:00
|
|
|
Tone.Source.prototype.setVolume = Tone.Master.setVolume;
|
2014-06-16 01:00:22 +00:00
|
|
|
|
2014-09-30 04:28:48 +00:00
|
|
|
/**
|
2015-02-02 01:02:13 +00:00
|
|
|
* gets the getVolume method from {@link Tone.Master}
|
|
|
|
* @method
|
2014-09-30 04:28:48 +00:00
|
|
|
*/
|
2015-02-02 01:02:13 +00:00
|
|
|
Tone.Source.prototype.getVolume = Tone.Master.getVolume;
|
2014-09-30 04:28:48 +00:00
|
|
|
|
2014-08-24 20:24:16 +00:00
|
|
|
/**
|
2015-02-02 01:02:13 +00:00
|
|
|
* clean up
|
|
|
|
* @private
|
2014-08-24 20:24:16 +00:00
|
|
|
*/
|
2015-02-02 01:02:13 +00:00
|
|
|
Tone.Source.prototype._dispose = function(){
|
2014-08-24 20:24:16 +00:00
|
|
|
this.state = null;
|
|
|
|
};
|
|
|
|
|
2015-02-02 01:02:13 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
});
|