Fix GP3 writeOldChord/readOldChord asymmetry#48
Merged
Perlence merged 2 commits intoPerlence:masterfrom Apr 18, 2026
Merged
Conversation
da8d76f to
cdf344d
Compare
writeOldChord unconditionally wrote 6 fret ints after firstFret, but readOldChord only reads them when firstFret != 0 (matching the Guitar Pro byte layout). When a chord with firstFret == 0 was written and then read back, 24 unread bytes remained in the stream, misaligning every following read. The typical symptom was a later note's bend type byte being read as -1, raising "ValueError: -1 is not a valid BendType". Fix: only write the fret list when firstFret is non-zero. Added tests/Chord Old Format.gp3 (derived from Chords.gp3 with the first chord's newFormat set to False and firstFret set to 0). Without the fix the new test fails with the exact error above; with the fix it passes.
cdf344d to
aa5d7c6
Compare
Owner
|
@kaizenman Cheers! |
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
GP3File.writeOldChordunconditionally writes the 6 fret ints afterfirstFret, butGP3File.readOldChordonly reads them whenfirstFret != 0:When a chord with
firstFret == 0is written and parsed back, 24 unread bytes remain in the stream. Every subsequent read is misaligned; a later note's bend type byte ends up being read as-1, raising:Reproduction
Any GP3 file whose chord has
firstFret == 0(i.e.newFormat = Falseand no trailing fret list) triggers the crash on a library-only roundtrip:The included fixture
tests/Chord Old Format.gp3(a 1-track minimal variant of the existingChords.gp3with the chord'snewFormatset toFalseandfirstFretset to0) reproduces this deterministically.Fix
Write the fret list only when
firstFretis non-zero, mirroring the read logic and the byte layout emitted by Guitar Pro itself:Verification
TESTSintest_conversion.py, the existingtestReadWriteEqualsfails on the currentmasterwith the exact error above and passes after the fix.firstFret == 0load correctly in both TuxGuitar and PyGuitarPro, whereas files produced by the buggywriteOldChordfail to load in both. This confirms the read side (and the fixed write) matches the actual Guitar Pro byte layout.Scope
writeOldChordis only invoked for GP3 (.gp) files withchord.newFormat == False. GP4/GP5 usewriteNewChord, which is symmetric and unaffected.