⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wrd_read.c

📁 MIDI解码程序(用VC编写)
💻 C
📖 第 1 页 / 共 4 页
字号:
		next = p->next;		if(p->waittime <= 0)		{		    WRD_ADDEVENT(wrdstep->at, p->cmd, p->arg);		    p->next = wrdstep->free_de;		    wrdstep->free_de = p;		}		else		{		    p->next = NULL;		    if(qtail == NULL)			q = qtail = p;		    else			qtail = qtail->next = p;		}		p = next;	    }	    wrdstep->de = q;	    inc -= w;	    wrdstep->at += w;	}    } while(inc > 0);    wrdstep->step += inc_save;    if(inc_save >= 0)    {	while(wrdstep->step >= wrdstep->barstep)	{	    wrdstep->step -= wrdstep->barstep;	    wrdstep->bar++;	    wrdstep_update_forward(wrdstep);	}    }    else    {	while(wrdstep->step < 0)	{	    wrdstep->step += wrdstep->barstep;	    wrdstep->bar--;	    wrdstep_update_backward(wrdstep);	}    }}static void wrdstep_wait(struct wrd_step_tracer *wrdstep, int bar, int step){    bar = bar + wrdstep->offset - 1;    step = wrdstep->timebase * step / 48;    if(mimpi_bug_emulation_level >= 2 && wrdstep->bar > bar)    {	/* ignore backward bar */	WRD_BUGEMUINFO(213);    }    else    {	while(wrdstep->bar > bar)	    wrdstep_prevbar(wrdstep);    }    while(wrdstep->bar < bar)	wrdstep_nextbar(wrdstep);    wrdstep_setstep(wrdstep, step);}static void wrdstep_rest(struct wrd_step_tracer *wrdstep, int bar, int step){    while(bar-- > 0)	wrdstep_nextbar(wrdstep);    wrdstep_setstep(wrdstep, wrdstep->timebase * step / 48);}static void wrd_add_lyric(int32 at, char *lyric, int len){    MBlockList pool;    char *str;    init_mblock(&pool);    str = (char *)new_segment(&pool, len + 1);    memcpy(str, lyric, len);    str[len] = '\0';    WRD_ADDSTREVENT(at, WRD_LYRIC, str);    reuse_mblock(&pool);}static int wrd_hexval(char *hex){    int val, neg;    if(!*hex)	return WRD_NOARG;    if(*hex != '-')	neg = 0;    else    {	neg = 1;	hex++;    }    val = 0;    for(;;)    {	if('0' <= *hex && *hex <= '9')	    val = (val << 4) | (*hex - '0');	else if('a' <= *hex && *hex <= 'f')	    val = (val << 4) | (*hex - 'a' + 10);	else if('A' <= *hex && *hex <= 'F')	    val = (val << 4) | (*hex - 'A' + 10);	else	    break;	hex++;    }    return neg ? -val : val;}static int wrd_eint(char *s){    if(*s == '\0')	return WRD_NOARG;    if(*s != '$')	return atoi(s);    return wrd_hexval(s + 1);}static int wrd_atoi(char *val, int default_value){    while(*val && (*val < '0' || '9' < *val))	val++;    return !*val ? default_value : atoi(val);}static struct timidity_file *open_wrd_file(char *fn){    char *wrdfile, *p;    MBlockList pool;    struct timidity_file *tf;    init_mblock(&pool);    wrdfile = (char *)new_segment(&pool, strlen(fn) + 5);    strcpy(wrdfile, fn);    if((p = strrchr(wrdfile, '.')) == NULL)    {	reuse_mblock(&pool);	return NULL;    }    if('A' <= p[1] && p[1] <= 'Z')	strcpy(p + 1, "WRD");    else	strcpy(p + 1, "wrd");    tf = open_file(wrdfile, 0, OF_NORMAL);    reuse_mblock(&pool);    return tf;}static void wrd_readinit(void){    wrd_nexttok(NULL);    version = -1;    lineno = 0;    last_event_time = 0;}/* return 1 if line is modified */static int connect_wrd_line(char *line){    int len;    len = strlen(line);    if(len > 1 && line[len - 2] != ';')    {	line[len - 1] = ';';	line[len] = '\n';	line[len + 1] = '\0';	return 1;    }    return 0;}static void mimpi_bug_emu(int cmd, char *linebuf){    if(mimpi_bug_emulation_level >= 1 && version <= 0)    {	switch(wrd_bugstatus)	{	  case 0:  /* Normal state (0) */	  bugstate_0:	    if(cmd == WRD_WAIT)	    {		if(connect_wrd_line(linebuf))		    WRD_BUGEMUINFO(105);		wrd_bugstatus = 2; /* WRD_WAIT shift */	    }	    else if(mimpi_bug_emulation_level >= 2 &&		    cmd == WRD_REST)	    {		if(connect_wrd_line(linebuf))		    WRD_BUGEMUINFO(206);		wrd_bugstatus = 4; /* REST shift */	    }	    else if(mimpi_bug_emulation_level >= 8 && /* For testing */		    cmd == WRD_WMODE)		wrd_bugstatus = 3; /* WMODE shift */	    break;	  case 2: /* WRD_WAIT shift */	    if(mimpi_bug_emulation_level >= 2)	    {		if(connect_wrd_line(linebuf))		    WRD_BUGEMUINFO(212);	    }	    else if(cmd == WRD_WMODE)	    {		if(connect_wrd_line(linebuf))		    WRD_BUGEMUINFO(107);	    }	    wrd_bugstatus = 0;	    goto bugstate_0;	  case 3: /* Testing */	    if(cmd > 0 && connect_wrd_line(linebuf))		WRD_BUGEMUINFO(808);	    wrd_bugstatus = 0;	    goto bugstate_0;	  case 4: /* WRD_REST shift */	    if(connect_wrd_line(linebuf))		WRD_BUGEMUINFO(209);	    wrd_bugstatus = 0;	    goto bugstate_0;	}    }}static int wrd_nexttok(struct timidity_file *tf){    int c, len;    static int waitflag;    static uint8 linebuf[MAXTOKLEN + 16]; /* Token value */    static int tokp;    if(tf == NULL)    {	waitflag = 0;	tokp = 0;	linebuf[0] = '\0';	wrd_bugstatus = 0;	wrd_wmode_prev_step = 0;	return 1;    }    if(waitflag)    {	waitflag = 0;	wrd_tok = WRD_STEP;	return 1;    }  retry_read:    if(!linebuf[tokp])    {	tokp = 0;	wrd_wmode_prev_step = 0;	lineno++;	if(tf_gets((char *)linebuf, MAXTOKLEN, tf) == NULL)	{	    wrd_tok = WRD_EOF;	    return 0;	}	len = strlen((char *)linebuf); /* 0 < len < MAXTOKLEN */	if(linebuf[len - 1] != '\n') /* linebuf must be terminated '\n' */	{	    linebuf[len] = '\n';	    linebuf[len++] = '\0';	}	else if(len > 1 &&		linebuf[len - 2] == '\r' && linebuf[len - 1] == '\n')	{	    /* CRLF => LF */	    linebuf[len - 2] = '\n';	    linebuf[len - 1] = '\0';	    len--;	}    }  retry_parse:    if(linebuf[tokp] == WRDENDCHAR)    {	wrd_tok = WRD_EOF;	return 0;    }    if(tokp == 0 && linebuf[tokp] != '@' && linebuf[tokp] != '^') /* Lyric */    {	len = 0;	c = 0; /* Shut gcc-Wall up! */	while(len < MAXTOKLEN)	{	    c = linebuf[tokp++];	    if(c == '\n' || c == WRDENDCHAR)		break;	    wrd_tokval[len++] = c;	}	wrd_tokval[len] = '\0';	wrd_tok = WRD_LYRIC;	if(c == WRDENDCHAR)	{	    tokp = 0;	    linebuf[0] = WRDENDCHAR;	}	return 1;    }    /* Command */    if(tokp == 0)    {	int i;	/* tab to space */	for(i = 0; linebuf[i]; i++)	    if(linebuf[i] == '\t')		linebuf[i] = ' ';    }    /* Skip white space */    for(;;)    {	if(linebuf[tokp] == ' ')	    tokp++;#ifdef IS_SJIS_ZENKAKU_SPACE	else if(IS_SJIS_ZENKAKU_SPACE(linebuf + tokp))	    tokp += 2;#endif /* IS_SJIS_ZENKAKU_SPACE */	else	    break;    }    c = linebuf[tokp++];    if(c == '\n')    {	wrd_tok = WRD_STEP;	return 1;    }    if(c == ';')    {	if(linebuf[tokp] == '\n')	{	    tokp = 0;	    linebuf[0] = '\0';	}	goto retry_read;    }    if(c == '@' || c == '^') /* command */    {	int cmd, save_tokp;	wrd_tok = (c == '@' ? WRD_COMMAND : WRD_ECOMMAND);	save_tokp = tokp;	len = 0;#ifdef IS_SJIS_ZENKAKU_SPACE	if(IS_SJIS_ZENKAKU_SPACE(linebuf + tokp)) {	    /* nop */	    mimpi_bug_emu(-1, (char *) linebuf);	    tokp += 2;	    goto retry_parse;	}#endif /* IS_SJIS_ZENKAKU_SPACE */	if(linebuf[tokp] == ' ' ||	   linebuf[tokp] == '\n' ||	   linebuf[tokp] == WRDENDCHAR ||	   linebuf[tokp] == ';')	{	    /* nop */	    mimpi_bug_emu(-1, (char *) linebuf);	    goto retry_parse;	}	while(len < MAXTOKLEN)	{	    c = linebuf[tokp++];	    if(!isalpha(c))		break;	    wrd_tokval[len++] = toupper(c);	}	wrd_tokval[len] = '\0';	cmd = wrd_tokval[0] = cmdlookup(wrd_tokval);	if(c != '(' || cmd == 0)	{	    len = 1;	    if(cmd == 0) {		/* REM */		tokp = save_tokp;		cmd = wrd_tokval[0] = WRD_REM;	    } else {		linebuf[--tokp] = c;	/* Putback advanced char */		/* skip spaces */		while(linebuf[tokp] == ' ')		    tokp++;	    }	    if(cmd == WRD_STARTUP)	    {		while(len < MAXTOKLEN)		{		    c = linebuf[tokp++];		    if((c == ';' && linebuf[tokp] == '\n') ||		       c == '\n' ||		       c == WRDENDCHAR ||		       c == '@' ||		       c == ' ')			break;		    wrd_tokval[len++] = c;		}	    }	    else	    {		while(len < MAXTOKLEN)		{		    c = linebuf[tokp++];		    if((c == ';' && linebuf[tokp] == '\n') ||		       c == '\n' ||		       c == WRDENDCHAR)			break;		    wrd_tokval[len++] = c;		}	    }	    linebuf[--tokp] = c;	/* Putback advanced char */	    wrd_tokval[len] = '\0';	    return 1;	}	if(wrd_tok == WRD_ECOMMAND)	{	    if(cmd == WRD_PAL)		wrd_tokval[0] = WRD_ePAL;	    else if(cmd == WRD_SCROLL)		wrd_tokval[0] = WRD_eSCROLL;	}	len = 1;	while(len < MAXTOKLEN)	{	    c = linebuf[tokp++];	    if(c == ')' || c == '\n' || c == WRDENDCHAR)		break;	    wrd_tokval[len++] = c;	}	wrd_tokval[len] = '\0';	mimpi_bug_emu(wrd_tokval[0], (char *) linebuf);	if(c == WRDENDCHAR)	{	    tokp = 0;	    linebuf[0] = WRDENDCHAR;	}	return 1;    }    /* This is quick hack for informal WRD file */    if(c == ':' && mimpi_bug_emulation_level >= 1)    {	WRD_BUGEMUINFO(111);	goto retry_parse;    }    /* Convert error line to @REM format */    linebuf[--tokp] = c;	/* Putback advanced char */    len = 0;    wrd_tok = WRD_COMMAND;    wrd_tokval[len++] = WRD_REM;    while(len < MAXTOKLEN)    {	c = linebuf[tokp++];	if((c == ';' && linebuf[tokp] == '\n') ||	   c == '\n' ||	   c == WRDENDCHAR)	    break;	wrd_tokval[len++] = c;    }    linebuf[--tokp] = c;	/* Putback advanced char */    wrd_tokval[len] = '\0';    return 1;}static uint8 cmdlookup(uint8 *cmd){    switch(cmd[0])    {      case 'C':	return WRD_COLOR;      case 'E':	if(cmd[1] == 'N')	    return WRD_END;	if(cmd[1] == 'S')	    return WRD_ESC;	return WRD_EXEC;      case 'F':	if(cmd[1] == 'A')	    return WRD_FADE;	if(cmd[4] == 'M')	    return WRD_eFONTM;	if(cmd[4] == 'P')	    return WRD_eFONTP;	return WRD_eFONTR;      case 'G':	if(cmd[1] == 'O')	    return WRD_GON;	if(cmd[1] == 'S')	{	    if(cmd[3] == 'R')		return WRD_GSCREEN;	    return WRD_eGSC;	}	if(cmd[3] == 'R')	    return WRD_GCIRCLE;	if(cmd[3] == 'S')	    return WRD_GCLS;	if(cmd[3] == 'I')	    return WRD_GINIT;	if(cmd[3] == 'N')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -