问题
I'm looking for a midi library in Python that will allow me to create a polyphonic midi file using different instruments.
What seems to get recommended here alot is MidiUtil. Although, it seems to have support for polyphony, I can't seem to change the instrument from piano.
Can anyone recommend an alternative midi library or advise on how to change the instrument?
回答1:
To do this, each of the different timbres that you'd like to use in your file need to have their events on a separate MIDI channel. Before any notes sound on each channel, use the addProgramChange()method of the MIDIFIle object to select the correct patch on each channel.
addProgramChange(track, channel, time, program)
Add a MIDI program change event.
Use MyMIDI.addProgramChange(track,channel, time, program)
Arguments
track: The track to which the event is added. [Integer, 0-127].
channel: The channel the event is assigned to. [Integer, 0-15].
time: The time at which the event is added, in beats. [Float].
program: the program number. [Integer, 0-127].
See http://www.emergentmusics.org/mididutil-class-reference for documentation of all the methods supported by that class.
来源:https://stackoverflow.com/questions/13795959/making-midi-files-in-python-that-are-polyphonic-and-different-instruments