refactor(studio): extract the visualisation layer to src/viz.js (step 6) - #21
Conversation
Move the rAF playhead loop (_startAnimLoop/_stopAnimLoop), waveform canvas rendering + zoom/scroll (_drawWaveform/_redrawWaveform/_drawAllCursors/ _clampScroll/_initWaveformWheelZoom), and the master meter (_startMasterMeter/ _debounceSaveMaster) out of main.js into src/viz.js. Upper layer over the audio engine: imports _getAudioCtx (audio-graph) + _formatTime (util), reaches the stop action via window.studioStop (global, no import-back). Its 3 animation/meter exports are the ones main.js injects into audio-graph via configureAudioGraph — no cycle (audio-graph never imports viz). Also moved _getTrackColor + TRACK_COLORS/INSTRUMENT_COLORS to util.js: viz's _redrawWaveform needs it and so does main's render, so the pure colour helper belongs in the shared leaf (fixes the ReferenceError Codex caught where viz referenced a main-private helper). +util test. main.js 2489 -> 2236. node 15/15, python 25/25. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR extracts visualization logic from ChangesVisualization extraction
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant RAF as requestAnimationFrame
participant Viz as viz.js
participant DOM as Studio UI
participant Window as window.studioStop
RAF->>Viz: _startAnimLoop tick
Viz->>DOM: update studio-time-current, studio-seek-bar
Viz->>Viz: _drawAllCursors(timeSeconds)
Viz->>DOM: redraw waveform canvases
Viz->>Window: studioStop() when duration reached
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR continues the Studio ES-module refactor by extracting the visualisation responsibilities (playhead rAF loop, waveform rendering/zoom/scroll, and master level meter) out of main.js into a dedicated src/viz.js, while also relocating the shared track-colour helper into src/util.js and adding focused unit tests to pin the new seams.
Changes:
- Extract visualisation logic from
src/main.jsintosrc/viz.jsand wire it back viaconfigureAudioGraph(avoiding an import cycle). - Move
_getTrackColor(and its palettes) intosrc/util.jsfor shared use, and add a unit test for it. - Add
tests/audio-graph.test.mjsto validate theconfigureAudioGraphinjection contract and module importability.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/util.test.mjs | Adds coverage for the newly shared _getTrackColor helper. |
| tests/audio-graph.test.mjs | Pins the configureAudioGraph seam and verifies exported surface. |
| src/viz.js | New module containing the visualisation layer (animation loop, waveform rendering, master meter). |
| src/util.js | Adds _getTrackColor and related palette constants. |
| src/main.js | Removes inlined visualisation/color helpers and imports them from viz.js/util.js. |
| CHANGELOG.md | Documents step 6 of the ES-module migration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address Copilot on #21 — a fractional canvas width W made new Float32Array(peakCount) risk a RangeError; a peak count is integral by nature, so floor it. (Pre-existing; moved verbatim, hardened here since it's a trivial safe integer guard.) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What
Step 6. Moves the visualisation layer out of
main.jsintosrc/viz.js:_startAnimLoop/_stopAnimLoop_drawWaveform/_redrawWaveform/_drawAllCursors/_clampScroll/_initWaveformWheelZoom_startMasterMeter/_debounceSaveMasterUpper layer over the audio engine: imports
_getAudioCtx(audio-graph) +_formatTime(util), reaches the stop action via thewindow.studioStopglobal (no import-back). Its 3 animation/meter exports are whatmain.jsinjects into audio-graph viaconfigureAudioGraph— no cycle (audio-graph never imports viz).Also moved
_getTrackColor+TRACK_COLORS/INSTRUMENT_COLORS→util.js:viz's_redrawWaveformneeds it and so doesmain's render, so the pure colour helper belongs in the shared leaf. (This fixes theReferenceErrorCodex flagged in preflight — viz referencing a main-private helper.) Added a_getTrackColorunit test.main.js2489 → 2236.Tests
node --test15/15,pytest25/25. Codex preflight: 0 (clean after the_getTrackColorfix).Summary by CodeRabbit
New Features
Bug Fixes
Tests