Log In  

Cart #playerpiano-4 | 2022-12-16 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

On this day 154 years ago, Scott Joplin was born. Happy birthday to the King of Ragtime!

Here's a rendition of his famous Maple Leaf Rag, with accompanying animation.

I've been trying to learn this piece on piano for a while. At some point I thought it might be fun to try transcribing it in PICO-8, and this is the result! Information on the music and animation is below:


I tried to stay as true to the score as possible - since I was limited to only 4 channels, I had to make creative use of instruments and effects. So even though it's all just piano, there are 5 different instruments used:

  • normal held note
  • held note that's one octave down (for the low note at the start of the run that goes all the way up the piano)
  • held note with simultaneous octave down (using detune)
  • staccato note
  • staccato note with simultaneous octave down (using detune)

Since this piece makes heavy use of octaves in the bass and the accented parts of the melody, the detune trick was a huge help in getting all of the notes in (there are a lot of notes!). The detune emphasizes the lower note over the higher one, but I think it sounds convincing enough. Even with this trick, there were a handful of places I had to leave a note out of a chord, but I tried to leave out notes which were the least important/noticeable (eg. repeated nearby in either the bass or melody, or notes less important to the character of a chord, like prioritizing the 3rd/7th over the 5th). I think unless you know this piece really well and closely watch the animation, it would be pretty hard to notice the missing notes.

There weren't quite enough sfx slots to fit the last section of the piece, so I ended up arranging that in a separate cart and then putting it into the map data using CSTORE(). Partway through playback, I swap out some sfx that are no longer needed for the ones used in the last section.


The animation is all dynamic, based on the SFX data. Which is nice, because once I got it working I could change the sfx or add new parts and the animation would continue to reflect the music.

As for how it works, I wrote a function GETNOTES() which takes as parameters a time offset and returns a list of the notes that would be playing. I'm using STAT(54) to get the index of the currently playing pattern, and STAT(56) to get the current tick within it. With that information, I can add the time offset and use PEEK() to determine which pattern/sounds would be playing at the requested time and get the note information. By checking the pitch along with which instrument voice is playing a given note, I can figure out which keys should be pressed. For the detune notes that means playing two keys at once an octave apart. For staccato notes or notes with the fade out effect the key lets off earlier in the beat.

For the animation of the actual keys, I call GETNOTES() without a time offset to get the currently playing notes. Each of the keys is rendered with a sprite, and we can look up whether the key's note is being played to determine whether we should draw its pressed or unpressed sprite.

For the piano roll, I call GETNOTES() with a different time offset for each line, and for all the notes returned I use PSET() to change the colour at the coresponding spot on the roll (adjusting for perspective and scaling so the 88 notes of the piano span 44 horizontal pixels). Since it's all offset based on what's currently playing, doing this every frame naturally makes the dots scroll down the screen as if the roll is moving.

Other thoughts

If you'd like to see how it works in more detail, the code is reasonable well-commented so take a peek inside :) You could probably use a similar approach to automatically synchronize things in a rhythm game.

I also think it would be cool to transcribe more pieces of piano music and make this into a series -- you could even fit multiple songs in a single cart by using PX9 compression or similar, since the current code doesn't use very many tokens/characters. But it took me quite a while to transcribe just this one piece, and styles with more sustained notes / big chords wouldn't work well with PICO-8's limitations, so I'll leave it at this for now.

P#121275 2022-11-24 16:05 ( Edited 2022-12-16 17:19)

gold star and place in "featured" page!

P#121334 2022-11-24 17:29

this is nutty!

P#121339 2022-11-24 18:30

Neat! I haven't seen something quite like it on pico 8 before. As dw817 would say, "gold star."

P#121340 2022-11-24 18:53

That's so good! Thank you for this gift - I love Scott Joplin and your player piano animation is amazing.

P#121341 2022-11-24 18:56

:O amazing. i've tried other music and it works great then too! appreciate the trasnferability :)

P#121342 2022-11-24 19:14 ( Edited 2022-11-26 02:46)

Really amazing 👌⭐
also I had China Miner flashbacks (a 1984 platformer for C64)

P#121343 2022-11-24 19:16


P#121344 2022-11-24 19:33

This is really great thanks for sharing.

P#121345 2022-11-24 19:40

What a lovely cart! Thank you for sharing how you made it too.

P#121352 2022-11-24 22:13

Unbe-freaking-lievable ! Wow, this is so epic on so many levels, @ericb !

At first I thought it was just random animation but no if you watch carefully both the roller and keyboard animate in complete precision with the melody that is played.

So nice ! Needs to be considered one of the top demos to demonstrate Pico-8 and its ability.

Gold star to hang on your piano !

P#121357 2022-11-25 00:49

This is phenomenal. Congrats on making it to the featured list!!

P#121363 2022-11-25 01:40

This is next-level great! I love Scott Joplin as well, used a (much worse) rendition of "The Entertainer" as the opening music for my last game. The photo, the animation matching the playing, the sepia-toned old-timey color palette . . . the whole thing just brings a huge smile to my face.

P#121383 2022-11-25 12:18

What an amazing tribute. I'm constantly blown away by the creativity of the PICO-8 community. I'm a massive Scott Joplin fan, and this brought tears to my eyes. Bravo @ericb!

P#121440 2022-11-26 23:30

This is simply wonderful! 🤩👌
Genius implementation to have the piano "play" real notes 👏

P#121475 2022-11-27 13:17

Wow. It sounds amazing, and the animation is mind-blowing!

P#121679 2022-12-01 17:38

Wow, I love it! The animation is very satisfying.

P#121905 2022-12-06 12:28

Update: fixed a few errant notes (am not the best at reading music). If anybody spots any others let me know

P#122563 2022-12-16 17:21

Really loved watching this play through and the history + development recap was a joy to read. Thank you :)

P#124381 2023-01-16 07:53

I know this is somewhat irrelevant but I can’t seem to get music to play in my carts. I put the notes in the pattern and put only music(0-1) as the code. What am I doing wrong? Am I missing something?

P#128597 2023-04-15 22:07


P#129330 2023-05-03 03:13

Amazing! Well done :)

P#134182 2023-09-11 17:20

When I first met Pico-8 almost a year ago, I was looking for "Best carts" and this one was on the main page. When I loaded it and... played I was like "WTF was that? It's not even a game! Why would one do it and why is it in featured?"
Well, 2 things happened since then.

  1. I am learning piano and by far Joplin's Entertainer is one of my favorites (weirdly).
  2. I (try to) make games on Pico-8.

And now, my friend, I think that what you did here is freaking amazing and it's simply one of the best things that was done on Pico-8!
Thank you!

P#137042 2023-11-06 21:52 ( Edited 2023-11-06 21:52)

nice work using the secret pallet 👍

P#137240 2023-11-10 17:21

[Please log in to post a comment]