From d453afc6d0d4a4ed9a480f1d0d79ef3a36e60d5c Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sun, 22 Dec 2024 16:23:56 +0100 Subject: [PATCH] Undid some "OOPing" that just made it unnecessarily more complicated. --- wobuzz/gui_communication.py | 4 ++-- wobuzz/player/play_state.py | 11 ----------- wobuzz/player/player.py | 36 ++++++++++++++++++++---------------- 3 files changed, 22 insertions(+), 29 deletions(-) delete mode 100644 wobuzz/player/play_state.py diff --git a/wobuzz/gui_communication.py b/wobuzz/gui_communication.py index 288a752..58eeca3 100644 --- a/wobuzz/gui_communication.py +++ b/wobuzz/gui_communication.py @@ -38,7 +38,7 @@ class GUICommunication: self.app.player.seek(self.track_control.track_progress_slider.value()) def on_track_start(self): - if self.app.player.play_state.playing: + if self.app.player.playing: duration = self.app.player.playing_track.duration self.track_control.track_progress_slider.setRange( @@ -51,7 +51,7 @@ class GUICommunication: self.update_progress() def update_progress(self): - if self.app.player.play_state.playing and not self.track_progress_slider_dragged: + if self.app.player.playing and not self.track_progress_slider_dragged: remaining = self.app.player.track_progress.timer.remainingTime() if remaining == -1: diff --git a/wobuzz/player/play_state.py b/wobuzz/player/play_state.py deleted file mode 100644 index 39fe26b..0000000 --- a/wobuzz/player/play_state.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/python3 - -from dataclasses import dataclass - - -@dataclass -class PlayState: - has_tracks: bool=False - playing: bool=False - paused: bool=False - searched: bool=False diff --git a/wobuzz/player/player.py b/wobuzz/player/player.py index 6b587b5..e0dd747 100644 --- a/wobuzz/player/player.py +++ b/wobuzz/player/player.py @@ -6,19 +6,23 @@ import pygame.mixer import pygame.event from .track import Track from .track_progress_timer import TrackProgress -from .play_state import PlayState class Player: def __init__(self, app): self.app = app - self.track_progress = TrackProgress(self.app) - self.play_state = PlayState() pygame.mixer.init() self.mixer = pygame.mixer self.music_channel = self.mixer.Channel(0) + self.track_progress = TrackProgress(self.app) + + self.playing = False + self.paused = False + self.has_tracks = False + self.searched = False + self.current_playlist = [] self.playing_track = None self.current_playlist_index = 0 @@ -41,7 +45,7 @@ class Player: self.current_playlist_index = 0 self.playing_segment = self.playing_track.sound self.playing_segment_duration = self.playing_track.duration - self.play_state.has_tracks = len(self.current_playlist) > 0 + self.has_tracks = len(self.current_playlist) > 0 def track_finished(self): self.current_playlist_index += 1 @@ -59,24 +63,24 @@ class Player: self.stop() def start_playing(self): - if self.play_state.has_tracks: + if self.has_tracks: self.music_channel.play(self.playing_track.sound) self.track_progress.start() - self.play_state.paused = False - self.play_state.playing = True + self.paused = False + self.playing = True def pause(self): self.music_channel.pause() self.track_progress.pause() - self.play_state.paused = True + self.paused = True def unpause(self): self.music_channel.unpause() self.track_progress.unpause() - self.play_state.paused = False + self.paused = False def skip_current(self): - if self.play_state.has_tracks: + if self.has_tracks: self.music_channel.stop() self.track_progress.stop() self.track_finished() @@ -97,25 +101,25 @@ class Player: self.app.gui_communication.on_track_start() def toggle_playing(self): - if self.play_state.playing and self.play_state.paused: + if self.playing and self.paused: self.unpause() - elif self.play_state.playing: + elif self.playing: self.pause() else: self.start_playing() def stop(self): - if self.play_state.has_tracks: + if self.has_tracks: self.music_channel.stop() self.track_progress.stop() - self.play_state.playing = False + self.playing = False self.playing_segment_duration = self.playing_track.duration def seek(self, position: int): - if self.play_state.has_tracks: - self.play_state.searched = True + if self.has_tracks: + self.searched = True self.music_channel.stop() self.track_progress.stop() (self.playing_segment, self.playing_segment_duration) = self.playing_track.remaining(position)