cuthbertLab / music21

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

music21 write xml error #1600

Open liusw02 opened 1 year ago

liusw02 commented 1 year ago

python code: from music21 import converter,instrument
file = converter.parse('The Shadow of Your Smile.mid') components = []

Recurse = file.recurse() alto = Recurse.parts[0]

print(alto)

excerpt = alto.measures(1,1) excerpt.show('text')

Text {0.0} <music21.stream.Measure 1 offset=0.0> {0.0} <music21.instrument.Piano 'Piano: Piano'> {0.0} <music21.instrument.Instrument 'None'> {0.0} <music21.instrument.ElectricPiano 'Electric Piano'> {0.0} {0.0} {0.0} <music21.meter.TimeSignature 4/4> {0.0} {1.5} {2.0} {2.5} {3.0} {3.5} text shows no problem

music21 write xml note duration error score = stream.Score()
score.insert(0,excerpt) score.insert(0,metadata.Metadata()) score.metadata.title = 'The Shadow of Your Smile' score.metadata.composer = 'example composer' print(type(file),type(excerpt)) score.write('xml',fp=r'The Shadow of Your Smile.xml')

xml <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">

The Shadow of Your Smile The Shadow of Your Smile example composer 2023-06-10 music21 v.8.1.0 7 40 Piano Pno Piano Pno None Electric Piano E.Pno 1 1 3 5 10080 G 2 quarter 65 15120 quarter E 4 5040 eighth A 4 5040 eighth B 4 5040 eighth C 5 6720 quarter 3 2 quarter 3 quarter 2 quarter E 5 5040 eighth

Importing xml sheet music with overt The Shadow of Your Smile(F)

The red circled part should be eighth notes, but it is wrongly written in xml as quarter notes, the note duration of this bar is longer than 4 (See Figure 1-1) The Shadow of Your Smile(F)1-1

Using music21 preview also gives an error The red circled part should be eighth notes, but it is wrongly written in xml as quarter notes, the note duration of this bar is longer than 4 There are also eighth rests and thirds. (See Figure 1-2) The Shadow of Your Smile(F)1-2

Correct The Shadow of Your Smile(Tur)

Version win10 Home Chinese 1909 Anaconda3 python 3.97 music21 8.1.3.0

music21-8.3.0 and music21- 8.1.0 both have this problem

jacobtylerwalls commented 1 year ago

text shows no problem

Do you mind adding the argument addEndTimes=True to your show('text') call? That would show us whether there is an overlap between the last two notes. That would indicate the issue is with parsing the MIDI (and to investigate further, we'd need you to attach the MIDI file, or better, check how other programs like GarageBand import that file.)

jacobtylerwalls commented 1 year ago

It's possible there is an issue somewhere inside this, where we fail to see that voices are required:

https://github.com/cuthbertLab/music21/blob/8ab0fe9feb903b01d9da6a0a060aa8429c21a241/music21/midi/translate.py#L2005-L2040

mscuthbert commented 1 year ago

I don't think that midiTrackToStream believes in voices. If a note is sounding and another one comes in then I think it makes a chord and ties the first note to its pitch in the next chord, like a chordify.

mscuthbert commented 1 year ago

In addition to seeing the addEndTimes version, we should see the uncompressed MusicXML version to confirm that it's not an import error by the other software.

jacobtylerwalls commented 1 year ago

I don't think that midiTrackToStream believes in voices. If a note is sounding and another one comes in then I think it makes a chord and ties the first note to its pitch in the next chord, like a chordify.

I quoted too large of a chunk 😅 -- there is a voicesRequired variable in there.