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
- transportTimeToSeconds
- connect
- connectParallel
- connectSeries
- dbToGain
- defaultArg
- disconnect
- dispose
- equalPowerScale
- fan
- frequencyToNote
- frequencyToSeconds
- fromUnits
- gainToDb
- get
- intervalToFrequencyRatio
- isArray
- isBoolean
- isFrequency
- isFunction
- isNumber
- isObject
- isString
- isUndef
- midiToFrequency
- midiToNote
- noGC
- notationToSeconds
- noteToFrequency
- noteToMidi
- now
- optionsObject
- receive
- samplesToSeconds
- secondsToFrequency
- secondsToSamples
- secondsToTransportTime
- send
- set
- ticksToSeconds
- toFrequency
- toMaster
- toNotation
- toSamples
- toSeconds
- toString
- toTicks
- toTransportTime
- toUnits
- chain
Members
Methods
.transportTimeToSeconds ( )
#seconds
convert transportTime into seconds. ie: 4:2:3 == 4 measures + 2 quarters + 3 sixteenths
.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
.connectParallel ( )
#this
fan out the connection from the first argument to the rest of the arguments
.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.
.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.
.frequencyToNote ( )
#Convert a frequency to a note name (i.e. A4, C#5).
.frequencyToSeconds ( )
#Convert a frequency into seconds. Accepts numbers and strings: i.e. “10hz” or 10 both return 0.1.
.fromUnits ( )
#Convert the given value from the type specified by units into a number.
.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); // returns 1
tone.intervalToFrequencyRatio(12); // returns 2.isArray ( )
#Test if the argument is an Array
.isBoolean ( )
#Test if the argument is a boolean.
.isFrequency ( )
#Test if the input is in the format of number + hz i.e.: 10hz
.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
.midiToFrequency ( )
#Convert a MIDI note to frequency value.
EXAMPLE
tone.midiToFrequency(57); // returns 440.midiToNote ( )
#Convert a midi note number into a note name.
EXAMPLE
tone.midiToNote(60); // returns "C3".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
.notationToSeconds ( )
#convert notation format strings to seconds
.noteToFrequency ( )
#Convert a note name to frequency.
EXAMPLE
var freq = tone.noteToFrequency("A4"); //returns 440.now ( )
#the currentTime from the AudioContext
Return the current time of the clock + a single buffer frame. If this value is used to schedule a value to change, the earliest it could be scheduled is the following frame.
.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");.samplesToSeconds ( )
#Convert a sample count to seconds.
.secondsToFrequency ( )
#Convert a number in seconds to a frequency.
.secondsToSamples ( )
#Convert from seconds to samples.
.secondsToTransportTime ( )
#Convert seconds to transportTime in the form “measures:quarters:sixteenths”
.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);.ticksToSeconds ( )
#Convert ticks into seconds
.toFrequency ( )
#if passed in, this number will be used for all ‘now’ relative timings
the frequency in hertz
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();.toNotation ( )
#Convert a Time to Notation. Values will be thresholded to the nearest 128th note.
.toSeconds ( )
#if passed in, this number will be used for all ‘now’ relative timings
| 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 TransportTime: 2:4:1 (measure:quarters:sixteens) Now Relative: +3n Math: 3n+16n or even complicated expressions ((3n*2)/6 + 1) |
.toTicks ( )
#Convert the time representation into ticks. Now-Relative timing will be relative to the current Tone.Transport.ticks.
.toUnits ( )
#Convert a number to the specified units.
.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
.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.