How to write music with code

Live coding topic

That includes impromptu musical performances with code.

Sonic Pi for writing music with code

Try out Sonic Pi - a Ruby-based programming language that plays notes and music based on the code you write.


    Sonic Pi is a code-based music creation and performance tool.

It can be used for a live performance, as it constantly loops and responds to the changes you make.

Download for Window, macOS or Raspberry Pi.


This is relies on the JACK, covered below.

JACK - Jack Audio Connection Kit

A tool for mixing sound and recordings.

It can be installed on Ubuntu as:

sudo apt-get install jackd

There are plenty of resources listed here including live programming:

Music composed by computers


I found this tool which provides AI-generated music based on human-made samples. Their mobile app is great. I just found the genres too limiting based on my tastes but there are plenty to choose from.

Here is their API page.

TEDx talk - The world’s ugliest music

Watch this TEDxMIA talk on YouTube:

A song was composed by an algorithm which made sure there are no repeats or patterns in time between the notes or in pitch changes. It’s not just random - its deliberately pattern free.

The result is music which is ugly to us. As we look for a pattern but there is none. It reminds me of some jazz music I’ve heard, but this is way worse.

A pianist performs the piece at the end.