How JavaScript Made Me an Expert Melody Writer

How JavaScript Made Me an Expert Melody Writer

Written on August 9, 2024 by dean

What if I told you that the secret to writing your next great melody might lie not in your guitar or DAW, but in your code editor? As a software engineer, I discovered that the logic behind writing efficient code has a surprising connection to crafting exquisite music. And it all starts with one simple idea: Songs are just objects.

Seeing Music Through a Programmer's Lens

In programming, there’s a concept known as objects. Objects are data structures that organize information as key-value pairs, much like a dictionary where each word (key) has a definition (value). In code, these pairs are enclosed in curly braces and might look something like this:

  {
      name: "Dean",
      age: 25,
      occupation: "Software Engineer"
  }

Here are some details about me represented as an object. Name, age, and occupation are the keys and Dean, 25, and Software Engineer are the values.

Now, imagine applying this concept to music. Each song can be visualized as an object with its own set of attributes (keys) and corresponding values. Here’s how you might represent a song using this approach:

{
    song_name: "Baby",
    artist: "Justin Bieber",
    featured_artist: "Ludacris",
    tempo: 130,
    key: "Eb Major",
    chord_progression: "Eb, C-, Ab, Bb",
    time_signature: "4/4",
    melody: ??
    // There are many more key/value pairs that could be added.
    // This is just a small subset.
}

"Baby" by Justin Bieber represented as an object

Just like objects in programming, songs are built on a foundation of attributes that define their structure and character. But, just like in coding, not all attributes are created equal.

Automating the Mundane

In software development, automating repetitive tasks is key to freeing up mental bandwidth for more complex and creative challenges. For example, it’s common to write a function that capitalizes the first letter in a word:

function capitalizeFirstLetter(str: string): string {
    if (!str) return str;
    return str.charAt(0).toUpperCase() + str.slice(1);
}

// In use
const title = "hello world";
const capitalizedTitle = capitalizeFirstLetter(title);
console.log(capitalizedTitle); // Output: "Hello world"

Writing reusable code like this makes it suprisingly easy to build powerful applications that are easy to maintain.

This idea of automation can be applied to music as well. By automating low-priority tasks, we can focus more on the aspects of music that truly matter.

Prioritizing What Actually Matters in Music

James Clear, in his classic Atomic Habits, discusses a strategy he calls addition by subtraction:

The Japanese companies looked for every point of friction in the manufacturing process and eliminated it. As they subtracted wasted effort, they added customers and revenue. Similarily, when we remove the points of friction that sap our time and energy, we can achieve more with less effort (154).

This idea ties in perfectly with Pareto's Principle, which states that 20% of your inputs generate 80% of your outputs. In the context of music production, this principle highlights that some inputs matter a lot more than others. Here’s how I categorize them:

Low importance inputs

(what we can automate)

  • tempo
  • chords
  • scales
  • instruments
  • many others...

High importance inputs

(what we shouldn't automate)

  • melody
  • timing
  • dynamics
  • emotion

The Unpopular Truth About Chord Progressions

Here’s something that took me too long to realize: chord progressions, tempo, and instruments DO NOT MATTER! By this, I mean as long as you’re selecting a high-quality input (a proven chord progression, a reliable instrument, etc.), you can get away with deciding on these things before you write any music. Chord progressions, picking patterns, and rhythms can be copied, shared, and reused across countless songs without legal issues.

Melodies, however, are different. Melodies are unique (hopefully), emotional, and most importantly, they can be copyrighted. Because of this, it’s crucial to put as much of our focus on crafting a killer, original melody as we can.

Automating the Setup: Preparing the Canvas

What most people don't realize is that our brains can only handle a limited amount of information at once. Eliminating the need to think about these low-importance inputs allows us to focus on the high-importance inputs that make our music unique. Before I even touch my guitar, I’ll decide on the tempo, key, and basic chord progression. This sets the foundation for me to write banging melodies over. I even automate simple tasks like coming up with file names. I also made a guitar loop checklist that streamlines the process of making guitar loops.

Part 1 of the checklist is shown below:

Recap: The Programmer’s Approach to Music

  1. Songs/beats/loops are just objects with key-value pairs.
  2. Some of these key-value pairs are more important than others.
  3. Automate the low-priority key-value pairs by preselecting them before you write any music.
  4. Focus all your creative energy on the high-priority key-value pairs (melody, dynamics, etc.).

By embracing this approach, not only will you write insane music, but you’ll do it in a fraction of the time.

It's important to keep in mind that music should be fun! I do not write music like an assembly line everytime I make music, I just do it when I want to be fast 😅 :]]]]]]

Video

~dean