]> kaliko git repositories - mpd-goodies.git/commitdiff
Remove external volume change detection in mfade
authorkaliko <kaliko@azylum.org>
Fri, 17 May 2019 08:59:25 +0000 (10:59 +0200)
committerkaliko <kaliko@azylum.org>
Fri, 17 May 2019 08:59:25 +0000 (10:59 +0200)
README.md
bin/mfade

index 6be0ecf36c595f57a941ab2a05f49c086b4cdc99..9a029f8a52430e99dc89c692b0cf504383879f95 100644 (file)
--- 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: )
index 61a68f305d166944c8cb6e3ece4a1b361db23cb2..9627a44b67637b7befebe0c426d3a2d220ff213d 100755 (executable)
--- 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