Emacs' AlsaPlayer - Music Without Jolts

Table of Contents

Emacs' AlsaPlayer - Music Without Jolts

This manual (last modified: <16/01/2009 07:49:23 UTC>) documents Emacs' AlsaPlayer version 0.12 (Gaza Remembered), an Emacs interface to the AlsaPlayer PCM audio player.

Emacs' AlsaPlayer is referred to as EAP (pronounced 'eep') throughout the rest of this manual.

1 Obtaining Emacs' AlsaPlayer

EAP is a project kindly hosted by Gna!.

EAP home
http://home.gna.org/eap

Includes package download links as well as links to the manual (online, and in various formats).

EAP project page
https://gna.org/projects/eap/

Mainly for co-developers and project members.

Daily snapshot of latest SVN version
http://svn.gna.org/daily/eap-snapshot.tar.gz

For Subversion users.

Anonymous SVN over HTTP
svn co http://svn.gna.org/svn/eap/trunk eap

For Subversion users.

Anonymous SVN over SVN (TCP 3690)
svn co svn://svn.gna.org/svn/eap/trunk eap

For Subversion users.

2 Music Without Jolts

What is a 'jolt' exactly? According to the GNU Collaborative International Dictionary of English, to jolt someone is:

To stun or shock or change the mental state of a person suddenly, as if with a blow; as, the sight of the house on fire jolted him into action; his mother's early death jolted his idyllic happiness. [PJC]

So there we have it.

Imagine, if you will, that you are listening to the elegiac, yet somehow uplifting title track of the album 'Room To Roam' by British folk rock band The Waterboys, and decide that it doesn't quite suit your mood at that particular moment in time. What do you do? Well, let's say you tell your audio player to skip forward to the next song in the current playlist. Now imagine that your audio player is in what's commonly known as 'shuffle mode' and the next song happens to be 'War On War' by American alt country band Wilco. Unless sufficient care is taken (and EAP is the only audio player I know of that takes sufficient care), you will undoubtedly endure a significant jolt to your idyllic happiness.

In short, listen to your music with EAP (with all volume related settings at their default values) and anything you do that would ordinarily result in an abrupt change of volume is preceeded by a gentle volume fade, ensuring that jolts to your idyllic happiness are a thing of the past (power cuts excepted).

Finally, your personal idyllic happiness is part of a wider struggle, namely that of trying to rid our environment of jolts entirely. For most people, Vim is the once popular scouring powder produced by Lever Brothers from 1904 to 1993 and reputedly used by Francis Bacon as a substitute for toothpaste, but for a very few people it is a program that can be used for editing text.

If someone offers you Vim (the program) or makes Vim (the program) available to you in any way, do not accept it! Every attempt to extend Vim (the program) so that it performs adequately as a jolt-eliminating music player has resulted in total and unmitigated failure and each time someone adopts Vim (the program) as their editor of choice the struggle to rid our environment of jolts suffers a significant, demoralising setback; significant because it defeats our stated aim, and demoralising because users of Vim (the program) often develop a strange, irrational loyalty to it, accompanied by an equally unfathomable prejudice towards Emacs. When that happens we have what can only be described as an immovable jolt to contend with.

Persuading users of Vim (the program) to switch to Emacs for the sake of the environment, and not for any other reason, has been known to work in a few well known (though poorly documented) cases.

3 Feature list

4 Brief technical overview

EAP is an Emacs interface to AlsaPlayer:

AlsaPlayer
The following description is taken from the AlsaPlayer website (to which a link is provided above):
AlsaPlayer is a new type of PCM player. It is heavily multi-threaded and tries to excercise the ALSA library and driver quite a bit. It has some very interesting features unique to *nix players. The goal is to create a fully pluggable framework for playback of all sorts of media with the focus on PCM audio data.

Despite the name, AlsaPlayer supports a wide array of different audio output interfaces, including the one-time GNU/Linux default output interface; OSS. Other output interfaces supported include Esound, NAS, Sparc, SGI and JACK.

Emacs' AlsaPlayer
EAP manages calls to AlsaPlayer via Emacs' synchronous process routines and two new key bindings in Dired buffers provide the interface between your music library and AlsaPlayer. Named playlists are simply directories of symbolic links and a third Dired key binding is provided to facilitate the easy addition of symbolic links to these directories.

5 Installation

EAP is an Emacs interface to AlsaPlayer so, not surprisingly, it won't work without it.

5.1 Installing AlsaPlayer

On a Debian GNU/Linux system a minimal working AlsaPlayer requires that these two packages:

     alsaplayer-common
     alsaplayer-text

and one of these:

     alsaplayer-alsa
     alsaplayer-esd
     alsaplayer-jack
     alsaplayer-nas
     alsaplayer-oss

be installed.

Choose the last package according to your audio output interface. AlsaPlayer is designed to work closely with the ALSA system when it's available, i.e., it works perfectly well without it.

Test the text interface by issuing the command:

alsaplayer -i text some-audio-file.ogg

5.2 Installing Emacs' AlsaPlayer

EAP consists of three separate files; eap.el, eap-dired-keybindings.el and eap-autoloads.el. Ensure that all three files are located somehwere in your ‘load-path’. For example, put them in the directory ~/elisp and then add this line to your ~/.emacs:

     (add-to-list 'load-path "~/elisp")

Next you must tell EAP the location of your music library, and where you would like to keep your playlists. For example, add these lines to your ~/.emacs:

     (setq eap-music-library
           "~/my-music-library" ;default value "~/Music"
     
           eap-playlist-library
           "~/eap-playlists") ;default value "~/eap-playlist-library"

Important note: Don't make your playlist library a sub-directory of your music library!

EAP will create both directories for you if they don't exist. On the other hand, if you are happy with the default locations you needn't add these lines to your ~/.emacs file at all.

Finally, either add the line:

     (require 'eap-autoloads) ;recommended on principle

or

     (require 'eap)

to your ~/.emacs file.

The first form defers loading of the package until you actually need it. The second form will causes the package to be loaded at start time every time.

Save your ~/.emacs file and restart Emacs, or issue the command:

M-x load-file RET ~/.emacs RET.

6 Starting Emacs' AlsaPlayer

EAP can be started by issuing the command M-x eap from anywhere within Emacs.

M-x eap
First of all, a note about how AlsaPlayer behaves. When AlsaPlayer exits cleanly it writes its current playlist to a playlist file (usually ~/.alsaplayer/alsaplayer.m3u).

Assuming EAP is not already running, when you issue the command M-x eap EAP checks for the presence of this playlist file and if it is found (and has non-zero length) EAP will ask you if you'd like to continue where you left off. Answer positively and EAP will create a playlist from the contents of this file and proceed to play it. If the file is not found (or is of zero length) your music library is displayed in Dired.

If EAP is running when you issue the command M-x eap the EAP buffer (default name ‘*EAP*’) is displayed.

EAP may also be started via one of the three Dired keybindings, all of which can be performed on a single file, a set of marked files, a single directory, or a set of marked directories. I refer to these simply as marked below.

M-p p
Start a new playlist consisting of marked. Use a prefix argument (C-u) to shuffle marked in the new playlist.
M-p q
Add marked to the current playlist (a.k.a enqueuing). Use a prefix argument (C-u) to shuffle marked before they are added.
M-p s
Add marked to named playlist. This command will not start AlsaPlayer or have any effect on the current playlist if AlsaPlayer is already running.

7 Emacs' AlsaPlayer Buffers

There are two Emacs' AlsaPlayer buffers, called ‘*EAP*’ and ‘*EAP Playlist*’ by default, although these names are customisable. See Customising Emacs' AlsaPlayer.

Exactly the same commands are available in each buffer. See Keys and commands.

*EAP*
Buffer ‘*EAP*’ is only supposed to be two lines tall, and displays the AlsaPlayer process output. It is not designed to be killed (C-x k). Doing so kills the AlsaPlayer process very abruptly, not allowing it time to save the current playlist to disk. The correct way to stop listening to music is to type Q, in the ‘*EAP*’ buffer, or M-x apq, from anywhere within Emacs.

If you find killing buffers a hard habit to break you can ensure that AlsaPlayer always quits cleanly (and saves your current playlist) by adding the function ‘eap-always-kill-buffer-cleanly’ to ‘kill-buffer-hook’. This isn't as hard as it sounds. Simply add the following lines to your ~/.emacs:

          (add-hook 'kill-buffer-hook
                    'eap-always-kill-buffer-cleanly)

The same precaution can be taken when killing your Emacs session by adding the function ‘eap-always-kill-emacs-cleanly’ to the list ‘kill-emacs-query-functions’. Simply add these lines to your ~/.emacs as well:

          (add-to-list 'kill-emacs-query-functions
                       'eap-always-kill-emacs-cleanly)

N.B. If EAP is doing its best to avoid jolts to your idyllic happiness (see Music Without Jolts), which it does by default, then adding these hooks will add two or three seconds to each operation.

*EAP Playlist*
The ‘*EAP Playlist*’ buffer displays the contents of the current playlist, with the currently playing song highlighted. This buffer is not self-refreshing so you may occasionally need to type p to update it.

8 Keys and commands

The same set of key commands listed below are available in both EAP buffers; ‘*EAP*’ and ‘*EAP Playlist*’ by default.

8.1 Playlist/song position commands

Key Action Global command
< OR [left] Previous song M-x ap<
> OR [right] Next song M-x ap>
SPC Pause/Play M-x ap.
j Jump to song M-x apj

8.2 Volume adjustment commands

Key Action Global command
0 Volume mute M-x ap0
- Volume soft M-x ap-
= Volume full M-x ap=

8.3 Other commands

Key Action Global command
p Show current playlist M-x app
m Show music library M-x apm
l Show playlist library M-x apl
v Show current song M-x apv
s Add current song to named playlist M-x aps
i Toggle fade-in functionality M-x api
o Toggle fade-out functionality M-x apo
Q Quit EAP M-x eaq

8.4 Commands only available in EAP buffers

Key Action
f Seek forward
b Seek backward
[up] Volume up
[down] Volume down
k Keep window small
q Bury EAP buffers

9 Customising Emacs' AlsaPlayer

To customise EAP via Emacs' popular Customize framework, issue the command:

M-x customize-group RET eap RET

See Customization.

10 Mailing lists

Support/development list
https://mail.gna.org/listinfo/eap-dev/

Please send bug reports, feature requests, hacks, patches and feedback of any sort (good or bad), to this list.

Subversion activity list
https://mail.gna.org/listinfo/eap-commits/

11 TODOs

Secondary music library location (and playlist library location)
This would be useful in a case (such as mine) where my main music library is on a removable drive that I can't always be bothered to switch on. EAP should use secondary libraries if primary libraries aren't found.
Make column widths in playlist buffer customisable
My development machine accomodates about 120 columns in a full-width buffer (and using a medium-sized font) so the column widths I've chosen reflect that value. Better (but harder) than making the column widths user-configurable, would be some 'smart sizing' routines, reflecting the number of columns available in any given buffer.
Scrobble song information to Last.FM
Scrobbling song information to http://last.fm. Don't really know where to begin on this one.

12 Known bugs and limitations

If volume fade-out functionality is enabled and you pause playback (SPC in an EAP buffer or M-x ap. from anywhere), followed immediately by a command to skip to the next song in the current playlist (> or [right] in an EAP buffer or M-x ap> from anywhere), the volume is not properly restored. Typing = in an EAP buffer, or M-x ap= from anywhere, usually corrects this situation.

Failure to properly restore the volume after a fade-out has been observed in other less easily identifiable situations, but these occasions are thankfully few. If it does happen to you, the same fix (described above) applies.

13 Possibly asked questions

Does AlsaPlayer play Ogg Vorbis files?
The question should really be, does AlsaPlayer play mp3 files? I didn't write AlsaPlayer (only the Emacs interface), but I happen to know that it takes a pretty dim view of always playing mp3s. Even if you only play oggs occasionally you'll be surprised how much you go up in its estimation.
Why commit yourself to one particular back-end?
I like Alsplayer. I like the fact that the designers thought to include a text interface (no GUI) and it's command line interface is especiialy clean and simple.

People are welcome to implement support for other players but the name, Emacs' AlsaPlayer, is here to stay.