A web application that automatically writes music! This web app generates melodies based on a given chord progression. It can then play back those generated melodies to users. One can also download the melody (and accompaniment) as a MIDI file, for future playback or tinkering.
This can be a useful tool for exploring different ways to move through a chord progression. Or for brainstorming when writing a musical composition.
|LIBRARIES & FRAMEWORKS USED||React and Browserify for bundling the HTML/JS. Mocha for unit testing. ESDoc for generating documentation. Stylus for CSS processing.|
I’ve always wanted to write software that creates music. It’s one of the reasons I liked studying music theory. And I needed an excuse to learn how to use React and some other JS tools. I’ve played with some JS libraries out there that can handle music theory, playback, and notation. So it wasn’t too ambitious of me to mix all of these skills together and take the first step to making an automatic music composer.
Thankfully, I was at a point where I could do something with my coding skills and music theory knowledge. Music theory can be seen as a set of design patterns or best practices followed by musicians and composers for the last few centuries. As those musicians kept encountering musical problems, they developed techniques to solve them, and passed those techniques down to their apprentices.
The way I saw it, I could embed those musical rules into a piece of software, and it should produce sounds that weren’t too horrible. For this version of the AutoComposer, I modelled the following musical concepts in code:
Musical chords are commonly defined as a set of notes* being played together. There are many types of chords out there, and each one specifies the notes that musicians will choose in order to play a chord. For example, G major consists of the notes G, B, and D. There are other principles which determine the exact order and range to be played. But generally, when a musician wants to play a G major chord, the audience will hear the notes G, B, and D.
In most musical situations, melodies are rarely played on their own. Even when an instrument takes a solo, the band continues playing. Now, as a melody rises and falls in pitch, the exact notes in the melody usually harmonize with the chord that’s currently being played by the band. So if the band is playing G major chord and our melody is playing a G, B, or D, those two sides are in harmony.
The easiest way to create a smooth melody that sounds good when played with chords is to simply choose from the chord tones of each chord. For the initial stage of melody generation, the AutoComposer simply chooses which chord tones are available for each chord, and connects them together. Then it filters them out by a few criteria.