Hi,
I have a hard time writing chords in a MIDI file using MIDO, the MIDI library for Python.
I have a list of 100 chords with notes stored in the list. So each chord in the code below is [60, 63, 67] as in Cmin. The timing of each in seconds is stored in the chordTimes list.
I iterate in the list,
[code type=markup]
for i in range(1, len(chords)):
chordNotes = chordMidiNotes(chords, extraBass= False)[0]
chordSymbol = chordMidiNotes(chords, extraBass= False)[1]
for note_value in chordNotes: # result has chord notes
track.append(Message('note_on', note=note_value, velocity=100, time=0))
for note_value in chordNotes: # result has chord notes
track.append(Message('note_off', note=note_value, velocity=127, time=time_in_ticks(chordTimes, mo)))
mo.save("songWithChords.mid")
[/code]
But then when I open the files, the chords start at the same time, however, the top note ends just before last chords, the one below ends before that, the one before the later stops again several beats before it, .... as you see in the image. I am using type 1 midi file.
Any help would be appreciated.
Hello,
The stave view certainly looks strange, but it would be helpful if you could attach the .mid file. Looking at the raw data might tell a lot.
Geoff
At a guess, it's because you are using time=0 for every note you add. You will need to specify a different time for different chords if you want them played at different times.
Thank you guys. I changed the time and it now works.