Variables and basslines

In the previous section, we created a little chiptune melody

d1 $ sometimes (|+ voice "<0.2 0.25>")
   $ s "superchip(7,8)" # n "<[f a c e] [d e f c]>" 
   # release "0.4 <0.3 0.6>" # voice "0.3 0.4 0.5"

but in order to turn this into a full track we need more, like a bassline. One cool way to build up a bassline is to take your melody and drop it an octave or two and then apply transformations until it sounds like it fits but is still distinct from the melody.

In our previous lessons, on the superpiano synth, we built our arpeggiated melody from our chords by just copying and pasting. That’s an okay solution, but we’re doing programming here. That means we can do better. Better, in this case, meaning that we’re going to use something called a variable to store the melody and using it in both places.

Variables are names given to things that we want to be able to reuse and change. In Tidal, we can declare and use a variable like this:

let melody = s "superchip(7,8)" # n "<[f a c e] [d e f c]>"

d1 $ sometimes (|+ voice "<0.2 0.25>")
   $ melody 
# release "0.4 <0.3 0.6>" # voice "0.3 0.4 0.5"

What we’ve done is take our melody part and put it in a variable. In Tidal, our variables are made by saying let nameOfVariable = thingStoredInVariable. The next step is that we can use the variable we made to make the bassline.

let melody = s "superchip(7,8)" # n "<[f a c e] [d e f c]>"

d1 $ sometimes (|+ voice "<0.2 0.25>")
   $ melody 
# release "0.4 <0.3 0.6>" # voice "0.3 0.4 0.5"

d2 $ slow 2
   $ (|- 12) 
   $ melody # release "0.6 0.8" # voice "0.2 0.4 0.3"

Here, what we’ve done is

  • Uses the melody variable
  • Pitch it down an octave with (|- 12)
  • Slow the whole pattern down so it’s more distinct from the melody

This didn’t just save us a little typing though! Imagine you’re in a live coding performance, and you want to keep the melody and bassline related to each other but you also want to keep changing them. If you had just copypasted the melody into the bassline, then you’d have to do a fair bit of work to change the melody, then change the bassline, and make sure they still match up while you’re also trying to make sure you’re planning out your other moves in the performance. This way, you can just change the melody variable and then ctrl-enter on all three of these lines.

let melody = s "superchip(<3 5 7>,8)" # n "<[f a c e] [d e f c]>"

d1 $ sometimes (|+ voice "<0.2 0.25>")
   $ melody 
# release "0.4 <0.3 0.6>" # voice "0.3 0.4 0.5"

d2 $ slow 2
   $ (|- 12) 
   $ melody # release "0.6 0.8" # voice "0.2 0.4 0.3"

Here we’re using the fact that you can put a pattern inside the euclidean rhythm, so now the melody pattern alternates between three beats in a cycle, five beats in a cycle, and seven beats in a cycle.

We could do more to make this sound good, though, and in our next section we’ll deal with transformations and modifiers to make our chip tune sound better and we’ll also add a little percussion.