Projects :: EMPCd - Event Music Player Client daemon

EMPCd - Event Music Player Client daemon

USB numpad Keyboard

This is EMPCd which can use for instance /dev/input/event0 or other event devices to control MPD (Music Player Daemon), directly using libmpdclient and other programs by executing them using a system(2) call.

The right hand picture shows an USB numpad keyboard which was connected to paradise.ch.unfix.org. The keyboard's keys are coupled using empcd to control Music Player Daemon allowing easy next/prev, volume up/down and other functions as depicted below. Of course, this can all be customized to your hearts desire.

Limitations

  • Only events of type EV_KEY are supported, thus no Force Feedback Joysticks yet (can be done easily as the code is extendable and flexible)
  • Hardcoded maximum of 100 configurable events (can be changed in source)
  • Currently abuses libmpdclient from the mpc distribution though it needs to use the dynamically linked version (requires debian libmpdclient developer deb)

Contact, Bug Reports, Feature Requests etc

Found a bug? Need something different?
One can use the Issue tracker at GitHub for reporting patches/fixes/comments/issues etc.

Download

Bleeding Edge version:

Current version:

Older versions:

Help

$ /usr/sbin/empcd -V
empcd 2008.02.16 by Jeroen Massar <jeroen@massar.ch>
$ /usr/sbin/empcd -h
usage: /usr/sbin/empcd
-c -config          <file>          Configuration File Location
-d -daemonize                       Detach the program into the background
-f -nodaemonize                     Don't detach, stay in the foreground
-e -eventdevice     <eventdevice>   The event device to use, default: /dev/input/event0
-h -help                            This help
-K -list-keys                       List the keys that are known to this program
-L -list-functions                  List the functions known to this program
-q -quiet                           Lower the verbosity level to 0 (quiet)
-u -user            <username>      Drop priveleges to <user>
-v -verbose                         Increase the verbosity level by 1
-V -version                         Show the version of this program
-y -verbosity       <level>         Set the verbosity level to <level>
-x -exclusive                       Exclusive device access (default)
-X -nonexclusive                    Non-Exclusive device access

Functions

exec <shellcmd>             Execute a command
mpd_next                    MPD Next Track
mpd_prev                    MPD Previous Track
mpd_stop                    MPD Stop Playing
mpd_play                    MPD Start Playing
mpd_pause [toggle|on|off]   MPD Pause Toggle or Set
mpd_seek [+|-]<val>[%]      MPD Seek direct or relative (+|-), percentage when ends in %
mpd_volume [+|-]<val>[%]    MPD Volume direct or relative (+|-), percentage when ends in %
mpd_random [toggle|on|off]  MPD Random Toggle or Set
mpd_plst_load <playlist>    MPD Load Playlist
mpd_plst_save <playlist>    MPD Save Playlist
mpd_plst_clear              MPD Clear Playlist
mpd_plst_remove <playlist>  MPD Remove Playlist

Notes

  • For security reasons, always use the 'user' option where possible, this to limit what can be done by mpd, it has a system() command thus can do almost everything.
  • Exclusive mode steals all your keypresses, disable this option if you are accessing the host through an input device, eg your keyboard

Short "How to use"

  • Download the archive or the deb
  • For the debian package, just dpkg -i package.deb; /etc/init.d/empcd stop (as it autostarts)
  • For the tarball, tar -zxvlof package.tar.gz; cd empcd[tab]; make install;
  • You will now have an empcd binary in /usr/sbin/, now you will have to configure it.
  • Edit the configuration file (/etc/empcd.conf) using your favourite vi flavor.
  • You can find the supported keys and functions using '/usr/sbin/empcd -K' and '/usr/sbin/empcd -L' respectively.
  • Using '/usr/sbin/empcd -y 9 -f' the program will be very verbose and run in the foreground, this will show you which buttons you are pressing, thus you don't have to look them up then.

Configuration File


#########################################################
# ecmpd.conf by Jeroen Massar <jeroen@massar.ch>
# Example empcd configuration file
#
# Lines starting with '#' or '//' are comment lines
# Repeating spaces and tabs are trimmed
#########################################################

#########################################################
# MPD settings
#########################################################
# Run empcd under the 'mpd' account
user mpd

# mpd_host [<password>@]<host> (defaults to "localhost")
mpd_host pass@mpd.example.com

# mpd_port <port> (defaults to 6600)
mpd_port 6600

# Device to read events from
//eventdevice /dev/input/event0

# Exclusive (default) / Non-Exclusive device access
//exclusive
//exclusive on
//exclusive off
//nonexclusive

#########################################################
# Key configuration
#########################################################
#
# key <key-id> up|down|repeat <function> [arguments]
#
# down   = key gets pressed down
# up     = key goes up (after being pressed down)
# repeat = key is kept down and sends repeat events
#
# functions (also see 'empcd --list-functions'):
# exec <shellcmd>       Execute a shell command (eg exec mount /dev/sdb2 /mnt)
# mpd_next              MPD Next Track
# mpd_play              MPD Previous Track
# mpd_stop              MPD Stop Playing
# mpd_play              MPD Start Playing
# mpd_pause [on|off]    MPD Pause Toggle (no options) or set
# mpd_seek              MPD Seek
#                       "mpd_seek 0"   - begin of track
#                       "mpd_seek 100" - begin of track
#                       "mpd_seek +10" - advance 10 seconds
#                       "mpd_seek -20" - backward 20 seconds
# mpd_random            MPD Random Toggle (no options) or set
#
#
#########################################################
# Play/Pause
key KEY_KP1             UP      mpd_play
key KEY_KP0             UP      mpd_pause

# Prev/Next
key KEY_KPMINUS         UP      mpd_prev
key KEY_KPPLUS          UP      mpd_next

# Seek to the beginning of the current song
key KEY_BACKSPACE       UP      mpd_seek 0

#  2 seconds back/forward on 1 hit,
# 10 seconds back/forward when holding
key KEY_KPSLASH         UP      mpd_seek -2
key KEY_KPSLASH         REPEAT  mpd_seek -10
key KEY_KPASTERISK      UP      mpd_seek +2
key KEY_KPASTERISK      REPEAT  mpd_seek +10

# Toggle random mode
key KEY_KPDOT           UP      mpd_random

# Pause button, hold it down to pause, release for resume
key KEY_KPENTER         DOWN    mpd_pause on
key KEY_KPENTER         UP      mpd_pause off

License

The license is a 3-clause BSD, only the copyright line has been changed.

(s/The Regents of the University of California/Jeroen Massar \/ Unfix/ & s/University/Unfix/)


Copyright (c) Jeroen Massar / Unfix.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. Neither the name of Unfix nor the names of its contributors
   may be used to endorse or promote products derived from this software
   without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.