Skip to content

Instantly share code, notes, and snippets.

@dubiouscript
Created January 1, 2019 11:32
Show Gist options
  • Save dubiouscript/c152c458e386a53cad1a716eb6e8be78 to your computer and use it in GitHub Desktop.
Save dubiouscript/c152c458e386a53cad1a716eb6e8be78 to your computer and use it in GitHub Desktop.

Virtual Midi Janko Keyboard

The good thing about language-related subreddits is you can always tell people there about your hello world project, and the good thing about medium sized subreddits is your post might even be noticed.

So let's talk about mine one.

What

VMJK is a program that allows you to use your computer keyboard like some kind of midi keyboard with Janko key layout. It is written in Rust, and you can find it on github.

Why

I don't have a midi keyboard. But I have a computer keyboard. And I want to use my computer keyboard as a midi keyboard.

There're several issues with traditional virtual keyboards (like Virtual Midi Piano Keyboard). The first is 7-5 pitch pattern takes a lot of space, so you can't fit two octaves into one line, also some keys remain unused. The second is it requires learning dozens of different fingerings, like a normal piano, so there's a lot to learn and playing is much less intuitive than with the Janko layout.

The third is related to chords. Due to hardware limitations, you can't use some key combinations as chords. With the Janko layout this is not a big deal, you can just change your fingering a bit. While with traditional layout some chords are just not available to you.

Janko layout maps to computer keyboard perfectly, that's why it was used.

Tell me more about Janko layout

Sure. You can read more about it here: http://squeezehead.com/uniform-keyboard/

Janko layout is one of so called isomorphic layout. The word isomorphic basically means that you can play any interval anywhere without changing your fingering. Bayan and guitar (especially properly tuned) are the most known isomorphic instruments. Other isomorphic layouts are Wicki-Hayden and Harmonic table layouts. If you're interested in microtonality (you should), there's also generalized keyboard that basically generalizes Janko layout to microtonal tunings.

I will argue that generalized keyboard layout is superiour to Wicki-Hayden or Harmonic table layouts. Not only because reminds a traditional keyboard, but also because it uses key space in a more optimal way.

To show this, there're some pictures. This is generalized keyboard for 31-tone equal temperament:

As you can see, there's a lot of new keys. But all of them are easy to reach. Do you play it in traditional way (don't confuse sharps with flats!) or do you go full Wyshnegradsky, all keys are reachable, everything is easy to play.

Wicky-Hayden layout is different (let it be 19-TET):

Here, sharp and flat keys are harder to reach than white keys. With 31-TET this is even worse, since you also have double flat (semi-sharp) and double sharp (semi-flat) keys that are even more far from the center. So, simple diatonic stuff is easy to play, more complex stuff is harder, and advanced microtonal stuff is very hard to play.

The advanages of Wicky-Hayden layout are it is easier to play very wide chords (they might sound good) and harmony based on fifths, fourths and octaves (which is obsolete since Middle Ages).

To tell you even more about keyboards, I went on the internet and I found this:

Enough about keyboards, how to I use it

Ok, ok. Look at the keyboard:

  • \, z, x, c... → C, D, E, F♯...
  • \, a, w, 3... → C, C♯, D, D♯...
  • Yes, right Ctrl and right Shift are musical keys too

For example, I-V-I progression: \xf, fhi, xfn. Pretty straightforward.

VMJK have two modes: “high” and “low”. The “low” mode is one octave below the “high” mode. You can change modes by pressing Space.

You can change channels by using numpad + and -. PageUp and PageDown navigate patches while the same keys plus Ctrl navigate banks.

Beside hotkeys, there's also command mode. You can enter or leave command mode by pressing Esc. There're several commands available in command mode:

  • dev: connects VMJK to a midi device. Note, it doesn't require to type the whole device name, you can type only a part of it and select the first element from the list (navigating the list via arrow keys is not implemented yet)
  • chan: selects a channel
  • prog selects a program or/and a bank. They syntax is patch/bank, so prog 10 chooses patch 10, prog /2 chooses bank 2 and prog 7/4 chooses patch 7 from bank 4.

Why Rust & SFML

You code better/faster with a language you're familiar with, and at this moment I'm familiar with Rust more than with e.g. Haskell. The project is tiny, so there's almost no issues with owning & borrowing semantics.

The reason why I use SFML is, well, SFML is simple. I tried to use Piston, the overengineered framework of complexy that requires xml-rs even to show a window, and it was horrible. Nothing is easy or even straightforward. And despite all that complexy it doesn't even allow to disable the key repeat!

SFML was the only simple graphics library I could find. It's not perfect, it is written in C++ and has the way too traditional C++ API, but it just works. I'd like to use some nice rust library with rustic API, but there's none. Please tell me if I'm wrong and such a library actually exist.

Virtual keyboard is nice, but what about a physical one

You're out of luck. Music instruments manufactures keep being extremely uncreative and believe that there is only one tuning, only one keyboard design, and you don't need anything else. After all, Chopin used an ordinary piano, Debussy used an ordinary piano, Scriabin used an ordinary piano, their music was awesome, why do you need anything else? Who cares you don't have limitations of an acoustic instrument in XXI century.

You probably say this is horrible and I can't be right. Indeed, there're always some deviants. If you go on the internet, you can find this:

So many cool instruments! Good luck finding them in a music instruments store nearby.

But if you think a bit, it finds out you're relatively lucky. Look, you have maybe not perfert but useful keyboard. You have notation that sucks, but it doesn't suck too much. You always have enough notes, you have usable sequencers and DAWs, you have a lot of cool synths. And, or course, you have teachers, books and a lot of music to learn from.

Microtonalists generally don't have any of these. The main way to get an instrument is to make it yourself, MIDI only have 128 notes, sequencers are hardly usable when even major third is ten steps wide, and, of course, notation sucks even more.

What about synths, there're two tuning standards: MTS and Scala. Guess which one synths usually support? You're absolutely right: none. Indeed, I actually know two synths that support Scala: Zynaddsubfx and Pianoteq (what a rich choice!).

By the way, this are some advices if you're going to do some microtonal music (I wish you do, it's sad we stuck with 5-limit diet). Don't do quartertone music. It not only sounds like out of tune, it is out of tune. Instead listen to majestic sounds of harmonic series and choose a tuning that approximates it well.

31 tone equal temperament is very good. It have all possibilities of 11-limit harmony and yet have large enough step (diesis). No, 31 is not too much, it's actually very reasonable number of tones. No, it's not too hard to learn. And you can map most of music to it. No, it's not alien. For example, blue notes are a septimal (related to 7th harmonic) grass growing through 5-limit pavement. Wyshnegradsky may sound crazy, but there's enough of music that sounds better.

There's a good site about 31-TET. Also visit Online Terpstra Keyboard any try clicking some keys (Space sustains notes), it is fun.

Oh, and some music in the end:

Do you really think it sounds horrible?

Why don't you just use a midi bayan

You must be kidding.

Do you plan to code something else

Yep. As I said above, standard piano roll is barely useful for 31-tone music. I'd like to tell you more, but I'm lazy and it post is already long enough.

Why your post is so long

Ordinary presentation of VMJK would be short&boring. So I tell you about various awesome things, light your imagination, wake up your passion... and leave you with hello world tier project for 12-TET. :P

Questions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment