The definitive MIDI controller

What is RPC?

The Raspberry Pi Controller is intended to be a stand-alone MIDI sequencer workstation, made with open-source software and DIY electronic components. It is built around a Raspberry Pi board delivering a solid user interface. The I/O connections are served by an Arduino feeding directly to four MIDI inputs and outputs, guaranteeing accurate timing.

The name pays homage to the venerable Akai MPC series, but this is going to be a whole new kind of beast.

If this project is of interest to you, or if you would be interested in having your own little RPC (DIY, kit or pre-built, doesn’t matter) please drop me an email, tell me what you want to see me accomplish, and I will add you to the news email list. You’ll be the first to hear of updates, and I will be aware if someone actually wants one! No spam.

The protosynth

The DSP synthesizer project has taken most of my attention lately, with the RPC making steady progress on the background. The unique synthesis algorithms of the synth will make it a beast of a companion for the RPC.

Recent posts

It’s alive!

The box for the protosynth is finally complete. See the previous posts for details. The paint is still not entirely finished and could use some final touch-up, but it’s good enough for now. First pics!

Sumutor-1 ready to rok

Sumutor-1 ready to rok

All the hardware is in there and, most importantly, it all seems to work. All knobs and buttons register, leds light, and although there is no real gui, you can tap on the mock buttons and they register. Headphone output works, but I’m not sure yet if the voltage levels are right or if it’s clipping. All the parts of the synth work just as before.

The picture is taken at such an angle that the display looks empty. No, it works just fine. The led segment displays will get covered later, I still have to find some nice red film to put on top of them.

Sumutor-1 with its fleshy belly open

Sumutor-1 with its fleshy belly open

All the internals are in place. In the cover: thumbstick, big buttons and the headphone amplifier on the left, with the main UI panel and the touch TFT screen with its SD card slot taking the rest of the space. On the bottom: the synth on the left has grown itself an opamp attachment and a couple of admittedly ugly connectors, the USB+MIDI interface in the middle, and power supply board and the power connector and switch on the right. Oops, I forgot to remove the jtag cables for the photo shoot.

I’ll take some fancier shots and soundclips later (see the previous posts though!). There’s still much to do on the software side.

Mellotron on the Raspberry Pi

Mellotron is one of those curious instruments that are impossibly difficult and expensive to own, but so deceptively simple and expressive that when you get to play one, you can’t let go of it. So of course I want one.

Note: you will need an audio interface that works with Jack. This will define how playable your new instrument will be! You will also need a MIDI interface, such as the USBmidi2, but any Linux-compatible audio interface will do.

IMG_2486

Step 0: Acquire the necessary parts

The purpose of this post is to demo the USBmidi2. So I have one of those for connecting a MIDI keyboard. It will let you plug in a laptop also.

For the audio I used an old Terratec audio interface that I was familiar with. You can use any audio interface that you can get Jack to work with. The Raspberry Pi’s internal headphone jack will also “work”, kind of, but it requires so long buffer sizes that it’s unusable.

The Mellotron sample bank is available on the LinuxSampler instrument page.

Step 1: Configure Jack

Sorry, this part I will not explain here in detail. I used jackd2 and qjackctl. I was able get a latency of 2.9 ms at 44.1khz (according to qjackctl)!

You have to make sure that your Pi is configured to output audio at the minimum possible latency with minimum glitches, before you continue.

For testing Jack, I simply played some mp3s with mplayer -ao jack [song.mp3]

Step 2: Acquire LinuxSampler sources

LinuxSampler is available in the official SVN repository. See the LinuxSampler download page for details.

I had to install a few dependencies first (I already had a g++ installed):

sudo apt-get install subversion bison flex libtool automake autoconf intltool libsqlite3-dev patch

Then download the sources:

mkdir linuxsampler-src
cd linuxsampler-src
svn co https://svn.linuxsampler.org/svn/libsf2/trunk libsf2
svn co https://svn.linuxsampler.org/svn/libgig/trunk libgig
svn co https://svn.linuxsampler.org/svn/liblscp/trunk liblscp
svn co https://svn.linuxsampler.org/svn/linuxsampler/trunk linuxsampler

Step 3: Build the support libraries

Build libsf2, libgig, and liblscp in that order.

To build each, run these commands:

libtoolize
aclocal
autoconf
autoheader
automake --add-missing
./configure --prefix=/usr
make -j4
sudo make install

Some of them may require some variation or some commands were unnecessary; I will make better notes if I have to do this from scratch. Make sure the make and make install steps finish completely before continuing to the next.

Step 4: Patch LinuxSampler sources for the Raspberry Pi

LinuxSampler does not support the ARM CPU of the Raspberry Pi out of the box. Luckily someone has already fixed this, and the necessary patches are available here. You need both the RTMath.cpp patch, and also the attached atomic.h.diff patch. Or you can just grab them from my site.

Apply the patches:

cd src/common/
patch < ~/RTMath.cpp.diff
patch -p2 < ~/atomic.h.diff
cd ../..

Step 5: Build LinuxSampler

There are a few programs in linuxsampler/scripts/ that you have to run first, before LinuxSampler is ready to compile. I ran them all on order:

cd scripts
./create_instr_db.sh
./generate_instrument_script_parser.sh
./generate_lscp_parser.sh
./generate_lscp_shell_reference.pl
./update_lscp_grammar.pl

Those perl scripts required XML::Parser to run, but I think that installing ‘intltool’ adds the necessary dependencies. If not, make sure to see “Installing packages system-wide” before going on installing all the Perl libraries with cpan.

Step 6: Build LinuxSampler

This will take some time if you do it on the Pi, and it will require several hundred megabytes of disk space.

The same commands work as before, but configure required some help:

libtoolize
aclocal
autoconf
autoheader
automake --add-missing

CFLAGS="-I/usr/include/sf2 -I/usr/include/libgig" CPPFLAGS="-I/usr/include/sf2 -I/usr/include/libgig" ./configure --prefix=/usr

make -j4
sudo make install

You should now be able to run ‘linuxsampler’ in a shell on the Pi.

Step 7, optional: Install qsampler on a PC

LinuxSampler allows the GUI to run remotely. You can build qsampler to run on a more powerful computer, and connect to the Pi with it. The sources are in the same subversion repository.

Step 8: Install the sample bank and configure LinuxSampler

Extract the TaijiguyGigaTron.tar.bz2 from the LinuxSampler instrument page on the Pi. If you use qsampler remotely, the .gig file must be at the exact same path on both the Pi and your remote controller host.

I ran out of disk space at this point. Running “make clean” in the linuxsampler source tree will make you some room. I was able to fit everything on a 4 GB disk by removing a bunch of unnecessary locales from /usr/share/locale. My Raspbian also came with a rather large General Midi sound bank in /usr/share/, see if you can find it! (OK, I’m assuming it was General Midi, I deleted it before listening to it.)

Now you have to create a LSCP (LinuxSampler Control Protocol) script that initializes your hardware and loads the Mellotron sample bank. I did it like this:

  • Start linuxsampler on Pi
  • Start qsampler on PC
  • In qsampler:
    • Disable local server
    • Connect to “raspberrypi”
    • Add ports for your audio and MIDI hardware
    • Add a channel with TaijiguyGigaTron_switched.gig
    • Make sure the green “led” in qsampler blinks when you play notes – if not, check your MIDI connections!
    • Make sure sound comes out when the green “led” blinks – if not, check your audio connectiosn!
    • Save settings to LSCP file, I called mine “TaijiguyGigaTron.lscp”

Then copy the LSCP file to your Pi. My example LSCP file is available for download here, but I’m sure that you will have to modify it to work with your choice of hardware.

Step 9: Set up LinuxSampler to start without remote control

There’s a nice trick to load the LSCP file from the previous step on the Pi.

First run LinuxSampler in one shell on the Pi:

linuxsampler

When it says “initialization completed”, send the LSCP file to it in a second shell:

cat TaijiguyGigaTron.lscp | netcat localhost 8888

If you didn’t change anything else since Step 7, you should now be able to play notes with the Mellotron patch.

Step 10: Wrapping it up in a script

To prepare for starting everything in one go, I wrote a simple script that kicks off Jack and LinuxSampler. OK, it’s dirty with those sleeps and all, but works pretty well for a quick hack.

I have this in /home/pi/jackd.sh, you have to replace the jackd command line with whatever your hardware needs:

daemon -e "DISPLAY=:0.0" -- /usr/bin/jackd -P10 -dalsa -dhw:USB2448 -r44100 -p64 -n2 -Xseq -P
sleep 1
daemon -- linuxsampler
sleep 1
cat /home/pi/TaijiguyGigaTron.lscp | netcat localhost 8888

Debugging it is easy; you can add the -f parameter to daemon to run the programs in a terminal. That allows you to directly see the jack error messages. And when you get each step to run properly, just update the parameters in the script and continue with the next.

Step 11: Running Jack and LinuxSampler on startup

I found it easiest to add my script to the LXDE autostart scripts. I had two directories in /etc/xdg/lxsession/, and I’m not sure why, so I added it in both:


sudo nano /etc/xdg/lxsession/LXDE/autostart
# add on new line at end of file: /home/pi/jackd.sh

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
# add on new line at end of file: /home/pi/jackd.sh

Save everything, test it a few times, reboot, and you’re ready to rok!

Second iteration: USBmidi2

usbmidi2 full frontal

usbmidi2 full frontal


* Download datasheet *

USBmidi2 is a USB MidiStreaming class-compliant device, in double. It connects your computer, over MIDI, to another computer.

USBmidi2 is also a component that you can embed in your own musical instruments. Add a USB MIDI device port to your project, along with the three standard MIDI jacks!


To skip to the end of the story, I built a few of them to share.

Drop me an email if you are interested in acquiring one at a reasonable price.

BoardsAvailable?Price
USBmidi 1x1Yes!35 EUR+postage

I got a few requests for a MIDI interface for the Raspberry Pi, so that the Pi could be used as a component in a hardware synth module. The point was that most MIDI interfaces only have a single USB device port for connecting to a computer, and that one is taken when you plug it to your Pi. Yet a synth should behave like a USB MIDI device itself, so there should be a second port for a laptop.

So two computers, talking to each other over MIDI over USB, both acting as USB hosts… no problem! Stijn had told me about these really really nice Kinetis KL26 microcontrollers with plenty of UARTs and a built-in USB interface. One USB interface, per chip.

The only MCU with two USB interfaces that could possibly fit this purpose was the NXP LPC43xx series that I used in the signal analyzer. But the LPC is massive – TQFP144 – while the KL26 is small and flexible. So it was clear: there should be two KL26’s, with one USB port each, connected together. And the overall design seems simple enough, this way:

usbmidi2 design

The board appears as two MIDI ports on both computers. First port goes directly to the other USB host. The second one is connected to the MIDI jacks, and data is interleaved from both computers.

usbmidi2 connections

You can see the MIDI in/thru/out ports and the slave USB connector in the picture of the front of the device, at the top of this page. The backside has just the USB jack for the Pi, and looks like this:

usbmidi2 left profile

First batch of usbmidi2. Fresh hand-made boards, mmm! :)

First batch of usbmidi2. Fresh hand-made boards, mmm! :)

This is how it works in practice:

usbmidi2 connected to a Raspberry Pi

usbmidi2 connected to a Raspberry Pi; the board is intended to be mounted behind a panel, so that the Pi fits inside the same enclosure.

I’m also working on the expanded version; since you read all the way down here, here’s a teaser ;-)
usbmidi2 4x4 front viewusbmidi 4×4 – not announced yet!

Mounting dimensions: TBD.

Further technical details: TBD.

Source distribution: TBD. Please contact me if interested.

KL26ZxxxVFM4 pinout

The KL26Z feels overall like a very nice MCU; the collection of features and the pin mapping that it provides works very well for me. The chip does USB natively, it has three serial ports, two SPI, two I2C, I2S, plenty of ADCs and a DAC… the evaluation board is a scam, but can be converted into a cheap debugger with USBDM. And Erich Styger has made some really impressive work writing Processor Expert modules that also work with this chip. And the chip itself is tiny. I think I’ve found my new favorite microcontroller.

The datasheet and manuals are a mess. So I combined the pin layout, spread over three pages, on a single printable page. Click the picture below for a print-size version.

KL26ZxxxVFM4 Cheatsheet