Livecoding: Piano Scales


"Piano Scales" is a new experiment in algorithmic composition, demonstrating the captivating simplicity of piano-based systems. The piece generates musical patterns from time-triggered, overlapping piano scales, using a simple but effective technique: a cosine function (cosr) dictates the variable time interval between notes. This variable timing removes the rigid "computer-like" feel, injecting a subtle, intriguing touch of suspense.

Repeated Scales with a Touch of Randomness

The gist of this musical algorithm is amazingly simple.

Pick a scale. You play it using a variable time interval between its notes, which is determined by a cosine function (cosr). The variable interval gives the final result a touch of suspense and makes it less computer-like.

(define xsc
    (lambda (beat vel scale)
        (let ((dur (cosratio 4 2 1/128)))

After each note, more notes are played programmatically, after brief (random) intervals of half a beat, or 3/2 of a beat. Fifths, octaves, minor sevenths... as you please.

This whole thing repeats itself. At each iteration of the loop, though, the sound volume gets quieter by a fixed amount. Eventually, when the volume goes to 0, the repetition stops.

(define xsc
  (lambda (beat vel scale)
    (let ((dur (cosratio 4 2 1/128)))

      ;; piano
      (play (car scale) vel dur 1)
      (play 5 (+ 12 (car scale)) 1 (* dur 2) 1)
      (play (oneof 3/2 2) (+ 24 (car scale)) 1 (* dur 2) 1)

      ;; bass
      (play 5 (car scale) 90 (* dur 2) 2)
      (:chance .8 (play 6 (+ (car scale) 2) 90 (* dur 2) 2))

      ;; repeat
      (set! scale (rotate scale -1))
      (set! vel (- vel 1))

      (if (> vel 0)
        (callback (*metro* (+ beat (* 1/2 dur))) 'xsc
          (+ beat dur)
          vel
          scale)))))


;; set scale to play so that scales overlap with each other

(xsc (*metro* 'get-beat 1)
  50 ; volume
  (:mkscale c1 'pentatonic 2))
  ;; run again with 'ionian, 'aeolian etc. for interesting harmonic effects

The full source code is available on GitHub.

About Extempore and Algorithmic Composition

Extempore is a programming language and runtime environment designed by Andrew Sorensen to support livecoding and cyberphysical programming, where a human programmer operates as an active agent in the world.

Algorithmic composition is the technique of using algorithms to create music.

The Beauty of Generative Music

What makes algorithmic composition particularly interesting is the element of surprise. Each time the code runs, the interaction between the deterministic elements (the scale structure) and the random elements (the variable timing) creates something slightly different. This mirrors the natural variation we find in human musical performance, where no two performances are ever exactly the same.

By layering multiple instances of the same algorithm with different parameters (different scales, different starting notes), complex harmonic textures emerge from simple rules, creating an evolving soundscape that rewards extended listening.

Cite this blog post:


Michele Pasin. Livecoding: Piano Scales. Blog post on www.michelepasin.org. Published on Nov. 2, 2020.

Comments via Github:


See also: