From 74bf30bec5e908eefb82752ff02ec42ae89e308d Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sun, 11 May 2014 10:53:48 -0400 Subject: [PATCH] queue: Remove the add_front() function This is best implemented in a derived class, since it's only used by the recently played queue. Signed-off-by: Anna Schumaker --- include/queue.h | 4 ++-- lib/audio.cpp | 17 ++++++++++++++--- lib/queue.cpp | 31 +++++++++++-------------------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/include/queue.h b/include/queue.h index fb96dd24..9a05eef0 100644 --- a/include/queue.h +++ b/include/queue.h @@ -33,6 +33,7 @@ protected: unsigned int _length; unsigned int find_sorted_id(Track *); + unsigned int _add_at(Track *, unsigned int); void _add_sort(sort_t, bool); public: @@ -48,8 +49,7 @@ public: std::string get_length_str(); - unsigned int add(Track *); - unsigned int add_front(unsigned int); + virtual unsigned int add(Track *); void del(unsigned int); void del_track(unsigned int); void track_updated(unsigned int); diff --git a/lib/audio.cpp b/lib/audio.cpp index 051f49d7..162ca3c2 100644 --- a/lib/audio.cpp +++ b/lib/audio.cpp @@ -19,9 +19,20 @@ static bool o_pause_enabled = false; static unsigned int o_pause_count = 0; static bool o_should_pause = false; -static Queue o_recently_played(Q_ENABLED | Q_REPEAT | Q_NO_SORT | Q_DISABLE_CHANGED_SIZE); static File f_cur_track("cur_track"); + +class RecentQueue : public Queue +{ +public: + RecentQueue() + : Queue(Q_ENABLED | Q_REPEAT | Q_NO_SORT | Q_DISABLE_CHANGED_SIZE) {} + unsigned int add(Track *track) { return _add_at(track, 0); } +}; + +static RecentQueue o_recently_played; + + static void parse_error(GstMessage *error) { GError *err; @@ -197,7 +208,7 @@ void audio :: next() cur_trackid = track->id; save_state(); o_recently_played.del_track(track->id); - o_recently_played.add_front(track->id); + o_recently_played.add(track); o_recently_played.set_cur(0); } @@ -231,7 +242,7 @@ void audio :: load_trackid(unsigned int track_id) cur_trackid = track_id; save_state(); o_recently_played.del_track(track_id); - o_recently_played.add_front(track_id); + o_recently_played.add(track); o_recently_played.set_cur(0); } diff --git a/lib/queue.cpp b/lib/queue.cpp index 57d0d79d..5f011ead 100644 --- a/lib/queue.cpp +++ b/lib/queue.cpp @@ -149,31 +149,22 @@ unsigned int Queue :: find_sorted_id(Track *rhs) return begin; } +unsigned int Queue :: _add_at(Track *track, unsigned int pos) +{ + _tracks.insert(_tracks.begin() + pos, track); + _length += track->length; + get_callbacks()->on_queue_track_add(this, pos); + if (!(_flags & Q_DISABLE_CHANGED_SIZE)) + get_callbacks()->on_queue_changed(); + return pos; +} + unsigned int Queue :: add(Track *track) { unsigned int id = _tracks.size(); - if (_sort_order.size() > 0) id = find_sorted_id(track); - - _tracks.insert(_tracks.begin() + id, track); - _length += track->length; - get_callbacks()->on_queue_track_add(this, id); - if (!(_flags & Q_DISABLE_CHANGED_SIZE)) - get_callbacks()->on_queue_changed(); - return id; -} - -unsigned int Queue :: add_front(unsigned int track_id) -{ - Track *track = tagdb :: lookup(track_id); - _tracks.insert(_tracks.begin(), track); - - _length += track->length; - get_callbacks()->on_queue_track_add(this, 0); - if (!(_flags & Q_DISABLE_CHANGED_SIZE)) - get_callbacks()->on_queue_changed(); - return 0; + return _add_at(track, id); } void Queue :: del(unsigned int plist_id)