Tuesday, January 30, 2018

A Little Language for Music Composition | A Programmer's Approach to Song Construction

I was surprised by how successful I was at creating small animations, known as Poetic Computations and wanted to try the same thing with audio. Fortunately, much of the heavy lifting has already been done by the Web Audio API. The fact that I know nothing about music composition hardly seemed like a reason not to give this a try.

In the case of animations, my platform only allows for the creation of line segments. By scaling, rotating, translating and copying these segments interesting animations can be constructed without a lot of effort. Could the same be true with music? Here are the primitives I developed to find out:

Sound - a sound consists of a frequency, duration and volume (gain).

Stack - a collection of items (sounds, stacks or scores) that are all played at the same time. I think this may be similar in concept to a chord.

Score - a collection of items (sounds, stacks or scores) that are played sequentially.

By now, those familiar with music theory are surely shaking their heads. But from a coding perspective, there's a nice symmetry to working with the above.

I was pleased at how quickly the code came together. And I do love the compositional nature of the system. But man, is making music hard! In fairness, I've got about 20 minutes of experimentation under my belt. I currently have the same set of skills a toddler has when he bangs on your piano.

My hope is that with a little research I'll get a better sense of what patterns lead to a more pleasant sound and then my career as amateur musical composer will be truly off and running.

In the mean time, feel free to grab my code and make suggestions as to what I should do to improve the system.