From c8a6f2b48f93db363b66b3cdcc5c9517614da05a Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Sep 2026 03:38:36 +0000 Subject: [PATCH 1/3] fix: hold chord shapes on the fretboard longer so they're readable Struck chords used to fade out ~300ms after onset, and individual member notes with shorter sustains would drop out before the rest of the shape, leaving an incomplete-looking diagram. Chords are now held together for a fixed 0.9s minimum, closing #2 and #3. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_016cfE1wg6F2VT6eqJEp4LBz --- plugin.json | 2 +- screen.js | 14 +++++++++----- tests/screen.test.js | 21 +++++++++++++++------ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/plugin.json b/plugin.json index a39cd54..a6674f2 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "id": "fretboard", "name": "Fretboard View", - "version": "1.1.0", + "version": "1.1.1", "private": false, "script": "screen.js", "category": "practice", diff --git a/screen.js b/screen.js index 20e6eaa..346b433 100644 --- a/screen.js +++ b/screen.js @@ -262,16 +262,20 @@ function _fbGetActiveNotes(t, notes, chords) { } } - // Chord notes + // Chord notes. CHORD_HOLD_S keeps a struck chord's shape on the + // fretboard well past its literal onset (issues #2/#3: the shape used + // to vanish after ~300ms, too fast for a player to read and form). + const CHORD_HOLD_S = 0.9; if (chords) { for (const c of chords) { - if (c.t <= t + window && c.t >= t - 0.3) { + if (c.t <= t + window && c.t >= t - CHORD_HOLD_S) { for (const cn of (c.notes || [])) { - const noteEnd = c.t + (cn.sus || 0); + const noteEnd = c.t + Math.max(cn.sus || 0, CHORD_HOLD_S); if (noteEnd >= t - window) { let alpha = 1; - if (cn.sus > 0 && t > c.t) { - alpha = Math.max(0.3, 1 - (t - c.t) / cn.sus * 0.7); + const holdEnd = c.t + Math.max(cn.sus || 0, CHORD_HOLD_S); + if (t > c.t) { + alpha = Math.max(0.45, 1 - (t - c.t) / (holdEnd - c.t) * 0.55); } active.push({ s: cn.s, f: cn.f, alpha }); } diff --git a/tests/screen.test.js b/tests/screen.test.js index eee2008..10ec4d1 100644 --- a/tests/screen.test.js +++ b/tests/screen.test.js @@ -59,18 +59,27 @@ test('chord notes within window are all included', () => { ]); }); -test('a chord well before the current time is excluded (0.3s lookback)', () => { - const chords = [{ t: 0.5, notes: [{ s: 0, f: 0 }] }]; +test('a chord well before the current time is excluded (0.9s hold)', () => { + const chords = [{ t: 0.05, notes: [{ s: 0, f: 0 }] }]; assert.deepEqual(mod._fbGetActiveNotes(1.0, null, chords), []); }); +test('a chord shape is held on the fretboard well past its onset (issue #2/#3)', () => { + // Onset at t=0.5, no sustain on the member notes: previously this would + // have faded out by t=0.8 (300ms lookback); now it should still be lit + // most of the way to a full second later. + const chords = [{ t: 0.5, notes: [{ s: 0, f: 0, sus: 0 }] }]; + const active = mod._fbGetActiveNotes(1.3, null, chords); + assert.equal(active.length, 1); + assert.ok(active[0].alpha >= 0.45); +}); + test('individual chord-member sustain still governs member inclusion', () => { - // Chord onset within the 0.3s lookback gate; members have different sustains. + // Chord onset within the 0.9s hold gate; members have different sustains. const chords = [{ t: 0.85, notes: [{ s: 0, f: 0, sus: 0 }, { s: 1, f: 1, sus: 2.0 }] }]; const active = mod._fbGetActiveNotes(1.0, null, chords); - // Only the long-sustain member should still be ringing at t=1.0. - assert.equal(active.length, 1); - assert.equal(active[0].s, 1); + // Both members are still within the chord's hold/sustain window at t=1.0. + assert.equal(active.length, 2); }); test('handles missing notes/chords gracefully', () => { From 7e863ea872d781ecc8b6b01c261e7e048bd4d387 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 8 Sep 2026 04:08:36 +0000 Subject: [PATCH 2/3] fix: a chord member sustained past CHORD_HOLD_S was cut off early CodeRabbit review finding on #12: the outer chord-visibility gate used a flat `c.t >= t - CHORD_HOLD_S` check, so a chord onset more than 0.9s in the past was excluded entirely before the inner per-member loop ever got a chance to see that one of its members had a longer sus and should still be lit. E.g. a chord at t=0 with a sus:2 member was gone by t=1.5 despite the member still sustaining. Now computes the chord's actual end (max of CHORD_HOLD_S and every member's sustain) and gates on that instead, so a long-sustain member stays lit for its real duration while short members still get the 0.9s minimum hold. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_016cfE1wg6F2VT6eqJEp4LBz --- CHANGELOG.md | 1 + plugin.json | 2 +- screen.js | 16 ++++++++++++---- tests/screen.test.js | 13 ++++++++++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbc074a..79e04a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,3 +13,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - The player's own "Fretboard" toggle now creates its single instance through the same factory. Its behavior is unchanged. +- Struck chord shapes are now held on the fretboard for a 0.9s minimum (with a raised alpha floor), instead of fading out ~300ms after onset — the shape used to vanish too quickly to read or form. A member note sustained longer than 0.9s stays lit for its full sustain rather than being cut off at the flat hold time. (#2, #3) diff --git a/plugin.json b/plugin.json index a6674f2..539a3b9 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "id": "fretboard", "name": "Fretboard View", - "version": "1.1.1", + "version": "1.1.2", "private": false, "script": "screen.js", "category": "practice", diff --git a/screen.js b/screen.js index 346b433..669edbe 100644 --- a/screen.js +++ b/screen.js @@ -268,12 +268,20 @@ function _fbGetActiveNotes(t, notes, chords) { const CHORD_HOLD_S = 0.9; if (chords) { for (const c of chords) { - if (c.t <= t + window && c.t >= t - CHORD_HOLD_S) { + // Gate on the chord's longest member end, not a flat + // CHORD_HOLD_S — otherwise a member sustained past 0.9s (e.g. + // sus: 2) was dropped by this outer check before its own + // per-member noteEnd below ever got a chance to keep it lit. + let chordEnd = c.t + CHORD_HOLD_S; + for (const cn of (c.notes || [])) { + const end = c.t + (cn.sus || 0); + if (end > chordEnd) chordEnd = end; + } + if (c.t <= t + window && chordEnd >= t - window) { for (const cn of (c.notes || [])) { - const noteEnd = c.t + Math.max(cn.sus || 0, CHORD_HOLD_S); - if (noteEnd >= t - window) { + const holdEnd = c.t + Math.max(cn.sus || 0, CHORD_HOLD_S); + if (holdEnd >= t - window) { let alpha = 1; - const holdEnd = c.t + Math.max(cn.sus || 0, CHORD_HOLD_S); if (t > c.t) { alpha = Math.max(0.45, 1 - (t - c.t) / (holdEnd - c.t) * 0.55); } diff --git a/tests/screen.test.js b/tests/screen.test.js index 10ec4d1..92f5e0c 100644 --- a/tests/screen.test.js +++ b/tests/screen.test.js @@ -60,8 +60,9 @@ test('chord notes within window are all included', () => { }); test('a chord well before the current time is excluded (0.9s hold)', () => { + // 0.05 + 0.9s hold + the 80ms trailing grace window all elapsed by t=1.2. const chords = [{ t: 0.05, notes: [{ s: 0, f: 0 }] }]; - assert.deepEqual(mod._fbGetActiveNotes(1.0, null, chords), []); + assert.deepEqual(mod._fbGetActiveNotes(1.2, null, chords), []); }); test('a chord shape is held on the fretboard well past its onset (issue #2/#3)', () => { @@ -82,6 +83,16 @@ test('individual chord-member sustain still governs member inclusion', () => { assert.equal(active.length, 2); }); +test('a chord member sustained past CHORD_HOLD_S stays lit for its full sustain, not just 0.9s (CodeRabbit finding)', () => { + // Onset at t=0, one short member (sus:0) and one long-sustain member + // (sus:2.0). At t=1.5 — past the flat 0.9s hold — the long member must + // still be active; only the short one has genuinely ended. + const chords = [{ t: 0, notes: [{ s: 0, f: 0, sus: 0 }, { s: 1, f: 1, sus: 2.0 }] }]; + const active = mod._fbGetActiveNotes(1.5, null, chords); + assert.equal(active.length, 1); + assert.equal(active[0].s, 1); +}); + test('handles missing notes/chords gracefully', () => { assert.deepEqual(mod._fbGetActiveNotes(1.0, null, null), []); assert.deepEqual(mod._fbGetActiveNotes(1.0, undefined, undefined), []); From 0acfd3b4142ae50ca2263360705cca92b33cc4bc Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 10 Sep 2026 13:15:56 +0000 Subject: [PATCH 3/3] fix: derive string grid from getStringCount() instead of hardcoded 6 The overlay hardcoded a 6-string grid (FB_STRINGS = 6) and mapped chart note string indices straight onto it. On a 4-string bass chart this put highlighted notes two rows off from where they're actually played (and the e/B/G/D/A/E labels don't apply to a bass); 7/8-string GP imports had the inverse problem, with note string indices falling outside the fixed 6-row array entirely. draw() now derives stringCount from highway.getStringCount() each frame (falling back to 6 for a host too old to expose it) and uses it for all grid geometry, string colors (extended to 8 entries), and note-position mapping. String names are shown for the tunings this plugin can name confidently (6-string guitar, 4-string bass); other counts fall back to numeric labels rather than guessing a wrong note name. Closes #19 Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_016cfE1wg6F2VT6eqJEp4LBz --- CHANGELOG.md | 4 +++ plugin.json | 2 +- screen.js | 73 ++++++++++++++++++++++++++++++++------------ tests/screen.test.js | 62 +++++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79e04a9..1d4c3dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,3 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - The player's own "Fretboard" toggle now creates its single instance through the same factory. Its behavior is unchanged. - Struck chord shapes are now held on the fretboard for a 0.9s minimum (with a raised alpha floor), instead of fading out ~300ms after onset — the shape used to vanish too quickly to read or form. A member note sustained longer than 0.9s stays lit for its full sustain rather than being cut off at the flat hold time. (#2, #3) + +### Fixed + +- The overlay hardcoded a 6-string grid (`FB_STRINGS = 6`) and mapped chart note string indices straight onto it — on a 4-string bass chart, highlighted notes landed two rows off from where they were actually played (and the string labels didn't apply at all); 7/8-string GP imports had the inverse problem, with note indices falling outside the 6-row grid entirely. The overlay now reads the chart's real string count via `highway.getStringCount()` and sizes/labels the grid accordingly, falling back to 6 for a host too old to expose it. String names are shown for standard 6-string guitar and 4-string bass; other counts (5-string bass, 7/8-string guitar, alternate tunings) show numeric labels rather than a guessed-wrong note name. (#19) diff --git a/plugin.json b/plugin.json index 539a3b9..8227319 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "id": "fretboard", "name": "Fretboard View", - "version": "1.1.2", + "version": "1.1.3", "private": false, "script": "screen.js", "category": "practice", diff --git a/screen.js b/screen.js index 669edbe..1884a32 100644 --- a/screen.js +++ b/screen.js @@ -1,16 +1,44 @@ // Fretboard View plugin // Draws a horizontal guitar fretboard that lights up with active notes. -const FB_STRINGS = 6; +// Default when the host highway doesn't expose getStringCount() (older +// host) — see _fbStringCount() below, which is what draw() actually uses. +const FB_STRINGS_DEFAULT = 6; const FB_FRETS = 24; +// Sized for up to 8 strings (extended-range GP imports) — issue #60/#19: +// this used to hardcode 6 and silently misalign bass (4-string) and +// 7/8-string charts, whose note string indices go out of range of a +// 6-entry array. const FB_STRING_COLORS = [ '#cc0000', '#cca800', '#0066cc', '#cc6600', '#00cc66', '#9900cc', + '#cc0099', '#00cccc', ]; const FB_STRING_BRIGHT = [ '#ff4444', '#ffe050', '#4499ff', '#ff9944', '#44ff99', '#cc44ff', + '#ff44cc', '#44cccc', ]; +// String-name labels, indexed by display row (row 0 = top = highest-pitch +// string), for tunings we can confidently name. Only standard 6-string +// guitar and 4-string bass are covered — everything else (5-string bass, +// 7/8-string guitar, alternate tunings) falls back to a numeric label in +// _fbStringNames() rather than guess a wrong note name. +const FB_STRING_NAMES_BY_COUNT = { + 4: ['G', 'D', 'A', 'E'], + 6: ['e', 'B', 'G', 'D', 'A', 'E'], +}; +function _fbStringNames(n) { + return FB_STRING_NAMES_BY_COUNT[n] || Array.from({ length: n }, (_, i) => String(n - i)); +} +// The chart's real string count for this instance's highway — 4 for bass, +// 6 for guitar, 7/8 for extended-range GP imports (see host CLAUDE.md's +// getStringCount() docs). Cheap property read, safe to call every frame; +// falls back to FB_STRINGS_DEFAULT for a host too old to expose it. +function _fbStringCount(hw) { + const n = typeof hw.getStringCount === 'function' ? hw.getStringCount() : null; + return Number.isInteger(n) && n > 0 ? n : FB_STRINGS_DEFAULT; +} const FB_DOT_FRETS = [3, 5, 7, 9, 12, 15, 17, 19, 21, 24]; const FB_DOUBLE_DOT = [12, 24]; @@ -89,12 +117,21 @@ function _fbCreateInstance({ container, getHighway, bottomOffset, dismissible, o ctx.fillStyle = 'rgba(8, 8, 16, 0.92)'; ctx.fillRect(0, 0, W, H); + // Resolve the highway (and its real string count) before laying out + // geometry — issue #60/#19: string count varies per chart (4 for + // bass, 6 for guitar, 7/8 for extended-range GP imports), so it + // can't be a fixed constant. Falls back to the 6-string default + // when no highway is bound yet, so an empty board still renders. + const hw = getHighway(); + const stringCount = hw ? _fbStringCount(hw) : FB_STRINGS_DEFAULT; + const stringNames = _fbStringNames(stringCount); + const padL = 35; // space for string labels const padR = 10; const padT = 10; const padB = 20; // space for fret numbers const fretW = (W - padL - padR) / FB_FRETS; - const stringH = (H - padT - padB) / (FB_STRINGS - 1); + const stringH = (H - padT - padB) / (stringCount - 1); // Draw fret lines ctx.strokeStyle = '#2a2a40'; @@ -103,7 +140,7 @@ function _fbCreateInstance({ container, getHighway, bottomOffset, dismissible, o const x = padL + f * fretW; ctx.beginPath(); ctx.moveTo(x, padT); - ctx.lineTo(x, padT + (FB_STRINGS - 1) * stringH); + ctx.lineTo(x, padT + (stringCount - 1) * stringH); ctx.stroke(); // Nut (thicker at fret 0) @@ -112,7 +149,7 @@ function _fbCreateInstance({ container, getHighway, bottomOffset, dismissible, o ctx.lineWidth = 3; ctx.beginPath(); ctx.moveTo(x, padT); - ctx.lineTo(x, padT + (FB_STRINGS - 1) * stringH); + ctx.lineTo(x, padT + (stringCount - 1) * stringH); ctx.stroke(); ctx.strokeStyle = '#2a2a40'; ctx.lineWidth = 1; @@ -137,12 +174,12 @@ function _fbCreateInstance({ container, getHighway, bottomOffset, dismissible, o } // Draw strings - for (let s = 0; s < FB_STRINGS; s++) { + for (let s = 0; s < stringCount; s++) { const y = padT + s * stringH; - // String 0 = high e (top), string 5 = low E (bottom) - // But in the chart, string 0 = low E. So reverse: draw index (FB_STRINGS-1-s) - const rsString = FB_STRINGS - 1 - s; - ctx.strokeStyle = FB_STRING_COLORS[rsString]; + // Row 0 = highest-pitch string (top), last row = lowest (bottom). + // Chart string 0 = lowest pitch, so reverse: draw index (stringCount-1-s) + const rsString = stringCount - 1 - s; + ctx.strokeStyle = FB_STRING_COLORS[rsString % FB_STRING_COLORS.length]; ctx.lineWidth = 1 + s * 0.3; // thicker for lower strings ctx.globalAlpha = 0.4; ctx.beginPath(); @@ -159,24 +196,22 @@ function _fbCreateInstance({ container, getHighway, bottomOffset, dismissible, o ctx.textBaseline = 'top'; for (let f = 1; f <= FB_FRETS; f++) { const x = padL + (f - 0.5) * fretW; - ctx.fillText(f, x, padT + (FB_STRINGS - 1) * stringH + 5); + ctx.fillText(f, x, padT + (stringCount - 1) * stringH + 5); } // String names ctx.textAlign = 'right'; ctx.textBaseline = 'middle'; ctx.font = 'bold 10px sans-serif'; - const stringNames = ['e', 'B', 'G', 'D', 'A', 'E']; - for (let s = 0; s < FB_STRINGS; s++) { + for (let s = 0; s < stringCount; s++) { const y = padT + s * stringH; - const rsString = FB_STRINGS - 1 - s; - ctx.fillStyle = FB_STRING_COLORS[rsString]; + const rsString = stringCount - 1 - s; + ctx.fillStyle = FB_STRING_COLORS[rsString % FB_STRING_COLORS.length]; ctx.fillText(stringNames[s], padL - 8, y); } // Get active notes from THIS instance's highway, not a global one — // splitscreen panels each run their own independent highway. - const hw = getHighway(); if (!hw) return; const t = hw.getTime(); const notes = hw.getNotes(); @@ -185,9 +220,9 @@ function _fbCreateInstance({ container, getHighway, bottomOffset, dismissible, o // Draw active notes for (const n of activeNotes) { - const rsString = n.s; // the chart string (0=low E) + const rsString = n.s; // the chart string (0=lowest pitch) const fret = n.f; - const drawString = FB_STRINGS - 1 - rsString; // flip for display + const drawString = stringCount - 1 - rsString; // flip for display const y = padT + drawString * stringH; let x; @@ -197,7 +232,7 @@ function _fbCreateInstance({ container, getHighway, bottomOffset, dismissible, o x = padL + (fret - 0.5) * fretW; } - const color = FB_STRING_BRIGHT[rsString] || '#fff'; + const color = FB_STRING_BRIGHT[rsString % FB_STRING_BRIGHT.length] || '#fff'; const alpha = n.alpha || 1; // Glow @@ -298,7 +333,7 @@ function _fbGetActiveNotes(t, notes, chords) { // Node-only export hook for tests; browsers fall through to the hooks IIFE. if (typeof module !== 'undefined' && module.exports) { - module.exports = { _fbGetActiveNotes, _fbCreateInstance }; + module.exports = { _fbGetActiveNotes, _fbCreateInstance, _fbStringCount, _fbStringNames }; } else { // ── Player toggle (single global instance, anchored to #player) ──────── diff --git a/tests/screen.test.js b/tests/screen.test.js index 92f5e0c..e015db1 100644 --- a/tests/screen.test.js +++ b/tests/screen.test.js @@ -249,3 +249,65 @@ test('_fbCreateInstance sizes the canvas to 15% of a tall container', () => { inst.destroy(); }); }); + +// Coverage for issue #60/#19: the overlay used to hardcode a 6-string grid +// (FB_STRINGS = 6) and map chart string indices straight onto it, putting +// bass (4-string) and extended-range (7/8-string) charts' highlighted notes +// on the wrong row entirely, since their string indices don't fit a 6-row +// array. _fbStringCount()/_fbStringNames() are the fix's pure building +// blocks — draw() now derives the grid from these instead of a constant. + +test('_fbStringCount reads getStringCount() from the highway', () => { + assert.equal(mod._fbStringCount({ getStringCount: () => 4 }), 4); + assert.equal(mod._fbStringCount({ getStringCount: () => 7 }), 7); + assert.equal(mod._fbStringCount({ getStringCount: () => 8 }), 8); +}); + +test('_fbStringCount falls back to 6 when the highway has no getStringCount()', () => { + assert.equal(mod._fbStringCount({}), 6); +}); + +test('_fbStringCount falls back to 6 for a non-positive-integer result (older/broken host)', () => { + assert.equal(mod._fbStringCount({ getStringCount: () => 0 }), 6); + assert.equal(mod._fbStringCount({ getStringCount: () => -1 }), 6); + assert.equal(mod._fbStringCount({ getStringCount: () => NaN }), 6); + assert.equal(mod._fbStringCount({ getStringCount: () => 4.5 }), 6); + assert.equal(mod._fbStringCount({ getStringCount: () => null }), 6); +}); + +test('_fbStringNames returns real note names for 6-string guitar and 4-string bass', () => { + assert.deepEqual(mod._fbStringNames(6), ['e', 'B', 'G', 'D', 'A', 'E']); + assert.deepEqual(mod._fbStringNames(4), ['G', 'D', 'A', 'E']); +}); + +test('_fbStringNames falls back to numeric labels for uncommon string counts, high-to-low by display row', () => { + // Row 0 (top, display) must be the highest-numbered chart string, same + // convention real-named tunings use — never guess a wrong note name for + // a tuning this plugin doesn't have a confident name table for. + assert.deepEqual(mod._fbStringNames(7), ['7', '6', '5', '4', '3', '2', '1']); + assert.deepEqual(mod._fbStringNames(5), ['5', '4', '3', '2', '1']); + assert.equal(mod._fbStringNames(7).length, 7); +}); + +test('draw() reads the highway\'s real string count instead of assuming 6', () => { + withDom((step) => { + let calls = 0; + const hw = { + getStringCount: () => { calls++; return 4; }, // 4-string bass + getTime: () => 0, getNotes: () => [], getChords: () => [], + }; + const inst = mod._fbCreateInstance({ container: fakeContainer(640, 300), getHighway: () => hw }); + step(); // run the first queued draw() frame + assert.ok(calls >= 1, 'draw() must consult getStringCount() on the bound highway'); + inst.destroy(); + }); +}); + +test('draw() does not throw when the highway has no getStringCount (older host)', () => { + withDom((step) => { + const hw = { getTime: () => 0, getNotes: () => [], getChords: () => [] }; + const inst = mod._fbCreateInstance({ container: fakeContainer(640, 300), getHighway: () => hw }); + assert.doesNotThrow(() => step()); + inst.destroy(); + }); +});