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