diff --git a/apps/action.h b/apps/action.h index 96e8086baa..deb3681dd2 100644 --- a/apps/action.h +++ b/apps/action.h @@ -58,6 +58,7 @@ enum { CONTEXT_SETTINGS_EQ, CONTEXT_SETTINGS_COLOURCHOOSER, CONTEXT_SETTINGS_TIME, + CONTEXT_SETTINGS_RECTRIGGER, /* The following contexts should use ACTION_STD_[NEXT|PREV] and (possibly) ACTION_SETTINGS_[INC|DEC] diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c index 023f9b47e5..0e4ed8deac 100644 --- a/apps/gui/option_select.c +++ b/apps/gui/option_select.c @@ -44,7 +44,16 @@ #endif static int selection_to_val(const struct settings_list *setting, int selection); - +int option_value_as_int(const struct settings_list *setting) +{ + int type = (setting->flags & F_T_MASK); + int temp = 0; + if (type == F_T_BOOL) + temp = *(bool*)setting->setting?1:0; + else if (type == F_T_UINT || type == F_T_INT) + temp = *(int*)setting->setting; + return temp; +} static const char *unit_strings[] = { [UNIT_INT] = "", [UNIT_MS] = "ms", @@ -214,7 +223,8 @@ static int option_talk(int selected_item, void * data) return 0; } -#ifdef HAVE_QUICKSCREEN /* only the quickscreen uses this so far */ +#if defined(HAVE_QUICKSCREEN) || defined(HAVE_RECORDING) + /* only the quickscreen and recording trigger needs this */ void option_select_next_val(const struct settings_list *setting, bool previous, bool apply) { diff --git a/apps/gui/option_select.h b/apps/gui/option_select.h index 16465cf7f7..ed7b6ae6d6 100644 --- a/apps/gui/option_select.h +++ b/apps/gui/option_select.h @@ -27,11 +27,16 @@ bool option_screen(const struct settings_list *setting, struct viewport parent[NB_SCREENS], bool use_temp_var, unsigned char* option_title); - +#if defined(HAVE_QUICKSCREEN) || defined(HAVE_RECORDING) void option_select_next_val(const struct settings_list *setting, bool previous, bool apply); +#endif char *option_get_valuestring(const struct settings_list *setting, char *buffer, int buf_len, intptr_t temp_var); void option_talk_value(const struct settings_list *setting, int value, bool enqueue); + +/* only use this for int and bool settings */ +int option_value_as_int(const struct settings_list *setting); + #endif /* _GUI_OPTION_SELECT_H_ */ diff --git a/apps/gui/quickscreen.c b/apps/gui/quickscreen.c index 261b1ca8ac..ddc02c1103 100644 --- a/apps/gui/quickscreen.c +++ b/apps/gui/quickscreen.c @@ -200,10 +200,7 @@ static void gui_quickscreen_draw(struct gui_quickscreen *qs, title = P2STR(ID2P(qs->items[i]->lang_id)); setting = qs->items[i]->setting; - if ((qs->items[i]->flags & F_BOOL_SETTING) == F_BOOL_SETTING) - temp = *(bool*)setting?1:0; - else - temp = *(int*)setting; + temp = option_value_as_int(qs->items[i]); value = option_get_valuestring((struct settings_list*)qs->items[i], buf, MAX_PATH, temp); @@ -235,23 +232,13 @@ static void gui_quickscreen_draw(struct gui_quickscreen *qs, display->set_viewport(NULL); } -static int option_value(const struct settings_list *setting) -{ - if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) - { - return *(bool*)setting->setting==true?1:0; - } - else - return *(int*)setting->setting; -} - static void talk_qs_option(struct settings_list *opt, bool enqueue) { if (global_settings.talk_menu) { if(!enqueue) talk_shutup(); talk_id(opt->lang_id, true); - option_talk_value(opt, option_value(opt), true); + option_talk_value(opt, option_value_as_int(opt), true); } } diff --git a/apps/keymaps/keymap-c200.c b/apps/keymaps/keymap-c200.c index d3b0593954..81efc4ca5b 100644 --- a/apps/keymaps/keymap-c200.c +++ b/apps/keymaps/keymap-c200.c @@ -5,7 +5,7 @@ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ - * $Id:$ + * $Id$ * * Copyright (C) 2007 Mark Arigo * @@ -307,6 +307,7 @@ const struct button_mapping* get_context_mapping(int context) case CONTEXT_CUSTOM|CONTEXT_SETTINGS: case CONTEXT_SETTINGS_COLOURCHOOSER: case CONTEXT_SETTINGS_EQ: + case CONTEXT_SETTINGS_RECTRIGGER: return button_context_settings_right_is_inc; case CONTEXT_YESNOSCREEN: diff --git a/apps/keymaps/keymap-cowond2.c b/apps/keymaps/keymap-cowond2.c index 59ca7cb123..8dbc299527 100644 --- a/apps/keymaps/keymap-cowond2.c +++ b/apps/keymaps/keymap-cowond2.c @@ -152,6 +152,7 @@ const struct button_mapping* target_get_context_mapping(int context) case CONTEXT_SETTINGS: return button_context_settings; case CONTEXT_CUSTOM|CONTEXT_SETTINGS: + case CONTEXT_SETTINGS_RECTRIGGER: return button_context_settings_right_is_inc; case CONTEXT_SETTINGS_COLOURCHOOSER: diff --git a/apps/keymaps/keymap-e200.c b/apps/keymaps/keymap-e200.c index 1c11f3f917..e51ca7c5e2 100644 --- a/apps/keymaps/keymap-e200.c +++ b/apps/keymaps/keymap-e200.c @@ -293,6 +293,7 @@ const struct button_mapping* get_context_mapping(int context) case CONTEXT_CUSTOM|CONTEXT_SETTINGS: case CONTEXT_SETTINGS_COLOURCHOOSER: case CONTEXT_SETTINGS_EQ: + case CONTEXT_SETTINGS_RECTRIGGER: return button_context_settings_right_is_inc; case CONTEXT_SETTINGS_TIME: diff --git a/apps/keymaps/keymap-h10.c b/apps/keymaps/keymap-h10.c index 2ea934bd9a..a264b8a844 100644 --- a/apps/keymaps/keymap-h10.c +++ b/apps/keymaps/keymap-h10.c @@ -391,6 +391,7 @@ const struct button_mapping* get_context_mapping(int context) case CONTEXT_SETTINGS_COLOURCHOOSER: case CONTEXT_SETTINGS_EQ: case CONTEXT_SETTINGS_TIME: + case CONTEXT_SETTINGS_RECTRIGGER: return button_context_settings_right_is_inc; case CONTEXT_YESNOSCREEN: diff --git a/apps/keymaps/keymap-h1x0_h3x0.c b/apps/keymaps/keymap-h1x0_h3x0.c index f674e2cab7..37c08824c0 100644 --- a/apps/keymaps/keymap-h1x0_h3x0.c +++ b/apps/keymaps/keymap-h1x0_h3x0.c @@ -889,6 +889,7 @@ static const struct button_mapping* get_context_mapping_remote(int context) case CONTEXT_CUSTOM|CONTEXT_TREE: return remote_btn_ctxt_tree; case CONTEXT_SETTINGS_TIME: + case CONTEXT_SETTINGS_RECTRIGGER: return remote_btn_ctxt_settingsgrph; case CONTEXT_SETTINGS: @@ -939,6 +940,7 @@ const struct button_mapping* get_context_mapping(int context) case CONTEXT_SETTINGS: return button_context_settings; case CONTEXT_CUSTOM|CONTEXT_SETTINGS: + case CONTEXT_SETTINGS_RECTRIGGER: return button_context_settings_right_is_inc; case CONTEXT_SETTINGS_COLOURCHOOSER: diff --git a/apps/keymaps/keymap-ipod.c b/apps/keymaps/keymap-ipod.c index b05db02aae..e162f0e621 100644 --- a/apps/keymaps/keymap-ipod.c +++ b/apps/keymaps/keymap-ipod.c @@ -196,6 +196,7 @@ const struct button_mapping* get_context_mapping(int context) case CONTEXT_SETTINGS_COLOURCHOOSER: case CONTEXT_SETTINGS_TIME: case CONTEXT_SETTINGS: + case CONTEXT_SETTINGS_RECTRIGGER: return button_context_settings; case CONTEXT_YESNOSCREEN: return button_context_yesno; diff --git a/apps/keymaps/keymap-m3.c b/apps/keymaps/keymap-m3.c index 23d78e47b2..f18ec9371c 100644 --- a/apps/keymaps/keymap-m3.c +++ b/apps/keymaps/keymap-m3.c @@ -469,6 +469,7 @@ const struct button_mapping* get_context_mapping(int context) return button_context_settings; case CONTEXT_SETTINGS_EQ: + case CONTEXT_SETTINGS_RECTRIGGER: return button_context_settings_r_is_inc; case CONTEXT_TREE: diff --git a/apps/keymaps/keymap-ondio.c b/apps/keymaps/keymap-ondio.c index cd64657730..2448d00a7c 100644 --- a/apps/keymaps/keymap-ondio.c +++ b/apps/keymaps/keymap-ondio.c @@ -204,6 +204,7 @@ const struct button_mapping* get_context_mapping( int context ) case CONTEXT_CUSTOM|CONTEXT_TREE: return button_context_tree; case CONTEXT_RECSCREEN: + case CONTEXT_SETTINGS_RECTRIGGER: return button_context_recscreen; case CONTEXT_KEYBOARD: return button_context_keyboard; diff --git a/apps/keymaps/keymap-recorder.c b/apps/keymaps/keymap-recorder.c index 403ebbfd80..7160e0b4c9 100644 --- a/apps/keymaps/keymap-recorder.c +++ b/apps/keymaps/keymap-recorder.c @@ -294,6 +294,7 @@ const struct button_mapping* get_context_mapping( int context ) return button_context_quickscreen; case CONTEXT_RECSCREEN: + case CONTEXT_SETTINGS_RECTRIGGER: return button_context_recscreen; case CONTEXT_KEYBOARD: return button_context_keyboard; diff --git a/apps/keymaps/keymap-x5.c b/apps/keymaps/keymap-x5.c index 7acb84fbbd..ee64090be3 100644 --- a/apps/keymaps/keymap-x5.c +++ b/apps/keymaps/keymap-x5.c @@ -418,6 +418,7 @@ const struct button_mapping* get_context_mapping( int context ) case CONTEXT_SETTINGS_COLOURCHOOSER: case CONTEXT_SETTINGS_EQ: + case CONTEXT_SETTINGS_RECTRIGGER: return button_context_settings_r_is_inc; case CONTEXT_SETTINGS_TIME: diff --git a/apps/menus/recording_menu.c b/apps/menus/recording_menu.c index 8a26be03e9..9dcdcf5d3e 100644 --- a/apps/menus/recording_menu.c +++ b/apps/menus/recording_menu.c @@ -63,7 +63,10 @@ #include "action.h" #include "recording.h" #include "sound_menu.h" - +#include "option_select.h" +#include "settings_list.h" +#include "list.h" +#include "viewport.h" static bool no_source_in_menu = false; int recmenu_callback(int action,const struct menu_item_ex *this_item); @@ -381,477 +384,192 @@ enum trigger_menu_option TRIG_OPTION_COUNT, }; -static char* create_thres_str(int threshold, long *voice_id) +static enum themable_icons trigger_get_icon(int selected_item, void * data) { - static char retval[6]; - if (threshold < 0) { - if (threshold < -88) { - snprintf (retval, sizeof retval, "%s", str(LANG_DB_INF)); - if(voice_id) - *voice_id = LANG_DB_INF; - } else { - snprintf (retval, sizeof retval, "%ddb", threshold + 1); - if(voice_id) - *voice_id = TALK_ID(threshold + 1, UNIT_DB); - } - } else { - snprintf (retval, sizeof retval, "%d%%", threshold); - if(voice_id) - *voice_id = TALK_ID(threshold, UNIT_PERCENT); - } - return retval; + (void)data; + if ((selected_item % 2) == 0) /* header */ + return Icon_Menu_setting; + return Icon_NOICON; } -#define INF_DB (-89) -static void change_threshold(int *threshold, int change) +static char * trigger_get_name(int selected_item, void * data, + char * buffer, size_t buffer_len) { - if (global_settings.peak_meter_dbfs) { - if (*threshold >= 0) { - int db = (calc_db(*threshold * MAX_PEAK / 100) - 9000) / 100; - *threshold = db; - } - *threshold += change; - if (*threshold > -1) { - *threshold = INF_DB; - } else if (*threshold < INF_DB) { - *threshold = -1; - } - } else { - if (*threshold < 0) { - *threshold = peak_meter_db2sample(*threshold * 100) * 100 / MAX_PEAK; - } - *threshold += change; - if (*threshold > 100) { - *threshold = 0; - } else if (*threshold < 0) { - *threshold = 100; + const struct settings_list **settings = + (const struct settings_list **)data; + const struct settings_list *s = settings[selected_item / 2]; + if ((selected_item % 2) == 0) /* header */ + return P2STR(ID2P(s->lang_id)); + else + { + int temp; + temp = option_value_as_int(s); + if ((selected_item / 2 == START_THRESHOLD || + selected_item / 2 == STOP_THRESHOLD) && + temp == 0) + { + return str(LANG_OFF); } + return option_get_valuestring(s, buffer, buffer_len, temp); } } - -/** - * Displays a menu for editing the trigger settings. - */ -bool rectrigger(void) +static void trigger_speak_item(const struct settings_list *s, bool title) { - int exit_request = false; - enum trigger_menu_option selected = TRIGGER_MODE; - bool retval = false; - int old_x_margin[NB_SCREENS]; - int old_y_margin[NB_SCREENS]; - -#define TRIGGER_MODE_COUNT 3 - static const unsigned char *trigger_modes[] = { - ID2P(LANG_OFF), - ID2P(LANG_RECORD_TRIG_NOREARM), - ID2P(LANG_REPEAT) - }; - -#define PRERECORD_TIMES_COUNT 31 - static const struct opt_items prerecord_times[] = { - { STR(LANG_OFF) }, -#define T(x) { (unsigned char *)(#x "s"), TALK_ID(x, UNIT_SEC) } - T(1), T(2), T(3), T(4), T(5), T(6), T(7), T(8), T(9), T(10), - T(11), T(12), T(13), T(14), T(15), T(16), T(17), T(18), T(19), T(20), - T(21), T(22), T(23), T(24), T(25), T(26), T(27), T(28), T(29), T(30), -#undef T - }; - -#define TRIGGER_TYPE_COUNT 3 - static const unsigned char *trigger_types[] = { - ID2P(LANG_RECORD_TRIGGER_STOP), - ID2P(LANG_PAUSE), - ID2P(LANG_RECORD_TRIGGER_NEWFILESTP), - }; - - static const unsigned char *option_name[] = { - [TRIGGER_MODE] = ID2P(LANG_RECORD_TRIGGER), - [TRIGGER_TYPE] = ID2P(LANG_RECORD_TRIGGER_TYPE), - [PRERECORD_TIME] = ID2P(LANG_RECORD_PRERECORD_TIME), - [START_THRESHOLD] = ID2P(LANG_RECORD_START_THRESHOLD), - [START_DURATION] = ID2P(LANG_MIN_DURATION), - [STOP_THRESHOLD] = ID2P(LANG_RECORD_STOP_THRESHOLD), - [STOP_POSTREC] = ID2P(LANG_MIN_DURATION), - [STOP_GAP] = ID2P(LANG_RECORD_STOP_GAP) - }; - - int old_start_thres = global_settings.rec_start_thres; + int temp; + if (!global_settings.talk_menu) + return; + temp = option_value_as_int(s); + if (title) + talk_id(s->lang_id, false); + option_talk_value(s, temp, title?true:false); +} +int rectrigger(void) +{ + struct viewport vp[NB_SCREENS]; + struct gui_synclist lists; + int i, action = ACTION_REDRAW; + bool done = false, changed = true; + const struct settings_list *settings[TRIG_OPTION_COUNT]; + + int pm_y[NB_SCREENS]; + int trig_xpos[NB_SCREENS]; + int trig_ypos[NB_SCREENS]; + int trig_width[NB_SCREENS]; + + int old_start_thres_db = global_settings.rec_start_thres_db; + int old_start_thres_linear = global_settings.rec_start_thres_linear; int old_start_duration = global_settings.rec_start_duration; int old_prerecord_time = global_settings.rec_prerecord_time; - int old_stop_thres = global_settings.rec_stop_thres; + int old_stop_thres_db = global_settings.rec_stop_thres_db; + int old_stop_thres_linear = global_settings.rec_stop_thres_linear; int old_stop_postrec = global_settings.rec_stop_postrec; int old_stop_gap = global_settings.rec_stop_gap; int old_trigger_mode = global_settings.rec_trigger_mode; int old_trigger_type = global_settings.rec_trigger_type; - - int offset[NB_SCREENS]; - int option_lines[NB_SCREENS]; - int w, h, i; - int stat_height = gui_statusbar_height(); - int pm_y[NB_SCREENS]; - - int trig_xpos[NB_SCREENS]; - int trig_ypos[NB_SCREENS]; - int trig_width[NB_SCREENS]; - - bool say_field = true, say_value = true; - - FOR_NB_SCREENS(i) - { - offset[i] = 0; - trig_xpos[i] = 0; - trig_ypos[i] = screens[i].height - stat_height - TRIG_HEIGHT; - pm_y[i] = screens[i].height - stat_height; - trig_width[i] = screens[i].width; - } - - /* restart trigger with new values */ - settings_apply_trigger(); - peak_meter_trigger (global_settings.rec_trigger_mode != TRIG_MODE_OFF); - + FOR_NB_SCREENS(i) { screens[i].clear_display(); - - old_x_margin[i] = screens[i].getxmargin(); - old_y_margin[i] = screens[i].getymargin(); - if(global_settings.statusbar) - screens[i].setmargins(0, STATUSBAR_HEIGHT); - else - screens[i].setmargins(0, 0); - - screens[i].getstringsize("M", &w, &h); - - // 16 pixels are reserved for peak meter and trigger status - option_lines[i] = MIN(((screens[i].height) - - stat_height - 16)/h, - TRIG_OPTION_COUNT); + screens[i].update(); + viewport_set_defaults(&vp[i], i); + vp[i].height -= SYSFONT_HEIGHT*2; + trig_xpos[i] = 0; + trig_ypos[i] = vp[i].y + vp[i].height; + pm_y[i] = screens[i].height - SYSFONT_HEIGHT; + trig_width[i] = screens[i].width; } + /* TODO: what to do if there is < 4 lines on the screen? */ + + settings[TRIGGER_MODE] = + find_setting(&global_settings.rec_trigger_mode, NULL); + settings[TRIGGER_TYPE] = + find_setting(&global_settings.rec_trigger_type, NULL); + settings[PRERECORD_TIME] = + find_setting(&global_settings.rec_prerecord_time, NULL); + settings[START_DURATION] = + find_setting(&global_settings.rec_start_duration, NULL); + settings[STOP_POSTREC] = + find_setting(&global_settings.rec_stop_postrec, NULL); + settings[STOP_GAP] = + find_setting(&global_settings.rec_stop_gap, NULL); + if (global_settings.peak_meter_dbfs) /* show the dB settings */ + { + settings[START_THRESHOLD] = + find_setting(&global_settings.rec_start_thres_db, NULL); + settings[STOP_THRESHOLD] = + find_setting(&global_settings.rec_stop_thres_db, NULL); + } + else + { + settings[START_THRESHOLD] = + find_setting(&global_settings.rec_start_thres_linear, NULL); + settings[STOP_THRESHOLD] = + find_setting(&global_settings.rec_stop_thres_linear, NULL); + } + gui_synclist_init(&lists, trigger_get_name, settings, false, 2, vp); + gui_synclist_set_nb_items(&lists, TRIG_OPTION_COUNT*2); + gui_synclist_set_icon_callback(&lists, trigger_get_icon); + /* restart trigger with new values */ + settings_apply_trigger(); + peak_meter_trigger (global_settings.rec_trigger_mode != TRIG_MODE_OFF); + + trigger_speak_item(settings[0], true); - while (!exit_request) { - int button, k; - const char *str; - char option_value[TRIG_OPTION_COUNT][16]; - - snprintf( - option_value[TRIGGER_MODE], - sizeof option_value[TRIGGER_MODE], - "%s", - P2STR(trigger_modes[global_settings.rec_trigger_mode])); - - snprintf( - option_value[TRIGGER_TYPE], - sizeof option_value[TRIGGER_TYPE], - "%s", - P2STR(trigger_types[global_settings.rec_trigger_type])); - - snprintf ( - option_value[PRERECORD_TIME], - sizeof option_value[PRERECORD_TIME], - "%s", - P2STR(prerecord_times[global_settings.rec_prerecord_time].string)); - - /* due to value range shift (peak_meter_define_trigger) -1 is 0db */ - if (global_settings.rec_start_thres == -1) { - str = str(LANG_OFF); - } else { - str = create_thres_str(global_settings.rec_start_thres, NULL); - } - snprintf( - option_value[START_THRESHOLD], - sizeof option_value[START_THRESHOLD], - "%s", - str); - - snprintf( - option_value[START_DURATION], - sizeof option_value[START_DURATION], - "%s", - trig_durations[global_settings.rec_start_duration].string); - - if (global_settings.rec_stop_thres <= INF_DB) { - str = str(LANG_OFF); - } else { - str = create_thres_str(global_settings.rec_stop_thres, NULL); - } - snprintf( - option_value[STOP_THRESHOLD], - sizeof option_value[STOP_THRESHOLD], - "%s", - str); - - snprintf( - option_value[STOP_POSTREC], - sizeof option_value[STOP_POSTREC], - "%s", - trig_durations[global_settings.rec_stop_postrec].string); - - snprintf( - option_value[STOP_GAP], - sizeof option_value[STOP_GAP], - "%s", - trig_durations[global_settings.rec_stop_gap].string); - - FOR_NB_SCREENS(i) + while (!done) + { + if (changed) { - screens[i].set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); - screens[i].fillrect(0, stat_height, screens[i].width, - screens[i].height - stat_height); - screens[i].set_drawmode(DRMODE_SOLID); + gui_synclist_draw(&lists); + gui_syncstatusbar_draw(&statusbars, true); + peak_meter_trigger(global_settings.rec_trigger_mode!=TRIG_OFF); + settings_apply_trigger(); + changed = false; } - - gui_syncstatusbar_draw(&statusbars, true); - - /* reselect FONT_SYSFONT as status_draw has changed the font */ - /*lcd_setfont(FONT_SYSFIXED);*/ - - FOR_NB_SCREENS(i) - { - for (k = 0; k < option_lines[i]; k++) { - int x, y; - - str = P2STR(option_name[k + offset[i]]); - screens[i].putsxy((option_lines[i] < TRIG_OPTION_COUNT) ? 5 : 0, - stat_height + k * h, str); - - str = option_value[k + offset[i]]; - screens[i].getstringsize(str, &w, &h); - y = stat_height + k * h; - x = screens[i].width - w; - screens[i].putsxy(x, y, str); - if ((int)selected == (k + offset[i])) { - screens[i].set_drawmode(DRMODE_COMPLEMENT); - screens[i].fillrect(x, y, w, h); - screens[i].set_drawmode(DRMODE_SOLID); - } - } - if (option_lines[i] < TRIG_OPTION_COUNT) - gui_scrollbar_draw(&screens[i], 0, stat_height, - 4, screens[i].height - 16 - stat_height, - TRIG_OPTION_COUNT, offset[i], offset[i] + option_lines[i], - VERTICAL); - } - - bool enqueue = false; - if(say_field) { - talk_id(P2ID(option_name[selected]), enqueue); - enqueue = true; - } - if(say_value) { - long id; - switch(selected) { - case TRIGGER_MODE: - id = P2ID(trigger_modes[global_settings.rec_trigger_mode]); - break; - case TRIGGER_TYPE: - id = P2ID(trigger_types[global_settings.rec_trigger_type]); - break; - case PRERECORD_TIME: - id = prerecord_times[global_settings.rec_prerecord_time] - .voice_id; - break; - case START_THRESHOLD: - if (global_settings.rec_start_thres == -1) - id = LANG_OFF; - else create_thres_str(global_settings.rec_start_thres, &id); - break; - case START_DURATION: - id = trig_durations[global_settings.rec_start_duration] - .voice_id; - break; - case STOP_THRESHOLD: - if (global_settings.rec_stop_thres <= INF_DB) - id = LANG_OFF; - else create_thres_str(global_settings.rec_stop_thres, &id); - break; - case STOP_POSTREC: - id = trig_durations[global_settings.rec_stop_postrec].voice_id; - break; - case STOP_GAP: - id = trig_durations[global_settings.rec_stop_gap].voice_id; - break; - case TRIG_OPTION_COUNT: - // avoid compiler warnings - break; - }; - talk_id(id, enqueue); - } - say_field = say_value = false; - + peak_meter_draw_trig(trig_xpos, trig_ypos, trig_width, NB_SCREENS); - button = peak_meter_draw_get_btn(0, pm_y, 8, NB_SCREENS); - + action = peak_meter_draw_get_btn(CONTEXT_SETTINGS_RECTRIGGER, 0, pm_y, + SYSFONT_HEIGHT, NB_SCREENS); FOR_NB_SCREENS(i) screens[i].update(); - - switch (button) { + i = gui_synclist_get_sel_pos(&lists); + switch (action) + { case ACTION_STD_CANCEL: - gui_syncsplash(50, str(LANG_CANCEL)); - global_settings.rec_start_thres = old_start_thres; + gui_syncsplash(HZ/2, str(LANG_CANCEL)); + global_settings.rec_start_thres_db = old_start_thres_db; + global_settings.rec_start_thres_linear = old_start_thres_linear; global_settings.rec_start_duration = old_start_duration; global_settings.rec_prerecord_time = old_prerecord_time; - global_settings.rec_stop_thres = old_stop_thres; + global_settings.rec_stop_thres_db = old_stop_thres_db; + global_settings.rec_stop_thres_linear = old_stop_thres_linear; global_settings.rec_stop_postrec = old_stop_postrec; global_settings.rec_stop_gap = old_stop_gap; global_settings.rec_trigger_mode = old_trigger_mode; global_settings.rec_trigger_type = old_trigger_type; - exit_request = true; - break; - - case ACTION_REC_PAUSE: - exit_request = true; - break; - - case ACTION_STD_PREV: - selected += TRIG_OPTION_COUNT - 1; - selected %= TRIG_OPTION_COUNT; - FOR_NB_SCREENS(i) - { - offset[i] = MIN(offset[i], (int)selected); - offset[i] = MAX(offset[i], (int)selected - option_lines[i] + 1); - } - say_field = say_value = true; - break; - - case ACTION_STD_NEXT: - selected ++; - selected %= TRIG_OPTION_COUNT; - FOR_NB_SCREENS(i) - { - offset[i] = MIN(offset[i], (int)selected); - offset[i] = MAX(offset[i], (int)selected - option_lines[i] + 1); - } - say_field = say_value = true; - break; - - case ACTION_SETTINGS_INC: - switch (selected) { - case TRIGGER_MODE: - global_settings.rec_trigger_mode ++; - global_settings.rec_trigger_mode %= TRIGGER_MODE_COUNT; - break; - - case TRIGGER_TYPE: - global_settings.rec_trigger_type ++; - global_settings.rec_trigger_type %= TRIGGER_TYPE_COUNT; - break; - - case PRERECORD_TIME: - global_settings.rec_prerecord_time ++; - global_settings.rec_prerecord_time %= PRERECORD_TIMES_COUNT; - break; - - case START_THRESHOLD: - change_threshold(&global_settings.rec_start_thres, 1); - break; - - case START_DURATION: - global_settings.rec_start_duration ++; - global_settings.rec_start_duration %= TRIG_DURATION_COUNT; - break; - - case STOP_THRESHOLD: - change_threshold(&global_settings.rec_stop_thres, 1); - break; - - case STOP_POSTREC: - global_settings.rec_stop_postrec ++; - global_settings.rec_stop_postrec %= TRIG_DURATION_COUNT; - break; - - case STOP_GAP: - global_settings.rec_stop_gap ++; - global_settings.rec_stop_gap %= TRIG_DURATION_COUNT; - break; - - case TRIG_OPTION_COUNT: - // avoid compiler warnings - break; - } peak_meter_trigger(global_settings.rec_trigger_mode!=TRIG_OFF); settings_apply_trigger(); - say_value = true; + done = true; + break; + case ACTION_STD_OK: + done = true; break; - case ACTION_SETTINGS_DEC: - switch (selected) { - case TRIGGER_MODE: - global_settings.rec_trigger_mode+=TRIGGER_MODE_COUNT-1; - global_settings.rec_trigger_mode %= TRIGGER_MODE_COUNT; - break; - - case TRIGGER_TYPE: - global_settings.rec_trigger_type+=TRIGGER_TYPE_COUNT-1; - global_settings.rec_trigger_type %= TRIGGER_TYPE_COUNT; - break; - - case PRERECORD_TIME: - global_settings.rec_prerecord_time += PRERECORD_TIMES_COUNT - 1; - global_settings.rec_prerecord_time %= PRERECORD_TIMES_COUNT; - break; - - case START_THRESHOLD: - change_threshold(&global_settings.rec_start_thres, -1); - break; - - case START_DURATION: - global_settings.rec_start_duration += TRIG_DURATION_COUNT-1; - global_settings.rec_start_duration %= TRIG_DURATION_COUNT; - break; - - case STOP_THRESHOLD: - change_threshold(&global_settings.rec_stop_thres, -1); - break; - - case STOP_POSTREC: - global_settings.rec_stop_postrec += - TRIG_DURATION_COUNT - 1; - global_settings.rec_stop_postrec %= - TRIG_DURATION_COUNT; - break; - - case STOP_GAP: - global_settings.rec_stop_gap += - TRIG_DURATION_COUNT - 1; - global_settings.rec_stop_gap %= TRIG_DURATION_COUNT; - break; - - case TRIG_OPTION_COUNT: - // avoid compiler warnings - break; - } - peak_meter_trigger(global_settings.rec_trigger_mode!=TRIG_OFF); - settings_apply_trigger(); - say_value = true; + case ACTION_SETTINGS_DECREPEAT: + option_select_next_val(settings[i/2], true, false); + trigger_speak_item(settings[i/2], false); + changed = true; break; - - case ACTION_REC_F2: - peak_meter_trigger(true); + case ACTION_SETTINGS_INC: + case ACTION_SETTINGS_INCREPEAT: + option_select_next_val(settings[i/2], false, false); + trigger_speak_item(settings[i/2], false); + changed = true; break; - - case SYS_USB_CONNECTED: - if(default_event_handler(button) == SYS_USB_CONNECTED) { - retval = true; - exit_request = true; - } + case ACTION_STD_PREV: + case ACTION_STD_PREVREPEAT: + i -= 2; + if (i<0) + i = (TRIG_OPTION_COUNT*2) - 2; + gui_synclist_select_item(&lists, i); + i = gui_synclist_get_sel_pos(&lists); + trigger_speak_item(settings[i/2], true); + changed = true; + break; + case ACTION_STD_NEXT: + case ACTION_STD_NEXTREPEAT: + gui_synclist_select_item(&lists, (i+2) % (TRIG_OPTION_COUNT*2)); + i = gui_synclist_get_sel_pos(&lists); + trigger_speak_item(settings[i/2], true); + changed = true; break; } } - peak_meter_trigger(false); - FOR_NB_SCREENS(i) - { - screens[i].setfont(FONT_UI); - screens[i].setmargins(old_x_margin[i], old_y_margin[i]); - } - return retval; + settings_save(); + return 0; } - MENUITEM_FUNCTION(rectrigger_item, 0, ID2P(LANG_RECORD_TRIGGER), - (int(*)(void))rectrigger, NULL, NULL, Icon_Menu_setting); - - - + rectrigger, NULL, NULL, Icon_Menu_setting); diff --git a/apps/recorder/peakmeter.c b/apps/recorder/peakmeter.c index 3e85fd5509..9014e5c351 100644 --- a/apps/recorder/peakmeter.c +++ b/apps/recorder/peakmeter.c @@ -1318,7 +1318,8 @@ void peak_meter_draw_trig(int xpos[], int ypos[], int trig_width[], int nb_scree } #endif -int peak_meter_draw_get_btn(int x, int y[], int height, int nb_screens) +int peak_meter_draw_get_btn(int action_context, int x, int y[], + int height, int nb_screens) { int button = BUTTON_NONE; long next_refresh = current_tick; @@ -1337,7 +1338,7 @@ int peak_meter_draw_get_btn(int x, int y[], int height, int nb_screens) bool dopeek = true; while (TIME_BEFORE(current_tick, next_big_refresh)) { - button = get_action(CONTEXT_RECSCREEN, TIMEOUT_NOBLOCK); + button = get_action(action_context, TIMEOUT_NOBLOCK); if (button != BUTTON_NONE) { break; } diff --git a/apps/recorder/peakmeter.h b/apps/recorder/peakmeter.h index 9aa32905c1..2d63aefa75 100644 --- a/apps/recorder/peakmeter.h +++ b/apps/recorder/peakmeter.h @@ -33,7 +33,8 @@ extern void pm_activate_clipcount(bool active); extern bool peak_meter_enabled; extern void peak_meter_playback(bool playback); -extern int peak_meter_draw_get_btn(int x, int y[], int height, int nb_screens); +extern int peak_meter_draw_get_btn(int action_context, int x, int y[], + int height, int nb_screens); extern void peak_meter_set_clip_hold(int time); extern void peak_meter_peek(void); extern void peak_meter_init_range( bool dbfs, int range_min, int range_max); diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index c2b2360df1..28b3a44b3a 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -121,37 +121,28 @@ static unsigned long rec_sizesplit_bytes(void) { return rec_size_bytes[global_settings.rec_sizesplit]; } -/* - * Time strings used for the trigger durations. - * Keep synchronous to trigger_times in settings_apply_trigger - */ -const struct opt_items trig_durations[TRIG_DURATION_COUNT] = -{ -#define TS(x) { (unsigned char *)(#x "s"), TALK_ID(x, UNIT_SEC) } -#define TM(x) { (unsigned char *)(#x "min"), TALK_ID(x, UNIT_MIN) } - TS(0), TS(1), TS(2), TS(5), - TS(10), TS(15), TS(20), TS(25), TS(30), - TM(1), TM(2), TM(5), TM(10) -#undef TS -#undef TM -}; void settings_apply_trigger(void) { - /* Keep synchronous to trig_durations and trig_durations_conf*/ - static const long trigger_times[TRIG_DURATION_COUNT] = { - 0, HZ, 2*HZ, 5*HZ, - 10*HZ, 15*HZ, 20*HZ, 25*HZ, 30*HZ, - 60*HZ, 2*60*HZ, 5*60*HZ, 10*60*HZ - }; + int start_thres, stop_thres; + if (global_settings.peak_meter_dbfs) + { + start_thres = global_settings.rec_start_thres_db - 1; + stop_thres = global_settings.rec_stop_thres_db - 1; + } + else + { + start_thres = global_settings.rec_start_thres_linear; + stop_thres = global_settings.rec_stop_thres_linear; + } peak_meter_define_trigger( - global_settings.rec_start_thres, - trigger_times[global_settings.rec_start_duration], - MIN(trigger_times[global_settings.rec_start_duration] / 2, 2*HZ), - global_settings.rec_stop_thres, - trigger_times[global_settings.rec_stop_postrec], - trigger_times[global_settings.rec_stop_gap] + start_thres, + global_settings.rec_start_duration*HZ, + MIN(global_settings.rec_start_duration*HZ / 2, 2*HZ), + stop_thres, + global_settings.rec_stop_postrec*HZ, + global_settings.rec_stop_gap*HZ ); } /* recording screen status flags */ @@ -784,12 +775,12 @@ static void trigger_listener(int trigger_status) else { if((audio_status() & AUDIO_STATUS_PAUSE) && - (global_settings.rec_trigger_type == 1)) + (global_settings.rec_trigger_type == TRIG_TYPE_PAUSE)) { rec_command(RECORDING_CMD_RESUME); } /* New file on trig start*/ - else if (global_settings.rec_trigger_type != 2) + else if (global_settings.rec_trigger_type != TRIG_TYPE_NEW_FILE) { rec_command(RECORDING_CMD_START_NEWFILE); /* tell recording_screen to reset the time */ @@ -804,15 +795,15 @@ static void trigger_listener(int trigger_status) { switch(global_settings.rec_trigger_type) { - case 0: /* Stop */ + case TRIG_TYPE_STOP: /* Stop */ rec_command(RECORDING_CMD_STOP); break; - case 1: /* Pause */ + case TRIG_TYPE_PAUSE: /* Pause */ rec_command(RECORDING_CMD_PAUSE); break; - case 2: /* New file on trig stop*/ + case TRIG_TYPE_NEW_FILE: /* New file on trig stop*/ rec_command(RECORDING_CMD_START_NEWFILE); /* tell recording_screen to reset the time */ last_seconds = 0; @@ -1036,7 +1027,8 @@ bool recording_screen(bool no_source) #endif /* CONFIG_LED */ /* Wait for a button a while (HZ/10) drawing the peak meter */ - button = peak_meter_draw_get_btn(pm_x, pm_y, h * PM_HEIGHT, + button = peak_meter_draw_get_btn(CONTEXT_RECSCREEN, + pm_x, pm_y, h * PM_HEIGHT, screen_update); if (last_audio_stat != audio_stat) diff --git a/apps/settings.h b/apps/settings.h index 9a9169a74f..320e2b0517 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -90,12 +90,19 @@ struct opt_items { #define BOOKMARK_RECENT_ONLY_YES 3 #define BOOKMARK_RECENT_ONLY_ASK 4 -#define TRIG_MODE_OFF 0 -#define TRIG_MODE_NOREARM 1 -#define TRIG_MODE_REARM 2 +enum +{ + TRIG_MODE_OFF = 0, + TRIG_MODE_NOREARM, + TRIG_MODE_REARM +}; -#define TRIG_DURATION_COUNT 13 -extern const struct opt_items trig_durations[TRIG_DURATION_COUNT]; +enum +{ + TRIG_TYPE_STOP = 0, + TRIG_TYPE_PAUSE, + TRIG_TYPE_NEW_FILE +}; #define CROSSFADE_ENABLE_SHUFFLE 1 #define CROSSFADE_ENABLE_TRACKSKIP 2 @@ -354,10 +361,12 @@ struct user_settings 2 = main and remote lcd 3 = remote lcd */ - int rec_start_thres; /* negative: db, positive: % range -87 .. 100 */ + int rec_start_thres_db; + int rec_start_thres_linear; int rec_start_duration; /* index of trig_durations */ - int rec_stop_thres; /* negative: db, positive: % */ - int rec_stop_postrec; /* negative: db, positive: % range -87 .. 100 */ + int rec_stop_thres_db; + int rec_stop_thres_linear; + int rec_stop_postrec; int rec_stop_gap; /* index of trig_durations */ int rec_trigger_mode; /* see TRIG_MODE_XXX constants */ int rec_trigger_type; /* what to do when trigger released */ diff --git a/apps/settings_list.c b/apps/settings_list.c index 17ca714e76..8576c5b926 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -207,10 +207,6 @@ static const char graphic_numeric[] = "graphic,numeric"; #define DEFAULT_BACKDROP "cabbiev2" #ifdef HAVE_RECORDING -/* keep synchronous to trig_durations and - trigger_times in settings_apply_trigger */ -static const char trig_durations_conf [] = - "0s,1s,2s,5s,10s,15s,20s,25s,30s,1min,2min,5min,10min"; /* these should be in the config.h files */ #if CONFIG_CODEC == MAS3587F # define DEFAULT_REC_MIC_GAIN 8 @@ -918,24 +914,35 @@ const struct settings_list settings[] = { /** Encoder settings end **/ #endif /* CONFIG_CODEC == SWCODEC */ /* values for the trigger */ - {F_T_INT|F_RECSETTING,&global_settings.rec_start_thres, - LANG_RECORD_START_THRESHOLD, INT(-35), - "trigger start threshold",NULL,UNUSED}, - {F_T_INT|F_RECSETTING,&global_settings.rec_stop_thres, - LANG_RECORD_STOP_THRESHOLD,INT(-45), - "trigger stop threshold",NULL,UNUSED}, - {F_T_INT|F_RECSETTING,&global_settings.rec_start_duration, - LANG_MIN_DURATION,INT(0), - "trigger start duration",trig_durations_conf,UNUSED}, - {F_T_INT|F_RECSETTING,&global_settings.rec_stop_postrec, - LANG_MIN_DURATION,INT(2), - "trigger stop postrec",trig_durations_conf,UNUSED}, - {F_T_INT|F_RECSETTING,&global_settings.rec_stop_gap, - LANG_RECORD_STOP_GAP,INT(1), - "trigger min gap",trig_durations_conf,UNUSED}, - {F_T_INT|F_RECSETTING,&global_settings.rec_trigger_mode, - LANG_RECORD_TRIGGER,INT(0), - "trigger mode","off,once,repeat",UNUSED}, + INT_SETTING(F_RECSETTING, rec_start_thres_db, LANG_RECORD_START_THRESHOLD, -35, + "trigger start threshold dB", UNIT_DB, VOLUME_MIN/10, 0, -1, NULL, NULL, NULL), + INT_SETTING(F_RECSETTING, rec_start_thres_linear, LANG_RECORD_START_THRESHOLD, 5, + "trigger start threshold linear", UNIT_PERCENT, 0, 100, 1, NULL, NULL, NULL), + INT_SETTING(F_RECSETTING, rec_stop_thres_db, LANG_RECORD_STOP_THRESHOLD, -45, + "trigger stop threshold dB", UNIT_DB, VOLUME_MIN/10, 0, -1, NULL, NULL, NULL), + INT_SETTING(F_RECSETTING, rec_stop_thres_linear, LANG_RECORD_STOP_THRESHOLD, 10, + "trigger stop threshold linear", UNIT_PERCENT, 0, 100, 1, NULL, NULL, NULL), + TABLE_SETTING(F_RECSETTING, rec_start_duration, LANG_MIN_DURATION, 0, + "trigger start duration", + "0s,1s,2s,5s,10s,15s,20s,25s,30s,1min,2min,5min,10min", + UNIT_SEC, NULL, NULL, NULL, 13, + 0,1,2,5,10,15,20,25,30,60,120,300,600), + TABLE_SETTING(F_RECSETTING, rec_stop_postrec, LANG_MIN_DURATION, 0, + "trigger stop duration", + "0s,1s,2s,5s,10s,15s,20s,25s,30s,1min,2min,5min,10min", + UNIT_SEC, NULL, NULL, NULL, 13, + 0,1,2,5,10,15,20,25,30,60,120,300,600), + TABLE_SETTING(F_RECSETTING, rec_stop_gap, LANG_RECORD_STOP_GAP, 1, + "trigger min gap", + "0s,1s,2s,5s,10s,15s,20s,25s,30s,1min,2min,5min,10min", + UNIT_SEC, NULL, NULL, NULL, 13, + 0,1,2,5,10,15,20,25,30,60,120,300,600), + CHOICE_SETTING(F_RECSETTING, rec_trigger_mode, LANG_RECORD_TRIGGER, TRIG_MODE_OFF, + "trigger mode","off,once,repeat", NULL ,3, + ID2P(LANG_OFF), ID2P(LANG_RECORD_TRIG_NOREARM), ID2P(LANG_REPEAT)), + CHOICE_SETTING(F_RECSETTING, rec_trigger_type, LANG_RECORD_TRIGGER_TYPE, TRIG_TYPE_STOP, + "trigger mode","off,once,repeat", NULL ,3, + ID2P(LANG_RECORD_TRIGGER_STOP), ID2P(LANG_PAUSE), ID2P(LANG_RECORD_TRIGGER_NEWFILESTP)), #endif /* HAVE_RECORDING */ #ifdef HAVE_SPDIF_POWER @@ -1192,14 +1199,6 @@ const struct settings_list settings[] = { OFFON_SETTING(0, audioscrobbler, LANG_AUDIOSCROBBLER, false, "Last.fm Logging", NULL), - -#ifdef HAVE_RECORDING - {F_T_INT|F_RECSETTING,&global_settings.rec_trigger_type, - LANG_RECORD_TRIGGER_TYPE, INT(0), - "trigger type","stop,pause,nf stp",UNUSED}, -#endif - - /** settings not in the old config blocks **/ #if CONFIG_TUNER FILENAME_SETTING(0, fmr_file, "fmr", "", FMPRESET_PATH "/", ".fmr", MAX_FILENAME+1), diff --git a/apps/sound_menu.h b/apps/sound_menu.h index 2bf1016e4c..5f4cbb8afd 100644 --- a/apps/sound_menu.h +++ b/apps/sound_menu.h @@ -22,6 +22,6 @@ #include "menu.h" bool recording_menu(bool no_source); -bool rectrigger(void); +int rectrigger(void); #endif