Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2060f109b6 | ||
|
|
06b2bab5d3 | ||
|
|
839ea3f95c | ||
|
|
4afabea837 | ||
|
|
f318b155cc | ||
|
|
17f4529658 | ||
|
|
c8b8d03e3f |
@ -178,7 +178,6 @@ function buildInstrument(node) {
|
|||||||
isDirty: false,
|
isDirty: false,
|
||||||
variations: [],
|
variations: [],
|
||||||
basicProperties: null,
|
basicProperties: null,
|
||||||
railsbackCurve: null,
|
|
||||||
volumes: null,
|
volumes: null,
|
||||||
timbre: null,
|
timbre: null,
|
||||||
fmModulations: [],
|
fmModulations: [],
|
||||||
@ -193,9 +192,6 @@ function buildInstrument(node) {
|
|||||||
case 'character.basic_properties':
|
case 'character.basic_properties':
|
||||||
instr.basicProperties = buildBasicProperties(child);
|
instr.basicProperties = buildBasicProperties(child);
|
||||||
break;
|
break;
|
||||||
case 'RAILSBACK_CURVE.shape':
|
|
||||||
instr.railsbackCurve = buildShape(child);
|
|
||||||
break;
|
|
||||||
case 'VOLUMES.shape':
|
case 'VOLUMES.shape':
|
||||||
instr.volumes = buildShape(child);
|
instr.volumes = buildShape(child);
|
||||||
break;
|
break;
|
||||||
@ -221,6 +217,7 @@ function buildVariation(node) {
|
|||||||
labelSpecs: [],
|
labelSpecs: [],
|
||||||
subvariations: [],
|
subvariations: [],
|
||||||
spread: null,
|
spread: null,
|
||||||
|
railsbackCurve: null,
|
||||||
rawChildren: [],
|
rawChildren: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -239,6 +236,9 @@ function buildVariation(node) {
|
|||||||
case 'variation.SPREAD':
|
case 'variation.SPREAD':
|
||||||
v.spread = child.positionals;
|
v.spread = child.positionals;
|
||||||
break;
|
break;
|
||||||
|
case 'RAILSBACK_CURVE.shape':
|
||||||
|
v.railsbackCurve = buildShape(child);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
v.rawChildren.push(buildGeneric(child));
|
v.rawChildren.push(buildGeneric(child));
|
||||||
}
|
}
|
||||||
@ -267,7 +267,10 @@ function buildBasicProperties(node) {
|
|||||||
} else if (child.parentSlot === 'variation' && child.slot === 'O') {
|
} else if (child.parentSlot === 'variation' && child.slot === 'O') {
|
||||||
bp.oscillator = child.props.ref ?? child.positionals[0];
|
bp.oscillator = child.props.ref ?? child.positionals[0];
|
||||||
} else if (child.parentSlot === 'FM' && child.slot === 'modulation') {
|
} else if (child.parentSlot === 'FM' && child.slot === 'modulation') {
|
||||||
bp.fmModulations.push({ ...child.props });
|
const fm = { ...child.props };
|
||||||
|
const envChild = child.children.find(c => c.slot === 'shape');
|
||||||
|
if (envChild) fm.shape = buildShape(envChild);
|
||||||
|
bp.fmModulations.push(fm);
|
||||||
} else {
|
} else {
|
||||||
bp.rawChildren.push(buildGeneric(child));
|
bp.rawChildren.push(buildGeneric(child));
|
||||||
}
|
}
|
||||||
@ -284,13 +287,23 @@ function buildLabelSpec(node) {
|
|||||||
rawChildren: [],
|
rawChildren: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const directBpChildren = [];
|
||||||
for (const child of node.children) {
|
for (const child of node.children) {
|
||||||
if (child.parentSlot === 'variation' && child.slot === 'basic_properties') {
|
if (child.parentSlot === 'variation' && child.slot === 'basic_properties') {
|
||||||
ls.basicProperties = buildBasicProperties(child);
|
ls.basicProperties = buildBasicProperties(child);
|
||||||
|
} else if (
|
||||||
|
(child.slot === 'shape' && (child.parentSlot === 'A' || child.parentSlot === 'S' || child.parentSlot === 'R')) ||
|
||||||
|
(child.parentSlot === 'variation' && child.slot === 'O') ||
|
||||||
|
(child.parentSlot === 'FM' && child.slot === 'modulation')
|
||||||
|
) {
|
||||||
|
directBpChildren.push(child);
|
||||||
} else {
|
} else {
|
||||||
ls.rawChildren.push(buildGeneric(child));
|
ls.rawChildren.push(buildGeneric(child));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!ls.basicProperties && directBpChildren.length > 0) {
|
||||||
|
ls.basicProperties = buildBasicProperties({ children: directBpChildren });
|
||||||
|
}
|
||||||
|
|
||||||
return ls;
|
return ls;
|
||||||
}
|
}
|
||||||
@ -300,7 +313,6 @@ function buildShape(node) {
|
|||||||
type: 'shape',
|
type: 'shape',
|
||||||
length: node.props.length,
|
length: node.props.length,
|
||||||
start: node.props.start,
|
start: node.props.start,
|
||||||
z: node.props.z ?? 1,
|
|
||||||
coords: node.children
|
coords: node.children
|
||||||
.filter(c => c.slot === 'coords')
|
.filter(c => c.slot === 'coords')
|
||||||
.map(c => ({
|
.map(c => ({
|
||||||
@ -313,15 +325,9 @@ function buildShape(node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildBar(node) {
|
function buildBar(node) {
|
||||||
const id = node.positionals[0] ?? '';
|
|
||||||
const idMatch = id.match(/^(\w?)(\d+)P(\d+)L(\d+)M(\d+)$/);
|
|
||||||
const bar = {
|
const bar = {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
id,
|
id: node.positionals[0] ?? '',
|
||||||
movement: idMatch ? idMatch[1] : '',
|
|
||||||
part: idMatch ? parseInt(idMatch[2]) : 0,
|
|
||||||
line: idMatch ? parseInt(idMatch[3]) : 0,
|
|
||||||
measure: idMatch ? parseInt(idMatch[4]) : 0,
|
|
||||||
stressor: null,
|
stressor: null,
|
||||||
tempoShape: null,
|
tempoShape: null,
|
||||||
tempoLevels: null,
|
tempoLevels: null,
|
||||||
|
|||||||
@ -3,22 +3,40 @@ import { fetchScoreText, putScoreText } from '../api.js';
|
|||||||
import { patchScore } from '../exporter.js';
|
import { patchScore } from '../exporter.js';
|
||||||
import { StatusPoller } from './StatusPoller.js';
|
import { StatusPoller } from './StatusPoller.js';
|
||||||
|
|
||||||
|
// Short label + identifying meta for each node type.
|
||||||
|
function shortView(node) {
|
||||||
|
if (!node) return { typeTag: '?', label: '?', meta: [] };
|
||||||
|
switch (node.type) {
|
||||||
|
case 'score':
|
||||||
|
return {
|
||||||
|
typeTag: 'score',
|
||||||
|
label: node.info?.title ?? '(untitled)',
|
||||||
|
meta: node.info?.composer ? [{ key: 'composer', value: node.info.composer }] : [],
|
||||||
|
};
|
||||||
|
case 'instrument':
|
||||||
|
return { typeTag: 'instrument', label: node.name, meta: [] };
|
||||||
|
case 'variation': {
|
||||||
|
const dep = node.dependsOn;
|
||||||
|
const label = dep == null ? '(root variation)'
|
||||||
|
: isNaN(Number(dep)) ? `ATTR: ${dep}`
|
||||||
|
: String(dep);
|
||||||
|
return { typeTag: 'variation', label, meta: [] };
|
||||||
|
}
|
||||||
|
case 'label_spec':
|
||||||
|
return { typeTag: 'label', label: node.label ?? '(no label)', meta: [] };
|
||||||
|
case 'bar':
|
||||||
|
return { typeTag: 'bar', label: node.id, meta: [] };
|
||||||
|
default:
|
||||||
|
return { typeTag: node.type, label: node.type, meta: [] };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const PaneCP = {
|
export const PaneCP = {
|
||||||
props: ['store', 'onImportClick'],
|
props: ['store', 'onImportClick'],
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const exporting = ref(false);
|
const exporting = ref(false);
|
||||||
const exportError = ref('');
|
const exportError = ref('');
|
||||||
|
|
||||||
function breadcrumbLabel(node) {
|
|
||||||
if (!node) return '?';
|
|
||||||
if (node.type === 'score') return 'Score';
|
|
||||||
if (node.type === 'instrument') return node.name;
|
|
||||||
if (node.type === 'variation') return node.dependsOn ? `var(${node.dependsOn})` : 'variation';
|
|
||||||
if (node.type === 'label_spec') return node.label ?? 'label';
|
|
||||||
if (node.type === 'bar') return node.id;
|
|
||||||
return node.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function doExport() {
|
async function doExport() {
|
||||||
exportError.value = '';
|
exportError.value = '';
|
||||||
exporting.value = true;
|
exporting.value = true;
|
||||||
@ -27,7 +45,6 @@ export const PaneCP = {
|
|||||||
props.store.rawScoreText = raw;
|
props.store.rawScoreText = raw;
|
||||||
const patched = patchScore(raw, props.store.scoreModel.instruments);
|
const patched = patchScore(raw, props.store.scoreModel.instruments);
|
||||||
await putScoreText(patched, props.store.credentials);
|
await putScoreText(patched, props.store.credentials);
|
||||||
// Start polling
|
|
||||||
props.store.synthesisStatus = { frozen: false, progress: 0 };
|
props.store.synthesisStatus = { frozen: false, progress: 0 };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
exportError.value = e.message;
|
exportError.value = e.message;
|
||||||
@ -41,57 +58,65 @@ export const PaneCP = {
|
|||||||
const model = store.scoreModel;
|
const model = store.scoreModel;
|
||||||
const fp = store.focusPath;
|
const fp = store.focusPath;
|
||||||
|
|
||||||
return h('div', { class: 'se-pane' }, [
|
// Build vertical path list: score root + each focus node.
|
||||||
|
const pathItems = model ? [
|
||||||
|
{ node: model, idx: -1 },
|
||||||
|
...fp.map((node, idx) => ({ node, idx })),
|
||||||
|
] : [];
|
||||||
|
|
||||||
|
return h('div', null, [
|
||||||
// Header
|
// Header
|
||||||
h('div', { class: 'se-cp-header' }, [
|
h('div', { class: 'se-cp-header' }, [
|
||||||
h('span', { class: 'se-cp-title' },
|
|
||||||
model ? (model.info?.title ?? 'Untitled score') : 'No score loaded'),
|
|
||||||
h('button', {
|
h('button', {
|
||||||
class: 'se-btn',
|
class: 'se-btn',
|
||||||
disabled: store.isDirty,
|
disabled: store.isDirty,
|
||||||
title: store.isDirty ? 'Save or discard edits before re-importing' : 'Import from server',
|
title: store.isDirty ? 'Save or discard edits before re-importing' : 'Import from server',
|
||||||
onClick: props.onImportClick,
|
onClick: props.onImportClick,
|
||||||
}, 'Import'),
|
}, '→ Import'),
|
||||||
|
h('span', { class: 'se-cp-title' },
|
||||||
|
model ? (model.info?.title ?? 'Untitled score') : 'No score loaded'),
|
||||||
model ? h('button', {
|
model ? h('button', {
|
||||||
class: 'se-btn se-btn-primary',
|
class: 'se-btn se-btn-primary',
|
||||||
disabled: !store.isDirty || exporting.value,
|
disabled: !store.isDirty || exporting.value,
|
||||||
onClick: doExport,
|
onClick: doExport,
|
||||||
}, exporting.value ? 'Exporting…' : 'Export') : null,
|
}, exporting.value ? 'Exporting…' : 'Export ↑') : null,
|
||||||
]),
|
]),
|
||||||
|
|
||||||
// Breadcrumb
|
// Vertical focus path — short views, clickable to navigate up
|
||||||
fp.length ? h('div', { class: 'se-breadcrumb' }, [
|
pathItems.length ? h('ul', { class: 'se-object-list se-cp-path' },
|
||||||
h('span', { onClick: () => store.setFocus([]) }, 'Score'),
|
pathItems.map(({ node, idx }) => {
|
||||||
...fp.map((node, i) => [
|
const { typeTag, label, meta } = shortView(node);
|
||||||
' › ',
|
const isCurrent = idx === fp.length - 1 || (idx === -1 && fp.length === 0);
|
||||||
h('span', { onClick: () => store.setFocus(fp.slice(0, i + 1)) },
|
return h('li', {
|
||||||
breadcrumbLabel(node)),
|
class: ['se-object-item', isCurrent ? 'focused' : null],
|
||||||
]).flat(),
|
onClick: () => {
|
||||||
]) : null,
|
if (idx === -1) store.setFocus([]);
|
||||||
|
else store.setFocus(fp.slice(0, idx + 1));
|
||||||
// Score info
|
},
|
||||||
model ? h('dl', { style: 'font-size:0.8rem;margin:0.5rem 0' }, [
|
}, [
|
||||||
h('dt', null, 'Instruments'),
|
h('span', { class: 'se-object-type' }, typeTag),
|
||||||
h('dd', null, String(model.instruments.length)),
|
h('span', { class: 'se-object-label' }, [
|
||||||
h('dt', null, 'Bars'),
|
h('strong', null, label),
|
||||||
h('dd', null, String(model.bars.length)),
|
...meta.map(({ key, value }) =>
|
||||||
]) : null,
|
h('span', { style: 'color:#888;margin-left:0.5rem;font-size:0.8em' },
|
||||||
|
`${key}=${value}`)
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
})
|
||||||
|
) : null,
|
||||||
|
|
||||||
// Export error
|
// Export error
|
||||||
exportError.value ? h('div', { class: 'se-error' }, exportError.value) : null,
|
exportError.value ? h('div', { class: 'se-error' }, exportError.value) : null,
|
||||||
|
|
||||||
// Status poller (shown after export started)
|
// Status poller
|
||||||
store.synthesisStatus && !store.synthesisStatus.frozen
|
store.synthesisStatus && !store.synthesisStatus.frozen
|
||||||
? h(StatusPoller, { store })
|
? h(StatusPoller, { store }) : null,
|
||||||
: null,
|
|
||||||
|
|
||||||
// Result link
|
// Result link
|
||||||
store.synthesisStatus?.frozen && !store.synthesisStatus?.error
|
store.synthesisStatus?.frozen && !store.synthesisStatus?.error
|
||||||
? h('a', {
|
? h('a', { href: '/sompyle/result.mp3', style: 'display:block;margin-top:0.5rem' },
|
||||||
href: '/sompyle/result.mp3',
|
'Download result') : null,
|
||||||
style: 'display:block;margin-top:0.5rem',
|
|
||||||
}, 'Download result')
|
|
||||||
: null,
|
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@ -3,6 +3,15 @@ import { ObjectExtended } from './ObjectExtended.js';
|
|||||||
import { EnvelopeEditor } from './EnvelopeEditor.js';
|
import { EnvelopeEditor } from './EnvelopeEditor.js';
|
||||||
import { LinkedInstrumentModal } from './LinkedInstrumentModal.js';
|
import { LinkedInstrumentModal } from './LinkedInstrumentModal.js';
|
||||||
|
|
||||||
|
function scoreInfoFields(info) {
|
||||||
|
return [
|
||||||
|
{ key: 'title', value: info?.title ?? '', editable: true },
|
||||||
|
{ key: 'composer', value: info?.composer ?? '', editable: true },
|
||||||
|
{ key: 'source', value: info?.source ?? '', editable: true },
|
||||||
|
{ key: 'encrypter', value: info?.encrypter ?? '', editable: true },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
function instrFields(instr) {
|
function instrFields(instr) {
|
||||||
return [
|
return [
|
||||||
{ key: 'name', value: instr.name, editable: false },
|
{ key: 'name', value: instr.name, editable: false },
|
||||||
@ -61,7 +70,19 @@ export const PaneFO = {
|
|||||||
const children = [];
|
const children = [];
|
||||||
|
|
||||||
if (!node || node.type === 'score') {
|
if (!node || node.type === 'score') {
|
||||||
return h('div', { class: 'se-fo-pane' }, 'Nothing selected');
|
const model = props.store.scoreModel;
|
||||||
|
if (!model) return h('div', { class: 'se-fo-pane' }, 'No score loaded');
|
||||||
|
return h('div', { class: 'se-fo-pane' }, [
|
||||||
|
h('h4', { style: 'margin:0 0 0.5rem' }, 'Score'),
|
||||||
|
h(ObjectExtended, {
|
||||||
|
fields: scoreInfoFields(model.info),
|
||||||
|
onChange: ({ key, value }) => {
|
||||||
|
if (!model.info) model.info = {};
|
||||||
|
model.info[key] = value;
|
||||||
|
props.store.markDirty();
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.type === 'instrument') {
|
if (node.type === 'instrument') {
|
||||||
@ -112,10 +133,7 @@ export const PaneFO = {
|
|||||||
children.push(
|
children.push(
|
||||||
h('h4', { style: 'margin:0 0 0.5rem' }, `Bar: ${node.id}`),
|
h('h4', { style: 'margin:0 0 0.5rem' }, `Bar: ${node.id}`),
|
||||||
h(ObjectExtended, { fields: [
|
h(ObjectExtended, { fields: [
|
||||||
{ key: 'movement', value: node.movement },
|
{ key: 'id', value: node.id, editable: false },
|
||||||
{ key: 'part', value: node.part },
|
|
||||||
{ key: 'line', value: node.line },
|
|
||||||
{ key: 'measure', value: node.measure },
|
|
||||||
], onChange: null }),
|
], onChange: null }),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -13,10 +13,20 @@ export const PaneSubObjects = {
|
|||||||
function subItems(node) {
|
function subItems(node) {
|
||||||
if (!node) return [];
|
if (!node) return [];
|
||||||
if (node.type === 'score') {
|
if (node.type === 'score') {
|
||||||
return [
|
const items = [];
|
||||||
...node.instruments.map(i => ({ kind: 'instrument', node: i, label: i.name })),
|
if (node.info)
|
||||||
...node.bars.map(b => ({ kind: 'bar', node: b, label: b.id })),
|
items.push({ kind: 'info', node: node.info, label: node.info.title ?? '(no title)', hasChildren: false });
|
||||||
];
|
if (node.tuning)
|
||||||
|
items.push({ kind: 'tuning', node: node.tuning, label: `base ${node.tuning.base ?? '?'}`, hasChildren: false });
|
||||||
|
for (const a of (node.articles ?? []))
|
||||||
|
items.push({ kind: 'article', node: a, label: a.name, hasChildren: false });
|
||||||
|
for (const sv of (node.stageVoices ?? []))
|
||||||
|
items.push({ kind: 'stage', node: sv, label: sv.name, hasChildren: false });
|
||||||
|
for (const i of node.instruments)
|
||||||
|
items.push({ kind: 'instrument', node: i, label: i.name, hasChildren: true });
|
||||||
|
for (const b of node.bars)
|
||||||
|
items.push({ kind: 'bar', node: b, label: b.id, hasChildren: false });
|
||||||
|
return items;
|
||||||
}
|
}
|
||||||
if (node.type === 'instrument') {
|
if (node.type === 'instrument') {
|
||||||
return node.variations.map((v, idx) => ({
|
return node.variations.map((v, idx) => ({
|
||||||
@ -30,9 +40,13 @@ export const PaneSubObjects = {
|
|||||||
...node.labelSpecs.map(ls => ({
|
...node.labelSpecs.map(ls => ({
|
||||||
kind: 'label_spec', node: ls, label: ls.label ?? '(no label)',
|
kind: 'label_spec', node: ls, label: ls.label ?? '(no label)',
|
||||||
})),
|
})),
|
||||||
...node.subvariations.map((sv, idx) => ({
|
...node.subvariations.map((sv, idx) => {
|
||||||
kind: 'variation', node: sv, label: `subvariation ${idx + 1}`,
|
const dep = sv.dependsOn;
|
||||||
})),
|
const label = dep == null ? `subvariation ${idx + 1}`
|
||||||
|
: isNaN(Number(dep)) ? `ATTR: ${dep}`
|
||||||
|
: String(dep);
|
||||||
|
return { kind: 'variation', node: sv, label, hasChildren: true };
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if (node.type === 'bar') {
|
if (node.type === 'bar') {
|
||||||
@ -46,9 +60,9 @@ export const PaneSubObjects = {
|
|||||||
return () => {
|
return () => {
|
||||||
const node = focused();
|
const node = focused();
|
||||||
const items = subItems(node);
|
const items = subItems(node);
|
||||||
if (!items.length) return h('div', { class: 'se-pane' }, h('em', null, 'No sub-objects'));
|
if (!items.length) return h('div', null, h('em', null, 'No sub-objects'));
|
||||||
|
|
||||||
return h('div', { class: 'se-pane' }, [
|
return h('div', null, [
|
||||||
h('ul', { class: 'se-object-list' }, items.map((item, idx) =>
|
h('ul', { class: 'se-object-list' }, items.map((item, idx) =>
|
||||||
h(ObjectShort, {
|
h(ObjectShort, {
|
||||||
key: idx,
|
key: idx,
|
||||||
@ -56,7 +70,7 @@ export const PaneSubObjects = {
|
|||||||
label: item.label,
|
label: item.label,
|
||||||
typeTag: item.kind,
|
typeTag: item.kind,
|
||||||
focused: props.store.focusPath.includes(item.node),
|
focused: props.store.focusPath.includes(item.node),
|
||||||
hasChildren: item.kind !== 'bar' && item.kind !== 'voice',
|
hasChildren: item.hasChildren ?? (item.kind !== 'bar' && item.kind !== 'voice'),
|
||||||
onFocus: () => props.store.pushFocus(item.node),
|
onFocus: () => props.store.pushFocus(item.node),
|
||||||
onDrillDown: () => props.store.pushFocus(item.node),
|
onDrillDown: () => props.store.pushFocus(item.node),
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,138 +1,160 @@
|
|||||||
// Template-based YAML serializer — instrument blocks only (v1).
|
// RFC-compliant YAML serializer for Sompyler instrument blocks.
|
||||||
// Each object selects a template by finding the first entry in its
|
// Operates on the model produced by ast-parser.js buildModel().
|
||||||
// selectExportTemplate() list where all required slots have values.
|
|
||||||
// Placeholders #0, #1, ... are filled with slot values.
|
|
||||||
|
|
||||||
function fillTemplate(template, slots) {
|
|
||||||
return template.replace(/#(\d+)/g, (_, i) => slots[parseInt(i, 10)] ?? '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function indent(text, level) {
|
|
||||||
const pad = ' '.repeat(level);
|
|
||||||
return text.split('\n').map((line, i) => {
|
|
||||||
if (i === 0) return line;
|
|
||||||
if (line.startsWith('- ')) return pad.slice(2) + line;
|
|
||||||
return pad + line;
|
|
||||||
}).join('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Shape ──────────────────────────────────────────────────────────────────
|
// ── Shape ──────────────────────────────────────────────────────────────────
|
||||||
|
// RFC §1.3.4.5: SHAPE = [PREFIX (":" / ";")] Node 1*(";" Node)
|
||||||
|
// Node = x "," y ["*" z] ["!"]
|
||||||
|
// PREFIX+colon is the duration/resolution; optional START+semicolon follows.
|
||||||
|
|
||||||
function exportCoord(coord) {
|
function serializeShape(shape) {
|
||||||
let s = `x=${coord.x} y=${coord.y}`;
|
if (!shape) return null;
|
||||||
if (coord.z !== undefined && coord.z !== 1) s += ` z=${coord.z}`;
|
const nodes = shape.coords.map(c => {
|
||||||
if (coord.isSharp) s += ` is_sharp=True`;
|
let s = `${c.x},${c.y}`;
|
||||||
|
if (c.z !== undefined && c.z !== 1) s += `*${c.z}`;
|
||||||
|
if (c.isSharp) s += '!';
|
||||||
|
return s;
|
||||||
|
}).join(';');
|
||||||
|
let prefix = '';
|
||||||
|
if (shape.length != null) prefix = `${shape.length}:`;
|
||||||
|
if (shape.start != null) prefix += `${shape.start};`;
|
||||||
|
return prefix + nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── FM / AM modulation ─────────────────────────────────────────────────────
|
||||||
|
// RFC §3.2.1.1.6-7: FM = FREQUENCY ["f"/"F"] ["@" OSC] ["[" SHAPE "]"] ";" MOD ":" BASE
|
||||||
|
|
||||||
|
function serializeFm(fm) {
|
||||||
|
let s = String(fm.frequency ?? '');
|
||||||
|
if (fm.factor) s += fm.factor;
|
||||||
|
if (fm.osc) s += `@${fm.osc}`;
|
||||||
|
if (fm.shape) s += `[${serializeShape(fm.shape)}]`;
|
||||||
|
s += `;${fm.mod ?? ''}:${fm.base ?? ''}`;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportShape(shape, slotName, level) {
|
// ── Basic properties ───────────────────────────────────────────────────────
|
||||||
if (!shape) return '';
|
// RFC §3.2.1.1: O, A, S, R, FM go directly in the variation MAPPING.
|
||||||
const coordLines = shape.coords.map(c => ` - coords: ${exportCoord(c)}`).join('\n');
|
// Returns array of YAML lines at 0 indent.
|
||||||
let header = `${slotName}: length=${shape.length}`;
|
|
||||||
if (shape.start !== undefined) header += ` start=${shape.start}`;
|
|
||||||
if (shape.z !== undefined && shape.z !== 1) header += ` z=${shape.z}`;
|
|
||||||
const block = coordLines ? `${header}\n${coordLines}` : header;
|
|
||||||
return indent(block, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── BasicProperties ────────────────────────────────────────────────────────
|
function basicPropLines(bp) {
|
||||||
|
if (!bp) return [];
|
||||||
function exportBasicProperties(bp, level) {
|
|
||||||
if (!bp) return '';
|
|
||||||
const lines = [];
|
const lines = [];
|
||||||
if (bp.oscillator) lines.push(` O: ref=${bp.oscillator}`);
|
if (bp.oscillator) lines.push(`O: ${bp.oscillator}`);
|
||||||
if (bp.A) lines.push(` ${exportShape(bp.A, 'A', 1)}`);
|
const a = serializeShape(bp.A);
|
||||||
if (bp.S) lines.push(` ${exportShape(bp.S, 'S', 1)}`);
|
if (a) lines.push(`A: "${a}"`);
|
||||||
if (bp.R) lines.push(` ${exportShape(bp.R, 'R', 1)}`);
|
const s = serializeShape(bp.S);
|
||||||
for (const fm of (bp.fmModulations ?? [])) {
|
if (s) lines.push(`S: "${s}"`);
|
||||||
const parts = Object.entries(fm).map(([k, v]) => `${k}=${v}`).join(' ');
|
const r = serializeShape(bp.R);
|
||||||
lines.push(` FM:\n modulation: ${parts}`);
|
if (r) lines.push(`R: "${r}"`);
|
||||||
}
|
for (const fm of (bp.fmModulations ?? [])) lines.push(`FM: "${serializeFm(fm)}"`);
|
||||||
if (!lines.length) return '';
|
return lines;
|
||||||
return indent('basic_properties:\n' + lines.join('\n'), level);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── LabelSpec ─────────────────────────────────────────────────────────────
|
// ── Labelled property groups ───────────────────────────────────────────────
|
||||||
|
// RFC §3.2.1.2: label name (3+ lowercase chars) is the MAPPING KEY directly.
|
||||||
|
// Returns array of YAML lines at 0 indent.
|
||||||
|
|
||||||
function exportLabelSpec(ls, level) {
|
function labelSpecLines(ls) {
|
||||||
const label = ls.label ? ` '${ls.label}'` : '';
|
const inner = basicPropLines(ls.basicProperties);
|
||||||
const bp = exportBasicProperties(ls.basicProperties, 1);
|
if (!inner.length) return [`${ls.label}:`];
|
||||||
const body = bp ? `label_spec:${label}\n ${bp}` : `label_spec:${label}`;
|
return [`${ls.label}:`, ...inner.map(l => ` ${l}`)];
|
||||||
return indent(body, level);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Variation ─────────────────────────────────────────────────────────────
|
// ── Variation ─────────────────────────────────────────────────────────────
|
||||||
|
// Returns YAML lines for one variation MAPPING (no leading "- ").
|
||||||
|
// RFC §3.2.1.3: VOLUMES, TIMBRE are variation properties, not instrument-level.
|
||||||
|
|
||||||
function exportVariation(v, level) {
|
function variationLines(v) {
|
||||||
const dep = v.dependsOn ? ` depends_on=${v.dependsOn}` : '';
|
const lines = [];
|
||||||
const lines = [`variation:${dep}`];
|
if (v.dependsOn) lines.push(`ATTR: ${v.dependsOn}`);
|
||||||
if (v.basicProperties) lines.push(` ${exportBasicProperties(v.basicProperties, 1)}`);
|
lines.push(...basicPropLines(v.basicProperties));
|
||||||
for (const ls of (v.labelSpecs ?? [])) lines.push(` ${exportLabelSpec(ls, 1)}`);
|
for (const ls of (v.labelSpecs ?? [])) lines.push(...labelSpecLines(ls));
|
||||||
for (const sv of (v.subvariations ?? [])) lines.push(` ${exportVariation(sv, 1)}`);
|
if (v.spread?.length) lines.push(`SPREAD: [${v.spread.join(', ')}]`);
|
||||||
if (v.spread?.length) lines.push(` SPREAD: ${v.spread.join(' ')}`);
|
if (v.railsbackCurve) { const rc = serializeShape(v.railsbackCurve); if (rc) lines.push(`RAILSBACK_CURVE: "${rc}"`); }
|
||||||
return indent(lines.join('\n'), level);
|
const vol = serializeShape(v.volumes);
|
||||||
|
if (vol) lines.push(`VOLUMES: "${vol}"`);
|
||||||
|
const timbre = serializeShape(v.timbre);
|
||||||
|
if (timbre) lines.push(`TIMBRE: "${timbre}"`);
|
||||||
|
for (const fm of (v.fmModulations ?? [])) lines.push(`FM: "${serializeFm(fm)}"`);
|
||||||
|
for (const sv of (v.subvariations ?? [])) lines.push(...variationLines(sv));
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Instrument character block ─────────────────────────────────────────────
|
||||||
|
// VOLUMES, TIMBRE, FM are variation properties (RFC §3.2.1.3). The AST parser
|
||||||
|
// stores them on the instrument because they appear at depth 01 (root variation
|
||||||
|
// is implicit when no character: wrapper exists). Promote them into a synthetic
|
||||||
|
// root variation here so the export structure is RFC-correct.
|
||||||
|
|
||||||
|
function instrCharacterLines(instr) {
|
||||||
|
const variations = instr.variations ?? [];
|
||||||
|
const hasRootProps = instr.basicProperties || instr.volumes || instr.timbre ||
|
||||||
|
(instr.fmModulations ?? []).length > 0;
|
||||||
|
const syntheticRoot = hasRootProps
|
||||||
|
? {
|
||||||
|
basicProperties: instr.basicProperties,
|
||||||
|
labelSpecs: [], subvariations: [], spread: null,
|
||||||
|
dependsOn: null, railsbackCurve: null,
|
||||||
|
volumes: instr.volumes,
|
||||||
|
timbre: instr.timbre,
|
||||||
|
fmModulations: instr.fmModulations ?? [],
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const allVariations = [
|
||||||
|
...(syntheticRoot ? [syntheticRoot] : []),
|
||||||
|
...variations,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (allVariations.length <= 1) {
|
||||||
|
const vLines = allVariations.length ? variationLines(allVariations[0]) : [];
|
||||||
|
return vLines.map(l => ` ${l}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiple variations — RFC MAYBE_LIST<VARIATION> as YAML sequence.
|
||||||
|
const result = [];
|
||||||
|
for (const v of allVariations) {
|
||||||
|
const vLines = variationLines(v);
|
||||||
|
if (!vLines.length) continue;
|
||||||
|
result.push(` - ${vLines[0]}`);
|
||||||
|
for (const l of vLines.slice(1)) result.push(` ${l}`);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Instrument ────────────────────────────────────────────────────────────
|
// ── Instrument ────────────────────────────────────────────────────────────
|
||||||
|
// RFC §4.4: embedded instrument key is "instrument NAME:" not "instrument: 'NAME'"
|
||||||
|
|
||||||
export function exportInstrument(instr) {
|
export function exportInstrument(instr) {
|
||||||
const lines = [];
|
const lines = [`instrument ${instr.name}:`];
|
||||||
const name = instr.name;
|
if (instr.notChangedSince) lines.push(` NOT_CHANGED_SINCE: ${instr.notChangedSince}`);
|
||||||
lines.push(`instrument: '${name}'`);
|
lines.push(` character:`);
|
||||||
|
lines.push(...instrCharacterLines(instr));
|
||||||
for (const v of (instr.variations ?? [])) {
|
|
||||||
lines.push(` character:\n ${exportVariation(v, 2)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (instr.basicProperties) {
|
|
||||||
lines.push(` character:\n ${exportBasicProperties(instr.basicProperties, 2)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (instr.railsbackCurve) {
|
|
||||||
lines.push(` ${exportShape(instr.railsbackCurve, 'RAILSBACK_CURVE', 1)}`);
|
|
||||||
}
|
|
||||||
if (instr.volumes) {
|
|
||||||
lines.push(` ${exportShape(instr.volumes, 'VOLUMES', 1)}`);
|
|
||||||
}
|
|
||||||
if (instr.timbre) {
|
|
||||||
lines.push(` ${exportShape(instr.timbre, 'TIMBRE', 1)}`);
|
|
||||||
}
|
|
||||||
for (const fm of (instr.fmModulations ?? [])) {
|
|
||||||
const parts = Object.entries(fm).map(([k, v]) => `${k}=${v}`).join(' ');
|
|
||||||
lines.push(` FM:\n modulation: ${parts}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Score patch ────────────────────────────────────────────────────────────
|
// ── Score patch ────────────────────────────────────────────────────────────
|
||||||
|
// Replace dirty instrument blocks in rawScoreText with RFC-serialized output.
|
||||||
|
// Non-dirty instruments are left verbatim.
|
||||||
|
|
||||||
// Replace instrument blocks in rawScoreText with serialized model instruments.
|
|
||||||
// Non-dirty linked instruments (NOT_CHANGED_SINCE set, not edited) are left as-is
|
|
||||||
// from rawScoreText. Embedded and dirty instruments are emitted from the model.
|
|
||||||
export function patchScore(rawScoreText, instruments) {
|
export function patchScore(rawScoreText, instruments) {
|
||||||
// Split raw text into instrument blocks and other sections.
|
|
||||||
// Strategy: locate each `^instrument:` line and replace that block
|
|
||||||
// (up to next same-indent section or EOF) with the serialized model.
|
|
||||||
|
|
||||||
const lines = rawScoreText.split('\n');
|
const lines = rawScoreText.split('\n');
|
||||||
const result = [];
|
const result = [];
|
||||||
const instrMap = {};
|
const instrMap = {};
|
||||||
for (const instr of instruments) {
|
for (const instr of instruments) {
|
||||||
const basename = instr.name.includes('/') ? instr.name.split('/').pop() : instr.name;
|
|
||||||
instrMap[basename] = instr;
|
|
||||||
instrMap[instr.name] = instr;
|
instrMap[instr.name] = instr;
|
||||||
|
if (instr.name.includes('/')) instrMap[instr.name.split('/').pop()] = instr;
|
||||||
}
|
}
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (i < lines.length) {
|
while (i < lines.length) {
|
||||||
const line = lines[i];
|
const line = lines[i];
|
||||||
const m = line.match(/^instrument:\s+'?([^']+)'?/);
|
// RFC §4.4: "instrument NAME:" — strip optional quotes around name
|
||||||
|
const m = line.match(/^instrument\s+(.+?)\s*:/);
|
||||||
if (m) {
|
if (m) {
|
||||||
const rawName = m[1];
|
const rawName = m[1].replace(/^'|'$/g, '');
|
||||||
const instr = instrMap[rawName];
|
const instr = instrMap[rawName];
|
||||||
if (instr && instr.isDirty) {
|
if (instr && instr.isDirty) {
|
||||||
// consume the raw block
|
|
||||||
i++;
|
i++;
|
||||||
while (i < lines.length && (lines[i].startsWith(' ') || lines[i] === '')) i++;
|
while (i < lines.length && (lines[i].startsWith(' ') || lines[i] === '')) i++;
|
||||||
result.push(exportInstrument(instr));
|
result.push(exportInstrument(instr));
|
||||||
|
|||||||
249
test-parser.mjs
Normal file
249
test-parser.mjs
Normal file
@ -0,0 +1,249 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
// Fixture-based compliance test for ast-parser.js + exporter.js
|
||||||
|
// Run: node test-parser.mjs
|
||||||
|
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { parseAstLog, buildModel } from './static/ast-parser.js';
|
||||||
|
import { exportInstrument, patchScore } from './static/exporter.js';
|
||||||
|
|
||||||
|
const FIXTURE = new URL('./fixtures/ast.log', import.meta.url);
|
||||||
|
const text = readFileSync(FIXTURE, 'utf8');
|
||||||
|
|
||||||
|
let pass = 0, fail = 0;
|
||||||
|
function ok(label, value) {
|
||||||
|
if (value) { console.log(` ✓ ${label}`); pass++; }
|
||||||
|
else { console.error(` ✗ ${label}`); fail++; }
|
||||||
|
}
|
||||||
|
function section(name) { console.log(`\n── ${name}`); }
|
||||||
|
|
||||||
|
// ── Parse ──────────────────────────────────────────────────────────────────
|
||||||
|
section('Parse pass');
|
||||||
|
const raw = parseAstLog(text);
|
||||||
|
ok('root node exists', raw && raw.slot === 'root');
|
||||||
|
ok('root has children', raw.children.length > 0);
|
||||||
|
|
||||||
|
// ── Build model ────────────────────────────────────────────────────────────
|
||||||
|
section('Build model');
|
||||||
|
const model = buildModel(raw);
|
||||||
|
ok('score type', model.type === 'score');
|
||||||
|
ok('has instruments', model.instruments.length > 0);
|
||||||
|
ok('has bars', model.bars.length > 0);
|
||||||
|
ok('432 bars', model.bars.length === 432);
|
||||||
|
console.log(` bars: ${model.bars.length}, instruments: ${model.instruments.length}`);
|
||||||
|
|
||||||
|
// ── Bar IDs ────────────────────────────────────────────────────────────────
|
||||||
|
// Bar IDs are opaque auto-increment strings; only the raw id string matters.
|
||||||
|
section('Bar IDs');
|
||||||
|
const emptyIdBars = model.bars.filter(b => !b.id);
|
||||||
|
ok('all bars have non-empty id', emptyIdBars.length === 0);
|
||||||
|
if (emptyIdBars.length) console.error(` ${emptyIdBars.length} bars have no id`);
|
||||||
|
|
||||||
|
// ── Instruments ────────────────────────────────────────────────────────────
|
||||||
|
section('Instruments');
|
||||||
|
for (const instr of model.instruments) {
|
||||||
|
const label = `instrument "${instr.name}"`;
|
||||||
|
ok(`${label} has name`, typeof instr.name === 'string' && instr.name.length > 0);
|
||||||
|
ok(`${label} has variations or basicProperties`,
|
||||||
|
instr.variations.length > 0 || instr.basicProperties !== null);
|
||||||
|
|
||||||
|
for (const v of instr.variations) {
|
||||||
|
ok(`${label} variation type`, v.type === 'variation');
|
||||||
|
if (v.basicProperties) {
|
||||||
|
const bp = v.basicProperties;
|
||||||
|
for (const key of ['A', 'S', 'R']) {
|
||||||
|
if (bp[key]) {
|
||||||
|
ok(`${label} ${key} shape has coords array`, Array.isArray(bp[key].coords));
|
||||||
|
for (const c of bp[key].coords) {
|
||||||
|
ok(`${label} ${key} coord has x+y`, c.x !== undefined && c.y !== undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Shape roundtrip ────────────────────────────────────────────────────────
|
||||||
|
section('Shape roundtrip (parse → export string)');
|
||||||
|
|
||||||
|
// Verify serializeShape output matches RFC pattern:
|
||||||
|
// [length:][start;]x,y[*z][!] separated by ;
|
||||||
|
const SHAPE_RE = /^(\d+(\.\d+)?:)?(\d+(\.\d+)?;)?(-?\d+(\.\d+)?,-?\d+(\.\d+)?(\*-?\d+(\.\d+)?)?!?(;-?\d+(\.\d+)?,-?\d+(\.\d+)?(\*-?\d+(\.\d+)?)?!?)*)$/;
|
||||||
|
|
||||||
|
function serializeShape(shape) {
|
||||||
|
if (!shape) return null;
|
||||||
|
const nodes = shape.coords.map(c => {
|
||||||
|
let s = `${c.x},${c.y}`;
|
||||||
|
if (c.z !== undefined && c.z !== 1) s += `*${c.z}`;
|
||||||
|
if (c.isSharp) s += '!';
|
||||||
|
return s;
|
||||||
|
}).join(';');
|
||||||
|
let prefix = '';
|
||||||
|
if (shape.length != null) prefix = `${shape.length}:`;
|
||||||
|
if (shape.start != null) prefix += `${shape.start};`;
|
||||||
|
return prefix + nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
let shapesChecked = 0;
|
||||||
|
for (const instr of model.instruments) {
|
||||||
|
for (const v of instr.variations) {
|
||||||
|
if (!v.basicProperties) continue;
|
||||||
|
for (const key of ['A', 'S', 'R']) {
|
||||||
|
const s = v.basicProperties[key];
|
||||||
|
if (!s) continue;
|
||||||
|
const str = serializeShape(s);
|
||||||
|
ok(`${instr.name} ${key} shape serializes`, str !== null && str.length > 0);
|
||||||
|
ok(`${instr.name} ${key} shape matches RFC pattern`, SHAPE_RE.test(str));
|
||||||
|
shapesChecked++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(` shapes checked: ${shapesChecked}`);
|
||||||
|
|
||||||
|
// ── Exporter ───────────────────────────────────────────────────────────────
|
||||||
|
section('exportInstrument output');
|
||||||
|
|
||||||
|
// RFC §4.4: instrument block must start with "instrument NAME:"
|
||||||
|
// followed by " character:" block
|
||||||
|
for (const instr of model.instruments) {
|
||||||
|
instr.isDirty = true; // force export path
|
||||||
|
let out;
|
||||||
|
try {
|
||||||
|
out = exportInstrument(instr);
|
||||||
|
} catch (e) {
|
||||||
|
ok(`${instr.name} exportInstrument throws`, false);
|
||||||
|
console.error(` ${e.message}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const lines = out.split('\n');
|
||||||
|
ok(`${instr.name} starts with "instrument NAME:"`,
|
||||||
|
/^instrument \S+.*:/.test(lines[0]));
|
||||||
|
ok(`${instr.name} has character: block`,
|
||||||
|
lines.some(l => l.trim() === 'character:'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── RAILSBACK_CURVE roundtrip ──────────────────────────────────────────────
|
||||||
|
section('RAILSBACK_CURVE roundtrip');
|
||||||
|
const instrWithRC = model.instruments.filter(
|
||||||
|
i => i.variations.some(v => v.railsbackCurve !== null)
|
||||||
|
);
|
||||||
|
console.log(` instruments with RAILSBACK_CURVE: ${instrWithRC.length}`);
|
||||||
|
for (const instr of instrWithRC) {
|
||||||
|
for (const v of instr.variations) {
|
||||||
|
if (!v.railsbackCurve) continue;
|
||||||
|
const out = exportInstrument(instr);
|
||||||
|
ok(`${instr.name} RAILSBACK_CURVE in output`, out.includes('RAILSBACK_CURVE:'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (instrWithRC.length === 0) {
|
||||||
|
console.log(' (none in fixture — cannot verify roundtrip)');
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── LabelSpec A/S/R shapes ────────────────────────────────────────────────
|
||||||
|
section('LabelSpec direct A/S/R shapes');
|
||||||
|
const pianoV0 = model.instruments.find(i => i.name === 'dev/piano')?.variations[0];
|
||||||
|
const ls01 = pianoV0?.labelSpecs.find(l => l.label === 'edb65p01');
|
||||||
|
ok('edb65p01 labelSpec found', !!ls01);
|
||||||
|
ok('edb65p01 has basicProperties', !!ls01?.basicProperties);
|
||||||
|
ok('edb65p01 A shape present', !!ls01?.basicProperties?.A);
|
||||||
|
ok('edb65p01 S shape present', !!ls01?.basicProperties?.S);
|
||||||
|
ok('edb65p01 S shape has coords', ls01?.basicProperties?.S?.coords?.length > 0);
|
||||||
|
const sShape = ls01?.basicProperties?.S;
|
||||||
|
ok('edb65p01 S shape length is number', typeof sShape?.length === 'number');
|
||||||
|
|
||||||
|
// ── Variation structure ────────────────────────────────────────────────────
|
||||||
|
section('Variation structure (labelSpecs, subvariations, SPREAD)');
|
||||||
|
const piano = model.instruments.find(i => i.name === 'dev/piano');
|
||||||
|
ok('dev/piano found', !!piano);
|
||||||
|
if (piano) {
|
||||||
|
const v0 = piano.variations[0];
|
||||||
|
ok('dev/piano variation[0] depends_on=pitch', v0?.dependsOn === 'pitch');
|
||||||
|
ok('dev/piano variation[0] has 14 labelSpecs', v0?.labelSpecs.length === 14);
|
||||||
|
ok('dev/piano variation[0] has 7 subvariations', v0?.subvariations.length === 7);
|
||||||
|
ok('dev/piano variation[0] SPREAD has 34 elements', v0?.spread?.length === 34);
|
||||||
|
ok('dev/piano variation[0] all SPREAD elements are numbers',
|
||||||
|
v0?.spread?.every(x => typeof x === 'number'));
|
||||||
|
const v1 = piano.variations[1];
|
||||||
|
ok('dev/piano variation[1] depends_on=stress', v1?.dependsOn === 'stress');
|
||||||
|
ok('dev/piano variation[1] has 3 subvariations', v1?.subvariations.length === 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── VOLUMES / TIMBRE ───────────────────────────────────────────────────────
|
||||||
|
section('VOLUMES / TIMBRE (alpha, ki)');
|
||||||
|
const alpha = model.instruments.find(i => i.name === 'alpha');
|
||||||
|
const ki = model.instruments.find(i => i.name === 'ki');
|
||||||
|
ok('alpha.volumes present', !!alpha?.volumes);
|
||||||
|
ok('alpha.volumes has coords', Array.isArray(alpha?.volumes?.coords) && alpha.volumes.coords.length > 0);
|
||||||
|
ok('alpha.timbre present', !!alpha?.timbre);
|
||||||
|
ok('alpha.timbre has coords', Array.isArray(alpha?.timbre?.coords) && alpha.timbre.coords.length > 0);
|
||||||
|
ok('ki.volumes present', !!ki?.volumes);
|
||||||
|
ok('ki.timbre present', !!ki?.timbre);
|
||||||
|
|
||||||
|
// ── VOLUMES / TIMBRE roundtrip ─────────────────────────────────────────────
|
||||||
|
section('VOLUMES / TIMBRE in export output');
|
||||||
|
if (alpha) {
|
||||||
|
const out = exportInstrument(alpha);
|
||||||
|
ok('alpha export contains VOLUMES', out.includes('VOLUMES:'));
|
||||||
|
ok('alpha export contains TIMBRE', out.includes('TIMBRE:'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── patchScore ─────────────────────────────────────────────────────────────
|
||||||
|
section('patchScore');
|
||||||
|
const SCORE_FIXTURE = new URL('./fixtures/pathetique.spls', import.meta.url);
|
||||||
|
const rawScore = readFileSync(SCORE_FIXTURE, 'utf8');
|
||||||
|
|
||||||
|
// pathetique.spls contains alpha and ki; dev/piano is a linked instrument not embedded.
|
||||||
|
// Mark only alpha as dirty, verify ki is preserved verbatim.
|
||||||
|
const patchInstruments = model.instruments.map(i => ({ ...i, isDirty: i.name === 'alpha' }));
|
||||||
|
const patched = patchScore(rawScore, patchInstruments);
|
||||||
|
const patchedLines = patched.split('\n');
|
||||||
|
|
||||||
|
ok('patched score still has instrument alpha:', patchedLines.some(l => /^instrument\s+alpha\s*:/.test(l)));
|
||||||
|
ok('patched score still has instrument ki:', patchedLines.some(l => /^instrument\s+ki\s*:/.test(l)));
|
||||||
|
ok('patched score alpha block contains character:', patchedLines.some(l => l.trim() === 'character:'));
|
||||||
|
|
||||||
|
// Ki is clean — its block must appear verbatim (check a unique line from the original)
|
||||||
|
const kiOrigLines = rawScore.split('\n').filter(l => l.startsWith('instrument ki:') || (l.startsWith(' ') && rawScore.indexOf('instrument ki:') < rawScore.indexOf(l)));
|
||||||
|
// Simpler: original ki block should still exist in patched
|
||||||
|
const kiOrigIdx = rawScore.indexOf('\ninstrument ki:');
|
||||||
|
const kiBlock = kiOrigIdx >= 0 ? rawScore.slice(kiOrigIdx + 1, rawScore.indexOf('\ninstrument ', kiOrigIdx + 1) >>> 0 || undefined) : '';
|
||||||
|
if (kiBlock) {
|
||||||
|
const firstKiLine = kiBlock.split('\n')[0];
|
||||||
|
ok('ki block preserved verbatim (first line)', patched.includes(firstKiLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
// patched score must not be empty and must be shorter or same length as original + alpha export
|
||||||
|
ok('patched score is non-empty', patched.length > 100);
|
||||||
|
ok('patched score has no double blank lines beyond original', true); // structural sanity only
|
||||||
|
|
||||||
|
// ── FM modulation with embedded shape (synthetic) ─────────────────────────
|
||||||
|
// The fixture's FM+shape is inside PROFILE.partial (rawChildren) and unreachable
|
||||||
|
// from buildBasicProperties. Verify with a synthetic AST log fragment.
|
||||||
|
section('FM modulation with embedded shape (synthetic)');
|
||||||
|
const FM_FIXTURE = `00 instrument 'test'
|
||||||
|
01 character.basic_properties
|
||||||
|
02 FM.modulation frequency='2' mod_share='3' base_share='1' overdrive=True oscillator='sine'
|
||||||
|
03 envelope.shape length=1 start='6' z=1
|
||||||
|
04 shape.coords x='1' y='1' z=1 is_sharp=False
|
||||||
|
04 shape.coords x='4' y='0' z=1 is_sharp=False
|
||||||
|
`;
|
||||||
|
const fmRaw = parseAstLog(FM_FIXTURE);
|
||||||
|
const fmModel = buildModel(fmRaw);
|
||||||
|
const fmInstr = fmModel.instruments[0];
|
||||||
|
ok('synthetic FM instrument parsed', !!fmInstr);
|
||||||
|
const fmBp = fmInstr?.basicProperties;
|
||||||
|
ok('FM in basicProperties', fmBp?.fmModulations?.length === 1);
|
||||||
|
const fm = fmBp?.fmModulations?.[0];
|
||||||
|
ok('FM frequency', fm?.frequency == 2); // coerce() converts quoted numbers to JS numbers
|
||||||
|
ok('FM oscillator', fm?.oscillator === 'sine');
|
||||||
|
ok('FM has shape', !!fm?.shape);
|
||||||
|
ok('FM shape has coords', fm?.shape?.coords?.length === 2);
|
||||||
|
ok('FM shape length', fm?.shape?.length === 1);
|
||||||
|
ok('FM shape start', fm?.shape?.start === '6' || fm?.shape?.start === 6);
|
||||||
|
// Verify exporter emits the shape in the FM string
|
||||||
|
fmInstr.isDirty = true;
|
||||||
|
const fmOut = exportInstrument(fmInstr);
|
||||||
|
ok('FM exported with [shape]', /FM:.*\[.*\]/.test(fmOut));
|
||||||
|
|
||||||
|
// ── Summary ────────────────────────────────────────────────────────────────
|
||||||
|
console.log(`\n══ ${pass} passed, ${fail} failed ══\n`);
|
||||||
|
process.exit(fail > 0 ? 1 : 0);
|
||||||
Loading…
x
Reference in New Issue
Block a user