这是歌词解析与现实函数
#include"main.h" #define SONG_NUM 12 //显示歌词列数 int row;//歌词行数 char *lrc_row[50]; int fp_lrc;//打开的歌词标识符 SONGNAME *head_name,*dispname; SONGLRC *head_lrc,*displrc; Lrc *sort_lrc(Lrc *head){ Lrc *pa=head,*pb; char *next; int temp; while(pa->next!=NULL){ pb=pa->next; while(pb!=NULL){ if(pa->time>pb->time){ temp=pa->time; pa->time=pb->time; pb->time=temp; next=pa->song_lrc; pa->song_lrc=pb->song_lrc; pb->song_lrc=next; } pb=pb->next; } pa=pa->next; } return head; } void disp_time(){ int temp=atoi(time_temp); char Time[6]=""; TFT_File_Picture(windowHZ, 204, 44, "./picture/time.bmp", 1); Time[0]=temp/60/10+'0'; Time[1]=temp/60%10+'0'; Time[2]=':'; Time[3]=temp%60/10+'0'; Time[4]=temp%60%10+'0'; Time[5]='\0'; printHZ(windowHZ,Time,210,51); } void disp(Lrc *head){ int i=0; FILE *lrcfp; char name_old[100]; Lrc *pa,*pb,*pc; pa=head; int second=0,lrc_flag=0; int k=0,lrc_row_num=0,lrc_row_flag; for(i=0;i<4;i++){ if(pa->next!=NULL) pa=pa->next; } pc=pa; strcpy(name_old,name_temp); while(atoi(position)!=100){ if(!pic_flag){ write(fp_lrc,"get_time_pos\n",strlen("get_time_pos\n")); write(fp_lrc,"get_percent_pos\n",strlen("get_percent_pos\n")); write(fp_lrc,"get_file_name\n",strlen("get_file_name\n")); } lrc_flag=0; if(strcmp(name_old,name_temp)!=0){//如果现在的歌曲名和上次不同,就表示换歌了 TFT_File_Picture(windowLrc, 400, 0, "./picture/lrc.bmp", 1); return ; } lrc_row_num=1; pa=pc; while(pa!=NULL){ int timer; timer=pa->time; lrc_row_num++; if(timer==atoi(time_temp)){ lrc_flag=1; break; } pa=pa->next; } if(lrc_flag){ int i; if(lrc_row_num<=SONG_NUM){ pb=pc; i=0; TFT_File_Picture(windowLrc, 0, 0, "./picture/lrc.bmp", 1); while(pb!=pa){ printHZ(windowLrc,pb->song_lrc,50,450-32*(lrc_row_num-i)); i++; pb=pb->next; } printHZ(windowLrc,pb->song_lrc,50,450-32*(lrc_row_num-i-1)); } else if(lrc_row_num>SONG_NUM) { pb=pc; for(i=0;i<(lrc_row_num-SONG_NUM);i++){ pb=pb->next; } i=0; TFT_File_Picture(windowLrc, 0, 0, "./picture/lrc.bmp", 1); while(pb!=pa){ printHZ(windowLrc,pb->song_lrc,50,450-32*(SONG_NUM-i)); i++; pb=pb->next; } printHZ(windowLrc,pa->song_lrc,50,450-32); } disp_time(); usleep(100*100); } } Lrc *Get_Lrc(WIN_HANDLE windowLrc,FILE *lrcfp){ int i=0; Lrc *head,*pa,*pb; FILE *p; int len=0; char *ptr; fseek(lrcfp,0,2); len=ftell(lrcfp); p=(FILE *)malloc(len); rewind(lrcfp); fread(p,1,len,lrcfp); printf("%s\n",lrcfp); lrc_row[i++]=(char *)strtok(p,"\n"); while((ptr=strtok(NULL,"\n"))!=NULL){ lrc_row[i++]=ptr; } row=i; int flag=1; for(i=0;i<row;i++){ if(i==0){ head=(Lrc *)malloc(sizeof(Lrc)); ptr=strtok(lrc_row[i],"]"); head->song_lrc=ptr; while(head->song_lrc=strtok(NULL,"]")!=NULL); pa=head; } else{ pb=malloc(sizeof(Lrc)); pa->next=pb; char *p;//存储歌词的首地址 p=strrchr(lrc_row[i],']')+1; ptr=strtok(lrc_row[i],"]"); if(flag++<4)pa->song_lrc=ptr; else{ pb->time=(*(ptr+1)-'0')*600+(*(ptr+2)-'0')*60+(*(ptr+4)-'0')*10+*(ptr+5)-'0'; pb->song_lrc=p; } while((ptr=strtok(NULL,"]"))!=NULL){ if(*ptr=='['){ pa=pb; pb=malloc(sizeof(Lrc)); pa->next=pb; pb->time=(*(ptr+1)-'0')*600+(*(ptr+2)-'0')*60+(*(ptr+4)-'0')*10+*(ptr+5)-'0'; pb->song_lrc=p; } } pa=pb; } } pa->next=NULL; return head; /**/ } void open_lrc(char *name){ FILE *lrcfp; Lrc *pa; if((lrcfp=fopen(name,"rb"))==NULL){ printHZ(windowLrc,"不能找到歌词",150,200); return ; } pa=Get_Lrc(windowLrc,lrcfp); pa=sort_lrc(pa); disp(pa); displrc=displrc->next; } void *disp_lrc(void *p){ char buf[100]=".lrc/"; char buf1[255]; char buf2[255]; head_name=readsongname();//读出歌曲名字和歌词名字 head_lrc=readlrc(); displrc=head_lrc; dispname=head_name; fp_lrc=open("./fifo_cmd",O_WRONLY); disp_song_name(head_name);//初始化歌曲名字显示 while(1){ int fp=open("./fifo_cmd",O_WRONLY); write(fp,"get_file_name\n",strlen("get_file_name\n")); bzero(buf,sizeof(buf)); bzero(buf1,sizeof(buf1)); bzero(buf2,sizeof(buf2)); strcpy(buf,"./lrc/"); sprintf(buf1,"%s\n",name_temp); strcpy(buf2,strtok(buf1,"'")); strtok(buf2,"."); strcat(buf2,".lrc");//转换成歌曲名字 strcat(buf,buf2); open_lrc(buf); } free(head_name);//释放内存 free(head_lrc); }