Skip to content

Extract shared natural-HOPO helpers into natural-hopo.ts - #73

Closed
elicwhite wants to merge 1 commit into
derived-flags-to-scannedfrom
shared-natural-hopo-helpers
Closed

Extract shared natural-HOPO helpers into natural-hopo.ts#73
elicwhite wants to merge 1 commit into
derived-flags-to-scannedfrom
shared-natural-hopo-helpers

Conversation

@elicwhite

Copy link
Copy Markdown
Owner

The chart scanner, chart writer, and MIDI writer each had their own near-
identical copies of isFretChord / isSameFretNote / isInFretNote /
computeHopoThresholdTicks / isNaturalHopo, all operating on NoteEvent[].
Consolidate them into src/chart/natural-hopo.ts. computeHopoThresholdTicks
takes the format ('chart' | 'mid') so both backends share one function.

This commit only updates the scanner; the writers are updated in the two
branches further up the stack that own them. The parser's TrackEvent-based
helpers stay put — they operate on a different type shape (EventType, not
NoteType) and generalizing over both would cost more readability than it
would buy.

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
elicwhite force-pushed the shared-natural-hopo-helpers branch from f850ad9 to ec22459 Compare April 21, 2026 04:29
@elicwhite

Copy link
Copy Markdown
Owner Author

Closing — content merged upstream via Geomitron#105 (commit ec22459 is now on master).

@elicwhite elicwhite closed this Apr 21, 2026
@elicwhite
elicwhite deleted the shared-natural-hopo-helpers branch April 21, 2026 04:55
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.

1 participant