fbpx
  Sunday, 19 April 2020
  3 Replies
  12.4K Visits
0
Votes
Undo
  Subscribe
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,


for i in range(1, len(chords)):
chordNotes = chordMidiNotes(chords[i], extraBass= False)[0]
chordSymbol = chordMidiNotes(chords[i], 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[i], mo)))
mo.save("songWithChords.mid")


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.

Screen Shot 2020-04-19 at 1.10.11 AM.png

Any help would be appreciated.
3 years ago
·
#5048
0
Votes
Undo
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
0
Votes
Undo
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.
3 years ago
·
#5052
0
Votes
Undo
Thank you guys. I changed the time and it now works.
  • Page :
  • 1
There are no replies made for this post yet.