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

    Class Duration

    An immutable written duration: the note value a score shows — a base value, its augmentation dots, and an optional tuplet ratio — and the beats it lasts. A thin convenience wrapper over the duration module's plain value.

    import { Duration } from '@libraz/libcantus';
    Duration.ofBeats(1.5).spelled; // { base: 'quarter', dots: 1 }
    Index
    • Build a duration from its parts.

      Parameters

      • base: NoteValue

        The base note value, from the whole note down to the sixty-fourth.

      • dots: number = 0

        Augmentation dots; up to four are accepted.

      • Optionaltuplet: Tuplet

        Optional tuplet ratio: { actual: 3, normal: 2 } writes three notes in the time of two.

      Returns Duration

      The duration.

      If the base value is unknown, the dot count is not an integer in 0..4, or a tuplet side is not a positive integer.

    • Spell a length in beats as the note value a score would show.

      The spelling is the conventional one: 1.5 beats is a dotted quarter rather than a quarter tied to an eighth, and a third of a beat is an eighth triplet rather than a twenty-fourth note.

      Parameters

      • beats: number

        The length in beats.

      • options: { beatUnit?: NoteValue | DurationData } = {}

        beatUnit sets what one beat is; a quarter note by default.

      Returns Duration

      The duration that spells the length.

      If the length is not positive, or — as a NoSolutionError — if no single note value spells it, as for 5 beats. Use Duration.tieChain for those.

    • Spell a length in beats as a chain of tied durations.

      A length with a single spelling comes back as a one-element chain. Anything else is broken into plain and dotted values, longest first. The chain knows nothing of barlines or beat grouping — an engraver splits further at those — and it uses no tuplets.

      Parameters

      • beats: number

        The length in beats.

      • options: { beatUnit?: NoteValue | DurationData } = {}

        beatUnit sets what one beat is; a quarter note by default.

      Returns Duration[]

      The tied durations, longest first, summing to the length.

      If the length is not positive, if the chain would exceed the generation budget, or — as a NoSolutionError — if no chain of plain and dotted values sums to it.

      import { Duration } from '@libraz/libcantus';
      Duration.tieChain(5).map((value) => value.toString()); // ['whole', 'quarter']
    • The length of the written value in beats.

      Parameters

      • options: { beatUnit?: NoteValue | DurationData } = {}

        beatUnit sets what one beat is; a quarter note by default, so a dotted quarter reads as 1.5. Pass { base: 'quarter', dots: 1 } to count in the felt beats of a compound meter.

      Returns number

      The length in beats.

      If the beat unit is not a duration the library reads.

      import { Duration } from '@libraz/libcantus';
      Duration.of('quarter', 1).beats(); // 1.5
    • Whether another duration is written identically.

      Two values of the same length are not equal unless they are written the same way: a dotted quarter and a quarter in the time of a triplet half both last 1.5 beats and are different notations.

      Parameters

      • other: Duration

        The duration to compare with.

      Returns boolean

      True when base, dots, and tuplet all match.

    • The plain duration, for JSON serialization.

      Private class fields do not serialize, so an explicit toJSON keeps JSON.stringify(duration) from collapsing to {}. The tuplet appears only on a value that carries one, which is the shape the duration module produces.

      Returns SpelledDuration

      A copy of the base value, dot count, and tuplet.

    • The written value, so a template literal or a log line reads as the duration.

      Returns string

      The base value, a dot per augmentation dot, and the tuplet ratio when it has one, e.g. 'quarter.' or 'eighth 3:2'.