Fixed some bugs that happened when tracks got rearranged.

This commit is contained in:
The Wobbler 2025-01-26 16:49:09 +01:00
parent b2bd8ef784
commit 519b2d0adb
10 changed files with 72 additions and 17 deletions

View file

@ -30,11 +30,40 @@ class Track:
self.sound = None
self.duration = 0
self.item = None
self.items = []
self.occurrences = {} # all occurrences in playlists categorized by playlist and track widget
if cache:
self.cache()
def set_occurrences(self):
# set track item for every occurrence of track in a playlist
new_occurrences = {}
for item in self.items:
playlist_occurrences = new_occurrences.get(item.playlist, {})
playlist_occurrences[id(item)] = item.index
new_occurrences[item.playlist] = playlist_occurrences
self.correct_occurrences(new_occurrences)
self.occurrences = new_occurrences
def correct_occurrences(self, new_occurrences):
"""
If this track is the currently playing track, and it gets moved, this corrects the current playlist index.
"""
if self.app.player.current_playlist.current_track is self:
for item in self.items:
if (
item.playlist in self.occurrences and
self.occurrences[item.playlist][id(item)] == self.app.player.current_playlist.current_track_index
):
self.app.player.current_playlist.set_track(new_occurrences[item.playlist][id(item)])
def cache(self):
self.load_audio()
# audio = normalize(audio)