refactor(editor): move Sync-Tempo to src/sync-tempo.js (R2, step 33) - #185
Conversation
Extract the tempo-sync feature (detectAudioBPM onset-autocorrelation, getTabBPM, and the sync dialog that scales notes/beats/sections to match — respecting locked sync points) out of the src/main.js monolith into a new native ES module. - src/sync-tempo.js: 4 window.editor* handlers (re-attached by main.js) + getTabBPM exported back (main.js calls it at 2 sites). The start-landing helpers (editorShowStartLanding / _editorMaybeShowStartLanding) that shared the banner are a separate feature and STAYED in main.js — this was a function-level cut. - draw routes through host; no new host hook. - Removed the now-dead beatOf/timeOf main.js import (only the moved reproject used them). - tests/beat_lock.test.mjs retargeted to slice editorApplySync's section-scale loop from sync-tempo.js. main.js drops ~218 lines. 34 modules. Verified: 90/90 JS suites pass, ESLint gate clean (0 errors), strict no-undef clean on sync-tempo.js, Codex preflight 0 issues. New headless harness drives the REAL detect→apply flow: editorSyncTempo detects the audio BPM (autocorrelation over the decoded buffer) and tab BPM, populates the dialog; editorApplySync scales by the factor and reports it (proving host.draw); dialog closes; zero page errors. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Caution Review failedFailed to post review comments. GitHub was unavailable or timed out while CodeRabbit was posting the review. Please request a new review later if the pull request still needs one. Use ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
⏰ Context from checks skipped due to timeout. (1)
🧰 Additional context used🪛 ast-grep (0.44.1)src/sync-tempo.js[error] 135-135: React's useState should not be directly called (usestate-direct-usage) [error] 139-139: React's useState should not be directly called (usestate-direct-usage) [error] 155-155: React's useState should not be directly called (usestate-direct-usage) [error] 224-224: React's useState should not be directly called (usestate-direct-usage) 📝 WalkthroughWalkthroughSync Tempo functionality moves from ChangesSync Tempo modularization
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant EditorUI
participant sync-tempo.js
participant S.audioBuffer
participant S.beats
participant host.draw
EditorUI->>sync-tempo.js: editorSyncTempo()
sync-tempo.js->>S.audioBuffer: detectAudioBPM()
sync-tempo.js->>S.beats: getTabBPM()
sync-tempo.js->>EditorUI: show BPM and factor dialog
EditorUI->>sync-tempo.js: editorApplySync()
sync-tempo.js->>S.beats: rescale beats, notes, and sections
sync-tempo.js->>host.draw: redraw editor
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
What
Step 33 of the R2 module-extraction refactor: move the Sync-Tempo feature out of
src/main.jsinto a new native ES modulesrc/sync-tempo.js.Detect the audio's BPM (onset autocorrelation), compare against the tab's grid BPM, and scale notes/beats/sections to match — reprojecting onto the warped grid when a sync point is locked.
How the seam is drawn
window.editor*handlers (editorSyncTempo/editorSyncUpdateFactor/editorHideSyncDialog/editorApplySync) become named exports, re-attached bymain.js.getTabBPMexported back —main.jscalls it at 2 sites.editorShowStartLanding/_editorMaybeShowStartLanding) that happened to share the banner are a separate feature and stayed in main.js — this was a function-level cut, not a banner range.drawroutes throughhost; no new host hook.beatOf/timeOfmain.jsimport (only the moved reproject used them).tests/beat_lock.test.mjsretargeted to sliceeditorApplySync's section-scale loop fromsrc/sync-tempo.js(byte-identical).main.js drops ~218 lines. 34 modules.
Verification
no-undefclean onsync-tempo.js.verify_sync_tempo.py) drives the real detect→apply flow:editorSyncTempodetects the audio BPM by autocorrelation over the decoded buffer (90 tab / 120 audio on the diagnostic song) and populates the dialog;editorApplySyncscales by the 1.3333× factor and reports it (provinghost.drawresolved); the dialog closes; zero page errors. Negative-checked by breaking thehost.drawcall.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests