Objects for realtime playback of Music21 Streams as MIDI.
From an idea of Joe “Codeswell”:
Requires pygame: http://www.pygame.org/download.shtml
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.
>>> from music21 import * >>> 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)
Attributes without Documentation: mixerInitialized