diff --git a/src/playbin.vala b/src/playbin.vala index 5e71bec..a9baf39 100644 --- a/src/playbin.vala +++ b/src/playbin.vala @@ -40,8 +40,8 @@ public class Playbin : GLib.Object { } } - // invariant: equal to play queue length iff state is STOPPED - public uint play_queue_position { get; private set; } + // invariant: negative iff stopped, otherwise < play queue length + public int play_queue_position { get; private set; default = -1; } // signalled when a new track is current public signal void new_track (); @@ -125,15 +125,15 @@ public class Playbin : GLib.Object { int64 playlist_pos = data.parse_int64 (); if (playlist_pos < 0) { if (this.state != PlaybinState.STOPPED) { - error ("mpv has no current playlist entry, but we think it's index %u", this.play_queue_position); + error ("mpv has no current playlist entry, but we think it's index %d", this.play_queue_position); } - assert (this.play_queue_position == this.play_queue.get_n_items ()); + assert (this.play_queue_position < 0); } else { if (this.state == PlaybinState.STOPPED) { - error ("mpv is at playlist entry %u, but we're stopped", (uint) playlist_pos); + error ("mpv is at playlist entry %d, but we're stopped", (int) playlist_pos); } - if (this.play_queue_position != (uint) playlist_pos) { - error ("mpv is at playlist entry %u, but we think it's %u", (uint) playlist_pos, this.play_queue_position); + if (this.play_queue_position != (int) playlist_pos) { + error ("mpv is at playlist entry %d, but we think it's %d", (int) playlist_pos, this.play_queue_position); } } break; @@ -182,6 +182,7 @@ public class Playbin : GLib.Object { if (this.play_queue_position == this._play_queue.get_n_items ()) { // reached the end (?) this.state = PlaybinState.STOPPED; + this.play_queue_position = -1; this.stopped (); } } @@ -220,7 +221,7 @@ public class Playbin : GLib.Object { requires (position < this.play_queue.get_n_items ()) { assert (this.mpv.command ({"playlist-play-index", position.to_string ()}) >= 0); - this.play_queue_position = position; + this.play_queue_position = (int) position; this.state = PlaybinState.PLAYING; this.play (); // make sure mpv actually starts playing the track } @@ -283,6 +284,7 @@ public class Playbin : GLib.Object { if (this.play_queue_position == this._play_queue.get_n_items ()) { // we just killed the last track this.state = PlaybinState.STOPPED; + this.play_queue_position = -1; this.stopped (); } } @@ -294,7 +296,7 @@ public class Playbin : GLib.Object { } this.state = PlaybinState.STOPPED; this._play_queue.remove_all (); - this.play_queue_position = 0; + this.play_queue_position = -1; this.stopped (); } @@ -305,7 +307,6 @@ public class Playbin : GLib.Object { this.api.stream_uri (song.id), "append", }) >= 0); - if (this.state == STOPPED) this.play_queue_position += 1; this._play_queue.append (song); } @@ -317,7 +318,6 @@ public class Playbin : GLib.Object { }); assert (err >= 0); - if (this.state == STOPPED) this.play_queue_position += 1; this._play_queue.append (song); } @@ -348,8 +348,8 @@ public class Playbin : GLib.Object { additions[to-from] = this._play_queue.get_item (from); this._play_queue.splice(from, to-from+1, additions); - if (this.play_queue_position == from) this.play_queue_position = to; - else if (this.play_queue_position > from && this.play_queue_position <= to) this.play_queue_position -= 1; + if (this.play_queue_position == (int) from) this.play_queue_position = (int) to; + else if (this.play_queue_position > (int) from && this.play_queue_position <= (int) to) this.play_queue_position -= 1; } else if (from > to) { assert(this.mpv.command({ "playlist-move", @@ -365,8 +365,8 @@ public class Playbin : GLib.Object { } this._play_queue.splice (to, from-to+1, additions); - if (this.play_queue_position == from) this.play_queue_position = to; - else if (this.play_queue_position >= to && this.play_queue_position < from) this.play_queue_position += 1; + if (this.play_queue_position == (int) from) this.play_queue_position = (int) to; + else if (this.play_queue_position >= (int) to && this.play_queue_position < (int) from) this.play_queue_position += 1; } } @@ -375,7 +375,7 @@ public class Playbin : GLib.Object { // don't clear the playlist, just in case (less state changes to sync) assert(this.mpv.command({"stop", "keep-playlist"}) >= 0); this.state = PlaybinState.STOPPED; - this.play_queue_position = this._play_queue.get_n_items (); + this.play_queue_position = -1; this.stopped (); }