diff --git a/src/playbin.vala b/src/playbin.vala index 7650198..9b37595 100644 --- a/src/playbin.vala +++ b/src/playbin.vala @@ -25,6 +25,8 @@ class Playbin : GLib.Object { public PlaybinState state { get; private set; default = PlaybinState.STOPPED; } + public Song? current_song { get; private set; default = null; } + // true if a timer should update the position property private bool update_position = false; public int64 position { get; private set; default = 0; } @@ -34,7 +36,7 @@ class Playbin : GLib.Object { // sent when a new song starts playing // continues: whether the track is a gapless continuation - public signal void now_playing (bool continues, uint index, Song song); + public signal void now_playing (bool continues); public signal void stopped (); // the index of the track in the play queue that is currently playing @@ -183,7 +185,8 @@ class Playbin : GLib.Object { var now_playing = (Song) play_queue.get_item (this.current_position); if (this.api.stream_uri (now_playing.id) == (string) this.playbin.current_uri) { if (continues) { - this.now_playing (true, this.current_position, now_playing); + this.current_song = now_playing; + this.now_playing (true); } if (this.current_position+1 < play_queue.get_n_items ()) { @@ -238,7 +241,7 @@ class Playbin : GLib.Object { // playbin.uri wont match up with the current track's stream uri and we can // fix it there - this.now_playing (false, position, song); + this.current_song = song; this.position = 0; this.duration = 1; } diff --git a/src/ui/window.blp b/src/ui/window.blp index a2404d0..af97d78 100644 --- a/src/ui/window.blp +++ b/src/ui/window.blp @@ -103,21 +103,21 @@ template $UiWindow: Adw.ApplicationWindow { styles [ "heading" ] xalign: 0; halign: start; - label: bind $song_title (template.song) as ; + label: bind $song_title (template.playbin as <$Playbin>.current_song) as ; ellipsize: end; } Label { styles [ "caption" ] xalign: 0; - label: bind $song_artist (template.song) as ; + label: bind $song_artist (template.playbin as <$Playbin>.current_song) as ; ellipsize: end; } Label { styles [ "caption" ] xalign: 0; - label: bind $song_album (template.song) as ; + label: bind $song_album (template.playbin as <$Playbin>.current_song) as ; ellipsize: end; } } diff --git a/src/ui/window.vala b/src/ui/window.vala index d624b82..0370b5e 100644 --- a/src/ui/window.vala +++ b/src/ui/window.vala @@ -20,8 +20,6 @@ class Ui.Window : Adw.ApplicationWindow { set { this.playbin.mute = value; } } - public Song? song { get; set; default = null; } - private Cancellable cancel_loading_art; public bool cover_art_loading { get; set; default = false; } public Gdk.Paintable playing_cover_art { get; set; } @@ -60,13 +58,11 @@ class Ui.Window : Adw.ApplicationWindow { this.setup.connected.connect ((api) => { this.playbin.api = api; - this.playbin.now_playing.connect ((continues, position, song) => { - this.song = song; - api.scrobble.begin (song.id); - this.play_queue.selection.playbin_select (position); + this.playbin.now_playing.connect ((continues) => { + api.scrobble.begin (playbin.current_song.id); + this.play_queue.selection.playbin_select (playbin.current_position); }); this.playbin.stopped.connect (() => { - this.song = null; this.play_queue.selection.playbin_select (this.play_queue_store.get_n_items ()); }); @@ -98,17 +94,17 @@ class Ui.Window : Adw.ApplicationWindow { this.sidebar.select_row (this.sidebar.get_row_at_index (0)); - this.notify["song"].connect (() => { + this.playbin.notify["current-song"].connect (() => { if (this.cancel_loading_art != null) { this.cancel_loading_art.cancel (); } this.cancel_loading_art = new GLib.Cancellable (); this.playing_cover_art = Gdk.Paintable.empty (1, 1); - if (this.song != null) { + if (playbin.current_song != null) { this.cover_art_loading = true; - string song_id = this.song.id; + string song_id = playbin.current_song.id; public_api.cover_art.begin (song_id, this.cancel_loading_art, (obj, res) => { try { this.playing_cover_art = Gdk.Texture.for_pixbuf (public_api.cover_art.end (res)); @@ -122,7 +118,6 @@ class Ui.Window : Adw.ApplicationWindow { }); } }); - this.song = null; this.playbin.notify["position"].connect (() => { // only set if we aren't seeking