Files
phat-beat/mpdbox.md

3.2 KiB

MPD BOX on Pimoroni's Phat Beat / pirate radio

  1. Use Python Music Player Daemon as a service to play both local files and playlists (including radio urls) on the phat beat.

  2. Use beets (optionnaly ?) to organize / import the local music library

  3. Use MPD client lib in a python script running as a service. It will act as a MPD client to control the local MPD server service, through the phat beat buttons.

Others clients should be able to control played music through the local network. (Many android clients are available). Command-line client mpc is available.

Installation

Install MPD (server/daemon) and MPC (client)

apt-get install mpd mpc

mpc client won't be able to retrieve / adjust volume until editing configuration file at /etc/mpd.conf to replace line

audio_output {
  mixer_type "hardware"
}

by

audio_output {
  mixer_type "software"
}

Troubleshooting

Disable PiVumeter

If you tried the VLC radio project before, you may have to get rid of pivumter like this :

Try editing /etc/asound.conf and changing:

pcm.softvol_and_pivumeter {
        type softvol
        slave.pcm "pivumeter"
        control {
                name "PCM"
                card 0
        }
}

to:

pcm.softvol_and_pivumeter {
        type softvol
        slave.pcm "hw:0,0"
        control {
                name "PCM"
                card 0
        }
}

Removing /etc/asound.conf entirely will disable the alsamixer command, which may be used to set global sound level.

Roadmap

client service script still to do. See ideas below.

Controls

Use button holding (next / prev) to cycle through available playlists.

LED

Visual feedback when using buttons (setting volume / browsing playlist(s)).

Replace Pimoroni's green pivumeter by a rainbow one. Integrated within the client service or decoupled ?

Something along this :

def set_volume(self, level=3):
    if level >= 0 and level <= 8:
        self.volume = level
        self.player.set_volume(self.volume*12) # 0-96
        self.show_volume(level)

def volume_up(self, pin):
    self.set_volume(self.volume + 1)

def volume_down(self, pin):
    self.set_volume(self.volume - 1)

def show_volume(self, level, saturation=1.0, value=0.2):
    phatbeat.clear()
    for i in range(0,8):
        # definition de la teinte en fonction de la "hauteur" du pixel
        # pour un effet "arc en ciel"
        # on divise 360° par 8 "crans" (=45°)
        # et on decale arbitrairement de 45° pour ne pas débuter sur rouge
        hue = 315 - 45*i # definition de la teinte (8 crans = 45°)
        if level > i:
            r, g, b = [int(x * 255) for x in colorsys.hsv_to_rgb(hue / 360.0, saturation, value)]
            phatbeat.set_pixel(7-i, r, g, b, 0.1, channel=0)
            phatbeat.set_pixel(7-i, r, g, b, 0.2, channel=1)
    phatbeat.show()

On the second led bar, show playlist or track progress ?

Maybe representing playlist as a color spectre and adjusting shown part of the spectre to available leds / size of the playlist ?