Source
internal class ↳ extends ToneAudioNode<Options>
Base class for sources. start/stop of this.context.transport.
// Multiple state change events can be chained together,// but must be set in the correct order and with ascending times// OKstate.start().stop("+0.2");// OKstate.start().stop("+0.2").start("+0.4").stop("+0.7")// BADstate.stop("+0.2").start();// BADstate.start("+0.3").stop("+0.2");Constructor
Section titled “Constructor”new Source(options: SourceOptions)Parameters
- options
SourceOptions
Properties
Section titled “Properties”onstop
Section titled “onstop”onstop: onStopCallbackThe callback to invoke when the source is stopped.
volume
Section titled “volume”volume: Param<"decibels">The volume of the output in decibels.
const source = new Tone.PWMOscillator().toDestination(); source.volume.value = -6;
mute: booleanMute the output.
const osc = new Tone.Oscillator().toDestination().start(); // mute the output osc.mute = true;
read-only
state: BasicPlaybackStateReturns the playback state of the source, either “started” or “stopped”.
const player = new Tone.Player("https://tonejs.github.io/audio/berklee/ahntone_c3.mp3", () => {
player.start();
console.log(player.state);
}).toDestination();Methods
Section titled “Methods”start()
Section titled “start()”Start the source at the specified time. If no time is given, start the source now.
const source = new Tone.Oscillator().toDestination();
source.start("+0.5"); // starts the source 0.5 seconds from nowParameters
Returns this
stop()
Section titled “stop()”stop(time?: Time): thisStop the source at the specified time. If no time is given, stop the source now.
const source = new Tone.Oscillator().toDestination();
source.start();
source.stop("+0.5"); // stops the source 0.5 seconds from nowParameters
-
time
TimeoptionalWhen the source should be stopped.
Returns this
sync()
Section titled “sync()”sync(): thisSync the source to the Transport so that all subsequent
calls to start and stop are synced to the TransportTime
instead of the AudioContext time.
const osc = new Tone.Oscillator().toDestination(); // sync the source so that it plays between 0 and 0.3 on the Transport's timeline osc.sync().start(0).stop(0.3); // start the transport. Tone.Transport.start(); // set it to loop once a second Tone.Transport.loop = true; Tone.Transport.loopEnd = 1;
Returns this
unsync()
Section titled “unsync()”unsync(): thisUnsync the source to the Transport.
See also: sync
Returns this
getDefaults()
Section titled “getDefaults()”static
getDefaults(): SourceOptionsReturns all of the default options belonging to the class.
Returns SourceOptions
Inherited members
Section titled “Inherited members”- From
ToneWithContext: context, blockTime, sampleTime, get(), immediate(), now(), set(), toFrequency(), toSeconds(), toTicks() - From
Tone: debug, version, disposed, toString() - From
ToneAudioNode: name, channelCount, channelCountMode, channelInterpretation, numberOfInputs, numberOfOutputs, chain(), connect(), disconnect(), fan(), toDestination(), toMaster()