Add volume slider to the transport bar

A slim horizontal master-volume slider in its own slot between the
visualizer and the timeline (TASKS.md). Perceptual->linear gain so it
ramps like iTunes; persists to preferences.json (debounced so it doesn't
thrash the theme). Clicking jumps to the spot via a new ClickJumpSlider
base extracted from SeekSlider.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-26 21:21:00 -04:00
co-authored by Claude Opus 4.8
parent 45bc8518a3
commit bb31e9e5cc
4 changed files with 174 additions and 5 deletions
+21 -1
View File
@@ -3,7 +3,7 @@ from pathlib import Path
from PyQt6.QtCore import QObject, QUrl, pyqtSignal
from PyQt6.QtMultimedia import (
QMediaPlayer, QAudioOutput, QAudioBufferOutput, QMediaDevices)
QMediaPlayer, QAudioOutput, QAudioBufferOutput, QMediaDevices, QAudio)
from lintunes.models import Track
@@ -53,6 +53,7 @@ class Player(QObject):
self._counted_finish_id: int | None = None
self._audio = QAudioOutput(self)
self._volume = 1.0 # logical 0..1; what the volume slider shows
self._media = QMediaPlayer(self)
self._media.setAudioOutput(self._audio)
# Tee of the decoded PCM, feeding the visualizer
@@ -138,6 +139,25 @@ class Player(QObject):
def duration_ms(self) -> int:
return self._media.duration()
# ---- volume ----
def set_volume(self, level: float):
"""Set output volume from a logical 0..1 value (0=silent, 1=full).
The slider scale is perceptual, so convert to the linear gain
QAudioOutput expects — that makes the knob feel iTunes-like rather
than jumping to "loud" in the first few percent."""
level = max(0.0, min(1.0, float(level)))
self._volume = level
self._audio.setVolume(QAudio.convertVolume(
level,
QAudio.VolumeScale.LogarithmicVolumeScale,
QAudio.VolumeScale.LinearVolumeScale,
))
def volume(self) -> float:
"""The logical 0..1 volume last set (what the slider shows)."""
return self._volume
# ---- transport ----
def toggle_play(self):