Class 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.

Param: val

The time value.

Param: units

The units of the value.

Example

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

Type Parameters

Hierarchy (view full)

Constructors

  • Type Parameters

    • Type extends number = number
    • Unit extends string = TimeBaseUnit

    Parameters

    • context: BaseContext

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

    • Optional value: TimeValue

      The time value as a number, string or object

    • Optional units: Unit

      Unit values

    Returns TimeClass<Type, Unit>

Properties

context: BaseContext
debug: boolean = false

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

defaultUnits: Unit = ...

The default units

name: string = "TimeClass"
version: string = version

The version number semver

Accessors

  • get disposed(): 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.

    Returns boolean

Methods

  • disconnect and dispose.

    Returns this

  • Coerce a time type into this units type.

    Parameters

    • type: TimeBaseClass<any, any>

      Any time type units

    Returns this

  • 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.

    Parameters

    • subdiv: Unit.Time

      The subdivision to quantize to

    • percent: number = 1

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

    Returns Type

    Example

    Tone.Time(21).quantize(2); // returns 22
    Tone.Time(0.6).quantize("4n", 0.5); // returns 0.55
  • Return the time encoded as Bars:Beats:Sixteenths.

    Returns `${number}:${number}:${number}`

  • Return the value as a midi note.

    Returns 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127

  • Return the time in milliseconds.

    Returns number

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

    Returns Subdivision

    Example

    // if the Transport is at 120bpm:
    Tone.Time(2).toNotation(); // returns "1m"
  • Return the time in seconds.

    Returns number

  • Convert the class to a string

    Returns string

    Example

    const osc = new Tone.Oscillator();
    console.log(osc.toString());
  • Returns all of the default options belonging to the class.

    Returns BaseToneOptions