~hristoast/hristoast

hristoast/site/mpd-local-listening.html -rw-r--r-- 9.1 KiB
4c97c4e5Hristos N. Triantafillou No more zen2 7 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<h1 id="title">MPD for local listening</h1>

<div id="dates">
  <span>Posted: <time id="post-date">2016-03-27</time> | Updated: <time>2017-02-25</time></span>
</div>

<p>
  <span class="bold">UPDATE!</span> Check out <a href="/mpd-through-a-bluetooth-speaker/">my other post on MPD</a> to see how some of the flaws of the setup described here are resolved!
</p>

<p id="post-excerpt">
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.
</p>

<p>
For a few years now, I've been using (and still really like) <a href="https://clementine-player.org/">Clementine</a>, 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?
</p>

<p>
In this (long) post I'll talk about using MPD for local listening enjoyment!
</p>

<div id="toc"></div>

<h3 class="bold">Options</h3>

<p>
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 <a href="http://www.musicpd.org/">MPD</a> and <a href="http://rybczak.net/ncmpcpp/">ncmpcpp</a>, a few other options are worth mentioning.
</p>

<h4 class="bold">Deadbeef</h4>

<p>
A former colleague of mine once recommended <a href="http://deadbeef.sourceforge.net/">DeaDBeeF</a>. Read more about it <a href="http://deadbeef.sourceforge.net/about.html">here</a>, but suffice it to say it's a lightweight player with a clutter-free UI. It was just a bit <span class="italics">too</span> minimalist for me.
</p>

<h4 class="bold">mpc</h4>

<p>
I actually have <code>mpc</code> installed but I don't use it very often. As is <a href="http://www.musicpd.org/clients/mpc/">advertised on the MPD site</a>, "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.

<pre><code class="language-bash">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</code></pre>

</p>

<h3 class="bold">A different kind of setup.</h3>

<p>
As always, I'll be using <a href="http://www.voidlinux.eu/">Void Linux</a> which, among other differences from more common distros, uses <a href="http://smarden.org/runit/faq.html">runit</a> 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!
</p>

<p>
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 <a href="https://en.wikipedia.org/wiki/Daemon_%28computing%29">daemon</a> 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!
</p>

<h3 class="bold">MPD</h3>

<p>
In configuring MPD, I've got two goals:

<ol>
<li>Run as a service in the background, so I can use it in my desktop sessions</li>
<li>Enable visualizations (more on this later)</li>
</ol>

So first thing's first, let's install it:
</p>

<p><pre><code class="language-bash">larry@soma:(~) ➜ sudo xbps-install mpd</code></pre></p>

<p>
Once MPD is installed, you'll find the global configuration file at <code>/etc/mpd.conf</code> 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.
</p>

<h4 class="bold"><code>/etc/mpd.conf</code></h4>

<p>
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 <code>mpd.conf</code> that I am currently using (even as I type this!):
</p>

<p>
<pre><code class="language-bash">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"
}</code></pre>
</p>

<p>
As you can see, there isn't a whole lot going on here since I stripped out all comments and extra things:
</p>

<p><pre><code class="language-bash">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"</code></pre></p>

<p>
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.
</p>

<p><pre><code class="language-bash">audio_output {
	type	"pulse"
	name	"MPD"
}</code></pre></p>

<p>
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.
</p>

<p><pre><code class="language-bash">audio_output {
	type	"fifo"
	name	"Visualizer"
	path	"/tmp/mpd.fifo"
	format	"44100:16:2"
}</code></pre></p>

<p>
<a href="https://wiki.archlinux.org/index.php/Ncmpcpp#Enabling_visualization">This link on the Arch Linux wiki</a> 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.
</p>

<h4 class="bold">Running MPD</h4>

<p>
Since I want to run MPD as my login user, I've got to make a slight modification to the runit init script (<code>/etc/sv/mpd/run</code>):
</p>

<p><pre><code class="language-bash">#!/bin/sh
install -d -m 0755 -o larry -g larry /run/mpd
exec mpd --no-daemon --stderr --stdout /etc/mpd.conf</code></pre></p>

<p>
Now, all that's left to do is enable MPD with runit:
</p>

<p><pre><code class="language-bash">larry@soma:(~) ➜ sudo ln -s /etc/sv/mpd /var/service/</code></pre></p>

If your configuration is good, MPD will be running within a few seconds. If not, try manually running mpd with the <code>--stderr</code> and <code>--no-daemon</code> options.

<h3 class="bold">ncmpcpp</h3>

<p>
ncmpcpp requires no configuring to use, though we will add a few config options for the visualizer. First, install it:
</p>

<p><pre><code class="language-bash">larry@soma:(~) ➜ sudo xbps-install ncmpcpp</code></pre></p>

<p>
The local config file, <code>$HOME/.ncmpcpp/config</code>, may or may not exist. If it doesn't, create it; if it does, rename it and start from scratch.
</p>

<h4 class="bold"><code>$HOME/.ncmpcpp/config</code></h4>

<p>
This file will contain configuration options for the visualizer, taken from <a href="">the Arch Linux wiki page on ncmpcpp</a>:
</p>

<p><pre><code class="language-bash">visualizer_fifo_path = "/tmp/mpd.fifo"
visualizer_output_name = "Visualizer"
visualizer_sync_interval = "30" 
visualizer_in_stereo = "yes"
visualizer_type = "spectrum"
visualizer_look = "+|"</code></pre></p>

<p>
There are likely more options -- go nuts if you want to! Otherwise, this is enough for the visualizer to work.
</p>

<h4 class="bold">Running ncmpcpp</h4>

<p>
Now you're ready to jam! Run the <code>ncmpcpp</code> in your favorite terminal to get started. You may want to ensure the <code>F1</code> 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.
</p>

<p>
On that note: at this point you should be able to use <code>ncmpcpp</code> 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.
</p>

<p>
<a href="https://i.imgur.com/NxWSoie.jpg">Here</a>'s a screenshot of my visualizer in action. Great Job!
</p>

<h3 class="bold">BONUS: emms bindings for Emacs</h3>

<p>
As a fun bonus - <a href="https://github.com/hristoast/dot-emacs/blob/50d2c1e4c8e0d72048341f14f8b42ba09fb900cb/init.el#L258-L275">emms configs and key bindings for Emacs</a> to interact with your new MPD setup!
</p>

<p>
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, <code>mpc</code>, <code>ncmpcpp</code>, any other MPC client that exists -- or all of them at once!
</p>