Wednesday, December 12, 2012

Updating Your iTunes Library with BPM Data

Last time, I mentioned that MixMeister BPM Analyzer does a great job of crawling through your music files and deriving the Beats Per Minute (BPM) for each track. However, running iTunes afterward and displaying the Beats Per Minute column, or setting up a smart playlist that uses the BPM attribute, I found that the BPM data had not fully made its way into the iTunes database. If you select a track, choose "Get Info", and go to the Info tab, you'll see that the BPM value suddenly flashes into place, as if iTunes is reloading the track metadata (title, artist, genre, etc.) on demand.

I like smart playlists, and was hoping to use them to help come up with a good 90 BPM playlist for running, so I need to get iTunes to know about all those individual track tempos, but with thousands of tracks the idea of clicking on each one to get it to load is a nonstarter.

Solution #1


 Lifehacker has this helpful receipe, which I'll rewrite in a little more detail here:

  • Open iTunes
  • Select Music library
  • Make sure BPM is one of the columns displayed. If not, right-click on one of the other columns, and check "Beats per Minute"
  • Click on the BPM column to sort it, so all of the tracks that don't have BPM info are all at the beginning
  • Select all tracks showing blank BPM (or a subset if you have a lot of tracks and want to do this in batches)
  • Right-click on the selection and click "Get Info"
  • On the Multiple Item Information screen, click OK without modifying anything
  • If there are a lot of tracks, a progress bar should come up. The total time it takes to update everything will depend on how many tracks are involved and the speed of your hard drive, but shouldn't be more than a minute or two in most cases.
  • Close and reopen iTunes to refresh the music list
Only one problem: this didn't work for me, at least not consistently, and I was still left with thousands of "un-tempo'd" tracks. It may work for you; if it does, let me know in the comments.

Solution #2

(For the non-technical: skip to the bottom to download the app)

Time to write a little code. On Windows, iTunes has a COM interface (I hear you shuddering out there, but I'm nothing if not pragmatic). It doesn't appear to be well-documented, but a little web searching makes things clear enough. I'm working in C#/.NET/Visual Studio, but you could use Python, Powershell, or almost anything.

In Visual Studio, create a new Console Application project, add a reference, go to the COM tab, and select "iTunes 1.13 Type Library". Instantiate a new iTunesAppClass object representing the iTunes application:

var iTunesApp = new iTunesAppClass();

When done, in a finally block, be sure to release the object:

Marshal.ReleaseComObject(iTunesApp);

The LibraryPlaylist property contains all the tracks:

var mainLibrary = iTunesApp.LibraryPlaylist;


The collection of tracks for a playlist is on the Tracks property, from which you can enumerate individual tracks:

foreach (var track in mainLibrary.Tracks) { .. }

We want to limit ourselves to file-based tracks. One way to do that is to cast each track object to the IITFileOrCDTrack class, and only proceed if the cast succeeds.

var filetrack = track as IITFileOrCDTrack;

Finally, the IITFileOrCDTrack class has an UpdateInfoFromFile() method, which does what it sounds like:

filetrack.UpdateInfoFromFile();

If you're interested, you can download the source project, or the compiled application.

Links

Thursday, October 4, 2012

90/180 BPM Running Playlists and Beat Detection Software

In my last post, I discussed my motivation for coming up with an iPod playlist of songs with tempos and 90 or 180 beats per minute (BPM), to listen to while running. This helps in running with a cadence of 180 strides per minute. Fortunately, the interwebs oblige with lots of suitable running playlists, as well as quite an extensive list at jog.fm.

With sample playlists in hand, I was able to put together one based on my own collection of music that looks something like this:

Ramblin' Man - The Allman Brothers Band
Never Is Enough - Barenaked Ladies
Wild Honey Pie - The Beatles
I'm a Loser - The Beatles
One After 909 - Beatles
Run for Your Life - The Beatles
Norwegian Wood (This Bird Has Flown) - The Beatles
Can't Find My Way Home - Blind Faith / Eric Clapton
Subterranean Homesick Blues - Bob Dylan
From A Buick 6 - Bob Dylan
Modern Love (1999 Digital Remaster) - David Bowie
16 Military Wives - The Decemberists
The Boys of Summer - Don Henley
Man With a Mission - Don Henley
Maxine - Donald Fagen
Son of a Preacher Man - Dusty Springfield
At Last - Etta James
It's Your Thing - Isley Brothers
Feelin' Alright - Joe Cocker
One More Time - Joe Jackson
All My Love - Led Zeppelin
Custard Pie - Led Zeppelin
Boom, Like That - Mark Knopfler
Don't Crash the Ambulance - Mark Knopfler
Sunday Morning - Maroon 5
The Impression That I Get - The Mighty Mighty Bosstones
The Flyer - Nanci Griffith
Live Forever - Oasis
All Around the World or the Myth of Fingerprints - Paul Simon
The Obvious Child - Paul Simon
In Your Eyes - Peter Gabriel
Watching the Clothes - The Pretenders
Precious - Pretenders
Fat Bottomed Girls - Queen
Finest Worksong - R.E.M.
Breaking the Girl - Red Hot Chili Peppers
Give It Away - Red Hot Chili Peppers
Yertle the Turtle - The Red Hot Chili Peppers
Black Cow - Steely Dan
Hello It's Me - Todd Rundgren
Bright Side Of The Road - Van Morrison

If you noticed that this list is full of a lot of moldy oldies, you're right. But I'm of a certain age, and that's what's in my iTunes. In any event, it's not a bad list, and I have been running happily with it for several weeks. However, I quickly tire of almost anything, and longer term I would like more variety. Now, I should say that I own a lot of music. The CD rack holds about 800 discs, and it's full, and other CDs are squirreled away in various other locations. There are about 15,000 tracks in my iTunes music library, so I probably own a lot more tracks that are 90 or 180 BPM. How to find them?  Ideally I'd like something that could crawl through all of my iTunes tracks, analyze the music, and automatically fill in the BPM information. I know it’s not going to be fast, but that's OK. It can run overnight if necessary, or over many nights, for that matter. I found three programs for Windows, free and commercial, that claim to do what I'm looking for.

Cadence Desktop Pro


The Big Kahuna in the very sparse field of automatic beat detection software seems to be Cadence Desktop Pro. It claims to do pretty much exactly what I want: it communicates with iTunes so it knows about your playlists, and makes it fairly easy to select a playlist or part of one, find and display the tempo for each track, and then gives you the option of saving the BPM info back to the tracks. It also gives you a way to verify the tempo by playing a track and tapping with the beat on the space bar.



I downloaded and installed the trial version, and my initial results were good enough that I went ahead and paid $6.99 for the full version. The problem is, it crashes... a lot. It worked well at the beginning, but after a while it became completely unusable. Apparently this happens for other people who have a lot of tracks in their iTunes library. If you have a modest collection of tracks, probably less than a thousand, Cadence Desktop Pro is a very good tool for the purpose. Otherwise, you might want to evaluate carefully before buying.

MixMeister BPM Analyzer


MixMeister BPM Analyzer is a free tool intended for DJ's to find the perfect beat, but looks promising for those of us who don't make it into nightclubs much these days. Its user interface is a bit simpler than Cadence Desktop, and it doesn't integrate with iTunes - it just works off music files on the filesystem. You can browse to a directory, and the program will analyze all music files in that directory as well as all subdirectories (incidentally, it only works with WAV, MP3, and WMA formats). This allowed me to quickly find several more songs in the 88-92 BPM range in an old playlist directory of running songs:


All in all, I like this tool. It's very fast, maybe about 5 seconds per song on my reasonably high-end developers' PC. It automatically saves the Beats Per Minute data to each track, so you could certainly use it in conjunction with smart playlists on iTunes.

BPM Detector Pro


The final entry in the world of automatic beat detectors is BPM Detector Pro. This is also a file-based program, and works quickly, but the look and feel is certainly nothing to write home about:



The trial version is very limited, as you can only analyze three songs at a time. I never did figure out its scheme for exporting BPM data. According to the help file, "Source files may either be renamed, or copied to a new file with a new name. In either case the BPM value can be placed either at the beginning or at the end of the new file name." I didn't want it to do either, and fortunately it didn't create any new files, unless it put them an undisclosed location.

Conclusion


At $24.95 for the full version of BPM Detector Pro, I'll be sticking with MixMeister BPM Analyzer. Besides working well and being free, they also get bonus points for not including the word "Pro" in their name.


Thursday, September 27, 2012

Barefoot Running and the Perfect Beat

Blame it on Born To Run.

No, not the Bruce Springsteen album or song, but the book by Christopher McDougall chronicling his journeys among ultramarathoners, a native Mexican tribe of (seemingly) superathletes, and his own running pain. The main point of the book is: everything you know about running is wrong. Specifically, shoes. All that padding and stability and motion control just gets in the way of the natural sensory feedback your feet give you when you run barefoot, leading to bad running form and eventually, for most people, injuries. To put it bluntly, the shoes are indirectly causing the very injuries they're supposed to be preventing.



I have been running more or less regularly since the fall of 2000, when my wife and I found out we were expecting our first child. At the time I didn't lead an unhealthy lifestyle exactly, but I wasn't getting a great deal of exercise either, and if I wanted to be around to see this kid grow up, I needed to take better care of myself. I joined a gym, started on cardio machines, transitioned to treadmill running and outside running. I ran my first Peachtree Road Race in 2002 and did quite a few races over the next few years, mostly 10Ks but also a few 5Ks and one half-marathon. Some nagging injuries led me to give up running for a couple of years, but I found I really missed it so I made the effort to start up again in 2010 - about the time I learned about Born To Run. The book was a revelation, and made a lot of sense to me - after all, humans have been running barefoot for thousands of years - do we really need expensive, high-tech shoes to keep from injuring ourselves? I tried some barefoot running but the bigger impact (no pun intended) on my running came in the form of some more minimalist shoes and more careful attention to my form.

McDougall's book talks a good bit about correcting your running form, as merely taking off your shoes isn't enough. Most of us need to unlearn years of bad habits, such as landing on your heels, developed from running in highly-cushioned shoes. Correcting one's running form isn't easy, even for McDougall, who had the benefit of some of the best running coaches around. I found some YouTube videos and other sites which helped, but I wasn't sure I was on the right track. I felt like I needed some coaching, but I'm basically too cheap to hire a personal trainer; plus, all this barefoot/minimalist running stuff, as trendy as it was, was still new, and I doubted that there was an abundance of coaches out there who knew what they were talking about.

Big Peach Running Co. Logo


Fortunately, the good folks at Big Peach started to offer Good Form Running classes for a modest fee. This technique, very much in line with the barefoot running craze, divides running form into four areas: posture, mid-foot landing, cadence, and lean. Breaking it down like this lets you work on one thing at a time. The cadence part is particularly simple: aim for 180 strides per minute, or 90 per minute on each foot, which will give you a shorter, more efficient stride, while at the same time discouraging you from landing on your heels. I had known about the 180 strides per minute guideline for some time, and briefly tried running with a metronome, but I wasn't crazy about it. However, the class suggested running with an iPod playlist consisting of songs with tempos at 90 or 180 beats per minute. I hadn't thought about doing this before, but it made a lot of sense for me - I run with an iPod Nano (although usually listening to podcasts), and I have a lot of music in iTunes. Surely some fraction of the thousands of songs were at the correct tempo, right?

In the next post I'll discuss my efforts at putting together a playlist of suitable songs.

Wednesday, September 19, 2012

I'm Feeling Ducky


duckduckgo.com screenshot


I have used Google products for a long time. I started using their search engine back around 2000 or so, when they were still in their lengthy beta period, and most other people were still getting by with AltaVista, Yahoo, or whatever else passed for web search in those days. When Google search exploded in popularity, I had my share of early-adopter smugness, and soon took it for granted that with enough search wizardry I could find anything.

Likewise, I was an early and enthusiastic adopter of GMail in 2004, which I continue to use for my main account, and now my work account (although I didn't make that decision). Although we keep a paper calendar on the fridge, it doesn't get written on much anymore as our lives have migrated to Google Calendar. Google Documents has become a handy permanent-and-accessible-anywhere location for various lists and other handy documents. Picasa rapidly became an easy tool for managing, editing, and uploading family photos - to Google servers, of course. (Then there's the blogging platform you're reading now, of course). I even used Google Desktop Search on my old Windows XP machines, which was approximately 15253% better than trying to find a file using Windows's own search capability. If it's on that black Google toolbar, I probably use it. (OK, Google+, not so much.) In short, Google has insinuated itself into my life pretty heavily. If they cared to look, they could probably learn just about anything about me.

Which brings me back to search.

About a year ago I was listening to a Hanselminutes podcast about a search engine called DuckDuckGo. It's a general-purpose web search engine that does all the usual spidery-crawly indexing, while adding some interesting touches of their own. Their search results have more emphasis on noncommercial, curated sites such as Wikipedia and Delicious, and deliberately avoid content farms such as Answers.com. They have an interesting "Zero-click Info" feature: where possible, you'll see a box at the top of the search results with a brief synopsis or definition, again from curated sources. If you're keyboard-driven, they have scads of keyboard shortcuts, so for instance you can search for a book on Amazon by typing "steve jobs biography !amazon" (or just "steve jobs biography !a" if you're into brevity). Finally, they make it a point not to track you. This earned DuckDuckGo a Class A rating from Terms Of Service; Didn't Read, a new website that is trying to distill the terms of service of various websites into plain English (and presumably other languages).

Up to this point, I could count on one hand the number of non-Google web searches I had performed over the last 10 years or so. (Bing just seemed... slow, cluttered, and not that compelling.) But I admired the audacity (insanity?) of going up against a juggernaut like Google, so I gave DuckDuckGo a try, and I liked what I saw. Soon it was my default search engine on Chrome (my browser of choice, natch) and Firefox.

I still respect Google as a company, and feel that they try to adhere to the "Don't be evil" motto when possible (although perhaps not as much as a few years ago). They still provide my email, calendar, browser, and more. But, with privacy on the Internet being easy to lose and difficult to regain, I like having that big "search" egg in a different basket.