# MPD-GOODIES
-A collection of small commands to play with [MusicPlayerDaemon]:
+A collection of commands to play with [MusicPlayerDaemon]:
* Fading in/out over a specified time
- * Jumping to next album en queue.
+ * Jumping to next album in queue.
* Last modified artist/album/tracks
* Crop the queue
+Commands do not expose options to set MPD host|port, use MPD_HOST/MPD_PORT environment variables.
+Defaults to /run/mpd/socket or localhost:6600 when no environment variables are set (cf. [python-musicpd]).
+
[MusicPlayerDaemon]: https://www.musicpd.org/
+[python-musicpd]: https://kaliko.gitlab.io/python-musicpd
+
+[//]: # ( vim:set spelllang=en spell: )
self.mpd_vol = int(self.status().get('volume'))
if not self.volum:
self.volum = self.mpd_vol // 10
- if self.volum > self.mpd_vol:
- print('Error: specified min volume (%d%%) > to current volume (%d%%)' % (
+ if self.volum >= self.mpd_vol:
+ print('Error: specified min volume (%d%%) >= to current volume (%d%%)' % (
self.volum, self.mpd_vol))
sys.exit(1)
print('fading down from %d%% to %d%% over %ss' % (self.mpd_vol, self.volum, self.tempo), file=sys.stdout)
def fade(self, mpd_vol, target):
""""""
# TODO: handle possible lost connections
+ resolution = 5
span = target - mpd_vol
- step = span / (10*self.tempo)
+ step = span / (resolution*self.tempo)
vol = mpd_vol
if step == 0:
return True
while True:
- if int(vol) != int(self.status().get('volume')):
- sys.stderr.write(
- 'Warning: external volume change, aborting!\n')
- return False
vol += step
- self.setvol(int(vol))
+ self.setvol(round(vol))
+ # monitor external volume change
+ # print(vol, round(vol), self.status().get('volume'))
if abs(vol - target) < 1.1*abs(step):
self.setvol(target)
return True
- sleep(.1)
+ sleep(1/resolution)
# Script starts here