commit 6b47a39f8abd2139a76aeeeceff8886ffab8aa30 from: Omar Polo date: Mon Feb 21 21:11:23 2022 UTC add the `monitor' command commit - 87f575c3c6293c5cdff2b424a9f182f1857248f3 commit + 6b47a39f8abd2139a76aeeeceff8886ffab8aa30 blob - 63f406b97e28dd1da3fce97f090e1dfa368736d7 blob + 73ff36048ca50150e73d4ba0bdb5e79672ba90f4 --- amused.1 +++ amused.1 @@ -68,6 +68,12 @@ Load a playlist from which has one song per line. If not specified, reads from .Em stdin . +.It Cm monitor +Stop indefinitely and print the events as happen. +Events are print one per line and are triggered either by other +instances of +.Nm +issuing commands or the player itself anvancing the playing queue. .It Cm next Play the next song. .It Cm pause blob - afaf2d8374fa674a3f9052182ad18d97c9ba1c41 blob + a5e417e252642512a12362c2b31c0b987a39e376 --- amused.h +++ amused.h @@ -79,6 +79,7 @@ enum actions { LOAD, JUMP, REPEAT, + MONITOR, }; struct ctl_command; blob - c146c3485fdaf4fac39eb47bb4a9373ae8fb709b blob + f0b1cc15bef6fef39856b42ef2eb53878656d678 --- ctl.c +++ ctl.c @@ -61,6 +61,7 @@ struct ctl_command ctl_commands[] = { { "load", LOAD, ctl_load, "[file]", 1 }, { "jump", JUMP, ctl_jump, "pattern" }, { "repeat", REPEAT, ctl_repeat, "one|all on|off" }, + { "monitor", MONITOR, ctl_noarg, "" }, { NULL }, }; @@ -333,6 +334,70 @@ show_load(struct parse_result *res, struct imsg *imsg, } static int +show_monitor(struct imsg *imsg, int *ret) +{ + int type; + + if (imsg->hdr.type != IMSG_CTL_MONITOR) { + log_warnx("wrong message type received: %d", + imsg->hdr.type); + *ret = 1; + return 1; + } + + if (IMSG_DATA_SIZE(*imsg) != sizeof(type)) { + log_warnx("size mismatch"); + *ret = 1; + return 1; + } + + memcpy(&type, imsg->data, sizeof(type)); + switch (type) { + case IMSG_CTL_PLAY: + puts("play"); + break; + case IMSG_CTL_TOGGLE_PLAY: + puts("toggle"); + break; + case IMSG_CTL_PAUSE: + puts("pause"); + break; + case IMSG_CTL_STOP: + puts("stop"); + break; + case IMSG_CTL_RESTART: + puts("restart"); + break; + case IMSG_CTL_FLUSH: + puts("flush"); + break; + case IMSG_CTL_NEXT: + puts("next"); + break; + case IMSG_CTL_PREV: + puts("prev"); + break; + case IMSG_CTL_JUMP: + puts("jump"); + break; + case IMSG_CTL_REPEAT: + puts("repeat"); + break; + case IMSG_CTL_ADD: + puts("add"); + break; + case IMSG_CTL_COMMIT: + puts("load"); + break; + default: + puts("unknown"); + break; + } + + return 0; +} + +static int ctlaction(struct parse_result *res) { struct imsg imsg; @@ -415,6 +480,11 @@ ctlaction(struct parse_result *res) imsg_compose(ibuf, IMSG_CTL_REPEAT, 0, 0, -1, &res->rep, sizeof(res->rep)); break; + case MONITOR: + done = 0; + imsg_compose(ibuf, IMSG_CTL_MONITOR, 0, 0, -1, + NULL, 0); + break; case NONE: /* action not expected */ fatalx("invalid action %u", res->action); @@ -457,6 +527,9 @@ ctlaction(struct parse_result *res) case LOAD: done = show_load(res, &imsg, &ret); break; + case MONITOR: + done = show_monitor(&imsg, &ret); + break; default: done = 1; break;