Ex falso quodlibet

Ceci n'est pas un blog

A web service to practice scales

This post explains why the hell I wrote a web service.

For some years now, I'm learning (trying to learn really) jazz improvisation. One of the thing you have to learn and practice in this context is the different scales, or musical modes.

There is a whole theory behind these modes, so I'm quite at home. But theory doesn't always help to memorize and internalize these things: there is a gap to fill between theory and practice in order to be able to improvise music based on these different modes.

Modes (I'm talking only about diatonic heptatonic modes here) are grouped by the reference scale they are build upon. There are seven modes build on the major scale, seven modes build on the minor melodic scale, seven more modes from the minor harmonic scale and seven from the major harmonic scale.

The way musical modes are build is by taking the notes from the reference scale and starting from the first note for the first mode, the second note for the second mode, the third note for the third mode, etc...

Although it is indeed the way modes are build, I don't find this approach very helpful when it comes to learn them. For starters, it is a lot of computation to do in order to figure out what notes you are going to play. Say you want to improvise over an F minor seventh chord. OK, you may want to play the dorian mode on this chord. Dorian mode is the second mode of the major scales. F is the second note of E flat major. So you'll play the notes of the E flat major scale, but with F being the root (the point of attraction of the musical phrase you'll play). At this point, there is a good chance the band is playing the next chord already. But also, and more seriously, I don't feel it helps relating to how the mode sounds like, which is what we are after. With this approach, you end up thinking "notes of the E flat major scale" but the dorian mode doesn't sound at all like a major scale.

An other way to look at modes is to consider the fact that we can move from one mode to another (keeping the same root) by changing exactly one note by exactly half a tone. For example you can go from the ionian mode to the mixolydian one by making the seventh go half a tone down. Or to the lydian mode by making the fourth go half a tone up.

Here is the ionian mode starting from C:

ionian mode: c d e f g a b c

Here the mixolydian mode starting from C, you can see there is only one note that differs:

mixolydian mode: c d e f g a b flat c

Now, with the information above, and a bit of musical knowledge, you should be able to figure out the lydian mode.

So, now we have a binary relation between modes, that we'll call the neighbourhood relation. Once we have a binary relation over a set, we have a graph. Once we have a graph we have a map! A map we can explore! (Hence the name scales-explorer... Yeah, I'm very good at naming stuff...)

Here is the graph build with the modes from the major and the melodic minor scales. The arcs are oriented so that we need to make the note from the label go up half a tone when we follow the sense of the arrow. If we flip the arrow, we just go down half a tone (the graph is a bit overcrowded when we display both arcs, I'm still not completely happy with the graphical representation).

graph of modes from the major and the melodic minor scales based on the neighbourhood relation

I find this approach works quite well for me. I can now quite easily play the phrygian mode (well, maybe not that easily on F sharp if I'm being honest...), which I couldn't before practicing with this method. There is also, in my opinion, a better relation to how the modes sound like. As there is only one note that differs to go from one mode to one of its neighbours, you can practice them and focus your ear on this difference. And you build your knowledge of the modes from the intervals rather than from the notes. For example, from the ionian mode (the major scale), you'll have to make the third and the seventh go down half a tone to obtain the dorian mode. Hence, you know that the dorian mode has a minor third and a minor seventh. Which is also something you can rely on independently of the root: it is the same for C dorian, D dorian, F sharp dorian...

So I build a web service to share it, and have fun building it. The source code can be found here.

Fair warning, I don't usually do web programming.

But I wanted to manage a certain set of constraints:

  1. The web app is here to help the musician practice, not provide every little useless things I can program or think of.
  2. The web service should be small.
  3. I want to experiment with a stack I don't know.

An example of 1 is the fact that I provide, as an optional hint, the notes of the mode displayed as a music score (same thing than above for the ionian and the mixolydian modes). I provide the score for the mode starting with C as the root. But maybe the user is practicing the modes starting with F! At this point, I could say "OK, I just have to generate the 4 * 7 * 12 svg images for all the modes starting from every notes, come up with a naming convention, add a field in the HTML form to select the root note and send back the right svg files." Nothing overly complex, but kind of fun for a lazy Sunday afternoon. Sure. But part of the goal of the practice is to be able to build these modes on your instrument from every starting note, not ask a computer to send the correct svg file.

About 2, I tried to reduce the dependencies on the server side and to limit javascript on the client side. But I see that my CSS doesn't get a good grade from the smolweb validator. So I know what to improve next. I've found myself writing more javascript that I intended. In particular to improve (I hope) the ergonomics of the HTML form.

3 is basically me saying that I want to have fun and learn stuff. I've picked OCaml as the server language. This is also my working-day programming language, so something I know, hopefully. But I wanted to experiment a bit more with unikernels. So I've picked the vif framework. I plan to move, one day, not sure when, to the unikernel version. I've also decided not to use the very good ocamlgraph library and implement myself a specialised graph of musical modes. Algorithm on graphs are fun to implement. I've also, obviously, written some property based tests for the musical theory I've encoded to build and explore the graphs :-)

All in all, it was a lot of fun. I hope some fellow musicians will find this useful too. This is not the only way to practice and learn musical modes, just a way that works for me. I may think of other ways, and add them to the service.