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 ( [
inputs
= 1 ] , [
outputs
= 1 ] )
inputs

the number of input nodes

type: number
default: 1
outputs

the number of output nodes

type: number
default: 1

Members

.context

↝ AudioContext #

The audio context.

</>

Methods

.toTicks ( )

#
time
type: Time
↪ returns Ticks

the time in ticks

Convert a time representation into ticks.

</>

.connect ( )

#
outputNum

optionally which output to connect from

type: number
default: 0
inputNum

optionally which input to connect to

type: number
default: 0
↪ returns Tone

this

connect the output of a ToneNode to an AudioParam, AudioNode, or ToneNode

</>

.connectSeries ( )

#
nodes
↪ returns Tone

this

connect together all of the arguments in series

</>

.createInsOuts ( )

#
input

The number of inputs

type: Number
outputs

The number of outputs

type: Number
optional
↪ returns Tone

this

Create input and outputs for this object.

</>

.dbToGain ( )

#
db
↪ returns Number

Convert decibels into gain.

</>

.defaultArg ( )

#
given
type: *
fallback
type: *
↪ returns *

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 ( )

#
output

Either the output index to disconnect if the output is an array, or the node to disconnect from.

↪ returns Tone

this

disconnect the output

</>

.dispose ( )

#
↪ returns Tone

this

disconnect and dispose

</>

.equalPowerScale ( )

#
percent

(0-1)

↪ returns Number

output gain (0-1)

Equal power gain scale. Good for cross-fading.

</>

.fan ( )

#
nodes
↪ returns Tone

this

connect the output of this node to the rest of the nodes in parallel.

</>

.gainToDb ( )

#
gain

(0-1)

type: Number
↪ returns Decibels

Convert gain to decibels.

</>

.get ( )

#
params

the parameters to get, otherwise will return all available.

↪ returns Object

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 ( )

#
interval

the number of semitones above the base note

↪ returns number

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 ( )

#
arg

the argument to test

type: *
↪ returns boolean

true if the arg is an array

Test if the argument is an Array

</>

.isBoolean ( )

#
arg

the argument to test

type: *
↪ returns boolean

true if the arg is a boolean

Test if the argument is a boolean.

</>

.isFunction ( )

#
arg

the argument to test

type: *
↪ returns boolean

true if the arg is a function

test if the arg is a function

</>

.isNumber ( )

#
arg

the argument to test

type: *
↪ returns boolean

true if the arg is a number

Test if the argument is a number.

</>

.isObject ( )

#
arg

the argument to test

type: *
↪ returns boolean

true if the arg is an object literal.

Test if the given argument is an object literal (i.e. {});

</>

.isString ( )

#
arg

the argument to test

type: *
↪ returns boolean

true if the arg is a string

Test if the argument is a string.

</>

.isUndef ( )

#
arg

the argument to test

type: *
↪ returns boolean

true if the arg is undefined

test if the arg is undefined

</>

.noGC ( )

#
↪ returns Tone

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 ( )

#
↪ returns Number

the currentTime from the AudioContext

Return the current time of the AudioContext clock.

</>

.optionsObject ( )

#
values

the ‘arguments’ object of the function

type: Array
keys

the names of the arguments as they should appear in the options object

type: Array
defaults

optional defaults to mixin to the returned options object

type: Object
optional
↪ returns 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 ( )

#
channelName

A named channel to send the signal to.

type: string
input

If no input is selected, the input of the current node is chosen.

optional
↪ returns Tone

this

Recieve the input from the desired channelName to the input

EXAMPLE

reverbEffect.receive("reverb");
</>

.send ( )

#
channelName

A named channel to send the signal to.

type: string
amount

The amount of the source to send to the bus.

↪ returns GainNode

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 ( )

#
params
value
type: number
optional
rampTime
type: Time
optional
↪ returns Tone

this

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 ( )

#
freq
↪ returns Hertz

the frequency in hertz

Convert a frequency representation into a number.

</>

.toMaster ( )

#
↪ returns Tone

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 ( )

#
time
type: Time
↪ returns Seconds
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)
</>

.toString ( )

#
↪ returns string

returns the name of the class as a string

</>

.chain ( )

#
nodes
↪ returns Tone

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 ( )

#
child
parent

(optional) parent to inherit from if no parent is supplied, the child will inherit from Tone

optional

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

</>

.noOp ( )

#

An empty function.

</>

.now ( )

#
↪ returns Number

the currentTime from the AudioContext

Return the current time of the AudioContext clock.

</>

.setContext ( )

#
ctx

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.

</>
docs generated Sep 15 2019