From a72f95c2ba57c5f4764f20044d6ac1ca4be79e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Stenberg?= Date: Wed, 26 Jun 2002 23:25:03 +0000 Subject: [PATCH] Added next/previous track git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1211 a1c6a512-1295-4272-9138-f99709370657 --- apps/playlist.c | 8 ++++---- apps/playlist.h | 2 +- apps/tree.c | 49 +++++++++++++++++++++++++++++++------------------ apps/wps.c | 24 +++++++++++++++++------- firmware/mpeg.c | 6 +----- 5 files changed, 54 insertions(+), 35 deletions(-) diff --git a/apps/playlist.c b/apps/playlist.c index 5d7ef2fd6c..bd5c2b2053 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -35,15 +35,15 @@ bool playlist_shuffle = false; char now_playing[256]; -char* playlist_next(int type) +char* playlist_next(int steps) { - int seek = playlist.indices[playlist.index]; + int seek; int max; int fd; int i; - (void)type; /* prevent compiler warning until this is gets used */ - playlist.index = (playlist.index+1) % playlist.amount; + playlist.index = (playlist.index+steps) % playlist.amount; + seek = playlist.indices[playlist.index]; fd = open(playlist.filename, O_RDONLY); if(-1 != fd) { diff --git a/apps/playlist.h b/apps/playlist.h index 2517d2b877..273a612da0 100644 --- a/apps/playlist.h +++ b/apps/playlist.h @@ -38,7 +38,7 @@ extern playlist_info_t playlist; extern bool playlist_shuffle; void play_list(char *dir, char *file); -char* playlist_next(int type); +char* playlist_next(int steps); void randomise_playlist( playlist_info_t *playlist, unsigned int seed ); void empty_playlist( playlist_info_t *playlist ); void add_indices_to_playlist( playlist_info_t *playlist ); diff --git a/apps/tree.c b/apps/tree.c index a071ce73d6..4b16bac68b 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -190,7 +190,7 @@ static int playing = 0; static char currdir[255]; /* QUICK HACK! this should be handled by the playlist code later */ -char* peek_next_track(int type) +char* peek_next_track(int steps) { static char buf[256]; @@ -204,26 +204,39 @@ char* peek_next_track(int type) /* 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; + if ( steps == 1 ) { + 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 ); + return buf; + } + } + } + else { + while (dircursor + start > 0) { + if (dircursor > 0) + 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); + return buf; + } } } break; case 2: /* playlist mode */ - return playlist_next(type); + return playlist_next(steps); } return NULL; @@ -313,8 +326,9 @@ bool dirbrowse(char *root) else { playing = 1; - playtune(buf); - playing = 0; + mpeg_play(buf); + lcd_stop_scroll(); + wps_show(); } } restore = true; @@ -367,7 +381,6 @@ bool dirbrowse(char *root) 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); } diff --git a/apps/wps.c b/apps/wps.c index 75b68d0d8d..838f8f786a 100644 --- a/apps/wps.c +++ b/apps/wps.c @@ -146,25 +146,35 @@ void wps_show(void) #ifdef HAVE_RECORDER_KEYPAD case BUTTON_UP: -#else - case BUTTON_RIGHT: -#endif global_settings.volume += 2; if(global_settings.volume > 100) global_settings.volume = 100; mpeg_volume(global_settings.volume); break; -#ifdef HAVE_RECORDER_KEYPAD case BUTTON_DOWN: -#else - case BUTTON_LEFT: -#endif global_settings.volume -= 2; if(global_settings.volume < 0) global_settings.volume = 0; mpeg_volume(global_settings.volume); break; +#endif + + case BUTTON_LEFT: + mpeg_prev(); + break; + + case BUTTON_RIGHT: + mpeg_next(); + break; + +#ifdef HAVE_RECORDER_KEYPAD + case BUTTON_OFF: +#else + case BUTTON_DOWN: +#endif + mpeg_stop(); + break; } sleep(HZ/20); } diff --git a/firmware/mpeg.c b/firmware/mpeg.c index b1cbf33e7e..31e50caed3 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c @@ -319,11 +319,7 @@ static int new_file(bool next_track) { char *trackname; - if (next_track) - trackname = peek_next_track(0); - else - trackname = peek_prev_track(0); - + trackname = peek_next_track( next_track ? 1 : -1 ); if ( !trackname ) return -1;