2015年8月21日 星期五

use RPi2 and Snappy Ubuntu Core to make a MIDI parser

Snappy Ubuntu Core is a system specific to IOT clients based on Ubuntu. There is unofficial image supporting Raspberry Pi 2. I want to use both of them, Snappy Ubuntu Core and RPi2, to make a MIDI parser and connect it to any machine. So those machines could receive MIDI signal and even more, use a instrument to output MIDI signals and control the machines via this Snappy Ubuntu Core + RPi2 MIDI parser.

Firstly, this parser must be able to receive MIDI signals from MIDI instruments. Secondly, this parser could dump the MIDI signals it received to the machine we want to control. Let's call it target machine.

get the image


First of all, of course, we need to download the Snappy image. Currently it is unofficial so it is very welcome to play around with it and, uhmm, report a bug if we find any of them. For example, I found a bug and report is as this one (LP:#1461878) which the apps will disappear by no reason. If you think you find out a bug, please have a look of the mailing list first. The mailing list is very active so it is very useful. Once you make sure there is no one has encountered the same issue, please feel free to file a bug on Launchpad and mention it on the mailing list.

After you get the image from this link, un-compress the image you downloaded and put it into the micro SD by this command.

sudo dd <the image> of=/dev/sdX bs=32M

Please note you should replace /dev/sdX with the device name of your micro SD card.

receive MIDI signals - enable the hardware

If we want to receive MIDI signals from the hardware, which is something like a MIDI instrument, we have to make sure two things work. The first one is the kernel could detect and enable to use this instrument. It is very easy to know about this information by applying this command right after you plugin your instrument into your Pi.

dmesg

we should see something like this

[44934.115258] usb 2-2: new full-speed USB device number 9 using xhci_hcd
[44934.244564] usb 2-2: New USB device found, idVendor=07cf, idProduct=6803
[44934.244573] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[44934.244578] usb 2-2: Product: CASIO USB-MIDI
[44934.244581] usb 2-2: Manufacturer: CASIO
This means our kernel found the hardware, a CASIO electronic piano, and got ready to use it. Fortunately, modern kernels support many MIDI instruments. Thanks to people contributed to kernels!

receive MIDI signals - dump the signals

Now we know our hardware/instrument is enabled and get ready to use. We are now trying to access the signals and to dump it to somewhere we could manipulate it later.

Again, thanks for the modern mature Linux kernels, ALSA has been part of the modern Linux kernels and supports MIDI handling very well. I will illustrate my study to use ALSA stack and tools in the other articles.