From 4cd7148d793912b8ef97ce9265962b73d32a1c3f Mon Sep 17 00:00:00 2001 From: waker Date: Mon, 17 Aug 2009 21:45:08 +0200 Subject: added config file --- Jamfile | 2 +- conf.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ conf.h | 13 +++++++++++ csid.cpp | 12 +++++----- main.c | 17 ++++++++------ palsa.c | 7 ++++-- streamer.c | 4 +++- 7 files changed, 114 insertions(+), 17 deletions(-) create mode 100644 conf.c create mode 100644 conf.h diff --git a/Jamfile b/Jamfile index b7340fab..ae17488a 100644 --- a/Jamfile +++ b/Jamfile @@ -23,7 +23,7 @@ HDRS += $(ROOT)/libsidplay2/sidplay-libs-2.1.0/builders/resid-builder/include ; HDRS += $(ROOT)/gme/Game_Music_Emu-0.5.2 ; Main deadbeef : - codec.c cvorbis.c cmp3.c cgme.c cdumb.c cwav.c cflac.c csid.cpp playlist.c palsa.c streamer.c md5/md5.c main.c support.c interface.c callbacks.c threading_pthread.c messagepump.c gtkplaylist.c search.c progress.c ; + codec.c cvorbis.c cmp3.c cgme.c cdumb.c cflac.c csid.cpp playlist.c palsa.c streamer.c md5/md5.c main.c support.c interface.c callbacks.c threading_pthread.c messagepump.c gtkplaylist.c search.c progress.c conf.c ; LINKLIBS on deadbeef = -lm -lvorbis -logg -lvorbisfile -lmad -lFLAC -lsamplerate -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lgthread-2.0 -lstdc++ -lasound ; diff --git a/conf.c b/conf.c new file mode 100644 index 00000000..90a5f0a2 --- /dev/null +++ b/conf.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include + +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; + +int +conf_load (void) { + extern char dbconfdir[1024]; // $HOME/.config/deadbeef + char str[1024]; + snprintf (str, 1024, "%s/config", dbconfdir); + FILE *fp = fopen (str, "rt"); + if (!fp) { + fprintf (stderr, "failed to load config file\n"); + return -1; + } + int line = 0; + while (fgets (str, 1024, fp) != NULL) { + line++; + if (str[0] == '#') { + continue; + } + uint8_t *p = (uint8_t *)str; + while (*p && *p > 0x20) { + p++; + } + if (!*p) { + fprintf (stderr, "error in config file line %d\n", line); + continue; + } + *p = 0; + p++; + // skip whitespace + while (*p && *p <= 0x20) { + p++; + } + if (!*p) { + fprintf (stderr, "error in config file line %d\n", line); + continue; + } + char *value = p; + // remove trailing trash + while (*p && *p >= 0x20) { + p++; + } + *p = 0; + if (!strcasecmp (str, "samplerate")) { + conf_samplerate = atoi (value); + } + else if (!strcasecmp (str, "alsa_soundcard")) { + strncpy (conf_alsa_soundcard, value, 1024); + conf_alsa_soundcard[1023] = 0; + } + else if (!strcasecmp (str, "src_quality")) { + conf_src_quality = atoi (value); + } + else if (!strcasecmp (str, "hvsc_path")) { + strncpy (conf_hvsc_path, value, 1024); + conf_hvsc_path[1023] = 0; + } + else if (!strcasecmp (str, "hvsc_enable")) { + conf_hvsc_enable = atoi (value); + } + else { + fprintf (stderr, "error in config file line %d\n", line); + } + } + fclose (fp); + return 0; +} + diff --git a/conf.h b/conf.h new file mode 100644 index 00000000..3080fe95 --- /dev/null +++ b/conf.h @@ -0,0 +1,13 @@ +#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; + +int +conf_load (void); + +#endif // __CONF_H diff --git a/csid.cpp b/csid.cpp index ed5abb50..0df172b4 100644 --- a/csid.cpp +++ b/csid.cpp @@ -28,6 +28,7 @@ extern "C" { #include "md5/md5.h" #include "common.h" #include "playback.h" +#include "conf.h" } static inline void @@ -57,15 +58,14 @@ static int sldb_poolmark; static int16_t *sldb_lengths[SLDB_MAX_SONGS]; static int sldb_size; static int sldb_loaded; -static const char *sldb_fname = "/home/waker/hvsc/C64Music/DOCUMENTS/Songlengths.txt"; -//static const char *sldb_fname = "/mnt/win/mus/chiptune/C64Music/DOCUMENTS/Songlengths.txt"; -static void sldb_load(const char *fname) +static void sldb_load() { - if (sldb_loaded) { + if (sldb_loaded || !conf_hvsc_enable) { return; } sldb_loaded = 1; + const char *fname = conf_hvsc_path; FILE *fp = fopen (fname, "r"); if (!fp) { return; @@ -364,7 +364,7 @@ convstr (const char* str) { extern "C" playItem_t * csid_insert (playItem_t *after, const char *fname) { - sldb_load(sldb_fname); + sldb_load (); SidTune *tune; tune = new SidTune (fname); int tunes = tune->getInfo ().songs; @@ -390,7 +390,7 @@ csid_insert (playItem_t *after, const char *fname) { } md5_finish (&md5, sig); - sldb_load(sldb_fname); + sldb_load (); int song = -1; if (sldb_loaded) { song = sldb_find (sig); diff --git a/main.c b/main.c index 56096f9d..a2af6e04 100644 --- a/main.c +++ b/main.c @@ -41,12 +41,20 @@ #include "streamer.h" #include "search.h" #include "progress.h" +#include "conf.h" +// some common global variables +char confdir[1024]; // $HOME/.config +char dbconfdir[1024]; // $HOME/.config/deadbeef +char defpl[1024]; // $HOME/.config/deadbeef/default.dbpl + +// main widgets GtkWidget *mainwin; GtkWidget *searchwin; GtkStatusIcon *trayicon; GtkWidget *traymenu; +// playlist configuration structures gtkplaylist_t main_playlist; gtkplaylist_t search_playlist; @@ -55,11 +63,6 @@ static int sb_context_id = -1; static char sb_text[512]; static float last_songpos = -1; -// some common global variables -char confdir[1024]; // $HOME/.config -char dbconfdir[1024]; // $HOME/.config/deadbeef -char defpl[1024]; // $HOME/.config/deadbeef/default.dbpl - void update_songinfo (void) { char sbtext_new[512] = "-"; @@ -469,7 +472,6 @@ main (int argc, char *argv[]) { exit(1); } - printf ("argc: %d\n", argc); remote.sun_family = AF_UNIX; snprintf (remote.sun_path, 108, "%s/socket", dbconfdir); len = strlen(remote.sun_path) + sizeof(remote.sun_family); @@ -486,7 +488,7 @@ main (int argc, char *argv[]) { } char out[1]; if (recv(s, out, 1, 0) == -1) { - printf ("failed to pass args to remote!\n"); + fprintf (stderr, "failed to pass args to remote!\n"); exit (-1); } close (s); @@ -494,6 +496,7 @@ main (int argc, char *argv[]) { } close(s); + conf_load (); pl_load (defpl); messagepump_init (); codec_init_locking (); diff --git a/palsa.c b/palsa.c index eea4a743..09550065 100644 --- a/palsa.c +++ b/palsa.c @@ -22,6 +22,7 @@ #include "palsa.h" #include "threading.h" #include "streamer.h" +#include "conf.h" static inline void le_int16 (int16_t in, char *out) { @@ -57,11 +58,12 @@ palsa_init (void) { snd_pcm_hw_params_t *hw_params; snd_pcm_sw_params_t *sw_params; state = 0; + alsa_rate = conf_samplerate; - if ((err = snd_pcm_open (&audio, "default", SND_PCM_STREAM_PLAYBACK, 0))) { + if ((err = snd_pcm_open (&audio, conf_alsa_soundcard, SND_PCM_STREAM_PLAYBACK, 0))) { fprintf (stderr, "could not open audio device (%s)\n", snd_strerror (err)); - return -1; + exit (-1); } if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) { @@ -98,6 +100,7 @@ palsa_init (void) { snd_strerror (err)); goto open_error; } + alsa_rate = val; if ((err = snd_pcm_hw_params_set_channels (audio, hw_params, 2)) < 0) { fprintf (stderr, "cannot set channel count (%s)\n", diff --git a/streamer.c b/streamer.c index cebd9eed..56145ad7 100644 --- a/streamer.c +++ b/streamer.c @@ -29,6 +29,7 @@ #include "playback.h" #include "messagepump.h" #include "messages.h" +#include "conf.h" static SRC_STATE *src; static SRC_DATA srcdata; @@ -166,7 +167,8 @@ int 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 (SRC_LINEAR, 2, NULL); + src = src_new (conf_src_quality, 2, NULL); if (!src) { return -1; } -- cgit v1.2.3