metachronistic

Mon, 26 Nov 2007

Music players, mpd vs. iTunes

Simone Dinnerstein, Goldberg Variations album cover

simone dinnerstein, goldberg variations (telarc)

At work, on my Linux box, I listen to music with the Music Player Daemon (MPD) and command-line mpc client. I have managed to build both MPD and mpc on my MacBook Pro, but I haven’t figured out how to configure MPD to play through AirTunes to my stereo. There are commercial solutions, but I don’t want to have to pay money just to listen to my music on my stereo wirelessly. DVD Jon figured out how the AirTunes encryption works, and even wrote a program that you can use at the end of a pipe to stream music to the AirPort. But I haven’t figured out how to glue the MPD audio output together with JustePort.exe so I can play music this way on my Mac.

So what’s wrong with just using iTunes? Well, it’s a snazzy program, but I can’t script it the way I want to, I can’t easily control it from the command line, and it is limited in what file types it can handle (like OGG for example: you can get a plugin that will play OGG, but you can’t burn CDs using those OGG files).

Here’s an example of why I like MPD. The Telarc label recently joined eMusic and I was pleased to discover that Simone Dinnerstein’s recent, well-reviewed interpretation of Bach’s Goldberg Variations appeared on the site. I downloaded it, and also ripped the Bach Edition version (by Pieter-Jan Belder on harpsichord) from the set of Bach CDs I’m working my way through. After listening to them all the way through several times, album by album, I decided I wanted to listen to them with the two albums interlaced so I’d hear the Belder version of a variation followed directly by the Dinnerstein version. There are 32 of them. Imagine how many mouse movements and clicks it would be to get iTunes to do this.

Here’s how I did it with MPD and mpc. It took about 30 seconds, mostly trying to figure out how to get bash to do math.

First, here’s what the playlist looked like initially. The Belder harpsichord version was first, occupying tracks 1-32 in the playlist. Dinnerstein’s 1903 Hamburg Steinway concert grand version occupies tracks 33-64. So I needed to move track 33 to position 2, track 34 to position 4 (because track 2 was now in position 3), 35 to 6. See the pattern? [Dinnerstein track] moved to [([Dinnerstein track] – 32) * 2]

$ mpc playlist
>1) Pieter-Jan Belder - Bach: Goldberg Variations - Aria
 2) Pieter-Jan Belder - Bach: Goldberg Variations - Variatio 1
 3) Pieter-Jan Belder - Bach: Goldberg Variations - Variatio 2
 4) Pieter-Jan Belder - Bach: Goldberg Variations - Variatio 3, canone all'unisono
...
 33) Simone Dinnerstein - Bach: Goldberg Variations: Aria
 34) Simone Dinnerstein - Bach: Goldberg Variations: Variation 1
 35) Simone Dinnerstein - Bach: Goldberg Variations: Variation 2
 36) Simone Dinnerstein - Bach: Goldberg Variations: Variation 3 (Canone all'Unisono)

And here’s the command to reorder the playlist. The extra dollar signs and parentheses are just bash’s way of escaping parentheses so they’ll be interpreted as an arithmetic expression.

$ for i in `seq 33 64`; do mpc move $i $(($(($i-32))*2)); done

And the playlist afterwards:

$ mpc playlist
>1) Pieter-Jan Belder - Bach: Goldberg Variations - Aria
 2) Simone Dinnerstein - Bach: Goldberg Variations: Aria
 3) Pieter-Jan Belder - Bach: Goldberg Variations - Variatio 1
 4) Simone Dinnerstein - Bach: Goldberg Variations: Variation 1
 5) Pieter-Jan Belder - Bach: Goldberg Variations - Variatio 2
 6) Simone Dinnerstein - Bach: Goldberg Variations: Variation 2
 7) Pieter-Jan Belder - Bach: Goldberg Variations - Variatio 3, canone all'unisono
 8) Simone Dinnerstein - Bach: Goldberg Variations: Variation 3 (Canone all'Unisono)
...

And then:

$ mpc play

Tags: , , , , ,
cswingle @ 16:20:57 -0800

Wed, 13 Jun 2007

eMusic Album Chooser

Glass Album Cover

Philip Glass Cover

Yesterday I found myself with 43 eMusic downloads available and my refresh date approaching quickly. I’ve got quite a few records in my queue, and choosing among them to exactly consume my available downloads is difficult to do by hand. So I wrote a program to do it.

It’s a Python script, so it’ll run any any platform. Click this link to download it: choose_albums.py

To use it, you’ll need to create a separate file that contains a list of the albums you’re interested in and the number of tracks on each album. Here’s the file I was working with yesterday, called queue:

clientele 14
rosebuds 9
okkervil river 11
stravinsky 19
saint-saens violin 3 8
mapmaker 12
of montreal 5
long blondes 14
glass #4 7
widor #5&9 9
bonnie billy 13

Each line contains an album name, a space, and the lines end with the number of tracks on the album.

To run the program, call it and pass the name of your file and the number of downloads you’ve got left:

$ ./choose_albums.py queue 43
glass #4, saint-saens violin 3, stravinsky, widor #5&9: 43

This is one (of many) ways to use up my 43 downloads. The script chooses albums randomly, so if you want to see all the possibilities, you’ll need to run it a lot. I wrote a very simple shell script to do that:

#! /bin/sh

tracks=$@

for i in `seq 1 100`; do ./choose_albums.py queue $tracks; done | sort | uniq

You can download it here: doit.sh

Depending on how large your queue is, you may need to increase the number of times it runs the script. Because it’s random and not deterministic, it can take a lot of runs to find all possible options (in fact, with 25 albums in the queue and 90 tracks available, there are more than 40,000 possible combinations, so this script is best at choosing from a small set of options, unless a random choice is what you’re after). You’ll also need to change the name of your queue file if it’s not called queue.

Here’s what I did yesterday:

$ ./doit.sh 43 | grep blonde | grep glass
bonnie billy, glass #4, long blondes, rosebuds: 43
bonnie billy, glass #4, long blondes, widor #5&9: 43
clientele, glass #4, long blondes, saint-saens violin 3: 43
glass #4, long blondes, of montreal, rosebuds, saint-saens violin 3: 43
glass #4, long blondes, of montreal, saint-saens violin 3, widor #5&9: 43

The two grep commands were included because I knew I wanted to include the new Long Blondes album and Philip Glass’s Fourth Symphony in my selections. I wound up going with the second choice, adding Bonnie “Prince” Billy’s The Letting Go and Widor’s Fifth and Ninth Symphonies.

One final note: if after 1,000 tries, the script doesn’t find a set of choices that uses up all your downloads, it’ll report the last set of albums it found and the number of tracks used up. Be sure that the final number reported matches the number you passed in or you won’t be using all your downloads for the month. The script isn’t smart enough to find the “best” solution in this situation, so if this happens, you’ll need to run it a bunch of times to maximize the number you’re downloading (or better, add more items to the queue file and run it again).

Tags: , , ,
cswingle @ 5:37:09 -0800

Back to Swingley Development
Powered by WordPress

Switch to our mobile site