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

.transportTimeToSeconds ( )

#
transportTime
bpm
type: BPM
optional
timeSignature
type: number
optional
↪ returns number

seconds

convert transportTime into seconds. ie: 4:2:3 == 4 measures + 2 quarters + 3 sixteenths

</>

.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

</>

.connectParallel ( )

#
nodes
↪ returns Tone

this

fan out the connection from the first argument to the rest of the arguments

</>

.connectSeries ( )

#
nodes
↪ returns Tone

this

connect together all of the arguments in series

</>

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

#
↪ 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.

</>

.frequencyToNote ( )

#
freq
type: number
↪ returns String

Convert a frequency to a note name (i.e. A4, C#5).

</>

.frequencyToSeconds ( )

#
freq
↪ returns number

Convert a frequency into seconds. Accepts numbers and strings: i.e. “10hz” or 10 both return 0.1.

</>

.fromUnits ( )

#
val

the value to convert

type: *
↪ returns Number

the number which the value should be set to

Convert the given value from the type specified by units into a number.

</>

.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); // returns 1
tone.intervalToFrequencyRatio(12); // returns 2
</>

.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.

</>

.isFrequency ( )

#
freq
type: String
↪ returns boolean

Test if the input is in the format of number + hz i.e.: 10hz

</>

.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

</>

.midiToFrequency ( )

#
midi

The midi number to convert.

type: MIDI
↪ returns Frequency

the corresponding frequency value

Convert a MIDI note to frequency value.

EXAMPLE

tone.midiToFrequency(57); // returns 440
</>

.midiToNote ( )

#
midiNumber

the midi note number

type: MIDI
↪ returns String

the note’s name and octave

Convert a midi note number into a note name.

EXAMPLE

tone.midiToNote(60); // returns "C3"
</>

.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

</>

.notationToSeconds ( )

#
notation
type: String
bpm
type: BPM
optional
timeSignature
type: number
optional
↪ returns number

convert notation format strings to seconds

</>

.noteToFrequency ( )

#
note
type: String
↪ returns number

Convert a note name to frequency.

EXAMPLE

var freq = tone.noteToFrequency("A4"); //returns 440
</>

.noteToMidi ( )

#
note

the note name (i.e. “C3”)

type: String
↪ returns MIDI

the midi value of that note

Convert a note to it’s midi value.

EXAMPLE

tone.noteToMidi("C3"); // returns 60
</>

.now ( )

#
↪ returns number

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

#
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");
</>

.samplesToSeconds ( )

#
samples
type: number
↪ returns number

Convert a sample count to seconds.

</>

.secondsToFrequency ( )

#
seconds
type: number
↪ returns number

Convert a number in seconds to a frequency.

</>

.secondsToSamples ( )

#
seconds
type: number
↪ returns number

The number of samples

Convert from seconds to samples.

</>

.secondsToTransportTime ( )

#
seconds
type: Number
bpm
type: BPM
optional
timeSignature
type: Number
optional
↪ returns TransportTime

Convert seconds to transportTime in the form “measures:quarters:sixteenths”

</>

.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);
</>

.ticksToSeconds ( )

#
ticks
type: Ticks
bpm
type: BPM
optional
↪ returns number

seconds

Convert ticks into seconds

</>

.toFrequency ( )

#
freq
now

if passed in, this number will be used for all ‘now’ relative timings

type: number
optional
↪ returns number

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

.toNotation ( )

#
time
type: Time
bpm
type: BPM
optional
timeSignature
type: number
optional
↪ returns Notation

Convert a Time to Notation. Values will be thresholded to the nearest 128th note.

</>

.toSamples ( )

#
time
type: Time
↪ returns number

convert a time into samples

</>

.toSeconds ( )

#
time
type: Time
now

if passed in, this number will be used for all ‘now’ relative timings

type: number
optional
↪ returns number
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)
</>

.toString ( )

#
↪ returns string

returns the name of the class as a string

</>

.toTicks ( )

#
time
type: Time
↪ returns Ticks

Convert the time representation into ticks. Now-Relative timing will be relative to the current Tone.Transport.ticks.

</>

.toTransportTime ( )

#
</>

.toUnits ( )

#
val

the value to convert

type: number
↪ returns number

Convert a number to the specified units.

</>

.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.

</>

.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.

</>

.startMobile ( )

#

Bind this to a touchstart event to start the audio on mobile devices.
http://stackoverflow.com/questions/12517000/no-sound-on-ios-6-web-audio-api/12569290#12569290

</>
docs generated Sep 15 2019