Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to adjust fade duration #779

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion feeluown/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions feeluown/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +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='淡入淡出持续时间')
return config
8 changes: 5 additions & 3 deletions feeluown/player/mpvplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Loading