diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2009-10-10 16:28:45 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2009-10-10 16:28:45 +0200 |
commit | 7cca327d228d6314e30fc5418cae0b9fbd4691cb (patch) | |
tree | 87bd15bde1be5ebeca7bdef2e82fc6a29bb8244e | |
parent | 87e34106f7ffabeb92110ccaece44b910de325b0 (diff) |
new config file WIP
-rw-r--r-- | callbacks.c | 1 | ||||
-rw-r--r-- | conf.c | 106 | ||||
-rw-r--r-- | conf.h | 28 | ||||
-rw-r--r-- | csid.cpp | 7 | ||||
-rw-r--r-- | palsa.c | 3 | ||||
-rw-r--r-- | plugins.c | 1 | ||||
-rw-r--r-- | streamer.c | 7 |
7 files changed, 91 insertions, 62 deletions
diff --git a/callbacks.c b/callbacks.c index 1dd4f940..02fad417 100644 --- a/callbacks.c +++ b/callbacks.c @@ -1145,6 +1145,7 @@ on_mainwin_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data) { + int conf_close_send_to_tray = conf_get_int ("close_send_to_tray", 0); if (conf_close_send_to_tray) { gtk_widget_hide (widget); } @@ -19,16 +19,15 @@ #include <stdint.h> #include <string.h> #include <stdlib.h> +#include "conf.h" -char conf_alsa_soundcard[1024] = "default"; // name of soundcard for alsa player -int conf_samplerate = 48000; -int conf_src_quality = 1; -char conf_hvsc_path[1024] = ""; -int conf_hvsc_enable = 0; -char conf_blacklist_plugins[1024]; // plugins listed in this option will not be loaded -int conf_close_send_to_tray = 0; -int conf_replaygain_mode = 0; -int conf_replaygain_scale = 1; +struct conf_item_t { + char *key; + char *value; + struct conf_item_t *next; +}; + +static struct conf_item_t *conf_items; int conf_load (void) { @@ -70,48 +69,57 @@ conf_load (void) { p++; } *p = 0; - if (!strcasecmp (str, "samplerate")) { - conf_samplerate = atoi (value); - } - else if (!strcasecmp (str, "alsa_soundcard")) { - strncpy (conf_alsa_soundcard, value, sizeof (conf_alsa_soundcard)); - conf_alsa_soundcard[sizeof (conf_alsa_soundcard) - 1] = 0; - } - else if (!strcasecmp (str, "src_quality")) { - conf_src_quality = atoi (value); - } - else if (!strcasecmp (str, "hvsc_path")) { - strncpy (conf_hvsc_path, value, sizeof (conf_hvsc_path)); - conf_hvsc_path[sizeof (conf_hvsc_path)-1] = 0; - } - else if (!strcasecmp (str, "hvsc_enable")) { - conf_hvsc_enable = atoi (value); - } - else if (!strcasecmp (str, "blacklist_plugins")) { - fprintf (stderr, "blacklisted plugins: %s\n", value); - strncpy (conf_blacklist_plugins, value, sizeof (conf_blacklist_plugins)); - conf_blacklist_plugins[sizeof (conf_blacklist_plugins)-1] = 0; - } - else if (!strcasecmp (str, "close_send_to_tray")) { - conf_close_send_to_tray = atoi (value); - } - else if (!strcasecmp (str, "replaygain_mode")) { - int rg = atoi (value); - if (rg >= 0 && rg <= 2) { - conf_replaygain_mode = atoi (value); - } - else { - fprintf (stderr, "config warning: replaygain_mode must be one of 0, 1 or 2\n"); - } - } - else if (!strcasecmp (str, "replaygain_scale")) { - conf_replaygain_scale = atoi (value); - } - else { - fprintf (stderr, "error in config file line %d\n", line); - } + conf_set_str (str, value); } fclose (fp); return 0; } +int +conf_save (void) { + return 0; +} + +void +conf_free (void) { +} + +const char * +conf_get_str (const char *key, const char *def) { + for (struct conf_item_t *it = conf_items; it; it = it->next) { + if (!strcasecmp (key, it->key)) { + return it->value; + } + } + return def; +} + +float +conf_get_float (const char *key, float def) { + const char *v = conf_get_str (key, NULL); + return v ? atof (v) : def; +} + +int +conf_get_int (const char *key, int def) { + const char *v = conf_get_str (key, NULL); + return v ? atoi (v) : def; +} + +void +conf_set_str (const char *key, const char *val) { + for (struct conf_item_t *it = conf_items; it; it = it->next) { + if (!strcasecmp (key, it->key)) { + free (it->value); + it->value = strdup (val); + return; + } + } + struct conf_item_t *it = malloc (sizeof (struct conf_item_t)); + memset (it, 0, sizeof (struct conf_item_t)); + it->next = conf_items; + it->key = strdup (key); + it->value = strdup (val); + conf_items = it; +} + @@ -18,17 +18,25 @@ #ifndef __CONF_H #define __CONF_H -extern char conf_alsa_soundcard[1024]; -extern int conf_samplerate; -extern int conf_src_quality; -extern char conf_hvsc_path[1024]; -extern int conf_hvsc_enable; -extern char conf_blacklist_plugins[1024]; -extern int conf_close_send_to_tray; -extern int conf_replaygain_mode; -extern int conf_replaygain_scale; - int conf_load (void); +int +conf_save (void); + +void +conf_free (void); + +const char * +conf_get_str (const char *key, const char *def); + +float +conf_get_float (const char *key, float def); + +int +conf_get_int (const char *key, int def); + +void +conf_set_str (const char *key, const char *val); + #endif // __CONF_H @@ -28,10 +28,10 @@ // #include "sidplay/sidendian.h" #include "deadbeef.h" -#include "conf.h" extern "C" { #include "md5/md5.h" +#include "conf.h" } // forward decls @@ -129,9 +129,14 @@ static sldb_t *sldb; static void sldb_load() { fprintf (stderr, "sldb_load\n"); + int conf_hvsc_enable = conf_get_int ("hvsc_enable", 0); if (sldb_loaded || !conf_hvsc_enable) { return; } + const char *conf_hvsc_path = conf_get_str ("hvsc_path", NULL); + if (!conf_hvsc_path) { + return; + } sldb_loaded = 1; const char *fname = conf_hvsc_path; FILE *fp = fopen (fname, "r"); @@ -56,7 +56,8 @@ palsa_init (void) { snd_pcm_hw_params_t *hw_params; snd_pcm_sw_params_t *sw_params; state = 0; - alsa_rate = conf_samplerate; + alsa_rate = conf_get_int ("samplerate", 48000); + const char *conf_alsa_soundcard = conf_get_str ("alsa_soundcard", "default"); if ((err = snd_pcm_open (&audio, conf_alsa_soundcard, SND_PCM_STREAM_PLAYBACK, 0))) { trace ("could not open audio device (%s)\n", @@ -325,6 +325,7 @@ plug_load_all (void) { #if DISABLE_VERSIONCHECK fprintf (stderr, "\033[0;31mDISABLE_VERSIONCHECK=1! do not distribute!\033[0;m\n"); #endif + const char *conf_blacklist_plugins = conf_get_str ("blacklist_plugins", ""); mutex = mutex_create (); char dirname[1024]; snprintf (dirname, 1024, "%s/lib/deadbeef", PREFIX); @@ -400,7 +400,7 @@ streamer_init (void) { mutex = mutex_create (); // src = src_new (SRC_SINC_BEST_QUALITY, 2, NULL); // src = src_new (SRC_LINEAR, 2, NULL); - src = src_new (conf_src_quality, 2, NULL); + src = src_new (conf_get_int ("src_quality", 2), 2, NULL); if (!src) { return -1; } @@ -430,6 +430,9 @@ int replaygain_scale = 1; static void apply_replay_gain_int16 (playItem_t *it, char *bytes, int size) { + int conf_replaygain_mode = conf_get_int ("replaygain_mode", 0); + int conf_replaygain_scale = conf_get_int ("replaygain_scale", 1); + if (!replaygain || !conf_replaygain_mode) { return; } @@ -472,6 +475,8 @@ apply_replay_gain_int16 (playItem_t *it, char *bytes, int size) { static void apply_replay_gain_float32 (playItem_t *it, char *bytes, int size) { + int conf_replaygain_mode = conf_get_int ("replaygain_mode", 0); + int conf_replaygain_scale = conf_get_int ("replaygain_scale", 1); if (!replaygain || !conf_replaygain_mode) { return; } |