refactor(studio): extract recording to src/recording.js (step 9, final module) - #24
Conversation
…l module)
Move main-track capture, punch-in/out re-record, and live highway recording
(MediaRecorder + upload) out of main.js: ~22 functions incl. the window.studio*
record commands, _startRecording/_stopRecording, _uploadRecording/
_uploadPunchRecording, _beginHwRecording/_hwUploadRecording, the highway overlay/
meter helpers, PUNCH_PREROLL, and _populatePunchTrackSelect. Imports state/util/
audio-graph/prefs; session reload via an injected configureRecording({reloadSession})
seam (main owns _reloadSession, which calls the exported _populatePunchTrackSelect)
— no static cycle. _stopRecording exported (main's studioStop calls it).
The window.studio* record commands register INSIDE configureRecording (guarded
path), not at module top level, so a fresh module re-eval can't clobber installed
handlers with an unconfigured set — honours the §V idempotency guard. main.js
1993 -> 1309.
Codex preflight caught + fixed 5 issues across iterations (4 missed members,
_stopRecording export, the §V re-registration). 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 (3)
📝 WalkthroughWalkthroughRecording functionality (main-track, punch-in/out, and highway live recording) is extracted from src/main.js into a new src/recording.js module. main.js now imports and wires configureRecording with a reloadSession seam, and CHANGELOG.md documents this move-only ES-module migration step. ChangesRecording module extraction
Estimated code review effort: 4 (Complex) | ~60 minutes 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 completes the ES-module migration by extracting the Studio “recording” surface area (main recording, punch-in, and highway recording + upload flows) from src/main.js into a dedicated src/recording.js module, wiring it back into the app via configureRecording({ reloadSession }) to avoid a static import cycle.
Changes:
- Added
src/recording.jsencapsulating recording/punch/highway logic and registeringwindow.studio*handlers viaconfigureRecording. - Updated
src/main.jsto import/configure recording, call exported_stopRecording, and keep_reloadSessioncalling_populatePunchTrackSelect. - Documented the refactor in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/recording.js | New module containing recording, punch-in, and highway recording/upload logic plus the configureRecording registration seam. |
| src/main.js | Wires the new recording module into startup and replaces inline recording implementations with imported helpers. |
| CHANGELOG.md | Notes the migration step and what moved out of main.js. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| S.recordedChunks = []; | ||
|
|
||
| // Use MediaRecorder with WAV-compatible format |
| // Set up audio graph: mic → gain → destination (for recording) | ||
| // mic → gain → analyser (for metering) | ||
| S.hwAudioCtx = new (window.AudioContext || window.webkitAudioContext)(); | ||
| if (S.hwAudioCtx.state === 'suspended') await S.hwAudioCtx.resume(); | ||
| S.hwSourceNode = S.hwAudioCtx.createMediaStreamSource(S.hwMediaStream); | ||
| S.hwGainNode = S.hwAudioCtx.createGain(); | ||
| S.hwGainNode.gain.value = S.hwInputGain; | ||
| S.hwAnalyser = S.hwAudioCtx.createAnalyser(); | ||
| S.hwAnalyser.fftSize = 256; | ||
| S.hwRecDest = S.hwAudioCtx.createMediaStreamDestination(); | ||
|
|
||
| S.hwSourceNode.connect(S.hwGainNode); | ||
| S.hwGainNode.connect(S.hwRecDest); | ||
| S.hwGainNode.connect(S.hwAnalyser); |
| if (!S.hwAnalyser) return; | ||
| const data = new Uint8Array(S.hwAnalyser.frequencyBinCount); | ||
| S.hwAnalyser.getByteTimeDomainData(data); |
|
|
||
| - **ES-module migration, step 9 — extract recording to `src/recording.js`.** | ||
| Main-track capture, punch-in/out re-record, and live "highway" recording | ||
| (MediaRecorder + upload) — 18 functions incl. the `window.studio*` record |
What
Step 9 — the final and most-entangled module. Moves recording (main-track capture, punch-in/out re-record, live "highway" recording — MediaRecorder + upload) out of
main.jsintosrc/recording.js: ~22 functions including thewindow.studio*record commands,_startRecording/_stopRecording,_uploadRecording/_uploadPunchRecording,_beginHwRecording/_hwUploadRecording, the highway overlay/meter helpers,PUNCH_PREROLL, and_populatePunchTrackSelect.Seam + cycle break
Imports state/util/audio-graph/prefs. Session reload goes through an injected
configureRecording({reloadSession})— main owns_reloadSession, which in turn calls the exported_populatePunchTrackSelecthere — so no static cycle._stopRecordingis exported (main'sstudioStopcalls it whenS.isRecording).§V idempotency
The
window.studio*record commands register insideconfigureRecording(the guarded path), not at module top level — so a fresh module re-eval that skips main's IIFE guard can't clobber the installed handlers with an unconfigured (no-opreloadSession) set. This makes recording consistent with the rest ofmain's guardedwindow.studio*registration, honouring constitution §V.main.js1993 → 1309.Tests
node --test15/15,pytest25/25. Codex preflight caught + fixed 5 issues across iterations (4 missed cluster members, the_stopRecordingexport, the §V re-registration); final review clean.Summary by CodeRabbit