From 8adf0a8b0abd1c8b140078294e7bcdb0fabb28d9 Mon Sep 17 00:00:00 2001 From: Ivan Schneider Date: Sat, 5 Dec 2026 14:15:30 +0000 Subject: [PATCH] Draw a theme's extract from its upbeat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A note's link from the first full bar of a score that opens on a pickup now draws the pickup too: "the theme, bars 1–4" of the Nocturne Op. 9 No. 2 starts on its B-flat, the Waltz Op. 69 No. 2 on its F-sharp. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 5 ++++- public/js/about.js | 3 ++- public/js/scoreExcerpt.js | 6 +++++- test/about_test.rb | 13 +++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 0bcea96f..2d49cd80 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -233,7 +233,10 @@ A note is read as fact by a player, so it is written like one: mainstream teaching, not a personal reading. - **Check every bar against the file**, not against a recording or another edition: links use the numbers the file gives its bars (a pickup is often - 0), and what the text says happens there must be what that file has. + 0), and what the text says happens there must be what that file has. A + link from the first full bar is drawn from the pickup before it, so a + theme is heard from its upbeat without naming bar 0 (`drawExcerpt` in + `public/js/scoreExcerpt.js`). `test/js/about.test.js` fails on a bar the score does not have or gives the same number to twice (the Gnossienne numbers all its bars 0), on a link one language has and the other lacks, and on a tab past its length cap. The diff --git a/public/js/about.js b/public/js/about.js index 554593ae..b0ebcb12 100644 --- a/public/js/about.js +++ b/public/js/about.js @@ -13,7 +13,8 @@ // carries on over indented lines), **bold**, *italic*, and bar links. // A bar link — [m. 21–27](#m21-27) — names bars as the score's file numbers // them, which is what the sheet prints. Tapped, it unfolds those bars drawn -// under its sentence (scoreExcerpt.js). +// under its sentence (scoreExcerpt.js), from the pickup when they start at the +// first full bar. // // test/js/about.test.js holds every note to the files naming it: both // languages, the same bars linked in each, only bars the score has. diff --git a/public/js/scoreExcerpt.js b/public/js/scoreExcerpt.js index c42dbe86..fb295166 100644 --- a/public/js/scoreExcerpt.js +++ b/public/js/scoreExcerpt.js @@ -40,10 +40,14 @@ export async function toggleBarExcerpt(link, xml) { // than through OSMD's drawFromMeasureNumber, which guesses at a pickup bar // from durations; a bar split in two (barCounter in fingeringKeys.js) carries // its number on both halves, and both are drawn. +// +// A passage from the first full bar starts on the pickup before it, which +// is where its tune starts: "the theme, bars 1–4" is heard from its upbeat. async function drawExcerpt(container, xml, { from, to }) { const osmd = await loadSheet(container, xml, { drawCredits: false }) const bars = osmd.Sheet.SourceMeasures - osmd.rules.MinMeasureToDrawIndex = bars.findIndex((bar) => bar.MeasureNumberXML === from) + const first = bars.findIndex((bar) => bar.MeasureNumberXML === from) + osmd.rules.MinMeasureToDrawIndex = first === 1 && bars[0].ImplicitMeasure ? 0 : first osmd.rules.MaxMeasureToDrawIndex = bars.findLastIndex((bar) => bar.MeasureNumberXML === to) osmd.zoom = EXCERPT_ZOOM placeChordFingerings(bars) diff --git a/test/about_test.rb b/test/about_test.rb index c8f23990..b4377898 100644 --- a/test/about_test.rb +++ b/test/about_test.rb @@ -67,6 +67,19 @@ def test_a_link_from_the_pickup_bar_draws_it end end + # A theme starts on its upbeat: a link from the first full bar draws the + # pickup before it too, the Nocturne's B♭ ahead of bar 1. + def test_a_link_from_the_first_full_bar_draws_its_pickup + visit '/score.html?url=scores/Chopin_-_Nocturne_Op_9_No_2_E_Flat_Major.mxl' + wait_for_score_render + + find('button.pt-about-button').click + within('#aboutModal') do + click_button 'm. 1–4' + assert_selector '.pt-bar-excerpt svg .vf-measure', count: 10 + end + end + def test_a_score_without_a_note_has_no_about_button visit '/score.html?url=scores/Swan_Lake.mxl' wait_for_score_render