Added option to always clear the cache of the last track when another track starts to greatly reduce memory usage.

This commit is contained in:
The Wobbler 2025-01-25 18:29:27 +01:00
parent cba4fd67fa
commit dc46ac07bb
5 changed files with 38 additions and 1 deletions

View file

@ -45,6 +45,9 @@ class Player:
self.track_progress.start()
self.app.gui.on_track_change(previous_track, self.current_playlist.current_track)
if self.app.settings.clear_track_cache:
previous_track.clear_cache()
else:
self.stop()
@ -70,6 +73,9 @@ class Player:
self.track_progress.start()
self.app.gui.on_track_change(previous_track, self.current_playlist.current_track)
if self.app.settings.clear_track_cache:
previous_track.clear_cache()
def pause(self):
self.music_channel.pause()
self.track_progress.pause()

View file

@ -47,6 +47,13 @@ class Track:
self.cached = True
def clear_cache(self):
self.cached = False
self.audio = None
self.sound = None
self.duration = 0
def load_audio(self):
type = self.path.split(".")[-1]

View file

@ -8,4 +8,5 @@ class Settings:
window_size: tuple[int, int]=None
window_maximized: bool=False
library_path: str="~/.wobuzz"
clear_track_cache: bool=True

View file

@ -0,0 +1,14 @@
#!/usr/bin/python3
from PyQt6.QtWidgets import QWidget, QFormLayout, QCheckBox
class BehaviourSettings(QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.layout = QFormLayout(self)
self.setLayout(self.layout)
self.clear_track_cache = QCheckBox(self)
self.layout.addRow("Clear track cache immediately when finished", self.clear_track_cache)

View file

@ -3,6 +3,7 @@
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QWidget, QDockWidget, QTabWidget, QPushButton, QVBoxLayout
from .file import FileSettings
from .behavior import BehaviourSettings
class Settings(QDockWidget):
@ -24,10 +25,13 @@ class Settings(QDockWidget):
self.content.setLayout(self.content_layout)
self.tabs = QTabWidget(self.content)
self.content_layout.addWidget(self.tabs)
self.file_settings = FileSettings()
self.tabs.addTab(self.file_settings, "Files")
self.content_layout.addWidget(self.tabs)
self.behavior_settings = BehaviourSettings()
self.tabs.addTab(self.behavior_settings, "Behavior")
self.save_button = QPushButton("&Save", self.content)
self.content_layout.addWidget(self.save_button)
@ -39,12 +43,17 @@ class Settings(QDockWidget):
def update_all(self, _=True): # ignore visible parameter passed by visibilityChanged event
self.file_settings.library_path_input.setText(self.app.settings.library_path)
self.behavior_settings.clear_track_cache.setChecked(self.app.settings.clear_track_cache)
def update_settings(self, key, value):
match key:
case "library_path":
self.file_settings.library_path_input.setText(value)
case "clear_track_cache":
self.behavior_settings.clear_track_cache.setDown(value)
def write_settings(self):
self.app.settings.library_path = self.file_settings.library_path_input.text()
self.app.settings.clear_track_cache = self.behavior_settings.clear_track_cache.isChecked()