random tracks). User-chosen tracks are added before the final block
of random tracks.
Also updated CHANGES a bit.
The interval at which the preferences log file will be synchronised. Defaults
to 3600, i.e. one hour.
.TP
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:
.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:
{ C(player), &type_stringlist_accum, validate_player },
{ C(plugins), &type_string_accum, validate_isdir },
{ C(prefsync), &type_integer, validate_positive },
{ 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 },
{ C(refresh), &type_integer, validate_positive },
{ C2(restrict, restrictions), &type_restrict, validate_any },
{ C(sample_format), &type_sample_format, validate_sample_format },
c->sample_format.rate = 44100;
c->sample_format.channels = 2;
c->sample_format.byte_format = AO_FMT_NATIVE;
c->sample_format.rate = 44100;
c->sample_format.channels = 2;
c->sample_format.byte_format = AO_FMT_NATIVE;
const char *url; /* canonical URL */
long refresh; /* maximum refresh period */
unsigned restrictions; /* restrictions */
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
#define RESTRICT_SCRATCH 1
#define RESTRICT_REMOVE 2
#define RESTRICT_MOVE 4
struct queue_entry *queue_add(const char *track, const char *submitter,
int where) {
struct queue_entry *queue_add(const char *track, const char *submitter,
int where) {
+ struct queue_entry *q, *beforeme;
q = xmalloc(sizeof *q);
q->track = xstrdup(track);
q = xmalloc(sizeof *q);
q->track = xstrdup(track);
l_add(qhead.prev, q);
break;
case WHERE_BEFORE_RANDOM:
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 */
break;
}
/* submitter will be a null pointer for a scratch */
int add_random_track(void) {
struct queue_entry *q;
const char *p;
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 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)
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();
/* Commit the queue */
queue_write();
- D(("picked %p (%s) at random", (void *)q, q->track));
- return 0;
}
/* try to play a track */
}
/* try to play a track */