queue: Fix up queue :: add()
It should take a Track pointer, rather than a track_id. This makes the code easier to work with. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
69f4d21c04
commit
38ae4ba0f3
|
@ -161,7 +161,7 @@ void Tab :: tab_queue_add(Queue *pq)
|
|||
|
||||
tab_selected_ids(ids);
|
||||
for (unsigned int i = 0; i < ids.size(); i++)
|
||||
pq->add(ids[i]);
|
||||
pq->add(tagdb :: lookup(ids[i]));
|
||||
}
|
||||
|
||||
bool Tab :: tab_queue_selected(bool random)
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
|
||||
std::string get_length_str();
|
||||
|
||||
unsigned int add(unsigned int);
|
||||
unsigned int add(Track *);
|
||||
unsigned int add_front(unsigned int);
|
||||
void del(unsigned int);
|
||||
void del_track(unsigned int);
|
||||
|
|
|
@ -15,7 +15,7 @@ static File deck_file("deck");
|
|||
|
||||
static void add_library_track(unsigned int id)
|
||||
{
|
||||
library_playqueue.add(id);
|
||||
library_playqueue.add(tagdb :: lookup(id));
|
||||
}
|
||||
|
||||
static void del_library_track(unsigned int id)
|
||||
|
|
|
@ -38,7 +38,7 @@ void playlist :: init()
|
|||
|
||||
ids = get_tracks(cur_pq);
|
||||
for (it = ids.begin(); it != ids.end(); it++)
|
||||
playlist_pq.add(*it);
|
||||
playlist_pq.add(tagdb :: lookup(*it));
|
||||
}
|
||||
|
||||
void playlist :: add(const std::string &name, unsigned int track_id)
|
||||
|
@ -47,7 +47,7 @@ void playlist :: add(const std::string &name, unsigned int track_id)
|
|||
playlist_db.insert(name, track_id);
|
||||
playlist_db.save();
|
||||
if (name == cur_pq)
|
||||
playlist_pq.add(track_id);
|
||||
playlist_pq.add(tagdb :: lookup(track_id));
|
||||
if (name == "Banned")
|
||||
get_callbacks()->on_playlist_ban(track_id);
|
||||
} else
|
||||
|
@ -76,7 +76,7 @@ void playlist :: select(const std::string &name)
|
|||
playlist_pq.del(0);
|
||||
|
||||
for (it = ids.begin(); it != ids.end(); it++)
|
||||
playlist_pq.add(*it);
|
||||
playlist_pq.add(tagdb :: lookup(*it));
|
||||
cur_pq = name;
|
||||
}
|
||||
|
||||
|
|
|
@ -149,10 +149,9 @@ unsigned int Queue :: find_sorted_id(Track *rhs)
|
|||
return begin;
|
||||
}
|
||||
|
||||
unsigned int Queue :: add(unsigned int track_id)
|
||||
unsigned int Queue :: add(Track *track)
|
||||
{
|
||||
unsigned int id = _tracks.size();
|
||||
Track *track = tagdb :: lookup(track_id);
|
||||
|
||||
if (_sort_order.size() > 0)
|
||||
id = find_sorted_id(track);
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
/*
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <callback.h>
|
||||
#include <queue.h>
|
||||
#include <tags.h>
|
||||
#include "test.h"
|
||||
|
||||
|
||||
unsigned int count_add = 0;
|
||||
|
||||
|
||||
class TestQueue : public Queue
|
||||
{
|
||||
public:
|
||||
|
@ -60,6 +64,29 @@ void test_flags()
|
|||
test :: equal(q.has_flag(Q_NO_SORT), false);
|
||||
}
|
||||
|
||||
void test_add_cb(Queue *q, unsigned int id)
|
||||
{
|
||||
check_equal(id, count_add);
|
||||
count_add++;
|
||||
}
|
||||
|
||||
void test_add_remove()
|
||||
{
|
||||
TestQueue q(0);
|
||||
unsigned int expected = 0;
|
||||
|
||||
get_callbacks()->on_queue_track_add = test_add_cb;
|
||||
|
||||
test :: begin();
|
||||
for (unsigned int i = 0; i < 24; i++) {
|
||||
check_equal(q.add(tagdb :: lookup(i)), i);
|
||||
expected += 100 + (i * 10);
|
||||
}
|
||||
test :: success();
|
||||
|
||||
test :: equal(q.get_length(), expected);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
test :: cp_library();
|
||||
|
@ -68,5 +95,6 @@ int main(int argc, char **argv)
|
|||
run_test("Queue Default Constructor Test", test_default);
|
||||
run_test("Queue Constructor Test", test_constructor, Q_ENABLED | Q_RANDOM);
|
||||
run_test("Queue Flag Test", test_flags);
|
||||
run_test("Queue Add and Remove Test", test_add_remove);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue