I’ve tried to procedurally generate music from scratch a few times in other languages over the years, but since this is a “couch project” I spent a couple minutes searching for NPM libraries and settled on ScribbleTune.
ScribbleTune provides an elegant API for declaratively generating midi, I’m only scratching the surface of the capabilities in this video. I basically just run through the examples to see how they work, and ended up sticking with the chord/rhythm generation and tweaking it.
Initially, I thought I would create a website to play the file but once I opened a file in Garage Band I realized that I might actually use this thing. Throughout this video you’ll hear me playing around a bit with the file, changing instruments, editing the file, etc
Next, I used Tracery that I had seen in a GDC talk, and have been dying to try out. I hadn’t worked with it before, but in short it allows you to declaratively define a grammar, which will recursively fill in any tokens you setup. It’s really elegant and easy to use, people use it for all sorts of things: Twitter bots, images, game content, etc
Side note, if you’ve got an open-source library and you actually want people to use it. Examples, examples, examples
After I got my libraries working I just need to clean-up the data a little bit so the music I’m generating doesn’t sound so terrible. I don’t know a lot about music theory, so I just divided the chords in the Am/C scale (aka the white notes on the piano) into sad, happy, and sassy. Then I ask for a random chord.
I also created a second grammar for rhythm so things don’t sound so same-y.
Where do we go from here?
- Create more grammars, things like verse, chorus, bridge
- Experiment with more complex rhythm
- Generate melodies and drum parts
- Hook up a web player and make a little app to practice your favorite
- Source on Github
- Watch the video on Youtube
- Download a sample!