main.c
#include<stdio.h>
#include<string.h>
#include <unistd.h>
#include<stdlib.h>
#include"code/start_mplayer.h"
#include"code/song_lrc.h"
#include"pos/console.h"
int main(int argc,char *argv[])
{
//读取歌词文件
char *arr = NULL;
LRC *head = NULL;
arr = read_lrc(arr);
set_bg_color(30);//设置字体背景色
//按行切割
char *buf[128]={
arr,NULL};
int i=0;
cusor_hide();//隐藏光标
while(1)//切割
{
buf[i] = strtok(buf[i],"\r\n");
if(buf[i] == NULL)
break;
i++;
}
int n = i;//总行数
clear_screen();//清屏
//逐行分析
head = analyse_row(head,buf,n);
//启动mplayer
mplayer_play("song/简单爱.mp3");
//模拟时钟、滚屏、反显
imitate_clock(head,n,buf);
cusor_set_pos();//恢复光标位置
cusor_show();//显示光标
free(head);
free(arr);
return 0;
}
makefile
exec=main
cc=gcc
obj=main.o code/start_mplayer.o code/read_lrc.o code/lrc_link.o pos/console.o code/analyse_row.o code/imitate_clock.o#你要修改的地方
cflags=-Wall -g
$(exec):$(obj)
$(cc) $^ -o $@ $(cflags)
%.o:%.c
$(cc) -c $< -o $@ $(cflags)
clean:
rm $(exec) *.o code/*.o pos/*.o
code文件
analyse_row.c
#include<stdio.h>
#include<string.h>
#include "../pos/console.h"
#include"song_lrc.h"
LRC* analyse_row(LRC *head,char **buf,int n)
{
int i = 0;
for(i=0;i<n;i++)
{
char c=0;
sscanf(buf[i],"[%c:",&c);
if(c>=48 && c<=57)
{
char *str_lrc = buf[i];
while(*str_lrc=='[')
str_lrc +=10;
//strlrc 指向了歌词的位置
char *str_time = buf[i];
while(*str_time=='[')
{
int m = 0,s = 0;
sscanf(str_time,"[%d:%d.80]",&m,&s);
int time = m*60+s;
LRC temp;
temp.time=time;
strcpy(temp.lrc,str_lrc);
head = insert_link(head,temp);
str_time +=10;
}
}
else
{
cusor_moveto(55,5+i);
char tmp[128]