play: New option: --end-of-playlist.
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 1 Aug 2018 12:13:07 +0000 (14:13 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 18 May 2019 11:29:50 +0000 (13:29 +0200)
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
m4/lls/play.suite.m4
play.c

diff --git a/error.h b/error.h
index 8f4f9bb..cd08003 100644 (file)
--- 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"), \
index 57a9377..f2220f1 100644 (file)
@@ -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 647367a..e8dfbde 100644 (file)
--- 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",