X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/460b9539a7c15580e41a71bbc0f47ae776238915..28bacdc0e8ab3e4d8b7f628f59d65e4fa38b9622:/server/play.c diff --git a/server/play.c b/server/play.c index e70e116..e8df3e8 100644 --- a/server/play.c +++ b/server/play.c @@ -458,24 +458,31 @@ void abandon(ev_source attribute((unused)) *ev, int add_random_track(void) { struct queue_entry *q; const char *p; + long qlen = 0; + int rc = 0; /* If random play is not enabled then do nothing. */ if(shutting_down || !random_is_enabled()) return 0; - /* If there is already a random track, do nothing. */ + /* Count how big the queue is */ for(q = qhead.next; q != &qhead; q = q->next) - if(q->state == playing_random) - return 0; - /* Try to pick a random track */ - if(!(p = trackdb_random(16))) - return -1; - /* Add it to the end of the queue. */ - q = queue_add(p, 0, WHERE_END); - q->state = playing_random; + ++qlen; + /* Add random tracks until the queue is at the right size */ + while(qlen < config->queue_pad) { + /* Try to pick a random track */ + if(!(p = trackdb_random(16))) { + rc = -1; + break; + } + /* Add it to the end of the queue. */ + q = queue_add(p, 0, WHERE_END); + q->state = playing_random; + D(("picked %p (%s) at random", (void *)q, q->track)); + ++qlen; + } /* Commit the queue */ queue_write(); - D(("picked %p (%s) at random", (void *)q, q->track)); - return 0; + return rc; } /* try to play a track */ @@ -722,4 +729,3 @@ comment-column:40 fill-column:79 End: */ -/* arch-tag:17f4e83cce4cbaa60a122475379e63f1 */