ToneWithContext
internal class ↳ extends Tone
The Base class for all nodes that have an AudioContext.
Constructor
Section titled “Constructor”new ToneWithContext(context?: BaseContext)Pass in a constructor as the first argument
Parameters
- context
BaseContextoptional
new ToneWithContext(options?: Partial<ToneWithContextOptions>)Parameters
- options
Partial<ToneWithContextOptions>optional
Properties
Section titled “Properties”blockTime
Section titled “blockTime”read-only
blockTime: numberThe number of seconds of 1 processing block (128 samples)
console.log(Tone.Destination.blockTime);
sampleTime
Section titled “sampleTime”read-only
sampleTime: numberThe duration in seconds of one sample.
Methods
Section titled “Methods”get(): OptionsGet the object’s attributes.
const osc = new Tone.Oscillator(); console.log(osc.get());
Returns Options
immediate()
Section titled “immediate()”immediate(): numberReturn the current time of the Context clock without any lookAhead.
setInterval(() => {
console.log(Tone.immediate());
}, 100);Returns number
now(): numberReturn the current time of the Context clock plus the lookAhead.
setInterval(() => {
console.log(Tone.now());
}, 100);Returns number
set(props: RecursivePartial<Options>): thisSet 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
- props
RecursivePartial<Options>
Returns this
toFrequency()
Section titled “toFrequency()”toFrequency(freq: Frequency): numberConvert the input to a frequency number
const gain = new Tone.Gain();
console.log(gain.toFrequency("4n"));Parameters
- freq
Frequency
Returns number
toSeconds()
Section titled “toSeconds()”toSeconds(time?: Time): numberConvert the incoming time to seconds. This is calculated against the current TransportInstance 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
Timeoptional
Returns number
toTicks()
Section titled “toTicks()”toTicks(time?: Time | TimeClass<number, TimeBaseUnit>): numberConvert the input time into ticks
const gain = new Tone.Gain();
console.log(gain.toTicks("4n"));Parameters
- time
Time | TimeClass<number, TimeBaseUnit>optional
Returns number
getDefaults()
Section titled “getDefaults()”static
getDefaults(): ToneWithContextOptionsReturns all of the default options belonging to the class.
Returns ToneWithContextOptions
Inherited members
Section titled “Inherited members”- From
Tone: debug, version, disposed, toString()