Commit Diff
Commit:
af27e631bb7de2e74c2bebd8caf8d5707fb9f223
Date:
Thu Feb 17 08:53:22 2022
UTC
Message:
add next and prev command
--- amused.c
+++ amused.c
@@ -411,6 +411,23 @@ main_restart_track(void)
}
void
+main_playlist_previous(void)
+{
+ const char *song;
+
+ for (;;) {
+ song = playlist_previous();
+ if (song == NULL)
+ return;
+
+ if (main_play_song(song))
+ break;
+
+ playlist_dropcurrent();
+ }
+}
+
+void
main_restart_track(void)
{
const char *song;
--- amused.h
+++ amused.h
@@ -43,6 +43,8 @@ enum imsg_type {
IMSG_CTL_FLUSH,
IMSG_CTL_SHOW,
IMSG_CTL_STATUS,
+ IMSG_CTL_NEXT,
+ IMSG_CTL_PREV,
IMSG_CTL_ERR,
};
@@ -65,6 +67,8 @@ enum actions {
FLUSH,
SHOW,
STATUS,
+ PREV,
+ NEXT,
};
struct ctl_command;
@@ -95,6 +99,7 @@ void main_restart_track(void);
pid_t, int, const void *, uint16_t);
int main_send_player(uint16_t, int, const void *, uint16_t);
void main_playlist_advance(void);
+void main_playlist_previous(void);
void main_restart_track(void);
void main_enqueue(struct imsgev *, struct imsg *);
void main_send_playlist(struct imsgev *);
--- control.c
+++ control.c
@@ -307,6 +307,14 @@ control_dispatch_imsg(int fd, short event, void *bula)
break;
case IMSG_CTL_STATUS:
main_send_status(&c->iev);
+ break;
+ case IMSG_CTL_NEXT:
+ main_send_player(IMSG_STOP, -1, NULL, 0);
+ main_playlist_advance();
+ break;
+ case IMSG_CTL_PREV:
+ main_send_player(IMSG_STOP, -1, NULL, 0);
+ main_playlist_previous();
break;
default:
log_debug("%s: error handling imsg %d", __func__,
--- ctl.c
+++ ctl.c
@@ -52,6 +52,8 @@ struct ctl_command ctl_commands[] = {
{ "flush", FLUSH, ctl_noarg, "" },
{ "show", SHOW, ctl_noarg, "" },
{ "status", STATUS, ctl_noarg, "" },
+ { "next", NEXT, ctl_noarg, "" },
+ { "prev", PREV, ctl_noarg, "" },
{ NULL },
};
@@ -276,7 +278,13 @@ ctlaction(struct parse_result *res)
case STATUS:
done = 0;
imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0);
+ break;
+ case NEXT:
+ imsg_compose(ibuf, IMSG_CTL_NEXT, 0, 0, -1, NULL, 0);
break;
+ case PREV:
+ imsg_compose(ibuf, IMSG_CTL_PREV, 0, 0, -1, NULL, 0);
+ break;
case NONE:
/* action not expected */
fatalx("invalid action %u", res->action);
--- playlist.c
+++ playlist.c
@@ -78,6 +78,29 @@ void
return playlist.songs[play_off];
}
+const char *
+playlist_previous(void)
+{
+ if (playlist.len == 0) {
+ play_state = STATE_STOPPED;
+ return NULL;
+ }
+
+ play_off--;
+ if (play_off < 0) {
+ if (repeat_all)
+ play_off = playlist.len - 1;
+ else {
+ play_state = STATE_STOPPED;
+ play_off = -1;
+ return NULL;
+ }
+ }
+
+ play_state = STATE_PLAYING;
+ return playlist.songs[play_off];
+}
+
void
playlist_reset(void)
{
--- playlist.h
+++ playlist.h
@@ -39,6 +39,7 @@ void playlist_reset(void);
void playlist_enqueue(const char *);
const char *playlist_current(void);
const char *playlist_advance(void);
+const char *playlist_previous(void);
void playlist_reset(void);
void playlist_truncate(void);
void playlist_dropcurrent(void);
Omar Polo