Repository navigation
fix: drive sliders from the song's actual stems - #10
Conversation
The mixer rendered six hardcoded sliders for every song: dead sliders on songs without stems (drags silently no-oped), and no slider at all for stems outside the six known ids, which played at full volume with no control. Track per-song availability (stems:state provider-ready when the stems plugin is loaded, the bootstrap poll otherwise; null until either reports) and render slider rows from it: only the song's stems get rows, a stem-less song gets a "No stems available" notice, unknown availability keeps the old six. Unknown stem ids are now first-class: sanitizeState keeps their levels (so they persist and survive profiles), the audio-map gains exact id detection from data-stem and /stems/<id> paths, and the legacy gain-node wiring and level pushes follow the dynamic list. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: topkoa <topkoa@gmail.com>
|
Warning Review limit reached
Next review available in: 49 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe stem mixer now discovers per-song stem IDs, preserves dynamic levels, applies them during bootstrap, and rebuilds slider rows accordingly. Songs without stems display an empty-state message, while plugin events and song changes reset and resynchronize stem availability. ChangesDynamic stem mixer
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Song
participant StemsPlugin
participant StemMixer
participant AudioGraph
Song->>StemsPlugin: playSong
StemsPlugin->>StemMixer: stems:state provider-ready
StemMixer->>AudioGraph: discover and configure current stem IDs
AudioGraph-->>StemMixer: stem audio map
StemMixer->>StemMixer: render rows and apply stored levels
Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Updates the Stem Mixer UI and persisted state handling to reflect the actual stems present in the current song, including arbitrary stem IDs beyond the legacy six, and introduces an explicit “unknown / none / list” availability model to avoid dead sliders.
Changes:
- Track per-song stem availability (event-driven with bootstrap polling fallback) and render slider rows dynamically (including “No stems available” message).
- Preserve and apply dynamic (non-
STEM_KEYS) stem level keys through state sanitization, audio-map detection, and UI updates. - Add tests for dynamic-key preservation/normalization, and bump plugin version.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/state.test.js | Adds coverage for dynamic level preservation, alias folding expectations, localStorage round-trips, and availability normalization. |
| screen.js | Implements three-valued availableStems, dynamic slider row rendering, dynamic stem detection, and state sanitization updates. |
| README.md | Updates feature description to reflect per-song/dynamic stem sliders and the no-stems notice. |
| plugin.json | Bumps plugin version to 1.3.0. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ng change Review follow-ups: own-key lookups everywhere a dynamic stem id indexes a plain object (STEM_ALIASES, STEM_LABELS, levels dedup), drop __proto__ outright, and kill the previous song's bootstrap timers at the top of the playSong wrapper so a leftover tick can't report the old song's stems or flip the new song to 'no stems' mid-load. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: topkoa <topkoa@gmail.com>
Review follow-ups: an array smuggled into persisted levels no longer leaks its numeric indices in as stem ids, and getStemAudioMap's exact-id detection drops __proto__ like every other dynamic-id path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: topkoa <topkoa@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (4)
screen.js:589
state.levels[stem] !== undefinedcan mis-detect a missing dynamic stem level whenstemcollides withObject.prototype(e.g., "constructor"). In that casestate.levels[stem]resolves to an inherited function, which then gets passed intosetStemVolumeand can produce NaN/invalid gain. Use an own-property check when deciding whether to fall back to the default level.
const level = state.levels[stem] !== undefined ? state.levels[stem] : 1;
screen.js:722
- For dynamic stem ids that collide with
Object.prototype(e.g., "constructor"),state.levels[stem] !== undefinedmay return an inherited function even when no saved level exists. That makesMath.round(level * 100)yield NaN and can set the range input to an invalid value. Prefer an own-property check for the default fallback.
const level = state.levels[stem] !== undefined ? state.levels[stem] : 1;
screen.js:752
- When
stemis a dynamic id that collides withObject.prototype(e.g., "constructor"),state.levels[stem] !== undefinedcan be true even if there is no own key, causinglevelto become an inherited function and breaking the appliedLevels idempotence check / volume push. UsehasOwnPropertyto determine whether a saved level exists.
const level = state.levels[stem] !== undefined ? state.levels[stem] : 1;
screen.js:945
state.levels[stem] !== undefinedis unsafe for dynamic stem ids that may matchObject.prototypeproperties (e.g., "constructor"). If there is no saved level, the lookup returns an inherited function andNumber(...)becomes NaN, creating a broken slider value. Use an own-property check and default to 1 when absent.
const current = state.levels[stem] !== undefined ? Number(state.levels[stem]) : 1;
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
screen.js (1)
121-157: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAlias-only dynamic levels are silently dropped for the six known stems.
next.levelsalready owns all sixSTEM_KEYS(defaulted to 1) the moment it's cloned fromDEFAULT_STATE— before theSTEM_KEYS.forEachpass even runs. So the dynamic loop's guardObject.prototype.hasOwnProperty.call(next.levels, canonical)is always true for any alias resolving to one of the six known ids, even when the raw payload never contained the canonical key itself. A payload like{ levels: { voice: 0.9 } }(alias only, novocalskey) will have itsvoicevalue dropped andvocalssilently reset to the default1, instead of being folded in as the "aliased dynamic keys are folded into the canonical known key" comment/behavior implies.In current normal operation this is low-probability, since
setStemVolumealways canonicalizes beforesaveState, so this plugin never itself persists alias-only keys — but it's a real gap for legacy-format or externally-written state. Guard against the raw payload instead of the already-defaultednext.levels:🐛 Proposed fix
Object.keys(rawLevels).forEach((key) => { const canonical = canonicalStemId(key); - // Own-key check, not `in`: next.levels is a plain object, so `in` - // would see inherited names ('constructor', …) and wrongly skip a - // stem that happens to use one. '__proto__' is the one key plain - // assignment can't shadow — drop it outright. + // Check the RAW payload for an existing canonical entry, not + // next.levels — next.levels already owns all six STEM_KEYS + // (defaulted to 1) before this loop runs, so checking it would + // always block an alias-only value (e.g. only "voice", no + // "vocals") from ever reaching its canonical stem. + // '__proto__' is the one key plain assignment can't shadow — + // drop it outright. if (!canonical || canonical === 'full' || canonical === '__proto__' || - Object.prototype.hasOwnProperty.call(next.levels, canonical)) return; + (canonical !== key && Object.prototype.hasOwnProperty.call(rawLevels, canonical))) return; const n = Number(rawLevels[key]); if (Number.isFinite(n)) next.levels[canonical] = Math.max(0, Math.min(1, n)); });Worth adding a test for the alias-only case (only
voice, novocals) alongside the existing "both present" test in tests/state.test.js.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@screen.js` around lines 121 - 157, Update sanitizeState’s dynamic levels loop to check whether the canonical key exists in rawLevels, rather than next.levels, so alias-only entries such as voice are folded into the known canonical stem. Preserve the existing handling for explicit canonical keys, unknown stems, and reserved keys, and add coverage in the state tests for an alias-only payload.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@screen.js`:
- Around line 121-157: Update sanitizeState’s dynamic levels loop to check
whether the canonical key exists in rawLevels, rather than next.levels, so
alias-only entries such as voice are folded into the known canonical stem.
Preserve the existing handling for explicit canonical keys, unknown stems, and
reserved keys, and add coverage in the state tests for an alias-only payload.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d84277fd-5c29-4540-b917-eff886bf3407
📒 Files selected for processing (4)
README.mdplugin.jsonscreen.jstests/state.test.js
CodeRabbit: the dynamic-levels dedup checked next.levels, which already owns all six defaulted STEM_KEYS, so an alias-only payload (voice with no vocals) could never reach its canonical stem - dedup against the raw payload instead, with exact canonical keys still winning over aliases. Copilot: reading state.levels[stem] with a bare !== undefined resolved inherited names (constructor) to prototype values for dynamic ids - new levelFor() helper does an own-key, finite, clamped lookup with default 1, used at all four read sites. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: topkoa <topkoa@gmail.com>
|
Addressed both review-body findings in f4ec4a4: @coderabbitai's outside-diff comment (alias-only dynamic levels dropped, screen.js 121–157): confirmed — Copilot's four suppressed low-confidence comments ( 20/20 tests pass. |
|
Tip For best results, initiate chat on the files or code changes.
🐇 ✅ If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
Problem
The mixer rendered six hardcoded sliders (
STEM_KEYS) for every song:strings,synth, …) got no slider at all and played at full volume with no control. Their levels were also stripped from state on every load (sanitizeStaterebuiltlevelsfromSTEM_KEYSonly).Change
Track per-song stem availability and render slider rows from it:
stems:stateprovider-readyevent (authoritative, instant —stemIds, orstemCount: 0for stem-less songs); the existing bootstrap poll as fallback for hosts without the stems plugin (derives ids fromstems.getState()/ bridge / audio-map, and flips unknown → known-empty on its 12 s give-up). Reset to unknown at the top of theplaySongwrapper, before the await, so aprovider-readythat lands mid-flight isn't erased.null= unknown → render the default six (exactly the old behavior, no "no stems" flash during load);[]→ "No stems available for this song." notice; non-empty → exactly those sliders, in both the floating panel and the plugin screen. Rebuilds are guarded by a rendered-list stash, so unchanged sweeps do zero DOM work.sanitizeStatenow preserves dynamic level keys (canonicalized, clamped — so they persist and survive profiles), the audio-map gained exact-id detection fromdata-stem//stems/<id>.<ext>paths, and the legacy gain-node wiring plus level pushes follow the dynamic list. Labels fall back to a titlecased id.makeSliderRowwith the panel, which also fixes their percent tag never updating fromapplyStateToUi(it looked for_pctTag; the old plugin rows set_valueTag).Testing
node tests/state.test.js— 16/16 pass (5 new: dynamic-key preservation, alias folding, dynamic round-trip through localStorage,normalizeAvailableStemsshapes).🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores