X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/460b9539a7c15580e41a71bbc0f47ae776238915..ad58ebcc8a950f4624cfb1a836e18a703c3b6610:/lib/queue.c diff --git a/lib/queue.c b/lib/queue.c index c7d32a4..940fde3 100644 --- a/lib/queue.c +++ b/lib/queue.c @@ -353,7 +353,7 @@ void queue_id(struct queue_entry *q) { struct queue_entry *queue_add(const char *track, const char *submitter, int where) { - struct queue_entry *q; + struct queue_entry *q, *beforeme; q = xmalloc(sizeof *q); q->track = xstrdup(track); @@ -369,11 +369,13 @@ struct queue_entry *queue_add(const char *track, const char *submitter, l_add(qhead.prev, q); break; case WHERE_BEFORE_RANDOM: - if(qhead.prev == &qhead /* Empty queue. */ - || qhead.prev->state != playing_random) /* No random track */ - l_add(qhead.prev, q); - else - l_add(qhead.prev->prev, q); /* Before random track. */ + /* We want to find the point in the queue before the block of random tracks + * at the end. */ + beforeme = &qhead; + while(beforeme->prev != &qhead + && beforeme->prev->state == playing_random) + beforeme = beforeme->prev; + l_add(beforeme->prev, q); break; } /* submitter will be a null pointer for a scratch */ @@ -509,4 +511,3 @@ comment-column:40 fill-column:79 End: */ -/* arch-tag:62474dd3e75e5483b61b6befe2c523cc */