refactor: rename Offset.motifs to motifRefs

This commit is contained in:
c0dev0id
2026-07-06 21:11:55 +02:00
parent 7fb584d929
commit 3beaa1d2ec
3 changed files with 11 additions and 11 deletions

View File

@@ -470,14 +470,14 @@ function buildOffset(node) {
type: 'offset', type: 'offset',
tick: node.props.tick, tick: node.props.tick,
stemNotes: [], stemNotes: [],
motifs: [], motifRefs: [],
unknownProps: collectUnknownProps(node.props, new Set(['tick'])), unknownProps: collectUnknownProps(node.props, new Set(['tick'])),
}; };
for (const child of node.children) { for (const child of node.children) {
if (child.parentSlot === 'line' && child.slot === 'stem_note') if (child.parentSlot === 'line' && child.slot === 'stem_note')
offset.stemNotes.push(buildStemNote(child)); offset.stemNotes.push(buildStemNote(child));
else if (child.parentSlot === 'line' && child.slot === 'motif') else if (child.parentSlot === 'line' && child.slot === 'motif')
offset.motifs.push({ label: child.positionals[0], chord: child.props.chord ?? null }); offset.motifRefs.push({ label: child.positionals[0], chord: child.props.chord ?? null });
} }
return offset; return offset;
} }

View File

@@ -251,8 +251,8 @@ export const PaneFO = {
fields: [ fields: [
{ key: 'tick', value: node.tick, editable: false }, { key: 'tick', value: node.tick, editable: false },
{ key: 'stem notes', value: node.stemNotes.map(snLabel).join(', ') || '—', editable: false }, { key: 'stem notes', value: node.stemNotes.map(snLabel).join(', ') || '—', editable: false },
node.motifs?.length node.motifRefs?.length
? { key: 'motifs', value: node.motifs.map(m => m.chord ? `${m.label}(${m.chord})` : m.label).join(', '), editable: false } ? { key: 'motifRefs', value: node.motifRefs.map(m => m.chord ? `${m.label}(${m.chord})` : m.label).join(', '), editable: false }
: null, : null,
...unknownPropFields(node), ...unknownPropFields(node),
].filter(Boolean), ].filter(Boolean),

View File

@@ -631,11 +631,11 @@ const LM_FIXTURE = `00 bar '001P1L1M1'
`; `;
const lmOffset = buildModel(parseAstLog(LM_FIXTURE)).bars[0].voices['pi'].offsets[0]; const lmOffset = buildModel(parseAstLog(LM_FIXTURE)).bars[0].voices['pi'].offsets[0];
ok('line.motif: offset has 1 stem note', lmOffset.stemNotes.length === 1); ok('line.motif: offset has 1 stem note', lmOffset.stemNotes.length === 1);
ok('line.motif: offset.motifs has 2 entries', lmOffset.motifs.length === 2); ok('line.motif: offset.motifRefs has 2 entries', lmOffset.motifRefs.length === 2);
ok('line.motif: first motif label', lmOffset.motifs[0].label === 'coct'); ok('line.motif: first motifRef label', lmOffset.motifRefs[0].label === 'coct');
ok('line.motif: second motif label', lmOffset.motifs[1].label === 'oct'); ok('line.motif: second motifRef label', lmOffset.motifRefs[1].label === 'oct');
ok('line.motif: second motif chord', lmOffset.motifs[1].chord === 'C2'); ok('line.motif: second motifRef chord', lmOffset.motifRefs[1].chord === 'C2');
ok('line.motif: first motif chord null', lmOffset.motifs[0].chord === null); ok('line.motif: first motifRef chord null', lmOffset.motifRefs[0].chord === null);
section('stem_note.write_to and chainText'); section('stem_note.write_to and chainText');
const WT_FIXTURE = `00 bar '001P1L1M1' const WT_FIXTURE = `00 bar '001P1L1M1'
@@ -704,8 +704,8 @@ const voicesWithMotifs = model.bars.flatMap(b => Object.values(b.voices)).filter
ok('fixture voices have motif objects', voicesWithMotifs.every(v => v.motifs.every(m => typeof m === 'object' && 'label' in m))); ok('fixture voices have motif objects', voicesWithMotifs.every(v => v.motifs.every(m => typeof m === 'object' && 'label' in m)));
const offsetsWithStemNotes = model.bars.flatMap(b => Object.values(b.voices)).flatMap(v => v.offsets).filter(o => o.stemNotes.length > 0); const offsetsWithStemNotes = model.bars.flatMap(b => Object.values(b.voices)).flatMap(v => v.offsets).filter(o => o.stemNotes.length > 0);
ok('fixture offsets have stem note objects', offsetsWithStemNotes.every(o => o.stemNotes.every(sn => 'pitch' in sn && 'clauses' in sn))); ok('fixture offsets have stem note objects', offsetsWithStemNotes.every(o => o.stemNotes.every(sn => 'pitch' in sn && 'clauses' in sn)));
const offsetsWithMotifInvocations = model.bars.flatMap(b => Object.values(b.voices)).flatMap(v => v.offsets).filter(o => o.motifs?.length > 0); const offsetsWithMotifInvocations = model.bars.flatMap(b => Object.values(b.voices)).flatMap(v => v.offsets).filter(o => o.motifRefs?.length > 0);
ok('fixture offset motif invocations are objects', offsetsWithMotifInvocations.every(o => o.motifs.every(m => 'label' in m))); ok('fixture offset motif invocations are objects', offsetsWithMotifInvocations.every(o => o.motifRefs.every(m => 'label' in m)));
const stemNotesWithChainText = offsetsWithStemNotes.flatMap(o => o.stemNotes).filter(sn => sn.chainText); const stemNotesWithChainText = offsetsWithStemNotes.flatMap(o => o.stemNotes).filter(sn => sn.chainText);
ok('fixture stem notes with chain text have clauses', stemNotesWithChainText.every(sn => sn.clauses.length > 0)); ok('fixture stem notes with chain text have clauses', stemNotesWithChainText.every(sn => sn.clauses.length > 0));