0

I'm somewhat new to both Python and Pygame, and trying to simply read MIDI controls live from a Windows computer. I've looked into Pygame and have set up what I think to be most of the right syntaxes, but the shell seems to crash or at least reset at the line pygame.midi.Input(input_id) every time.

import pygame.midi
import time

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

clock = pygame.time.Clock()
crashed = False

while (crashed == False):
    print("input:")
    pygame.midi.Input(input_id)
    print(str(pygame.midi.Input.read(10)))
    clock.tick(2)
Optica
  • 1
  • 1

1 Answers1

0

I am also new to both Python and and Pygame.

I also tried for quite some time to get the midi input reading to work. In another forum I was pointed to an included sample file in the library. You can see the answer here.

Side note:

On my computer there are several Midi devices active. So it maybe would be a good idea to not rely on the default input id. You can get a list of your Midi devices like this:

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

def printMIDIDeviceList():
        for i in range(pygame.midi.get_count()):
            print(pygame.midi.get_device_info(i), i)
Dharman
  • 30,962
  • 25
  • 85
  • 135
Leonhard Wolf
  • 93
  • 2
  • 10