From: rjk@greenend.org.uk <> Date: Tue, 10 Jul 2007 23:08:49 +0000 (+0100) Subject: New queue_pad option defines how big to keep the queue (by adding X-Git-Tag: debian-1_5_99dev8~275 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/459d4402420f2156690262a3bb24e85fa87f4220 New queue_pad option defines how big to keep the queue (by adding random tracks). User-chosen tracks are added before the final block of random tracks. Also updated CHANGES a bit. --- diff --git a/doc/disorder_config.5.in b/doc/disorder_config.5.in index 8a03b49..3ddeb47 100644 --- a/doc/disorder_config.5.in +++ b/doc/disorder_config.5.in @@ -296,6 +296,10 @@ If multiple player commands match a track then the first match is used. The interval at which the preferences log file will be synchronised. Defaults to 3600, i.e. one hour. .TP +.B queue_pad \fICOUNT\fR +The target size of the queue. If random play is enabled then randomly picked +tracks will be added until the queue is at least this big. +.TP .B sample_format \fIBITS\fB/\fIRATE\fB/\fICHANNELS Describes the sample format expected by the \fBspeaker_command\fR (below). The components of the format specification are as follows: diff --git a/lib/configuration.c b/lib/configuration.c index 0282630..845c32a 100644 --- a/lib/configuration.c +++ b/lib/configuration.c @@ -749,6 +749,7 @@ static const struct conf conf[] = { { C(player), &type_stringlist_accum, validate_player }, { C(plugins), &type_string_accum, validate_isdir }, { C(prefsync), &type_integer, validate_positive }, + { C(queue_pad), &type_integer, validate_positive }, { C(refresh), &type_integer, validate_positive }, { C2(restrict, restrictions), &type_restrict, validate_any }, { C(sample_format), &type_sample_format, validate_sample_format }, @@ -873,6 +874,7 @@ static struct config *config_default(void) { c->sample_format.rate = 44100; c->sample_format.channels = 2; c->sample_format.byte_format = AO_FMT_NATIVE; + c->queue_pad = 10; return c; } diff --git a/lib/configuration.h b/lib/configuration.h index dbdb65b..c304921 100644 --- a/lib/configuration.h +++ b/lib/configuration.h @@ -112,6 +112,8 @@ struct config { const char *url; /* canonical URL */ long refresh; /* maximum refresh period */ unsigned restrictions; /* restrictions */ + long queue_pad; /* how far to pad queue with + * random tracks */ #define RESTRICT_SCRATCH 1 #define RESTRICT_REMOVE 2 #define RESTRICT_MOVE 4 diff --git a/lib/queue.c b/lib/queue.c index 1e5c1d4..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 */ diff --git a/server/play.c b/server/play.c index 3b18891..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 */