Geek Seeks iPod Song-Shuffling Nirvana

[Note: out of whack with normal Pun Salad content. Feel free to skip, unless you're interested in the kind of mental aberration that causes people to algorithmize everyday issues.]

Ever since I've had one kind of iPod or another, I've been trying to come up with a good algorithm to govern its music selection. Herewith a description of my latest scheme. It assumes some easily-acquired familiarity with iTunes/iPod operations.

Guiding principles and relevant facts:

  • I prefer a random shuffle of songs. Apple has a "genius" feature that, among other things, will create an "aesthetically coherent" playlist of songs (they say) "will sound great together". I don't care about that.

    In fact, I actively don't want that. I kind of like hearing a sweet Linda Ronstadt tear-jerker immediately followed by an ass-kicker from The Who.

    So shoot me. (Also: yes, I'm old.) But this preference makes things easier.

  • But! I do want to hear certain songs more often than others. For whatever reason. I may simply love the song (e.g., "Bernadette" by the Four Tops) and could listen to it every day for the rest of my life. Or it might be new and fresh, just downloaded/purchased.

    Conversely, I might prefer to hear certain songs less often than others, because they are older or less-loved.

    This preference makes things more difficult.

  • My iTunes song collection is much larger (about 40 GB) than the space available for songs on my primary iPod (an older Nano, about 7.22 GB). So I need to cycle a subset of iTunes library songs onto the iPod when it syncs. It would be nice if songs that have been recently played were replaced with songs not-so-recently played; that way, everything gets heard eventually. [See update below.]

The iPod/iTunes system has a simple way of representing song preference: the rating, which can be 1-5 stars. (Songs can also be unrated.) So let's say I rate all the songs in my library (and, going forward, remember to rate any new incoming songs).

This reduces the problem to: how do I insure higher-rated songs get played more frequently, while still keeping things simple?

Initial vague answer: keep more of my high-rated songs on the iPod than low-rated songs. A simple song shuffle will play the high-rated songs more often, simply because there are more of them.

Duh, right?

To firm this up, let's do some simple math. Let pn be the probability of playing a song with an n-star rating. So we have:

p5 + p4 + p3 + p2 + p1 = 1

And the "play higher-rated songs more frequently" implies that:

p5 > p4 > p3 > p2 > p1

The values I'm using are

( p5, p4, p3, p2, p1 ) = ( 13, 415, 15, 215, 115 )

Those numbers are arbitrary and could change (within the above constraints), but (modulo randomness) they say: out of a shuffle of 15 songs, it's expected 5 songs will be 5-star, 4 will be 4-star, 3 will be 3-star, 2 will be 2-star, and 1 will be 1-star. (This seems to work for me in practice.)

[Aside, added a couple of days later: it's an arithmetic progression, where each rating-star increases the play probability by a fixed amount. One could also imagine a geometric progression, where the play probability gets increased by a fixed factor. For example, if we wanted each rating star to double the play probability, we'd have:

( p5, p4, p3, p2, p1 ) = ( 1631, 831, 431, 231, 131 )

Nothing magic about that either. It's all about what produces a mix that "sounds right" to you. End of aside. On with the show:]

How do we make that happen? Surprisingly easy!

I created 5 smart playlists: "Nano1", "Nano2", …, "Nano5", one for each rating. The math described above enters when we define each list:

Suppose we want to store a total of N songs on the iPod. (For my Nano, a conservative choice for N is 900.) Simply populate each playlist with songs having the corresponding n-star Rating, but limit it to N * pn items.

Consider "Nano3": the p3 probability is 15, so the playlist should be limited to

900 * 15 = 180 items.

And that translates into the smart playlist definition:

smart playlist nano3

The "least recently played" criterion is not that important (at least not to me), but it insures that the songs in the library will get sync'ed out to the iPod sooner than they might if we were to rely on a random selection. [Oops. See update below.]

To keep things uncluttered, I put these five playlists into a Playlist Folder named "Nano".

And finally (finally!), I plugged in my Nano, and specified that it should sync from the aforementioned "Nano" folder. Looks like this: NanoSync spec

All done!

Going forward: if I happen to notice that a certain song isn't getting played enough, or getting played too often, it's easy to raise/lower its rating to increase/decrease the probability it will get played. And if I decide I don't want my iPod to play a song ever again, I can de-rate it (or more drastically, delete it.)

I'm not sure whether I should be admired or pitied, but I'm happy with the setup, and maybe someone out there with the same geeky compulsion will find inspiration here.

PS: this was inspired by Jamie Zawinski's (apparently failing) efforts to come up with an iTunes playlist solution to match his desires. Fortunately, my desires were far less complex than his. And I recognized I could satisfy them even with iTunes doing (as Jamie puts it) "the stupidest possible thing."

Update 2014-08-14: I noticed a couple things:

  • I was implicitly assuming that the "least recently played" criterion would select randomly from any songs that had never been played. Instead, it seemed to pick songs from artists that were alphabetically last in the library.

    I had a lot of songs that had never been played, because I'd recently done a mass-rip of my CD collection. So I noticed my iPod playing a lot of Who, Van Morrison, T-Bone Walker, and Talking Heads, but no Beatles, Beach Boys, Band, Billy Joel, …. Kind of a fail.

  • So I switched from "least recently played" to "random" on my playlists. And ran into another minor gotcha. iTunes will generate a random smart playlist once when you specify its criteria. The playlist is not regenerated when you use it to sync your iPod. So you don't get any new songs swapped in.

    That's not a huge deal. You just need to re-randomize the playlist: display it, select-all, and press Delete. The songs are removed, and a fresh set are generated.

  • OR you can add a new date-based criteria to the playlist rule. For example:

    new smart playlist nano3

    This will select randomly, but the date criterion will force it to automatically update the playlist when a device syncs (which updates the last-played information).

    I think so anyway. We'll see.

Last Modified 2014-08-14 10:20 AM EDT