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

    Function sectionsFromNotes

    • Recover a piece's sections from what it repeats.

      The span is cut into equal units of unitBars bars, each unit is compared with every unit before it, and a unit alike enough to an earlier one takes that unit's label. Neighbouring units carrying the same label are then merged, so an eight-bar section built of two like four-bar units is reported as one section rather than two.

      Likeness is measured on the melodic line and on the harmonic content together — the same tune under different harmony is a variation, not a restatement — and the labels are letters in order of first appearance. Nothing beyond "this is a restatement of that" is asserted: see FormSection.label.

      A pickup belongs to the section it leads into, so material before the first bar is folded into the opening unit rather than made a section of its own.

      Parameters

      Returns FormSection[]

      The sections, in time order.

      import { sectionsFromNotes } from '@libraz/libcantus';
      const bar = (pitch: number, at: number) => ({ pitch, startBeat: at, durationBeat: 4 });
      const notes = [bar(60, 0), bar(64, 4), bar(67, 8), bar(60, 12)];
      sectionsFromNotes(notes, { unitBars: 2 }).map((section) => section.label);