Commit Diff
Commit:
3af9396383944c20699d5340bd000f7a5dafb387
From:
Omar Polo <op@omarpolo.com>
Date:
Wed Mar 2 17:54:37 2022 UTC
Message:
keep the current song if load input was generated by show -p `amused show -p' generates a listing in the form of song > current song song ... This adds an heuristic to `amused load' so that the current song can be set if it's prefixed by "> ". It's particularly useful when re-importing the state from a previous run.
commit - 0f5568cbed68c3c871f2ee9b4bbbe63490cc68b5
commit + 3af9396383944c20699d5340bd000f7a5dafb387
blob - a5e417e252642512a12362c2b31c0b987a39e376
blob + 0fd2a5a1bab5c40838c3c37d0b1c2d17b95121b7
--- amused.h
+++ amused.h
@@ -49,7 +49,7 @@ enum imsg_type {
IMSG_CTL_BEGIN,
IMSG_CTL_ADD, /* path to a file */
- IMSG_CTL_COMMIT,
+ IMSG_CTL_COMMIT, /* offset of the track to jump to */
IMSG_CTL_MONITOR,
blob - 05357b0c0efba4aa25477ee8ff32265c2202307a
blob + db7f92c72422e526c6c67aaac8aac5992c4b2692
--- control.c
+++ control.c
@@ -247,7 +247,7 @@ control_dispatch_imsg(int fd, short event, void *bula)
struct ctl_conn *c;
struct imsg imsg;
struct player_repeat rp;
- ssize_t n;
+ ssize_t n, off;
if ((c = control_connbyfd(fd)) == NULL) {
log_warnx("%s: fd %d: not found", __func__, fd);
@@ -388,7 +388,12 @@ control_dispatch_imsg(int fd, short event, void *bula)
main_senderr(&c->iev, "locked");
break;
}
- playlist_swap(&control_state.play);
+ if (IMSG_DATA_SIZE(imsg) != sizeof(off)) {
+ main_senderr(&c->iev, "wrong size");
+ break;
+ }
+ memcpy(&off, imsg.data, sizeof(off));
+ playlist_swap(&control_state.play, off);
memset(&control_state.play, 0,
sizeof(control_state.play));
control_state.tx = -1;
blob - fb5b2c107489b81822f5ec0d319d0de966cbf8ca
blob + d59f7739bf42943ea1e737d7260b70a88477c0ab
--- ctl.c
+++ ctl.c
@@ -269,9 +269,8 @@ show_load(struct parse_result *res, struct imsg *imsg,
const char *file;
char *line = NULL;
char path[PATH_MAX];
- size_t linesize = 0;
- ssize_t linelen;
- int any = 0;
+ size_t linesize = 0, i = 0;
+ ssize_t linelen, curr = -1;
if (imsg->hdr.type == IMSG_CTL_ERR) {
print_error_message("load failed", imsg);
@@ -301,8 +300,10 @@ show_load(struct parse_result *res, struct imsg *imsg,
continue;
line[linelen-1] = '\0';
file = line;
- if (file[0] == '>' && file[1] == ' ')
+ if (file[0] == '>' && file[1] == ' ') {
file += 2;
+ curr = i;
+ }
if (file[0] == ' ' && file[1] == ' ')
file += 2;
@@ -312,7 +313,7 @@ show_load(struct parse_result *res, struct imsg *imsg,
continue;
}
- any++;
+ i++;
imsg_compose(ibuf, IMSG_CTL_ADD, 0, 0, -1,
path, sizeof(path));
}
@@ -322,13 +323,13 @@ show_load(struct parse_result *res, struct imsg *imsg,
fatal("getline");
fclose(f);
- if (!any) {
+ if (i == 0) {
*ret = 1;
return 1;
}
imsg_compose(ibuf, IMSG_CTL_COMMIT, 0, 0, -1,
- NULL, 0);
+ &curr, sizeof(curr));
imsg_flush(ibuf);
return 0;
}
blob - 18d33d2a8c1d5c9f2be9475556fc3ba7578ceba0
blob + b17c51b79025f1f1bce141b64da8b26b5993a123
--- playlist.c
+++ playlist.c
@@ -45,11 +45,14 @@ playlist_swap(struct playlist *p)
}
void
-playlist_swap(struct playlist *p)
+playlist_swap(struct playlist *p, ssize_t off)
{
ssize_t i = -1;
- if (current_song != NULL) {
+ if (off > p->len)
+ off = -1;
+
+ if (current_song != NULL && off < 0) {
/* try to adjust play_off to match the same song */
for (i = 0; i < p->len; ++i) {
if (!strcmp(current_song, p->songs[i]))
@@ -73,6 +76,8 @@ playlist_swap(struct playlist *p)
if (i != -1)
play_off = i;
+ else if (off >= 0)
+ play_off = off;
playlist.len = p->len;
playlist.cap = p->cap;
blob - 996655b0ce47c796db811762bde003c0671313c1
blob + 63b7b13c147f39aef28532cf6b5851e6ff795ce1
--- playlist.h
+++ playlist.h
@@ -37,7 +37,7 @@ void playlist_swap(struct playlist *);
extern ssize_t play_off;
extern const char *current_song;
-void playlist_swap(struct playlist *);
+void playlist_swap(struct playlist *, ssize_t);
void playlist_push(struct playlist *, const char *);
void playlist_enqueue(const char *);
const char *playlist_advance(void);
Omar Polo