@libraz/libcantus - v1.1.0
    Preparing search index...

    Class Tempo

    An immutable constant tempo, in quarter-note beats per minute, and the conversions it settles: beats to wall-clock seconds and back, and beats to MIDI ticks and back.

    One tempo, not a piece's tempo over time: a piece that changes tempo is described by a tempo map, which the tempo module's own functions read.

    import { Tempo } from '@libraz/libcantus';
    Tempo.of(120).secondsAt(16); // 8
    Index
    • Build a tempo from a beats-per-minute marking.

      Parameters

      • bpm: number

        Quarter-note beats per minute.

      Returns Tempo

      The tempo.

      If the marking is not a positive, finite number the library holds.

    • Wall-clock seconds from the downbeat to a position.

      A position before the downbeat reports negative elapsed time: a pickup sounds before it, and asking when it sounds is a fair question.

      Parameters

      • beat: number

        Position in quarter-note beats.

      Returns number

      Elapsed seconds, 0 at beat 0 and negative before it.

      If the position is not finite.

    • The position reached after a number of seconds — the inverse of Tempo.secondsAt.

      Parameters

      • seconds: number

        Elapsed seconds from the downbeat; negative for a position before it, such as a pickup.

      Returns number

      The position in quarter-note beats.

      If the elapsed time is not finite.

      import { Tempo } from '@libraz/libcantus';
      Tempo.of(90).beatAtSeconds(4); // 6
    • Duration in seconds of a span of beats.

      The tempo is constant, so the span is measured from the downbeat: where it begins cannot change how long it lasts.

      Parameters

      • lengthBeats: number

        How long the span lasts, in quarter-note beats.

      Returns number

      The span's duration in seconds.

      If the length is negative or not finite.

    • Convert quarter-note beats to MIDI ticks, rounded to the nearest tick.

      Parameters

      • beat: number

        Position or length in quarter-note beats.

      • ppq: number

        Pulses (ticks) per quarter note, e.g. 96, 480, or 960.

      Returns number

      The whole tick count, negative before the first downbeat.

      If the position is not finite or ppq is not a positive integer.

    • Convert MIDI ticks to quarter-note beats.

      Parameters

      • ticks: number

        Whole tick count, negative before the first downbeat.

      • ppq: number

        Pulses (ticks) per quarter note, e.g. 96, 480, or 960.

      Returns number

      The position or length in quarter-note beats.

      If ticks is not an integer or ppq is not a positive integer.

    • Whether another tempo carries the same marking.

      Parameters

      • other: Tempo

        The tempo to compare with.

      Returns boolean

      True when both name the same beats per minute.

    • The plain tempo value, for JSON serialization.

      Private class fields do not serialize, so an explicit toJSON keeps JSON.stringify(tempo) from collapsing to {}.

      Returns TempoData

      A copy of the marking.

    • The marking, so a template literal or a log line reads as the tempo.

      Returns string

      The marking, e.g. '120 bpm'.