summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-06-25 13:26:04 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-06-25 13:26:04 +0000
commitbb9aaf50654bb32184d289b18f110cf9fd6687d1 (patch)
tree188943fa5d709086a89de94f1b3f98ed12979bea
parent3f9c7c2ab5edef46346fed58807307ea4499b39c (diff)
downloadrockbox-bb9aaf50654bb32184d289b18f110cf9fd6687d1.zip
rockbox-bb9aaf50654bb32184d289b18f110cf9fd6687d1.tar.gz
rockbox-bb9aaf50654bb32184d289b18f110cf9fd6687d1.tar.bz2
rockbox-bb9aaf50654bb32184d289b18f110cf9fd6687d1.tar.xz
A step towards WPS
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1184 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/tree.c82
-rw-r--r--apps/wps.c51
-rw-r--r--apps/wps.h2
-rw-r--r--firmware/mpeg.c42
-rw-r--r--firmware/mpeg.h1
-rw-r--r--uisimulator/x11/Makefile5
-rw-r--r--uisimulator/x11/mpeg.c18
7 files changed, 145 insertions, 56 deletions
diff --git a/apps/tree.c b/apps/tree.c
index a1af9bc..b43c1d7 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,"<Playing>");
- lcd_puts(0,1,"<all files>");
- 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,"<Playing>");
+ lcd_puts(0,1,"<all files>");
+ 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 fb878d6..bd23a28 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:"<nothing>");
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:"<no artist>");
- lcd_puts(0, 1, mp3.title?mp3.title:"<no title>");
+ lcd_puts(0, 0, id3->artist?id3->artist:"<no artist>");
+ lcd_puts(0, 1, id3->title?id3->title:"<no 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 2bc6fbf..4963ffe 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 cce67db..41be070 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<MAX_ID3_TAGS-1; i++)
+ id3tags[i] = id3tags[i+1];
+ last_tag--;
+ }
}
else
{
@@ -297,7 +316,15 @@ static int new_file(void)
if ( !trackname )
return -1;
- debugf("playing %s\n", trackname);
+ DEBUGF("playing %s\n", trackname);
+
+ /* grab id3 tag of new file and remember where in memory it starts */
+ if ( last_tag < MAX_ID3_TAGS ) {
+ mp3info(&(id3tags[last_tag].id3), trackname);
+ id3tags[last_tag].mempos = mp3buf_write;
+ last_tag++;
+ }
+
mpeg_file = open(trackname, O_RDONLY);
if(mpeg_file < 0)
{
@@ -307,6 +334,11 @@ static int new_file(void)
return 0;
}
+struct mp3entry* mpeg_current_track(void)
+{
+ return &(id3tags[0].id3);
+}
+
static void mpeg_thread(void)
{
struct event ev;
@@ -344,6 +376,14 @@ static void mpeg_thread(void)
break;
}
+ /* grab id3 tag of new file and
+ remember where in memory it starts */
+ if ( last_tag < MAX_ID3_TAGS ) {
+ mp3info(&(id3tags[last_tag].id3), ev.data);
+ id3tags[last_tag].mempos = mp3buf_write;
+ last_tag++;
+ }
+
/* Make it read more data */
filling = true;
queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
diff --git a/firmware/mpeg.h b/firmware/mpeg.h
index 493e5f5..54b760c 100644
--- a/firmware/mpeg.h
+++ b/firmware/mpeg.h
@@ -27,5 +27,6 @@ void mpeg_resume(void);
void mpeg_volume(int percent);
void mpeg_bass(int percent);
void mpeg_treble(int percent);
+struct mp3entry* mpeg_current_track(void);
#endif
diff --git a/uisimulator/x11/Makefile b/uisimulator/x11/Makefile
index 9681ad5..d3b446f 100644
--- a/uisimulator/x11/Makefile
+++ b/uisimulator/x11/Makefile
@@ -76,7 +76,7 @@ APPCFLAGS = $(DEBUG) $(DEFINES) $(APPINCLUDES) -W -Wall
FIRMSRCS = chartables.c lcd.c sprintf.c id3.c debug.c settings.c
APPS = main.c tree.c play.c menu.c credits.c main_menu.c\
- playlist.c showtext.c
+ playlist.c showtext.c wps.c
MENUS = games_menu.c screensavers_menu.c settings_menu.c sound_menu.c
@@ -182,6 +182,9 @@ $(OBJDIR)/boxes.o: $(RECDIR)/boxes.c
$(OBJDIR)/main.o: $(APPDIR)/main.c
$(CC) $(APPCFLAGS) -c $< -o $@
+$(OBJDIR)/wps.o: $(APPDIR)/wps.c
+ $(CC) $(APPCFLAGS) -c $< -o $@
+
$(OBJDIR)/bmp.o: $(RECDIR)/bmp.c
$(CC) $(APPCFLAGS) -c $< -o $@
diff --git a/uisimulator/x11/mpeg.c b/uisimulator/x11/mpeg.c
index 0f3680d..e1bce1e 100644
--- a/uisimulator/x11/mpeg.c
+++ b/uisimulator/x11/mpeg.c
@@ -16,11 +16,13 @@
* KIND, either express or implied.
*
****************************************************************************/
-
+#include <stdbool.h>
#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;
+}