13

I've got a trigger finger (MIDI tablet) and I want to be able to read its input live and make python execute actions depending on the pressed key.

I need it for Windows, and preferably working with python 2.5 +

Thanks

kettlepot
  • 10,574
  • 28
  • 71
  • 100

1 Answers1

11

PyGame includes a built-in midi module, available for Linux, Windows and MacOS and is very well supported.

For example, here is the documentation for pygame.midi.Input:

  Input is used to get midi input from midi devices.
  Input(device_id)
  Input(device_id, buffer_size)
        Input.close - closes a midi stream, flushing any pending buffers.   closes a midi stream, flushing any pending buffers.
        Input.poll - returns true if there's data, or false if not. returns true if there's data, or false if not.
        Input.read - reads num_events midi events from the buffer.  reads num_events midi events from the buffer.

If you're looking for an alternative, have a look at PythonInMusic in the Python wiki.

There are various different projects related to MIDI input and output there, some for Windows as well. (Click the little > sign after each project to follow the link to the project homepage)

I have not used any of them personally, but I'm sure it will help you get started.

Andre Miller
  • 15,255
  • 6
  • 55
  • 53
  • how do i get to know the device id? – kettlepot Oct 12 '09 at 14:49
  • Have a look at the other functions on that page. There is one to return the default input device: http://www.pygame.org/docs/ref/midi.html#pygame.midi.get_default_input_id – Andre Miller Oct 12 '09 at 14:50
  • Bear in mind that if you use PyGame, you will have to process the events by **polling**, so it won't be as real-time as you would want to. Ideally, there should be a libary to **hook** functions to the midi events. – jcrs Jul 23 '18 at 18:14