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

📄 wps-display.c

📁 编译后直接运行的MP3播放器全部C语言源代码 一个包含FAT文件系统、系统引导 Boot、FLASH Driver等内容的
💻 C
📖 第 1 页 / 共 3 页
字号:
                            return NULL;                    }            }            break;        case 'f':  /* File Information */            *flags |= WPS_REFRESH_STATIC;            switch(tag[1])            {                case 'v':  /* VBR file? */                    return id3->vbr ? "(avg)" : NULL;                case 'b':  /* File Bitrate */                    if(id3->bitrate)                        snprintf(buf, buf_size, "%d", id3->bitrate);                    else                        snprintf(buf, buf_size, "?");                    return buf;                case 'f':  /* File Frequency */                    snprintf(buf, buf_size, "%d", id3->frequency);                    return buf;                case 'p':  /* File Path */                    return id3->path;                case 'm':  /* File Name - With Extension */                    return get_dir(buf, buf_size, id3->path, 0);                case 'n':  /* File Name */                    if (get_dir(buf, buf_size, id3->path, 0))                    {                        /* Remove extension */                        char* sep = strrchr(buf, '.');                        if (NULL != sep)                        {                            *sep = 0;                        }                        return buf;                    }                    else                    {                        return NULL;                    }                case 's':  /* File Size (in kilobytes) */                    snprintf(buf, buf_size, "%d", id3->filesize / 1024);                    return buf;            }            break;        case 'p':  /* Playlist/Song Information */            switch(tag[1])            {                case 'b':  /* progress bar */                    *flags |= WPS_REFRESH_PLAYER_PROGRESS;#ifdef HAVE_LCD_CHARCELLS                    snprintf(buf, buf_size, "%c", wps_progress_pat[0]);                    full_line_progressbar=0;                    return buf;#else                    return "\x01";#endif                case 'f':  /* full-line progress bar */#ifdef HAVE_LCD_CHARCELLS#ifndef HAVE_NEO_LCD                    if(has_new_lcd()) {                        *flags |= WPS_REFRESH_PLAYER_PROGRESS;                        *flags |= WPS_REFRESH_DYNAMIC;                        full_line_progressbar=1;                        /* we need 11 characters (full line) for                           progress-bar */                        snprintf(buf, buf_size, "           ");                    }                    else#endif /* HAVE_NEO_LCD */                    {                        /* Tell the user if we have an OldPlayer */                        snprintf(buf, buf_size, " <Old LCD> ");                    }                    return buf;#endif                case 'p':  /* Playlist Position */                    *flags |= WPS_REFRESH_STATIC;                    snprintf(buf, buf_size, "%d", playlist_get_display_index());                    return buf;                case 'n':  /* Playlist Name (without path) */                    *flags |= WPS_REFRESH_STATIC;                    return playlist_name(NULL, buf, buf_size);                case 'e':  /* Playlist Total Entries */                    *flags |= WPS_REFRESH_STATIC;                    snprintf(buf, buf_size, "%d", playlist_amount());                    return buf;                case 'c':  /* Current Time in Song */                    *flags |= WPS_REFRESH_DYNAMIC;                    format_time(buf, buf_size, id3->elapsed + ff_rewind_count);                    return buf;                case 'r': /* Remaining Time in Song */                    *flags |= WPS_REFRESH_DYNAMIC;                    format_time(buf, buf_size,                                 id3->length - id3->elapsed - ff_rewind_count);                    return buf;                case 't':  /* Total Time */                    *flags |= WPS_REFRESH_STATIC;                    format_time(buf, buf_size, id3->length);                    return buf;#ifdef HAVE_LCD_BITMAP                case 'm': /* Peak Meter */                    *flags |= WPS_REFRESH_PEAK_METER;                    return "\x01";#endif                case 's': /* shuffle */                    if ( global_settings.playlist_shuffle )                        return "s";                    else                        return NULL;                    break;                case 'v': /* volume */                    *flags |= WPS_REFRESH_DYNAMIC;                    snprintf(buf, buf_size, "%d%%", global_settings.volume);                    return buf;            }            break;        case 'b': /* battery info */            *flags |= WPS_REFRESH_DYNAMIC;            switch (tag[1]) {                case 'l': /* battery level */                    snprintf(buf, buf_size, "%d%%", battery_level());                    return buf;                case 't': /* estimated battery time */                {                    int t = battery_time();                    if (t >= 0)                        snprintf(buf, buf_size, "%dh %dm", t / 60, t % 60);                    else                        strncpy(buf, "?h ?m", buf_size);                    return buf;                }            }            break;        case 'd': /* Directory path information */            {                int level = tag[1] - '0';                *flags |= WPS_REFRESH_STATIC;                /* d1 through d9 */                if ((0 < level) && (9 > level))                {                    return get_dir(buf, buf_size, id3->path, level);                }            }            break;        case 't': /* set sub line time multiplier */            {                 int d = 1;                int time_mult = 0;                bool have_point = false;                bool have_tenth = false;                              while (((tag[d] >= '0') &&                         (tag[d] <= '9')) ||                       (tag[d] == '.'))                 {                    if (tag[d] != '.')                     {                        time_mult = time_mult * 10;                        time_mult = time_mult + tag[d] - '0';                        if (have_point)                         {                            have_tenth = true;                            d++;                            break;                        }                    }                    else                     {                        have_point = true;                    }                    d++;                }                                if (have_tenth == false)                    time_mult *= 10;                                       *subline_time_mult = time_mult;                 *tag_len = d;                buf[0] = 0;                return buf;            }            break;    }        return NULL;}/* Skip to the end of the current %? conditional. * * fmt     - string to skip it. Should point to somewhere after the leading  *           "<" char (and before or at the last ">"). * to_else - if true, skip to the else part (after the "|", if any), else skip *           to the end (the ">"). * * Returns the new position in fmt. */static char* skip_conditional(char* fmt, bool to_else){    int level = 1;    while (*fmt)    {        switch (*fmt++)        {            case '%':                break;                    case '|':                if (to_else && (1 == level))                    return fmt;                            continue;                        case '>':                if (0 == --level)                 {                    if (to_else)                        fmt--;                                    return fmt;                }                continue;            default:                continue;        }                switch (*fmt++)        {            case 0:            case '%':            case '|':            case '<':            case '>':                break;                    case '?':                while (*fmt && ('<' != *fmt))                    fmt++;                            if ('<' == *fmt)                    fmt++;                            level++;                break;                    default:                break;        }    }        return fmt;}/* Generate the display based on id3 information and format string. * * buf      - char buffer to write the display to. * buf_size - the size of buffer. * id3      - the ID3 data to format with. * fmt      - format description. * flags    - returns the type of the line. See constants i wps-display.h */static void format_display(char* buf,                            int buf_size,                            struct mp3entry* id3,                            char* fmt,                            unsigned char* subline_time_mult,                            unsigned char* flags){    char temp_buf[128];    char* buf_start = buf;    char* buf_end = buf + buf_size - 1;   /* Leave room for end null */    char* value = NULL;    int level = 0;    unsigned char tag_length;    *subline_time_mult = DEFAULT_SUBLINE_TIME_MULTIPLIER;    while (fmt && *fmt && buf < buf_end)    {        switch (*fmt)        {            case '%':                ++fmt;                break;                    case '|':            case '>':                if (level > 0)                 {                    fmt = skip_conditional(fmt, false);                    level--;                    continue;                }                /* Else fall through */            default:                *buf++ = *fmt++;                continue;        }                switch (*fmt)        {            case 0:                *buf++ = '%';                break;                    case 's':                *flags |= WPS_REFRESH_SCROLL;                ++fmt;                break;                    case '%':            case '|':            case '<':            case '>':            case ';':                *buf++ = *fmt++;                break;                    case '?':                fmt++;                value = get_tag(id3, fmt, temp_buf, sizeof(temp_buf),                                &tag_length, subline_time_mult, flags);                            while (*fmt && ('<' != *fmt))                    fmt++;                            if ('<' == *fmt)                    fmt++;                            /* No value, so skip to else part */                if ((!value) || (!strlen(value)))                    fmt = skip_conditional(fmt, true);                level++;                break;                    default:                value = get_tag(id3, fmt, temp_buf, sizeof(temp_buf),                                &tag_length, subline_time_mult, flags);                fmt += tag_length;                            if (value)                {                    while (*value && (buf < buf_end))                        *buf++ = *value++;                }        }    }        *buf = 0;    /* if resulting line is an empty line, set the subline time to 0 */    if (*buf_start == 0)        *subline_time_mult = 0;    /* If no flags have been set, the line didn't contain any format codes.       We still want to refresh it. */    if(*flags == 0)        *flags = WPS_REFRESH_STATIC;}bool wps_refresh(struct mp3entry* id3, int ffwd_offset,                  unsigned char refresh_mode){    char buf[MAX_PATH];    unsigned char flags;    int i;    bool update_line;    bool only_one_subline;    bool new_subline_refresh;    int search;    int search_start;#ifdef HAVE_LCD_BITMAP    int h = font_get(FONT_UI)->height;    int offset = global_settings.statusbar ? STATUSBAR_HEIGHT : 0;    /* to find out wether the peak meter is enabled we       assume it wasn't until we find a line that contains       the peak meter. We can't use peak_meter_enabled itself       because that would mean to turn off the meter thread        temporarily. (That shouldn't matter unless yield        or sleep is called but who knows...)    */    bool enable_pm = false;#endif    /* reset to first subline if refresh all flag is set */

⌨️ 快捷键说明

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