Bitscape's Lounge

Powered by:

Adventures in Perl

Started: Saturday, February 5, 2000 19:07

Finished: Saturday, February 5, 2000 19:43

Today, I finally got around to doing something I've been meaning to do since last week. An in depth examination of the SmartPlay code. There's no better exercise for a coder's brain than to read some good raw code, complete with global variables and one letter identifiers (fortunately, the two did not coincide much in this program).

My main goal was to figure out why it would always dump a strange error message, followed by "Restarting Player", and the error message again in an infinite loop. I had narrowed it down to the stop_player function on prior occassions.

Since it was forking off another thread to call mpg123, and the problem appeared to have something to do with the communication between parent and child processes, I decided I needed to get more information at perl.com before attempting further diagnosis. While there, I ran into a really good article by Tom Christiansen which covers the basics.

Inevitably, I got sidetracked. When I saw the example program that uses a named pipe to generate a random sig each time it's read, I knew I had to modify it to stick a random quote in my .plan each time someone fingers me. I set about the minor changes, uploaded it to core, and attempted to test it. "No plan." Doh! fingerd must be testing for a regular file, not a pipe. My plan to impress the other geeks who regularly log in there was foiled.

Getting back to my original goal, I decided I was armed with enough knowledge to at least attempt some diagnosis. I determined that it was probably the initial call to mpg123 that was causing the problem, since nothing even resembling normal output was happening. Then came another one of those "Well duh!" moments.

It was hardcoded to run /usr/bin/mpg123. My mpg123 is in /usr/local/bin. How did this escape my attention before? I don't know. But I plan to make a patch which causes it to run any mpg123 in the search path, as well as check that there's a valid executable before making such a mess. Some other minor fixes I've since discovered as well.

Of course, with momentum on my side, I couldn't just put it down now. So, as it began learning my musical preferences, I proceeded to examine the rest of the code. It does what the intelligent music player I had begun work on a few months ago was trying to do, but with two key advantages.

  1. It actually has a usable interface
  2. The implementation does more than just remember what songs to match with the immediately next/previous one. It actually globs (not a reference to typeglobs) them nicely with the recent playing history, and also has user-customizable mood buttons. Very cool.

Well, needless to say, I've decided to abandon my earlier attempt (not that it's had any recent improvements anyway), and try helping out a bit with this spiffy little piece of work.