Ear training program in Python, working with MIDI keyboard




I like very much the "Solfege" However it does not work with the MIDI keyboard.
I wanted something with training mode like this:
The software plays a random note, and asks me to replay it on the keyboard.
My eartrainer.py programm works just that way. Theoretically if you have a virtual guitar amplifier (like rakarrack or guitarix) with MIDI output, you can even use your electric guitar to play the same sound as emitted by eartrainer (however for me it didn't work very reliably :-( ).

How does it work?
The eartrainer to operate requires the same environment which you need to play your MIDI keyboard. Namely you need:
Jack and virtual synthesizer (e.g. ZynAddSubFX). You will also need the "virtual MIDI" (snd-virmidi) driver in your Linux kernel.

To start, you have to:
  1. as root: #modprobe snd-virmidi
  2. as normal user: $qjackctl
  3. as normal user: $zynaddsubfx
Then you have to setup connections in the qjackctl connections menu.
In my system I have:
In section AUDIO:
  1. ZynAddSubFX -> system

In section ALSA:
  1. 28:E-MU Xboard49 -> 24:Virtual Raw MIDI 2-0
  2. 28:E-MU Xboard49 -> 131:ZynAddSubFX
  3. 24:Virtual Raw MIDI 2-0 -> 131:ZynaAddSubFX

In your case the numbers may differ, however it essential that you
  1. Connect the audio output from the synthesizer to the system audio output
  2. Connect the MIDI output from your keyboard both to synthesizer and to virtual MIDI port
  3. Connect the output from the same virtual MIDI port to the synthesizer
If you have no MIDI keyboard, you can use the "vkeybd" in the same way, then instead of "28:E-MU Xboard49" you'll have e.g. "132:Virtual Keyboard"

When everything is routed, the proper bank in ZynAddSubFx is selected and playing the keyboard causes that sound is emitted, you can run the "eartrainer.py".
It needs just three parameters:
  1. The special file name of the virtual MIDI port. In the above described setup it will be just "/dev/snd/midiC2D0"
  2. The lowest key number
  3. The highest key number
When selecting the key number limits, take into consideration the limitations of your keyboard and virtual synthesizer!
You can check key number emitted by your keyboard using the amidi program. E.g. in the above setup you should run: "$amidi -p hw:2,0 -d" and watch the kay codes in the emited MIDI messages when playing.

In my described setup i just run "$eartrainer.py /dev/snd/midiC2D0 48 82"
The program plays a random note and requires me to play the same. If I play the correct note, it displays "Good!", selects another random note and repeats the above procedure.
If the note played by me is incorrect, it displays either "Too low!" or "Too high!" message ans plays the selected note again. This repeats, until finally I play the correct note.
Please note, that "eartrainer.py" is not foolproof. If you play two notes simultaneously, it may get confused.
The code of "eartrainer.py" is public domain. You may modify it any way you want. If you leave the information, that I've written the first version, it will be nice.
You can add some statistics to allow the user to monitor his or her progress. You can even use the pygame library and change eartrainer.py into a music arcade game like tuxlearnnotes was supposed to be...

Have fun, and please remember that this is a free open source software and you use it ON YOUR OWN RISK! I assume no responsibility for any problems you may run into because of using this program.

My other MIDI related designs and programs
Wojciech Zabolotny