core/queue: Move queue_selected() out of the queue struct
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
d6ae61d915
commit
6bd625f65b
|
@ -130,6 +130,9 @@ void queue :: del(unsigned int index)
|
|||
q_length -= q_tracks[index]->tr_length;
|
||||
q_tracks.erase(q_tracks.begin() + index);
|
||||
q_notify->on_track_removed(index);
|
||||
|
||||
if (q_cur == index)
|
||||
q_cur--;
|
||||
}
|
||||
|
||||
void queue :: del(struct track *track)
|
||||
|
@ -148,6 +151,13 @@ void queue :: updated(struct track *track)
|
|||
}
|
||||
}
|
||||
|
||||
void queue_selected(struct queue *queue, unsigned int index)
|
||||
{
|
||||
queue->q_cur = index;
|
||||
if (queue->has_flag(Q_REPEAT) == false)
|
||||
queue->del(index);
|
||||
}
|
||||
|
||||
struct track *queue :: next()
|
||||
{
|
||||
struct track *res;
|
||||
|
@ -165,10 +175,7 @@ struct track *queue :: next()
|
|||
|
||||
q_cur %= q_tracks.size();
|
||||
res = q_tracks[q_cur];
|
||||
if (!(q_flags & Q_REPEAT)) {
|
||||
del(q_cur);
|
||||
q_cur--;
|
||||
}
|
||||
queue_selected(this, q_cur);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -218,12 +225,3 @@ struct track *queue :: operator[](unsigned int index)
|
|||
{
|
||||
return q_tracks[index];
|
||||
}
|
||||
|
||||
void queue :: track_selected(unsigned int index)
|
||||
{
|
||||
q_cur = index;
|
||||
if (has_flag(Q_REPEAT) == false) {
|
||||
del(q_cur);
|
||||
q_cur--;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ void QueueModel::on_row_changed(unsigned int row)
|
|||
void QueueModel::on_path_selected(const Gtk::TreePath &path)
|
||||
{
|
||||
audio :: load_track(track_get(path_to_id(path)));
|
||||
_queue->track_selected(path[0]);
|
||||
queue_selected(_queue, path[0]);
|
||||
audio :: play();
|
||||
}
|
||||
|
||||
|
|
|
@ -201,15 +201,10 @@ struct queue {
|
|||
* @return The track found at the requested index.
|
||||
*/
|
||||
struct track *operator[](unsigned int);
|
||||
|
||||
/**
|
||||
* Tell the queue that a track has been selected for playback without
|
||||
* calling Queue :: next(). If Q_REPEAT is not set then the Track
|
||||
* will be removed from the queue.
|
||||
*
|
||||
* @param index The index that is now playing.
|
||||
*/
|
||||
void track_selected(unsigned int);
|
||||
};
|
||||
|
||||
|
||||
/* Called to tell the queue that a specific index has been selected. */
|
||||
void queue_selected(struct queue *, unsigned int);
|
||||
|
||||
#endif /* OCARINA_CORE_QUEUE_H */
|
||||
|
|
|
@ -159,7 +159,7 @@ static void test_stress(unsigned int N)
|
|||
q.set_flag(Q_REPEAT);
|
||||
for (i = 0; i < ex_size; i++) {
|
||||
test_loop_equal(q.next(), track_get((i % 11) + 2), i);
|
||||
q.track_selected(i);
|
||||
queue_selected(&q, i);
|
||||
test_loop_equal(q.size(), ex_size, i);
|
||||
} test_loop_passed();
|
||||
|
||||
|
@ -205,28 +205,28 @@ static void test_rand_select()
|
|||
test_equal(q.next()->tr_dbe.dbe_index, 1);
|
||||
|
||||
/* select = 6, q = { <0>, 2, 3, 4, 5, 6, (7), 8, 9, 10, 11, 12 } */
|
||||
q.track_selected(6);
|
||||
queue_selected(&q, 6);
|
||||
test_equal(q.size(), 11);
|
||||
|
||||
/* rand() = 3, q = { 0, 2, 3, 4, 5, <6>, 8, 9, [10], 11, 12 } */
|
||||
test_equal(q.next()->tr_dbe.dbe_index, 10);
|
||||
|
||||
/* select = 7, q = { 0, 2, 3, 4, 5, 6, 8, (<9>), 11, 12 } */
|
||||
q.track_selected(7);
|
||||
queue_selected(&q, 7);
|
||||
test_equal(q.size(), 9);
|
||||
|
||||
/* rand() = 4, q = { 0, 2, 3, 4, 5, 6, <8>, [11], 12 } */
|
||||
test_equal(q.next()->tr_dbe.dbe_index, 11);
|
||||
|
||||
/* select = 2, q = { 0, 2, (3), 4, 5, 6, <8>, 12 } */
|
||||
q.track_selected(2);
|
||||
queue_selected(&q, 2);
|
||||
test_equal(q.size(), 7);
|
||||
|
||||
/* rand() = 1, q = { 0, <2>, [4], 5, 6, 8, 12 } */
|
||||
test_equal(q.next()->tr_dbe.dbe_index, 4);
|
||||
|
||||
/* select = 1, q = { 0, <2>, 5, 6, 8, (12) } */
|
||||
q.track_selected(5);
|
||||
queue_selected(&q, 5);
|
||||
test_equal(q.size(), 5);
|
||||
|
||||
/* rand() = 1, q = { [0], 2, 5, 6, <8>, } */
|
||||
|
@ -236,14 +236,14 @@ static void test_rand_select()
|
|||
test_equal(q.next()->tr_dbe.dbe_index, 2);
|
||||
|
||||
/* select = 1, q = { <>, 5, (6), 8, } */
|
||||
q.track_selected(1);
|
||||
queue_selected(&q, 1);
|
||||
test_equal(q.size(), 2);
|
||||
|
||||
/* rand() = 1, q = { <5>, [8], } */
|
||||
test_equal(q.next()->tr_dbe.dbe_index, 8);
|
||||
|
||||
/* select = 1, q = { <[5]> } */
|
||||
q.track_selected(0);
|
||||
queue_selected(&q, 0);
|
||||
test_equal(q.size(), 0);
|
||||
|
||||
/* q = { } */
|
||||
|
|
Loading…
Reference in New Issue