简体   繁体   中英

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 :

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 :

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

I want to make notes and chords without passing by files I'm looking for python module but cannot find happyness

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 :

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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