Hack19.Shuffle Your Music the Smart Way

Hack 19. Shuffle Your Music the Smart Way

Use IMMS to weight your music collection based on your listening habits.

Think of all the ways you interact with a computer each day. Any action you take, or even don't take, conveys some meaning. For example, when listening to your music collection, you might sometimes skip songs. What does that mean? There are a number of possibilities. Maybe you do not like the song that was playing, or it does not suit your current mood, or, possibly, you've listened to this song too much and would rather it be played less often.

Is it possible to build a system that uses this information to learn which music you prefer and play it more often? Yes! Intelligent Multimedia Management System (IMMS) is an attempt to create such a systeman adaptive playlist framework that tracks your listening patterns and dynamically adapts to suit your personal music tastes. Plug-ins are currently available for two popular Linux media players: XMMS (http://www.xmms.org/) and Beep Media Player (http://beepmp.sourceforge.net/).

The main feature of IMMS is its complete transparency to the user. It is incredibly unobtrusiveyou never have to interact with IMMS directly. Just continue using your player as usual and, over time, IMMS will influence the song selection to cater to your preferences. When your music player chooses the next "random" track in shuffle mode, IMMS weights its choice, based on which songs you've played and which songs you've skipped previously.

IMMS also offers a number of features beyond basic rating. For example, it keeps track of when a song was played last and makes sure the same song does not repeat too oftena common complaint with traditional shuffle-based systems. Moreover, it is able to recognize different versions of the same songs (for example remixes) and treat them as the same song.

IMMS also learns which songs should be played together and which should not. It does so by both watching and learning from the user, and performing acoustic analysis on the actual songs to determine their tempo and spectral "color," and then attempts to group more similar songs together.

2.8.1. Get IMMS

Depending on the distribution you use, there may already be an IMMS package available to install. There is an up-to-date Debian package for IMMS, as well as a Gentoo ebuild. If you are unable to find a pre-packaged version of IMMS, you can easily build one from source. The tarball can be downloaded from the IMMS homepage at http://www.luminal.org/wiki/index.php/IMMS. A list of required dependencies and instructions on building IMMS are included with the source in an INSTALL file.

Once you have IMMS installed, you will need to enable it in XMMS. Open the Preferences dialog, go to the General plug-in category, select IMMS, and click the "Enable plugin" checkbox in the lower-right corner.

That's it. From now on your music player will be imbued with IMMS intelligence. You will notice that music selection will improve over time without your having to do anything at all. Of course, you should not expect this to happen overnight. It will take time for IMMS to learn your preferences. You may find IMMS to be a little slow at first, since it needs to read the tags and calculate checksums of all your files. Depending on the size of your collection, this process should not take very long. In the meantime, type:

 $ tailf ~/.imms/imms.log 

and watch IMMS rate your music.

2.8.2. More IMMS Magic

Although IMMS is built from the ground up to require no direct user interaction, it is possible to do some useful things with the data it accumulates. For example, if you own a portable MP3 player, you may want to fill it with the songs IMMS has identified as your favorites. James C. Jones wrote an excellent program called IMMS Magical Favorites Collector, or IMFavorites for short (http://imfavorites.sourceforge.net), for just that purpose. Simply specify how much space your player has, and IMFavorites will create a directory of symbolic links to the gems of your collection (see Figure 2-4).

Figure 2-4. IMFavorites in action

A lot of the flexibility of IMMS comes from the fact that it is based around an embedded SQL databaseSQLite (http://www.sqlite.org). SQLite allows users with even a very basic knowledge of Structured Query Language to generate neat statistics and reports about their music collection and preferences. To harvest its power, you will need to use the command-line client that comes with SQLite 3.0 and abovesqlite3. IMMS stores all of its data in .imms directory in your home directory, and the database is located in ~/.imms/imms2.db. Soto run an SQL query on it, you need to execute:

 $ sqlite3 ~/.imms/imms2.db  '<your query>'  

Here are some queries you can use:

 SELECT path FROM Identify NATURAL INNER JOIN Rating WHERE rating > 145 ; 

This query will effectively generate a list of favorites, because ratings in IMMS range from 75 (really bad) to 150 (really good).

A more involved example that allows you to list the top ten artists for last month would look like this:

 SELECT SUM( delta ) as sumdelta, readable FROM Journal NATURAL INNER JOIN Library NATURAL INNER JOIN Info NATURAL INNER JOIN Artists GROUP BY Artist ORDER BY sumdelta DESC LIMIT 10; 

To familiarize yourself with IMMS schema run:

 SELECT FROM sqlite master; 

This lists the tables present in the database and their attributes. Also refer to the description of query language understood by SQLite at http://www.hwaci.com/sw/sqlite/lang.html.

Michael "mag" Grigoriev

Linux Multimedia Hacks
Linux Multimedia Hacks
ISBN: 596100760
Year: 2005
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net