fbpx
Skip to main content

MIDI Forum

Issue with writing ...
 
Notifications
Clear all

Issue with writing chords to midi file

4 Posts
3 Users
0 Reactions
12.8 K Views
chekad
Posts: 5
Active Member
Topic starter
 

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.

 
Posted : 18/04/2020 9:15 pm
Geoff
Posts: 1040
Noble Member
 

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

 
Posted : 19/04/2020 3:53 am
Eddie Lotter
Posts: 295
Reputable Member
 

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.

 
Posted : 19/04/2020 6:15 am
chekad
Posts: 5
Active Member
Topic starter
 

Thank you guys. I changed the time and it now works.

 
Posted : 19/04/2020 8:56 am
Share: