Commit d956c3d8 authored by Conrad Parker's avatar Conrad Parker

add -Z, --random option to ogg123. Equivalent to combination of -z and -r,

and reshuffles before each repetition of the playlist.
Merged patch from tim@tim-landscheidt.de, closes ticket:357.

svn path=/trunk/vorbis-tools/; revision=10089
parent 36bc3038
......@@ -49,6 +49,7 @@ struct option long_options[] = {
{"nth", required_argument, 0, 'x'},
{"ntimes", required_argument, 0, 'y'},
{"shuffle", no_argument, 0, 'z'},
{"random", no_argument, 0, 'Z'},
{"list", required_argument, 0, '@'},
{"audio-buffer", required_argument, 0, 0},
{"repeat", no_argument, 0, 'r'},
......@@ -79,7 +80,7 @@ int parse_cmdline_options (int argc, char **argv,
audio_device_t *current;
int ret;
while (-1 != (ret = getopt_long(argc, argv, "b:c::d:f:hl:k:K:o:p:qrvVx:y:z@:",
while (-1 != (ret = getopt_long(argc, argv, "b:c::d:f:hl:k:K:o:p:qrvVx:y:zZ@:",
long_options, &option_index))) {
switch (ret) {
......@@ -225,6 +226,10 @@ int parse_cmdline_options (int argc, char **argv,
ogg123_opts->shuffle = 1;
break;
case 'Z':
ogg123_opts->repeat = ogg123_opts->shuffle = 1;
break;
case '@':
if (playlist_append_from_file(ogg123_opts->playlist, optarg) == 0)
status_error(_("--- Cannot open playlist file %s. Skipped.\n"),
......@@ -343,7 +348,8 @@ void cmdline_usage (void)
_("Playlist options\n"
" -@ file, --list file Read playlist of files and URLs from \"file\"\n"
" -r, --repeat Repeat playlist indefinitely\n"
" -z, --shuffle Shuffle play\n"
" -z, --shuffle Shuffle list of files before playing\n"
" -Z, --random Play files randomly until interrupted\n"
"\n"));
printf (
......
......@@ -9,7 +9,7 @@ ogg123 \- plays Ogg Vorbis files
.SH SYNOPSIS
.B ogg123
[
.B -vqzVh
.B -vqrzZVh
] [
.B -k
.I seconds
......@@ -108,6 +108,8 @@ speeds.
Repeat playlist indefinitely.
.IP "-z, --shuffle"
Play files in pseudo-random order.
.IP "-Z, --random"
Play files in pseudo-random order forever.
.SH DEVICES
......
......@@ -76,6 +76,8 @@ file_option_t file_opts[] = {
&options.default_device, NULL},
{0, "shuffle", N_("shuffle playlist"), opt_type_bool,
&options.shuffle, &int_0},
{0, "repeat", N_("repeat playlist forever"), opt_type_bool,
&options.repeat, &int_0},
{0, NULL, NULL, 0, NULL, NULL}
};
......@@ -367,20 +369,6 @@ int main(int argc, char **argv)
audio_buffer = NULL;
/* Shuffle playlist */
if (options.shuffle) {
int i;
srandom(time(NULL));
for (i = 0; i < items; i++) {
int j = i + random() % (items - i);
char *temp = playlist_array[i];
playlist_array[i] = playlist_array[j];
playlist_array[j] = temp;
}
}
/* Setup signal handlers and callbacks */
ATEXIT (exit_cleanup);
......@@ -389,14 +377,28 @@ int main(int argc, char **argv)
signal (SIGCONT, signal_handler);
signal (SIGTERM, signal_handler);
/* Play the files/streams */
i = 0;
while (i < items && !sig_request.exit) {
play(playlist_array[i]);
i++;
if(i == items && options.repeat)
i = 0;
}
do {
/* Shuffle playlist */
if (options.shuffle) {
int i;
srandom(time(NULL));
for (i = 0; i < items; i++) {
int j = i + random() % (items - i);
char *temp = playlist_array[i];
playlist_array[i] = playlist_array[j];
playlist_array[j] = temp;
}
}
/* Play the files/streams */
i = 0;
while (i < items && !sig_request.exit) {
play(playlist_array[i]);
i++;
}
} while (options.repeat);
playlist_array_destroy(playlist_array, items);
......
......@@ -26,7 +26,7 @@ typedef struct ogg123_options_t {
long int verbosity; /* Verbose output if > 1, quiet if 0 */
int shuffle; /* Should we shuffle playing? */
int repeat; /* Repeat playlist indefinately? */
int repeat; /* Repeat playlist indefinitely? */
ogg_int64_t delay; /* delay (in millisecs) for skip to next song */
int nth; /* Play every nth chunk */
int ntimes; /* Play every chunk n times */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment