diff --git a/design/playqueue.txt b/design/playqueue.txt index daab7fdd..d5fc1c30 100644 --- a/design/playqueue.txt +++ b/design/playqueue.txt @@ -91,6 +91,9 @@ Playqueue: (lib/playqueue.cpp) Erase tracks[playqueue_id] from the tracks vector. length -= track.length. + void Playqueue :: del_track(unsigned int track_id); + Erase all tracks with track id track_id. + void Playqueue :: set_flag(playqueue_flags flag); void Playqueue :: unset_flag(playqueue_flags flag); Set or unset the given flag. diff --git a/include/playqueue.h b/include/playqueue.h index cbb756a4..a0dbc275 100644 --- a/include/playqueue.h +++ b/include/playqueue.h @@ -36,6 +36,7 @@ public: unsigned int add(unsigned int); unsigned int add_front(unsigned int); void del(unsigned int); + void del_track(unsigned int); unsigned int size(); unsigned int next(); diff --git a/lib/playqueue.cpp b/lib/playqueue.cpp index 3d1b85fb..5cc54fbf 100644 --- a/lib/playqueue.cpp +++ b/lib/playqueue.cpp @@ -85,6 +85,17 @@ void Playqueue :: del(unsigned int plist_id) length -= song.track->length; } +void Playqueue :: del_track(unsigned int track_id) +{ + unsigned int i = 0; + while (i < tracks.size()) { + if (tracks[i] == track_id) + del(i); + else + i++; + } +} + unsigned int Playqueue :: size() { return tracks.size(); diff --git a/tests/playqueue/playqueue.cpp b/tests/playqueue/playqueue.cpp index 72274a67..ba47ccc1 100644 --- a/tests/playqueue/playqueue.cpp +++ b/tests/playqueue/playqueue.cpp @@ -181,6 +181,25 @@ void test_6() while (pqueue.size() > 0) print("Selecting id: %u\n", pqueue.next()); test_pqueue_status("6b", pqueue); + print("\n"); +} + +void test_7() +{ + char test[] = "7a"; + Playqueue pqueue(PQ_ENABLED); + + for (unsigned int i = 0; i < 60; i++) + pqueue.add(i % 15); + test_pqueue_status(test, pqueue); + + for (unsigned int i = 0; i < 15; i++) { + pqueue.del_track(i); + if ((i + 1) % 3 == 0) { + test[1]++; + test_pqueue_status(test, pqueue); + } + } } int main(int argc, char **argv) @@ -198,5 +217,6 @@ int main(int argc, char **argv) test_4(); test_5(); test_6(); + test_7(); return 0; } diff --git a/tests/playqueue/playqueue.good b/tests/playqueue/playqueue.good index 90cdf3bc..2bd5a7dc 100644 --- a/tests/playqueue/playqueue.good +++ b/tests/playqueue/playqueue.good @@ -112,3 +112,10 @@ Selecting id: 12 Selecting id: 14 Selecting id: 3 Test 6b: size: 0, length: 0 + +Test 7a: size: 60, length: 8572 +Test 7b: size: 48, length: 8288 +Test 7c: size: 36, length: 5608 +Test 7d: size: 24, length: 2964 +Test 7e: size: 12, length: 2644 +Test 7f: size: 0, length: 0