The MidiSequence class includes functions related to playing external MIDI files (as well as Part and Score objects) in real-time.  A MIDI sequence provides playback features that are similar to the functionality described above for audio samples.  Again, these functions are intended for building interactive musical instruments and installations.

This class is included in the music library, so, you need the following in your program:

from music import *

Use the following function to create a MidiSequence object:

Function Description
MidiSequence(material, pitch, volume) Creates a MIDI sequence from the MIDI  material specified in material (this may be a filename of an external MIDI file, a Part, or a Score object.  Parameter pitch (optional) specifies a MIDI note number to be used for playback (default is A4).  Parameter volume (optional) specifies a MIDI note velocity to be used for playback (default is 127).

Once a MIDI sequence, m, has been created, the following functions are available:

Function Description
m.play() Play the MIDI sequence once.
m.loop() Repeat the MIDI sequence indefinitely.
m.stop() Stops MIDI sequence playback immediately.
m.pause() Pauses MIDI sequence playback (remembers current position for resume).
m.resume() Resumes MIDI sequence playback (from the paused position).
m.isPlaying() Returns True if the MIDI sequence is still playing, False otherwise.
m.setPitch(pitch) Set the MIDI sequence’s playback pitch (0-127) by transposing the MIDI material.
m.getPitch() Returns the MIDI sequence’s playback pitch (0-127).
m.setTempo(tempo) Set MIDI sequence’s playback tempo in beats per minute (e.g., 60).
m.getTempo() Return MIDI sequence’s playback tempo (in beats per minute).
m.getDefaultTempo() Return MIDI sequence’s default tempo (in beats per minute).
m.setVolume(volume) Returns the volume of the MIDI sequence (0 – 127).
m.getVolume() Returns the current volume of the MIDI sequence (0 – 127).