refactor(editor): move the drum mouse handlers into src/drum.js (R2, step 20) - #171
Conversation
…step 20) src/main.js 13,347 -> 12,908. The graph stays acyclic. Cleanup, not a new lift. Step 15 moved the drum model, geometry, draw pass and undo commands into src/drum.js, but left 444 lines of mouse handlers and toolbar buttons behind — not by design. They sit physically under the Tempo Map section banner and have none of their own, so the coupling scan never saw them as a candidate and the drum lift never picked them up. Step 19 tripped over the same thing from the other side: the tempo banner's window ran 440 lines past the end of the tempo code, straight through these. They reach eight main.js symbols, seven of which were already host hooks. The eighth, _refreshPartsViewButton, joins them. The interesting one is _refreshTempoMapButton. It lives in src/tempo.js — and tempo.js already imports drum.js, so importing it back would close a cycle. It crosses through `host` instead, which is exactly what host.js is for. Verified beyond the unit tests, which cannot see host wiring. verify_drum.py now clicks a hit into a lane: AddDrumHitCmd rewrites the toolbar's "⟳ Drums (N)" label through host.updateArrangementSelector, so one number proves the whole chain — the click reached _drumEditorOnMouseDown, the command executed through the real EditHistory, and the hook fired. Undo puts it back. Comment out that one hook and all 89 unit tests still pass while the harness fails. node --test 89/89, pytest 248/248, npm run lint 0 errors (6 warnings), Codex clean (byte-for-byte move, no cycles), all 14 headless harnesses pass. 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)
📝 WalkthroughWalkthroughThe drum editor’s canvas handlers, velocity and selection commands, and toolbar controls are consolidated in ChangesDrum editor
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Canvas
participant DrumEditor
participant DrumCommands
participant Host
Canvas->>DrumEditor: mouse and drag events
DrumEditor->>DrumCommands: add, move, velocity, or selection command
DrumCommands->>DrumEditor: committed editor state
Host->>DrumEditor: refresh toolbar callbacks
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Refactors the editor code by relocating the drum editor canvas mouse/drag handlers and related toolbar button logic out of src/main.js into src/drum.js, reducing main.js size and keeping module dependencies acyclic via host callbacks.
Changes:
- Moved drum editor mouse/drag/velocity/selection handlers and drum toolbar button logic into
src/drum.jsand exported the needed entry points. - Extended
hostwithrefreshTempoMapButtonandrefreshPartsViewButtonhooks to avoid an import cycle (tempo.jsalready importsdrum.js). - Updated
src/main.jsto import the new drum editor handlers and wire the additional host hooks; documented the refactor inCHANGELOG.md.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/main.js | Removes inlined drum mouse/toolbar logic, imports new drum editor entry points, and wires new host hooks. |
| src/host.js | Adds refreshTempoMapButton and refreshPartsViewButton to the shared host callback surface. |
| src/drum.js | Adds the moved drum editor interaction handlers and toolbar button logic, switching dependencies to host.* where needed. |
| CHANGELOG.md | Notes the drum interaction/toolbar move and the cycle avoidance via host. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/drum.js (1)
1106-1144: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMinor:
S.drumSel = new Set()instead of.clear()for reset.Elsewhere the selection is reset with
.clear()(lines 1054, 1059). Reassigning the object here (line 1119) is inconsistent, though likely harmless since no other reference to the oldSetappears to be cached across a mode toggle.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/drum.js` around lines 1106 - 1144, In _ensureDrumEditButton, reset the drum selection with S.drumSel.clear() instead of replacing it with a new Set, matching the existing selection-reset pattern and preserving references to the selection set.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/drum.js`:
- Around line 1106-1144: In _ensureDrumEditButton, reset the drum selection with
S.drumSel.clear() instead of replacing it with a new Set, matching the existing
selection-reset pattern and preserving references to the selection set.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: facaea42-4213-41c3-9841-34acc5c4e2ca
📒 Files selected for processing (4)
CHANGELOG.mdsrc/drum.jssrc/host.jssrc/main.js
Copilot, on #171. The comment said 'clamp after snapping' but the code clamps on both sides. Both clamps are load-bearing, for different reasons: the inner one keeps the padding region left of t=0 from handing snapTime a negative time; the outer one catches snapTime rounding backward past zero when the first beat is offset from 0. The comment now says both. `t` is const. Pre-existing wording, moved verbatim in this PR — which is how it surfaced. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Right on both counts, and it is pre-existing wording that this PR moved verbatim — which is how it surfaced. Both clamps are load-bearing, for different reasons, which is why the comment naming only one read as a mistake:
Comment now says both. |
Cleanup, not a new lift.
src/main.js13,347 → 12,908.What was stranded, and why
Step 15 moved the drum model, geometry, draw pass and undo commands into
src/drum.js— and left 444 lines of mouse handlers and toolbar buttons behind. Not by design.They sit physically under the Tempo Map section banner and have none of their own, so the coupling scan never saw them as a candidate and the drum lift never picked them up. Step 19 tripped over the same fact from the other side: the tempo banner’s window ran 440 lines past the end of the tempo code, straight through these. Cutting at
TempoMapCmdrather than at the banner is what kept #170 honest — and left this behind to do properly.One genuine cycle, avoided
They reach eight
main.jssymbols; seven were already host hooks._refreshPartsViewButtonjoins them.The eighth is the interesting one.
_refreshTempoMapButtonlives insrc/tempo.js— andtempo.jsalready importsdrum.js. A direct import would close a cycle. It crosses throughhostinstead, which is precisely whathost.jsis for.Verified: 22 modules, zero cycles.
Why a headless harness, again
verify_drum.pynow clicks a hit into a lane.AddDrumHitCmdrewrites the toolbar’s⟳ Drums (N)label throughhost.updateArrangementSelector, so a single number proves the whole chain: the click reached_drumEditorOnMouseDown, the command executed through the realEditHistory, and the hook fired. Undo puts it back.updateArrangementSelectorunwiredComment out that one hook and all 89 unit tests still pass.
Verification
node --test89/89 ·pytest248/248 ·npm run lint0 errors (6 warnings) · Codex clean — it normalized the moved block byte-for-byte against the oldmain.jsand confirmed the graph is acyclic · all 14 headless harnesses pass.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation