From 8f659ae8d3845b40ff93ebfa3692f7b2302e6c7e Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Sun, 20 May 2007 20:26:36 +0000 Subject: Use bitmasks to define which inputs are available. Makes it easier to remove old assumptions of which are available. Inspired by e200 being unique in having FM Radio and Mic but no Line. Doesn't remove the assumption that Mic is available or that one of Mic and/or Line is available just to avoid excessive #ifdef'ing until needed. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13448 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/statusbar.c | 4 +- apps/menus/recording_menu.c | 30 +++++++-------- apps/recorder/radio.c | 8 ++-- apps/recorder/recording.c | 89 ++++++++++++++++++++------------------------- apps/settings_list.c | 14 +++---- 5 files changed, 65 insertions(+), 80 deletions(-) (limited to 'apps') diff --git a/apps/gui/statusbar.c b/apps/gui/statusbar.c index e082063a6f..9eb766f054 100644 --- a/apps/gui/statusbar.c +++ b/apps/gui/statusbar.c @@ -680,7 +680,7 @@ static void gui_statusbar_write_samplerate_info(struct screen * display) #ifdef SIMULATOR samprk = 44100; #else -#ifdef HAVE_SPDIF_IN +#ifdef HAVE_SPDIF_REC if (global_settings.rec_source == AUDIO_SRC_SPDIF) /* Use rate in use, not current measured rate if it changed */ samprk = pcm_rec_sample_rate(); @@ -731,7 +731,7 @@ static void gui_statusbar_icon_recording_info(struct screen * display) gui_statusbar_write_samplerate_info(display); #else /* !SWCODEC */ /* hwcodec targets have sysfont characters */ -#ifdef HAVE_SPDIF_IN +#ifdef HAVE_SPDIF_REC if (global_settings.rec_source == AUDIO_SRC_SPDIF) { /* Can't measure S/PDIF sample rate on Archos/Sim yet */ diff --git a/apps/menus/recording_menu.c b/apps/menus/recording_menu.c index 1bc84e90d2..62af2f94fe 100644 --- a/apps/menus/recording_menu.c +++ b/apps/menus/recording_menu.c @@ -67,21 +67,21 @@ int recmenu_callback(int action,const struct menu_item_ex *this_item); static int recsource_func(void) { - int n_opts = AUDIO_NUM_SOURCES; + int n_opts = REC_NUM_SOURCES; static const struct opt_items names[AUDIO_NUM_SOURCES] = { - [AUDIO_SRC_MIC] = { STR(LANG_RECORDING_SRC_MIC) }, - [AUDIO_SRC_LINEIN] = { STR(LANG_RECORDING_SRC_LINE) }, -#ifdef HAVE_SPDIF_IN - [AUDIO_SRC_SPDIF] = { STR(LANG_RECORDING_SRC_DIGITAL) }, -#endif -#ifdef HAVE_FMRADIO_IN - [AUDIO_SRC_FMRADIO] = { STR(LANG_FM_RADIO) } -#endif + HAVE_MIC_REC_([AUDIO_SRC_MIC] + = { STR(LANG_RECORDING_SRC_MIC) },) + HAVE_LINE_REC_([AUDIO_SRC_LINEIN] + = { STR(LANG_RECORDING_SRC_LINE) },) + HAVE_SPDIF_REC_([AUDIO_SRC_SPDIF] + = { STR(LANG_RECORDING_SRC_DIGITAL) },) + HAVE_FMRADIO_REC_([AUDIO_SRC_FMRADIO] + = { STR(LANG_FM_RADIO) },) }; /* caveat: assumes it's the last item! */ -#ifdef HAVE_FMRADIO_IN +#ifdef HAVE_FMRADIO_REC if (!radio_hardware_present()) n_opts--; #endif @@ -145,15 +145,15 @@ static int recfrequency_func(void) int rec_frequency; bool ret; -#ifdef HAVE_SPDIF_IN - if (global_settings.rec_source == AUDIO_SRC_SPDIF) +#ifdef HAVE_SPDIF_REC + if (global_settings.rec_source == REC_SRC_SPDIF) { /* Inform user that frequency follows the source's frequency */ opts[0].string = ID2P(LANG_SOURCE_FREQUENCY); opts[0].voice_id = LANG_SOURCE_FREQUENCY; n_opts = 1; rec_frequency = 0; -} + } else #endif { @@ -189,9 +189,7 @@ static int recfrequency_func(void) &rec_frequency, INT, opts, n_opts, NULL ); if (!ret -#ifdef HAVE_SPDIF_IN - && global_settings.rec_source != AUDIO_SRC_SPDIF -#endif + HAVE_SPDIF_REC_( && global_settings.rec_source != REC_SRC_SPDIF) ) { /* Translate back to full index */ diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c index ae534aca61..79febc9039 100644 --- a/apps/recorder/radio.c +++ b/apps/recorder/radio.c @@ -1429,7 +1429,7 @@ static int scan_presets(void) #ifdef HAVE_RECORDING -#if defined(HAVE_FMRADIO_IN) && CONFIG_CODEC == SWCODEC +#if defined(HAVE_FMRADIO_REC) && CONFIG_CODEC == SWCODEC #define FM_RECORDING_SCREEN static int fm_recording_screen(void) { @@ -1450,9 +1450,9 @@ static int fm_recording_screen(void) return ret; } -#endif /* defined(HAVE_FMRADIO_IN) && CONFIG_CODEC == SWCODEC */ +#endif /* defined(HAVE_FMRADIO_REC) && CONFIG_CODEC == SWCODEC */ -#if defined(HAVE_FMRADIO_IN) || CONFIG_CODEC != SWCODEC +#if defined(HAVE_FMRADIO_REC) || CONFIG_CODEC != SWCODEC #define FM_RECORDING_SETTINGS static int fm_recording_settings(void) { @@ -1471,7 +1471,7 @@ static int fm_recording_settings(void) return ret; } -#endif /* defined(HAVE_FMRADIO_IN) || CONFIG_CODEC != SWCODEC */ +#endif /* defined(HAVE_FMRADIO_REC) || CONFIG_CODEC != SWCODEC */ #endif /* HAVE_RECORDING */ #ifdef FM_RECORDING_SCREEN diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index 0981cb8811..0323ae12ff 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -183,7 +183,7 @@ static void set_gain(void) } else { - /* AUDIO_SRC_LINEIN, AUDIO_SRC_SPDIF, AUDIO_SRC_FMRADIO */ + /* AUDIO_SRC_LINEIN, AUDIO_SRC_FMRADIO, AUDIO_SRC_SPDIF */ audio_set_recording_gain(global_settings.rec_left_gain, global_settings.rec_right_gain, AUDIO_GAIN_LINEIN); @@ -235,13 +235,12 @@ static bool agc_gain_is_max(bool left, bool right) switch (global_settings.rec_source) { - case AUDIO_SRC_LINEIN: -#ifdef HAVE_FMRADIO_IN - case AUDIO_SRC_FMRADIO: -#endif + HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:) + HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:) gain_current_l = global_settings.rec_left_gain; gain_current_r = global_settings.rec_right_gain; break; + case AUDIO_SRC_MIC: default: gain_current_l = global_settings.rec_mic_gain; gain_current_r = global_settings.rec_mic_gain; @@ -257,14 +256,12 @@ static void change_recording_gain(bool increment, bool left, bool right) switch (global_settings.rec_source) { - case AUDIO_SRC_LINEIN: -#ifdef HAVE_FMRADIO_IN - case AUDIO_SRC_FMRADIO: -#endif - if(left) global_settings.rec_left_gain += factor; + HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:) + HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:) + if (left) global_settings.rec_left_gain += factor; if (right) global_settings.rec_right_gain += factor; break; - default: + case AUDIO_SRC_MIC: global_settings.rec_mic_gain += factor; } } @@ -469,31 +466,27 @@ static void adjust_cursor(void) #ifdef HAVE_AGC switch(global_settings.rec_source) { - case AUDIO_SRC_MIC: + case REC_SRC_MIC: if(cursor == 2) cursor = 4; else if(cursor == 3) cursor = 1; - case AUDIO_SRC_LINEIN: -#ifdef HAVE_FMRADIO_IN - case AUDIO_SRC_FMRADIO: -#endif + HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:) + HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:) max_cursor = 5; break; default: max_cursor = 0; break; } -#else +#else /* !HAVE_AGC */ switch(global_settings.rec_source) { case AUDIO_SRC_MIC: max_cursor = 1; break; - case AUDIO_SRC_LINEIN: -#ifdef HAVE_FMRADIO_IN - case AUDIO_SRC_FMRADIO: -#endif + HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:) + HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:) max_cursor = 3; break; default: @@ -556,7 +549,7 @@ int rec_create_directory(void) #if CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) -# ifdef HAVE_SPDIF_IN +# ifdef HAVE_SPDIF_REC # ifdef HAVE_ADJUSTABLE_CPU_FREQ static void rec_boost(bool state) { @@ -588,7 +581,7 @@ void rec_set_source(int source, unsigned flags) /** Do power up/down of associated device(s) **/ /** SPDIF **/ -#ifdef HAVE_SPDIF_IN +#ifdef HAVE_SPDIF_REC /* Always boost for SPDIF */ rec_boost(source == AUDIO_SRC_SPDIF); #endif /* HAVE_SPDIF_IN */ @@ -766,7 +759,7 @@ bool recording_screen(bool no_source) int warning_counter = 0; #define WARNING_PERIOD 7 #endif -#ifdef HAVE_FMRADIO_IN +#ifdef HAVE_FMRADIO_REC /* Radio is left on if: * 1) Is was on at the start and the initial source is FM Radio * 2) 1) and the source was never changed to something else @@ -849,7 +842,7 @@ bool recording_screen(bool no_source) agc_preset = global_settings.rec_agc_preset_line; agc_maxgain = global_settings.rec_agc_maxgain_line; } -#endif +#endif /* HAVE_AGC */ FOR_NB_SCREENS(i) { @@ -1117,7 +1110,7 @@ bool recording_screen(bool no_source) global_settings.rec_agc_maxgain_line = agc_maxgain; } break; -#endif +#endif /* HAVE_AGC */ } set_gain(); update_countdown = 1; /* Update immediately */ @@ -1185,7 +1178,7 @@ bool recording_screen(bool no_source) global_settings.rec_agc_maxgain_line = agc_maxgain; } break; -#endif +#endif /* HAVE_AGC */ } set_gain(); update_countdown = 1; /* Update immediately */ @@ -1194,7 +1187,7 @@ bool recording_screen(bool no_source) case ACTION_STD_MENU: if(audio_stat != AUDIO_STATUS_RECORD) { -#ifdef HAVE_FMRADIO_IN +#ifdef HAVE_FMRADIO_REC const int prev_rec_source = global_settings.rec_source; #endif @@ -1206,13 +1199,13 @@ bool recording_screen(bool no_source) { done = true; been_in_usb_mode = true; -#ifdef HAVE_FMRADIO_IN +#ifdef HAVE_FMRADIO_REC radio_status = FMRADIO_OFF; #endif } else { -#ifdef HAVE_FMRADIO_IN +#ifdef HAVE_FMRADIO_REC /* If input changes away from FM Radio, radio will remain off when recording screen closes. */ if (global_settings.rec_source != prev_rec_source @@ -1306,7 +1299,7 @@ bool recording_screen(bool no_source) default_event_handler(SYS_USB_CONNECTED); done = true; been_in_usb_mode = true; -#ifdef HAVE_FMRADIO_IN +#ifdef HAVE_FMRADIO_REC radio_status = FMRADIO_OFF; #endif } @@ -1493,11 +1486,10 @@ bool recording_screen(bool no_source) PM_HEIGHT + 3, buf); } } - else if(global_settings.rec_source == AUDIO_SRC_LINEIN -#ifdef HAVE_FMRADIO_IN - || global_settings.rec_source == AUDIO_SRC_FMRADIO -#endif - ) + else if(0 + HAVE_LINE_REC_( || global_settings.rec_source == AUDIO_SRC_LINEIN) + HAVE_FMRADIO_REC_( || global_settings.rec_source == AUDIO_SRC_FMRADIO) + ) { /* Draw LINE or FMRADIO recording gain */ snprintf(buf, sizeof(buf), "%s:%s", @@ -1541,16 +1533,14 @@ bool recording_screen(bool no_source) { switch (global_settings.rec_source) { - case AUDIO_SRC_LINEIN: -#ifdef HAVE_FMRADIO_IN - case AUDIO_SRC_FMRADIO: -#endif + HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:) + HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:) line[i] = 5; break; case AUDIO_SRC_MIC: line[i] = 4; break; -#ifdef HAVE_SPDIF_IN +#ifdef HAVE_SPDIF_REC case AUDIO_SRC_SPDIF: line[i] = 3; break; @@ -1615,12 +1605,11 @@ bool recording_screen(bool no_source) screens[i].puts_style_offset(0, filename_offset[i] + PM_HEIGHT + line[i], buf, STYLE_INVERT,0); } - else if (global_settings.rec_source == AUDIO_SRC_MIC - || global_settings.rec_source == AUDIO_SRC_LINEIN -#ifdef HAVE_FMRADIO_IN - || global_settings.rec_source == AUDIO_SRC_FMRADIO -#endif - ) + else if ( + global_settings.rec_source == AUDIO_SRC_MIC + HAVE_LINE_REC_(|| global_settings.rec_source == AUDIO_SRC_LINEIN) + HAVE_FMRADIO_REC_(|| global_settings.rec_source == AUDIO_SRC_FMRADIO) + ) { for(i = 0; i < screen_update; i++) { if (display_agc[i]) { @@ -1629,7 +1618,7 @@ bool recording_screen(bool no_source) } } } - + if (global_settings.rec_source == AUDIO_SRC_MIC) { if(agc_maxgain < (global_settings.rec_mic_gain)) @@ -1642,7 +1631,7 @@ bool recording_screen(bool no_source) if(agc_maxgain < (global_settings.rec_right_gain)) change_recording_gain(false, false, true); } -#else +#else /* !HAVE_AGC */ } #endif /* HAVE_AGC */ @@ -1758,7 +1747,7 @@ bool recording_screen(bool no_source) audio_stop_recording(); audio_close_recording(); -#ifdef HAVE_FMRADIO_IN +#ifdef HAVE_FMRADIO_REC if (radio_status != FMRADIO_OFF) /* Restore radio playback - radio_status should be unchanged if started through fm radio screen (barring usb connect) */ diff --git a/apps/settings_list.c b/apps/settings_list.c index d39779607d..c6adfe884a 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -747,14 +747,12 @@ const struct settings_list settings[] = { "rec split method", "Time,Filesize", NULL, 2, ID2P(LANG_REC_TIME), ID2P(LANG_REC_SIZE)), {F_T_INT,&global_settings.rec_source,LANG_RECORDING_SOURCE,INT(0), - "rec source","mic,line" -#ifdef HAVE_SPDIF_IN - ",spdif" -#endif -#ifdef HAVE_FMRADIO_IN - ",fmradio" -#endif - ,UNUSED}, + "rec source", + &HAVE_MIC_REC_(",mic") + HAVE_LINE_REC_(",line") + HAVE_SPDIF_REC_(",spdif") + HAVE_FMRADIO_REC_(",fmradio")[1] + ,UNUSED}, INT_SETTING(0, rec_prerecord_time, LANG_RECORD_PRERECORD_TIME, 0, "prerecording time", UNIT_SEC, 0, 30, 1, rectime_formatter, rectime_getlang, NULL), -- cgit