diff --git a/data/ui/window.blp b/data/ui/window.blp index 696d937..94c400d 100644 --- a/data/ui/window.blp +++ b/data/ui/window.blp @@ -310,12 +310,13 @@ template $HighTideWindow: Adw.ApplicationWindow { orientation: vertical; Box { halign: center; + spacing: 6; Label song_title_label { label: "No Song"; ellipsize: end; styles [ - "title-1", + "title-2", ] } diff --git a/src/lib/player_object.py b/src/lib/player_object.py index 354c3a4..0600c47 100644 --- a/src/lib/player_object.py +++ b/src/lib/player_object.py @@ -58,9 +58,12 @@ class PlayerObject(GObject.GObject): 'song-added-to-queue': (GObject.SignalFlags.RUN_FIRST, None, ()), 'play-changed': (GObject.SignalFlags.RUN_FIRST, None, (bool,)), 'duration-changed': (GObject.SignalFlags.RUN_FIRST, None, ()), - 'shuffle-changed': (GObject.SignalFlags.RUN_FIRST, None, (bool,)) + 'shuffle-changed': (GObject.SignalFlags.RUN_FIRST, None, (bool,)), + 'volume-changed': (GObject.SignalFlags.RUN_FIRST, None, (float,)) } + # TODO add add_to_queue and play_next back!!! + def __init__(self, preferred_sink=AudioSink.AUTO, sink_device=None): GObject.GObject.__init__(self) Gst.init(None) @@ -165,6 +168,12 @@ def play_this(self, thing, index=0): self.play() self.emit("song-changed") + def shuffle_this(self, thing): + """Same as play_this, but on shuffle""" + tracks = self.get_track_list(thing) + self.play_this(tracks, random.randint(0, len(tracks))) + self.shuffle(True) + def get_track_list(self, thing): """Convert various sources into a list of tracks.""" if isinstance(thing, Mix): @@ -282,8 +291,17 @@ def shuffle(self, state): self.emit("song-changed") + def add_to_queue(self, track): + self.queue.append(track) + self.emit("song-added-to-queue") + + def add_next(self, track): + self.queue.insert(0, track) + self.emit("song-added-to-queue") + def change_volume(self, value): self._player.set_property("volume", value) + self.emit("volume-changed", value) def _update_slider_callback(self): """Update playback slider and duration.""" diff --git a/src/mpris.py b/src/mpris.py index 9b56933..9ffc61f 100644 --- a/src/mpris.py +++ b/src/mpris.py @@ -18,6 +18,7 @@ from random import randint from .lib import variables + class Server: def __init__(self, con, path): method_outargs = {} @@ -164,7 +165,7 @@ def __init__(self, player): self.player.connect("song-changed", self._on_preset_changed) self.player.connect("duration-changed", self._on_preset_changed) self.player.connect("play-changed", self._on_playing_changed) - # MainPlayer.get().connect("notify::volume", self._on_volume_changed) + self.player.connect("volume-changed", self._on_volume_changed) def Raise(self): variables.window.present_with_time(Gdk.CURRENT_TIME) @@ -289,11 +290,8 @@ def _on_preset_changed(self, *args): def _on_volume_changed(self, _player, volume): self.PropertiesChanged( self.__MPRIS_PLAYER_IFACE, - { - "Volume": GLib.Variant("d", self.player.volume), - }, - [], - ) + {"Volume": GLib.Variant("d", volume)}, + []) def _on_playing_changed(self, *args): properties = {"PlaybackStatus": GLib.Variant("s", self._get_status())} diff --git a/src/pages/album_page.py b/src/pages/album_page.py index 50b5aae..7a33a18 100644 --- a/src/pages/album_page.py +++ b/src/pages/album_page.py @@ -51,8 +51,8 @@ def _th_load_page(self): play_btn = builder.get_object("_play_button") self.signals.append(( - play_btn, play_btn.connect( - "clicked", self.on_play_button_clicked))) + play_btn, + play_btn.connect("clicked", self.on_play_button_clicked))) shuffle_btn = builder.get_object("_shuffle_button") self.signals.append(( diff --git a/src/pages/artist_page.py b/src/pages/artist_page.py index c8feb94..a482bef 100644 --- a/src/pages/artist_page.py +++ b/src/pages/artist_page.py @@ -45,6 +45,8 @@ def __init__(self, _artist, _name): self.top_tracks = [] self.artist = _artist + # TODO get the arist ID not the artist so it shows the page faster + def _th_load_page(self): print(f"artist: {self.artist.name}, id: {self.artist.id}, {self.artist.picture}") @@ -167,24 +169,13 @@ def _th_load_page(self): def on_row_selected(self, list_box, row): index = int(row.get_name()) - - variables.player_object.current_mix_album_list = self.top_tracks - track = variables.player_object.current_mix_album_list[index] - variables.player_object.current_mix_album = track.album - variables.player_object.play_track(track) - variables.player_object.current_song_index = index + variables.player_object.play_this(self.item, index) def on_play_button_clicked(self, btn): - variables.player_object.current_mix_album = self.artist - variables.player_object.current_mix_album_list = self.top_tracks - track = variables.player_object.current_mix_album_list[0] - variables.player_object.play_track(track) - variables.player_object.current_song_index = 0 + variables.player_object.play_this(self.top_tracks, 0) def on_shuffle_button_clicked(self, btn): - variables.player_object.current_mix_album = None - variables.player_object.current_mix_album_list = self.top_tracks - variables.player_object.play_shuffle() + variables.player_object.play_this(self.shuffle_this, 0) def on_artist_radio_button_clicked(self, btn): from .track_radio_page import trackRadioPage diff --git a/src/pages/mix_page.py b/src/pages/mix_page.py index d86d8bf..5190cc1 100644 --- a/src/pages/mix_page.py +++ b/src/pages/mix_page.py @@ -82,7 +82,6 @@ def _th_load_page(self): def on_row_selected(self, list_box, row): index = int(row.get_name()) - variables.player_object.play_this(self.item, index) def th_add_to_my_collection(self, btn): diff --git a/src/pages/playlist_page.py b/src/pages/playlist_page.py index 6860794..c83eec6 100644 --- a/src/pages/playlist_page.py +++ b/src/pages/playlist_page.py @@ -93,5 +93,4 @@ def _th_load_page(self): def on_row_selected(self, list_box, row): index = int(row.get_name()) - variables.player_object.play_this(self.item, index) diff --git a/src/window.py b/src/window.py index a0dc571..3fc551c 100644 --- a/src/window.py +++ b/src/window.py @@ -89,7 +89,7 @@ def __init__(self, **kwargs): "default-height", Gio.SettingsBindFlags.DEFAULT) self.player_object = PlayerObject( - self.settings.get_string('preferred-sink')) + self.settings.get_int('preferred-sink')) variables.player_object = self.player_object self.volume_button.get_adjustment().set_value(