Skip to content

Note-entry preview cell + Logic-style ruler snap - #256

Merged
byrongamatos merged 4 commits into
mainfrom
feat/editor-note-entry-preview
Jul 14, 2026
Merged

Note-entry preview cell + Logic-style ruler snap#256
byrongamatos merged 4 commits into
mainfrom
feat/editor-note-entry-preview

Conversation

@ChrisBeWithYou

@ChrisBeWithYou ChrisBeWithYou commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What & why

Two small entry-usability wins that make the keyboard note-entry caret actually inform you, and make the playhead behave like a DAW's.

1. The entry caret previews the note you'll type

In String view with nothing selected, the dashed cell that marks the entry point used to be a fixed-width box that showed only where a note would land — no more than the playhead marker already tells you. Now it earns its note shape:

  • Length — sized to the current note value (the snap step), using the exact same width math a real note renders with (Math.max(MIN_NOTE_W, sustain * zoom)), so the box is the footprint the note will fill.
  • String — sits on the caret's string lane (↑/↓ move it).
  • Fret — ghosts the fret it will carry (the last one placed).

Typed notes are now placed at that same length (sustain = snap step) instead of sustain: 0, so consecutive 09 entries tile the grid instead of stacking as zero-length notes.

It's a persisted view prefView ▸ Snap ▸ Note-entry preview toggles it off (and back on) for mouse-first charters who find the cell distracting. Default on.

2. Clicking the ruler snaps the playhead to the grid (Logic-style)

A scrub click on the timeline ruler now lands the playhead on the nearest beat/subdivision when snap is on, so the entry caret sits on a real note position — instead of seeking to the raw pixel time. Hold Alt for a free, un-snapped scrub. Respects the existing snap toggle/mode; no change when snap is off.

Implementation

  • src/draw.js_caretCellWidthPure(stepSec, zoom, minW) (exported, pure; mirrors note render width, floors to the visible minimum, NaN-safe) + a richer caret block (faint fill, fret ghost, gated on host.editorEntryPreviewEnabled()).
  • src/input.js — place-at-caret uses sustain = snap step and remembers the fret; _editorEntryPreviewEnabled / editorToggleEntryPreview (localStorage editorEntryPreview, default on).
  • src/ruler.jsscrubTo snaps via snapTime; scrub drag carries bypassSnap = e.altKey.
  • src/host.js, src/main.js — wire editorEntryPreviewEnabled + window.editorToggleEntryPreview.
  • src/menu-bar.js — the View ▸ Snap toggle row.

Tests

  • tests/entry_preview.test.mjs (new): the width helper (note-value sizing, minimum floor, garbage/NaN degradation, monotonic-with-step) + the persisted toggle (default on, flip persists to localStorage, explicit-force idempotence).
  • Full JS suite green (npm test), lint clean (npx eslint@9.39.4 src tests — 0 errors), no routes.py change.
  • Live-verified against the :8000 testbed (AC/DC Back In Black, headless Chromium): no page errors on load; toggle wired + persists; caret redraw clean; plain ruler click snaps to grid (cursor === snapTime(cursor)), Alt-click is free.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a note-entry preview that ghosts the destination note’s shape/footprint, length, and fret while entering notes.
    • Added a Tempo/Grid ▸ Snap ▸ Note-entry preview toggle, with the setting saved between sessions.
    • Ruler clicks and scrubbing now snap the playhead to the nearest beat/subdivision when snapping is enabled.
    • Hold Alt while scrubbing to temporarily bypass snapping (applies live during the drag).

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 945dd44a-7177-4b8d-aeb7-adb9de2db971

📥 Commits

Reviewing files that changed from the base of the PR and between 6df31db and 91b6fa2.

📒 Files selected for processing (10)
  • .gitignore
  • CHANGELOG.md
  • src/draw.js
  • src/host.js
  • src/input.js
  • src/main.js
  • src/menu-bar.js
  • src/ruler.js
  • src/state.js
  • tests/entry_preview.test.mjs

📝 Walkthrough

Walkthrough

Adds a persisted note-entry caret preview with snap-sized ghost notes and fret digits, wires it through host, menu, and window APIs, updates keyboard placement timing, and makes ruler scrubbing snap-aware with live Alt bypass.

Changes

Editor entry preview

Layer / File(s) Summary
Entry preview behavior
src/state.js, src/input.js, src/draw.js
Keyboard entry stores the caret fret and snap-step timing, while String view renders the optional snap-sized ghost preview.
Preference wiring and validation
src/input.js, src/host.js, src/main.js, src/menu-bar.js, tests/entry_preview.test.mjs, CHANGELOG.md
The preview preference is persisted, exposed through host and window APIs, added to the Tempo/Grid menu, documented, and tested.

Snap-aware ruler scrubbing

Layer / File(s) Summary
Ruler scrub flow
src/ruler.js
Ruler dragging snaps the playhead unless Alt is active, with bypass state updated during movement.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: byrongamatos

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main user-facing changes: note-entry preview and snapped ruler behavior.
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/editor-note-entry-preview

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

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

Inline comments:
In `@CHANGELOG.md`:
- Around line 12-20: Update the changelog entry to reference the correct
`Tempo/Grid ▸ Snap` menu path for the `editorToggleEntryPreview` preference,
replacing the incorrect `View ▸ Snap` reference.

In `@src/ruler.js`:
- Line 507: Update the scrub drag handling around S.drag and scrubTo so the
current e.altKey state is evaluated on every move rather than only when the drag
starts. Pass or refresh the modifier value during each scrub operation while
preserving the existing resume and bypass-snap behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c74d2319-9e51-4255-ad49-3d781144f8b6

📥 Commits

Reviewing files that changed from the base of the PR and between a866705 and 60bda0f.

📒 Files selected for processing (8)
  • CHANGELOG.md
  • src/draw.js
  • src/host.js
  • src/input.js
  • src/main.js
  • src/menu-bar.js
  • src/ruler.js
  • tests/entry_preview.test.mjs

Comment thread CHANGELOG.md
Comment thread src/ruler.js
@byrongamatos
byrongamatos force-pushed the feat/editor-note-entry-preview branch from 60bda0f to e63e659 Compare July 14, 2026 17:43

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

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

Inline comments:
In `@node_modules`:
- Line 1: Remove the committed node_modules symbolic-link entry from the
repository, including its absolute local target, and leave dependency
installation to the project’s existing package-manager workflow.

In `@src/input.js`:
- Around line 114-127: Update the note-entry flow around _editorSeekToTime to
advance from the snapped note time rather than raw S.cursorTime, preventing
drift after free scrubbing. Reuse the positive value returned by
_editorSnapStepSeconds() directly and remove the redundant step > 0 fallback
while preserving sequential note placement.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 76b0bca6-3ea1-4967-bd63-72dfba9342de

📥 Commits

Reviewing files that changed from the base of the PR and between 60bda0f and e63e659.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • node_modules
  • src/draw.js
  • src/host.js
  • src/input.js
  • src/main.js
  • src/menu-bar.js
  • src/ruler.js
  • src/state.js
  • tests/entry_preview.test.mjs
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/menu-bar.js
  • CHANGELOG.md
  • src/draw.js
  • src/main.js
  • tests/entry_preview.test.mjs
  • src/ruler.js

Comment thread node_modules Outdated
Comment thread src/input.js Outdated
byrongamatos added a commit that referenced this pull request Jul 14, 2026
… untrack node_modules

Drains the four CodeRabbit findings on #256.

- input.js: advance the entry caret from the note's SNAPPED time, not the raw
  cursor. After a free (Alt) scrub — which this same PR introduces — the cursor
  sits off-grid, so stepping from it left the next note a fraction of a step off
  instead of flush against the last. Also drop the `step > 0` ternary:
  _editorSnapStepSeconds() is Math.max(0.001, ...) on every path, never <= 0.
- ruler.js: read e.altKey on each scrub move instead of freezing it at mouse-down,
  matching how the loopedge/barsel drags already re-read e.shiftKey per move.
- .gitignore + node_modules: the tracked absolute symlink is the symptom; the
  cause is that `node_modules/` (trailing slash) only matches directories, so the
  worktree symlink was never ignored and a `git add -A` swept it in. Drop the
  slash so the rule covers both, and untrack the blob.
- CHANGELOG: the entry-preview toggle lives under Tempo/Grid > Snap, not View.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@byrongamatos

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

ChrisBeWithYou and others added 4 commits July 14, 2026 20:59
The dashed keyboard-entry caret now previews the note a typed fret will
drop, not just the insertion point: it is sized to the current note value
(the snap step, so the box is the exact footprint the note will fill),
sits on the caret's string lane, and ghosts the fret it will carry. Typed
notes are placed at that same length so consecutive entries tile the grid
instead of stacking as zero-length notes. The preview is a persisted view
pref (View > Snap > Note-entry preview) for mouse-first charters who find
the cell distracting.

Clicking the ruler now snaps the playhead to the nearest beat/subdivision
when snap is on (Logic-style), so the caret lands on a real note position;
hold Alt for a free, un-snapped scrub.

- src/draw.js: _caretCellWidthPure (mirrors note render width) + richer
  caret block (fill, fret ghost, gated on host.editorEntryPreviewEnabled)
- src/input.js: place-at-caret uses sustain=snap step + remembers the fret;
  _editorEntryPreviewEnabled / editorToggleEntryPreview (localStorage)
- src/ruler.js: scrubTo snaps via snapTime; scrub drag carries bypassSnap=Alt
- src/host.js, src/main.js: wire editorEntryPreviewEnabled + window toggle
- src/menu-bar.js: View > Snap > Note-entry preview
- tests/entry_preview.test.mjs: width helper + persisted-toggle coverage

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EBQCHCNA81E9tHmSDHSe2Q
…l default-on test

Review follow-ups on the note-entry preview:

- src/state.js: caretFret was written ad-hoc onto S by _editorPlaceAtCaret but
  never declared beside caretString. Declared, so the caret's two fields live
  together and the default (open string, fret 0) is discoverable.
- src/draw.js: the fret ghost centred on Math.min(cw, MIN_NOTE_W), but cw is
  Math.max(MIN_NOTE_W, ...) by construction — the min could never bite. Dropped
  to MIN_NOTE_W with the intent (the digit stays put as the cell grows) in the
  comment.
- src/input.js: place-at-caret computed the snap step, then recomputed it for the
  cursor advance. One step, used for both, so "the note is as long as the caret
  advances" is visible in the code, not a coincidence of two calls.
- tests/entry_preview.test.mjs: "defaults ON when nothing is stored" forced the
  flag ON and then asserted it was ON — a tautology that never touched the
  localStorage default (the getter's cache is seeded by import). It now probes a
  fresh module instance per case, covering both the empty-store default and the
  stored-'0' read.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… untrack node_modules

Drains the four CodeRabbit findings on #256.

- input.js: advance the entry caret from the note's SNAPPED time, not the raw
  cursor. After a free (Alt) scrub — which this same PR introduces — the cursor
  sits off-grid, so stepping from it left the next note a fraction of a step off
  instead of flush against the last. Also drop the `step > 0` ternary:
  _editorSnapStepSeconds() is Math.max(0.001, ...) on every path, never <= 0.
- ruler.js: read e.altKey on each scrub move instead of freezing it at mouse-down,
  matching how the loopedge/barsel drags already re-read e.shiftKey per move.
- .gitignore + node_modules: the tracked absolute symlink is the symptom; the
  cause is that `node_modules/` (trailing slash) only matches directories, so the
  worktree symlink was never ignored and a `git add -A` swept it in. Drop the
  slash so the rule covers both, and untrack the blob.
- CHANGELOG: the entry-preview toggle lives under Tempo/Grid > Snap, not View.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Not a CodeRabbit finding — fallout from this PR's own two features meeting.
The caret cell drew at the RAW cursor while _editorPlaceAtCaret places at
snapTime(cursor). With snap on and the cursor off-grid — after the free (Alt)
scrub this same PR adds, or mid-playback — the dashed box promised a position
the typed note would not take. The changelog sells this cell as showing "which
note lands and how long, not just where"; it has to be right about where.

host.snapTime is already wired (main.js), so the cell just snaps like the
placement does.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@byrongamatos
byrongamatos force-pushed the feat/editor-note-entry-preview branch from 000379c to 91b6fa2 Compare July 14, 2026 18:59
@byrongamatos
byrongamatos merged commit d12822e into main Jul 14, 2026
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