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

    Function compareMelodies

    • Compare two lines and say why they scored what they did.

      The metric is a normalised edit distance over the interval sequence, weighted against the same over the rhythmic profile. Intervals rather than pitches, because the same tune in another key is the same tune; edit distance rather than a step-by-step correlation, because a variant that adds a passing note or drops one still has to line up with its model, and only an alignment-based measure can do that. Substituting one interval for another costs by how far apart they are rather than a flat step, so an answer that widens a third to a fourth stays close to its model while one that replaces it with a leap does not. The rhythm carries the smaller share: a melody is recognised mostly by its pitch shape, but a figure in a wholly different rhythm is a different figure.

      Both lines are expected to be monophonic, as analyzeVoice expects a voice to be. Notes struck together are read as one event, the highest of them standing for it, so a chord is reduced to its top voice rather than read as a line of its own.

      Parameters

      Returns MelodicComparison

      The overall likeness, the two terms behind it, and a rationale.

      import { compareMelodies } from '@libraz/libcantus';
      const line = [
      { pitch: 60, startBeat: 0, durationBeat: 1 },
      { pitch: 62, startBeat: 1, durationBeat: 1 },
      { pitch: 64, startBeat: 2, durationBeat: 1 },
      ];
      compareMelodies(line, line).similarity; // 1