简体   繁体   English

Python pygame.midi错误portmidi

[英]Python pygame.midi error portmidi

I use Debian 8 with any version of python pygame When i try to ear a midi by just clicking i got : 我将Debian 8与任何版本的python pygame一起使用时,当我尝试通过单击鼠标来获得Midi时:

Une erreur est survenue
La lecture de ce film exige un greffon Décodeur audio/x-midi-event qui n'est pas installé.

But i can ear it with : 但是我可以用:

aplay monfichier.mid

If I try to run my prog python/pygame a well know example find on the web that im sure it works : 如果我尝试运行我的编python / pygame,则可以在网上找到一个众所周知的示例,以确保它可以正常工作:

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()

I have: 我有:

python3 pygameex.py 
Exception ignored in: <pypm.Output object at 0xb6514e30>
Traceback (most recent call last):
  File "pypm.pyx", line 306, in pypm.Output.__dealloc__ (src/pypm.c:1438)
Exception: b"PortMidi: `Bad pointer'"

I tried python 2.7 and python 3 almost same error I looked for it on the web and i just found the same question without answers 我尝试了python 2.7和python 3几乎相同的错误,我在网上寻找了它,但我发现了相同的问题而没有答案

I want to make notes and chords without passing by files I'm looking for python module but cannot find happyness 我想在不传递文件的情况下做音符和和弦我正在寻找python模块但找不到快乐

In case anyone would experience the same issue, it usually happens when you forget to close the midi resources properly at the end of your program : 万一有人遇到相同的问题,通常会在程序结束时忘记正确关闭Midi资源时发生:

import pygame.midi
import time

pygame.midi.init()

midiOut = pygame.midi.Output(0)
midiOut.note_on(64,127)
time.sleep(0.5)
midiOut.note_off(64,127)

midiOut.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM