问题
I'm on Mac OSX Yosemite 10.10.5 and I'm trying to play midi sounds with pygame.midi with this code:
import pygame.midi
pygame.midi.init()
print pygame.midi.get_default_output_id() # -1
print pygame.midi.get_device_info(0) # None
player = pygame.midi.Output(0)
And I get this output:
-1
None
Traceback (most recent call last):
File "midi.py", line 11, in <module>
player = pygame.midi.Output(0)
File "/Library/Python/2.7/site-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.'
I've tried a bunch of different device id's (0-128) to look where my output speakers might be found, but I can't find anything. It's like my mac doesn't have an audio output, but it should.
回答1:
The purpose of pygame.midi
is to access MIDI devices.
Speakers are not MIDI devices. Neither is anything else on your computer.
If you want to ensure that your program can output MIDI data, you have to install a software synthesizer.
来源:https://stackoverflow.com/questions/33577001/pygame-midi-midiexception-device-id-invalid-out-of-range