The MIDI Forum

  1. chekad
  2. MIDI Software
  3. Sunday, 19 April 2020
  4.  Subscribe via email
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.
Attachments (1)
Comment
There are no comments made yet.
Accepted Answer Pending Moderation
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
Comment
There are no comments made yet.
  1. more than a month ago
  2. MIDI Software
  3. # 1
Accepted Answer Pending Moderation
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.
Comment
There are no comments made yet.
  1. more than a month ago
  2. MIDI Software
  3. # 2
Accepted Answer Pending Moderation
0
Votes
Undo
Thank you guys. I changed the time and it now works.
Comment
There are no comments made yet.
  1. more than a month ago
  2. MIDI Software
  3. # 3
  • Page :
  • 1


There are no replies made for this post yet.
Be one of the first to reply to this post!