The notes to analyze (any number of tracks, flattened).
Analysis options; see ChordTimelineOptions.
The inferred timeline, the key used, and per-segment confidences.
import { chordTimelineFromNotes } from '@libraz/libcantus';
const notes = [
{ pitch: 60, startBeat: 0, durationBeat: 2 }, // C
{ pitch: 64, startBeat: 0, durationBeat: 2 }, // E
{ pitch: 67, startBeat: 0, durationBeat: 2 }, // G
];
const { timeline, key } = chordTimelineFromNotes(notes);
timeline.at(0); // the chord inferred over beat 0, or null
Infer a chord timeline from raw multi-track notes.
The span
[0, totalBeats)is sliced intoharmonicRhythm-beat windows; each window's chord is inferred from a pitch-class weight histogram of the notes overlapping it (weight = overlap duration x velocity x metric-accent bonus for onsets in the window). Adjacent windows carrying the identical chord are merged into one segment; windows with no notes produce no segment, soat(beat)returns null there. Each segment carries a confidence in [0, 1]: the fraction of the window weight explained by chord tones, reduced when the match is inexact, and duration-weighted across merged windows.Notes with a zero or negative duration never sound, so they are dropped at ingest: they contribute to neither the key inference, the span, nor any window's histogram.