Extract shared natural-HOPO helpers into natural-hopo.ts - #105
Merged
Geomitron merged 2 commits intoApr 21, 2026
Conversation
This was referenced Apr 20, 2026
elicwhite
force-pushed
the
shared-natural-hopo-helpers
branch
2 times, most recently
from
April 20, 2026 05:10
2626335 to
f850ad9
Compare
2 tasks
…art (state-derived) The three derived boolean flags on ParsedChart (hasLyrics, hasVocals, hasForcedNotes) were parse-time snapshots that went stale whenever consumers mutated chart data post-parse. Remove them from ParsedChart entirely; scanChart derives all three at scan time from the current chart state, piggybacking on its existing single note-walk (no extra iterations). - hasLyrics / hasVocals: computed from parsedChart.vocalTracks.parts — constant-time existence check. - hasForcedNotes: inverts resolveFretModifiers. A note is 'forced' iff its resolved flag disagrees with the natural HOPO state the parser would pick without any force events, or it carries the tap flag (tap can only come from explicit forceTap). Inlined helpers for isNaturalHopo, isFretChord, isSameFretNote, isInFretNote, computeHopoThresholdTicks in chart-scanner.ts (duplicated from notes-parser.ts; a follow-up can extract to a shared helper). Semantic change to note: under the new definition, redundantly-applied force events (e.g. explicit forceHopo on a naturally-HOPO note) no longer contribute to hasForcedNotes — the chart plays identically with or without them, so state-derived detection correctly says false. This eliminates the need for any 'hasForcedNotes backstop' in writers since the flag round-trips naturally: the writer emits force events exactly when a flag disagrees with natural state, and the scanner detects those same disagreements on re-parse. ScannedChart.notesData's shape is unchanged (hasLyrics / hasVocals / hasForcedNotes still present); only the population source changes. Consumers that previously read parsedChart.hasLyrics / parsedChart.hasVocals / parsedChart.hasForcedNotes must switch to scanChart output.
The chart scanner, chart writer, and MIDI writer each had their own
near-identical copies of isFretChord / isSameFretNote / isInFretNote /
isNaturalHopo over NoteEvent[], and the parser had the same three
helpers again over TrackEvent[]. This consolidates all five callsites
into src/chart/natural-hopo.ts.
The helpers are generic (<T, E extends { type: T }> + an isFret
predicate); thin wrappers are exported for each concrete group type:
- NoteEvent-based (scanner + writers): isFretChord / isSameFretNote /
isInFretNote, plus the combined isNaturalHopo.
- TrackEvent-based (parser's resolveFretModifiers):
isFretChordRawEvents / isSameFretNoteRawEvents /
isInFretNoteRawEvents. The parser still builds its natural-HOPO
check inline — it compares effectiveNotes to lastNotes while
passing the raw pre-coalesced events to isSameFretNoteRawEvents,
a subtlety no NoteEvent callsite has.
The isFretNoteType / isFretEventType predicates are also exported,
so the parser's two standalone isFretNote(...) callsites (filtering
event lists outside the group helpers) share the same definition too.
The parser's four local helpers (isFretNote, isSameFretNote, isFretChord,
isInFretNote) are deleted.
Net: ~70 LOC of duplication removed across scanner, parser, and (in
the writer branches further up the stack) the two writers. One file
owns every natural-HOPO rule.
This commit updates the scanner + parser; the writers move to the
shared helpers in the two branches further up the stack that own them.
elicwhite
force-pushed
the
shared-natural-hopo-helpers
branch
from
April 21, 2026 04:29
f850ad9 to
ec22459
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The chart scanner, chart writer, and MIDI writer each had their own near-identical copies of
isFretChord/isSameFretNote/isInFretNote/isNaturalHopooverNoteEvent[], and the parser had the same three helpers again overTrackEvent[]. This PR consolidates all five callsites intosrc/chart/natural-hopo.ts.The helpers are generic (
<T, E extends { type: T }>+ anisFret: (t: T) => booleanpredicate); thin wrappers are exported for each concrete group type:isFretChord,isSameFretNote,isInFretNote, plus the combinedisNaturalHopo.resolveFretModifiers):isFretChordRawEvents,isSameFretNoteRawEvents,isInFretNoteRawEvents. (The parser still builds its own natural-HOPO check inline because it compareseffectiveNotestolastNoteswhile passing the raw pre-coalescedeventstoisSameFretNoteRawEvents— a subtlety no NoteEvent callsite has.)The
isFretNoteType/isFretEventTypepredicates are also exported, so the parser's two otherisFretNote(...)callsites (filtering event lists) share the same definition too. The parser's four local helpers (isFretNote,isSameFretNote,isFretChord,isInFretNote) are deleted.Net: ~70 LOC of duplication removed across the scanner, parser, and (in the later writer PRs) two writers. One file owns every natural-HOPO rule; changes to the rules happen in one place.
Stack (bottom → top)
Test plan
yarn testgreen at this branch (290 tests) and at the tip of the stack (442 tests).