forked from len0rd/rockbox
Changed .eq file format to simple 'setting: value' model.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2478 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
175747d0ec
commit
0e6088fc9c
6 changed files with 186 additions and 167 deletions
257
apps/settings.c
257
apps/settings.c
|
@ -39,6 +39,8 @@
|
|||
#include "status.h"
|
||||
#include "atoi.h"
|
||||
#include "screens.h"
|
||||
#include "ctype.h"
|
||||
#include "file.h"
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
#include "icons.h"
|
||||
#include "font.h"
|
||||
|
@ -459,161 +461,120 @@ void settings_load(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Loads a .eq file
|
||||
*/
|
||||
static int read_line(int fd, char* buffer, int buffer_size)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (count < buffer_size)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
if (1 != read(fd, &c, 1))
|
||||
break;
|
||||
|
||||
if ( c == '\n' )
|
||||
break;
|
||||
|
||||
if ( c == '\r' )
|
||||
continue;
|
||||
|
||||
buffer[count++] = c;
|
||||
}
|
||||
|
||||
if ( count < buffer_size )
|
||||
buffer[count] = 0;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/* parse a line from a configuration file. the line format is:
|
||||
|
||||
setting name: setting value
|
||||
|
||||
Any whitespace before setting name or value (after ':') is ignored.
|
||||
A # as first non-whitespace character discards the whole line.
|
||||
Function sets pointers to null-terminated setting name and value.
|
||||
Returns false if no valid config entry was found.
|
||||
*/
|
||||
|
||||
static bool settings_parseline(char* line, char** name, char** value)
|
||||
{
|
||||
char* ptr;
|
||||
|
||||
while ( isspace(*line) )
|
||||
line++;
|
||||
|
||||
if ( *line == '#' )
|
||||
return false;
|
||||
|
||||
ptr = strchr(line, ':');
|
||||
if ( !ptr )
|
||||
return false;
|
||||
|
||||
*name = line;
|
||||
*ptr = 0;
|
||||
ptr++;
|
||||
while (isspace(*ptr))
|
||||
ptr++;
|
||||
*value = ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void set_eq_sound(char* value, int type, int* setting)
|
||||
{
|
||||
int num = atoi(value);
|
||||
|
||||
num = mpeg_phys2val(type, num);
|
||||
|
||||
if ((num > mpeg_sound_max(type)) ||
|
||||
(num < mpeg_sound_min(type)))
|
||||
{
|
||||
num = mpeg_sound_default(type);
|
||||
}
|
||||
|
||||
*setting = num;
|
||||
mpeg_sound_set(type, num);
|
||||
}
|
||||
|
||||
bool settings_load_eq(char* file)
|
||||
{
|
||||
char buffer[512];
|
||||
char buf_set[16];
|
||||
char buf_disp[16];
|
||||
char buf_val[8];
|
||||
bool syntax_error = false;
|
||||
int fd;
|
||||
int i;
|
||||
int d = 0;
|
||||
int vtype = 0;
|
||||
int line = 0;
|
||||
char line[128];
|
||||
|
||||
|
||||
lcd_clear_display();
|
||||
fd = open(file, O_RDONLY);
|
||||
|
||||
if (-1 != fd)
|
||||
{
|
||||
int numread = read(fd, buffer, sizeof(buffer) - 1);
|
||||
|
||||
if (numread > 0) {
|
||||
buffer[numread] = 0;
|
||||
for(i=0;i<numread;i++) {
|
||||
switch(buffer[i]) {
|
||||
case '[':
|
||||
vtype = 1;
|
||||
buf_set[0] = 0;
|
||||
d = 0;
|
||||
break;
|
||||
case ']':
|
||||
vtype = 2;
|
||||
buf_set[d] = 0;
|
||||
buf_val[0] = 0;
|
||||
d = 0;
|
||||
break;
|
||||
case '#':
|
||||
buf_val[d] = 0;
|
||||
vtype = 3;
|
||||
break;
|
||||
default:
|
||||
switch(vtype) {
|
||||
case 1:
|
||||
buf_set[d++] = buffer[i];
|
||||
break;
|
||||
case 2:
|
||||
buf_val[d++] = buffer[i];
|
||||
break;
|
||||
case 3:
|
||||
snprintf(buf_disp,sizeof(buf_disp),"[%s]%s", buf_set, buf_val);
|
||||
lcd_puts(0,line++ % MAX_LINES, buf_disp);
|
||||
lcd_update();
|
||||
sleep(HZ/2);
|
||||
if (!strcasecmp(buf_set,"volume")) {
|
||||
global_settings.volume = (atoi(buf_val)/2);
|
||||
if(global_settings.volume > mpeg_sound_max(SOUND_VOLUME) ||
|
||||
global_settings.volume < mpeg_sound_min(SOUND_VOLUME)) {
|
||||
global_settings.volume = mpeg_sound_default(SOUND_VOLUME);
|
||||
syntax_error = true;
|
||||
}
|
||||
mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
|
||||
if (-1 == fd)
|
||||
return false;
|
||||
|
||||
} else
|
||||
if (!strcasecmp(buf_set,"bass")) {
|
||||
if (buf_val[0] == '-')
|
||||
global_settings.bass = ((mpeg_sound_max(SOUND_BASS)/2)-atoi(buf_val+1));
|
||||
else
|
||||
global_settings.bass = (atoi(buf_val)+(mpeg_sound_max(SOUND_BASS)/2));
|
||||
if (global_settings.bass > mpeg_sound_max(SOUND_BASS) ||
|
||||
global_settings.bass < mpeg_sound_min(SOUND_BASS)) {
|
||||
global_settings.bass = mpeg_sound_default(SOUND_BASS);
|
||||
syntax_error = true;
|
||||
}
|
||||
mpeg_sound_set(SOUND_BASS, global_settings.bass);
|
||||
} else
|
||||
if (!strcasecmp(buf_set,"treble")) {
|
||||
if (buf_val[0] == '-')
|
||||
global_settings.treble = ((mpeg_sound_max(SOUND_TREBLE)/2)-atoi(buf_val+1));
|
||||
else
|
||||
global_settings.treble = (atoi(buf_val)+(mpeg_sound_max(SOUND_TREBLE)/2));
|
||||
if (global_settings.treble > mpeg_sound_max(SOUND_TREBLE) ||
|
||||
global_settings.treble < mpeg_sound_min(SOUND_TREBLE)) {
|
||||
global_settings.treble = mpeg_sound_default(SOUND_TREBLE);
|
||||
syntax_error = true;
|
||||
}
|
||||
mpeg_sound_set(SOUND_TREBLE, global_settings.treble);
|
||||
} else
|
||||
if (!strcasecmp(buf_set,"balance")) {
|
||||
if (buf_val[0] == '-')
|
||||
global_settings.balance = -(atoi(buf_val+1)/2);
|
||||
else
|
||||
global_settings.balance = ((atoi(buf_val)/2));
|
||||
if (global_settings.balance > mpeg_sound_max(SOUND_BALANCE) ||
|
||||
global_settings.balance < mpeg_sound_min(SOUND_BALANCE)) {
|
||||
global_settings.balance = mpeg_sound_default(SOUND_BALANCE);
|
||||
syntax_error = true;
|
||||
}
|
||||
mpeg_sound_set(SOUND_BALANCE, global_settings.balance);
|
||||
} else
|
||||
if (!strcasecmp(buf_set,"channels")) {
|
||||
global_settings.channel_config = atoi(buf_val);
|
||||
if (global_settings.channel_config > mpeg_sound_max(SOUND_CHANNELS) ||
|
||||
global_settings.channel_config < mpeg_sound_min(SOUND_CHANNELS)) {
|
||||
global_settings.channel_config = mpeg_sound_default(SOUND_CHANNELS);
|
||||
syntax_error = true;
|
||||
}
|
||||
mpeg_sound_set(SOUND_CHANNELS, global_settings.channel_config);
|
||||
} else
|
||||
if (!strcasecmp(buf_set,"loudness")) {
|
||||
global_settings.loudness = atoi(buf_val);
|
||||
if(global_settings.loudness > mpeg_sound_max(SOUND_LOUDNESS) ||
|
||||
global_settings.loudness < mpeg_sound_min(SOUND_LOUDNESS)) {
|
||||
global_settings.loudness = mpeg_sound_default(SOUND_LOUDNESS);
|
||||
syntax_error = true;
|
||||
}
|
||||
mpeg_sound_set(SOUND_LOUDNESS, global_settings.loudness);
|
||||
} else
|
||||
if (!strcasecmp(buf_set,"bass boost")) {
|
||||
global_settings.bass_boost = (atoi(buf_val)/10);
|
||||
if(global_settings.bass_boost > mpeg_sound_max(SOUND_SUPERBASS) ||
|
||||
global_settings.bass_boost < mpeg_sound_min(SOUND_SUPERBASS)) {
|
||||
global_settings.bass_boost = mpeg_sound_default(SOUND_SUPERBASS);
|
||||
syntax_error = true;
|
||||
}
|
||||
mpeg_sound_set(SOUND_SUPERBASS, global_settings.bass_boost);
|
||||
} else if (!strcasecmp(buf_set,"auto volume")) {
|
||||
global_settings.avc = atoi(buf_val);
|
||||
if (global_settings.avc > mpeg_sound_max(SOUND_AVC) ||
|
||||
global_settings.avc < mpeg_sound_min(SOUND_AVC)) {
|
||||
global_settings.avc = mpeg_sound_default(SOUND_AVC);
|
||||
syntax_error = true;
|
||||
}
|
||||
mpeg_sound_set(SOUND_AVC, global_settings.avc);
|
||||
}
|
||||
if (syntax_error) {
|
||||
lcd_clear_display();
|
||||
lcd_puts(0,1,"SyntaxError");
|
||||
lcd_puts(0,2,buf_set);
|
||||
lcd_update();
|
||||
sleep(HZ);
|
||||
syntax_error = false;
|
||||
}
|
||||
vtype = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
while (read_line(fd, line, sizeof line))
|
||||
{
|
||||
char* name;
|
||||
char* value;
|
||||
|
||||
if (!settings_parseline(line, &name, &value))
|
||||
continue;
|
||||
|
||||
if (!strcasecmp(name, "volume"))
|
||||
set_eq_sound(value, SOUND_VOLUME, &global_settings.volume);
|
||||
else if (!strcasecmp(name, "bass"))
|
||||
set_eq_sound(value, SOUND_BASS, &global_settings.bass);
|
||||
else if (!strcasecmp(name, "treble"))
|
||||
set_eq_sound(value, SOUND_TREBLE, &global_settings.treble);
|
||||
else if (!strcasecmp(name, "balance"))
|
||||
set_eq_sound(value, SOUND_BALANCE, &global_settings.balance);
|
||||
else if (!strcasecmp(name, "channels"))
|
||||
set_eq_sound(value, SOUND_CHANNELS, &global_settings.bass);
|
||||
#ifdef HAVE_MAS3587F
|
||||
else if (!strcasecmp(name, "loudness"))
|
||||
set_eq_sound(value, SOUND_LOUDNESS, &global_settings.loudness);
|
||||
else if (!strcasecmp(name, "bass boost"))
|
||||
set_eq_sound(value, SOUND_SUPERBASS, &global_settings.bass_boost);
|
||||
else if (!strcasecmp(name, "auto volume"))
|
||||
set_eq_sound(value, SOUND_AVC, &global_settings.avc);
|
||||
#endif
|
||||
}
|
||||
return(false);
|
||||
|
||||
close(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -5,7 +5,6 @@ Description / General Info
|
|||
--------------------------
|
||||
* The Custom EQ is used on both the Rockbox Player and Recorder, in order to
|
||||
load, well, custom eq settings.
|
||||
* After editing the .eq file, you may need to reboot your Rockbox.
|
||||
|
||||
File Location
|
||||
-------------
|
||||
|
@ -14,24 +13,31 @@ the filename must end in .eq
|
|||
|
||||
Format Rules
|
||||
------------
|
||||
* Each setting must have it's own line
|
||||
* The setting you wish to change must be in brackets.
|
||||
* The value must be immediately after the end bracket, with no spaces.
|
||||
* There must be a # immediately after the value, with no spaces
|
||||
* Any text after the # will be ignored
|
||||
* Each setting must have it's own line.
|
||||
* Lines starting with # are ignored.
|
||||
* If a value is out of the acceptable range for the device, which can vary
|
||||
depending on the model, a Syntax Error will be displayed and the value
|
||||
will be set to the default value.
|
||||
depending on the model, the value will be set to its default value.
|
||||
|
||||
Example File
|
||||
------------
|
||||
[volume]70# 0 to 100
|
||||
[bass]11# player: -15 to 15, recorder: -12 to 12
|
||||
[treble]12# player: -15 to 15, recorder: -12 to 12
|
||||
[balance]0# -100 to 100
|
||||
[channels]0# 0=Stereo, 1=Mono, 2=Mono Left, 3=Mono Right
|
||||
[loudness]5# 0 to 17, recorder only!
|
||||
[bass boost]30# 0 to 100, recorder only!
|
||||
[auto volume]0# 0=off, 1=2s, 2=4s, 3=8s, recorder only!
|
||||
volume: 70
|
||||
bass: 11
|
||||
treble: 12
|
||||
balance: 0
|
||||
channels: 0
|
||||
loudness: 5
|
||||
bass boost: 30
|
||||
auto volume: 0
|
||||
|
||||
This sets each line to the respective values after it. Notice that you can put comments after the #
|
||||
This sets each line to the respective values after it.
|
||||
|
||||
Value ranges
|
||||
------------
|
||||
volume: 0 to 100
|
||||
bass: player: -15 to 15, recorder: -12 to 12
|
||||
treble: player: -15 to 15, recorder: -12 to 12
|
||||
balance: -100 to 100
|
||||
channels: 0=Stereo, 1=Mono, 2=Mono Left, 3=Mono Right
|
||||
loudness: 0 to 17 (recorder only)
|
||||
bass boost: 0 to 100 (recorder only)
|
||||
auto volume: 0=off, 1=2s, 2=4s, 3=8s (recorder only)
|
||||
|
|
|
@ -1757,6 +1757,51 @@ int mpeg_val2phys(int setting, int value)
|
|||
return result;
|
||||
}
|
||||
|
||||
int mpeg_phys2val(int setting, int value)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
switch(setting)
|
||||
{
|
||||
case SOUND_VOLUME:
|
||||
result = value / 2;
|
||||
break;
|
||||
|
||||
case SOUND_BALANCE:
|
||||
result = value / 2;
|
||||
break;
|
||||
|
||||
case SOUND_BASS:
|
||||
#ifdef HAVE_MAS3587F
|
||||
result = value + 12;
|
||||
#else
|
||||
result = value + 15;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SOUND_TREBLE:
|
||||
#ifdef HAVE_MAS3587F
|
||||
result = value + 12;
|
||||
#else
|
||||
result = value + 15;
|
||||
#endif
|
||||
break;
|
||||
|
||||
#ifdef HAVE_MAS3587F
|
||||
case SOUND_LOUDNESS:
|
||||
result = value;
|
||||
break;
|
||||
|
||||
case SOUND_SUPERBASS:
|
||||
result = value / 10;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void mpeg_sound_channel_config(int configuration)
|
||||
{
|
||||
#ifdef SIMULATOR
|
||||
|
|
|
@ -37,6 +37,7 @@ int mpeg_sound_max(int setting);
|
|||
int mpeg_sound_default(int setting);
|
||||
void mpeg_sound_channel_config(int configuration);
|
||||
int mpeg_val2phys(int setting, int value);
|
||||
int mpeg_phys2val(int setting, int value);
|
||||
char *mpeg_sound_unit(int setting);
|
||||
int mpeg_sound_numdecimals(int setting);
|
||||
struct mp3entry* mpeg_current_track(void);
|
||||
|
|
|
@ -63,7 +63,7 @@ CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) -W -Wall -mwindows
|
|||
APPCFLAGS = $(DEBUG) $(DEFINES) $(APPINCLUDES) -W -Wall -mwindows
|
||||
|
||||
FIRMSRCS = lcd-recorder.c power.c sprintf.c id3.c usb.c \
|
||||
mpeg.c powermgmt.c font.c sysfont.c
|
||||
mpeg.c powermgmt.c font.c sysfont.c ctype.c
|
||||
|
||||
APPS = main.c tree.c menu.c credits.c main_menu.c icons.c language.c \
|
||||
playlist.c showtext.c wps.c wps-display.c settings.c status.c \
|
||||
|
@ -221,6 +221,9 @@ $(OBJDIR)/mpeg.o: $(FIRMWAREDIR)/mpeg.c
|
|||
$(OBJDIR)/sprintf.o: $(COMMON)/sprintf.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/ctype.o: $(COMMON)/ctype.c
|
||||
$(CC) $(CFLAGS) $(APPINCLUDES) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/strtok.o: $(COMMON)/strtok.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) -W -Wall
|
|||
APPCFLAGS = $(DEBUG) $(DEFINES) -DAPPSVERSION=\"$(VERSION)\" $(APPINCLUDES) -W -Wall
|
||||
|
||||
FIRMSRCS = lcd-recorder.c sprintf.c id3.c debug.c usb.c mpeg.c power.c\
|
||||
powermgmt.c font.c panic.c sysfont.c
|
||||
powermgmt.c font.c panic.c sysfont.c ctype.c
|
||||
|
||||
APPS = main.c tree.c menu.c credits.c main_menu.c language.c\
|
||||
playlist.c showtext.c wps.c wps-display.c settings.c status.c icons.c\
|
||||
|
@ -263,6 +263,9 @@ $(OBJDIR)/mpeg.o: $(FIRMWAREDIR)/mpeg.c
|
|||
$(OBJDIR)/sprintf.o: $(COMMON)/sprintf.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/ctype.o: $(COMMON)/ctype.c
|
||||
$(CC) $(CFLAGS) $(APPINCLUDES) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/stubs.o: ../common/stubs.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue