From bb9aaf50654bb32184d289b18f110cf9fd6687d1 Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Tue, 25 Jun 2002 13:26:04 +0000 Subject: A step towards WPS git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1184 a1c6a512-1295-4272-9138-f99709370657 --- apps/tree.c | 82 ++++++++++++++++++++++++++---------------------- apps/wps.c | 51 +++++++++++++++++++++--------- apps/wps.h | 2 +- firmware/mpeg.c | 42 ++++++++++++++++++++++++- firmware/mpeg.h | 1 + uisimulator/x11/Makefile | 5 ++- uisimulator/x11/mpeg.c | 18 ++++++++++- 7 files changed, 145 insertions(+), 56 deletions(-) diff --git a/apps/tree.c b/apps/tree.c index a1af9bc203..b43c1d725d 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -34,6 +34,7 @@ #include "mpeg.h" #include "playlist.h" #include "menu.h" +#include "wps.h" #ifdef HAVE_LCD_BITMAP #include "icons.h" @@ -198,31 +199,31 @@ char* peek_next_track(int type) return NULL; switch(playing) { - default: - case 1: - /* play-full-dir mode */ + default: + case 1: + /* play-full-dir mode */ - /* get next track in dir */ - while (dircursor + start + 1 < numentries ) { - if(dircursor+1 < TREE_MAX_ON_SCREEN) - dircursor++; - else - start++; - if ( dircacheptr[dircursor+start]->file && - dircacheptr[dircursor+start]->name[strlen(dircacheptr[dircursor+start]->name)-1] == '3') { - snprintf(buf,sizeof buf,"%s/%s", - currdir, dircacheptr[dircursor+start]->name ); - lcd_clear_display(); - lcd_puts(0,0,""); - lcd_puts(0,1,""); - return buf; - } - } - break; + /* get next track in dir */ + while (dircursor + start + 1 < numentries ) { + if(dircursor+1 < TREE_MAX_ON_SCREEN) + dircursor++; + else + start++; + if ( dircacheptr[dircursor+start]->file && + dircacheptr[dircursor+start]->name[strlen(dircacheptr[dircursor+start]->name)-1] == '3') { + snprintf(buf,sizeof buf,"%s/%s", + currdir, dircacheptr[dircursor+start]->name ); + lcd_clear_display(); + lcd_puts(0,0,""); + lcd_puts(0,1,""); + return buf; + } + } + break; - case 2: - /* playlist mode */ - return playlist_next(type); + case 2: + /* playlist mode */ + return playlist_next(type); } return NULL; @@ -246,6 +247,7 @@ bool dirbrowse(char *root) lcd_update(); while(1) { + bool restore = false; button = button_get(true); switch(button) { @@ -267,8 +269,7 @@ bool dirbrowse(char *root) } else start = dircursor = 0; - numentries = showdir(currdir, start); - put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, true); + restore = true; } else mpeg_stop(); @@ -316,8 +317,7 @@ bool dirbrowse(char *root) playing = 0; } } - numentries = showdir(currdir, start); - put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, true); + restore = true; break; case TREE_PREV: @@ -354,20 +354,28 @@ bool dirbrowse(char *root) case TREE_MENU: lcd_stop_scroll(); main_menu(); + restore = true; + break; - /* restore display */ - /* TODO: this is just a copy from BUTTON_STOP, fix it */ - lcd_clear_display(); - numentries = showdir(currdir, start); - put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, true); - + case BUTTON_ON: + wps_show(); + restore = true; break; + } - lcd_stop_scroll(); - if ( numentries ) - lcd_puts_scroll(LINE_X, LINE_Y+dircursor, - dircacheptr[start+dircursor]->name); + if ( restore ) { + /* restore display */ + /* TODO: this is just a copy from BUTTON_STOP, fix it */ + numentries = showdir(currdir, start); + put_cursorxy(0, CURSOR_Y + LINE_Y+dircursor, true); + } + else { + lcd_stop_scroll(); + if ( numentries ) + lcd_puts_scroll(LINE_X, LINE_Y+dircursor, + dircacheptr[start+dircursor]->name); + } lcd_update(); } diff --git a/apps/wps.c b/apps/wps.c index fb878d6aaf..bd23a28557 100644 --- a/apps/wps.c +++ b/apps/wps.c @@ -29,6 +29,7 @@ #include "sprintf.h" #include "settings.h" #include "wps.h" +#include "mpeg.h" #define LINE_Y 1 /* initial line */ @@ -38,11 +39,12 @@ #define PLAY_DISPLAY_TRACK_TITLE 2 /* demonstrates showing different formats from playtune */ -void wps_show_play(char* filename) +void wps_show(void) { - struct mp3entry mp3; - mp3info(&mp3,filename); + struct mp3entry* id3 = mpeg_current_track(); + static bool playing = true; + lcd_clear_display(); switch ( global_settings.wps_display ) { case PLAY_DISPLAY_TRACK_TITLE: { @@ -54,7 +56,7 @@ void wps_show_play(char* filename) char szBuff[257]; szBuff[sizeof(szBuff)-1] = 0; - strncpy(szBuff, filename, sizeof(szBuff)); + strncpy(szBuff, id3->path, sizeof(szBuff)); szTok = strtok_r(szBuff, "/", &end); szTok = strtok_r(NULL, "/", &end); @@ -62,7 +64,7 @@ void wps_show_play(char* filename) // Assume path format of: Genre/Artist/Album/Mp3_file strncpy(szArtist,szTok,sizeof(szArtist)); szArtist[sizeof(szArtist)-1] = 0; - szDelimit = strrchr(filename, ch); + szDelimit = strrchr(id3->path, ch); lcd_puts(0,0, szArtist?szArtist:""); lcd_puts_scroll(0,LINE_Y,(++szDelimit)); break; @@ -70,12 +72,12 @@ void wps_show_play(char* filename) case PLAY_DISPLAY_FILENAME_SCROLL: { char ch = '/'; - char* szLast = strrchr(filename, ch); + char* szLast = strrchr(id3->path, ch); if (szLast) lcd_puts_scroll(0,0, (++szLast)); else - lcd_puts_scroll(0,0, mp3.path); + lcd_puts_scroll(0,0, id3->path); break; } @@ -85,27 +87,46 @@ void wps_show_play(char* filename) char buffer[256]; lcd_puts(0, 0, "[id3 info]"); - lcd_puts(0, LINE_Y, mp3.title?mp3.title:""); - lcd_puts(0, LINE_Y+1, mp3.album?mp3.album:""); - lcd_puts(0, LINE_Y+2, mp3.artist?mp3.artist:""); + lcd_puts(0, LINE_Y, id3->title?id3->title:""); + lcd_puts(0, LINE_Y+1, id3->album?id3->album:""); + lcd_puts(0, LINE_Y+2, id3->artist?id3->artist:""); - snprintf(buffer,sizeof(buffer), "%d ms", mp3.length); + snprintf(buffer,sizeof(buffer), "%d ms", id3->length); lcd_puts(0, LINE_Y+3, buffer); - snprintf(buffer,sizeof(buffer), "%d kbits", mp3.bitrate); + snprintf(buffer,sizeof(buffer), "%d kbits", id3->bitrate); lcd_puts(0, LINE_Y+4, buffer); - snprintf(buffer,sizeof(buffer), "%d Hz", mp3.frequency); + snprintf(buffer,sizeof(buffer), "%d Hz", id3->frequency); lcd_puts(0, LINE_Y+5, buffer); #else - lcd_puts(0, 0, mp3.artist?mp3.artist:""); - lcd_puts(0, 1, mp3.title?mp3.title:""); + lcd_puts(0, 0, id3->artist?id3->artist:""); + lcd_puts(0, 1, id3->title?id3->title:""); #endif break; } + } + lcd_update(); + while ( 1 ) { + switch ( button_get(true) ) { + case BUTTON_ON: + return; +#ifdef HAVE_RECORDER_KEYPAD + case BUTTON_PLAY: +#else + case BUTTON_UP: +#endif + if ( playing ) + mpeg_pause(); + else + mpeg_resume(); + + playing = !playing; + break; + } } } diff --git a/apps/wps.h b/apps/wps.h index 2bc6fbf8dc..4963ffee4f 100644 --- a/apps/wps.h +++ b/apps/wps.h @@ -21,7 +21,7 @@ #include "id3.h" #include "playlist.h" -void wps_show_play(char* filename); +void wps_show(void); //void wps_show_playlist(char* current, playlist_info_t *list); #endif diff --git a/firmware/mpeg.c b/firmware/mpeg.c index cce67dbdee..41be070a6e 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c @@ -29,6 +29,7 @@ #include "panic.h" #include "file.h" #include "settings.h" +#include "id3.h" #define MPEG_STACK_SIZE 0x2000 #define MPEG_CHUNKSIZE 0x20000 @@ -141,6 +142,14 @@ static bool filling; /* We are filling the buffer with data from disk */ static int mpeg_file; +/* list of tracks in memory */ +#define MAX_ID3_TAGS 4 +static struct { + struct mp3entry id3; + int mempos; +} id3tags[MAX_ID3_TAGS]; +static int last_tag = 0; + static void create_fliptable(void) { int i; @@ -271,6 +280,16 @@ void DEI3(void) last_dma_chunk_size = MIN(last_dma_chunk_size, space_until_end_of_buffer); DTCR3 = last_dma_chunk_size & 0xffff; SAR3 = (unsigned int)mp3buf + mp3buf_read; + + /* will we move across the track boundary? */ + if (( mp3buf_read <= id3tags[0].mempos ) && + ( mp3buf_read + last_dma_chunk_size > id3tags[0].mempos )) { + /* shift array so index 0 is current track */ + int i; + for (i=0; i #include "debug.h" +#include "id3.h" /* This file is for emulating some of the mpeg controlling functions of the target */ +static struct mp3entry dummy; void mpeg_volume(void) { @@ -43,6 +45,20 @@ void mpeg_play(char *tune) { DEBUGF("We instruct the MPEG thread to play %s for us\n", tune); + mp3info(&dummy, tune); +} + +void mpeg_pause(void) +{ +} + +void mpeg_resume(void) +{ } #endif + +struct mp3entry* mpeg_current_track(void) +{ + return &dummy; +} -- cgit v1.2.3