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):
|Status Byte||Data Byte 1||Data Byte 2|
Looks familiar, right?
Yes, computer keyboards work in a very similar way (only they don’t have as many features as MIDI 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:
(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:
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:
Yuriy Guts is an R&D engineer, .NET architect and simply an übergeek at ELEKS. Being a polyglot programmer, he’s been dealing with code for the biggest part of his life. Some witnesses even claim his first words were “Hello world!\n”. Yuriy enjoys designing complex cloud solutions for various companies across the globe. When not at work, he can often be seen (and heard by his neighbors) jamming on his guitars.