From aa5d7c6d2fec21f32e5f36c8ec1597b91390717e Mon Sep 17 00:00:00 2001 From: kaizenman Date: Tue, 14 Apr 2026 23:55:03 +0200 Subject: [PATCH 1/2] Fix GP3 writeOldChord/readOldChord asymmetry 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. --- src/guitarpro/gp3.py | 7 +++++-- tests/Chord Old Format.gp3 | Bin 0 -> 1165 bytes tests/test_conversion.py | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 tests/Chord Old Format.gp3 diff --git a/src/guitarpro/gp3.py b/src/guitarpro/gp3.py index d14d936..4d6fc56 100644 --- a/src/guitarpro/gp3.py +++ b/src/guitarpro/gp3.py @@ -1281,8 +1281,11 @@ def writeChord(self, chord): def writeOldChord(self, chord): self.writeIntByteSizeString(chord.name) self.writeI32(chord.firstFret) - for fret in clamp(chord.strings, 6, fillvalue=-1): - self.writeI32(fret) + # Fret list is only present when firstFret is non-zero; this + # matches readOldChord and the byte layout produced by Guitar Pro. + if chord.firstFret: + for fret in clamp(chord.strings, 6, fillvalue=-1): + self.writeI32(fret) def writeNewChord(self, chord): self.writeBool(chord.sharp) diff --git a/tests/Chord Old Format.gp3 b/tests/Chord Old Format.gp3 new file mode 100644 index 0000000000000000000000000000000000000000..5a3d078d31105aca7e0639dfe3b65aed0f452962 GIT binary patch literal 1165 zcmb1e^K|y`bPZB)5A_Uj3{nUP@>eJ`)-y0*00Tx4Ndy5_TmdE-7$ku-F9(D}YxaL2 zpqE{=@XM(C>61=y#T_leACzA}n3;uzfjy)sF*#eo5aLTbBpXo90f?=E*c^zBfLIrZ zHGmidV1_aQ*%Dw828RDY8pLP%52hHMq2iDn3zcLB(jZ^fC@?Z8FfxKkCIv=jrvD%# gu>*uj*yVwuFwHO; Date: Sat, 18 Apr 2026 17:22:20 +0400 Subject: [PATCH 2/2] fixup! Fix GP3 writeOldChord/readOldChord asymmetry --- src/guitarpro/gp3.py | 2 -- tests/Chord Old Format.gp3 | Bin 1165 -> 1052 bytes 2 files changed, 2 deletions(-) diff --git a/src/guitarpro/gp3.py b/src/guitarpro/gp3.py index 4d6fc56..23e49f7 100644 --- a/src/guitarpro/gp3.py +++ b/src/guitarpro/gp3.py @@ -1281,8 +1281,6 @@ def writeChord(self, chord): def writeOldChord(self, chord): self.writeIntByteSizeString(chord.name) self.writeI32(chord.firstFret) - # Fret list is only present when firstFret is non-zero; this - # matches readOldChord and the byte layout produced by Guitar Pro. if chord.firstFret: for fret in clamp(chord.strings, 6, fillvalue=-1): self.writeI32(fret) diff --git a/tests/Chord Old Format.gp3 b/tests/Chord Old Format.gp3 index 5a3d078d31105aca7e0639dfe3b65aed0f452962..588f46b550895d7627251debe0d5260468eff7ca 100644 GIT binary patch delta 99 scmeC>oWrrToDEa0RNW<@&Et; delta 133 zcmbQk(aX8vAhQh<0|Nuoe+Cf6=nN#lfDuZAM45s3KM>R?Ffu4GGJ;7a1x9A3|BRCh jnI)Kk+CcQ=24+qfm_8VdtRJd~orMtyCSPP021)_|a8(uJ