pygame.midi.MidiException: 'Device id invalid, out of range.'

拥有回忆 提交于 2019-12-11 12:51:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!