MIDI piano keyboard

Programming on a Keyboard… a Piano Keyboard

How can you tell a programmer from a musician? Ask them what C# is.

Since the early 1950s, when the humans finally managed to make an electronic machine sing, the computers have been gradually becoming a helpful and versatile tool in audio production. Nowadays, thanks to digital synthesizers, VSTi instruments and digital audio workstations, you can forget about endless rolls of magnetic tape and produce an almost-studio-quality recording at home if you’re persistent enough.

This progress in the music industry was significantly boosted by the invention of MIDI, a technical standard that allowed the electronic musical instruments to communicate with each other using a digital protocol. The protocol itself is based on the concept of MIDI messages, where each message consists of a status byte (indicating the type of the message), and some data bytes that contain the payload.

For example, here is what happens when you press and release the middle C key on a MIDI piano keyboard (assuming you use MIDI channel #1):

midi-piano-keyboard-middle-c-smaller

Status Byte Data Byte 1 Data Byte 2
144 = Note On 60 = Note C, octave 3 127 = Velocity (0..127): you hit the key hard
128 = Note Off 60 = Note C, octave 3 10 = Velocity (0..127): you released the key smoothly

Looks familiar, right?
Yes, computer keyboards work in a very similar way (only they don’t have as many features as MIDI piano keyboard does). So, we can easily interpret these messages and turn a MIDI input device into a handy tool for computer programming. Imagine a MIDI trigger pad doing something like this:

midi-trigger-pad-smaller

(hitting the Push key really hard makes it do a git push -f)

If you feel brave enough, you can even try to completely replace the computer keyboard with a digital piano. All you need is to have some piece of software on the computer to translate MIDI messages into computer commands. It could be a user-mode driver, or you can create a plug-in for your favoride IDE to teach it new tricks.

Which we did. Just for fun, I developed Midichlorian, a Visual Studio extension that allows you to write code and automate VS using MIDI instruments. And, inspired by The Song of Pi, my colleague Lana composed a song which is both a melody in the key of C# minor and a valid C# computer program. Watch her in action!

Under the hood, the extension attaches to the editor window, processes the incoming MIDI stream, recognizes notes and chords within it, and executes the corresponding Visual Studio commands according to the profile configured on the UI:

midichlorian-vs-options

The extension is open source, you can contribute to it on GitHub and create your own tunes.

P.S. Of course, this post would be incomplete without the sheet music:

Hello World: a Suite for Visual Studio in C# Minor

Have a question?

Speak to an expert