gp5: extract per-track clef (clefMode + bass-tuning inference)#57
Closed
kaizenman wants to merge 1 commit intoPerlence:masterfrom
Closed
gp5: extract per-track clef (clefMode + bass-tuning inference)#57kaizenman wants to merge 1 commit intoPerlence:masterfrom
kaizenman wants to merge 1 commit intoPerlence:masterfrom
Conversation
`GP5File.readTrackRSE` read three consecutive int32s as "???". The
first of those is the track's clef mode (``12`` forces bass clef),
documented in alphaTab's Gp3To5Importer.readTrack. Without extracting
it, every GP5 track was reported as treble clef regardless of tuning
or percussion status.
Writer was asymmetric too: `writeTrackRSE` hard-coded the clefMode
int32 to ``0``, so round-tripping a bass track corrupted its clef.
This change:
* adds ``TrackRSE.clefMode`` field
* adds ``MeasureClef.neutral`` for percussion tracks
* reads/writes clefMode in readTrackRSE/writeTrackRSE
* infers Measure.clef during readMeasure, matching alphaTab's rule:
percussion → neutral; else bass if clefMode==12 or lowest string
below MIDI B1; else treble
* adds round-trip regression tests covering all three cases
Closes #2
Owner
Owner
|
@kaizenman I went with a slightly different implementation, but thanks for the heads-up! |
Perlence
added a commit
that referenced
this pull request
Apr 26, 2026
I made the new attributes not participate in __eq__ because doing so breaks the comparison between otherwise equal GP4 and GP5 tabs. Closes #57. Co-authored-by: kaizenman <15638776+kaizenman@users.noreply.github.com>
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.

Bug
GP5File.readTrackRSEreads three consecutive int32s from the track's RSE block as???placeholders. The first of those is the track's clef mode (12forces bass clef), documented in alphaTab'sGp3To5Importer.readTrack.Without extracting it, every GP5 track is reported as treble clef regardless of:
The writer is asymmetric too:
writeTrackRSEhard-codes the clefMode int32 to0, so round-tripping a bass-clef track silently corrupts its clef.Reference: alphaTab
alphaTab's
Gp3To5Importer.ts:553-558shows clef extraction inreadTrack:Gp3To5Importer.ts:618handles percussion:Gp3To5Importer.ts:458documents the bass-tuning threshold:// Guitar Pro 3-6 changes to a bass clef if any string tuning is below B1Fix
TrackRSE.clefModefieldMeasureClef.neutralenum value for percussion tracksreadTrackRSE/writeTrackRSE: read/write clefMode (no longer ignoring)readMeasure: inferMeasure.clefusing alphaTab's rule:clefMode == 12→ bassVerification
Added 4 round-trip tests in
tests/test_conversion.py:testGp5TrackClefRoundtripBass— explicit bass clef preservedtestGp5PercussionTrackUsesNeutralClef— percussion → neutraltestGp5LowTuningInfersBassClef— low tuning → basstestGp5GuitarTrackKeepsTrebleClef— guitar track stays trebleWithout the fix: 3/4 tests fail (bass clef becomes treble; percussion not handled; low tuning not inferred).
With the fix: 4/4 tests pass.
All 196 existing tests continue to pass.