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

    Function durationToSeconds

    • Duration in seconds of a span of beats.

      Equal to the difference of two beatsToSeconds calls — the integral is additive, so that reading is exact — but integrated over the span directly, so a short note late in a long piece does not lose precision to the subtraction of two large elapsed times.

      Parameters

      • startBeat: number

        Where the span begins, in quarter-note beats; a pickup starts before the map's first event and is measured like any other span.

      • lengthBeats: number

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

      • map: TempoMap

        The tempo map.

      Returns number

      The span's duration in seconds, never negative.

      If the map is malformed or the length is negative.

      import { durationToSeconds } from '@libraz/libcantus';
      const map = [{ startBeat: 0, bpm: 120 }, { startBeat: 4, bpm: 60 }];
      durationToSeconds(2, 4, map); // 3 = 2 beats at 120 + 2 beats at 60