From d7a55e186827508a39247334405a5b473c589f9f Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Wed, 12 Mar 2003 20:21:30 +0000 Subject: Changed ON+PLAY screen to a menu, unified player & recorder and moved the code to a separate file. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3436 a1c6a512-1295-4272-9138-f99709370657 --- apps/onplay.c | 163 +++++++++++++++++++++++++++++++ apps/onplay.h | 24 +++++ apps/tree.c | 305 ++-------------------------------------------------------- apps/tree.h | 11 +++ 4 files changed, 208 insertions(+), 295 deletions(-) create mode 100644 apps/onplay.c create mode 100644 apps/onplay.h (limited to 'apps') diff --git a/apps/onplay.c b/apps/onplay.c new file mode 100644 index 0000000000..571caa403b --- /dev/null +++ b/apps/onplay.c @@ -0,0 +1,163 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 Björn Stenberg + * + * 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 +#include +#include + +#include "lcd.h" +#include "dir.h" +#include "file.h" +#include "mpeg.h" +#include "menu.h" +#include "lang.h" +#include "playlist.h" +#include "button.h" +#include "kernel.h" +#include "keyboard.h" + +static char* selected_file = NULL; +static bool reload_dir = false; + +static bool queue_file(void) +{ + queue_add(selected_file); + return false; +} + +static bool delete_file(void) +{ + bool exit = false; + + lcd_clear_display(); + lcd_puts(0,0,str(LANG_REALLY_DELETE)); + lcd_puts_scroll(0,1,selected_file); + + while (!exit) { + int btn = button_get(true); + switch (btn) { + case BUTTON_PLAY: + case BUTTON_PLAY | BUTTON_REL: + if (!remove(selected_file)) { + reload_dir = true; + lcd_clear_display(); + lcd_puts_scroll(0,0,selected_file); + lcd_puts(0,1,str(LANG_DELETED)); + lcd_update(); + sleep(HZ); + exit = true; + } + break; + + default: + /* ignore button releases */ + if (!(btn & BUTTON_REL)) + exit = true; + break; + } + } + return false; +} + +static bool rename_file(void) +{ + char newname[MAX_PATH]; + char* ptr = strrchr(selected_file, '/') + 1; + int pathlen = (ptr - selected_file); + strncpy(newname, selected_file, sizeof newname); + if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) { + if (!strlen(selected_file+pathlen) || + (rename(selected_file, newname) < 0)) { + lcd_clear_display(); + lcd_puts(0,0,str(LANG_RENAME)); + lcd_puts(0,1,str(LANG_FAILED)); + lcd_update(); + sleep(HZ*2); + } + else + reload_dir = true; + } + + return false; +} + +extern int d_1; +extern int d_2; + +static void xingupdate(int percent) +{ + char buf[32]; + + snprintf(buf, 32, "%d%%", percent); + lcd_puts(0, 3, buf); + snprintf(buf, 32, "%x", d_1); + lcd_puts(0, 4, buf); + snprintf(buf, 32, "%x", d_2); + lcd_puts(0, 5, buf); + lcd_update(); +} + +static bool vbr_fix(void) +{ + char buf[32]; + unsigned long start_tick; + unsigned long end_tick; + + lcd_clear_display(); + lcd_puts(0, 0, selected_file); + lcd_update(); + + start_tick = current_tick; + mpeg_create_xing_header(selected_file, xingupdate); + end_tick = current_tick; + + snprintf(buf, 32, "%d ticks", (int)(end_tick - start_tick)); + lcd_puts(0, 1, buf); + snprintf(buf, 32, "%d seconds", (int)(end_tick - start_tick)/HZ); + lcd_puts(0, 2, buf); + lcd_update(); + + return false; +} + +int onplay(char* file, int attr) +{ + struct menu_items menu[5]; /* increase this if you add entries! */ + int m, i=0, result; + + selected_file = file; + + if (mpeg_status() & MPEG_STATUS_PLAY) + menu[i++] = (struct menu_items) { str(LANG_QUEUE), queue_file }; + + if (!(attr & ATTR_DIRECTORY)) + menu[i++] = (struct menu_items) { str(LANG_DELETE), delete_file }; + + menu[i++] = (struct menu_items) { str(LANG_RENAME), rename_file }; + menu[i++] = (struct menu_items) { "VBRfix", vbr_fix }; + + /* DIY menu handling, since we want to exit after selection */ + m = menu_init( menu, i ); + result = menu_show(m); + if (result >= 0) + menu[result].function(); + menu_exit(m); + + return reload_dir; +} diff --git a/apps/onplay.h b/apps/onplay.h new file mode 100644 index 0000000000..8540aaf2c7 --- /dev/null +++ b/apps/onplay.h @@ -0,0 +1,24 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 Björn Stenberg + * + * 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 _ONPLAY_H_ +#define _ONPLAY_H_ + +int onplay(char* file, int attr); + +#endif diff --git a/apps/tree.c b/apps/tree.c index 8fbe6ad404..acb53e5071 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -50,6 +50,7 @@ #include "language.h" #include "screens.h" #include "keyboard.h" +#include "onplay.h" #ifdef HAVE_LCD_BITMAP #include "widgets.h" @@ -142,17 +143,6 @@ extern unsigned char bitmap_icons_6x8[LastIcon][6]; #define TREE_MENU BUTTON_MENU #endif /* HAVE_RECORDER_KEYPAD */ -/* using attribute not used by FAT */ -#define TREE_ATTR_MPA 0x40 /* mpeg audio file */ -#define TREE_ATTR_M3U 0x80 /* playlist */ -#define TREE_ATTR_WPS 0x100 /* wps config file */ -#define TREE_ATTR_MOD 0x200 /* firmware file */ -#define TREE_ATTR_CFG 0x400 /* config file */ -#define TREE_ATTR_TXT 0x500 /* text file */ -#define TREE_ATTR_FONT 0x800 /* font file */ -#define TREE_ATTR_LNG 0x1000 /* binary lang file */ -#define TREE_ATTR_MASK 0xffd0 /* which bits tree.c uses (above + DIR) */ - static int build_playlist(int start_index) { int i; @@ -652,289 +642,6 @@ void set_current_file(char *path) } } -#ifdef HAVE_LCD_BITMAP -extern int d_1; -extern int d_2; - -void xingupdate(int percent) -{ - char buf[32]; - - snprintf(buf, 32, "%d%%", percent); - lcd_puts(0, 3, buf); - snprintf(buf, 32, "%x", d_1); - lcd_puts(0, 4, buf); - snprintf(buf, 32, "%x", d_2); - lcd_puts(0, 5, buf); - lcd_update(); -} - -void do_xing(char *filename) -{ - char buf2[32]; - unsigned long start_tick; - unsigned long end_tick; - - lcd_clear_display(); - lcd_puts(0, 0, filename); - lcd_update(); - start_tick = current_tick; - mpeg_create_xing_header(filename, xingupdate); - end_tick = current_tick; - snprintf(buf2, 32, "%d ticks", (int)(end_tick - start_tick)); - lcd_puts(0, 1, buf2); - snprintf(buf2, 32, "%d seconds", (int)(end_tick - start_tick)/HZ); - lcd_puts(0, 2, buf2); - lcd_update(); -} - -static int onplay_screen(char* dir, char* file) -{ - bool exit = false; - bool used = false; - bool playing = mpeg_status() & MPEG_STATUS_PLAY; - char buf[MAX_PATH]; - struct entry* f = &dircache[dirstart + dircursor]; - bool isdir = f->attr & ATTR_DIRECTORY; - - if (dir[1]) - snprintf(buf, sizeof buf, "%s/%s", dir, file); - else - snprintf(buf, sizeof buf, "/%s", file); - - lcd_clear_display(); - - { - int w,h; - char* ptr; - - lcd_setfont(FONT_SYSFIXED); - - if (playing) { - ptr = str(LANG_QUEUE); - lcd_getstringsize(ptr,&w,&h); - lcd_putsxy((LCD_WIDTH-w)/2, h*2, ptr); - lcd_bitmap(bitmap_icons_7x8[Icon_Play], - LCD_WIDTH/2 - 3, LCD_HEIGHT/2 - 4, 7, 8, true); - } - - /* don't delete directories */ - if (!isdir) { - ptr = str(LANG_DELETE); - lcd_getstringsize(ptr,&w,&h); - lcd_putsxy(LCD_WIDTH - w, LCD_HEIGHT/2 - h/2, ptr); - lcd_bitmap(bitmap_icons_7x8[Icon_FastForward], - LCD_WIDTH/2 + 8, LCD_HEIGHT/2 - 4, 7, 8, true); - } - - ptr = str(LANG_RENAME); - lcd_getstringsize(ptr,&w,&h); - lcd_putsxy(0, LCD_HEIGHT/2 - h/2, ptr); - lcd_bitmap(bitmap_icons_7x8[Icon_FastBackward], - LCD_WIDTH/2 - 16, LCD_HEIGHT/2 - 4, 7, 8, true); - - ptr = "VBR Fix"; - lcd_getstringsize(ptr,&w,&h); - lcd_putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT - h, ptr); - lcd_bitmap(bitmap_icons_7x8[Icon_DownArrow], - LCD_WIDTH/2 - 3, LCD_HEIGHT - h*3, 7, 8, true); - } - lcd_update(); - - - while (!exit) { - switch (button_get(true)) { - case BUTTON_LEFT: - case BUTTON_ON | BUTTON_LEFT: { - char newname[MAX_PATH]; - char* ptr = strrchr(buf, '/') + 1; - int pathlen = (ptr - buf); - strncpy(newname, buf, sizeof newname); - if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) { - if (!strlen(buf+pathlen) || (rename(buf, newname) < 0)) { - lcd_clear_display(); - lcd_puts(0,0,str(LANG_RENAME)); - lcd_puts(0,1,str(LANG_FAILED)); - lcd_update(); - sleep(HZ*2); - } - else - reload_dir = true; - } - exit = true; - break; - } - - case BUTTON_RIGHT: - case BUTTON_ON | BUTTON_RIGHT: - /* don't delete directories */ - if (isdir) - break; - lcd_clear_display(); - lcd_puts(0,0,str(LANG_REALLY_DELETE)); - lcd_puts_scroll(0,1,file); - lcd_puts(0,3,str(LANG_RESUME_CONFIRM_RECORDER)); - lcd_puts(0,4,str(LANG_RESUME_CANCEL_RECORDER)); - lcd_update(); - while (!exit) { - int btn = button_get(true); - switch (btn) { - case BUTTON_PLAY: - case BUTTON_PLAY | BUTTON_REL: - if (!remove(buf)) { - reload_dir = true; - lcd_clear_display(); - lcd_puts_scroll(0,0,file); - lcd_puts(0,1,str(LANG_DELETED)); - lcd_update(); - sleep(HZ); - exit = true; - } - break; - - default: - /* ignore button releases */ - if (!(btn & BUTTON_REL)) - exit = true; - break; - } - } - break; - - case BUTTON_DOWN: - case BUTTON_ON | BUTTON_DOWN: - do_xing(buf); -// exit = true; - break; - - case BUTTON_PLAY: - case BUTTON_ON | BUTTON_PLAY: { - if (playing) - queue_add(buf); - exit = true; - break; - } - - case BUTTON_ON | BUTTON_REL: - used = true; - break; - - case BUTTON_ON: - if (used) - exit = true; - break; - - case BUTTON_OFF: - exit = true; - break; - } - } - - lcd_setfont(FONT_UI); - - return false; -} - -#else - -static int onplay_screen(char* dir, char* file) -{ - bool exit = false; - bool playing = mpeg_status() & MPEG_STATUS_PLAY; - char buf[MAX_PATH]; - struct entry* f = &dircache[dirstart + dircursor]; - bool isdir = f->attr & ATTR_DIRECTORY; - struct menu_items items[3]; - int ids[3]; - int lastitem=0; - int m_handle; - int selected; - - if (dir[1]) - snprintf(buf, sizeof buf, "%s/%s", dir, file); - else - snprintf(buf, sizeof buf, "/%s", file); - - if (playing) { - items[lastitem].desc=str(LANG_QUEUE); - ids[lastitem]=1; - lastitem++; - } - - items[lastitem].desc=str(LANG_RENAME); - ids[lastitem]=2; - lastitem++; - - /* don't delete directories */ - if (!isdir) { - items[lastitem].desc=str(LANG_DELETE); - ids[lastitem]=3; - lastitem++; - } - m_handle=menu_init(items, lastitem); - - selected=menu_show(m_handle); - if (selected>=0) { - switch(ids[selected]) { - case 1: - if (playing) - queue_add(buf); - break; - - case 2: { - char newname[MAX_PATH]; - char* ptr = strrchr(buf, '/') + 1; - int pathlen = (ptr - buf); - strncpy(newname, buf, sizeof newname); - if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) { - if (rename(buf, newname) < 0) { - lcd_clear_display(); - lcd_puts(0,0,str(LANG_RENAME)); - lcd_puts(0,1,str(LANG_FAILED)); - lcd_update(); - sleep(HZ*2); - } - else - reload_dir = true; - } - } - break; - - case 3: - lcd_clear_display(); - lcd_puts_scroll(0,0,file); - lcd_puts(0,1,str(LANG_REALLY_DELETE)); - lcd_update(); - while (!exit) { - int btn = button_get(true); - switch (btn) { - case BUTTON_PLAY: - if (!remove(buf)) { - reload_dir = true; - lcd_clear_display(); - lcd_puts_scroll(0,0,file); - lcd_puts(0,1,str(LANG_DELETED)); - lcd_update(); - sleep(HZ); - exit = true; - } - break; - - default: - /* ignore button releases */ - if (!(btn & BUTTON_REL)) - exit = true; - break; - } - } - break; - } - } - menu_exit(m_handle); - return false; -} -#endif - static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen) { bool exit = false; @@ -942,6 +649,7 @@ static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen) int dirstart = *ds; int dircursor = *dc; + char buf[MAX_PATH]; while (!exit) { switch (button_get(true)) { @@ -975,7 +683,14 @@ static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen) case BUTTON_PLAY: case BUTTON_ON | BUTTON_PLAY: - onplay_screen(currdir, dircache[dircursor+dirstart].name); + if (currdir[1]) + snprintf(buf, sizeof buf, "%s/%s", + currdir, dircache[dircursor+dirstart].name); + else + snprintf(buf, sizeof buf, "/%s", + dircache[dircursor+dirstart].name); + if (onplay(buf, dircache[dircursor+dirstart].attr)) + reload_dir = 1; exit = true; used = true; break; diff --git a/apps/tree.h b/apps/tree.h index 6b8879001f..a1e132f775 100644 --- a/apps/tree.h +++ b/apps/tree.h @@ -21,6 +21,17 @@ #include +/* using attribute not used by FAT */ +#define TREE_ATTR_MPA 0x40 /* mpeg audio file */ +#define TREE_ATTR_M3U 0x80 /* playlist */ +#define TREE_ATTR_WPS 0x100 /* wps config file */ +#define TREE_ATTR_MOD 0x200 /* firmware file */ +#define TREE_ATTR_CFG 0x400 /* config file */ +#define TREE_ATTR_TXT 0x500 /* text file */ +#define TREE_ATTR_FONT 0x800 /* font file */ +#define TREE_ATTR_LNG 0x1000 /* binary lang file */ +#define TREE_ATTR_MASK 0xffd0 /* which bits tree.c uses (above + DIR) */ + void browse_root(void); void set_current_file(char *path); bool dirbrowse(char *root); -- cgit v1.2.3