After creating the isomorphic alternative keyboard with a Cherry USB QWERTY keyboard and the program MIDI Integrator (see my previous post ‘Alternative Keyboards 3‘), I started to think about the possibility of using two keyboards, like the Jammer.
The Jammer uses MIDI Integrator, but it can do this because it uses two AXiS-49 MIDI keyboards. It wouldn’t be possible for me do the same with two QWERTY keyboards, for two reasons: a) MIDI Integrator only has the facility for mapping one QWERTY keyboard at a time, and b) MAX/MSP does not recognise alternative key codes with the ‘Shift’ key pressed – i.e. both ‘q’ and ‘Q’ are interpreted the same, even though they have different ASCII codes. This would mean that however many keyboards you had, they would all output the same notes to the same synthesiser or sound card.
So, I needed to find an alternative program for this application, one that would recognise two QWERTY keyboards, be able to interpret their outputs separately, and potentially route them to two different synths.
A program that will do this is ‘Pure Data’, a relative of MAX/MSP. Like MIDI Integrator (but unlike MAX/MSP itself) it is free to use, and programming is done graphically. Full details are on the Pure Data Community site at http://puredata.info/.
A piece of Pure Data programming looks like this:

You create the different types of boxes, write in them the values or functions and sequence them by joining them together with lines. In the above example, the message box at the top contains the number 60, the MIDI note number for middle C, and a little lower down is a box with the function ‘mtof’, MIDI-to-frequency, which converts the MIDI note number to a frequency measured in Hertz. There are 4 boxes marked ‘osc~’, which represent sine wave oscillators, mixers (‘*~’) and a graph which will display the complex waveform created by the summing of the 4 sine wave oscillators.
Amongst the many functions available in Pure Data are ‘key’, ‘keyup’ and ‘keyname’, which are designed to accept input from a QWERTY keyboard. The function ‘key’ accepts and outputs the ASCII key code when a key is pressed, ‘keyup’ does the same when the key is released, and ‘keyname’ tells you the name of the key in use.
Most importantly, Pure Data accepts all ASCII codes, and can therefore distinguish between simple key presses, and key presses + Shift. This means you can have two whole keyboards-worth of different key numbers, making it worthwhile using two keyboards, with no ASCII code being duplicated in both of them. As long as the program could be made to understand which numbers belong to which keyboard, it would be possible to treat each keyboard differently, and route their outputs to different MIDI synths.
So what I needed was a) a second Cherry Keyboard, and b) to learn how to program Pure Data to distinguish key presses from one keyboard or the other; divide them into two streams and deal with them separately; and use the ASCII codes received to output appropriate MIDI note numbers.
The second keyboard was easily found on eBay. It had a PS2 connector, and it was from this experience that I gained the knowledge of PS2 to USB converters which I wrote about in this post: https://andymurkin.wordpress.com/2012/01/01/alternative-keyboards-2/. It functioned perfectly with the aid of a ‘Blue Cube’. I also removed the keycaps, cleaned the (second-hand) keyboard, and painted the keycaps blue. It wouldn’t matter which keyboard was used for the left hand and which for the right, as they are identical models, but I tend to use the blue one for the left hand and the red one for the right.

They’re set up here for testing purposes only. Having two separate keyboards for left and right hands means that in practice, they can be placed in a more ergonomically suitable fashion for comfortable playing.
(The eMac they’re connected to is almost worthy of a post of its own. If you’re a Mac User, and you’ve got room for an old-fashioned CRT-screen desktop, it’s worth considering an eMac: nobody wants them, so they’re very cheap: this one, which was £20 off eBay has the same OS as my laptop – not the latest Mac OS, but a perfectly respectable one; it has firewire as well as USB and Ethernet, and a DVD ROM/CD burner drive. I’m able to use it as a dedicated MIDI machine, and use the laptop for soft synths and recording.
Upstairs in the Music Room I have 2 iMacs, which are similar in appearance, but slightly smaller. These aren’t as good as the eMac, and aren’t able to run such a recent OS, but are still able to perform some useful tasks as VST instruments hosts, MIDI control my Behringer V-Amp, and so on – and they were £5 each!)
The USB hub I installed in the Superstylonanphone came in handy at this point: although the eMac has 3 USB connectors, I was beginning to run short, as both of the Cherry keyboards needed to be connected individually, as well as various other devices I was using at the time.
Not shown is a vital piece of equipment required for the blue keyboard, which is a clip to hold the Shift key down. In order to take advantage of the two keyboards-worth of ASCII numbers recognised by Pure Data, it was necessary to do this – Caps Lock only affects the letter keys, not the others – and I haven’t yet found the best way of doing it. The next thing I’ll be trying is a drawing board or table cloth clip (it has to be thin and flat on the bottom); but in any event, it’s vital that one of the keyboards outputs the usual numbers and the other one outputs the numbers with the Shift key down.
Turning to the software, the two difficulties would be a) getting the program to distinguish the numbers received by one keyboard from the other, and b) getting it to output the appropriate MIDI note numbers.
The entire program looks like this:

The function called ‘key’ in the top left receives the numbers from the keyboards. It neither knows nor cares whether these numbers are coming from one keyboard or two. The function ‘keyname’ is just there for the sake of interest – originally for the sake of testing! – and doesn’t actually contribute to the working of the program (or ‘patch’, as they call it in Pure Data).
The number from the keypress is passed to a very complicated sifting system underneath, the purpose of which is to divide the numbers coming from the red keyboard from the numbers coming from the blue keyboard.
Unfortunately, as I said in the previous post referred to above, there is no simple way of distinguishing the ASCII numbers – they’re pretty random, it seems. I’ve used a function called ‘moses’. Like Moses, who parted the Red Sea, this function parts the stream of numbers coming into it: you put a number in the box and it sends this number and any higher numbers out of one output and all the lower numbers out of the other output. In this way I was able eventually to divide the numbers and send them in the right direction.
In the middle part of the program you can see the two separate streams of note numbers moving from top to bottom; the settings on the right-hand side of the program allocate MIDI channel, velocity, duration and octave information. At the bottom, the Pure Data functions ‘makenote’ and ‘noteout’ convert all these details to the kind of MIDI signal understood by a synth. You just need to tell the program where exactly to send these MIDI signals in the program ‘Preferences’.
That just leaves one question: how does the program know how to convert the incoming ASCII numbers to the correct MIDI note numbers? The answer is in a similar way to MIDI Integrator in the previous post: by means of a pre-written text file. In the bottom right of the program, there is a list (very incomplete at the moment as it only contains ‘Wicki-Hayden’, ‘Janko’ and ‘System C’, and only ‘Wicki-Hayden’ has so far been implemented!) of layouts which can be used.
When you select the ‘Wicki-Hayden’ option, the instruction at the bottom gets the program to read the text file ‘wicki.txt’ into a table (or array) called ‘notes’; the function ‘tabread notes’ in the middle of the program uses the information in this table to convert the ASCII numbers it receives into the MIDI note numbers you want it to output.
The format of this text file is quite different from the text file in MIDI Integrator. It looks like this:

On the face of it, pretty meaningless! The way it works is this: the table is 128 numbers long. This is because there are 128 possible MIDI note numbers, and why it says in the instructions at the top of the program, in the middle, ‘Open ‘table notes’. Set array size to 128′. The button for opening ‘table notes’ is right down near the bottom of the left-hand side of the program window, not right next to this instruction, as you would think it should be. Don’t ask me why.
So the table is 128 numbers long, and what the program is doing when it receives a number is this: if it receives the number 60, it outputs the number at position 60 in the table; if it receives the number 113, it outputs the number at position 113, and so on.
This is more complicated than the method for MIDI Integrator, but can nevertheless be achieved with a little patience and the correct data to hand. Here’s what I did:
First of all, as before, I filled out the spreadsheets showing the layout of the keys, the ASCII numbers and the MIDI note numbers (see https://andymurkin.wordpress.com/2012/01/01/alternative-keyboards-3/). In fact, the sheet for the red keyboard was the same as the one I used in MIDI Integrator, it was the new sheet for the blue keyboard that was different. To fill this in, I had to change the MIDI note numbers and the ASCII numbers.
In fact, I could have left the MIDI note numbers the same as the red keyboard, but I thought it would be more practical to have them an octave lower, so I entered all the MIDI numbers with 12 deducted from each one – that’s all it takes to lower the notes by one octave.
The ASCII codes had to be changed because the blue keyboard would output the number of the Shifted keys – i.e. ‘Q’ instead of ‘q’, ‘%’ instead of ‘5’, etc. I used this chart to change the numbers on the spreadsheet:
[Edit: to be clear, this is a list of all the MIDI notes and standard ASCII codes from 0-127.
In the chart below, Column 1 shows the names of all the 128 MIDI notes available, from the lowest to the highest; Column 2 shows the MIDI number associated with each of these notes – these are also the ASCII numbers which my Pure Data patch uses; Column 3 shows the key that produces this ASCII number; and Column 4 gives a description of which key this is].

[Edit: In fact, on UK keyboards the symbols ” (‘Quotes’) and @ (‘At’) are reversed, so ” = 64 and @ = 34]
The one obstacle I came up against was the F keys, which don’t have an alternative number when used with the Shift key. This meant that the blue keyboard was restricted to 4 rows – but as this is more than 40 notes, it wasn’t too much of a limitation.
[Edit: looking at the chart above, you can see that the F keys don’t have an ASCII number in any case, so neither of the keyboards can use this row of keys with the Pure data patch, even though the single keyboard could with the program MIDI Generator (see ‘Alternative Keyboards 3‘), based on Max/MSP, which uses a different, non-ASCII system. This problem may be overcome with some keyboard remapping.
Edit 2: I’ve now used KeyRemap4Mac – now called Karabiner – to remap F1 – F8 as 0 – 7; I couldn’t find a way of remapping F9 and above].
Here’s how I created the text file:
First of all, the first position in a 128-position table is 0, and the last one is 127. So I opened a blank text document and wrote a column of numbers down the left-hand side from 0 to 127. These are the ASCII key numbers. I then went through the two spreadsheets and for each key I needed to use I wrote down the MIDI number against its ASCII number in the text document. When I finished, I put ‘0’ against every unused ASCII number in the list.
When I had a list of 128 numbers – many of which were now 0 – I removed all the ASCII numbers in the left-hand column, left one space between each remaining MIDI note number, and saved the text file as ‘wicki.txt’. This file is now read at any time when ‘Wicki-Hayden’ is selected as the layout in the program, and the values don’t need to be entered again.
The patch and the text file are here: Double Keyboard patch; Wicki-Hayden layout text file.
See also this post: ‘Alternative Keyboards 5 – Postscript‘ for a little extra info on the Cherry Double Keyboard.