diff -urN rockbox-daily-20030819/apps/lang/english.lang rockbox/apps/lang/english.lang --- rockbox-daily-20030819/apps/lang/english.lang 2003-08-06 06:00:28.000000000 +0200 +++ rockbox/apps/lang/english.lang 2003-08-20 17:13:34.000000000 +0200 @@ -1730,3 +1730,13 @@ desc: Asked from onplay screen eng: "Recursively?" new: + +id: LANG_SLEEP_COUNTDOWN +desc: Menu item for sleeptimer - countdown +eng: "Countdown" +new: + +id: LANG_SLEEP_TRACK +desc: Menu item for sleeptimer - track +eng: "After a track" +new: \ No newline at end of file diff -urN rockbox-daily-20030819/apps/sleeptimer.c rockbox/apps/sleeptimer.c --- rockbox-daily-20030819/apps/sleeptimer.c 2003-04-24 06:00:44.000000000 +0200 +++ rockbox/apps/sleeptimer.c 2003-08-20 18:25:11.000000000 +0200 @@ -31,6 +31,10 @@ #include "status.h" #include "debug.h" +#include "menu.h" +#include "sleeptimer_functions.h" +#include "playlist.h" + #include "lang.h" #define SMALL_STEP_SIZE 15*60 /* Seconds */ @@ -38,7 +42,7 @@ #define THRESHOLD 60 /* Minutes */ #define MAX_TIME 5*60*60 /* Hours */ -bool sleeptimer_screen(void) +static bool sleeptimer_countdown(void) { #ifdef HAVE_LCD_BITMAP int w, h; @@ -58,9 +62,9 @@ lcd_getstringsize("M", &w, &h); lcd_setmargins(w, 8); #endif - + lcd_clear_display(); - lcd_puts_scroll(0, 0, str(LANG_SLEEP_TIMER)); + lcd_puts_scroll(0, 0, str(LANG_SLEEP_COUNTDOWN)); while(!done) { @@ -102,7 +106,7 @@ amount = SMALL_STEP_SIZE; else amount = LARGE_STEP_SIZE; - + newtime = oldtime * 60 + amount; if(newtime > MAX_TIME) newtime = MAX_TIME; @@ -110,7 +114,7 @@ changed=true; set_sleep_timer(newtime); break; - + #ifdef HAVE_PLAYER_KEYPAD case BUTTON_LEFT: #else @@ -121,11 +125,11 @@ amount = SMALL_STEP_SIZE; else amount = LARGE_STEP_SIZE; - + newtime = oldtime*60 - amount; if(newtime < 0) newtime = 0; - + changed=true; set_sleep_timer(newtime); break; @@ -154,3 +158,175 @@ lcd_stop_scroll(); return false; } + + +/* go to sleep after n tracks */ +static bool sleeptimer_track(void) +{ +#ifdef HAVE_LCD_BITMAP + int w, h; +#endif + unsigned long seconds=0; + unsigned long new_seconds=0; + + int hours, minutes; + int track=0; + int last_track=playlist_amount(); + + int current_track=0; + int result; + int button; + + int old_elapsed=0; + + bool done = false; + char buf[32]; + int oldtime; + int org_timer=get_sleep_timer(); + bool changed=false; + +#ifdef HAVE_LCD_BITMAP + lcd_setfont(FONT_UI); + lcd_getstringsize("M", &w, &h); + lcd_setmargins(w, 8); +#endif + + lcd_clear_display(); + lcd_puts_scroll(0, 0, str(LANG_SLEEP_TRACK)); + + while(!done) + { + result = playlist_get_resume_info(¤t_track); + button = button_get_w_tmo(HZ); + switch(button) + { +#ifdef HAVE_RECORDER_KEYPAD + case BUTTON_LEFT: + case BUTTON_PLAY: +#else + case BUTTON_PLAY: +#endif + + done = true; + break; + +#ifdef HAVE_RECORDER_KEYPAD + case BUTTON_OFF: +#else + case BUTTON_STOP: + case BUTTON_MENU: +#endif + if (changed) { + lcd_stop_scroll(); + lcd_puts(0, 0, str(LANG_MENU_SETTING_CANCEL)); + lcd_update(); + set_sleep_timer(org_timer); + sleep(HZ/2); + } + done = true; + break; + +#ifdef HAVE_PLAYER_KEYPAD + case BUTTON_RIGHT: +#else + case BUTTON_UP: +#endif + oldtime = get_sleep_timer(); + + track++; + + if (track<=last_track) { + + if (track>current_track) { + seconds+=get_track_length(track); + } + else if (track<=current_track) { + track=current_track; + seconds=get_current_track_length(); + old_elapsed=get_elapsed_time(); + seconds-=old_elapsed; + }; + } + else { + track=last_track; + }; + + seconds+=old_elapsed; + old_elapsed=get_elapsed_time(); + seconds-=old_elapsed; + + changed=true; + set_sleep_timer(seconds); + break; + +#ifdef HAVE_PLAYER_KEYPAD + case BUTTON_LEFT: +#else + case BUTTON_DOWN: +#endif + oldtime = get_sleep_timer(); + + track--; + + if (track ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: sleeptimer_functions.c,v 1.0 2003/08/20 11:26:22 cent20 Exp $ + * + * Copyright (C) 2003 Vincent Paeder + * + * 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. + * + ****************************************************************************/ + +#include +#include "kernel.h" + +#include "mpeg.h" +#include "id3.h" +#include "playlist.h" + + +/* returns the name of a track which is in the playlist */ +char get_filename(int track) +{ + int result; + struct playlist_track_info track_info; + + char *fname=""; + + if (track>0) { + result=playlist_get_track_info(track, &track_info); + strcpy(fname, track_info.filename); + return *fname; + }; + return *fname; +} + +/* returns the name of a length of a mp3 file */ +unsigned long get_file_length(char *filename) +{ + + bool result; + struct mp3entry entry; + + result = mp3info(&entry, filename); + + if (result) + return 0; + else + return (entry.length)/1000; + +} + +/* returns how many milliseconds have been played so far */ +unsigned long get_elapsed_time(void) +{ + struct mp3entry* entry; + + entry = mpeg_current_track(); + + return (entry->elapsed)/1000; + +} + +/* no comment! */ +unsigned long get_current_track_length(void) +{ + struct mp3entry* entry; + + entry = mpeg_current_track(); + + return (entry->length)/1000; + +} + +/* no comment as well ... erm ... track is the track number */ +/* in the playlist */ +unsigned long get_track_length(int track) { + char *fname=""; + *fname=get_filename(track); + return get_file_length(fname); +} + +/* get length of each track and return the sum */ +/* I don't use it anymore as it accesses the hard disk quite a lot */ +/* e.g. if you got 360 files in your playlist, when you reach */ +/* the, let's say, 345th position, it'll read each previous file */ +/* to compute the total length */ +/* Anyway, I leave it because it could be useful for other applications */ +/* ... maybe! */ + +unsigned long get_total_length(int track) +{ + unsigned long total_length=0; + char *fname=""; + int i; + int result; + int current_track=0; + + result=playlist_get_resume_info(¤t_track); + + for (i=current_track+1; i ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: sleeptimer_functions.h,v 1.0 2003/08/20 11:26:22 cent20 Exp $ + * + * Copyright (C) 2003 Vincent Paeder + * + * 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. + * + ****************************************************************************/ + +#ifndef _SLEEPTIMER_FUNCTIONS_H_ +#define _SLEEPTIMER_FUNCTIONS_H_ + +char get_filename(int track); +unsigned long get_file_length(char *filename); +unsigned long get_elapsed_time(void); +unsigned long get_total_length(int track); +unsigned long get_current_track_length(void); +unsigned long get_track_length(int track); +#endif