[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] detectng midi events in pygame?



Hi Brian,

The pygame midi.py example has an input event display mode.

python -m pygame.examples.midi -i

It is in the examples subdirectory in the pygame package directory. Unfortunately, the PortMidi with pygame.midi wraps does not have a midi event callback option, so midi events must be polled.

Lenard Lindstrom

On 15/12/10 03:19 PM, Brian Gryder wrote:
"""
How can I detect midi events in pygame? I am able to detect the count of MIDI devices and input and output device names (see program below) I'd like to display the midi note names like "C3 ON" or "D3 OFF". I am using the JACK Audio Connection Kit. Any code snippets, links to articles, or suggestions would be greatly appreciated.
"""

import pygame
import pygame.midi
from pygame.locals import *

pygame.init()
pygame.display.set_caption("midi test")
screen = pygame.display.set_mode((400, 300), RESIZABLE, 32)

pygame.midi.init()

print "There are " + str(pygame.midi.get_count()) + " MIDI devices"

print "The default input device number is " + str(pygame.midi.get_default_input_id())

print "The default input device info is " + str(pygame.midi.get_device_info(pygame.midi.get_default_input_id()))

print "The default output device info is " + str(pygame.midi.get_device_info(pygame.midi.get_default_output_id()))

print "The current time on the PortMidi timer is " + str(pygame.midi.time()) + " ms"

event_text = []

while True:

        for event in pygame.event.get():
                if event.type == QUIT:
                        exit()

        event = pygame.event.wait()
        print str(event)


"""
output:
user@lappy:~/Documents$ python -u miditest.py
There are 5 MIDI devices
The default input device number is 1
The default input device info is ('ALSA', 'Midi Through Port-0', 1, 0, 0)
The default output device info is ('ALSA', 'Midi Through Port-0', 0, 1, 0)
The current time on the PortMidi timer is 1 ms
"""