From: kaliko Date: Fri, 17 May 2019 08:59:25 +0000 (+0200) Subject: Remove external volume change detection in mfade X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=3c3b648efd0e9e2ce826b0ccb567c4af4fce9158;p=mpd-goodies.git Remove external volume change detection in mfade --- diff --git a/README.md b/README.md index 6be0ecf..9a029f8 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,16 @@ # 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: ) diff --git a/bin/mfade b/bin/mfade index 61a68f3..9627a44 100755 --- a/bin/mfade +++ b/bin/mfade @@ -97,8 +97,8 @@ class Sleep(musicpd.MPDClient): 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) @@ -117,22 +117,21 @@ class Sleep(musicpd.MPDClient): 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