简体   繁体   中英

How do I createa midi file with mutiple tracks of different instrument? with python and music21

so I have the code below

m3 = stream.Measure()
m4 = stream.Measure()
m5 = stream.Measure()
m3.append(instrument.Guitar())
m4.append(instrument.Tuba())
m5.append(instrument.Harp())


#----adding notes to track------#
    newNote = note.Note('F')
    newNote.duration.type = 'quarter'
    m3.append(newNote)


    newNote = note.Note('A')
    newNote.duration.type = 'eighth'
    m4.append(newNote)


    newNote = note.Note('G')
    newNote.duration.type = 'quarter'
    m5.append(newNote)
 
#-----adding tracks to song------------#
song = stream.Score()
song.insert(0,m3)
song.insert(0,m4)
song.insert(0,m5)

song.write('midi', 'blah.mid')

i want to create a song with 3 different tracks and each playing a different instrument. above code kind of combines everything into 1 track and overwrites the first 2 instruments. Is there a way that I can do this?

Ok, I figured it out. I need to change m3 = stream.Measure() to m3 = stream.Part() and m3.append(instrument.Guitar()) to m3.insert(instrument.Guitar())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM