]> kaliko git repositories - mpd-goodies.git/blobdiff - bin/mfade
Fixed style
[mpd-goodies.git] / bin / mfade
index 61a68f305d166944c8cb6e3ece4a1b361db23cb2..4b8a6a137710a15c70c117d64f5fed541cdec596 100755 (executable)
--- a/bin/mfade
+++ b/bin/mfade
@@ -45,6 +45,7 @@ this command to work properly.
 
 Set MPD host/port in env. var"""
 
+
 class Sleep(musicpd.MPDClient):
     """"""
     script_info = dict({
@@ -97,8 +98,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 +118,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