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

📄 wps-display.c

📁 编译后直接运行的MP3播放器全部C语言源代码 一个包含FAT文件系统、系统引导 Boot、FLASH Driver等内容的
💻 C
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************** *             __________               __   ___. *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  / *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  < *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \ *                     \/            \/     \/    \/            \/ * $Id: wps-display.c,v 1.83 2004/03/02 07:56:58 linusnielsen Exp $ * * Copyright (C) 2002 Bj鰎n Stenberg * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************//* ID3 formatting based on code from the MAD Winamp plugin (in_mad.dll),  * Copyright (C) 2000-2001 Robert Leslie.  * See http://www.mars.org/home/rob/proj/mpeg/ for more information. */#include <stdio.h>#include <string.h>#include <stdlib.h>#include "lcd.h"#include "hwcompat.h"#include "font.h"#include "mpeg.h"#include "id3.h"#include "settings.h"#include "playlist.h"#include "kernel.h"#include "system.h"#include "status.h"#include "wps-display.h"#include "debug.h"#include "mas.h"#include "lang.h"#include "powermgmt.h"#include "sprintf.h"#include "backlight.h"#ifdef HAVE_LCD_BITMAP#include "icons.h"#include "widgets.h"#include "peakmeter.h"#endif#define WPS_CONFIG ROCKBOX_DIR "/default.wps"#ifdef HAVE_LCD_BITMAP#define MAX_LINES 10#define FORMAT_BUFFER_SIZE 800#else#define MAX_LINES 2#define FORMAT_BUFFER_SIZE 400#endif#define MAX_SUBLINES 12#define DEFAULT_SUBLINE_TIME_MULTIPLIER 20 /* (10ths of sec) */#define BASE_SUBLINE_TIME 10 /* base time that multiplier is applied to                                 (1/HZ sec, or 100ths of sec) */#define SUBLINE_RESET -1#ifdef HAVE_LCD_CHARCELLSstatic unsigned char wps_progress_pat[8]={0,0,0,0,0,0,0,0};static bool full_line_progressbar=0;static bool draw_player_progress(struct mp3entry* id3, int ff_rewwind_count);static void draw_player_fullbar(char* buf, int buf_size,                                struct mp3entry* id3, int ff_rewwind_count);static char map_fullbar_char(char ascii_val);#endifstatic char format_buffer[FORMAT_BUFFER_SIZE];static char* format_lines[MAX_LINES][MAX_SUBLINES];static unsigned char line_type[MAX_LINES][MAX_SUBLINES];static unsigned char time_mult[MAX_LINES][MAX_SUBLINES];static long subline_expire_time[MAX_LINES]; static int curr_subline[MAX_LINES];static int ff_rewind_count;bool wps_time_countup = true;static bool wps_loaded = false;static const char* const genres[] = {    "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge",    "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B",    "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska",    "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop",    "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental",    "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", "AlternRock",    "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop",    "Instrumental Rock", "Ethnic", "Gothic", "Darkwave", "Techno-Industrial",    "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy",    "Cult", "Gangsta", "Top 40", "Christian Rap", "Pop/Funk", "Jungle",    "Native American", "Cabaret", "New Wave", "Psychadelic", "Rave",    "Showtunes", "Trailer", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz",    "Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock",    /* winamp extensions */    "Folk", "Folk-Rock", "National Folk", "Swing", "Fast Fusion", "Bebob",    "Latin", "Revival", "Celtic", "Bluegrass", "Avantgarde", "Gothic Rock",    "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock",    "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour", "Speech",    "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass",    "Primus", "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba",    "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle",    "Duet", "Punk Rock", "Drum Solo", "A capella", "Euro-House", "Dance Hall"};char* wps_get_genre(unsigned int genre){    if (genre < sizeof(genres)/sizeof(char*))        return (char*)genres[genre];    return NULL;}/* Set format string to use for WPS, splitting it into lines */static void wps_format(char* fmt){    char* buf = format_buffer;    char* start_of_line = format_buffer;    int line = 0;    int subline;        strncpy(format_buffer, fmt, sizeof(format_buffer));    format_buffer[sizeof(format_buffer) - 1] = 0;        for (line=0; line<MAX_LINES; line++)    {        for (subline=0; subline<MAX_SUBLINES; subline++)        {            format_lines[line][subline] = 0;            time_mult[line][subline] = 0;        }        subline_expire_time[line] = 0;        curr_subline[line] = SUBLINE_RESET;    }    line = 0;    subline = 0;    format_lines[line][subline] = buf;    while ((*buf) && (line < MAX_LINES))    {        switch (*buf)        {            /* skip % sequences so "%;" doesn't start a new subline */            case '%':                 buf++;                break;            case '\r': /* CR */                *buf = 0;                break;            case '\n': /* LF */                *buf = 0;                if (*start_of_line != '#') /* A comment? */                    line++;                                if (line < MAX_LINES)                {                    /* the next line starts on the next byte */                    subline = 0;                    format_lines[line][subline] = buf+1;                    start_of_line = format_lines[line][subline];                }                break;            case ';': /* start a new subline */                *buf = 0;                subline++;                if (subline < MAX_SUBLINES)                {                    format_lines[line][subline] = buf+1;                }                else /* exceeded max sublines, skip rest of line */                {                    while (*(++buf))                     {                        if  ((*buf == '\r') || (*buf == '\n'))                        {                            break;                        }                    }                    buf--;                    subline = 0;                }                break;        }        buf++;    }}void wps_reset(void){    wps_loaded = false;    memset(&format_buffer, 0, sizeof format_buffer);}bool wps_load(char* file, bool display){    int i, s;    char buffer[FORMAT_BUFFER_SIZE];    int fd;    fd = open(file, O_RDONLY);        if (fd >= 0)    {        int numread = read(fd, buffer, sizeof(buffer) - 1);                if (numread > 0)        {            buffer[numread] = 0;            wps_format(buffer);        }                close(fd);        if ( display ) {            bool any_defined_line;            lcd_clear_display();#ifdef HAVE_LCD_BITMAP            lcd_setmargins(0,0);#endif            for (s=0; s<MAX_SUBLINES; s++)            {                any_defined_line = false;                for (i=0; i<MAX_LINES; i++)                {                    if (format_lines[i][s])                     {                        if (*format_lines[i][s] == 0)                            lcd_puts(0,i," ");                        else                            lcd_puts(0,i,format_lines[i][s]);                        any_defined_line = true;                    }                    else                    {                        lcd_puts(0,i," ");                    }                }                if (any_defined_line)                {                    lcd_update();                    sleep(HZ/2);                }            }        }        wps_loaded = true;        return numread > 0;    }        return false;}/* Format time into buf. * * buf      - buffer to format to. * buf_size - size of buffer. * time     - time to format, in milliseconds. */static void format_time(char* buf, int buf_size, int time){    snprintf(buf, buf_size, "%d:%02d", time / 60000, time % 60000 / 1000);}/* Extract a part from a path. * * buf      - buffer extract part to. * buf_size - size of buffer. * path     - path to extract from. * level    - what to extract. 0 is file name, 1 is parent of file, 2 is  *            parent of parent, etc. * * Returns buf if the desired level was found, NULL otherwise. */static char* get_dir(char* buf, int buf_size, char* path, int level){    char* sep;    char* last_sep;    int len;    sep = path + strlen(path);    last_sep = sep;    while (sep > path)    {        if ('/' == *(--sep))        {            if (!level)            {                break;            }                        level--;            last_sep = sep - 1;        }    }    if (level || (last_sep <= sep))    {        return NULL;    }    len = MIN(last_sep - sep, buf_size - 1);    strncpy(buf, sep + 1, len);    buf[len] = 0;    return buf;}/* Get the tag specified by the two characters at fmt. * * id3      - ID3 data to get tag values from. * tag      - string (of two characters) specifying the tag to get. * buf      - buffer to certain tags, such as track number, play time or  *           directory name. * buf_size - size of buffer. * flags    - returns the type of the line. See constants i wps-display.h * * Returns the tag. NULL indicates the tag wasn't available. */static char* get_tag(struct mp3entry* id3,                      char* tag,                      char* buf,                      int buf_size,                     unsigned char* tag_len,                     unsigned char* subline_time_mult,                     unsigned char* flags){    if ((0 == tag[0]) || (0 == tag[1]))    {        *tag_len = 0;        return NULL;    }        *tag_len = 2;    switch (tag[0])    {        case 'i':  /* ID3 Information */            *flags |= WPS_REFRESH_STATIC;            switch (tag[1])            {                case 't':  /* ID3 Title */                    return id3->title;                case 'a':  /* ID3 Artist */                    return id3->artist;                            case 'n':  /* ID3 Track Number */                    if (id3->track_string)                        return id3->track_string;                    if (id3->tracknum) {                        snprintf(buf, buf_size, "%d", id3->tracknum);                        return buf;                    }                    return NULL;                                    case 'd':  /* ID3 Album/Disc */                    return id3->album;                case 'c':  /* ID3 Composer */                    return id3->composer;                                case 'y':  /* year */                    if( id3->year_string )                        return id3->year_string;                    if (id3->year) {                        snprintf(buf, buf_size, "%d", id3->year);                        return buf;                    }                    return NULL;                case 'g':  /* genre */                    if( id3->genre_string )                        return id3->genre_string ;                    if (id3->genre < sizeof(genres)/sizeof(char*))                        return (char*)genres[id3->genre];                    return NULL;                case 'v': /* id3 version */                    switch (id3->id3version) {                        case ID3_VER_1_0:                            return "1";                        case ID3_VER_1_1:                            return "1.1";                        case ID3_VER_2_2:                            return "2.2";                        case ID3_VER_2_3:                            return "2.3";                        case ID3_VER_2_4:                            return "2.4";                        default:

⌨️ 快捷键说明

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