Title: Python pygame.midi error portmidi
Tags: python;pygame;midi
Question: 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&gt;
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
Comment: `aplay` or `aplaymidi`?


Here is another answer: 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)
midiOut.close()

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:10/22/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><pygame><midi>', 'Title': 'Python pygame.midi error portmidi', 'ViewCount': 1608, 'id': 33286619, 'user_AboutMe': None, 'user_AccountId': 7168367.0, 'user_DisplayName': 'Pat', 'user_Reputation': 21.0, 'user_Views': 1.0, 'user_id': 5476732.0}}