I studied computer science at Brown University alongside a concentration in philosophy. After that, I worked at the CUNY Research Foundation for three years, at first as a front-end developer and later as a UX engineer. After CUNY, I’ve focused on learning more about web development from the ground up. Lately, I’ve been putting those efforts into Playtree, a web app which lets a user make Spotify song collections where playback can loop and branch.
All the while, I’ve also worked on personal game projects like Entale, an open-world RPG with a procedural language system. I also attended the Recurse Center, a programming retreat, where I experimented with computer graphics, React development, and logic programming.
In this article, I’ll explain what a playtree structure is. A basic familiarity with sequences and cycles, trees, graphs, and linked lists is assumed.
There’s no doubt you’re familiar with playlists. Let’s take an example of one on Spotify:

If you play this playlist without shuffle or loop toggled on, it will start playing “Hello.” After “Hello” finishes, “What’s Up?” will start playing. Then, “I’m Alright.” This will carry on until “See You Later, Alligator,” the last song in the playlist, finishes. After that, playback stops. We can model the playlist’s playback behavior with the following directed graph:
In this post I’ll explain shares and priority, parameters that apply to playedges. It presumes a familiarity with basic probability and the concept of mathematical limits.
We have to refer to incoming edges a lot, so I’ll use “=> playnode” as a shorthand for talking about the playedge that leads into the named playnode.

This playtree will play “One Week,” and then randomly select one of the day songs. “One Week” has seven outgoing playedges, and so, by default, each one has a 1/7 chance of being selected.
In this post, I’ll explain how limits work in Playtree.

This playtree will start at “Three Little Birds,” play one of “Blackbird,” “Free Bird,” or “Surfin’ Bird,” play “No Birds,” and then repeat forever. In case you’re not familiar with these tunes, “Free Bird” is over 9 minutes long, and “Surfin’ Bird” is best enjoyed in moderation. You might want to set a limit on how many times those songs can be selected.
Up to this point, playnodes have contained a single song. In practice, though, it would be tedious to have to make a playnode and playedges for every single song you want in a playtree. The playnodes in the Playtree app are containers for any number of songs. Because playnodes can handle collections of songs, it opens the possibility of adding whole playlists into a playnode.
Playnodes come in two types: sequencers and selectors.
You can make a shuffle playlist in Playtree with a selector:

Each song is limited to one play, and the node is set to repeat five times. This means the selector will play all five songs in a random order, just like a shuffle playlist.
But, by default, the counters that manage limiting plays during playback are global: if you go back to this playnode later, all of the songs will still be limited.