The View from the Corner

Troy H. Cheek

"Revising My First GFA BASIC Program" by Troy H. Cheek on Nov 24, 2008

Last week, I wrote my first GFA BASIC program. Well, not really. I've written any number of GFA programs on the Atari ST in the past. This was just my first in GFA BASIC 32 for Windows. Well, not really. This was just my first that actually tried to do anything useful.

The purpose of this program, which I titled "playlist generator" or the like, was to rifle through my entirely too large and entirely too disorganized music collection, pick out a selection, and copy it to whatever USB flash drive I was planning to play music from later that day. Of course, I couldn't just grab any old music file to copy. If I just grabbed the first files that came along, I'd be listening to the same ones over and over. If I just kept track of which ones I'd already listened to, I'd be listening to them in the same order over and over. I'd also probably get them fed to me a whole album at a time, or in order chronologically by when I last copied them to a new folder, or something else undesirable like that.

Copying them in a random order was right out. Random just isn't random enough.

The human mind has a spectacular capacity to notice patterns. The human mind can notice patterns where none were intended. The human mind has been known to notice patterns where none even exist. The human mind can certainly hear a song and think "didn't I just hear another song from that same album/artist/genre just a couple of songs ago?" The human mind might even be right.

Just because the human mind sees a pattern does not mean that the outcome was not random. Most card games hinge around the fact that you're going to deal a player a certain combination of cards which will score higher than another player's hand. Dice games depend on getting particular combinations of throws. The fact that the outcome matched a certain pattern in no way automatically means that it was arrived at through a less than 100% random process.

On the other hand, try convincing anyone who's noticed three 60s protest songs in a row during shuffle play that his portable music player doesn't love 60s protest songs. Try convincing anyone who's just realized that he's listened to random selections all day long and have not heard a single song from that new album he just loaded that his portable music player isn't ignoring it.

In other words, when you ask for random play, you don't really want random. You want something carefully picked and sorted and weighted so as to appear to be random. This is the exact opposite of random. And this is what I had to program.

(I'd like to pause here to give a shout out to Dan Goodin and his article My IPod for a Random Playlist which helped me figure out what the problem was.)

So, how could I "randomly" create a playlist that didn't repeat songs from the same album or artist or whatever within the last ten songs or so, but not simply play a single song from each album in turn. I decided to keep track of what had already been copied in kind of a rotating buffer.

As I mentioned before, my new program was scanning my harddrive for all my music files and sorting them by date. Not just any day, mind you. This was the date that my program had last used them in a playlist. All by itself, this would keep me from hearing the same songs today that I had just heard yesterday. Unfortunately, it wouldn't keep me from hearing two songs from the same band in a row.

Each music file has a name and location something like C:\my music collection\genre\artist\album\songname.ext. I wish. In real life, my organizational skills are nowhere up to that challenge. Still, it's a good start. My program breaks down the location of the file (for computer geeks, this is the path) into its component parts, being just smart enough to ignore the drive letter and base folder common to all the files. In the end, I have a short list composed of the genre, artist, album, and song, not necessarily in that order. It is not necessarily in that order because, like a said before, my organizational skills are teh suk.

This short list goes into a rotating buffer. When I look at each music file, I see if any of the items from its particular short list of attributes appears anywhere in the buffer. If it does, I look for another file. If it doesn't, I copy the file and add its information to the buffer. When the buffer fills up, I throw away a few of the older attributes.

It's not a perfect system. My music files are in no way named or located logically. Songs or bands or albums with similar names but which are nowhere near each other in content get pushed apart as readily as the first two songs from the same album. But it seems to be working well enough.

Now, some of you might wonder why I'm going by my directory structure (how I've organized my collection) instead of, say, the identifying information in the music files themselves. MP3 files, for example, often include the name of the song, artist, album, track number, and year of release. Why not use that information, since my organizational skills are so bad?

It is true that MP3 files use ID3 tags which contain a lot of information. The problem is that ID3 tags are optional. Furthermore, ID3 varies. An ID3 tag can consist of a ID3v1 127 byte TAG at the end of the file, an enhanced ID3v1 which consists of a 227 byte TAG+ just before the TAG, a variable length ID3v2 packet at the start of the file, a variable length ID3v2.4 packet at the end of the file, or a variable length ID3v2.4 packet just before the ID3v1 TAG, just before the ID3v1 TAG+, or anywhere else in the file.

I did throw together a little test program to see if I could read ID3 tags. It crashed. A lot. I begin to understand why my truck stereo, which plays MP3 files and displays ID3 tags, sometimes displays garbage or no ID3 tag at all. After just a few minutes with my collection, I discovered the following anamolies:

And that's just the MP3 files. Let's not even get into the other types of music files in my collection.

For now, I'm sticking with the path as the deciding factor. I can drag a folder of misplaced albums to another location a lot easier than I can edit a few dozen ID3 tags. I think it does a pretty good job as it is. People riding in my truck with me are no longer complaining about the weird patterns in the playlist.

Now they're complaining about the complete lack of pattern in the playlist.

This page last updated on Nov 24, 2008 by Troy H. Cheek
 Send feedback to 
Copyright (c)2009 by Troy H. Cheek 

Cheek.Org

The View from the Corner

Select your archive:


Web
Cheek.Org