Using ChatGPT for Algorithmic Music Composition

Written by on October 13, 2024 in Music, OpenAI with 0 Comments

Algorithmic music composition is one of my favourite areas. And in terms of tools, as several of my past articles show, OpusModus software is the main choice. 

Recently I have been spending some time checking if ChatGPT could be cajoled into writing some good OpusModus code. But the experience has not been very positive; the code won’t even compile in OpusModus most of the time, forget generating music (there is a separate OpusModus GPT, which I haven’t explored)!

That is when I decided to take a look at SonicPi, another interesting tool for algorithmic music composition. Just as OpusModus uses Common Lisp programming language, SonicPi uses Ruby. Fortunately, ChatGPT seems to be more capable in terms of SonicPi since most of the code compiles without any issue.

In this article, I would like to share some simple compositions I have managed to generate using ChatGPT (I use GPT-4o). Let us start with “Twinkle Twinkle Little Star”.

Here is the code (partial) that ChatGPT generated:

SonicPi Code for Twinkle Twinkle Lite Star

SonicPi Code for Twinkle Twinkle Little Star

I pasted the code in SonicPi and played it. Here is how it sounds.

Simple, but nice!

Next, I wanted to create something different. Here is the prompt I gave ChatGPT:

“This is an exercise to create background music. Two people are walking inside a haunted forest. You have to create an eerie ambience, that lasts around 45 seconds. Use proper instruments to create this background score.”

Here is the code it generated:

Code for Eerie Music

Code for Eerie Music

You can listen to the composition here.

Lastly, I wanted to create something quirky! Here is my prompt to ChatGPT:

“What would it be like if we mix the styles of Ilayaraja, MS Viswanathan, AR Rahman, and Anirudh? Can you generate a quirky composition with interesting instruments? This should last 2 minutes approx.”

Here is the code:

Quirky Mix

Quirky Mix

The music is really quirky! Listen.

Overall, it was a pleasant experience. I hope to generate music with multi-channel MIDI outputs and connect them to a DAW such as Ableton Live so that we can get richer sound and effects. More on that in a future article!

Download the Ruby code for SonicPi here.

Have a great weekend!

Tags: , ,

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *

Top