Skip to content

Commit

Permalink
various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Jan 10, 2025
1 parent f5192ce commit 5770c6c
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 27 deletions.
3 changes: 2 additions & 1 deletion data/ui/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}

Expand Down
20 changes: 19 additions & 1 deletion src/lib/player_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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."""
Expand Down
10 changes: 4 additions & 6 deletions src/mpris.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from random import randint
from .lib import variables


class Server:
def __init__(self, con, path):
method_outargs = {}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/album_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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((
Expand Down
19 changes: 5 additions & 14 deletions src/pages/artist_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/pages/mix_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion src/pages/playlist_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 5770c6c

Please sign in to comment.