Skip to content
Tone.js

Unit

namespace

interface UnitMap

Map the unit name to a unit value

type AudioRange = number

A number that is between [-1, 1]

type BarsBeatsSixteenths = `${number}:${number}:${number}`

A colon-separated representation of time in the form of Bars:Beats:Sixteenths.

type BPM = number

Beats per minute

type Cents = number

A Cent is 1/100th of a semitone. e.g. a value of 50 cents would be halfway between two intervals.

type Decibels = number

A number used to measure the intensity of a sound on a logarithmic scale.

type Degrees = number

Angle between 0 and 360.

type Frequency = Subdivision | Note | string | Hertz

Frequency can be described similar to time, except ultimately the values are converted to frequency instead of seconds. A number is taken literally as the value in hertz. Additionally any of the Time encodings can be used. Note names in the form of NOTE OCTAVE (i.e. C4) are also accepted and converted to their frequency value.

type GainFactor = number

A number representing the multiplication factor applied to a signal

type Hertz = number

Hertz are a frequency representation defined as one cycle per second.

type Interval = number

Half-step note increments, i.e. 12 is an octave above the root. and 1 is a half-step up.

type MidiNote = IntegerRange<128>

A number representing a midi note. Integers between 0-127

type Milliseconds = number

One millisecond is a thousandth of a second.

type NormalRange = number

A number that is between [0, 1]

type Note = `${Letter}${Accidental}${Octave}`

A note in Scientific pitch notation. The pitch class + octave number e.g. “C4”, “D#3”, “G-1”

type Positive = number

A number greater than or equal to 0.

type PowerOfTwo = number

A value which is a power of 2

type Radians = number

Angle between 0 and 2 * PI.

type Samples = number

Sampling is the reduction of a continuous signal to a discrete signal. Audio is typically sampled 44100 times per second.

type Seconds = number

A number representing a time in seconds

type Subdivision = "1m" | "1n" | "1n." | `${2 | 4 | 8 | 16 | 32 | 64 | 128 | 256}${"n" | "n." | "t"}` | "0"

Represents a subdivision of a measure. The number represents the subdivision. “t” represents a triplet. A “.” add a half. e.g. “4n” is a quarter note, “4t” is a quarter note triplet, and “4n.” is a dotted quarter note.

type Ticks = number

Ticks are the basic subunit of the Transport. They are the smallest unit of time that the Transport supports.

type Time = string | Seconds | TimeObject | Subdivision

Time can be described in a number of ways. Read more Time.

  • Numbers, which will be taken literally as the time (in seconds).
  • Notation, (“4n”, “8t”) describes time in BPM and time signature relative values.
  • TransportTime, (“4:3:2”) will also provide tempo and time signature relative times in the form BARS:QUARTERS:SIXTEENTHS.
  • Frequency, (“8hz”) is converted to the length of the cycle in seconds.
  • Now-Relative, (“+1”) prefix any of the above with “+” and it will be interpreted as “the current time plus whatever expression follows”.
  • Object, ({“4n” : 3, “8t” : -1}). The resulting time is equal to the sum of all of the keys multiplied by the values in the object.
  • No Argument, for methods which accept time, no argument will be interpreted as “now” (i.e. the currentTime).
type TimeObject = { [sub in Subdivision]: number }

A time object has a subdivision as the keys and a number as the values.

Tone.Time({
	"2n": 1,
	"8n": 3
}).valueOf(); // 2n + 8n * 3
type TimeSignature = number | number[]
type TransportTime = Time

TransportTime describes a position along the Transport’s timeline. It is similar to Time in that it uses all the same encodings, but TransportTime specifically pertains to the Transport’s timeline, which is startable, stoppable, loopable, and seekable. Read more

type Unit = UnitMap[keyof UnitMap]

All of the unit types

type UnitName = keyof UnitMap

All of the unit names