dev builds
themes manual
device status forums
mailing lists
IRC bugs
dev guide

Rockbox mail archive

Subject: menu/settings merging take 2!

menu/settings merging take 2!

From: Jonathan Gordon <>
Date: Mon, 4 Sep 2006 22:29:15 +1000

Ive started this once again and I tihnk i may have got it right this time.
What I hope for this to eventually do is make adding a setting to the
menus/global_settings as simple as possible. A side effect of this is
the removal of the config block (all settings are written either to
config.cfg or data.dat).

here is what the settings.h file is starting to look like.


#define GS(a) &global_settings.a

#define _INT(...) (int[]){__VA_ARGS__}
#define _STR(...) (*char[]){__VA_ARGS__}
#define SOUND_ITEM(var,name,setting) {F_T_INT|F_T_SOUND, GS(var), 0,
name, 1,_INT(setting), NULL }
#define BOOL_ITEM(var,name,default) {F_T_BOOL, GS(var), default, name,
#define INT_ITEM(var,name,default,min,max,step,unit) {F_T_INT,
GS(var), default, name, 3,_INT(min,max,step), _INT(unit) }
#define SYSTEM_ITEM(type,var,default) {type|F_SYSTEMSETTING, GS(var),
default, #var, 0,NULL, NUL }
union storage_type {
    int int_;
    unsigned int uint_;
    bool bool_;
    char *charptr;
    unsigned char *ucharptr;
/* the variable type for the setting */
#define F_T_INT 1
#define F_T_UINT 2
#define F_T_BOOL 3
#define F_T_CHARPTR 4
#define F_T_UCHARPTR 5

/* we can go up to 7 types, 3 bits should be enough */
#define F_T_MASK 0x7 /* NOTE mask does not include the sign flag bit */
#define F_T_SOUND 0x8 /* this variable uses the set_sound stuff,
| with one of the above types */
                            /* values[0] = setting type */
#define F_T_CHOICE 0x10 /* this variable is a "choice" type, \
                               if this is not set then values[0] =
min, values[1] = max, values[2] = step \
                               talk_id[0] = talk unit
#define F_LANG_STRING 0x20 /* this variable uses *strings in the
union for the values, donot try to xlate \
                               unless talk_id is NULL it will try to
talk the corresponding value there \
                               talk_id is only needed to be filled if
this is set */

#define F_SYSTEMSETTING 0x800 /* if set it will be saved in data.dat
not config.cfg */

struct settings_list {
    int flags; /* ____ ____ ____ ____ ____ S___ __LC STTT */
    union storage_type *variable; /* the variable in global_settings,
use GS() macro for this */
    union storage_type default_val;
    int cfg_name; /* lang_id of this variable in the
.cfg file */
    int nb_values; /* # of values, ignored unless
F_T_CHOICE is set */
    union {
        int *values; /* If F_T_CHOICE is not set and
        char *strings[]; /* then values[0] = min,
[1]=max, [2]=step. */
    int *talk_id;

    /* If F_T_SOUND is set then default_val, values and nb_values are
ignored */

const struct settings_list settings[] = {
    /* sound */
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
    {F_T_INT, GS(channel_config), 0, LANG_CHANNEL,

    /* playback */


this array will contain every setting in global_settings. Im using a
few macros because I'm incredibly lazy and i tinhk it makes the code
much easier to read, hopefully everyone agrees :D

I intend to use this list for both the setting load/saving and the
menus, so everything that is needed for an setting will be in this
list (except I havnt worked out how to do callbacks yet.. but I havnt
started coding anything so they may not be needed).

As you can see, everything uses the lang_id instead of a char*, so the
menus and settings will get the translated string from the id, and the
load/saving of the cfg files will use the english string for that id
as the name.

I cant remember how much of the last try i sent to the ml, but each
(sub)menu will be an array of menu items, an item either being a
function, sub-menu or setting to be set. So to add a setting to a menu
all that will be needed is to add something like
SETTING_MENU_ITEM(volume), the menu will then search the settings list
untill it finds the item with the same pointer to
global_settings.volume and use the information there to load the
correct settings widget.

So, in the end, to add an item to global settings, it would be added
to the global_settings struct, to the settings list (above) and maybe
to a menu. simple? :)

any thoughts? comments? needs more explanation?
Received on 2006-09-04

Page was last modified "Jan 10 2012" The Rockbox Crew