From 37c71ded1b61b69deb864f7fc1379e1e5335dd74 Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:08:10 -0300 Subject: [PATCH 01/14] fix: preserve current track when reordering playlist --- radiostudio/ui/playlist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radiostudio/ui/playlist.py b/radiostudio/ui/playlist.py index 9557b73..ba92ee1 100644 --- a/radiostudio/ui/playlist.py +++ b/radiostudio/ui/playlist.py @@ -181,7 +181,7 @@ def reorder_tracks(self, rows, target): self.tracks = [track for _, track, _source in ordered] self.track_sources = [source for _, _track, source in ordered] if old_current >= 0: - self.current_index = next((new_index for new_index, (old_index, _track) + self.current_index = next((new_index for new_index, (old_index, _track, _source) in enumerate(ordered) if old_index == old_current), -1) self.refresh_playlist() self.playlist.clearSelection() From 1eb785c75a263e983e89149fbfd064cc7f95e0a8 Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:08:24 -0300 Subject: [PATCH 02/14] test: cover playlist reorder current-track regression --- tests/test_playlist_regressions.py | 71 ++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/test_playlist_regressions.py diff --git a/tests/test_playlist_regressions.py b/tests/test_playlist_regressions.py new file mode 100644 index 0000000..3f9c3db --- /dev/null +++ b/tests/test_playlist_regressions.py @@ -0,0 +1,71 @@ +import unittest + +from radiostudio.ui.playlist import PlaylistMixin + + +class _SelectionModel: + def __init__(self): + self.selected = [] + + def select(self, index, flags): + self.selected.append((index, flags)) + + +class _Model: + @staticmethod + def index(row, column): + return row, column + + +class _Playlist: + def __init__(self): + self.selection = _SelectionModel() + self.table_model = _Model() + self.cleared = False + + def clearSelection(self): + self.cleared = True + + def selectionModel(self): + return self.selection + + def model(self): + return self.table_model + + +class _PlaylistHarness(PlaylistMixin): + def __init__(self): + self.tracks = ["a.mp3", "b.mp3", "c.mp3", "d.mp3"] + self.track_sources = ["manual", "autodj", "schedule", "manual"] + self.current_index = 2 + self.playlist = _Playlist() + self.saved = False + self.refreshed = False + + def cancel_pending_transition(self): + pass + + def refresh_playlist(self): + self.refreshed = True + + def save_state(self): + self.saved = True + + +class PlaylistRegressionTests(unittest.TestCase): + def test_reorder_preserves_current_track_and_its_source(self): + harness = _PlaylistHarness() + + PlaylistMixin.reorder_tracks(harness, [2], 1) + + self.assertEqual(harness.tracks, ["a.mp3", "c.mp3", "b.mp3", "d.mp3"]) + self.assertEqual(harness.track_sources, + ["manual", "schedule", "autodj", "manual"]) + self.assertEqual(harness.current_index, 1) + self.assertTrue(harness.refreshed) + self.assertTrue(harness.saved) + self.assertTrue(harness.playlist.cleared) + + +if __name__ == "__main__": + unittest.main() From 8d6ed9d310d7d7523d5ca7f9de1ba7da4898ddb6 Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:09:06 -0300 Subject: [PATCH 03/14] fix: keep live-input broadcast level independent from monitor volume --- radiostudio/services/audio_inputs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/radiostudio/services/audio_inputs.py b/radiostudio/services/audio_inputs.py index f0f817e..afc3c64 100644 --- a/radiostudio/services/audio_inputs.py +++ b/radiostudio/services/audio_inputs.py @@ -337,7 +337,9 @@ def _pump(self): while len(item["pending"]) >= PCM_BYTES_PER_FRAME: frame = bytes(item["pending"][:PCM_BYTES_PER_FRAME]) del item["pending"][:PCM_BYTES_PER_FRAME] - self.broadcast.push_audio(f"input:{channel}", frame, self.monitor_gain) + # The monitor slider only controls local listening. Live inputs + # must reach the program bus at unity just like the main deck. + self.broadcast.push_audio(f"input:{channel}", frame, 1.0) buffer = self.monitor_buffers.get(channel) if self.monitor_enabled and buffer is not None: buffer.append(frame) From a85a6dec10b4c235cbc7c871788cd7fec4f58072 Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:09:25 -0300 Subject: [PATCH 04/14] test: ensure monitor level cannot mute live broadcast inputs --- tests/test_audio_inputs.py | 52 +++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/test_audio_inputs.py b/tests/test_audio_inputs.py index c383be8..a35e554 100644 --- a/tests/test_audio_inputs.py +++ b/tests/test_audio_inputs.py @@ -8,7 +8,7 @@ convert_master_to_device, mix_pcm_chunks, pcm_rms_db, AudioInputController) -from radiostudio.services.broadcast import SAMPLE_RATE +from radiostudio.services.broadcast import PCM_BYTES_PER_FRAME, SAMPLE_RATE class AudioInputConversionTests(unittest.TestCase): @@ -88,6 +88,56 @@ def test_missing_monitor_device_is_reported_once_per_error_state(self): controller.deleteLater() self.app.processEvents() + def test_monitor_gain_does_not_attenuate_broadcast_input(self): + class FakeBroadcast: + def __init__(self): + self.calls = [] + + def push_audio(self, source, data, gain=1.0): + self.calls.append((source, data, gain)) + + def remove_source(self, _source): + pass + + class ReadDevice: + def __init__(self, data): + self.data = bytearray(data) + + def bytesAvailable(self): + return len(self.data) + + def read(self, length): + chunk = bytes(self.data[:length]) + del self.data[:length] + return chunk + + audio_format = QAudioFormat() + audio_format.setSampleRate(SAMPLE_RATE) + audio_format.setChannelCount(2) + audio_format.setSampleFormat(QAudioFormat.Int16) + frame = struct.pack("<" + "h" * (PCM_BYTES_PER_FRAME // 2), + *([12000] * (PCM_BYTES_PER_FRAME // 2))) + broadcast = FakeBroadcast() + controller = AudioInputController(broadcast) + controller.monitor_enabled = False + controller.monitor_gain = 0.05 + controller.active["aux1"] = { + "io": ReadDevice(frame), + "format": audio_format, + "pending": bytearray(), + "raw_pending": bytearray(), + "input_frame_bytes": 4, + } + + controller._pump() + + self.assertEqual(len(broadcast.calls), 1) + self.assertEqual(broadcast.calls[0][0], "input:aux1") + self.assertEqual(broadcast.calls[0][2], 1.0) + controller.active.clear() + controller.deleteLater() + self.app.processEvents() + if __name__ == "__main__": unittest.main() From 1869b11a96b17a500aed1524207556cde742214d Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:09:49 -0300 Subject: [PATCH 05/14] fix: exclude unknown years from ranged AutoDJ filters --- radiostudio/services/autodj.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/radiostudio/services/autodj.py b/radiostudio/services/autodj.py index 301cbf4..0e7befc 100644 --- a/radiostudio/services/autodj.py +++ b/radiostudio/services/autodj.py @@ -130,6 +130,11 @@ def filter_tracks(tracks, filters): track_year = int(track.get("year") or 0) except (TypeError, ValueError, OverflowError): track_year = 0 + # An unknown year cannot satisfy a user-requested year range. Previously + # year_to by itself treated missing/invalid years as year zero and let + # those tracks through. + if (year_from or year_to) and track_year <= 0: + continue if year_from and track_year < year_from: continue if year_to and track_year > year_to: From 68dc22f7a30e8223b14c2317717e46ddc8ae964f Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:10:10 -0300 Subject: [PATCH 06/14] test: reject unknown years from AutoDJ range filters --- tests/test_autodj.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_autodj.py b/tests/test_autodj.py index d96842d..d127a5b 100644 --- a/tests/test_autodj.py +++ b/tests/test_autodj.py @@ -34,6 +34,18 @@ def test_filtering_by_tags_and_keywords(self): "keyword_fields": ["title", "album"]}) self.assertEqual(["a"], [track["path"] for track in result]) + def test_year_filter_excludes_tracks_with_unknown_year(self): + tracks = [ + {"path": "known", "title": "Known", "year": "2008"}, + {"path": "unknown", "title": "Unknown", "year": ""}, + {"path": "invalid", "title": "Invalid", "year": "not-a-year"}, + {"path": "newer", "title": "Newer", "year": "2015"}, + ] + + result = filter_tracks(tracks, {"year_to": 2010}) + + self.assertEqual(["known"], [track["path"] for track in result]) + def test_repeat_cooldowns_fall_back_without_stalling(self): with tempfile.TemporaryDirectory() as folder: first = Path(folder) / "first.mp3"; first.write_bytes(b"a") From 79adf430c1a00e7971a0bcae55bf1d758543313e Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:11:42 -0300 Subject: [PATCH 07/14] fix: normalize whitespace when loading M3U playlists --- radiostudio/ui/playlist.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/radiostudio/ui/playlist.py b/radiostudio/ui/playlist.py index ba92ee1..effa063 100644 --- a/radiostudio/ui/playlist.py +++ b/radiostudio/ui/playlist.py @@ -4,6 +4,16 @@ from ..runtime_safety import guarded +def m3u_entries(lines): + """Return meaningful M3U path entries with surrounding whitespace removed.""" + result = [] + for raw in lines: + line = str(raw).strip() + if line and not line.startswith("#"): + result.append(line) + return result + + class PlaylistMixin: @guarded def refresh_playlist(self): @@ -90,9 +100,9 @@ def open_m3u(self): return self.cancel_pending_transition() base = Path(path).parent - lines = Path(path).read_text(encoding="utf-8-sig", errors="replace").splitlines() + lines = m3u_entries(Path(path).read_text(encoding="utf-8-sig", errors="replace").splitlines()) self.tracks = [str((base / line).resolve()) if not Path(line).is_absolute() else line - for line in lines if line.strip() and not line.startswith("#")] + for line in lines] self.track_sources = ["manual"] * len(self.tracks) self.current_index = -1 self.refresh_playlist() From dc01a71c0745b633037293ff35eb94ec45e9c6b3 Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:12:00 -0300 Subject: [PATCH 08/14] test: cover whitespace in M3U entries --- tests/test_playlist_regressions.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_playlist_regressions.py b/tests/test_playlist_regressions.py index 3f9c3db..122d9f7 100644 --- a/tests/test_playlist_regressions.py +++ b/tests/test_playlist_regressions.py @@ -1,6 +1,6 @@ import unittest -from radiostudio.ui.playlist import PlaylistMixin +from radiostudio.ui.playlist import PlaylistMixin, m3u_entries class _SelectionModel: @@ -66,6 +66,12 @@ def test_reorder_preserves_current_track_and_its_source(self): self.assertTrue(harness.saved) self.assertTrue(harness.playlist.cleared) + def test_m3u_entries_strip_whitespace_and_ignore_indented_comments(self): + self.assertEqual( + m3u_entries([" #EXTM3U ", " song one.mp3 ", "", "\t#EXTINF:10,x", "sub/song two.mp3\t"]), + ["song one.mp3", "sub/song two.mp3"], + ) + if __name__ == "__main__": unittest.main() From 830859ba16dba4ccad9eac6879c6edf70e886e97 Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:12:50 -0300 Subject: [PATCH 09/14] fix: apply microphone ducking to carts on broadcast bus --- radiostudio/ui/cart_wall.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/radiostudio/ui/cart_wall.py b/radiostudio/ui/cart_wall.py index b03b64a..35d5e3d 100644 --- a/radiostudio/ui/cart_wall.py +++ b/radiostudio/ui/cart_wall.py @@ -49,8 +49,12 @@ def play_cart(self, index): player.setAudioOutput(output) buffer_output = QAudioBufferOutput(self.broadcast_format, self) source_id = f"cart-{id(player)}" + # Keep broadcast carts in the same music-duck envelope as their local + # monitor. Previously only the local cart level fell under microphone + # ducking, while listeners still heard the cart at full level. buffer_output.audioBufferReceived.connect( - lambda buffer, key=source_id: self.forward_buffer(key, buffer, 0.8)) + lambda buffer, key=source_id: self.forward_buffer( + key, buffer, 0.8 * self.music_duck_gain)) player.setAudioBufferOutput(buffer_output) player.setSource(QUrl.fromLocalFile(path)) self.cart_players.append((player, output, buffer_output, source_id)) From 8f7dd57e61cf1be8599ec1fdabd96872e32c5f4a Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:14:12 -0300 Subject: [PATCH 10/14] fix: select all weekdays for new AutoDJ programs --- radiostudio/ui/autodj_panel.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/radiostudio/ui/autodj_panel.py b/radiostudio/ui/autodj_panel.py index b26dc6c..7053a2f 100644 --- a/radiostudio/ui/autodj_panel.py +++ b/radiostudio/ui/autodj_panel.py @@ -76,7 +76,7 @@ def __init__(self, libraries, program=None, parent=None): day_box = QGroupBox("Dias da semana") day_layout = QHBoxLayout(day_box) saved_days = set() - raw_days = program.get("days", range(7)) + raw_days = program.get("days", list(range(7))) if isinstance(raw_days, (list, tuple, set)): for day in raw_days: try: @@ -542,4 +542,3 @@ def clear_history(self): return self.library.clear_history() self.refresh_history(); self.main_window.save_state() - From 0116cd41fc8e82925916d2afc38fbc642b6bec22 Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:14:23 -0300 Subject: [PATCH 11/14] test: cover default weekdays in AutoDJ program dialog --- tests/test_autodj_panel_regressions.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/test_autodj_panel_regressions.py diff --git a/tests/test_autodj_panel_regressions.py b/tests/test_autodj_panel_regressions.py new file mode 100644 index 0000000..a03ea0a --- /dev/null +++ b/tests/test_autodj_panel_regressions.py @@ -0,0 +1,25 @@ +import unittest + +from PySide6.QtWidgets import QApplication + +from radiostudio.ui.autodj_panel import ProgramDialog + + +class AutoDJPanelRegressionTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.app = QApplication.instance() or QApplication([]) + + def test_new_program_defaults_to_all_weekdays(self): + dialog = ProgramDialog([]) + try: + self.assertEqual(len(dialog.days), 7) + self.assertTrue(all(check.isChecked() for check in dialog.days)) + finally: + dialog.close() + dialog.deleteLater() + self.app.processEvents() + + +if __name__ == "__main__": + unittest.main() From 79d5576e48f0b0f6b1f93a262d9299d0f79ddb2a Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:15:30 -0300 Subject: [PATCH 12/14] fix: avoid applying microphone ducking twice to carts --- radiostudio/ui/cart_wall.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/radiostudio/ui/cart_wall.py b/radiostudio/ui/cart_wall.py index 35d5e3d..b03b64a 100644 --- a/radiostudio/ui/cart_wall.py +++ b/radiostudio/ui/cart_wall.py @@ -49,12 +49,8 @@ def play_cart(self, index): player.setAudioOutput(output) buffer_output = QAudioBufferOutput(self.broadcast_format, self) source_id = f"cart-{id(player)}" - # Keep broadcast carts in the same music-duck envelope as their local - # monitor. Previously only the local cart level fell under microphone - # ducking, while listeners still heard the cart at full level. buffer_output.audioBufferReceived.connect( - lambda buffer, key=source_id: self.forward_buffer( - key, buffer, 0.8 * self.music_duck_gain)) + lambda buffer, key=source_id: self.forward_buffer(key, buffer, 0.8)) player.setAudioBufferOutput(buffer_output) player.setSource(QUrl.fromLocalFile(path)) self.cart_players.append((player, output, buffer_output, source_id)) From 9b4d4c7a3ef3511c8622feb19b9585b51eed81a7 Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:15:58 -0300 Subject: [PATCH 13/14] fix: refresh now-playing metadata after settings dialog --- radiostudio/ui/settings_controller.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/radiostudio/ui/settings_controller.py b/radiostudio/ui/settings_controller.py index 9e97c68..ef4ef56 100644 --- a/radiostudio/ui/settings_controller.py +++ b/radiostudio/ui/settings_controller.py @@ -49,9 +49,14 @@ def show_settings(self): self.apply_audio_devices() self.audio_input_controller.speech_threshold_db = self.speech_threshold_db self.update_music_duck_target() - if current_track and self.player.playbackState() != QMediaPlayer.StoppedState: + # The modal settings window can stay open long enough for playback to + # advance. Re-read the current row here instead of publishing metadata + # captured when the dialog was opened. + current_on_air = (read_track_metadata(self.tracks[self.current_index]) + if 0 <= self.current_index < len(self.tracks) else None) + if current_on_air and self.player.playbackState() != QMediaPlayer.StoppedState: self.broadcast.set_title(format_broadcast_title( - self.station_metadata["title_format"], current_track, self.station_metadata)) + self.station_metadata["title_format"], current_on_air, self.station_metadata)) if self.broadcast.local_server: server = self.broadcast.local_server server.station = self.broadcast_panel.local_config()["station"] or self.station_metadata["name"] From 4a5c6cb10ba8aa1157b9cee07a148bff877d8bf4 Mon Sep 17 00:00:00 2001 From: Raphael Cherfem <98133031+RaphaaCC@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:16:34 -0300 Subject: [PATCH 14/14] test: use QApplication for mixed audio and widget regressions --- tests/test_audio_inputs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_audio_inputs.py b/tests/test_audio_inputs.py index a35e554..e2470f4 100644 --- a/tests/test_audio_inputs.py +++ b/tests/test_audio_inputs.py @@ -1,7 +1,7 @@ import struct import unittest -from PySide6.QtCore import QCoreApplication +from PySide6.QtWidgets import QApplication from PySide6.QtMultimedia import QAudioFormat from radiostudio.services.audio_inputs import (convert_input_to_master, @@ -14,7 +14,7 @@ class AudioInputConversionTests(unittest.TestCase): @classmethod def setUpClass(cls): - cls.app = QCoreApplication.instance() or QCoreApplication([]) + cls.app = QApplication.instance() or QApplication([]) def test_mono_int16_input_becomes_stereo_master_pcm(self): audio_format = QAudioFormat()