The model statement.
The statement to name against it.
OptionalkeyLike: SpelledKeyLike
Key context for the tonal reading. Without one that reading is unavailable, and a statement holding only diatonically is left unnamed unless its interval pattern also fits a member of the retrograde family, in which case it is named there: a triad restated a degree higher swaps two adjacent interval sizes, which is what a retrograde inversion does to it as well, and equal note values read the same way round in both directions, so the notes alone cannot separate the two. A key separates them.
The relation, or null when the two stand in none.
import { majorKey, motifFromNotes, relateMotifs } from '@libraz/libcantus';
const model = motifFromNotes([
{ pitch: 60, startBeat: 0, durationBeat: 1 },
{ pitch: 62, startBeat: 1, durationBeat: 1 },
{ pitch: 64, startBeat: 2, durationBeat: 1 },
]);
const answer = motifFromNotes([
{ pitch: 62, startBeat: 3, durationBeat: 1 },
{ pitch: 64, startBeat: 4, durationBeat: 1 },
{ pitch: 65, startBeat: 5, durationBeat: 1 },
]);
relateMotifs(model, answer, majorKey(0))?.kind; // 'tonalTransposition'
Name how two statements of a motif relate.
The two are compared as shapes, not as pitches: the interval sequences say which transformations could name the pair and the onset gaps say which of them does, so a statement a fourth higher in doubled note values is recognised for what it is, and a cell that reads as both an inversion and a retrograde is named by the way its rhythm runs rather than by which name came to hand first. A pair whose rhythms correspond in neither direction — the same way round for a repetition or a transposition, the model played backwards for a retrograde, note values and all — is not a transformation of the motif but a different figure, and answers null; melodicSimilarity is what scores those.
With a
keyin hand the search also asks whether the second statement is the first moved by scale degrees rather than by semitones. That is the tonal answer to the real one, and the two are kept apart: a real transposition keeps every interval literally, a tonal one lets the key resize them, so a subject answered a step higher reads as'transposition'when its major second stays major and as'tonalTransposition'when the scale turns it minor.