Articles: key by label across subtypes, scope per property, FO toggle widget
A single article label (e.g. 'f') may emit on multiple `articles.<subtype>`
lines — `defaults` today, `overwrites` planned — with disjoint property
sets that apply at different stages. Model now merges those emissions:
{ name: 'f', properties: [{ name, value, scope: 'defaults'|'overwrites' }] }
Per-label entries in the AR pane show a property-count breakdown
(`f (1 defaults, 2 overwrites)`). The Article FO pane lists each property
with a `(O-) default` / `(-O) overwrite` toggle — click flips the scope
and marks the score dirty. ASCII glyph mimics a physical switch position
so the active scope is visible at a glance.
Fixture tests cover both the existing single-subtype shape and a synthetic
two-subtype merge (177 assertions total).
This commit is contained in:
@@ -172,7 +172,7 @@ export function buildModel(rawTree) {
|
||||
break;
|
||||
default:
|
||||
if (node.parentSlot === 'articles') {
|
||||
score.articles.push(buildArticle(node));
|
||||
mergeArticleEntry(score, node);
|
||||
} else {
|
||||
score[node.slot] = buildGeneric(node);
|
||||
}
|
||||
@@ -182,6 +182,24 @@ export function buildModel(rawTree) {
|
||||
return score;
|
||||
}
|
||||
|
||||
// Articles are keyed by label. The AST emits one line per (label, subtype)
|
||||
// — e.g. `articles.defaults 'f'` and (future) `articles.overwrites 'f'`.
|
||||
// We merge them into one entry per label whose properties carry the scope
|
||||
// of their originating subtype, so the UI can toggle scope per property.
|
||||
function mergeArticleEntry(score, node) {
|
||||
const name = node.positionals[0];
|
||||
let entry = score.articles.find(a => a.name === name);
|
||||
if (!entry) {
|
||||
entry = { type: 'article', name, properties: [] };
|
||||
score.articles.push(entry);
|
||||
}
|
||||
const scope = node.slot; // 'defaults' | 'overwrites' | future subtype
|
||||
for (const [key, value] of Object.entries(node.props)) {
|
||||
entry.properties.push({ name: key, value, scope });
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
function buildTuning(node) {
|
||||
const t = { type: 'tuning', base: node.props.base, scales: {}, chords: {}, frequencyFactors: null };
|
||||
for (const child of node.children) {
|
||||
@@ -199,15 +217,6 @@ function buildTuning(node) {
|
||||
return t;
|
||||
}
|
||||
|
||||
function buildArticle(node) {
|
||||
return {
|
||||
type: 'article',
|
||||
subtype: node.slot,
|
||||
name: node.positionals[0],
|
||||
props: { ...node.props },
|
||||
};
|
||||
}
|
||||
|
||||
function buildInstrument(node) {
|
||||
const instr = {
|
||||
type: 'instrument',
|
||||
|
||||
@@ -153,6 +153,29 @@ export const PaneFO = {
|
||||
? h(EnvelopeEditor, { basicProperties: node.basicProperties, onChange })
|
||||
: null,
|
||||
);
|
||||
} else if (node.type === 'article') {
|
||||
const markDirty = () => props.store.markDirty();
|
||||
const SCOPES = ['defaults', 'overwrites'];
|
||||
const scopeLabel = s => s === 'defaults' ? '(O-) default' : '(-O) overwrite';
|
||||
children.push(
|
||||
h('h4', H4, `Article: ${node.name}`),
|
||||
h('ul', { class: 'se-article-props', style: 'list-style:none;padding:0;margin:0' },
|
||||
node.properties.map((p, idx) =>
|
||||
h('li', { key: idx, style: 'display:flex;gap:0.5rem;align-items:center;padding:0.25rem 0' }, [
|
||||
h('span', { style: 'flex:1' }, `${p.name} = ${p.value}`),
|
||||
h('button', {
|
||||
class: ['se-scope-toggle', `scope-${p.scope}`],
|
||||
style: 'font-family:monospace;min-width:8em',
|
||||
onClick: () => {
|
||||
const i = SCOPES.indexOf(p.scope);
|
||||
p.scope = SCOPES[(i + 1) % SCOPES.length];
|
||||
markDirty();
|
||||
},
|
||||
}, scopeLabel(p.scope)),
|
||||
])
|
||||
)
|
||||
),
|
||||
);
|
||||
} else if (node.type === 'bar') {
|
||||
const markBarDirty = () => { node.isDirty = true; props.store.markDirty(); };
|
||||
children.push(
|
||||
|
||||
@@ -43,9 +43,13 @@ export function getKindGroups(node) {
|
||||
}
|
||||
|
||||
if ((node.articles ?? []).length) {
|
||||
groups.push({ kind: 'articles', items: node.articles.map(a => ({
|
||||
kind: 'articles', node: a, label: `${a.subtype}: ${a.name}`, hasChildren: false,
|
||||
}))});
|
||||
groups.push({ kind: 'articles', items: node.articles.map(a => {
|
||||
const counts = a.properties.reduce((acc, p) => {
|
||||
acc[p.scope] = (acc[p.scope] ?? 0) + 1; return acc;
|
||||
}, {});
|
||||
const suffix = Object.entries(counts).map(([s, n]) => `${n} ${s}`).join(', ');
|
||||
return { kind: 'articles', node: a, label: `${a.name} (${suffix})`, hasChildren: false };
|
||||
})});
|
||||
}
|
||||
|
||||
if (node.bars.length) {
|
||||
|
||||
Reference in New Issue
Block a user