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.