refactor(editor): move arrangement management to src/arrangement.js (R2, step 30) - #182
Conversation
…R2, step 30) Extract the arrangement-level operations out of the src/main.js monolith into a new native ES module: the undoable part rename (with the cross-kind guard @pure:rename-arr + RenameArrangementCmd), remove-arrangement, and the Add-Drums import (drum_tab.json from a GP/MIDI file). Add-Drums is the drum sibling of the keys/guitar imports in import.js and chains into its two shared post-import dialogs (_maybeOfferMidiTempoMap / _showDrumImportUnmappedModal). - src/arrangement.js: 7 window.editor* entry points (re-attached by main.js), the @pure:rename-arr block, RenameArrangementCmd. No back-exports: nothing in main.js references a symbol defined here. - Every dep that stays in main.js (draw, updateStatus, updateArrangementSelector, effectiveAudioOffset) routes through host — all four are pre-existing hooks, so no new host wiring this step. - tests/rename_part.test.mjs retargeted to slice @pure:rename-arr + RenameArrangementCmd from src/arrangement.js; injects a host stub because the command now refreshes the selector via host.updateArrangementSelector. main.js drops ~377 lines (5,804 → after wiring). 31 modules. Verified: 90/90 JS suites pass, ESLint gate clean (0 errors), strict no-undef clean on arrangement.js, Codex preflight 0 issues. New headless harness drives a real 76-byte channel-9 drums SMF through the actual Add-Drums import: proves the 7 handlers bind, host.effectiveAudioOffset is wired (POSTed audio_offset == seeded +5s), and the arrangement.js->import.js edge works (the tempo-map modal appears). Negative-checked by dropping a re-attach. 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)
📝 WalkthroughWalkthroughChangesArrangement editor operations
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Editor as editorDrumsFileSelected
participant ImportAPI as import-list endpoint
participant Commit as editorDoAddDrums
participant DrumAPI as drum import endpoint
participant State as S.drumTab and UI
Editor->>ImportAPI: submit GP or MIDI file
ImportAPI-->>Editor: return candidate tracks
Editor->>Commit: select drum track
Commit->>DrumAPI: submit selected track and offset
DrumAPI-->>Commit: return drum_tab
Commit->>State: store and sort hits, clear selection, refresh UI
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 R2 module-extraction refactor by moving arrangement-level editor operations out of src/main.js into a dedicated ES module (src/arrangement.js), with main.js re-attaching the public window.editor* entry points and routing retained main.js dependencies through the existing host hook object.
Changes:
- Extracts arrangement rename (including the cross-kind
@pure:rename-arrguard), arrangement removal, and Add-Drums import flow intosrc/arrangement.js. - Updates
src/main.jsto import these new module exports and re-attach the correspondingwindow.editor*handlers. - Retargets
tests/rename_part.test.mjsto slice@pure:rename-arrandRenameArrangementCmdfromsrc/arrangement.js, injecting ahoststub for selector refresh.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/rename_part.test.mjs | Updates the test harness to read/extract the pure rename guard and command from src/arrangement.js, and stubs host.updateArrangementSelector. |
| src/main.js | Removes arrangement-management implementations and re-attaches arrangement-related window.editor* entry points to src/arrangement.js exports; keeps dependencies routed via host. |
| src/arrangement.js | New module containing rename/remove/add-drums logic, calling back into main.js through host and reusing shared import dialogs from import.js. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
What
Step 30 of the R2 module-extraction refactor: move arrangement-level operations out of
src/main.jsinto a new native ES modulesrc/arrangement.js.Covers:
RenameArrangementCmd+ the@pure:rename-arrcross-kind guard (a rename can't silently change the name-inferred instrument kind and strand notes).drum_tab.jsonimport from a GP or MIDI file. This is the drum sibling of the keys/guitar imports moved in step 29, and chains into import.js's two shared post-import dialogs (_maybeOfferMidiTempoMap/_showDrumImportUnmappedModal).How the seam is drawn
window.editor*entry points become named exports;main.jsre-attaches them.main.jsreferences a symbol defined here.main.js(draw,updateStatus,updateArrangementSelector,effectiveAudioOffset) routes throughhost; all four are pre-existing hooks, so no new host wiring this step.arrangement.jsimports the two dialog helpers fromimport.js— a clean module→module edge.tests/rename_part.test.mjsretargeted to slice@pure:rename-arr+RenameArrangementCmdfromsrc/arrangement.js; it now injects ahoststub because the command refreshes the selector viahost.updateArrangementSelector.main.jsdrops ~377 lines. 31 modules.Verification
no-undefclean onarrangement.js.verify_arrangement.py) drives a real Add-Drums import of a 76-byte channel-9 drums SMF (kick+snare, 120 BPM, 4/4) through the actual#editor-add-drums-gpinput andeditorDoAddDrums: asserts the 7 handlers bind, the single-arrangement remove is a guarded no-op,host.effectiveAudioOffsetis wired (POSTedaudio_offset== a seeded +5s), and thearrangement.js → import.jsedge works (the MIDI tempo-map modal appears). Negative-checked by dropping a re-attach → harness throws.🤖 Generated with Claude Code
Summary by CodeRabbit