GetMoney_G5
GetMoney_G5

Reputation: 65

How to implement a MIDI keyboard into python

Looking to create a GUI based 25-key keyboard using PYQT5, which can support MIDI controller keyboards. However, I don’t know where to start (What libraries should I use and how do I go about finding a universal method to supporting all MIDI controller keyboards). I plan to potentially use the Mido Library, or PyUSB but I am still confused as to how to make this all function. Any starting guides would be much appreciated.

Upvotes: 0

Views: 596

Answers (1)

dspr
dspr

Reputation: 2433

MIDI is a universal standard shared by all manufacturers, so you don't have to worry about "supporting all MIDI controller keyboards", you just have to worry about supporting the MIDI studio of your system.

You'll have to scan your environment to get the existing MIDI ports. With the list of existing ports you can let the user choose to which port he wants to send the events generated by your keyboard and/or from which port he wants to receive events that will animate the keyboard (for instance from a physical MIDI keyboard connected to your computer), possibly all available input ports.

To support input events, you'll need a kind of callback prepared to receive the incoming notes on and off (which are the main relevant messages for a keyboard) at any time. That also means that you have to filter the received events that are not of those types because, in MIDI, a stream of events is subject to contain many kinds of other events mixed with the notes (pitch bend, controllers, program change, and so on).

Finally notice that MIDI doesn't produce any sound by itself. So if you plane to hear something when you play on your keyboard, the produced MIDI events should be send to a device subject to produce the sound (for instance a synthesizer or virtual instrument) via a port that this device receives.

For the library, Mido seems to be a pretty good choice : it has all the features needed for such a project.

Upvotes: 2

Related Questions