MidiSequence includes functions for playing external MIDI files (as well as Note, Phrase, Part, and Score objects) in real-time.
A MIDI sequence can be played, looped, paused, resumed, and stopped, among other possibilities. These functions are intended for building interactive musical instruments and installations.
A program may have several MIDI sequences active at the same time.
MidiSequence 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:
|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, or a Note, Phrase, Part, and Score object. Parameter pitch (optional) specifies a base MIDI pitch to be associated with the MIDI sequence (default is A4), so we can change how it sounds (via pitch transposition). 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:
|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).|