From c0f8a0334c75e4124ddad98fd344c7a5e9ba55d0 Mon Sep 17 00:00:00 2001 From: poly000 <1348292515@qq.com> Date: Sun, 21 Jan 2024 21:14:59 +0800 Subject: [PATCH 1/3] feat: allow to adjust fade duration --- feeluown/app/app.py | 3 ++- feeluown/app/config.py | 1 + feeluown/player/mpvplayer.py | 8 +++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/feeluown/app/app.py b/feeluown/app/app.py index e935d46932..ff02a20ddd 100644 --- a/feeluown/app/app.py +++ b/feeluown/app/app.py @@ -59,7 +59,8 @@ def __init__(self, args, config, **kwargs): # Player. self.player = Player( audio_device=bytes(config.MPV_AUDIO_DEVICE, 'utf-8'), - fade=config.PLAYBACK_CROSSFADE + fade=config.PLAYBACK_CROSSFADE, + fade_time_ms=config.PLAYBACK_CROSSFADE_DURATION, ) # Theoretically, each caller maintain its own position delegate. # For simplicity, this delegate is created for common use cases and diff --git a/feeluown/app/config.py b/feeluown/app/config.py index 6c874a5304..2c04cee505 100644 --- a/feeluown/app/config.py +++ b/feeluown/app/config.py @@ -32,4 +32,5 @@ def create_config() -> Config: desc='切换歌曲时显示桌面通知') config.deffield('NOTIFY_DURATION', type_=int, default=3000, desc='桌面通知保留时长(ms)') config.deffield('PLAYBACK_CROSSFADE', type_=bool, default=False, desc='播放暂停淡入淡出') + config.deffield('PLAYBACK_CROSSFADE_DURATION', type_=int, default=500, desc='淡入淡出持续时间') return config diff --git a/feeluown/player/mpvplayer.py b/feeluown/player/mpvplayer.py index a787551601..52983b4ec3 100644 --- a/feeluown/player/mpvplayer.py +++ b/feeluown/player/mpvplayer.py @@ -32,7 +32,8 @@ class MpvPlayer(AbstractPlayer): todo: make me singleton """ - def __init__(self, _=None, audio_device=b'auto', winid=None, fade=False, **kwargs): + def __init__(self, _=None, audio_device=b'auto', winid=None, + fade=False, fade_time_ms=500, **kwargs): """ :param _: keep this arg to keep backward compatibility """ @@ -87,6 +88,7 @@ def __init__(self, _=None, audio_device=b'auto', winid=None, fade=False, **kwarg self.do_fade = fade if self.do_fade: self.fade_lock = RLock() + self.fade_time_ms = fade_time_ms def shutdown(self): # The mpv has already been terminated. @@ -171,12 +173,12 @@ def fade_curve(k: float, fade_in: bool) -> float: def set_volume(max_volume: int, fade_in: bool): # https://bugs.python.org/issue31539#msg302699 if os.name == "nt": - freq = 25 interval = 0.02 else: - freq = 50 interval = 0.01 + freq = int(self.fade_time_ms / 1000 / interval) + for _tick in range(freq): new_volume = math.ceil( fade_curve(_tick/freq, fade_in=fade_in)*max_volume From 47529af63ad6f25f5e055caea1afb501623e5acf Mon Sep 17 00:00:00 2001 From: poly000 <1348292515@qq.com> Date: Sun, 21 Jan 2024 22:22:37 +0800 Subject: [PATCH 2/3] chore: fix pylint --- feeluown/app/config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/feeluown/app/config.py b/feeluown/app/config.py index 2c04cee505..8f4b7930ce 100644 --- a/feeluown/app/config.py +++ b/feeluown/app/config.py @@ -32,5 +32,6 @@ def create_config() -> Config: desc='切换歌曲时显示桌面通知') config.deffield('NOTIFY_DURATION', type_=int, default=3000, desc='桌面通知保留时长(ms)') config.deffield('PLAYBACK_CROSSFADE', type_=bool, default=False, desc='播放暂停淡入淡出') - config.deffield('PLAYBACK_CROSSFADE_DURATION', type_=int, default=500, desc='淡入淡出持续时间') + config.deffield('PLAYBACK_CROSSFADE_DURATION', type_=int, + default=500, desc='淡入淡出持续时间') return config From a6ab0ed270e1fff7850205c00ac5619391bfcc36 Mon Sep 17 00:00:00 2001 From: poly000 <1348292515@qq.com> Date: Sun, 21 Jan 2024 22:31:20 +0800 Subject: [PATCH 3/3] fix flake8 lint --- feeluown/player/mpvplayer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feeluown/player/mpvplayer.py b/feeluown/player/mpvplayer.py index 52983b4ec3..2f366f2473 100644 --- a/feeluown/player/mpvplayer.py +++ b/feeluown/player/mpvplayer.py @@ -33,7 +33,7 @@ class MpvPlayer(AbstractPlayer): todo: make me singleton """ def __init__(self, _=None, audio_device=b'auto', winid=None, - fade=False, fade_time_ms=500, **kwargs): + fade=False, fade_time_ms=500, **kwargs): """ :param _: keep this arg to keep backward compatibility """