Got shitty basic features working.
This commit is contained in:
parent
ce254c8b54
commit
45d97f5aeb
6 changed files with 97 additions and 29 deletions
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from PyQt6.QtCore import QTimer
|
||||||
from ui.main_window import MainWindow
|
from ui.main_window import MainWindow
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,12 +10,13 @@ class GUI:
|
||||||
|
|
||||||
self.window = MainWindow()
|
self.window = MainWindow()
|
||||||
|
|
||||||
self.window.show()
|
|
||||||
|
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
|
self.window.show()
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.window.main_container.track_control.previous_button.triggered.connect(self.app.player.previous_track)
|
self.window.main_container.track_control.previous_button.triggered.connect(self.app.player.previous_track)
|
||||||
self.window.main_container.track_control.toggle_play_button.triggered.connect(self.app.player.toggle_playing)
|
self.window.main_container.track_control.toggle_play_button.triggered.connect(self.app.player.toggle_playing)
|
||||||
self.window.main_container.track_control.stop_button.triggered.connect(self.app.player.stop)
|
self.window.main_container.track_control.stop_button.triggered.connect(self.app.player.stop)
|
||||||
self.window.main_container.track_control.next_button.triggered.connect(self.app.player.skip_current)
|
self.window.main_container.track_control.next_button.triggered.connect(self.app.player.skip_current)
|
||||||
|
|
||||||
|
|
34
wobuzz/gui_communication.py
Normal file
34
wobuzz/gui_communication.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from PyQt6.QtCore import QTimer
|
||||||
|
|
||||||
|
PROGRESS_UPDATE_RATE = 60
|
||||||
|
PROGRESS_UPDATE_INTERVAL = 1000 // PROGRESS_UPDATE_RATE
|
||||||
|
|
||||||
|
|
||||||
|
class GUICommunication:
|
||||||
|
def __init__(self, app):
|
||||||
|
self.app = app
|
||||||
|
self.window = self.app.gui.window
|
||||||
|
|
||||||
|
self.progress_update_timer = QTimer()
|
||||||
|
self.progress_update_timer.timeout.connect(self.update_progress)
|
||||||
|
self.progress_update_timer.start(PROGRESS_UPDATE_INTERVAL)
|
||||||
|
self.on_track_start()
|
||||||
|
|
||||||
|
def on_track_start(self):
|
||||||
|
self.window.main_container.track_control.track_progress_slider.setRange(
|
||||||
|
0,
|
||||||
|
self.app.player.playing_track.duration
|
||||||
|
)
|
||||||
|
|
||||||
|
self.update_progress()
|
||||||
|
|
||||||
|
def update_progress(self):
|
||||||
|
remaining = self.app.player.track_progress_timer.remainingTime()
|
||||||
|
track_duration = self.app.player.playing_track.duration
|
||||||
|
|
||||||
|
progress = track_duration - remaining
|
||||||
|
|
||||||
|
self.window.main_container.track_control.track_progress_slider.setValue(progress)
|
||||||
|
|
|
@ -2,17 +2,18 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from PyQt6.QtWidgets import QApplication
|
from PyQt6.QtWidgets import QApplication
|
||||||
from gui import GUI
|
|
||||||
from wobuzz.player.player import Player
|
from wobuzz.player.player import Player
|
||||||
|
from gui import GUI
|
||||||
|
from gui_communication import GUICommunication
|
||||||
|
|
||||||
|
|
||||||
class Wobuzz:
|
class Wobuzz:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.qt_app = QApplication([])
|
self.qt_app = QApplication([])
|
||||||
|
|
||||||
self.player = Player(sys.argv[1:])
|
self.player = Player(self, sys.argv[1:])
|
||||||
|
|
||||||
self.gui = GUI(self)
|
self.gui = GUI(self)
|
||||||
|
self.gui_communication = GUICommunication(self)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -2,19 +2,24 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from PyQt6.QtCore import QTimer
|
||||||
import pygame.mixer
|
import pygame.mixer
|
||||||
from pydub import AudioSegment
|
import pygame.event
|
||||||
from pydub.effects import normalize
|
|
||||||
import io
|
|
||||||
from pygame import mixer
|
|
||||||
from .track import Track
|
from .track import Track
|
||||||
|
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self, file_paths: list=[]):
|
def __init__(self, app, file_paths: list=[]):
|
||||||
|
self.app = app
|
||||||
|
|
||||||
pygame.mixer.init()
|
pygame.mixer.init()
|
||||||
self.mixer = mixer
|
self.mixer = pygame.mixer
|
||||||
self.mixer.music.set_endevent()
|
self.music_channel = self.mixer.Channel(0)
|
||||||
|
|
||||||
|
self.track_progress_timer = QTimer()
|
||||||
|
self.track_progress_timer.timeout.connect(self.track_finished)
|
||||||
|
self.track_progress_timer.setSingleShot(True)
|
||||||
|
self.remaining_time = 0
|
||||||
|
|
||||||
self.playing = False
|
self.playing = False
|
||||||
self.paused = False
|
self.paused = False
|
||||||
|
@ -51,36 +56,60 @@ class Player:
|
||||||
self.current_playlist_index += 1
|
self.current_playlist_index += 1
|
||||||
self.playing_track = self.current_playlist[self.current_playlist_index]
|
self.playing_track = self.current_playlist[self.current_playlist_index]
|
||||||
|
|
||||||
self.playing_track.sound.play()
|
self.music_channel.play(self.playing_track.sound)
|
||||||
|
self.start_track_progress_timer()
|
||||||
|
self.app.gui_communication.on_track_start()
|
||||||
|
|
||||||
|
def start_playing(self):
|
||||||
|
self.music_channel.play(self.playing_track.sound)
|
||||||
|
self.start_track_progress_timer()
|
||||||
|
self.paused = False
|
||||||
|
self.playing = True
|
||||||
|
|
||||||
|
def pause(self):
|
||||||
|
self.music_channel.pause()
|
||||||
|
self.paused = True
|
||||||
|
self.pause_track_progress_timer()
|
||||||
|
|
||||||
|
def unpause(self):
|
||||||
|
self.music_channel.unpause()
|
||||||
|
self.paused = False
|
||||||
|
self.unpause_track_progress_timer()
|
||||||
|
|
||||||
def skip_current(self):
|
def skip_current(self):
|
||||||
self.mixer.stop()
|
self.music_channel.stop()
|
||||||
self.track_finished()
|
self.track_finished()
|
||||||
|
|
||||||
def previous_track(self):
|
def previous_track(self):
|
||||||
if self.current_playlist_index > 0:
|
if self.current_playlist_index > 0:
|
||||||
self.mixer.stop()
|
self.music_channel.stop()
|
||||||
|
|
||||||
self.current_playlist_index -= 1
|
self.current_playlist_index -= 1
|
||||||
self.playing_track = self.current_playlist[self.current_playlist_index]
|
self.playing_track = self.current_playlist[self.current_playlist_index]
|
||||||
|
|
||||||
self.playing_track.sound.play()
|
self.music_channel.play(self.playing_track.sound)
|
||||||
|
|
||||||
def toggle_playing(self):
|
def toggle_playing(self):
|
||||||
if self.playing and self.paused:
|
if self.playing and self.paused:
|
||||||
self.mixer.pause()
|
self.unpause()
|
||||||
self.paused = False
|
|
||||||
|
|
||||||
elif self.playing:
|
elif self.playing:
|
||||||
self.mixer.unpause()
|
self.pause()
|
||||||
self.paused = True
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.playing_track.sound.play()
|
self.start_playing()
|
||||||
self.paused = False
|
|
||||||
self.playing = True
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.mixer.stop()
|
self.music_channel.stop()
|
||||||
self.playing = False
|
self.playing = False
|
||||||
|
|
||||||
|
def start_track_progress_timer(self):
|
||||||
|
self.track_progress_timer.start(self.playing_track.duration)
|
||||||
|
|
||||||
|
def pause_track_progress_timer(self):
|
||||||
|
self.remaining_time = self.track_progress_timer.remainingTime()
|
||||||
|
self.track_progress_timer.stop()
|
||||||
|
|
||||||
|
def unpause_track_progress_timer(self):
|
||||||
|
self.track_progress_timer.start(self.playing_track.duration - self.remaining_time)
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Track:
|
||||||
self.path = path
|
self.path = path
|
||||||
self.cached = cache
|
self.cached = cache
|
||||||
|
|
||||||
self.sound = self.cache() if self.cached else None
|
(self.audio, self.sound, self.duration) = self.cache() if self.cached else (None, None, 0)
|
||||||
|
|
||||||
def cache(self):
|
def cache(self):
|
||||||
audio = AudioSegment.from_mp3(self.path)
|
audio = AudioSegment.from_mp3(self.path)
|
||||||
|
@ -24,6 +24,8 @@ class Track:
|
||||||
|
|
||||||
sound = Sound(wav)
|
sound = Sound(wav)
|
||||||
|
|
||||||
# audio_bytes = io.BytesIO(wav.read())
|
# return pygame.mixer.Sound object and track duration in milliseconds
|
||||||
|
return audio, sound, len(audio)
|
||||||
|
|
||||||
return sound
|
def remaining(self, position: int):
|
||||||
|
return self.audio[-position:]
|
||||||
|
|
|
@ -24,8 +24,8 @@ class TrackControl(QToolBar):
|
||||||
self.current_position_indicator = QLabel("0:00")
|
self.current_position_indicator = QLabel("0:00")
|
||||||
self.addWidget(self.current_position_indicator)
|
self.addWidget(self.current_position_indicator)
|
||||||
|
|
||||||
self.play_position_slider = QSlider(Qt.Orientation.Horizontal, self)
|
self.track_progress_slider = QSlider(Qt.Orientation.Horizontal, self)
|
||||||
self.addWidget(self.play_position_slider)
|
self.addWidget(self.track_progress_slider)
|
||||||
|
|
||||||
self.track_length_indicator = QLabel("0:00")
|
self.track_length_indicator = QLabel("0:00")
|
||||||
self.addWidget(self.track_length_indicator)
|
self.addWidget(self.track_length_indicator)
|
||||||
|
|
Loading…
Reference in a new issue