diff --git a/core/deck.cpp b/core/deck.cpp index 3d1954a7..46ef7597 100644 --- a/core/deck.cpp +++ b/core/deck.cpp @@ -32,7 +32,7 @@ unsigned int TempQueue :: add(struct track *track) void TempQueue :: del(struct track *track) { - queue :: del(track); + queue_remove_all(this, track); deck :: write(); } @@ -201,7 +201,7 @@ struct track *deck :: next() if (!track) track = queue_next(collection :: get_queue()); if (track) { - recent_queue.del(track); + queue_remove_all(&recent_queue, track); queue_add(&recent_queue, track); recent_queue.q_cur = 0; } diff --git a/core/library.cpp b/core/library.cpp index c2e3d8b2..ae41d371 100644 --- a/core/library.cpp +++ b/core/library.cpp @@ -126,7 +126,7 @@ static void validate_library(void *data) path = track_path(track); if (g_file_test(path, G_FILE_TEST_EXISTS) == false) { - library_q.del(track); + queue_remove_all(&library_q, track); track_remove(track); } g_free(path); @@ -225,7 +225,7 @@ void collection :: set_enabled(struct library *library, bool enabled) if (enabled) queue_add(&library_q, track); else - library_q.del(track); + queue_remove_all(&library_q, track); } } } diff --git a/core/playlist.cpp b/core/playlist.cpp index 0ccad289..e8d78deb 100644 --- a/core/playlist.cpp +++ b/core/playlist.cpp @@ -87,7 +87,8 @@ void playlist :: init() return; set_for_each(&ent->ie_set, &it) - collection :: get_queue()->del(track_get(it.it_val)); + queue_remove_all(collection :: get_queue(), + track_get(it.it_val)); } bool playlist :: has(struct track *track, const std::string &name) @@ -107,7 +108,7 @@ void playlist :: add(struct track *track, const std::string &name) if (cur_plist == name) queue_add(&playlist_q, track); if (name == "Banned") - collection :: get_queue()->del(track); + queue_remove_all(collection :: get_queue(), track); } } @@ -115,7 +116,7 @@ void playlist :: del(struct track *track, const std::string &name) { index_remove(&playlist_db, name.c_str(), track->tr_dbe.dbe_index); if (cur_plist == name) - playlist_q.del(track); + queue_remove_all(&playlist_q, track); if (name == "Banned") queue_add(collection :: get_queue(), track); } diff --git a/core/queue.cpp b/core/queue.cpp index 39bc59bd..4de93a9a 100644 --- a/core/queue.cpp +++ b/core/queue.cpp @@ -141,11 +141,12 @@ void queue_remove(struct queue *queue, unsigned int index) queue->q_cur--; } -void queue :: del(struct track *track) +void queue_remove_all(struct queue *queue, struct track *track) { - for (unsigned int i = 0; i < q_tracks.size(); i++) { - while ((i < q_tracks.size()) && (q_tracks[i] == track)) - queue_remove(this, i); + for (unsigned int i = 0; i < queue->q_tracks.size(); i++) { + while (i < queue->q_tracks.size() && + queue->q_tracks[i] == track) + queue_remove(queue, i); } } diff --git a/gui/manager.cpp b/gui/manager.cpp index 46f0d1f6..ab4820a2 100644 --- a/gui/manager.cpp +++ b/gui/manager.cpp @@ -98,7 +98,7 @@ static void remove_banned_tracks() return; set_for_each(&ent->ie_set, &it) - collection :: get_queue()->del(track_get(it.it_val)); + queue_remove_all(collection :: get_queue(), track_get(it.it_val)); } diff --git a/include/core/queue.h b/include/core/queue.h index 6a4f6c2d..47e1a479 100644 --- a/include/core/queue.h +++ b/include/core/queue.h @@ -108,14 +108,6 @@ struct queue { * @param file File to read Queue data from. */ void read(file &); - - - /** - * Remove all instances of a track from the queue. - * - * @param track Track to remove from the queue. - */ - virtual void del(struct track *); }; @@ -154,6 +146,9 @@ unsigned int queue_add(struct queue *, struct track *); /* Called to remove a track from the queue by index. */ void queue_remove(struct queue *, unsigned int); +/* Called to remove all instances of the track from the queue. */ +void queue_remove_all(struct queue *, struct track *); + /* Called to tell the queue that a track has been updated. */ void queue_updated(struct queue *, struct track *); diff --git a/tests/core/queue.cpp b/tests/core/queue.cpp index be0c9153..47c7af33 100644 --- a/tests/core/queue.cpp +++ b/tests/core/queue.cpp @@ -168,11 +168,11 @@ static void test_stress(unsigned int N) test_equal(q.q_length, ex_length); test_equal(queue_size(&q), ex_size); - /* Queue :: del(struct track *) */ + /* queue_remove_all() */ track = track_get(0); ex_length -= track->tr_length * (N / 13); ex_size -= (N / 13); - q.del(track); + queue_remove_all(&q, track); test_equal(q.q_length, ex_length); test_equal(queue_size(&q), ex_size);