Skip to content
Tone.js

ToneWithContext

internal class ↳ extends Tone

The Base class for all nodes that have an AudioContext.

new ToneWithContext(context?: BaseContext)

Pass in a constructor as the first argument

Parameters

new ToneWithContext(options?: Partial<ToneWithContextOptions>)

Parameters

read-only

context: BaseContext

The context belonging to the node.

read-only

blockTime: number

The number of seconds of 1 processing block (128 samples)

console.log(Tone.Destination.blockTime);

read-only

sampleTime: number

The duration in seconds of one sample.

get(): Options

Get the object’s attributes.

const osc = new Tone.Oscillator();
console.log(osc.get());

Returns Options

immediate(): number

Return the current time of the Context clock without any lookAhead.

setInterval(() => {
	console.log(Tone.immediate());
}, 100);

Returns number

now(): number

Return the current time of the Context clock plus the lookAhead.

setInterval(() => {
	console.log(Tone.now());
}, 100);

Returns number

set(props: RecursivePartial<Options>): this

Set multiple properties at once with an object.

const filter = new Tone.Filter().toDestination();
// set values using an object
filter.set({
	frequency: "C6",
	type: "highpass"
});
const player = new Tone.Player("https://tonejs.github.io/audio/berklee/Analogsynth_octaves_highmid.mp3").connect(filter);
player.autostart = true;

Parameters

Returns this

toFrequency(freq: Frequency): number

Convert the input to a frequency number

const gain = new Tone.Gain();
console.log(gain.toFrequency("4n"));

Parameters

Returns number

toSeconds(time?: Time): number

Convert the incoming time to seconds. This is calculated against the current TransportClass bpm

const gain = new Tone.Gain();
setInterval(() => console.log(gain.toSeconds("4n")), 100);
// ramp the tempo to 60 bpm over 30 seconds
Tone.getTransport().bpm.rampTo(60, 30);

Parameters

  • time Time optional

Returns number

toTicks(time?: Time | TimeClass<number, TimeBaseUnit>): number

Convert the input time into ticks

const gain = new Tone.Gain();
console.log(gain.toTicks("4n"));

Parameters

Returns number

static

getDefaults(): ToneWithContextOptions

Returns all of the default options belonging to the class.

Returns ToneWithContextOptions