Here's a little details on my Raspberry Pi Midi-keyboard project I made as a degree work at school. This is my first attempt on making something with a RaspPi. https://www.youtube.com/watch?v=mpeTHLr1vlc
I've been interested in music and technology (and music technology) for almost my entire life, and when we had to come up with something to create as a degree work at our (finnish) college, I thougt it would be awesome to combine those two and create an instrument. As I thought of a method of implementation, I came across to my RaspPi I'd had for a while, which was perfect for the project.
I'm using Debian Wheezy as the distro, for it suits well with my needs. I made the program with Python, which I'd never used before. Luckily I learned it a little along the way. As the sound driver I used ALSA which comes within the distro. The software-synthesis happens with Timidity, a software synthesizer that renders midi data in real time without an external synthesizer (please correct me if I said it wrong). With Timidy its simple to change your soundfonts by just changing the .sf2-file path to timidity's configuration file.
The code:
The program itself is quite simple. I use Pygame to recognize the keypresses and output the midi data. If the key is pressed, the defined midi value plays. If the key is raised, the sound turns off.
Code: Select all
def keypress():
event = pg.event.wait()
if event.type == pg.KEYDOWN:
if notes.get(key, 0):
midiout.note_on(notes.get(key) + noteOffset, velocity)
return "d_" + key
if event.type == pg.KEYUP:
if notes.get(key, 0):
midiout.note_off(notes.get(key) + noteOffset, 0)
return "u_" + key
Code: Select all
notes = { "n":72, "j":73 }
The rest of the code just defines different fuctions for some keys on the keyboard. With the up and down arrow keys you can change volume, left and right changes the instrument and so forth. You can really change them to do anything you like. As the keyboards layout I used a pattern made by Paul von Janko (google it). I also made a layout like in an accordion. You can change it to anything.
Mechanics:
For the project I used an old Keytronic keyboard that I bought from a local flea market for 1€. The RaspPi is a model B+, which fits under the keyboard (with the help of two drawer handles

Pics:
https://www.dropbox.com/s/l0rry4g4ff5r0 ... 6.jpg?dl=0
https://www.dropbox.com/s/q794vuxj3pq22 ... 5.jpg?dl=0
https://www.dropbox.com/s/vg8g7gsoelg7c ... 4.jpg?dl=0
So, there's a quick introduction to my project. Please feel free to leave feedback, good or bad. Cheers!
EDIT (3.10.2017):
The needed packages for the project are Python 2.7 and Pygame for it, ALSA (Advanced Linux Sound Architecture) and Timidity. You can install them straight through apt-get or by downloading them with wget.
Timidity needs to be set to use ALSA to produce the sounds and this can be done by going to /etc/init.d/timidity (It’s there so it launches when the device boots) and adding parameters
”-iAD -B2,10 -Os”
The parameters “iAD” and “-Os” make Timidity use ALSA as the sound driver and “-B2,10” sets the buffer size to 1024. The bigger the buffer size is, the more there’s latency (if it’s too small the sound distorts).
You can change the sound “fonts” by changing the .sf2-file path in Timidity’s config file at /etc/timidity/timidity.cfg.
The program’s source code can be found at my GitHub: https://github.com/anttus/Raspberry-Mid ... eyboard.py
Images:
https://www.dropbox.com/s/jwsw89qqeajnu ... 1.jpg?dl=0
https://www.dropbox.com/s/kd2ug7sfeuvd6 ... 2.jpg?dl=0
https://www.dropbox.com/s/47nzrtr2ekidg ... 3.jpg?dl=0
https://www.dropbox.com/s/xc321690q0ksw ... 4.jpg?dl=0
https://www.dropbox.com/s/iqrdor88limg8 ... 5.jpg?dl=0
https://www.dropbox.com/s/flqxupxjbtqul ... 6.jpg?dl=0
Hopefully this clears out the project a little.
