diff --git a/app/classes.py b/app/classes.py index fda81b0..c6ebd8e 100644 --- a/app/classes.py +++ b/app/classes.py @@ -199,8 +199,12 @@ class PlaylistTrack: ) # Calculate time fade_graph should start updating - update_graph_at_ms = max(0, self.fade_at - Config.FADE_CURVE_MS_BEFORE_FADE - 1) - self.fade_graph_start_updates = now + dt.timedelta(milliseconds=update_graph_at_ms) + update_graph_at_ms = max( + 0, self.fade_at - Config.FADE_CURVE_MS_BEFORE_FADE - 1 + ) + self.fade_graph_start_updates = now + dt.timedelta( + milliseconds=update_graph_at_ms + ) @dataclass diff --git a/app/dialogs.py b/app/dialogs.py index 36ec626..519802b 100644 --- a/app/dialogs.py +++ b/app/dialogs.py @@ -84,7 +84,7 @@ class ReplaceFilesDialog(QDialog): continue rf = TrackFileData(new_file_path=new_file_path) rf.tags = get_tags(new_file_path) - if not rf.tags['title'] or not rf.tags['artist']: + if not rf.tags["title"] or not rf.tags["artist"]: show_warning( parent=self.main_window, title="Error", @@ -98,11 +98,11 @@ class ReplaceFilesDialog(QDialog): # Check for same filename match_track = self.check_by_basename( - session, new_file_path, rf.tags['artist'], rf.tags['title'] + session, new_file_path, rf.tags["artist"], rf.tags["title"] ) if not match_track: match_track = self.check_by_title( - session, new_file_path, rf.tags['artist'], rf.tags['title'] + session, new_file_path, rf.tags["artist"], rf.tags["title"] ) if not match_track: @@ -113,8 +113,7 @@ class ReplaceFilesDialog(QDialog): # We will store new file in the same directory as the # existing file but with the new file name rf.track_path = os.path.join( - os.path.dirname(match_track.path), - new_file_basename + os.path.dirname(match_track.path), new_file_basename ) # We will remove existing track file @@ -125,27 +124,34 @@ class ReplaceFilesDialog(QDialog): if match_basename == new_file_basename: path_text = " " + new_file_basename + " (no change)" else: - path_text = f" {match_basename} →\n {new_file_basename} (replace)" + path_text = ( + f" {match_basename} →\n {new_file_basename} (replace)" + ) filename_item = QTableWidgetItem(path_text) - if match_track.title == rf.tags['title']: - title_text = " " + rf.tags['title'] + " (no change)" + if match_track.title == rf.tags["title"]: + title_text = " " + rf.tags["title"] + " (no change)" else: - title_text = f" {match_track.title} →\n {rf.tags['title']} (update)" + title_text = ( + f" {match_track.title} →\n {rf.tags['title']} (update)" + ) title_item = QTableWidgetItem(title_text) - if match_track.artist == rf.tags['artist']: - artist_text = " " + rf.tags['artist'] + " (no change)" + if match_track.artist == rf.tags["artist"]: + artist_text = " " + rf.tags["artist"] + " (no change)" else: - artist_text = f" {match_track.artist} →\n {rf.tags['artist']} (update)" + artist_text = ( + f" {match_track.artist} →\n {rf.tags['artist']} (update)" + ) artist_item = QTableWidgetItem(artist_text) else: - rf.track_path = os.path.join(Config.REPLACE_FILES_DEFAULT_DESTINATION, - new_file_basename) + rf.track_path = os.path.join( + Config.REPLACE_FILES_DEFAULT_DESTINATION, new_file_basename + ) filename_item = QTableWidgetItem(" " + new_file_basename + " (new)") - title_item = QTableWidgetItem(" " + rf.tags['title']) - artist_item = QTableWidgetItem(" " + rf.tags['artist']) + title_item = QTableWidgetItem(" " + rf.tags["title"]) + artist_item = QTableWidgetItem(" " + rf.tags["artist"]) self.replacement_files.append(rf) row = self.ui.tableWidget.rowCount() diff --git a/app/music.py b/app/music.py index b3319c9..453eb24 100644 --- a/app/music.py +++ b/app/music.py @@ -175,7 +175,6 @@ class Music: if current_volume < volume: self.player.audio_set_volume(volume) log.debug(f"Reset from {volume=}") - break sleep(0.1) def stop(self) -> float: diff --git a/app/musicmuster.py b/app/musicmuster.py index 7d23fda..09eb9e0 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -1151,13 +1151,10 @@ class Window(QMainWindow, Ui_MainWindow): # If return is pressed during first PLAY_NEXT_GUARD_MS then # default to NOT playing the next track, else default to # playing it. - default_yes: bool = ( - track_sequence.now.start_time is not None - and ( - (dt.datetime.now() - track_sequence.now.start_time).total_seconds() - * 1000 - > Config.PLAY_NEXT_GUARD_MS - ) + default_yes: bool = track_sequence.now.start_time is not None and ( + (dt.datetime.now() - track_sequence.now.start_time).total_seconds() + * 1000 + > Config.PLAY_NEXT_GUARD_MS ) if not helpers.ask_yes_no( "Track playing", diff --git a/app/playlistmodel.py b/app/playlistmodel.py index 4d16088..b23b984 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -862,7 +862,7 @@ class PlaylistModel(QAbstractTableModel): # otherwise rows below the destination row will end up above the # moved rows. adjusted_to_row = to_row_number - len( - [a for a in from_rows if a <= to_row_number] + [a for a in from_rows if a < to_row_number] ) # Put the from_row row numbers into the row_map. Ultimately the diff --git a/tests/test_playlistmodel.py b/tests/test_playlistmodel.py index cfb5c45..2a5f227 100644 --- a/tests/test_playlistmodel.py +++ b/tests/test_playlistmodel.py @@ -244,6 +244,20 @@ class TestMMMiscRowMove(unittest.TestCase): new_order.append(int(self.model.playlist_rows[row].note)) assert new_order == [0, 1, 2, 3, 4, 7, 8, 10, 5, 6, 9] + def test_move_rows_test9(self): + # move rows [1, 2, 3] → 0 + # Replicate issue 244 + + self.model.move_rows([0, 1, 2, 3], 0) + + # Check we have all rows and plr_rownums are correct + new_order = [] + for row in range(self.model.rowCount()): + assert row in self.model.playlist_rows + assert self.model.playlist_rows[row].plr_rownum == row + new_order.append(int(self.model.playlist_rows[row].note)) + assert new_order == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + def test_insert_header_row_end(self): # insert header row at end of playlist