© 2004, 2005, 2006 Yoni Rabkin, Jorgen Schaefer, Mario Domgoergen

     Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

Emms Manual
***********

This is the Manual for the Emacs Multimedia System

Introduction
************

Emms is the Emacs Multi-Media System. It tries to be a clean and small application to play multimedia files from Emacs using external players. Many of its ideas are derived from MpthreePlayer (http://www.nongnu.org/mp3player), but it tries to be more general and more clean.

The basic functionality of Emms consists of three parts: The core, the sources, and the players.

The core resides in emms.el, and provides a simple playlist and the basic functionality to use all the other features of Emms. It provides the common user commands and interfaces for other parts. It thinks in tracks, where a track is the combination of a type and a name - e.g. the track type 'file has a name that is the file name. Other track types are possible.

To get to tracks, the core needs sources. The file emms-source-file.el provides simple sources to interact with the file system.

When Emms finally has the sources in the playlist, it needs a player to play them. emms-player-simple.el defines a few useful players, and allows you to define your own in a very simple way.

The way Emms works is easy to customize with your own code or by using `M-x customize'.

Installation
************

You need to put all the .el files of emms in a directory in your load-path. For example, if you put all those files into ~/elisp/emms/, then in your ~/.emacs, you should do:

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

Compiling Emms
==============

You can byte-compile Emms by first entering the directory containing the Emms source code, followed by invoking:

make

Which will byte compile Emms. You can then invoke:

make install

Which will install Emms into your Emacs directories (provided you have the appropriate permissions to do so on your system).

Note that Emms is a light-weight and agile program, you can therefore run Emms just fine without byte compiling it.

Simple Setup
************

After adding the location of the Emms code to the LOAD-PATH variable, see Installation. we invoke the following using the `emms-setup' feature which allows for quick and simple Emms setup.

     (require 'emms-setup)
     (emms-standard)
     (emms-default-players)

After which Emms is set-up and ready to go!

The above will setup Emms with standard features (interactive playlists, audio track tag reading etc.) and a default list of players (ogg, mp3, mplayer etc.).

The `emms-setup' feature is provided by the file emms-setup.el. It is essentially a collection of shortcuts for setting up Emms quickly and simply. Everything you can do with `emms-setup' can also be done manually.

We use `emms-setup' by calling one of the setup functions. Each of the functions sets up Emms to include a number of features.

 -- Function: emms-minimalistic
     An Emms setup script. Invisible playlists and all the basics for playing media.

 -- Function: emms-standard
     An Emms setup script. Everything included in the emms-minimalistic setup, the Emms interactive playlist mode and reading information from tagged audio files.

 -- Function: emms-all
     An Emms setup script. Everything included in the emms-standard setup and adds all the stable features which come with the Emms distribution.

 -- Function: emms-devel
     An Emms setup script. Everything included in the emms-all setup and adds all of the features which come with the Emms distribution regardless of if they are considered stable or not.  Use this if you like living on the edge.

`emms-setup' also comes with a convenience function to set a default list of media players.

 -- Function: emms-default-players
     Set EMMS-PLAYER-LIST to EMMS-SETUP-DEFAULT-PLAYER-LIST.

It is also worth noting that you can write your own Emms setup functions like the above by looking at the existing function definitions in emms-setup.el.

Configuration
*************

This chapter discusses the configuration of Emms in more detail.

The following code fragment provides a minimal Emms setup without using the layer of `emms-setup'. It can maybe be used to better understand the internals of Emms. You can see how Emms needs to know about players (these are defined in `emms-player-simple') and about sources for tracks (trivial file system based sources, such as this `emms-directory-tree', are defined in `emms-source-file').

     (require 'emms-player-simple)
     (require 'emms-source-file)
     (setq emms-player-list '(emms-player-mpg321
                              emms-player-ogg123
                              emms-player-mplayer))

For a discussion on how to define additional players, see Simple Players.

Much of the behaviour of Emms can be changed by setting variables. For example:

     (setq emms-info-asynchronously nil)
     (setq emms-playlist-buffer-name "*Music*")

The first setq turns off the asynchronous updating of info tags. The second sets the default name of the Emms playlist buffer.

Another way to change Emms variables is to use the M-x customize mechanism provided by Emacs.

Basic Commands
**************

Before you can use the interface commands, you need a playlist to start with. The following commands allow you to add to the current playlist from different sources:

Note that the commands with the ``emms-add-'' prefix add the source to the playlist but do not start playing it immediately. Conversely, the commands with the ``emms-play-'' prefix begin playing the track immediately.

 -- Function: emms-play-file file
     A source for a single file - either FILE, or queried from the user.

 -- Function: emms-add-file file
     A source for a single file - either FILE, or queried from the user.

 -- Function: emms-play-directory dir
     A source for a whole directory tree - either DIR, or queried from the user.

 -- Function: emms-add-directory dir
     A source for a whole directory tree - either DIR, or queried from the user.

 -- Function: emms-play-directory-tree dir
     A source for multiple directory trees - either DIR, or the value of EMMS-SOURCE-FILE-DEFAULT-DIRECTORY.

 -- Function: emms-add-directory-tree dir
     A source for multiple directory trees - either DIR, or the value of EMMS-SOURCE-FILE-DEFAULT-DIRECTORY.

 -- Function: emms-play-url url
     A source for an URL - for example, for streaming.

 -- Function: emms-add-url url
     A source for an URL - for example, for streaming.

 -- Function: emms-play-playlist playlist
     A source for the M3u or PLS playlist format from the file PLAYLIST.

 -- Function: emms-add-playlist playlist
     A source for the M3u or PLS playlist format from the file PLAYLIST.

 -- Function: emms-play-find dir regexp
     A source that will find files in DIR or EMMS-SOURCE-FILE-DEFAULT-DIRECTORY which match REGEXP.

 -- Function: emms-add-find dir regexp
     A source that will find files in DIR or EMMS-SOURCE-FILE-DEFAULT-DIRECTORY which match REGEXP.

The basic functionality of Emms is just to play music without being noticed. It provides a few commands to skip the current track and such, but other than that it doesn't show up. Emms provides the following basic user commands (which you might want to bind to keystrokes):

 -- Function: emms-start
     Start playing the current playlist

 -- Function: emms-stop
     Stop playing

 -- Function: emms-next
     Start playing the next track in the playlist

 -- Function: emms-previous
     Start playing previous track in the playlist

 -- Function: emms-shuffle
     Shuffle the current playlist. This uses EMMS-PLAYLIST-SHUFFLE-FUNCTION.

 -- Function: emms-sort
     Sort the current playlist. This uses EMMS-PLAYLIST-SORT-FUNCTION.

 -- Function: emms-show &optional insertp
     Describe the current Emms track in the minibuffer. If INSERTP is non-nil, insert the description into the current buffer instead. This function uses EMMS-SHOW-FORMAT to format the current track.

The Core File
*************

The core file emms.el provides the all basic functions for playing music, generating playlists and defining players.

User Variables
==============

The core file defines a number of user variables.

 -- User Option: emms-player-list
     A list of players Emms can use. You need to set this in order to use Emms to play media.

 -- User Option: emms-show-format
     The format to use for emms-show. Any "%s" is replaced by what EMMS-TRACK-DESCRIPTION-FUNCTION returns for the currently playing track.

 -- User Option: emms-repeat-playlist
     Non-nil if the Emms playlist should automatically repeat the playlist. If nil, playback will stop when the last track finishes playing.

 -- User Option: emms-track-description-function
     Function for describing an Emms track in a user-friendly way.

 -- User Option: emms-sort-lessp-function
     A function that compares two tracks, and returns non-nil if the first track should be sorted before the second (see also sort).

Hooks
=====

The core file provides hook variables for the basic functionality of Emms.

 -- User Option: emms-player-started-hook
     A hook run when an Emms player started playing.

 -- User Option: emms-player-stopped-hook
     A hook run when an Emms player stopped playing. See also EMMS-PLAYER-FINISHED-HOOK.

 -- User Option: emms-playlist-source-inserted-hook
     Hook run when a source got inserted into the playlist. The buffer is narrowed to the new tracks.

 -- User Option: emms-playlist-selection-changed-hook
     Hook run after another track is selected in the Emms playlist.

 -- User Option: emms-playlist-cleared-hook
     Hook run after the current Emms playlist is cleared. This happens both when the playlist is cleared and when a new buffer is created for it.

 -- User Option: emms-player-finished-hook
     Hook run when an Emms player finishes playing a track. Please pay attention to the differences between EMMS-PLAYER-FINISHED-HOOK and EMMS-PLAYER-STOPPED-HOOK. The former is called only when the player is stopped interactively; the latter, only when the player actually finishes playing a track.

 -- User Option: emms-player-paused-hook
     Hook run when a player is paused or resumed. Use EMMS-PLAYER-PAUSED-P to find the current state.

Core Functions
==============

The core file also defines all the functions important to the basic use of Emms.

There are functions which deal with movement in the playlist.

 -- Function: emms-next-noerror
     Start playing the next track in the Emms playlist. Unlike emms-next, this function doesn't signal an error when called at the end of the playlist. This function should only be called when no player is playing. This is a good function to put in emms-player-finished-hook.

 -- Function: emms-playlist-next
     Move to the previous track in the current buffer.

 -- Function: emms-playlist-previous
     Move to the previous track in the current buffer.

 -- Function: emms-random
     Jump to a random track.

 -- Function: emms-toggle-repeat-playlist
     Toggle whether emms repeats the playlist after it is done. See EMMS-REPEAT-PLAYLIST.

 -- Function: emms-toggle-repeat-track
     Toggle whether emms repeats the current track. See EMMS-REPEAT-TRACK.

Some functions deal with the getting and setting track information.

 -- Function: emms-track type name
     Create a track with type TYPE and name NAME.

 -- Function: emms-track-type track
     Return the type of TRACK.

 -- Function: emms-track-name track
     Return the name of TRACK.

 -- Function: emms-track-get name track &optional inexistent
     Return the value of NAME for TRACK. If there is no value, return DEFAULT (or nil, if not given).

 -- Function: emms-track-set track name value
     Set the value of NAME for TRACK to VALUE.

 -- Function: emms-track-description track
     Return a description of TRACK. This function uses EMMS-TRACK-DESCRIPTION-FUNCTION.

 -- Function: emms-player-for track
     Return an Emms player capable of playing TRACK. This will be the first player whose PLAYABLEP function returns non-nil, or nil if no such player exists.

 -- Function: emms-playlist-current-selected-track
     Return the currently selected track in the current playlist.

There are also functions which deal with the playing itself.

 -- Function: emms-player-start track
     Start playing TRACK.

 -- Function: emms-player-stop
     Stop the currently playing player.

 -- Function: emms-player-stopped
     Declare that the current Emms player is finished. This should only be done by the current player itself.

 -- Function: emms-seek seconds
     Seek the current player SECONDS seconds. This can be a floating point number for sub-second fractions. It can also be negative to seek backwards.

 -- Function: emms-seek-forward
     Seek ten seconds forward.

 -- Function: emms-seek-backward
     Seek ten seconds backward.

For more basic commands defined in the core file see Basic Commands.

Sources
*******

Sources allow Emms to add and play tracks. Emms comes with a number of sources of its own. Sources are designed so that creating new ones will be easy.

For examples of Emms sources for files and directories see emms-source-file.el.

 -- User Option: emms-source-file-default-directory
     The default directory to look for media files.

 -- Function: emms-play-find
     Play all files in EMMS-SOURCE-FILE-DEFAULT-DIRECTORY that match a specific regular expression.

 -- Function: emms-source-file &optional file
     An Emms source for a single file - either FILE, or queried from the user.

 -- Function: emms-source-files files
     An Emms source for a list of FILES.

 -- Function: emms-source-directory &optional dir
     An Emms source for a whole directory tree - either DIR, or queried from the user

 -- Function: emms-source-directory-tree & optional dir
     An Emms source for multiple directory trees - either DIR, or the value of EMMS-SOURCE-FILE-DEFAULT-DIRECTORY.

 -- Function: emms-source-find &optional dir regex
     An Emms source that will find files in DIR or EMMS-SOURCE-FILE-DEFAULT-DIRECTORY that match REGEXP.

 -- Function: emms-source-file-directory-tree &optional dir
     Return a list of all files under DIR which match REGEX.

 -- Function: emms-source-dired
     Play all marked files of a dired buffer

 -- Function: emms-source-file-regex
     Return a regexp that matches everything any player (that supports files) can play.

 -- Function: emms-locate regexp
     Search for REGEXP and display the results in a locate buffer

Simple Players
**************

 -- Macro: define-emms-simple-player name types regex command &rest args
     Define a simple player with the use of `emms-define-player'. NAME is used to construct the name of the function like emms-player-NAME. TYPES is a list of track types understood by this player. REGEX must be a regexp that matches the filenames the player can play. COMMAND specifies the command line argument to call the player and ARGS are the command line arguments.

For a discussion on how to define new players see New Player.

 -- Function: emms-player-simple-stop
     Stop the currently playing process, if indeed there is one.

 -- Function: emms-player-simple-start filename cmdname params
     Starts a process playing FILENAME using the specified CMDNAME with the specified PARAMS.

 -- Function: emms-player-simple-sentinel proc str
     Sentinel for determining the end of process for the process PROC and the sentinel string STR.

Playlists
*********

Emms uses Emacs buffers to store the media tracks for playing. We call one such buffer a ``playlist buffer'' or an ``Emms playlist buffer''. Emms then proceeds to play the media tracks in the buffer from top to bottom until the end of the playlist.

The name of the playlist buffer is defined in the variable EMMS-PLAYLIST-BUFFER-NAME and is set to be an invisible Emacs buffer by default. You can change to any name you want. For an example configuration see Configuration.

You can create any number of playlist buffers you wish. At any time Emms has a single ``current'' buffer through which it proceeds track by track.

 -- Function: emms-playlist-new &optional name
     Create a new playlist buffer. The buffer is named NAME, but made unique. NAME defaults to `emms-playlist-buffer-name'. If called interactively, the new buffer is also selected.

The current Emms playlist buffer is stored in the variable EMMS-PLAYLIST-BUFFER.

Track Information
*****************

Emms is distributed with two predefined methods for retrieving info, provided by emms-info-mp3info.el and emms-info-ogginfo.el. Both packages are front-ends for command-line tools. Ogg track information is retrieved using the ogginfo (http://directory.fsf.org/audio/ogg/vorbistools.html) software. Likewise, mp3 track information is available using mp3info (http://www.ibiblio.org/mp3info/).

Automatic track information retrieval is enabled by default in the `emms-standard', `emms-all' and `emms-devel' setup levels provided by emms-setup.el. For more information about emms-setup.el see Simple Setup.

If you would like to know how Emms track retreival works and how we can define new methods for track retrieval see Defining Info Methods.

There are a number of user variables which control the behaviour of `emms-info'.

 -- User Option: emms-info-auto-update
     Non-nil when Emms should update track information if the file changes. This will cause hard drive activity on track loading. If this is too annoying for you, set this variable to nil.

 -- User Option: emms-info-asynchronously
     Non-nil when track information should be loaded asynchronously. This requires the feature `later-do' which is provided by the file later-do.el, which should come with Emms.

 -- User Option: emms-info-functions
     Functions which add information to tracks.  Each is called with a track as argument.

Defining Info Methods
=====================

An info method essentially consists of a function which given an Emms track returns the appropriate info for that track.

We can for example look at the predefined method for retrieving information about audio tracks in the Ogg format.

The function emms-info-ogginfo provided by emms-info-ogginfo.el accepts an Emms track as a single argument and returns the appropriate information string.

We then register our info function with Emms by adding it to the EMMS-INFO-FUNCTIONS list. The function will then be called at the right time to provide track info.

     (add-to-list 'emms-info-functions 'emms-info-ogginfo)

Interactive Playlists
*********************

Emms provides a visual, interactive playlist mode as well as the ability to use playlists without ever looking at then. This visual, interactive mode is called the `emms-playlist-mode' and is defined in emms-playlist-mode.el.

The interactive playlist mode is enabled by default in the `emms-standard', `emms-all' and `emms-devel' setup levels. For more information about Emms setup levels see Simple Setup.

 -- Function: emms-playlist-mode-go
     Switch to the current emms-playlist buffer and use emms-playlist-mode.

The interactive playlist buffer shows the tracks in the current Emms playlist in the order in which they will be played. The current track will be highlighted.

When in the interactive playlist mode we can perform different actions on the current playlist.

n
     Start playing the next track in the playlist.

p
     Start playing the previous track in the playlist.

s
     Stop playing.

f
     Describe the currently playing track in the minibuffer.

c
     Display the current track in the center of the screen.

RET
     Start playing the track under point. Note that this is also available with <mouse-2>.

M-<
     Go to the first track in the playlist. M-> completes this command by going to the last track in the playlist using emms-playlist-mode-last.

r
     Go to a randomly selected track in the playlist.

q
     Put the interactive playlist buffer at the end of the list of all buffers.

C-x C-s
     Save the current playlist buffer to a file.

?
     Describe the mode.

We can also edit the playlist using familiar GNU/Emacs commands:

C-k
     Remove the track under point from the playlist buffer. Also available using the d key.

C-y
     See the command yank

C-w
     See the command kill-region

M-y
     See the command yank-pop.

C-j
     Insert a newline at point.

We can use the regular GNU/Emacs killing and yanking commands to move and copy tracks in between playlist buffers. We can use the same commands to insert arbitrary text into the playlist buffers together with the playlist tracks. Text which is not a track is ignored by the program and can therefore be used to include titles and annotations within the playlist.

Extending Emms
**************

Emms introduces a high abstraction layer for playing music so you can customise it to your needs.

New Player
==========

The file emms-player-simple.el defines some easy players to start with, but it shouldn't be hard to provide a function for your favourite player. We will start with an easy example that shows how we can use the play command under Unix to play our WAV files.

Simple Player for `play'
========================

Play is a very easy command line player for various format. If you want your emms to play WAV files just put the following lines in you .emacs:

     (require 'emms-player-simple)
     (define-emms-simple-player play '(file) "\\.wav$" "play")

Huh! Wasn't that easy?

The macro function define-emms-simple-player takes a minimum of three arguments. The first argument (play in our example) defines the name of the player. It's used to name the player functions. The second is a regexp, that defines which files to play with our player. \\.wav$ matches any filename ending with a dot and the string wav. The last argument is the actual command line command we use to play our files. You can also add the path but we just assume that the command is in your path. All arguments you add to these three are optional. They define the command line arguments you want to add to your argument. If you want to hear the wav file of your favourite artist in the most possible volume use the following line:

     (require 'emms-player-simple)

     (define-emms-simple-player play
                                '(file)
                                "\\artist-*.wav$"
                                "play"
                                "--volume=100")

Please notice that you have to add the arguments as strings!

The command line tool you use for define-emms-simple-player has to take one song as argument and stop after playing that particular song. For any other concept you will need to customise emms a bit more...

More Complex Player
===================

The most players you use will be simple players so you don't need to read this chapter. But if you are curious how you can use (almost) every player in emms read further...

In this chapter we will use mpg321 to construct a player that actually can pause a track, restart it and show rest time. We won't implement all of that, but after that chapter you will know how to define it.

The command define-emms-simple-player is just a abstraction layer for define-emms-player, which is a little bit more complicated but much more powerful!

     (define-emms-player "emms-mpg321-remote"
       :start 'emms-mpg321-remote-start
       :stop 'emms-mpg321-remote-stop
       :playablep 'emms-mpg321-remote-playable-p)

So, that is almost all! define-emms-player takes a minimum of three arguments. The first is the name of the player. The rest are methods with functions to call. Three methods are required: start, stop and playable. Start says Emms how to start a track (sic!), stop how to stop a player and playablep should return non-nil if the player can play the track.

So we just need these three functions to get our mpg321-remote:

First we code the start function. We will check if there's a open process and start one otherwise. Then we send a string to the process with the filename and set a filter.

     (defun emms-mpg321-remote-start ()
       (unless (get-process ``mpg321-remote'')
         (setq emms-mpg321-remote-process
     	  (start-process "mpg321-remote-process"
     			 "*mpg321*" "mpg321" "-R" "abc"))
       (process-send-string "mpg321-remote-process"
     		       (concat "l " (emms-track-name track)))
       (set-process-filter emms-mpg321-remote-process 'emms-mpg321-remote-filter)))

We need the filter, as mpg321-remote won't quit after playing the track as the simple player do. We wait until the process send the output ``@P 0'' (the signal of mpg321 that the song ended) to the filter and call emms-mpg321-remote-stop.

     (defun emms-mpg321-remote-filter (process output)
       (when (string-match "@P 0" output)
         (emms-mpg321-remote-stop)))

emms-mpg321-remote-stop won't do anything interesting. It just test if there are other files to play and close the process otherwise.

     (defun emms-mpg321-remote-stop ()
       (unless emms-playlist
         (process-send-string "mpg321-remote-process" "Q\n"))

And to make that a playable example i also added emms-mpg321-remote-playablep, which i just really steal from emms-player-simple.el

     (defun emms-mpg321-remote-playablep (track)
            "Return non-nil when we can play this track."
            (and (eq 'file (emms-track-type track))

Now we have a ready player and we could add commands like emms-mpg321-remote-pause for example.

Streaming Audio
***************

Emms provides a friendly interface for managing and playing streaming audio in addition to the Emms playlist interface. The interface is defined in the emms-streams.el package and can be loaded by invoking:

     (require 'emms-streams)

The Emms interface for streaming audio is enabled by default in the `emms-all' and `emms-devel' setup levels. For more information about Emms setup levels see Simple Setup.

Enter the emms-streams interface by invoking M-x emms-streams. The emms-streams interface comes with a built-in, eclectic list of streaming audio channels from throughout the Web. Emms can of-course play other streams than the ones listed by default, you are free to remove any or all of them and add your own. (If you enjoy a particular streaming audio station on the Web and think that it belongs in the default list, please send us a link and we will gladly add it!)

The following is a list of the key-bindings for the emms-streams interface:

RET
     Perform the default action when you press RET in the Emms Stream interface. Can be either ``add'' or ``play''. The default is ``add'', which adds the station under point to the Emms playlist. When EMMS-STREAM-DEFAULT-ACTION is ``play'' then Emms will play the streaming audio channel under point.

q
     Quit the emms-streams interface.

a
     Add a bookmark to a streaming audio URL to the list.

d
     Remove a bookmark to a streaming audio URL from the list.

e
     Edit the details of the bookmark under point.

h
     Describe the emms-streams mode.

n
     Move to the next line in the emms-streams buffer (same as C-n).

p
     Move to the previous line in the emms-streams buffer (same as C-p).

s
     Save the bookmarks in the emms-streams interface to disk. The bookmarks will be to the location designated in the variable EMMS-STREAM-BOOKMARKS-FILE.

i
     Return information about the streaming audio at the URL of the bookmark under point. Note that this will only work if the `emms-stream-info' has already been loaded.

     [file gpl.texi not included]
     [file fdl.texi not included]