playqueue: Add a way to delete rows by track_id
This will be used to delete tracks that no longer exist in the library. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
4c16f8370b
commit
2535a2fe56
|
@ -91,6 +91,9 @@ Playqueue: (lib/playqueue.cpp)
|
||||||
Erase tracks[playqueue_id] from the tracks vector.
|
Erase tracks[playqueue_id] from the tracks vector.
|
||||||
length -= track.length.
|
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 :: set_flag(playqueue_flags flag);
|
||||||
void Playqueue :: unset_flag(playqueue_flags flag);
|
void Playqueue :: unset_flag(playqueue_flags flag);
|
||||||
Set or unset the given flag.
|
Set or unset the given flag.
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
unsigned int add(unsigned int);
|
unsigned int add(unsigned int);
|
||||||
unsigned int add_front(unsigned int);
|
unsigned int add_front(unsigned int);
|
||||||
void del(unsigned int);
|
void del(unsigned int);
|
||||||
|
void del_track(unsigned int);
|
||||||
unsigned int size();
|
unsigned int size();
|
||||||
|
|
||||||
unsigned int next();
|
unsigned int next();
|
||||||
|
|
|
@ -85,6 +85,17 @@ void Playqueue :: del(unsigned int plist_id)
|
||||||
length -= song.track->length;
|
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()
|
unsigned int Playqueue :: size()
|
||||||
{
|
{
|
||||||
return tracks.size();
|
return tracks.size();
|
||||||
|
|
|
@ -181,6 +181,25 @@ void test_6()
|
||||||
while (pqueue.size() > 0)
|
while (pqueue.size() > 0)
|
||||||
print("Selecting id: %u\n", pqueue.next());
|
print("Selecting id: %u\n", pqueue.next());
|
||||||
test_pqueue_status("6b", pqueue);
|
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)
|
int main(int argc, char **argv)
|
||||||
|
@ -198,5 +217,6 @@ int main(int argc, char **argv)
|
||||||
test_4();
|
test_4();
|
||||||
test_5();
|
test_5();
|
||||||
test_6();
|
test_6();
|
||||||
|
test_7();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,3 +112,10 @@ Selecting id: 12
|
||||||
Selecting id: 14
|
Selecting id: 14
|
||||||
Selecting id: 3
|
Selecting id: 3
|
||||||
Test 6b: size: 0, length: 0
|
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
|
||||||
|
|
Loading…
Reference in New Issue