MPD for local listening
UPDATE! Check out my latest post on MPD to see an updated writeup on my MPD setup and usage.
Recently, out of a desire to use less memory while listening to music, I've been exploring different ways of listening to music under GNU/Linux. There's a wealth of GUI-based as well as terminal-based music playing itrfaces out there, and I've never really been a fan of most of them. Terminal-based players never appealed to me; I'm not someone who needs to do everything in the terminal and find it limiting for some things.
For a few years now, I've been using (and still really like) Clementine, but the size of my collection (more than 10,000 tracks) causes it to use quite a bit of memory. This becomes a problem when I'm doing other things that are also memory-hungry (virtual machines, games, most anything java) and I start swapping. But what are the options if you want something minimal?
In this (long) post I'll talk about using MPD for local listening enjoyment!
→ Options
For me, one of the great things about using GNU/Linux is the amount of choice that's available. Some folks find this annoying, and that's understandable, but it really is an advantage - if not a potentially time-consuming one. Although I'll be pitching MPD and ncmpcpp, a few other options are worth mentioning.
→ Deadbeef
A former colleague of mine once recommended DeaDBeeF. Read more about it here, but suffice it to say it's a lightweight player with a clutter-free UI. It was just a bit too minimalist for me.
→ mpc
I actually have mpc
installed but I don't use it very often. As is advertised on the MPD site, "A minimalist command line interface to MPD." It's pretty powerful and could allow for some neat scripts, but I haven't yet had a need to use it too much.
larry@soma:(~) ➜ mpc
The Slackers - Running From Safety (Feat. Chris Murray)
[paused] #1631/2009 1:01/2:48 (36%)
volume: 89% repeat: off random: off single: off consume: off
→ A different kind of setup.
As always, I'll be using Void Linux which, among other differences from more common distros, uses runit for service management and process supervision. If you're stuck in systemd land I suggest giving it a try. This is significant because it will affect how we run MPD. More on this later... now on with the details!
Using MPD in general is different than what you might be used to, but if you're familiar with running services under *nix systems you'll quickly begin to "get it." For starters, as the name implies MPD is a daemon and not necessarily a user-facing program, like most music players. And also as the name implies, pretty much all it does is play music!
→ MPD
In configuring MPD, I've got two goals:
- Run as a service in the background, so I can use it in my desktop sessions
- Enable visualizations (more on this later)
larry@soma:(~) ➜ sudo xbps-install mpd
Once MPD is installed, you'll find the global configuration file at /etc/mpd.conf
as well as a runit init script for the service. We'll need to make edits to both files, so it might not be a terrible idea to save copies of the vanilla files in case you want to do further edits on your own.
→ /etc/mpd.conf
There are a huge number of options for configuration, but thankfully there is also a decent amount of good information about how to use them - both in the file itself as comments or in other sources out there on the intertubes. Below is the mpd.conf
that I am currently using (even as I type this!):
music_directory "/home/larry/music"
playlist_directory "/home/larry/.mpd/playlists"
db_file "/home/larry/.mpd/mpd.db"
pid_file "/run/mpd/mpd.pid"
state_file "/home/larry/.mpd/mpdstate"
user "larry"
restore_paused "yes"
audio_output {
type "pulse"
name "MPD"
}
audio_output {
type "fifo"
name "Visualizer"
path "/tmp/mpd.fifo"
format "44100:16:2"
}
As you can see, there isn't a whole lot going on here since I stripped out all comments and extra things:
playlist_directory "/home/larry/.mpd/playlists"
db_file "/home/larry/.mpd/mpd.db"
pid_file "/run/mpd/mpd.pid"
state_file "/home/larry/.mpd/mpdstate"
user "larry"
restore_paused "yes"
Since I want to have full access to MPD and all it does from my desktop session, I set various options to run it as my user as well place playlists and statefiles under my home directory. The last part, as the name implies, pauses MPD at startup rather than playing tunes right away.
audio_output {
type "pulse"
name "MPD"
}
Here is where we run the stream that we'll be listening to. You can probably get more detailed with your options here but this will get you going.
audio_output {
type "fifo"
name "Visualizer"
path "/tmp/mpd.fifo"
format "44100:16:2"
}
This link on the Arch Linux wiki talks about both the MPD and ncmpcpp parts of it - but here we are setting up the usage of an algorithm which create visualizations from the music we listen to. More on this in a bit.
→ Running MPD
Since I want to run MPD as my login user, I've got to make a slight modification to the runit init script (/etc/sv/mpd/run
):
#!/bin/sh
install -d -m 0755 -o larry -g larry /run/mpd
exec mpd --no-daemon --stderr --stdout /etc/mpd.conf
Now, all that's left to do is enable MPD with runit:
larry@soma:(~) ➜ sudo ln -s /etc/sv/mpd /var/service/
If your configuration is good, MPD will be running within a few seconds. If not, try manually running mpd with the --stderr
and --no-daemon
options.
→ ncmpcpp
ncmpcpp requires no configuring to use, though we will add a few config options for the visualizer. First, install it:
larry@soma:(~) ➜ sudo xbps-install ncmpcpp
The local config file, $HOME/.ncmpcpp/config
, may or may not exist. If it doesn't, create it; if it does, rename it and start from scratch.
→ $HOME/.ncmpcpp/config
This file will contain configuration options for the visualizer, taken from the Arch Linux wiki page on ncmpcpp:
visualizer_fifo_path = "/tmp/mpd.fifo"
visualizer_output_name = "Visualizer"
visualizer_sync_interval = "30"
visualizer_in_stereo = "yes"
visualizer_type = "spectrum"
visualizer_look = "+|"
There are likely more options -- go nuts if you want to! Otherwise, this is enough for the visualizer to work.
→ Running ncmpcpp
Now you're ready to jam! Run the ncmpcpp
in your favorite terminal to get started. You may want to ensure the F1
key isn't used by your terminal, or change the ncmpcpp binding for the help page because you will want to be able to access that.
On that note: at this point you should be able to use ncmpcpp
to play your tunes! I recommend taking the time to look through the entire help page to get a feel for how to use it.
Here's a screenshot of my visualizer in action. Great Job!
→ BONUS: emms bindings for Emacs
As a fun bonus - emms configs and key bindings for Emacs to interact with your new MPD setup!
Part of what's awesome about using MPD is the server/client relationship that's at play when you use it. This means that you can use Emacs/emms, mpc
, ncmpcpp
, any other MPC client that exists -- or all of them at once!