From 300ca99876f66284b5b3605d374b985faa87fe92 Mon Sep 17 00:00:00 2001 From: topkoa Date: Sun, 19 Jul 2026 11:41:42 -0400 Subject: [PATCH 1/3] Show manifest stem names; describe stems via tooltip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feedpak 1.16.0 (spec §5.3) added optional presentational fields to a stems[] entry — `name` (display label) and `description` (free text). Core passes them through song_info (feedback#1013) and the stems plugin forwards them on stems:state / getState() (feedback-plugin-stems#41). Display them: - slider rows print the manifest `name` when one was reported, falling back to the built-in label (Guitar/Voice/...) and then the capitalized id, exactly as before for packs without the fields - a stem with a `description` gets a ⓘ glyph next to its name whose native tooltip (title + aria-label) carries the text; stems without one render no glyph - metadata is kept per canonical id in a map populated only by sources that carry it (stems rows on the provider-ready event, getState rows); a plain-id report from an older stems plugin or the bridge heuristics never wipes it, and it resets with the song - the row-render cache key now includes the metadata, so a name arriving after the id list was already rendered still rebuilds the rows Long names ellipsize inside the fixed label column instead of wrapping the row. 23/23 node tests pass, including new coverage for the metadata extraction and the display-name fallback chain. Co-Authored-By: Claude Fable 5 Signed-off-by: topkoa --- plugin.json | 2 +- screen.js | 81 +++++++++++++++++++++++++++++++++++++++------ tests/state.test.js | 40 ++++++++++++++++++++++ 3 files changed, 112 insertions(+), 11 deletions(-) diff --git a/plugin.json b/plugin.json index 58dca9e..cd1478c 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "id": "stem_mixer", "name": "Stem Mixer", - "version": "1.3.0", + "version": "1.4.0", "private": false, "nav": { "label": "Stem Mixer", diff --git a/screen.js b/screen.js index 1e9d55b..0c01f18 100644 --- a/screen.js +++ b/screen.js @@ -100,6 +100,11 @@ // default six, exactly the pre-availability behavior), [] = known to have no // stems (render the "no stems" message), non-empty = render exactly these. let availableStems = null; + // Per-stem display metadata keyed by canonical id: the manifest's optional + // `name`/`description` (feedpak §5.3), when a source that carries them + // (stems:state `stems` rows, getState() rows) has reported. Presentation + // only — levels, aliases and persistence all stay keyed by id. + let stemMeta = Object.create(null); let onStemsStateEvent = null; function invalidateAudioCaches() { @@ -245,10 +250,35 @@ return out; } + // Display metadata from object rows, keyed by canonical id. Only own, + // non-blank strings survive; plain string arrays yield an empty map. + function extractStemMeta(ids) { + const out = Object.create(null); + (Array.isArray(ids) ? ids : []).forEach((entry) => { + if (!entry || typeof entry !== 'object') return; + const canonical = canonicalStemId(entry.id); + if (!canonical || canonical === 'full' || canonical === '__proto__') return; + const meta = {}; + if (typeof entry.name === 'string' && entry.name.trim()) meta.name = entry.name; + if (typeof entry.description === 'string' && entry.description.trim()) meta.description = entry.description; + if (Object.keys(meta).length && !(canonical in out)) out[canonical] = meta; + }); + return out; + } + function setAvailableStems(ids) { const next = ids == null ? null : normalizeAvailableStems(ids); - if (JSON.stringify(next) === JSON.stringify(availableStems)) return; - availableStems = next; + const nextMeta = extractStemMeta(ids); + const listChanged = JSON.stringify(next) !== JSON.stringify(availableStems); + // A metadata-less report (plain id strings from an older stems plugin, + // bridge/audio-map derived keys) must never wipe metadata a richer + // report already provided for the same list — only a list change or a + // report that actually carries metadata may replace it. + const metaChanged = (listChanged || Object.keys(nextMeta).length > 0) + && JSON.stringify(nextMeta) !== JSON.stringify(stemMeta); + if (!listChanged && !metaChanged) return; + if (listChanged) availableStems = next; + if (metaChanged) stemMeta = nextMeta; queueUiUpdate(); } @@ -897,17 +927,41 @@ }); } + // What to print for a stem: the manifest's `name` when a metadata-bearing + // source reported one, else the built-in label, else the capitalized id. + // Own-key lookups throughout: a dynamic id like 'constructor' would + // otherwise pull inherited values off the label/meta objects. + function stemDisplayName(stem, meta) { + const m = (meta && Object.prototype.hasOwnProperty.call(meta, stem)) ? meta[stem] : null; + if (m && typeof m.name === 'string' && m.name) return m.name; + return Object.prototype.hasOwnProperty.call(STEM_LABELS, stem) + ? STEM_LABELS[stem] + : (stem.charAt(0).toUpperCase() + stem.slice(1)); + } + function makeSliderRow(stem, current, registry) { const row = document.createElement('label'); row.style.cssText = 'display:grid;grid-template-columns:58px 1fr 42px;gap:10px;align-items:center;'; + const meta = Object.prototype.hasOwnProperty.call(stemMeta, stem) ? stemMeta[stem] : null; const name = document.createElement('span'); - // Own-key lookup: a dynamic id like 'constructor' would otherwise pull - // an inherited value off the labels object. - name.textContent = Object.prototype.hasOwnProperty.call(STEM_LABELS, stem) - ? STEM_LABELS[stem] - : (stem.charAt(0).toUpperCase() + stem.slice(1)); - name.style.cssText = 'font-size:11px;color:#b5bfd5;'; + name.style.cssText = 'display:flex;align-items:center;min-width:0;'; + + const label = document.createElement('span'); + label.textContent = stemDisplayName(stem, stemMeta); + // Manifest names can outgrow the 58px column — clip, don't wrap the row. + label.style.cssText = 'font-size:11px;color:#b5bfd5;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;'; + name.appendChild(label); + + if (meta && meta.description) { + const info = document.createElement('span'); + info.textContent = 'ⓘ'; + info.title = meta.description; + info.setAttribute('role', 'img'); + info.setAttribute('aria-label', meta.description); + info.style.cssText = 'margin-left:4px;flex:none;font-size:10px;color:#8b95aa;cursor:help;'; + name.appendChild(info); + } const input = document.createElement('input'); input.type = 'range'; @@ -939,7 +993,9 @@ // unchanged list is a single string compare, no DOM work. function renderStemRowsInto(host, registry) { const list = displayStems(); - const key = JSON.stringify(list); + // Metadata is part of the render key: a name/description arriving for + // an unchanged id list must still rebuild the rows. + const key = JSON.stringify([list, list.map(s => (Object.prototype.hasOwnProperty.call(stemMeta, s) ? stemMeta[s] : null))]); if (host.dataset.stemMixerRows === key) return; host.dataset.stemMixerRows = key; @@ -1598,6 +1654,7 @@ sanitizeState, cloneState, canonicalStemId, safeDecodeUrl, stemIdFromUrl, loadState, saveState, loadProfiles, saveProfiles, normalizeAvailableStems, levelFor, + extractStemMeta, stemDisplayName, STEM_LABELS, }; return; } @@ -1610,7 +1667,10 @@ onStemsStateEvent = (e) => { const d = e && e.detail; if (!d || d.event !== 'provider-ready') return; - if (Array.isArray(d.stemIds)) setAvailableStems(d.stemIds); + // `stems` rows carry the manifest's optional name/description + // (feedpak §5.3) alongside ids; `stemIds` is the older plain-id shape. + if (Array.isArray(d.stems) && d.stems.length) setAvailableStems(d.stems); + else if (Array.isArray(d.stemIds)) setAvailableStems(d.stemIds); else if (Number(d.stemCount) === 0) setAvailableStems([]); }; window.addEventListener('stems:state', onStemsStateEvent); @@ -1626,6 +1686,7 @@ // timeout would flip the new song to "no stems"). clearStemBootstrapTimers(); availableStems = null; + stemMeta = Object.create(null); const result = await originalPlaySong.apply(this, args); // New song: audio elements and stems-plugin gain nodes are // recreated, so every cached mapping and pushed level is stale. diff --git a/tests/state.test.js b/tests/state.test.js index dd24649..b176a1d 100644 --- a/tests/state.test.js +++ b/tests/state.test.js @@ -197,6 +197,46 @@ test('normalizeAvailableStems canonicalizes, dedupes, drops full/blank, handles assert.deepEqual(normalizeAvailableStems([]), []); }); +test('extractStemMeta keeps name/description from object rows, keyed canonically', () => { + const { extractStemMeta } = freshPlugin(); + const meta = extractStemMeta([ + { id: 'Guitar', name: 'Rhythm Guitar' }, + { id: 'click', name: 'Click', description: 'Metronome click with 4-count lead-in.' }, + { id: 'Voice', name: 'Lead Vox' }, // alias -> vocals + { id: 'full', name: 'Full Mix' }, // reserved mixdown dropped + { id: 'bass' }, // no metadata -> no entry + { id: 'drums', name: ' ', description: 7 }, // blank / non-string dropped + 'strings', // plain id string -> no entry + null, + ]); + assert.deepEqual(meta.guitar, { name: 'Rhythm Guitar' }); + assert.deepEqual(meta.click, { name: 'Click', description: 'Metronome click with 4-count lead-in.' }); + assert.deepEqual(meta.vocals, { name: 'Lead Vox' }); + assert.equal('full' in meta, false); + assert.equal('bass' in meta, false); + assert.equal('drums' in meta, false); + assert.equal('strings' in meta, false); +}); + +test('extractStemMeta yields an empty map for plain string arrays and junk', () => { + const { extractStemMeta } = freshPlugin(); + assert.deepEqual(Object.keys(extractStemMeta(['guitar', 'bass'])), []); + assert.deepEqual(Object.keys(extractStemMeta('nope')), []); + assert.deepEqual(Object.keys(extractStemMeta(null)), []); +}); + +test('stemDisplayName prefers manifest name, then built-in label, then capitalized id', () => { + const { stemDisplayName, STEM_LABELS } = freshPlugin(); + const meta = { guitar: { name: 'Rhythm Guitar' }, click: { description: 'no name here' } }; + assert.equal(stemDisplayName('guitar', meta), 'Rhythm Guitar'); + assert.equal(stemDisplayName('vocals', meta), STEM_LABELS.vocals); // built-in label ("Voice") + assert.equal(stemDisplayName('click', meta), 'Click'); // description alone doesn't rename + assert.equal(stemDisplayName('kazoo', meta), 'Kazoo'); // unknown id capitalized + assert.equal(stemDisplayName('kazoo', null), 'Kazoo'); + // Inherited names must not leak off Object.prototype. + assert.equal(stemDisplayName('constructor', {}), 'Constructor'); +}); + test('loadProfiles tolerates corrupt storage and non-object payloads', () => { const { loadProfiles } = freshPlugin(); global.localStorage.setItem('stem_mixer:profiles', '{not json'); From 539c550d9759c010bd432866e6e56e0db0085205 Mon Sep 17 00:00:00 2001 From: topkoa Date: Sun, 19 Jul 2026 12:08:09 -0400 Subject: [PATCH 2/3] Store metadata trimmed; let the label actually shrink (review) Two Copilot catches: - extractStemMeta rejected whitespace-only values via trim() but stored the raw string, so padded manifest values would reach the label and tooltip. Store the trimmed string; test pins it. - the ellipsis on the name label never engaged: a flex item won't shrink below its content without min-width:0 (plus flex:1 1 auto), so a long manifest name would overflow the 58px column instead of clipping. Co-Authored-By: Claude Fable 5 Signed-off-by: topkoa --- screen.js | 15 +++++++++++---- tests/state.test.js | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/screen.js b/screen.js index 0c01f18..e108547 100644 --- a/screen.js +++ b/screen.js @@ -259,8 +259,12 @@ const canonical = canonicalStemId(entry.id); if (!canonical || canonical === 'full' || canonical === '__proto__') return; const meta = {}; - if (typeof entry.name === 'string' && entry.name.trim()) meta.name = entry.name; - if (typeof entry.description === 'string' && entry.description.trim()) meta.description = entry.description; + // Stored trimmed: whitespace-only is already rejected, so padding + // must not survive into the label / tooltip either. + const name = typeof entry.name === 'string' ? entry.name.trim() : ''; + const description = typeof entry.description === 'string' ? entry.description.trim() : ''; + if (name) meta.name = name; + if (description) meta.description = description; if (Object.keys(meta).length && !(canonical in out)) out[canonical] = meta; }); return out; @@ -949,8 +953,11 @@ const label = document.createElement('span'); label.textContent = stemDisplayName(stem, stemMeta); - // Manifest names can outgrow the 58px column — clip, don't wrap the row. - label.style.cssText = 'font-size:11px;color:#b5bfd5;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;'; + // Manifest names can outgrow the 58px column — clip, don't wrap the + // row. flex/min-width let the span actually shrink inside the flex + // container; without them the ellipsis never engages and long names + // overflow the column. + label.style.cssText = 'font-size:11px;color:#b5bfd5;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1 1 auto;min-width:0;'; name.appendChild(label); if (meta && meta.description) { diff --git a/tests/state.test.js b/tests/state.test.js index b176a1d..e05d9e5 100644 --- a/tests/state.test.js +++ b/tests/state.test.js @@ -210,6 +210,8 @@ test('extractStemMeta keeps name/description from object rows, keyed canonically null, ]); assert.deepEqual(meta.guitar, { name: 'Rhythm Guitar' }); + // Padded values are stored trimmed, not raw. + assert.deepEqual(extractStemMeta([{ id: 'bass', name: ' Bass VI ' }]).bass, { name: 'Bass VI' }); assert.deepEqual(meta.click, { name: 'Click', description: 'Metronome click with 4-count lead-in.' }); assert.deepEqual(meta.vocals, { name: 'Lead Vox' }); assert.equal('full' in meta, false); From 944b6b63123d04c0449b59e4f305342a8408c704 Mon Sep 17 00:00:00 2001 From: topkoa Date: Sun, 19 Jul 2026 12:14:58 -0400 Subject: [PATCH 3/3] Own-key metadata reads; reorders don't wipe stemMeta (review) Two Copilot catches on the metadata plumbing: - extractStemMeta claimed "only own values survive" but read id/name/description through normal property access, so a crafted prototype could smuggle values in. All three now go through hasOwnProperty, matching the file's prototype-safety pattern. - metaChanged was gated on an order-sensitive list compare, so a plain-id source replaying the same stems in a different order counted as a "new list" and wiped metadata a richer source had provided. Membership change (sameStemSet, order-insensitive) now gates the wipe; reorder-only reports keep the metadata. availableStems itself still updates on reorder, so row order keeps following the report. Tests pin both: inherited-key rejection and set-vs-order semantics. Co-Authored-By: Claude Fable 5 Signed-off-by: topkoa --- screen.js | 32 ++++++++++++++++++++++++-------- tests/state.test.js | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/screen.js b/screen.js index e108547..6e07f9e 100644 --- a/screen.js +++ b/screen.js @@ -251,18 +251,23 @@ } // Display metadata from object rows, keyed by canonical id. Only own, - // non-blank strings survive; plain string arrays yield an empty map. + // non-blank strings survive — own-key reads throughout, so values riding + // in off a crafted prototype are never treated as metadata; plain string + // arrays yield an empty map. function extractStemMeta(ids) { + const own = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key); const out = Object.create(null); (Array.isArray(ids) ? ids : []).forEach((entry) => { if (!entry || typeof entry !== 'object') return; - const canonical = canonicalStemId(entry.id); + const canonical = canonicalStemId(own(entry, 'id') ? entry.id : ''); if (!canonical || canonical === 'full' || canonical === '__proto__') return; const meta = {}; // Stored trimmed: whitespace-only is already rejected, so padding // must not survive into the label / tooltip either. - const name = typeof entry.name === 'string' ? entry.name.trim() : ''; - const description = typeof entry.description === 'string' ? entry.description.trim() : ''; + const rawName = own(entry, 'name') ? entry.name : undefined; + const rawDescription = own(entry, 'description') ? entry.description : undefined; + const name = typeof rawName === 'string' ? rawName.trim() : ''; + const description = typeof rawDescription === 'string' ? rawDescription.trim() : ''; if (name) meta.name = name; if (description) meta.description = description; if (Object.keys(meta).length && !(canonical in out)) out[canonical] = meta; @@ -270,15 +275,26 @@ return out; } + // Same membership regardless of order. Reorder-only reports must not count + // as a "new list" for metadata purposes: a plain-id source replaying the + // same stems in a different order carries no metadata, and treating the + // reorder as a list change would let it wipe what a richer source provided. + function sameStemSet(a, b) { + if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false; + return a.every(id => b.includes(id)); + } + function setAvailableStems(ids) { const next = ids == null ? null : normalizeAvailableStems(ids); const nextMeta = extractStemMeta(ids); const listChanged = JSON.stringify(next) !== JSON.stringify(availableStems); // A metadata-less report (plain id strings from an older stems plugin, // bridge/audio-map derived keys) must never wipe metadata a richer - // report already provided for the same list — only a list change or a - // report that actually carries metadata may replace it. - const metaChanged = (listChanged || Object.keys(nextMeta).length > 0) + // report already provided for the same stems — only a membership + // change (not a reorder of the same set) or a report that actually + // carries metadata may replace it. + const membershipChanged = listChanged && !sameStemSet(next, availableStems); + const metaChanged = (membershipChanged || Object.keys(nextMeta).length > 0) && JSON.stringify(nextMeta) !== JSON.stringify(stemMeta); if (!listChanged && !metaChanged) return; if (listChanged) availableStems = next; @@ -1661,7 +1677,7 @@ sanitizeState, cloneState, canonicalStemId, safeDecodeUrl, stemIdFromUrl, loadState, saveState, loadProfiles, saveProfiles, normalizeAvailableStems, levelFor, - extractStemMeta, stemDisplayName, STEM_LABELS, + extractStemMeta, stemDisplayName, sameStemSet, STEM_LABELS, }; return; } diff --git a/tests/state.test.js b/tests/state.test.js index e05d9e5..feb0456 100644 --- a/tests/state.test.js +++ b/tests/state.test.js @@ -227,6 +227,25 @@ test('extractStemMeta yields an empty map for plain string arrays and junk', () assert.deepEqual(Object.keys(extractStemMeta(null)), []); }); +test('extractStemMeta reads id/name/description as own keys only', () => { + const { extractStemMeta } = freshPlugin(); + // Values riding in off the prototype must not become metadata. + const inherited = Object.create({ id: 'guitar', name: 'Evil', description: 'nope' }); + assert.deepEqual(Object.keys(extractStemMeta([inherited])), []); + const ownId = Object.create({ name: 'Evil' }); + ownId.id = 'bass'; + assert.deepEqual(Object.keys(extractStemMeta([ownId])), []); +}); + +test('sameStemSet ignores order, catches membership changes', () => { + const { sameStemSet } = freshPlugin(); + assert.equal(sameStemSet(['guitar', 'drums'], ['drums', 'guitar']), true); + assert.equal(sameStemSet(['guitar', 'drums'], ['guitar', 'bass']), false); + assert.equal(sameStemSet(['guitar'], ['guitar', 'drums']), false); + assert.equal(sameStemSet(null, ['guitar']), false); + assert.equal(sameStemSet(['guitar'], null), false); +}); + test('stemDisplayName prefers manifest name, then built-in label, then capitalized id', () => { const { stemDisplayName, STEM_LABELS } = freshPlugin(); const meta = { guitar: { name: 'Rhythm Guitar' }, click: { description: 'no name here' } };