From ef7293f0bc336beb30f3a5f2eafad4a447f60ac5 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Wed, 21 Jan 2004 14:58:40 +0000 Subject: New feature: NOw you can store the recorded files in either /recordings (the directory will be created automatically) or in the current directory. New feature: A "Create directory" menu option (untested in the simulator). Bug fix: The ON+Play menu could do nasty things if you pressed ON+Play in an empty dir. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4268 a1c6a512-1295-4272-9138-f99709370657 --- apps/lang/english.lang | 15 ++++++++++++ apps/main_menu.c | 5 +++- apps/recorder/radio.c | 6 ++--- apps/recorder/recording.c | 60 ++++++++++++++++++++++++++++++++++++----------- apps/recorder/recording.h | 2 +- apps/settings.c | 28 +++++++++++++++++----- apps/settings.h | 5 ++++ apps/sound_menu.c | 15 +++++++++++- apps/tree.c | 27 +++++++++++++++++++++ apps/tree.h | 1 + 10 files changed, 138 insertions(+), 26 deletions(-) (limited to 'apps') diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 847c5b985a..5815ec2169 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -2030,3 +2030,18 @@ id: LANG_MANAGE_MENU desc: in the system sub menu eng: "Manage Settings" new: + +id: LANG_RECORD_DIRECTORY +desc: in recording settings_menu +eng: "Directory" +new: + +id: LANG_RECORD_CURRENT_DIR +desc: in recording directory options +eng: "Current dir" +new: + +id: LANG_CREATE_DIR +desc: in main menu +eng: "Create directory" +new: diff --git a/apps/main_menu.c b/apps/main_menu.c index 23af8d7817..b6d73ab6f2 100644 --- a/apps/main_menu.c +++ b/apps/main_menu.c @@ -304,7 +304,7 @@ bool main_menu(void) int i = 0; /* main menu */ - struct menu_items items[8]; + struct menu_items items[9]; items[i].desc = str(LANG_BOOKMARK_MENU); items[i++].function = bookmark_menu; @@ -336,6 +336,9 @@ bool main_menu(void) items[i].desc = str(LANG_INFO); items[i++].function = info_menu; + items[i].desc = str(LANG_CREATE_DIR); + items[i++].function = create_dir; + m=menu_init( items, i ); #ifdef HAVE_LCD_CHARCELLS status_set_param(true); diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c index 0cc85335b0..65b8beb164 100644 --- a/apps/recorder/radio.c +++ b/apps/recorder/radio.c @@ -117,7 +117,7 @@ static int find_preset(int freq) bool radio_screen(void) { - char buf[128]; + char buf[MAX_PATH]; bool done = false; int button; int val; @@ -248,13 +248,13 @@ bool radio_screen(void) case BUTTON_F3: if(mpeg_status() == MPEG_STATUS_RECORD) { - mpeg_new_file(rec_create_filename()); + mpeg_new_file(rec_create_filename(buf)); update_screen = true; } else { have_recorded = true; - mpeg_record(rec_create_filename()); + mpeg_record(rec_create_filename(buf)); status_set_playmode(STATUS_RECORD); update_screen = true; } diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index b98a4579f7..c7d4b803d2 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -42,6 +42,10 @@ #include "timefuncs.h" #include "debug.h" #include "misc.h" +#include "tree.h" +#include "string.h" +#include "dir.h" +#include "errno.h" bool f2_rec_screen(void); bool f3_rec_screen(void); @@ -114,20 +118,22 @@ void adjust_cursor(void) } } -char *rec_create_filename(void) +char *rec_create_filename(char *buffer) { - static char fname[32]; - struct tm * tm; + int fpos; + struct tm *tm = get_time(); - tm = get_time(); + if(global_settings.rec_directory) + getcwd(buffer, MAX_PATH); + else + strncpy(buffer, rec_base_directory, MAX_PATH); - /* Create a filename: RYYMMDD-HHMMSS.mp3 */ - snprintf(fname, 32, "/R%02d%02d%02d-%02d%02d%02d.mp3", + /* Append filename to path: RYYMMDD-HH.MM.SS.mp3 */ + fpos = strlen(buffer); + snprintf(&buffer[fpos], MAX_PATH-fpos, "/R%02d%02d%02d-%02d%02d%02d.mp3", tm->tm_year%100, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); - - DEBUGF("Filename: %s\n", fname); - return fname; + return buffer; } bool recording_screen(void) @@ -144,6 +150,9 @@ bool recording_screen(void) unsigned int seconds; unsigned int last_seconds = 0; int hours, minutes; + char path_buffer[MAX_PATH]; + int rc; + bool been_in_usb_mode = false; cursor = 0; mpeg_init_recording(); @@ -170,6 +179,25 @@ bool recording_screen(void) lcd_getstringsize("M", &w, &h); lcd_setmargins(global_settings.invert_cursor ? 0 : w, 8); + /* Try to create the base directory if needed */ + if(global_settings.rec_directory == 0) + { + rc = mkdir(rec_base_directory, 0); + if(rc < 0 && errno != EEXIST) + { + splash(HZ * 2, true, + "Can't create the %s directory. Error code %d.", + rec_base_directory, rc); + } + else + { + /* If we have created the directory, we want the dir browser to + be refreshed even if we haven't recorded anything */ + if(errno != EEXIST) + have_recorded = true; + } + } + while(!done) { button = button_get_w_tmo(HZ / peak_meter_fps); @@ -195,13 +223,13 @@ bool recording_screen(void) if(!(mpeg_status() & MPEG_STATUS_RECORD)) { have_recorded = true; - mpeg_record(rec_create_filename()); + mpeg_record(rec_create_filename(path_buffer)); status_set_playmode(STATUS_RECORD); update_countdown = 1; /* Update immediately */ } else { - mpeg_new_file(rec_create_filename()); + mpeg_new_file(rec_create_filename(path_buffer)); update_countdown = 1; /* Update immediately */ } last_seconds = 0; @@ -354,8 +382,8 @@ bool recording_screen(void) if(mpeg_status() != MPEG_STATUS_RECORD) { usb_screen(); - have_recorded = true; /* Refreshes the browser later on */ done = true; + been_in_usb_mode = true; } break; } @@ -419,7 +447,7 @@ bool recording_screen(void) that the recorded files don't get too big. */ if (mpeg_status() && (seconds >= dseconds)) { - mpeg_new_file(rec_create_filename()); + mpeg_new_file(rec_create_filename(path_buffer)); update_countdown = 1; last_seconds = 0; } @@ -529,7 +557,11 @@ bool recording_screen(void) mpeg_sound_set(SOUND_AVC, global_settings.avc); lcd_setfont(FONT_UI); - return have_recorded; + + if (have_recorded) + reload_directory(); + + return been_in_usb_mode; } bool f2_rec_screen(void) diff --git a/apps/recorder/recording.h b/apps/recorder/recording.h index 08edbbcfb4..174621b3b7 100644 --- a/apps/recorder/recording.h +++ b/apps/recorder/recording.h @@ -20,6 +20,6 @@ #define RECORDING_H bool recording_screen(void); -char *rec_create_filename(void); +char *rec_create_filename(char *buf); #endif diff --git a/apps/settings.c b/apps/settings.c index abb2b79dca..bfc943bef0 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -65,8 +65,10 @@ void dac_line_in(bool enable); #endif struct user_settings global_settings; char rockboxdir[] = ROCKBOX_DIR; /* config/font/data file directory */ +char rec_base_directory[] = REC_BASE_DIR; -#define CONFIG_BLOCK_VERSION 8 + +#define CONFIG_BLOCK_VERSION 9 #define CONFIG_BLOCK_SIZE 512 #define RTC_BLOCK_SIZE 44 @@ -156,7 +158,7 @@ Rest of config block, only saved to disk: 0xB8 (char[20]) WPS file 0xCC (char[20]) Lang file 0xE0 (char[20]) Font file -0xF4 Prerecording time (bit 0-4) +0xF4 Prerecording time (bit 0-4), Recording directory option (bit 5-6) 0xF5-0xFF *************************************/ @@ -439,7 +441,8 @@ int settings_save( void ) strncpy(&config_block[0xcc], global_settings.lang_file, MAX_FILENAME); strncpy(&config_block[0xe0], global_settings.font_file, MAX_FILENAME); - config_block[0xf4]=(unsigned char)global_settings.rec_prerecord_time; + config_block[0xf4]=((unsigned char)global_settings.rec_prerecord_time | + ((unsigned char)global_settings.rec_directory << 5)); if(save_config_buffer()) { @@ -681,7 +684,7 @@ void settings_load(void) } if (config_block[0x1d] != 0xFF) - memcpy(&global_settings.resume_seed,&config_block[0x1d], 4); + memcpy(&global_settings.resume_seed, &config_block[0x1d], 4); if (config_block[0x21] != 0xFF) { @@ -766,8 +769,10 @@ void settings_load(void) strncpy(global_settings.lang_file, &config_block[0xcc], MAX_FILENAME); strncpy(global_settings.font_file, &config_block[0xe0], MAX_FILENAME); - if (config_block[0xf4] != 0xff) - global_settings.rec_prerecord_time = config_block[0xf4]; + if (config_block[0xf4] != 0xff) { + global_settings.rec_prerecord_time = config_block[0xf4] & 0x1f; + global_settings.rec_directory = (config_block[0xf4] >> 5) & 3; + } #ifdef HAVE_LCD_CHARCELLS if (config_block[0xa8] != 0xff) @@ -1101,6 +1106,10 @@ bool settings_load_config(char* file) else if (!strcasecmp(name, "prerecording time")) { set_cfg_int(&global_settings.rec_prerecord_time, value, 0, 30); } + else if (!strcasecmp(name, "rec directory")) { + static char* options[] = {rec_base_directory, "current"}; + set_cfg_option(&global_settings.rec_directory, value, options, 2); + } #endif else if (!strcasecmp(name, "idle poweroff")) { static char* options[] = {"off","1","2","3","4","5","6","7","8", @@ -1454,6 +1463,12 @@ bool settings_save_config(void) fprintf(fd, "prerecording time: %d\r\n", global_settings.rec_prerecord_time); + { + static char* options[] = {rec_base_directory, "current"}; + fprintf(fd, "rec directory: %s\r\n", + options[global_settings.rec_directory]); + } + #endif fprintf(fd, "#\r\n# Bookmarking\r\n#\r\n"); @@ -1513,6 +1528,7 @@ void settings_reset(void) { global_settings.rec_right_gain = 2; /* 0dB */ global_settings.rec_editable = false; global_settings.rec_prerecord_time = 0; + global_settings.rec_directory = 0; /* rec_base_directory */ global_settings.resume = RESUME_ASK; global_settings.contrast = lcd_default_contrast(); global_settings.invert = DEFAULT_INVERT_SETTING; diff --git a/apps/settings.h b/apps/settings.h index 49fa83b359..436b5204d5 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -28,6 +28,7 @@ #define FONT_DIR "/fonts" #define LANG_DIR "/langs" #define PLUGIN_DIR ROCKBOX_DIR"/rocks" +#define REC_BASE_DIR "/recordings" #define MAX_FILENAME 20 @@ -95,6 +96,7 @@ struct user_settings 13= 24:00 */ int rec_prerecord_time; /* In seconds, 0-30, 0 means OFF */ + int rec_directory; /* 0=base dir, 1=current dir */ /* device settings */ @@ -230,6 +232,9 @@ extern struct user_settings global_settings; extern char rockboxdir[]; extern long lasttime; +/* Recording base directory */ +extern char rec_base_directory[]; + /* system defines */ #ifdef HAVE_LCD_CHARCELLS diff --git a/apps/sound_menu.c b/apps/sound_menu.c index 11a5581ecb..01bbe09bd1 100644 --- a/apps/sound_menu.c +++ b/apps/sound_menu.c @@ -255,6 +255,17 @@ static bool recprerecord(void) names, 31, NULL ); } +static bool recdirectory(void) +{ + char *names[] = { + rec_base_directory, str(LANG_RECORD_CURRENT_DIR) + }; + + return set_option(str(LANG_RECORD_DIRECTORY), + &global_settings.rec_directory, INT, + names, 2, NULL ); +} + #endif /* HAVE_MAS3587F */ static void set_chanconf(int val) @@ -308,7 +319,7 @@ bool recording_menu(bool no_source) { int m; int i = 0; - struct menu_items menu[7]; + struct menu_items menu[8]; bool result; menu[i].desc = str(LANG_RECORDING_QUALITY); @@ -327,6 +338,8 @@ bool recording_menu(bool no_source) menu[i++].function = rectimesplit; menu[i].desc = str(LANG_RECORD_PRERECORD_TIME); menu[i++].function = recprerecord; + menu[i].desc = str(LANG_RECORD_DIRECTORY); + menu[i++].function = recdirectory; m=menu_init( menu, i ); result = menu_run(m); diff --git a/apps/tree.c b/apps/tree.c index 9e1a22f567..aedeeb1dfd 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -772,6 +772,9 @@ static bool handle_on(int *ds, int *dc, int numentries, int tree_max_on_screen, { int onplay_result; + if(!numentries) + break; + if (currdir[1]) snprintf(buf, sizeof buf, "%s/%s", currdir, dircache[dircursor+dirstart].name); @@ -1499,6 +1502,30 @@ bool create_playlist(void) return true; } +bool create_dir(void) +{ + char dirname[MAX_PATH]; + int rc; + int pathlen; + + memset(dirname, 0, sizeof dirname); + + snprintf(dirname, sizeof dirname, "%s/", + currdir[1] ? currdir : ""); + + pathlen = strlen(dirname); + rc = kbd_input(dirname + pathlen, (sizeof dirname)-pathlen); + if(rc < 0) + return false; + + rc = mkdir(dirname, 0); + if(rc < 0) { + splash(HZ, true, "%s %s", str(LANG_CREATE_DIR), str(LANG_FAILED)); + } + + return true; +} + bool rockbox_browse(char *root, int dirfilter) { bool rc; diff --git a/apps/tree.h b/apps/tree.h index c7b678eb82..45297361f5 100644 --- a/apps/tree.h +++ b/apps/tree.h @@ -47,6 +47,7 @@ void browse_root(void); void set_current_file(char *path); bool rockbox_browse(char *root, int dirfilter); bool create_playlist(void); +bool create_dir(void); void resume_directory(char *dir); char *getcwd(char *buf, int size); void reload_directory(void); -- cgit v1.2.3