core/queue: Switch over to using struct queue_iter
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
9835235acd
commit
2b426cff48
|
@ -20,7 +20,7 @@ void history_deinit()
|
|||
void history_add(struct track *track)
|
||||
{
|
||||
queue_add(&history_queue, track);
|
||||
_q_iter_set(&history_queue.q_tracks, &history_queue.q_cur, 0);
|
||||
queue_iter_set(&history_queue, &history_queue.q_cur, 0);
|
||||
}
|
||||
|
||||
struct track *history_prev()
|
||||
|
|
39
core/queue.c
39
core/queue.c
|
@ -79,22 +79,22 @@ static inline unsigned int __queue_add_sorted(struct queue *queue,
|
|||
return __queue_add_tail(queue, track);
|
||||
}
|
||||
|
||||
static inline bool __queue_erase(struct queue *queue, struct _q_iter *it)
|
||||
static inline bool __queue_erase(struct queue *queue, struct queue_iter *it)
|
||||
{
|
||||
struct track *track = (struct track *)_q_iter_val(it);
|
||||
struct track *track = queue_iter_val(it);
|
||||
|
||||
if (queue->q_ops)
|
||||
return queue->q_ops->qop_erase(queue, track);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void __queue_remove(struct queue *queue, struct _q_iter *it)
|
||||
static inline void __queue_remove(struct queue *queue, struct queue_iter *it)
|
||||
{
|
||||
struct track *track = (struct track *)_q_iter_val(it);
|
||||
struct track *track = queue_iter_val(it);
|
||||
unsigned int pos = it->it_pos;
|
||||
GList *link = it->it_iter;
|
||||
|
||||
_q_iter_prev(it);
|
||||
queue_iter_prev(it);
|
||||
g_queue_delete_link(&queue->q_tracks._queue, link);
|
||||
|
||||
queue->q_length -= track->tr_length;
|
||||
|
@ -117,7 +117,7 @@ static inline void __queue_updated(struct queue *queue, unsigned int pos)
|
|||
|
||||
static inline struct track *__queue_selected(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
struct track *track = (struct track *)_q_iter_val(&queue->q_cur);
|
||||
struct track *track = queue_iter_val(&queue->q_cur);
|
||||
|
||||
if (queue_has_flag(queue, Q_REPEAT) == false)
|
||||
__queue_remove(queue, &queue->q_cur);
|
||||
|
@ -140,9 +140,8 @@ void queue_init(struct queue *queue, unsigned int flags,
|
|||
queue->q_sort = NULL;
|
||||
queue->q_ops = ops;
|
||||
|
||||
queue->q_cur.it_pos = -1;
|
||||
queue->q_cur.it_iter = NULL;
|
||||
g_queue_init(&queue->q_tracks._queue);
|
||||
queue_iter_init(queue, &queue->q_cur);
|
||||
|
||||
queue->q_private = __queue_init(queue);
|
||||
}
|
||||
|
@ -178,30 +177,30 @@ unsigned int queue_add(struct queue *queue, struct track *track)
|
|||
|
||||
void queue_erase(struct queue *queue, unsigned int index)
|
||||
{
|
||||
struct _q_iter it;
|
||||
struct queue_iter it;
|
||||
|
||||
_q_iter_set(&queue->q_tracks, &it, index);
|
||||
queue_iter_set(queue, &it, index);
|
||||
if (__queue_erase(queue, &it))
|
||||
__queue_remove(queue, &it);
|
||||
}
|
||||
|
||||
void queue_remove(struct queue *queue, unsigned int index)
|
||||
{
|
||||
struct _q_iter it;
|
||||
struct queue_iter it;
|
||||
|
||||
_q_iter_set(&queue->q_tracks, &it, index);
|
||||
queue_iter_set(queue, &it, index);
|
||||
__queue_remove(queue, &it);
|
||||
}
|
||||
|
||||
void queue_remove_all(struct queue *queue, struct track *track)
|
||||
{
|
||||
struct _q_iter it;
|
||||
struct queue_iter it;
|
||||
|
||||
while (queue_at(queue, 0) == track)
|
||||
queue_remove(queue, 0);
|
||||
|
||||
_q_for_each(&queue->q_tracks, &it) {
|
||||
if (_q_iter_val(&it) == track)
|
||||
queue_for_each(queue, &it) {
|
||||
if (queue_iter_val(&it) == track)
|
||||
__queue_remove(queue, &it);
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +228,7 @@ struct track *queue_selected(struct queue *queue, unsigned int index)
|
|||
if (index > queue_size(queue))
|
||||
return NULL;
|
||||
if (queue->q_cur.it_pos != index)
|
||||
_q_iter_set(&queue->q_tracks, &queue->q_cur, index);
|
||||
queue_iter_set(queue, &queue->q_cur, index);
|
||||
return __queue_selected(queue, index);
|
||||
}
|
||||
|
||||
|
@ -243,15 +242,15 @@ struct track *queue_next(struct queue *queue)
|
|||
return NULL;
|
||||
|
||||
if (size == 1)
|
||||
_q_iter_set(&queue->q_tracks, &queue->q_cur, 0);
|
||||
queue_iter_set(queue, &queue->q_cur, 0);
|
||||
else if (queue_has_flag(queue, Q_RANDOM)) {
|
||||
pos = g_random_int_range(1, (size < 15) ? size : size / 3);
|
||||
pos += queue->q_cur.it_pos;
|
||||
_q_iter_set(&queue->q_tracks, &queue->q_cur, pos % size);
|
||||
queue_iter_set(queue, &queue->q_cur, pos % size);
|
||||
} else {
|
||||
_q_iter_next(&queue->q_cur);
|
||||
queue_iter_next(&queue->q_cur);
|
||||
if (!queue->q_cur.it_iter)
|
||||
_q_iter_set(&queue->q_tracks, &queue->q_cur, 0);
|
||||
queue_iter_set(queue, &queue->q_cur, 0);
|
||||
}
|
||||
|
||||
return __queue_selected(queue, queue->q_cur.it_pos);
|
||||
|
|
|
@ -63,11 +63,11 @@ struct queue {
|
|||
unsigned int q_flags; /* The queue's set of flags. */
|
||||
unsigned int q_length; /* The queue's total runtime (in seconds). */
|
||||
struct _queue q_tracks; /* The queue's list of tracks. */
|
||||
struct _q_iter q_cur; /* The queue's last-played position. */
|
||||
GSList *q_sort; /* The queue's sort order. */
|
||||
void *q_private; /* The queue's private data. */
|
||||
|
||||
const struct queue_ops *q_ops; /* The queue's operations vector. */
|
||||
struct queue_iter q_cur; /* The queue's last-played position. */
|
||||
const struct queue_ops *q_ops; /* The queue's operations vector. */
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ static void test_history()
|
|||
test_equal(queue_size(q), track_db->db_size);
|
||||
|
||||
/* Cycle through the history queue. */
|
||||
_q_iter_set(&q->q_tracks, &q->q_cur, 0);
|
||||
queue_iter_set(q, &q->q_cur, 0);
|
||||
for (i = 2; i <= track_db->db_size; i++) {
|
||||
test_loop_equal((void *)history_prev(),
|
||||
(void *)track_get(track_db->db_size - i), i);
|
||||
|
|
Loading…
Reference in New Issue