v0.99.0: Boost Volume amplifies a quiet song's file up to a typical song's loudness (says how many dB and whether it clips; Edit ▸ Undo puts the original back), replacing the per-song Volume Adjustment, which could never play past full volume
This commit is contained in:
+3
-101
@@ -1,10 +1,9 @@
|
||||
"""Round 79: per-track volume, Get Info tidy-up, Preferences headings, and
|
||||
the laser rig diagram.
|
||||
|
||||
1. A track's volume adjustment (iTunes' "Volume Adjustment", already
|
||||
imported) scales the output while that track plays.
|
||||
2. Get Info edits it — one track or several — and has no dead
|
||||
Previous/Next buttons.
|
||||
1. (Retired in Round 131: the per-track volume adjustment, which could never
|
||||
play past full volume; Boost Volume amplifies the file instead.)
|
||||
2. Get Info has no dead Previous/Next buttons.
|
||||
3. Preferences section headings are bold and 2 px larger than the text.
|
||||
4. The laser page draws the rig, labelling distance, angles and dot size
|
||||
in place of those sliders' own numbers.
|
||||
@@ -15,62 +14,7 @@ from PyQt6.QtCore import QObject, pyqtSignal
|
||||
from PyQt6.QtGui import QFontInfo
|
||||
from PyQt6.QtWidgets import QApplication, QLabel, QPushButton
|
||||
|
||||
from lintunes.player import volume_with_adjustment, VOLUME_ADJUSTMENT_MAX
|
||||
from lintunes.preferences import Preferences
|
||||
from tests.test_round29 import _player, _local_track, _FakeSink
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# 1. The player
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
class TestVolumeAdjustment:
|
||||
def test_none_changes_nothing(self):
|
||||
assert volume_with_adjustment(0.6, 0) == 0.6
|
||||
|
||||
def test_minus_100_is_silence_and_plus_100_doubles(self):
|
||||
assert volume_with_adjustment(0.6, -VOLUME_ADJUSTMENT_MAX) == 0.0
|
||||
assert volume_with_adjustment(0.3, VOLUME_ADJUSTMENT_MAX) == 0.6
|
||||
|
||||
def test_never_past_full(self):
|
||||
assert volume_with_adjustment(0.8, VOLUME_ADJUSTMENT_MAX) == 1.0
|
||||
|
||||
def test_out_of_range_values_are_clamped(self):
|
||||
assert volume_with_adjustment(0.5, -10_000) == 0.0
|
||||
assert volume_with_adjustment(0.5, 10_000) == 1.0
|
||||
|
||||
def test_applied_when_the_track_loads(self, qapp, tmp_path):
|
||||
quiet = _local_track(tmp_path, 1, volume_adjustment=-128)
|
||||
plain = _local_track(tmp_path, 2)
|
||||
player = _player(qapp, [quiet, plain])
|
||||
sink = _FakeSink()
|
||||
player.set_sink(sink)
|
||||
player.set_volume(0.8)
|
||||
player.play_queue([1, 2], 0)
|
||||
assert sink.volume == pytest.approx(0.8 * (1 - 128 / 255))
|
||||
assert player.volume() == 0.8 # the slider is untouched
|
||||
player.next()
|
||||
assert sink.volume == pytest.approx(0.8)
|
||||
|
||||
def test_moving_the_slider_keeps_the_adjustment(self, qapp, tmp_path):
|
||||
track = _local_track(tmp_path, 1, volume_adjustment=255)
|
||||
player = _player(qapp, [track])
|
||||
sink = _FakeSink()
|
||||
player.set_sink(sink)
|
||||
player.play_queue([1], 0)
|
||||
player.set_volume(0.25)
|
||||
assert sink.volume == pytest.approx(0.5)
|
||||
|
||||
def test_an_edit_while_playing_applies_on_refresh(self, qapp, tmp_path):
|
||||
track = _local_track(tmp_path, 1)
|
||||
player = _player(qapp, [track])
|
||||
sink = _FakeSink()
|
||||
player.set_sink(sink)
|
||||
player.set_volume(0.6)
|
||||
player.play_queue([1], 0)
|
||||
track.volume_adjustment = -255
|
||||
player.refresh_volume()
|
||||
assert sink.volume == 0.0
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
@@ -99,48 +43,6 @@ class TestInfoDialog:
|
||||
texts = {b.text() for b in _info(manager, ids).findChildren(QPushButton)}
|
||||
assert not texts & {"Previous", "Next"}
|
||||
|
||||
def test_shows_the_tracks_adjustment(self, qapp, manager):
|
||||
dialog = _info(manager, [2])
|
||||
assert dialog._volume.value() == 20 # 51/255
|
||||
assert dialog._volume_label.text() == "+20%"
|
||||
assert _info(manager, [1])._volume_label.text() == "None"
|
||||
|
||||
def test_saving_one_track(self, qapp, manager):
|
||||
dialog = _info(manager, [1])
|
||||
dialog._volume.setValue(-50)
|
||||
dialog._on_ok()
|
||||
assert manager.library.tracks[1].volume_adjustment == -128
|
||||
|
||||
def test_an_untouched_value_keeps_its_exact_number(self, qapp, manager):
|
||||
manager.library.tracks[1].volume_adjustment = 37 # an iTunes value
|
||||
dialog = _info(manager, [1])
|
||||
dialog._on_ok()
|
||||
assert manager.library.tracks[1].volume_adjustment == 37
|
||||
|
||||
def test_the_edit_is_undoable(self, qapp, manager):
|
||||
dialog = _info(manager, [1])
|
||||
dialog._volume.setValue(100)
|
||||
dialog._on_ok()
|
||||
manager.undo_stack.undo()
|
||||
assert manager.library.tracks[1].volume_adjustment == 0
|
||||
|
||||
def test_several_tracks_mixed_untouched(self, qapp, manager):
|
||||
dialog = _info(manager, [1, 2])
|
||||
assert dialog._volume_label.text() == "Mixed"
|
||||
dialog._on_ok()
|
||||
assert manager.library.tracks[1].volume_adjustment == 0
|
||||
assert manager.library.tracks[2].volume_adjustment == 51
|
||||
|
||||
def test_several_tracks_shared_value(self, qapp, manager):
|
||||
assert _info(manager, [2, 3])._volume_label.text() == "+20%"
|
||||
|
||||
def test_several_tracks_touched(self, qapp, manager):
|
||||
dialog = _info(manager, [1, 2])
|
||||
dialog._volume.setValue(-100)
|
||||
dialog._on_ok()
|
||||
assert manager.library.tracks[1].volume_adjustment == -255
|
||||
assert manager.library.tracks[2].volume_adjustment == -255
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# 3 & 4. Preferences
|
||||
|
||||
Reference in New Issue
Block a user