Skip to content

gp3/gp4: extract note accent flags (0x02 heavy, 0x40 normal)#56

Closed
kaizenman wants to merge 1 commit intoPerlence:masterfrom
kaizenman:fix-upstream/gp34-accent-flags
Closed

gp3/gp4: extract note accent flags (0x02 heavy, 0x40 normal)#56
kaizenman wants to merge 1 commit intoPerlence:masterfrom
kaizenman:fix-upstream/gp34-accent-flags

Conversation

@kaizenman
Copy link
Copy Markdown
Contributor

Bug

GP3File.readNote never reads flag bits 0x02 (heavy accent) and 0x40 (normal accent) from the note flags byte, even though the docstring at gp3.py:870-879 documents both flags. GP4 inherits this broken read path; only GP5 reads them correctly.

The writer side is asymmetric:

  • GP3File.packNoteFlags emits 0x02 but not 0x40
  • GP4File.packNoteFlags overrides to add 0x40 only

Round-tripping a note with accentuatedNote=True through PGP silently drops the flag.

Reference: alphaTab

alphaTab's Gp3To5Importer.ts:1210-1217 shows the canonical read path for both flags:

public readNote(track: Track, bar: Bar, voice: Voice, beat: Beat, stringIndex: number): Note {
    const flags = ...
    if ((flags & 0x02) !== 0) {
        newNote.accentuated = AccentuationType.Heavy;     // 0x02 = heavy accent
    } else if ((flags & 0x40) !== 0) {
        newNote.accentuated = AccentuationType.Normal;    // 0x40 = normal accent
    }

Fix

  • GP3File.readNote: read both flags 0x02 and 0x40 (mirroring AT)
  • GP3File.packNoteFlags: write 0x40 alongside existing 0x02
  • GP4File.packNoteFlags: drop the now-redundant 0x40 override (superseded by gp3)

Verification

Added testNoteAccentuationRoundtrip in tests/test_conversion.py, parametrised over GP3/GP4/GP5 fixtures. Verifies both accentuatedNote and heavyAccentuatedNote survive a write→read cycle.

Without the fix:

  • Effects.gp3 fails (accentuatedNote not preserved on round-trip)
  • Effects.gp4 fails (same)
  • Effects.gp5 passes (already worked correctly)

With the fix: 3/3 tests pass.

All 195 existing tests continue to pass.

`GP3File.readNote` never read flag bits 0x02 (heavy accent) and 0x40
(normal accent) from the note flags byte, even though the docstring
documented them. GP4 inherited this broken read path; only GP5 read
them correctly.

The writer side was asymmetric too: `GP3File.packNoteFlags` emitted
0x02 but not 0x40, while GP4 overrode it to add 0x40 only. Round-tripping
a note with `accentuatedNote=True` through PGP silently dropped the flag.

This change:
  * reads both flags in `GP3File.readNote` (inherited by GP4)
  * writes flag 0x40 in `GP3File.packNoteFlags`
  * drops the now-redundant override in `GP4File.packNoteFlags`
  * adds a round-trip regression test for all three formats

Cross-checked against alphaTab's `Gp3To5Importer.ts:1203-1207` which
extracts both flags universally.

Closes #1
@kaizenman kaizenman mentioned this pull request Apr 25, 2026
5 tasks
@Perlence
Copy link
Copy Markdown
Owner

Thanks for pointing that out! I did some research with the original software, Guitar Pro 5.2 and Guitar Pro 4.0. Here's the complete break down:

App Format Operation Parameter Result
GP4 GP3 read 0x02 No effect
GP4 GP3 write Heavy accentuated note N/A
GP4 GP3 read 0x40 Accentuated note
GP4 GP3 write Accentuated note No effect
GP4 GP4 read 0x02 No effect
GP4 GP4 write Heavy accentuated note N/A
GP4 GP4 read 0x40 Accentuated note
GP4 GP4 write Accentuated note 0x40
GP4 GP5
GP5 GP3 read 0x02 No effect
GP5 GP3 write Heavy accentuated note N/A
GP5 GP3 read 0x40 Accentuated note
GP5 GP3 write Accentuated note N/A
GP5 GP4 read 0x02 No effect
GP5 GP4 write Heavy accentuated note 0x40
GP5 GP4 read 0x40 Accentuated note
GP5 GP4 write Accentuated note 0x40
GP5 GP5 read 0x02 Heavy accentuated note
GP5 GP5 write Heavy accentuated note 0x02
GP5 GP5 read 0x40 Accentuated note
GP5 GP5 write Accentuated note 0x40

I'll adjust the modules so that they read and write the accentuation effects in a way that mimics the original:

Format Operation Parameter Result
GP3 read 0x02 No effect
GP3 write heavyAccentuatedNote No effect
GP3 read 0x40 accentuatedNote
GP3 write accentuatedNote No effect
GP4 read 0x02 No effect
GP4 write heavyAccentuatedNote 0x40
GP4 read 0x40 accentuatedNote
GP4 write accentuatedNote 0x40
GP5 read 0x02 heavyAccentuatedNote
GP5 write heavyAccentuatedNote 0x02
GP5 read 0x40 accentuatedNote
GP5 write accentuatedNote 0x40

@kaizenman
Copy link
Copy Markdown
Contributor Author

Maybe you can also open an issue in alphaTab? They have the same problem — 0x02 read as heavy for GP3/GP4. Your testing is much stronger argument than anything from me. If you don't have time, I can open it and link your comment as the source.

@Perlence
Copy link
Copy Markdown
Owner

Please feel free to file an issue. Guitar Pro 3 doesn't support any kind of accentuated notes. Guitar Pro 4 supports regular accentuated notes 0x40. Guitar Pro 5 supports both. You might think it's inconsistent that the accentuated effect is read from a GP3 tab, but the heavy accentuated effect isn't. However, that's an original software quirk that I'm willing to keep.

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.

2 participants