playing midi sounds through pygame on raspberrypi <p>I'm trying to play midi sounds using pygame on my raspberrypi (without external midi devices), however I can't get anything to work.</p> <p>I have tried many examples: The following gives.</p> <pre><code>import pygame import time import pygame.midi pygame.midi.init() player= pygame.midi.Output(0) player.set_instrument(48,1) major=[0,4,7,12] def go(note): player.note_on(note, 127,1) time.sleep(1) player.note_off(note,127,1) def arp(base,ints): for n in ints: go(base+n) def chord(base, ints): player.note_on(base,127,1) player.note_on(base+ints[1],127,1) player.note_on(base+ints[2],127,1) player.note_on(base+ints[3],127,1) time.sleep(1) player.note_off(base,127,1) player.note_off(base+ints[1],127,1) player.note_off(base+ints[2],127,1) player.note_off(base+ints[3],127,1) def end(): pygame.quit() </code></pre> <p>Gives the following error</p> <pre><code>PortMidi call failed... PortMidi: 'Bad pointer' type ENTER... </code></pre> <p>The next example (like most of the others) gives a 'Device id invalid, out of range.' error:</p> <pre><code>import pygame import pygame.midi from time import sleep instrument = 0 note = 74 volume = 127 pygame.init() pygame.midi.init() for id in range(pygame.midi.get_count()): print pygame.midi.get_device_info(id) port = 2 midiOutput = pygame.midi.Output(port, 1) midiOutput.set_instrument(instrument) for note in range(0,127): midiOutput.note_on(note,volume) sleep(.25) midiOutput.note_off(note,volume) del midiOutput pygame.midi.quit() </code></pre> <p>Gives this error</p> <pre><code>('ALSA', 'Midi Through Port-0', 0, 1, 0) ('ALSA', 'Midi Through Port-0', 1, 0, 0) Traceback (most recent call last): File "midi-test2.py", line 16, in &lt;module&gt; midiOutput = pygame.midi.Output(port, 1) File "/usr/lib/python2.7/dist-packages/pygame/midi.py", line 414, in __init__ raise MidiException("Device id invalid, out of range.") pygame.midi.MidiException: 'Device id invalid, out of range.' </code></pre> <p>I haven't found any guides to setting up a RaspberryPi to play midi sounds, any suggestions?</p>