Listening to Past The Pain in Reverse

In the last post, I wrote about how we can reverse a linked list of MIDI notes. Now, let’s hear it!

Thanks for reading Learning Data Structures and Algorithms with Music! Subscribe for free to receive new posts and support my work.

First, let’s start with an easy major scale of middle C. We will convert this MIDI to a linked list and then save it back and play it. We will use the music21 library for the playback.

import music21
melody = music21.converter.parseFile(’forwardmajor.mid’)
melody.show(’midi’)

Now let’s play the reversed MIDI linked list.

melody = music21.converter.parseFile(’reversemajor.mid’)
melody.show(’midi’)

Let’s get a little more complicated, shall we? I recently released a new song, Past The Pain, that you can listen to on all major streaming platforms, including Spotify. I played the first verse and chorus on my MIDI controller to convert the melody to MIDI notes.

Subscribe now

Here is what the original MIDI sounds like:

Now, to make it a linked list using the classes that I discussed in my last post, it does make it sound a little funny. My classes aren’t retaining the same time deltas between the notes as the original MIDI file. But, this is the best that I can do for now!

This is how my Past The Pain MIDI sounds as a forward linked list:

And this is how my Past The Pain MIDI sounds as a reversed linked list:

To iterate on this, I would update the time attribute in the MIDI classes to match the original MIDI file better.

Thanks for reading Learning Data Structures and Algorithms with Music! Subscribe for free to receive new posts and support my work.