Marathon Devlog 3: Various Improvements

Github link

Marathon has been on the back of my mind ever since I started messing around with it. I still remember it not being 100 lines long and still be able to make microrhythms in MIDI. It was a bit crude, and simplistic, but it worked! I was so excited to solve an issue that bothered me, a musical cul-de-sac, with my flimsy programming skills. Since then, the little code grew bigger as I added presets (like a pre-made “swing” option, and similar choices for gnawa and samba rhythms) and functionalities (like the text command option, which I love!)

On Dots…

Thanks to a friend, Github user Sacules, who tidied up my messy code, I learned a thing or two there. Today, I’ve removed some redundancy within the code, making it more efficient. But that’s not the biggest improvement since I last wrote. There was always a thing bugging me about the way Marathon treated dotted notes. At first I made it look at the length of a command (say q. for a dotted quarter note), and look up if the last character was a dot. I’m sure you can already see the breaking point here, but at first it worked fine because there was nothing after the dots. However, as I added functionality to the text command option, I eventually added tuplets to go at the end of the note string, and then again rest notes, to bring silence into the whole thing.

Yesterday, I finally was able to sit down and overhaul the dotted note calculator, and I stumbled on something pretty awesome! Dots in music work by adding half the value of the note it’s attached to. If a second dot is added, then it will add half the value of the first dot to the note. With these two rules, you have the basis of a mathematical formula. A quarter note will be 1 beat, a dotted quarter note will be 1 + \(\frac{1}{2}\), a double-dotted one: 1 + \(\frac{1}{2}\) + \(\frac{1}{6}\), and so on. You see the denominator increasing in a peculiar fashion—it’s not quite exponential, not quite Fibonacciesque… It’s in fact a quadratic equation:

$$𝑆_𝑛 = 2(𝑛^2 − 𝑛 + 1)$$

Where \(n\) is the number of dots, and \(S\) is the value of the denominator. At one dot, it’s 2, two dots: 6, three dots: 14, and so on. It’s a rare occurrence to behold a triple-dotted note in music. A triple-dotted quarter note would be equal to fifteen 32nd notes, what use has this? In any case, with the quadratic equation, Marathon now accepts any number of dots you throw at it after a note value. Now, however, the issue comes down to resolution.

MIDI works with “ticks”, which are very small units of time. The highest resolution is 960 ticks per beat, which I use for Marathon. This resolution will stay the same whatever the tempo is, so that there will always be 960 ticks between two quarter notes, whether the tempo is at 60 or 360 beats per minute. For most practical purposes, this is a really high resolution for rhythm, even for my microrhythm program it’s more than enough, but when you take into account the need of rounding down numbers, there’s a problem.

MIDI doesn’t accept decimal points in its tick values. You can’t have 1.7 tick. One tick is like a pixel, indivisible, atomic in the etymological sense of the term. So, for example, when you throw in a value of 1.7, the program will only keep 1, and disregard the rest. So, that means that when the value of the dot falls below 1 tick, it becomes nil, and every additional dots beyond that point will be worth nothing either. Theoretically, the value of a note with an infinity of dots will be twice its undotted length. Within the program, though, the accuracy of this depends on the length of the note being dotted. For a quarter note, the value of the tenth dot will be 0, and the value of the dotted note will have risen from 960 to 1,916: four ticks short of its theoretical limit of 1,920 ticks (not bad, actually!) If you dot a 32nd note, the sixth dot will be void, but if you dot a whole note, you can go up to eleven significant dots. Despite its flaws, I doubt any other musical system allows for as many dots as this!

On Shorthand and Rests

Another improvement to Marathon’s text command was the implementation of shorthand writing. For example, instead of having to write out every note of a repeated pattern, like, for example, sixteen “s”‘s, you can now write it in parentheses with the number of desired repetitions preceding it: 16(s). It’s meant to be for a single note, so things like 4(q e 2(q)) might not work properly, or at all. Nevertheless, it’s a useful shortcut for writing repeated notes.

Just as with dots, something bugged me terribly with my implementation of rests. I didn’t fully understand the subtleties of MIDI programming (and still don’t), so I decided to make the program play a note, but very low and with 0 velocity (velocity is the power with which the note is played, it’s loudness if you will). This had the advantage of being easy to conceptualize for me, but had drawbacks, such as adding short “ghost notes” where the rest started, and I’m still not entirely sure why that happened at all, but it doesn’t matter anymore. Indeed, I’ve changed perspective and now rest notes are actual silences separating two notes. It turns out that it was quite easy, but I couldn’t see the obvious solution at first. So, now, when you write a silence (an r at the end of the string denoting the note, example: 2(q.3/2r)), it’s a real silence! It’s not much, but I’m proud of this.

What’s next?

Next up, I want to start tackling the issue of making the program act as a standalone. One of the biggest issues with the program right now is the difficulty of actually making it run properly. Most musicians I know never approached programming, and never even used a Command Prompt or Terminal window. I myself never did so just one year ago, so I recall the daunting feeling of powerlessness before the strange and scary world of programming and computer commands. So, one of my biggest aims is to pave the way for using the program. I’m not entirely sure how to approach this myself, as I’ve never done that, so hints are welcome! At first, a simple executable command window would already be a big improvement—a file that, when clicked on, makes sure you have the right modules to use it, and runs itself in an independent window—but, ultimately, I would like to be able to make it a true(ish) program, or application, with a graphical user interface at least!

Wish me luck, and keep playing with Marathon for some sick microrhythmic action!

On March 11 2019, this entry was posted.