From be3b6f16706c6a93bd46c6dc48caa8109e7860c6 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 1 Aug 2018 14:13:07 +0200 Subject: [PATCH] play: New option: --end-of-playlist. If the end of the playlist is reached, para_play starts over with the first file of the playlist. This commit provides the --end-of-playlist option to control the behaviour. The new option has three pre-defined values: stop, loop, quit with "loop" being the default. Since lopsub features multi-valued options, the implementation is pretty simple. --- error.h | 1 + m4/lls/play.suite.m4 | 10 ++++++++++ play.c | 11 +++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/error.h b/error.h index 8f4f9bb1..cd080031 100644 --- a/error.h +++ b/error.h @@ -83,6 +83,7 @@ PARA_ERROR(EMPTY, "file is empty"), \ PARA_ERROR(ENCRYPT, "encrypt error"), \ PARA_ERROR(EOF, "end of file"), \ + PARA_ERROR(EOP, "end of playlist"), \ PARA_ERROR(FEC_BAD_IDX, "invalid index vector"), \ PARA_ERROR(FECDEC_EOF, "received eof packet"), \ PARA_ERROR(FECDEC_OVERRUN, "fecdec output buffer overrun"), \ diff --git a/m4/lls/play.suite.m4 b/m4/lls/play.suite.m4 index 57a9377e..f2220f14 100644 --- a/m4/lls/play.suite.m4 +++ b/m4/lls/play.suite.m4 @@ -26,6 +26,16 @@ version-string = GIT_VERSION() [option randomize] short_opt = z summary = randomize playlist at startup + [option end-of-playlist] + summary = what to do after the last file has been played + arg_info = required_arg + arg_type = string + typestr = behaviour + values = { + EOP_LOOP = "loop", + EOP_STOP = "stop", + EOP_QUIT = "quit" + } [option key-map] short_opt = k summary = map a key to a command diff --git a/play.c b/play.c index 647367a3..e8dfbde9 100644 --- a/play.c +++ b/play.c @@ -219,7 +219,6 @@ static long unsigned get_play_time(void) return result; } - static void wipe_receiver_node(void) { PARA_NOTICE_LOG("cleaning up receiver node\n"); @@ -434,6 +433,15 @@ static int next_valid_file(void) int i, j = pt->current_file; unsigned num_inputs = lls_num_inputs(play_lpr); + if (j == num_inputs - 1) { + switch (OPT_UINT32_VAL(END_OF_PLAYLIST)) { + case EOP_LOOP: break; + case EOP_STOP: + pt->playing = false; + return 0; + case EOP_QUIT: return -E_EOP; + } + } for (i = 0; i < num_inputs; i++) { j = (j + 1) % num_inputs; if (!pt->invalid[j]) @@ -1249,7 +1257,6 @@ int main(int argc, char *argv[]) init_shuffle_map(); pt->invalid = para_calloc(sizeof(*pt->invalid) * num_inputs); pt->rq = CRT_FILE_CHANGE; - pt->current_file = num_inputs - 1; pt->playing = true; pt->task = task_register(&(struct task_info){ .name = "play", -- 2.39.2