cuthbertLab / music21

music21 is a Toolkit for Computational Musicology
https://www.music21.org/
Other
2.12k stars 401 forks source link

tablatures: Export Fret and String articulations inside chords #1534

Closed adhooge closed 1 year ago

adhooge commented 1 year ago

music21 version

9.0.0a6 my fork is slightly behind main branch but I've checked that it has not been fixed

Problem summary

When a note inside a chord has FretIndication and StringIndication articulations, they are not exported to musicXML. This is a problem because all notes have a fret and a string in tablatures, even in chords. If the actual fret or string is not present in the musicxml file, visualization softwares usually don't throw a warning but recompute the position based solely on pitch information, which returns the wrong fretboard position in most cases.

Quickfix

On my computer, I've modified the m21ToXml.py file like so (see the corresponding commit)

# in noteToNotations

#
#
# some code ...
#
#
chordOrNote = n
if chordParent is not None and len(chordOrNote.articulations) == 0:
   # get expressions from first note of chord
   chordOrNote = chordParent
#
#
# some code ...
#
#

# apply all articulations apart from fingerings and fret/string indication only to first note of chord
applicableArticulations = []
fingeringNumber = 0
for a in chordOrNote.articulations:
    if isinstance(a, articulations.Fingering):
        if fingeringNumber == noteIndexInChord:
            applicableArticulations.append(a)
        fingeringNumber += 1
    elif isinstance(a, articulations.StringIndication):
        applicableArticulations.append(a)
    elif isinstance(a, articulations.FretIndication):
        applicableArticulations.append(a)
    elif isSingleNoteOrFirstInChord:
        applicableArticulations.append(a)

I'd be happy to submit it properly as a PR. Is there something to do in other files? I did not check if parsing musicXML works fine in that case because it was not relevant to my use case.

adhooge commented 1 year ago

Actually I notice that my fix is quite dirty and is not the right solution because of the way I change chordOrNote. I don't know what is the best way to fix the problem

jacobtylerwalls commented 1 year ago

Thanks for the report. Going to mark as a duplicate of #909, so please feel free to join the discussion there. There were a couple ways forward suggested at https://github.com/cuthbertLab/music21/issues/909#issuecomment-796903557 and https://github.com/cuthbertLab/music21/issues/909#issuecomment-797452566, if you're interested in pursuing a PR, which would be welcome!