Cangen Cangen

Cangen

Cangen was actually my first coding project, all the way back in 2023. I had been exploring canonic sequences by hand with a pen and paper, and compiling all the results was becoming repetitive and begged for automation. Eventually I bit the bullet and learned a bit of C, and then JavaScript, and cangen was the result!

A melodic sequence is formed when melodic material is repeated, transposed to a new scale degree. A canon is a kind of strict imitation, where one voice enters after another with the same melodic material—possibly transposed or otherwised transformed in some way—while the original voice continues in counterpoint with it. A canonic sequence is a melodic sequence that is also imitated canonically. These patterns form an important kind of resource, ubiquitous in tonal music, and I was studying a specific subclass involving two-note melodic models, as they are the simplest sequences possible and can be easily exhaustively generated, studied and manipulated.

This app is essentially a constraint satisfaction algorithm powered by a few nested for loops. First, it generates the set of all “valid” two-note melodic models based on some constraints related to ease of singing, with models that fail to meet any constraints being skipped. Then, for each melodic model, every possible vertical placement of an imitating second “copy” is tried, and those that fail to meet certain constraints are again skipped.

Finally, a collection of functions that query properties of patterns algebraically are used to filter the patterns via user-specified parameters.


← Back to projects