~ft/zuke

9f63a97f4e9d7768ac3b0923d50f43d2d62e2874 — Sigrid Haflínudóttir 5 months ago 3379ca5
simplify seeking logic
1 files changed, 20 insertions(+), 47 deletions(-)

M zuke.c
M zuke.c => zuke.c +20 -47
@@ 15,10 15,7 @@ enum
	Cstart = 1,
	Cstop,
	Ctoggle,
	Cforward,
	Cbackward,
	Cforwardfast,
	Cbackwardfast,
	Cseekrel,

	Everror = 1,
	Evready,


@@ 38,6 35,7 @@ struct Player
	Channel *ctl;
	Channel *ev;
	Channel *img;
	vlong seekbytes;
	int pcur;
};



@@ 433,7 431,7 @@ playerthread(void *player_)
	ulong c;
	int p[2], fd, pid, noinit, trycoverload;
	long n, r;
	u64int bytesfrom, bf;
	vlong bytesfrom, bf;
	Meta *cur;

	threadsetname("player");


@@ 496,7 494,7 @@ restart:
	}

	pcurplaying = player->pcur;
	if(c != Cbackward && c != Cbackwardfast)
	if(c != Cseekrel || player->seekbytes >= 0)
		redraw(1);

	while(1){


@@ 522,18 520,12 @@ restart:
			if(c == Ctoggle){
				if(recv(player->ctl, &c) < 0 || c == Cstop)
					goto stop;
			}else if(c == Cforward){
				bytesfrom = bf + Seekbytes;
			}else if(c == Cforwardfast){
				bytesfrom = bf + Seekbytesfast;
			}else if(c == Cbackward){ /* to seek backwards we need to restart playback */
				bytesfrom = bf >= Seekbytes ? bf - Seekbytes : 0;
				n = 0; /* not an error */
				break;
			}else if(c == Cbackwardfast){
				bytesfrom = bf >= Seekbytesfast ? bf - Seekbytesfast : 0;
				n = 0; /* not an error */
				break;
			}else if(c == Cseekrel){
				bytesfrom = MAX(0, bf + player->seekbytes);
				if(player->seekbytes < 0){
					n = 0; /* not an error */
					break;
				}
			}else{ /* Cstop */
				goto stop;
			}


@@ 558,7 550,7 @@ restart:
	if(n < 1){ /* seeking backwards or end of the song */
		close(p[1]);
		p[1] = -1;
		if(c != Cbackward && c != Cbackwardfast){
		if(c != Cseekrel || player->seekbytes >= 0){
next:
			playercurr = nil;
			playercurr = newplayer((player->pcur+1) % plnum, 1);


@@ 596,31 588,12 @@ toggle(Player *player)
}

static void
backward(Player *player)
seekrel(Player *player, vlong off)
{
	if(player != nil)
		sendul(player->ctl, Cbackward);
}

static void
forward(Player *player)
{
	if(player != nil)
		sendul(player->ctl, Cforward);
}

static void
backwardfast(Player *player)
{
	if(player != nil)
		sendul(player->ctl, Cbackwardfast);
}

static void
forwardfast(Player *player)
{
	if(player != nil)
		sendul(player->ctl, Cforwardfast);
	if(player != nil){
		player->seekbytes = off;
		sendul(player->ctl, Cseekrel);
	}
}

static void


@@ 997,16 970,16 @@ ev:
		case 2:
			switch(key){
			case Kleft:
				backward(playercurr);
				seekrel(playercurr, -(vlong)Seekbytes);
				break;
			case Kright:
				forward(playercurr);
				seekrel(playercurr, Seekbytes);
				break;
			case ',':
				backwardfast(playercurr);
				seekrel(playercurr, -(vlong)Seekbytesfast);
				break;
			case '.':
				forwardfast(playercurr);
				seekrel(playercurr, Seekbytesfast);
				break;
			case Kup:
				pcur--;