Repository navigation
Fix hand assignment for grand-staff pianos imported from MusicXML, Guitar Pro and Capella - #42
Merged
Merged
Conversation
Squarebow
pushed a commit
that referenced
this pull request
Nov 14, 2026
Owner
|
Thanks a lot, Rafael! Merged into dev with you as the author, so you're in the Contributors list. It'll ship in the next release, and the changelog credits you. |
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.
Fixes #41.
Problem
Importing a
.mxl/.musicxml(and, by the same mechanism, Guitar Pro/Capella) file with a piano or organ part gave noticeably wrong left/right hand assignment compared to loading a.midfile exported directly from the same notation software.Root cause
alphaTab (
@coderline/alphatab) keeps a whole grand staff on oneTrackwith one shared channel —playbackInfo(program, channel) lives once perTrack, not perStaff— and never writes a track-name meta event at all. A notation program's own MIDI export, by contrast, always splits a grand staff into two separate tracks sharing one channel.handAssignment.ts'sfindStavePairs()specifically looks for that two-tracks-one-channel (or matching RH/LH name) shape to trust a piano's two staves outright; alphaTab-converted files never had that shape, so they always fell through to the generic per-track dividing-line guess instead.A second, easy-to-miss piece: alphaTab also defaults to SMF Type 0 (single track, channels multiplexed together). Even after splitting the staves into two
Trackobjects sharing one channel, writing them out with the default format silently merges them back into one indistinguishable stream — there's nowhere in a Type 0 file to keep two same-channel tracks apart.Fix
In
src/utils/foreignFormatImport.ts:MidiFile's format toMidiFileFormat.MultiTrack(SMF Type 1), so the split tracks actually survive serialisation instead of being multiplexed back onto one channel.This applies uniformly to MusicXML, Guitar Pro and Capella, since the split runs against alphaTab's shared
Score/Track/Staffmodel after import, regardless of which importer produced it — verified with a Guitar-Pro-shaped multi-channel test case (two separate grand-staff pianos on their own channels) as well as the MusicXML grand-staff and 3-staff-organ cases.Testing
npm run typecheckandnpm test(65 files) pass, including a newsrc/utils/foreignFormatImportTest.ts(14 checks) covering: a grand-staff piano gets a confidence-1 staff pair with correct hands; a 3-staff organ keeps its three staves on one shared channel without crashing the fallback; single-staff keyboard and non-keyboard parts are left untouched; two separate duet pianos each get independently correct hands (never pooled together).assignHandsByTrack()/findStavePairs()ondev, not just the old engine.Built and tested against the current
dev(merged in locally before pushing), so it sits on top of the staff-based hand-assignment rework already ondev.