From 48b7d6d36d562284ee3da4538d5b5990306bb45d Mon Sep 17 00:00:00 2001 From: kaliko Date: Fri, 6 Aug 2010 12:40:07 +0000 Subject: [PATCH] * nalbum : new fade out/in feature for album transition * startop.py : some comments --- lib/startop.py | 6 ++++-- nalbum | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/lib/startop.py b/lib/startop.py index 44cb64a..945e5bb 100644 --- a/lib/startop.py +++ b/lib/startop.py @@ -51,12 +51,14 @@ class StartOpt(object): """ """ - def __init__(self, script_info, options):#{{{ + def __init__(self, script_info, child_options):#{{{ self.parser = None self.cli_options = dict({}) self.cli_args = dict({}) self.info = dict(script_info) - self.options = list(options + OPTS) + # options allows to add new cli options within child objects calling + # parent __init__() + self.options = list(child_options + OPTS) self.main()#}}} def declare_opts(self):#{{{ diff --git a/nalbum b/nalbum index a0ed04f..c2e3110 100755 --- a/nalbum +++ b/nalbum @@ -21,28 +21,62 @@ import sys +from time import sleep + from lib.mpdclass import MPDClass from lib.startop import StartOpt NAME = 'nalbum' VERSION = '0.1' +NALBUM_OPTS = list([ + { + 'sw': ['-c', '--crossfade'], + 'type': 'int', + 'dest': 'time', + 'metavar': 't', + 'help': 'fade out/fade in over t seconds.'}, + ]) + + class Nalbum(StartOpt, MPDClass): """ """ script_info = dict({ 'version': VERSION, 'prog_name': NAME, - 'description': 'Seek to next album in playlist.', + 'description': 'Jump to next album in playlist.', }) def __init__(self): """""" - StartOpt.__init__(self, self.__class__.script_info, []) + StartOpt.__init__(self, self.__class__.script_info, NALBUM_OPTS) MPDClass.__init__(self) self._run() - def _get_next(self): + def _fade(self, io='out'):#{{{ + """ + end_volum => End volume value + mpd_vol => Start volume value + """ + mpd_vol = int(self.init_vol) + if io == 'out': + end_volum = mpd_vol / 10 + mpd_vol = self.init_vol + if io == 'in': + end_volum = int(self.init_vol) + mpd_vol = int(self.init_vol) / 10 + span = float(end_volum - mpd_vol) + step = span / float(10*self.cli_options.time) + while 42: + mpd_vol += step + self.client.setvol(int(mpd_vol)) + if abs(mpd_vol - end_volum) < 1: + self.client.setvol(end_volum) + return True + sleep(0.1)#}}} + + def _get_next(self):#{{{ """Retrieve playlist from current song to the end.""" if 'song' not in self.client.status(): print "No current song set in MPD!" @@ -62,13 +96,19 @@ class Nalbum(StartOpt, MPDClass): sys.exit(0) album = self.client.playlistinfo(next_album_pos)[0].get('album', 'TAG MISSING') print 'Next album appears to be: "%s"' % album - return next_album_pos + return next_album_pos#}}} def _run(self): """""" print 'Connecting %s:%i' % (self.cli_options.host, self.cli_options.port) self.mpdConnect() + self.init_vol = int(self.client.status().get('volume')) + if self.cli_options.time: + print 'Cross fading next album' + self._fade() self.client.play(self._get_next()) + if self.cli_options.time: + self._fade(io='in') self.client.disconnect() sys.exit(0) -- 2.39.5