Tone
Tone is the base class of all other classes. It provides a lot of methods and functionality to all classes that extend it.
CONSTRUCTOR
new Tone ( [the number of input nodes
the number of output nodes
- context
Members
Methods
.toTicks ( )
#Convert a time representation into ticks.
.connect ( )
#optionally which output to connect from
optionally which input to connect to
this
connect the output of a ToneNode to an AudioParam, AudioNode, or ToneNode
.connectSeries ( )
#this
connect together all of the arguments in series
.defaultArg ( )
#If the given parameter is undefined, use the fallback. If both given and fallback are object literals, it will return a deep copy which includes all of the parameters from both objects. If a parameter is undefined in given, it will return the fallback property.
WARNING: if object is self referential, it will go into an an infinite recursive loop.
.disconnect ( )
#Either the output index to disconnect if the output is an array, or the node to disconnect from.
this
disconnect the output
.equalPowerScale ( )
#(0-1)
output gain (0-1)
Equal power gain scale. Good for cross-fading.
.fan ( )
#this
connect the output of this node to the rest of the nodes in parallel.
.get ( )
#the parameters to get, otherwise will return all available.
Get the object’s attributes. Given no arguments get will return all available object properties and their corresponding values. Pass in a single attribute to retrieve or an array of attributes. The attribute strings can also include a “.” to access deeper properties.
EXAMPLE
osc.get();
//returns {"type" : "sine", "frequency" : 440, ...etc}
EXAMPLE
osc.get("type");
//returns { "type" : "sine"}EXAMPLE
//use dot notation to access deep properties
synth.get(["envelope.attack", "envelope.release"]);
//returns {"envelope" : {"attack" : 0.2, "release" : 0.4}}
.intervalToFrequencyRatio ( )
#the number of semitones above the base note
the frequency ratio
Convert an interval (in semitones) to a frequency ratio.
EXAMPLE
tone.intervalToFrequencyRatio(0); // 1
tone.intervalToFrequencyRatio(12); // 2
tone.intervalToFrequencyRatio(-12); // 0.5.isArray ( )
#Test if the argument is an Array
.isBoolean ( )
#Test if the argument is a boolean.
.isFunction ( )
#test if the arg is a function
.isNumber ( )
#Test if the argument is a number.
.isObject ( )
#Test if the given argument is an object literal (i.e. {});
.isString ( )
#Test if the argument is a string.
.isUndef ( )
#test if the arg is undefined
.noGC ( )
#this
makes a connection to ensure that the node will not be garbage collected until ‘dispose’ is explicitly called use carefully. circumvents JS and WebAudio’s normal Garbage Collection behavior
.now ( )
#the currentTime from the AudioContext
Return the current time of the AudioContext clock.
.optionsObject ( )
#the ‘arguments’ object of the function
the names of the arguments as they should appear in the options object
optional defaults to mixin to the returned options object
the options object with the names mapped to the arguments
returns the args as an options object with given arguments mapped to the names provided. if the args given is an array containing only one object, it is assumed that that’s already the options object and will just return it.
.receive ( )
#A named channel to send the signal to.
If no input is selected, the input of the current node is chosen.
this
Recieve the input from the desired channelName to the input
EXAMPLE
reverbEffect.receive("reverb");.send ( )
#A named channel to send the signal to.
The amount of the source to send to the bus.
The gain node which connects this node to the desired channel. Can be used to adjust the levels of the send.
Send this signal to the channel name.
EXAMPLE
source.send("reverb", -12);.set ( )
#Set the parameters at once. Either pass in an object mapping parameters to values, or to set a single parameter, by passing in a string and value. The last argument is an optional ramp time which will ramp any signal values to their destination value over the duration of the rampTime.
EXAMPLE
//set values using an object
filter.set({
"frequency" : 300,
"type" : highpass
});
EXAMPLE
filter.set("type", "highpass");
EXAMPLE
//ramp to the value 220 over 3 seconds.
oscillator.set({
"frequency" : 220
}, 3);.toFrequency ( )
#Convert a frequency representation into a number.
.toMaster ( )
#this
Connect ‘this’ to the master output. Shorthand for this.connect(Tone.Master)
EXAMPLE
//connect an oscillator to the master output
var osc = new Tone.Oscillator().toMaster();.toSeconds ( )
#| Convert Time into seconds. Unlike the method which it overrides, this takes into account transporttime and musical notation. Time : 1.40 Notation: 4n | 1m | 2t Now Relative: +3n Math: 3n+16n or even complicated expressions ((3n*2)/6 + 1) |
.chain ( )
#this
Connect the output of this node to the rest of the nodes in series.
EXAMPLE
//connect a node to an effect, panVol and then to the master output
node.chain(effect, panVol, Tone.Master);
Static Methods
.extend ( )
#(optional) parent to inherit from if no parent is supplied, the child will inherit from Tone
have a child inherit all of Tone’s (or a parent’s) prototype to inherit the parent’s properties, make sure to call Parent.call(this) in the child’s constructor based on closure library’s inherit function
.now ( )
#the currentTime from the AudioContext
Return the current time of the AudioContext clock.
.setContext ( )
#The new audio context to set
Tone automatically creates a context on init, but if you are working with other libraries which also create an AudioContext, it can be useful to set your own. If you are going to set your own context, be sure to do it at the start of your code, before creating any objects.