Commit Diff


commit - 2ac7eafd840cd17885c562fa6485811153cc5d25
commit + bb3f279f10e8ae485815c84453e4362eb984fea8
blob - 2e46ef7af0971f3ce4c31a75aca78e021be03d2b
blob + 6408cbef919f047b2eef8a780ddd0117104dec72
--- amused.c
+++ amused.c
@@ -465,4 +465,20 @@ main_send_playlist(struct imsgev *iev)
 	}
 
 	imsg_compose_event(iev, IMSG_CTL_SHOW, 0, 0, -1, NULL, 0);
+}
+
+void
+main_send_status(struct imsgev *iev)
+{
+	struct player_status s;
+	const char *song;
+
+	memset(&s, 0, sizeof(s));
+
+	song = playlist_current();
+	if (song != NULL)
+		strlcpy(s.path, song, sizeof(s.path));
+	s.status = play_state;
+
+	imsg_compose_event(iev, IMSG_CTL_STATUS, 0, 0, -1, &s, sizeof(s));
 }
blob - 77b043abadef6bf57b4b8765d51fa16c362ce0bd
blob + 89bb9ef272a2ab3af68762223946812bf39b49cf
--- amused.h
+++ amused.h
@@ -42,6 +42,7 @@ enum imsg_type {
 	IMSG_CTL_ADD,
 	IMSG_CTL_FLUSH,
 	IMSG_CTL_SHOW,
+	IMSG_CTL_STATUS,
 
 	IMSG_CTL_ERR,
 };
@@ -63,6 +64,7 @@ enum actions {
 	ADD,
 	FLUSH,
 	SHOW,
+	STATUS,
 };
 
 struct ctl_command;
@@ -81,6 +83,11 @@ struct ctl_command {
 	int			 has_pledge;
 };
 
+struct player_status {
+	char	path[PATH_MAX];
+	int	status;
+};
+
 /* amused.c */
 void		spawn_daemon(void);
 void		imsg_event_add(struct imsgev *iev);
@@ -91,6 +98,7 @@ void		main_playlist_advance(void);
 void		main_restart_track(void);
 void		main_enqueue(struct imsgev *, struct imsg *);
 void		main_send_playlist(struct imsgev *);
+void		main_send_status(struct imsgev *);
 
 /* ctl.c */
 __dead void	usage(void);
blob - f2db65e6305487b24104864843e1effc2f9ae710
blob + e46c1e47a7d9ba7269065026c5e40ec0af8f16a4
--- control.c
+++ control.c
@@ -28,6 +28,7 @@
 #include <errno.h>
 #include <event.h>
 #include <imsg.h>
+#include <limits.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -303,6 +304,9 @@ control_dispatch_imsg(int fd, short event, void *bula)
 			break;
 		case IMSG_CTL_SHOW:
 			main_send_playlist(&c->iev);
+			break;
+		case IMSG_CTL_STATUS:
+			main_send_status(&c->iev);
 			break;
 		default:
 			log_debug("%s: error handling imsg %d", __func__,
blob - bdb846af95dc64cc70eab4e95805b402a7484edb
blob + 7cb5487627250ddcbaeeea8240d2bd87d296bf7f
--- ctl.c
+++ ctl.c
@@ -34,6 +34,7 @@
 
 #include "amused.h"
 #include "log.h"
+#include "playlist.h"
 #include "xmalloc.h"
 
 static struct imsgbuf *ibuf;
@@ -50,6 +51,7 @@ struct ctl_command ctl_commands[] = {
 	{ "add",	ADD,		ctl_add,	"files...", 1 },
 	{ "flush",	FLUSH,		ctl_noarg,	"" },
 	{ "show",	SHOW,		ctl_noarg,	"" },
+	{ "status",	STATUS,		ctl_noarg,	"" },
 	{ NULL },
 };
 
@@ -192,6 +194,47 @@ show_complete(struct imsg *imsg, int *ret)
 
 	printf("%s\n", path);
 	return 0;
+}
+
+static int
+show_status(struct imsg *imsg, int *ret)
+{
+	struct player_status s;
+	size_t datalen;
+
+	if (imsg->hdr.type == IMSG_CTL_ERR) {
+		print_error_message("show failed", imsg);
+		*ret = 1;
+		return 1;
+	}
+
+	if (imsg->hdr.type != IMSG_CTL_STATUS)
+		fatalx("%s: got wrong reply", __func__);
+
+	datalen = IMSG_DATA_SIZE(*imsg);
+	if (datalen != sizeof(s))
+		fatalx("%s: data size mismatch", __func__);
+	memcpy(&s, imsg->data, sizeof(s));
+	if (s.path[sizeof(s.path)-1] != '\0')
+		fatalx("%s: data corrupted?", __func__);
+
+	switch (s.status) {
+	case STATE_STOPPED:
+		printf("stopped ");
+		break;
+	case STATE_PLAYING:
+		printf("playing ");
+		break;
+	case STATE_PAUSED:
+		printf("paused ");
+		break;
+	default:
+		printf("unknown ");
+		break;
+	}
+
+	printf("%s\n", s.path);
+	return 1;
 }
 
 static int
@@ -230,6 +273,10 @@ ctlaction(struct parse_result *res)
 		done = 0;
 		imsg_compose(ibuf, IMSG_CTL_SHOW, 0, 0, -1, NULL, 0);
 		break;
+	case STATUS:
+		done = 0;
+		imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0);
+		break;
 	case NONE:
 		/* action not expected */
 		fatalx("invalid action %u", res->action);
@@ -260,6 +307,9 @@ ctlaction(struct parse_result *res)
 			case SHOW:
 				done = show_complete(&imsg, &ret);
 				break;
+			case STATUS:
+				done = show_status(&imsg, &ret);
+				break;
 			default:
 				done = 1;
 				break;
blob - b26fc8b457ff9c7430d5e28f21610112d8615dcc
blob + 05cc53bf3b42995d18a118aefce89b45c9287827
--- player_flac.c
+++ player_flac.c
@@ -21,6 +21,7 @@
 #include <err.h>
 #include <event.h>
 #include <inttypes.h>
+#include <limits.h>
 #include <sndio.h>
 #include <stdio.h>
 #include <stdlib.h>
blob - 5dda0c58eb3755eae21ae708c60579876220804e
blob + 7ecebc7682bb76323a344d961fcac7443e712e3b
--- player_mad.c
+++ player_mad.c
@@ -23,6 +23,7 @@
 #include <err.h>
 #include <event.h>
 #include <fcntl.h>
+#include <limits.h>
 #include <sndio.h>
 #include <stdio.h>
 #include <stdint.h>
blob - 2726b9419c7466e3933d2076a20fa4bc9af8cce9
blob + 3a9eb89a37b03b6bf072b2d8a76712b437e1c0ae
--- player_oggvorbis.c
+++ player_oggvorbis.c
@@ -23,6 +23,7 @@
 #include <fcntl.h>
 #include <math.h>
 #include <inttypes.h>
+#include <limits.h>
 #include <sndio.h>
 #include <stdio.h>
 #include <stdint.h>
blob - 43812e46cda8499ed6cdd447707100c0396ddc55
blob + df81fe4c8785d0923adf92d4b232a96421f1017f
--- player_opus.c
+++ player_opus.c
@@ -23,6 +23,7 @@
 #include <fcntl.h>
 #include <math.h>
 #include <inttypes.h>
+#include <limits.h>
 #include <sndio.h>
 #include <stdio.h>
 #include <stdint.h>