A sample accurate clock which provides a callback at the given rate. While the callback is not sample-accurate (it is still susceptible to loose JS timing), the time passed in as the argument to the callback is precise. For most applications, it is better to use Tone.Transport instead of the Clock by itself since you can synchronize multiple callbacks.
import { Clock } from "tone";
// the callback will be invoked approximately once a second
// and will print the time exactly once a second apart.
const clock = new Clock(time => {
console.log(time);
}, 1);
clock.start();
The number of seconds of 1 processing block (128 samples)
The callback function to invoke at the scheduled tick.
The context belonging to the node.
Set this debug flag to log all events that happen in this class.
Indicates if the instance was disposed. 'Disposing' an instance means that all of the Web Audio nodes that were created for the instance are disconnected and freed for garbage collection.
The rate the callback function should be invoked.
The duration in seconds of one sample.
The time since ticks=0 that the Clock has been running. Accounts for tempo curves
Returns the playback state of the source, either "started", "stopped" or "paused".
The number of times the callback was invoked. Starts counting at 0 and increments after the callback was invoked.
The version number semver
Get the object's attributes.
import { Oscillator } from "tone";
const osc = new Oscillator();
console.log(osc.get());
// returns {"type" : "sine", "frequency" : 440, ...etc}
Returns all of the default options belonging to the class.
Return the elapsed seconds at the given time.
Returns the scheduled state at the given time.
import { Clock } from "tone";
const clock = new Clock();
clock.start("+0.1");
clock.getStateAtTime("+0.1"); // returns "started"
Get the time of the given tick. The second argument is when to test before. Since ticks can be set (with setTicksAtTime) there may be multiple times for a given tick value.
When to measure the tick value from.
Return the current time of the Context clock without any lookAhead.
Return the current time of the Context clock plus the lookAhead.
Set multiple properties at once with an object.
import { Filter } from "tone";
const filter = new Filter();
// set values using an object
filter.set({
frequency: 300,
type: "highpass"
});
Start the clock at the given time. Optionally pass in an offset of where to start the tick counter from.
Stop the clock. Stopping the clock resets the tick counter to 0.
import { Clock } from "tone";
const clock = new Clock(time => {
console.log(time);
}, 1);
clock.start();
// stop the clock after 10 seconds
clock.stop("+10");
Convert the input to a frequency number
Convert the incoming time to seconds
Convert the class to a string
import { Oscillator } from "tone";
const osc = new Oscillator();
console.log(osc.toString());
Convert the input time into ticks