📄 main.c
字号:
printf_P(("Artist : %s \r\n"),LrcStructHead.artist);
#endif
}
/**********************************************************************************************************/
else if(strcomp_noncase("OFFSET:",&buffer[j+1])) /* string compare to check if this is a offset tag */
{
j+=8; /* count += 8 */
LrcStructHead.offset = 0; /* default value, in case the tag like this [offset:] */
LrcStructHead.sign = 1;
#if DEBUG
printf_P((" found offset tag: "));
#else
//printf_P(("\r\n"));
#endif
while(1) /* proceed the offset */
{
temp = buffer[j++];
#if DEBUG
uart0_putc(temp);
#endif
if(temp == ']')break; /* tag end */
if(temp == '-') /* sign */
{
LrcStructHead.sign = 0;
continue;
}
LrcStructHead.offset *= 10; /* calculate the value */
LrcStructHead.offset += (temp-0x30);
}
#if DEBUG
printf_P(("the value in the structure is : %d\r\n"),LrcStructHead.offset);
#endif
}
/**********************************************************************************************************/
else if(strcomp_noncase("BY:",&buffer[j+1])) /* string compare to check if this is a By tag */
{ /* but we do not need this tag */
j+=4;
#if DEBUG
printf_P((" found by tag: "));
#endif
while(1)
{
temp = buffer[j++];
#if DEBUG
uart0_putc(temp);
#endif
if(temp == 0x0d || temp == 0x0a || temp == ']' ||i>30)break;
}
#if DEBUG
printf_P("\r\n");
#endif
}
/**********************************************************************************************************/
else if(strcomp_noncase("AL:",&buffer[j+1])) /* string compare to check if this is a album tag */
{
j+=4;
#if DEBUG
printf_P((" found al tag: "));
#else
uart0_prints(("Album : "));
#endif
while(1)
{
temp = buffer[j++];
if(temp == 0x0d || temp == 0x0a || temp == ']' ||i>30)break;
uart0_putc(temp);
}
printf_P("\r\n");
}
/**********************************************************************************************************/
else /* otherwise this must the time tag or other not recognize tag */
{
j+=1;
/****************************************************************/
if(sector == totalsect && j == leftbytes + 1) goto end; /* if the file is end */
if(j == 512) /* wether the sector is end, need to read the next sector */
{
if(part == (SectorsPerClust - 1)) /* if need to read next cluster */
{
//p=FAT_NextCluster_NEW(p);//读下一簇数据 //read next cluster
p=FAT_NextCluster(p);
if(p == 0x0fffffff || p == 0x0ffffff8 || (FAT32_Enable == 0 && p == 0xffff))//如果无后续簇则结束, //no more cluster
{
#if DEBUG
printf_P(("No next cluster or read next cluster error\r\n"));
#endif
goto end;
}
part = 0; /* clear the part count */
if(FAT_LoadPartCluster(p,part,buffer))
{
#if DEBUG
printf_P(("ERROR: Faild to load a sector\r\n"));
#endif
free(buffer);
return 1;
}
}
else /* else just read the next part of the cluster */
{
part ++; /* part ++ */
if(FAT_LoadPartCluster(p,part,buffer))
{
#if DEBUG
printf_P(("ERROR: Faild to load a sector\r\n"));
#endif
free(buffer);
return 1;
}
}
sector ++; /* sector count +=1 */
j = 0; /* loop value clear to 0*/
}
/********************************************************/
min = 0; /* clear the temp variable for time to 0 */
sec = 0;
ms = 0;
i = 0; /* for tag use, to ditermin tag like [XX:XX] & [XX:XX:XX] */
while(1)
{
temp = buffer[j++];
#if DEBUG
uart0_putc(temp);
#endif
/**********************************************************/
if(sector == totalsect && j == leftbytes + 1) goto end; /* file end */
if(j == 512) /* need to read next sector */
{
if(part == (SectorsPerClust - 1)) /* if need to read next cluster */
{
//p=FAT_NextCluster_NEW(p);//读下一簇数据 //read next cluster
p=FAT_NextCluster(p);
if(p == 0x0fffffff || p == 0x0ffffff8 || (FAT32_Enable == 0 && p == 0xffff))//如果无后续簇则结束, //no more cluster
{
#if DEBUG
printf_P(("No next cluster or read next cluster error\r\n"));
#endif
goto end;
}
part = 0; /* clear the part count */
if(FAT_LoadPartCluster(p,part,buffer))
{
#if DEBUG
printf_P(("ERROR: Faild to load a sector\r\n"));
#endif
free(buffer);
return 1;
}
}
else /* else just read the next part of the cluster */
{
part ++; /* part ++ */
if(FAT_LoadPartCluster(p,part,buffer))
{
#if DEBUG
printf_P(("ERROR: Faild to load a sector\r\n"));
#endif
free(buffer);
return 1;
}
}
sector ++; /* sector count +=1 */
j = 0; /* loop value clear to 0*/
}
/***********************************************/
if((temp < '0' || temp > '9') && temp != ':' && temp != '.')break; /* end or not a leagal ch*/
if(temp == ':'){i=1;continue;}
if(temp == '.'){i=2;mscnt = 0;continue;}
/* calculate the value */
if(i==0)min = min*10 + (temp-0x30);
else if(i==1)sec = sec*10 + (temp-0x30);
else
{
if(mscnt == 0)
ms += (temp-0x30)*100;
else if(mscnt == 1)
ms += (temp - 0x30)*10;
else ms += temp-0x30;
mscnt ++;
}
}
if(temp == ']') /* if tag end */
{
#if DEBUG
printf_P((" found time tag: "));
printf_P(("min = %d; "),min);
printf_P(("sec = %d; "),sec);
printf_P(("ms = %d; \r\n"),ms);
#endif
if(LrcStruct_p == 0)
{
printf_P(("WARNING: Sorry! no more space for the rest tag, som lryic can't display!\r\n"));
goto end;
}
/* set time value without offset */
LrcStruct_p->time = (uint32)(min*60 + sec)*1000 + ms;
#if DEBUG
printf_P(("\r\noffset : %d "),LrcStructHead.offset);
printf_P((" total = %ld; "),LrcStruct_p->time);
#endif
/* recalculate the time, use offset */
if(LrcStructHead.sign)
{
if(LrcStruct_p->time<LrcStructHead.offset)LrcStruct_p->time = 0;
else LrcStruct_p->time -= LrcStructHead.offset;
}
else LrcStruct_p->time += LrcStructHead.offset;
#if DEBUG
printf_P(("after calculate total = %ld; \r\n"),LrcStruct_p->time);
#endif
/* node operation, pointer to next node, and set address */
LrcStruct_p->eeaddr = lrcaddr;
temp = buffer[j];
LrcStruct_p = LrcStruct_p->next;
if(temp == '['); /* if two tag share one lyric, just jump and next loop it will process it */
else /* this is a sigle time tag */
{
while(1)
{
temp = buffer[j++];
#if DEBUG
uart0_putc(temp);
#endif
/*************************************************************/
if(sector == totalsect && j == leftbytes + 1) goto end; /* file end */
if(j == 512) /* need to read next sector */
{
if(part == (SectorsPerClust - 1)) /* if need to read next cluster */
{
//p=FAT_NextCluster_NEW(p);//读下一簇数据 //read next cluster
p=FAT_NextCluster(p);
if(p == 0x0fffffff || p == 0x0ffffff8 || (FAT32_Enable == 0 && p == 0xffff))//如果无后续簇则结束, //no more cluster
{
#if DEBUG
printf_P(("No next cluster or read next cluster error\r\n"));
#endif
goto end;
}
part = 0; /* clear the part count */
if(FAT_LoadPartCluster(p,part,buffer))
{
#if DEBUG
printf_P(("ERROR: Faild to load a sector\r\n"));
#endif
free(buffer);
return 1;
}
}
else /* else just read the next part of the cluster */
{
part ++; /* part ++ */
if(FAT_LoadPartCluster(p,part,buffer))
{
#if DEBUG
printf_P(("ERROR: Faild to load a sector\r\n"));
#endif
free(buffer);
return 1;
}
}
sector ++; /* sector count +=1 */
j = 0; /* loop value clear to 0*/
}
/****************************************************************/
if(temp == 0x0d || temp == 0x0a) /* one lyric end, when meet next line*/
{
//if(lrcaddr<MAXLRCDATSIZE) /* if lrcdatbuf is not full */
//{
lrcdatbuf[lrcaddr++] ='\0';
//}
//else /* otherwise use the eeprom */
// eeprom_write_byte(lrcaddr++ - MAXLRCDATSIZE,'\0');
break;
}
else /* else normal data */
{
//else
//{
//if(lrcaddr<MAXLRCDATSIZE) /* use ram */
//{
lrcdatbuf[lrcaddr++] = temp;
//}
//else /* use epprom */
// eeprom_write_byte(lrcaddr++ - MAXLRCDATSIZE,temp);
//}
}
if(lrcaddr == MAXLRCDATSIZE) /* if ram buffer run out, show some messages */
{
//printf_P(("\r\n\r\nInternal RAM is not enough, some data will be stored at EEPROM!"));
//printf_P(("\r\nThis may take little longer time. U know 8.4ms/Byte, pls wait!......"));
printf_P(("\r\n\r\nWow! The lyric is so long, Buffer is run out, sorry!\r\n"));
goto end;
}
}
}
}
}
}
else j++; /**/
}
sector ++; /**/
}
p=FAT_NextCluster(p);
//p=FAT_NextCluster_NEW(p);//读下一簇数据 //read next cluster
if(p == 0x0fffffff || p == 0x0ffffff8 || (FAT32_Enable == 0 && p == 0xffff))//如果无后续簇则结束, //no more cluster
{
#if DEBUG
printf_P(("No next cluster or read next cluster error\r\n"));
#endif
break;
}
}
end:
/* in case that some lyc file don not have empty line at the last */
// if(lrcaddr<MAXLRCDATSIZE)
// {
lrcdatbuf[lrcaddr++] = '\0';
// }
// else
// eeprom_write_byte(lrcaddr++ - MAXLRCDATSIZE,'\0');
/* end the node */
LrcStruct_p = LrcStruct_p - 1;
LrcStruct_p->next = 0;
/* free the buffer */
free(buffer);
/* below is a debug message */
/************************************************************/
#if DEBUG
printf_P(("\r\nLyric data stored completed!"));
printf_P(("\r\nThe data stored in RAM & EEPROM:\r\n"));
for(j=0;j<lrcaddr;j++)
{
//if(j<MAXLRCDATSIZE)uart0_putc(lrcdatbuf[j]);
uart0_putc(lrcdatbuf[j]);
//else uart0_putc(eeprom_read_byte(j - MAXLRCDATSIZE));
}
printf_P(("\r\nNo sorted data is : \r\n"));
LrcStruct_p = LrcStructHead.header;
while(1)
{
lrcaddr = LrcStruct_p->eeaddr;
while(1)
{
temp = lrcdatbuf[lrcaddr++];
//if(lrcaddr<MAXLRCDATSIZE)temp = lrcdatbuf[lrcaddr++];
//else temp = eeprom_read_byte(lrcaddr++ - MAXLRCDATSIZE);
if(temp == 0)break;
uart0_putc(temp);
}
printf_P(("\r\n"));
if(LrcStruct_p->next == 0)break;
LrcStruct_p = LrcStruct_p->next;
}
#endif
#if DEBUG
printf_P(("\r\nSort begining ......"));
#endif
#if DEBUG
temp = 0;
LrcStruct_p = LrcStructHead.header;
while(1)
{
temp++;
if(LrcStruct_p->next == 0)break;
LrcStruct_p = LrcStruct_p->next;
}
printf_P(("\r\ntotal %s time tags"),temp);
#endif
/***************************************************************/
/* tag sort */
LrcStruct_p_header = LrcStruct_p = LrcStructHead.header;
while(1)
{
LrcStruct_p_header = LrcStruct_p;
LrcStruct_p = LrcStruct_p->next;
if(LrcStruct_p == 0)break;
if(LrcStruct_p_header->time > LrcStruct_p->time)
{
LrcStruct_p_temp = LrcStructHead.header;
j = 0;
while(1)
{
j++;
if(LrcStruct_p_temp->time < LrcStruct_p->time) /* do not need to insert node */
{
LrcStruct_p_up = LrcStruct_p_temp;
LrcStruct_p_temp = LrcStruct_p_temp->next;
LrcStruct_p_down = LrcStruct_p_temp->next;
}
else /* need insert */
{
#if DEBUG
printf_P(("\r\nLrcStruct_p_up->time = %ld"),LrcStruct_p_up->time);
printf_P(("\r\nLrcStruct_p_temp->time = %ld"),LrcStruct_p_temp->time);
printf_P(("\r\nLrcStruct_p_down->time = %ld"),LrcStruct_p_down->time);
printf_P(("\r\nLrcStruct_p->time = %ld \r\n"),LrcStruct_p->time);
#endif
if(j == 1) /* if the first need to replace */
{
LrcStructHead.header = LrcStruct_p;
LrcStruct_p_header->next = LrcStruct_p ->next;
LrcStruct_p ->next = LrcStruct_p_header;
LrcStruct_p = LrcStruct_p_header;
}
else /* other normal condition */
{
LrcStruct_p_header->next = LrcStruct_p->next;
LrcStruct_p_up->next = LrcStruct_p;
LrcStruct_p->next = LrcStruct_p_temp;
LrcStruct_p = LrcStruct_p_header;
#if DEBUG
printf_P(("\r\nLrcStruct_p->time = %ld \r\n\r\n"),LrcStruct_p->time);
#endif
}
break;
}
}
}
}
printf_P(("\r\n\r\nAnalyze complete!\r\n\r\nCode written by Bozai - 章其波"));
printf_P(("\r\n*****************************************************\r\n"));
/* debug message, show sorted data */
#if DEBUG
printf_P(("\r\nSort completed!"));
printf_P(("\r\nData after sort is : \r\n"));
printf_P(("\r\n\r\nLrc Data:\r\n\r\n"));
LrcStruct_p = LrcStructHead.header;
while(1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -