danten.io

Debian: ncmpcpp, MPD & PulseAudio

Real DJ’s use ncmpcpp to play them grooves and keep the party stable.

ncmpcpp comes with an amazing user interface, and can easily connect to remote MPD servers, or you can simply SSH into the box and use ncmpcpp directly on the remote machine. This is really cool if you e.g have a sound system hooked up to a box - you can then chill out while DJ’ing remotely.

For many years - back in the time I was young and roaming the earth - I’d be using a small Asus Netbook running OpenBSD as a dedicated MPD server: I’ve learned to appreciate the speed & simplicity of “remote DJ’ing” using ncmpcpp as my MPD client.

Being described as a “featureful ncurses based MPD client inspired by ncmpc”, my favorite music player ncmpcpp is command line based and comes with some powerful features.

Main Features of ncmpcpp

My recommendation: Just go try it out, you might like it so much that you’ll never look back!

So how to install MPD and ncmpcpp, configure ‘em and get it all up running on a (de facto default) PulseAudio Debian box? So let’s break it down and take one step at a time…

Install and configure MPD

As usual, installing MPD is as easy as it gets:

$ apt install mpd

Configuration is pretty straight forward as well, here I’m using the system wide default Debian configuration located in /etc/mpd.conf:

music_directory         "/home/danten/Music"

Also, we’ll need to tell MPD to use PulseAudio, so let’s edit the first audio sink to look like this:

audio_output {
        type            "pulse"
        name            "Local Music Player Daemon"
    	mixer_type  	"software" # Or "hardware"
        server          "127.0.0.1"

And in case you’re one of those hard-core ALSA fan who believes PulseAudio is bloatware:

audio_output {
        type            "alsa"
        name            "Alsa for audio sound card"
        mixer_type      "software"      # optional
}

That’s more/less it, or at least enough to get you up running.

On Debian with systemd, MPD will run as a system service automatically, you can disable that:

sudo systemctl disable mpd.service
sudo systemctl disable mpd.socket

On my Devuan box running sysvinit, you could start MPD “the old way”, by either issuing a mpd or via /etc/init.d/mpd start. To verify MPD is running you’d something like:

$ netstat -ltunp | grep 6600

or to get some more info you’d use ss:

$ ss -tunelp | grep 6600
tcp     LISTEN   0        5                      *:6600                 *:*      users:(("mpd",pid=778,fd=4),("systemd",pid=1,fd=57)) ino:19201 sk:12 v6only:0 <->

“Yeah”, you might be thinking, “now we’ve got MPD up running, but how do I play my music??

MPD - the music player daemon - has a server-client architecture. It allows you to play audio files, organize playlists and keep a music database using minimal resources on your system. But in order to interface with MPD, you’ll need a separate MPD client. This is where ncmpcpp comes in.

Install and configure ncmpcpp

And again, the installation part is easy:

$ apt install ncmpcpp

Configuration is pretty much straight forward. Usually I just take the standard configuration, copy it to ~/.ncmpcpp/config as described in the man page:

CONFIGURATION
       When  ncmpcpp starts, it tries to read user's settings from $HOME/.ncmpcpp/config and $XDG_CONFIG_HOME/ncmpcpp/config files. If no configuration is found, ncmpcpp uses its default configuration. An example configuration file containing all default values is provided with ncmpcpp and can be usually found in /usr/share/doc/ncmpcpp (exact location may depend on used distribution or configure prefix).

After a couple of minor edits it’ll look something like this:

#############################################################################
## This is the example configuration file. Copy it to $HOME/.ncmpcpp/config ##
## or $XDG_CONFIG_HOME/ncmpcpp/config and set up your preferences.          ##
###########################################################################
#
##### directories ######
##
## Directory for storing ncmpcpp related files.  Changing it is useful if 
## you want to store everything somewhere else and provide command line 
## setting for alternative location to config file which defines that while 
## launching ncmpcpp.
##
#
ncmpcpp_directory = ~/.ncmpcpp
#
##
## Directory for storing downloaded lyrics. It defaults to ~/.lyrics since 
## other MPD clients (eg. ncmpc) also use that location.
##
#
lyrics_directory = ~/.lyrics
#
##### connection settings #####
#
mpd_host = 127.0.0.1
#
mpd_port = 6600
#
mpd_connection_timeout = 5
#
## Needed for tag editor and file operations to work.
##
mpd_music_dir = /home/danten/Music
#
#mpd_crossfade_time = 5
#
##### music visualizer #####
##
## Note: In order to make music visualizer work you'll need to use mpd fifo
## output, whose format parameter has to be set to 44100:16:1 for mono
## visualization or 44100:16:2 for stereo visualization. Example 
## configuration (it has to be put into mpd.conf):
##
## audio_output {
##        type            "fifo"
##        name            "Visualizer feed"
##        path            "/tmp/mpd.fifo"
##        format          "44100:16:2"
## }
##
#
visualizer_fifo_path = /tmp/mpd.fifo
#
##
## Note: Below parameter is needed for ncmpcpp to determine which output
## provides data for visualizer and thus allow syncing between 
## visualization and sound as currently there are some problems with it.
##
#
visualizer_output_name = Visualizer Feedz
#
##
## If you set format to 44100:16:2, make it 'yes'.
##
visualizer_in_stereo = yes
#
##
## Note: Below parameter defines how often ncmpcpp has to "synchronize"
## visualizer and audio outputs.  30 seconds is optimal value, but if you
## experience synchronization problems, set it to lower value.  
## Keep in mind that sane values start with >=10.
##
#
visualizer_sync_interval = 30
#
##
## Note: To enable spectrum frequency visualization you need to compile 
## ncmpcpp with fftw3 support.
##
#
## Available values: spectrum, wave, wave_filled, ellipse.
##
visualizer_type = wave
#
visualizer_look = ●▮
#

If you really want to go all the way tweaking ncmpcpp and it’s sexy looks, you’ll find plenty of nice customizations in the /r/unixporn threads:

https://www.reddit.com/r/unixporn/search?q=ncmpcpp

Now that’s pretty much it… BUT:

What about PulseAudio?

So I realized my setup on Debian Buster played my stuff as expected when configured to use ALSA, but somehow PulseAudio would not pick up the sound stream. A final little tweak is needed.

Once again, the ArchLinux1 community with their excellent documentation provides tangible results aka it works! You’ll need to tell PulseAudio to load the native TCP protocol and bind that to localhost.

Simply edit the system-wide configuration file in /etc/pulse/default.pa

### here if you plan to use paprefs)
#load-module module-esound-protocol-tcp
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
#load-module module-zeroconf-publish

Then go kill it - and don’t worry, PulseAudio is pretty persistent and will resurrect itself:

$ pulseaudio --kill

As mentioned above when talking about configuring MPD, make sure that you’ve edited your /etc/mpd.conf to add the pulse output pointing to 127.0.0.1 as a “remote” server:

audio_output {
       type		"pulse"
       name		"Local Music Player Daemon"
       server		"127.0.0.1"
}

That’s it - fire up your ncmpccp and start DJ’ing! 😎

Oh, and while we’re at it, make sure you check out this ncmpcpp cheat sheet and use the number keys to switch/show the playlist view, the search engine, visualizer etc. Happy groovin’ folks!

:wq


  1. https://wiki.archlinux.org/title/Music_Player_Daemon/Tips_and_tricks#PulseAudio ↩︎

#Debian #Music #Linux