TimeClass < Type ,  Unit >

TimeClass is a primitive type for encoding and decoding Time values. TimeClass can be passed into the parameter of any method which takes time as an argument.


const time = Tone.Time("4n"); // a quarter note

Hierarchy

Constructor

new TimeClass (
context:BaseContext ,

The context associated with the time value. Used to computeTransport and context-relative timing.

value?:TimeValue ,

The time value as a number, string or object

units?:Unit

Unit values

) => TimeClass

Properties

debug #

boolean

Set this debug flag to log all events that happen in this class.

defaultUnits #

Unit

The default units

disposed #

readonly boolean

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.

name #

string

static version #

string

The version number semver

Methods

dispose #

disconnect and dispose.

dispose ( ) => this

fromType #

Coerce a time type into this units type.

fromType (
type:TimeBaseClass<any , any >

Any time type units

) => this

static getDefaults #

Returns all of the default options belonging to the class.

getDefaults ( ) => BaseToneOptions

quantize #

Quantize the time by the given subdivision. Optionally add a percentage which will move the time value towards the ideal quantized value by that percentage.


Tone.Time(21).quantize(2); // returns 22
Tone.Time(0.6).quantize("4n", 0.5); // returns 0.55
quantize (
subdiv:Time ,

The subdivision to quantize to

percent= 1:number

Move the time value towards the quantized value by a percentage.

) => Type

toBarsBeatsSixteenths #

Return the time encoded as Bars:Beats:Sixteenths.

toBarsBeatsSixteenths ( ) => BarsBeatsSixteenths

toFrequency #

Return the value in hertz

toFrequency ( ) => Hertz

toMidi #

Return the value as a midi note.

toMidi ( ) => MidiNote

toMilliseconds #

Return the time in milliseconds.

toMilliseconds ( ) => Milliseconds

toNotation #

Convert a Time to Notation. The notation values are will be the closest representation between 1m to 128th note.


// if the Transport is at 120bpm:
Tone.Time(2).toNotation(); // returns "1m"
toNotation ( ) => Subdivision

toSamples #

Return the time in samples

toSamples ( ) => Samples

toSeconds #

Return the time in seconds.

toSeconds ( ) => Seconds

toString #

Convert the class to a string


const osc = new Tone.Oscillator();
console.log(osc.toString());
toString ( ) => string

toTicks #

Return the time in ticks.

toTicks ( ) => Ticks

valueOf #

Evaluate the time value. Returns the time in seconds.

valueOf ( ) => Type