Skip to content

refactor(studio): extract recording to src/recording.js (step 9, final module) - #24

Merged
byrongamatos merged 1 commit into
mainfrom
feat/es-module-split-recording
Jul 8, 2026
Merged

refactor(studio): extract recording to src/recording.js (step 9, final module)#24
byrongamatos merged 1 commit into
mainfrom
feat/es-module-split-recording

Conversation

@byrongamatos

@byrongamatos byrongamatos commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

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.js into src/recording.js: ~22 functions including the window.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 _populatePunchTrackSelect here — so no static cycle. _stopRecording is exported (main's studioStop calls it when S.isRecording).

§V idempotency

The window.studio* record commands register inside configureRecording (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-op reloadSession) set. This makes recording consistent with the rest of main's guarded window.studio* registration, honouring constitution §V.

main.js 1993 → 1309.

Tests

node --test 15/15, pytest 25/25. Codex preflight caught + fixed 5 issues across iterations (4 missed cluster members, the _stopRecording export, the §V re-registration); final review clean.

Behavioral + mic-driven — on-device (if a mic is available): record a take, punch-in re-record, and highway record; each should upload + refresh the session. Stop-while-recording should stop the recorder.

Summary by CodeRabbit

  • New Features
    • Added support for multiple recording flows in the studio, including standard recording, punch-in/punch-out, and live “highway” recording.
    • Recording uploads now handle session updates more smoothly, with the studio returning to the session after completion.

…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>
Copilot AI review requested due to automatic review settings July 8, 2026 21:22
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8b9dad08-d071-4bf7-a186-c2ec8fac9fce

📥 Commits

Reviewing files that changed from the base of the PR and between 4040a06 and 2826173.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • src/main.js
  • src/recording.js

📝 Walkthrough

Walkthrough

Recording 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.

Changes

Recording module extraction

Layer / File(s) Summary
Module wiring and main.js cleanup
src/main.js
Imports configureRecording and helpers from recording.js, calls it with { reloadSession: _reloadSession }, trims unused util imports, and removes prior in-file window.studioToggleRecord, punch controls, window.studioHighwayRecord, and window.studioActivateTake implementations.
Main-track recording implementation
src/recording.js
Implements configureRecording, toggle/start/stop handlers using MediaRecorder, and uploads the recorded blob to the session upload endpoint.
Punch-in/out recording implementation
src/recording.js
Populates the punch track select, validates punch timing, records within the punch window, and uploads the splice with punch metadata before reloading the session.
Highway live recording implementation
src/recording.js
Implements studioHighwayRecord with overlay UI, readiness polling, metering, draw hook, cleanup, stop, upload (trim/expected duration), and studioActivateTake.
Changelog entry
CHANGELOG.md
Documents the move-only extraction of recording logic to src/recording.js.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: extracting recording logic into src/recording.js as the final step of the studio refactor.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/es-module-split-recording

Comment @coderabbitai help to get the list of available commands.

@byrongamatos
byrongamatos merged commit 1b6eb76 into main Jul 8, 2026
4 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.js encapsulating recording/punch/highway logic and registering window.studio* handlers via configureRecording.
  • Updated src/main.js to import/configure recording, call exported _stopRecording, and keep _reloadSession calling _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.

Comment thread src/recording.js

S.recordedChunks = [];

// Use MediaRecorder with WAV-compatible format
Comment thread src/recording.js
Comment on lines +295 to +308
// 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);
Comment thread src/recording.js
Comment on lines +458 to +460
if (!S.hwAnalyser) return;
const data = new Uint8Array(S.hwAnalyser.frequencyBinCount);
S.hwAnalyser.getByteTimeDomainData(data);
Comment thread CHANGELOG.md

- **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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants