<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="article.xsl"?> 

<articles>
  <article date="10 Nov 2020" version="12.3">
    <pagetitle>Song library: engage!</pagetitle>
    <articleheader>Setting up MusicPD (mpd) and ncmpcpp under FreeBSD 12</articleheader>
    <articleabstract>I keep hearing how great mpc is, so I decided to try setting it up. </articleabstract>
    <articlebody>

<p>If you hang around certain circles on the Internet(tm), you'll eventually run across some people who are obsessed with efficiency and minimalism<sup class="inlinefootnote">1</sup>. I can get behind that sentiment (though I'm not a fanatic about it<sup class="inlinefootnote">2</sup>).</p>

<p>When the topic of media players comes up, the discussion seems to almost always point to mpd, mpc, and ncmpcpp. I've been using the Clementine Music Player, which is a good player. It hasn't seen any updates in several years, but It Still Works&#8482;, so that's nice, but I wanted to take a look to see how the other side lives, so to speak.</p>

<h3>What is mpd anyway?</h3>

<p><code>mpd</code> is the Music Player Daemon<sup class="inlinefootnote">3</sup>. It's a program that sits around and waits for another program to tell it to do something. Sometimes <code>mpc</code>, sometimes something else, but <code>mpd</code> doesn't have an interface of its own, so you can't control it directly.</p>

<h3>Problems</h3>

<p>Right away, I had trouble installing mpd. It turns out that there's another program called <code>mpd</code> in the FreeBSD repositories: <a href="https://www.freshports.org/net/mpd/">net/mpd5</a>, which is used for multi-link PPP connections<sup class="inlinefootnote">4</sup>. The companion program that's often bundled with <code>mpd</code> in Linux distributions is <code>mpc</code>, but there's another program called <code>mpc</code>, <a href="https://www.freshports.org/math/mpc/">math/mpc</a>, which is a 'Library of complex numbers with arbitrarily high precision', i.e. probably not what we want.</p>

<h3>Installation</h3>

<p>Now that we're thoroughly confused, it's time to install software! We'll want to install <code>audio/musicpd</code>, <code>audio/musicpc</code> and <code>audio/ncmpcpp</code><sup class="inlinefootnote">5</sup>. Since I use ports, I can install it with something like:</p>

<pre><code>portmaster -D audio/musicpd audio/musicpc audio/ncmpcpp</code></pre>

<p>Or I could install this from packages if I didn't feel like building these.</p>

<h3>Setup</h3>

<p>Setup is not as easy as I had hoped. Installing <code>musicpd</code> does a few things. It sets up a service that you can run if you want (spoiler: I do), it provides a configuration file with some questionable defaults, it creates a user named <code>mpd</code> with its home directory in <code>/var/mpd</code> that the service will run as (the service is called <code>musicpd</code>.</p>

<p><em>Whew!</em></p>

<p>Before starting to work on the config file (<code>/usr/local/etc/musicpd.conf</code>, I backed it up so I could get back to zero if I screwed something up.</p>

<p>My system has the current considerations:</p>

<ul>

<li>I have my music files stored in <code><a href="http://wyrm.org/freebsd/freebsdinstallnotes.xml">/outerspace</a></code></li>
<li>I commented out the line to use Unix sockets. The default is to listen on TCP port 6600<sup class="inlinefootnote">6</sup>. I couldn't get the player programs I tried to connect otherwise, probably due to user error</li>
</ul>

<p>My changed lines look something like this:</p>

<pre>/usr/local/etc/musicpd.conf
<code>music_directory   "/outerspace/music"</code>
<code>#bind_to_address  "/var/mpd/.mpd/socket"</code>
</pre>

<p>There are lots of other options that are pre-filled in with reasonable values, so I left them. Taking note of them, I noticed that they all have paths like <code>/var/mpd/.mpd/somedirectory</code>, and the problem is that <code>.../.mpd</code> and <code>somedirectory</code> (and, in some cases, <code>somefile</code>) don't exist, so I had to create these manually and assign ownership to the <code>mpd</code> user. Since I was very lazy and didn't bother writing down which folders and files it wanted, I tried to start up the <code>musicpd</code> daemon with <code>service musicpd onestart</code> and looked at the output to see what it was complaining about missing, then either <code>mkdir</code> the missing directory or <code>touch</code> the missing file and trying again. It turns out that this step wasn't needed for the <code>database</code> file. Even though <code>musicpd</code> complained that the database didn't exist, it created it anyway.</p>

<p>I kept <code>onestart</code>ing the service until the service actually started. I ended up creating the following directories:</p>

<ul>
<li><code>/var/mpd/.mpd</code></li>
<li><code>/var/mpd/.mpd/playlists</code></li>
</ul>

<p>And I ended up <code>touch</code>ing <code>/var/mpd/.mpd/database</code> even though I didn't really need to.</p>

<p>Once the service <code>onestart</code>ed without any griping I added <code>musicpd_enable="YES"</code> to my <code>rc.conf</code></p>

<p>Once it's started, nothing apparently happens. That's where musicpc comes in. Only the binary and the man page is named <code>mpc</code>, even though the port and package is <code>musicpc</code>. You can use <code>musicpc</code> to control <code>musicpd</code> and to do a whole lot more stuff than I'm going to list here. Right now I'm interested in seeing if <code>musicpd</code> can even see my music library. Running <code>mpc ls</code> will produce output if it does, and no output if it doesn't. If it doesn't, might need to check permissions on wherever the music files are stored, or <em>*gasp*</em> check the logs for errors. Once I was satisfied that it saw my library, I followed the man page's advice and ran <code>mpc ls | mpc add</code> to just add everything to the default playlist.</p>

<h3>Actually playing music</h3>

<p>Now, finally, I ran ncmpcpp and saw the ncmpcpp screen and a giant list of the music in my collection. I can search by using the forward-slash operator, I can play a track by hitting 'enter', I can stop playback with 's'. Since this isn't an ncmpcpp tutorial (mostly because I haven't learned that much about it yet), I can't tell you much more than that.</p>

<h3>Thoughts</h3>

<p>This was a bear to set up. Partially because the docs I found assume that you're running Linux (I'm not). It's nice that I can actually close ncmpcpp and the music will keep playing, and that the player seems to be more focused than Clementine-player is. I haven't decided yet if the amount of work I had to put in is outweighed by the benefit I'll get out of it.</p>

</articlebody>
    <footnotes>
      <footnote>Put another way, if you engage in <em>any</em> community even tangentially related to free and open source software you'll inevitably run across someone who is More Minimalist Than Thou&#8482; and will everyone within earshot know about it, completely missing the point that it's not a contest</footnote>
      <footnote>Yet</footnote>
      <footnote><a href="https://www.musicpd.org/">The mpd website</a> has a lot more information.</footnote>
      <footnote>Don't worry if you don't know what that is. Odds are that if you need to know what it is, you already know what it is.</footnote>
      <footnote><code>ncmpcpp</code> is the player that I'm going to use. It's got an awful name, but I don't think I have a better one to suggest</footnote>
      <footnote>Probably shoring up the firewall and/or adding a username/password to this is a good idea, but those are articles for another time</footnote>
    </footnotes>
  </article>
</articles>
