Previous topic

music21.midi.percussion

Next topic

music21.midi.translate

Table Of Contents

Table Of Contents

This Page

music21.midi.realtime

Objects for realtime playback of Music21 Streams as MIDI.

From an idea of Joe “Codeswell”:

Requires pygame: http://www.pygame.org/download.shtml

StreamPlayer

class music21.midi.realtime.StreamPlayer(streamIn, **keywords)

Create a player for a stream that plays its midi version in realtime using pygame.

Set up a detuned piano (where each key has a random but consistent detuning from 30 cents flat to sharp) and play a Bach Chorale on it in real time.

>>> import random
>>> keyDetune = []
>>> for i in range(0, 127):
...    keyDetune.append(random.randint(-30, 30))
>>> b = corpus.parse('bwv66.6')
>>> for n in b.flat.notes:
...    n.microtone = keyDetune[n.midi]
>>> sp = midi.realtime.StreamPlayer(b)
>>> sp.play()

The stream is stored (unaltered) in StreamPlayer.streamIn, and can be changed any time the midi file is not playing.

A number of mixer controls can be passed in with keywords:

mixerFreq (default 44100 – CD quality) mixerBitSize (default -16 (=unsigned 16bit) – really, are you going to do 24bit audio with Python?? :-) ) mixerChannels (default 2 = stereo) mixerBuffer (default 1024 = number of samples)

StreamPlayer methods

StreamPlayer.getStringIOFile()
StreamPlayer.play(busyFunction=None, busyArgs=None, endFunction=None, endArgs=None, busyWaitMilliseconds=50)
StreamPlayer.playStringIOFile(stringIOFile, busyFunction=None, busyArgs=None, endFunction=None, endArgs=None, busyWaitMilliseconds=50)