# HG changeset patch # User Matti Hamalainen # Date 1174592764 0 # Node ID 91ca76e6c23fbce35f533442c87737a80e92afbd # Parent 7ae251af5f839cd98d69e2f0123f7f55c95e87b0 More work towards filter configuration. diff -r 7ae251af5f83 -r 91ca76e6c23f src/xs_config.c --- a/src/xs_config.c Thu Mar 22 17:26:04 2007 +0000 +++ b/src/xs_config.c Thu Mar 22 19:46:04 2007 +0000 @@ -86,6 +86,15 @@ xs_ ## MV = NULL; \ } +/* Samplerates + */ +static gchar *xs_samplerates_table[] = { + "8000", "11025", "22050", + "44100", "48000", "64000", + "96000" +}; + +static gint xs_nsamplerates_table = (sizeof(xs_samplerates_table) / sizeof(xs_samplerates_table[0])); /* * Configuration specific stuff @@ -112,6 +121,7 @@ { CTYPE_INT, &xs_cfg.sid2Builder, "sid2Builder" }, { CTYPE_INT, &xs_cfg.sid2OptLevel, "sid2OptLevel" }, +{ CTYPE_INT, &xs_cfg.sid2NFilterPresets, "sid2NFilterPresets" }, { CTYPE_BOOL, &xs_cfg.oversampleEnable, "oversampleEnable" }, { CTYPE_INT, &xs_cfg.oversampleFactor, "oversampleFactor" }, @@ -390,51 +400,90 @@ static gboolean xs_filters_import(gchar *pcFilename, t_xs_sid2_filter **pFilters, gint *nFilters) { FILE *inFile; - gchar inLine[XS_BUF_SIZE]; - size_t lineNum; + gchar inLine[XS_BUF_SIZE], tmpStr[256], *sectName; + gboolean sectBegin; + size_t lineNum, i; t_xs_sid2_filter *f; + fprintf(stderr, "xs_filters_import(%s)\n", pcFilename); + if ((inFile = fopen(pcFilename, "ra")) == NULL) return FALSE; + fprintf(stderr, "importing...\n"); + sectBegin = FALSE; lineNum = 0; while (fgets(inLine, XS_BUF_SIZE, inFile) != NULL) { size_t linePos = 0; lineNum++; xs_findnext(inLine, &linePos); -fprintf(stderr, ":'%s'\n", &inLine[linePos]); - if (isalpha(inLine[linePos])) { + if (isalpha(inLine[linePos]) && sectBegin) { /* A new key/value pair */ - + i = 0; + while (i < 256 && inLine[linePos] && !isspace(inLine[linePos]) && inLine[linePos] != '=') { + tmpStr[i++] = inLine[linePos++]; + } + tmpStr[i] = 0; + xs_findnext(inLine, &linePos); + if (inLine[linePos] != '=') { + fprintf(stderr, "invalid line: %s [expect =']'", inLine); + } else { + linePos++; + xs_findnext(inLine, &linePos); + if (!isdigit(inLine[linePos])) { + fprintf(stderr, "expected numeric: %s\n", inLine); + } else { + + } + } } else if (inLine[linePos] == '[') { /* New filter(?) section starts */ + linePos++; + i = 0; + while (i < 256 && inLine[linePos] && inLine[linePos] != ']') { + tmpStr[i++] = inLine[linePos++]; + } + tmpStr[i] = 0; + if (inLine[linePos] != ']') { + fprintf(stderr, "invalid! expected ']': %s\n", inLine); + } else { + sectName = strdup(tmpStr); + fprintf(stderr, "filter: %s\n", sectName); + sectBegin = TRUE; + } } else if ((inLine[linePos] != ';') && (inLine[linePos] != 0)) { /* Syntax error */ - return FALSE; + fprintf(stderr, "syntax error: %s\n", inLine); } } fclose(inFile); - return FALSE; + return TRUE; } -static gboolean xs_filters_export(gchar *pcFilename, t_xs_sid2_filter *pFilters, gint nFilters) +static gboolean xs_filters_export(gchar *pcFilename, t_xs_sid2_filter **pFilters, gint nFilters) { FILE *outFile; - t_xs_sid2_filter *f = pFilters; + t_xs_sid2_filter *f; gint n; /* Open/create the file */ if ((outFile = fopen(pcFilename, "wa")) == NULL) return FALSE; + /* Header */ + fprintf(outFile, + "; SIDPlay2 compatible filter definition file\n" + "; Exported by " PACKAGE_STRING "\n\n"); + /* Write each filter spec in "INI"-style format */ for (n = 0; n < nFilters; n++) { gint i; + f = pFilters[n]; fprintf(outFile, "[%s]\n" @@ -512,6 +561,15 @@ /* Filters and presets are a special case */ xs_filter_load_into(cfg, 0, &xs_cfg.sid2Filter); + xs_cfg.sid2FilterPresets = g_malloc0(xs_cfg.sid2NFilterPresets * sizeof(t_xs_sid2_filter *)); + if (!xs_cfg.sid2FilterPresets) { + xs_error(_("Allocation of sid2FilterPresets structure failed!\n")); + } else { + for (i = 0; i < xs_cfg.sid2NFilterPresets; i++) { + xs_cfg.sid2FilterPresets[i] = + xs_filter_load(cfg, i); + } + } XS_CONFIG_FREE(cfg); @@ -657,6 +715,12 @@ break; } } + + /* Get filter settings */ + if (!xs_curve_get_points(XS_CURVE(LUW(""), &xs_cfg.sid2Filter.points, &xs_cfg.sid2Filter.npoints)) { + // FIXME + xs_error(_("Warning: Could not get filter curve widget points!\n")); + } /* Release lock */ XS_MUTEX_UNLOCK(xs_cfg); @@ -738,7 +802,7 @@ /* Selection was accepted! */ gtk_entry_set_text(GTK_ENTRY(LUW("cfg_stil_dbpath")), - gtk_file_selection_get_filename(GTK_FILE_SELECTION(xs_stil_fileselector))); + gtk_file_selection_get_filename(GTK_FILE_SELECTION(xs_stil_fileselector))); /* Close file selector window */ gtk_widget_destroy(xs_stil_fileselector); @@ -777,7 +841,7 @@ /* Selection was accepted! */ gtk_entry_set_text(GTK_ENTRY(LUW("cfg_hvsc_path")), - gtk_file_selection_get_filename(GTK_FILE_SELECTION(xs_hvsc_selector))); + gtk_file_selection_get_filename(GTK_FILE_SELECTION(xs_hvsc_selector))); /* Close file selector window */ gtk_widget_destroy(xs_hvsc_selector); @@ -809,15 +873,25 @@ xs_curve_reset(curve); xs_curve_set_range(curve, 0,0, XS_SIDPLAY2_NFPOINTS, XS_SIDPLAY2_FMAX); - xs_curve_set_points(curve, f->points, f->npoints); + if (!xs_curve_set_points(curve, f->points, f->npoints)) { + // FIXME + xs_error(_("Warning: Could not set filter curve widget points!\n")); + } } void xs_cfg_sp2_presets_update(void) { - /* - update the drowdown list of preset names from current filter presets list - */ + GList *tmpList = NULL; + gint i; + + for (i = 0; i < xs_cfg.sid2NFilterPresets; i++) { + tmpList = g_list_append(tmpList, + (gpointer) xs_cfg.sid2FilterPresets[i]->name); + } + + gtk_combo_set_popdown_strings(GTK_COMBO(LUW("cfg_sp2_filter_combo")), tmpList); + g_list_free(tmpList); } @@ -879,7 +953,7 @@ } if (j != -1) { - fprintf(stderr, "found, confirm overwrite?\n"); + fprintf(stderr, "Found, confirm overwrite?\n"); } fprintf(stderr, "saving!\n"); @@ -926,9 +1000,7 @@ /* Selection was accepted! */ tmpStr = gtk_file_selection_get_filename(GTK_FILE_SELECTION(xs_filt_importselector)); -fprintf(stderr, "paf: %s\n", tmpStr); xs_filters_import(tmpStr, xs_cfg.sid2FilterPresets, &xs_cfg.sid2NFilterPresets); - xs_cfg_sp2_presets_update(); /* Close file selector window */ @@ -967,8 +1039,7 @@ /* Selection was accepted! */ tmpStr = gtk_file_selection_get_filename(GTK_FILE_SELECTION(xs_filt_exportselector)); -fprintf(stderr, "paf: %s\n", tmpStr); -// xs_filters_export(tmpStr, xs_cfg.sid2FilterPresets, &xs_cfg.sid2NFilterPresets); + xs_filters_export(tmpStr, xs_cfg.sid2FilterPresets, xs_cfg.sid2NFilterPresets); /* Close file selector window */ gtk_widget_destroy(xs_filt_exportselector); @@ -1154,6 +1225,7 @@ gint i; gfloat tmpValue; gchar tmpStr[64]; + GList *tmpList = NULL; GtkWidget *tmpCurve; /* Check if the window already exists */ @@ -1164,10 +1236,18 @@ /* Create the window */ xs_configwin = create_xs_configwin(); - + /* Get lock on configuration */ XS_MUTEX_LOCK(xs_cfg); + /* Add samplerates */ + for (i = 0; i < xs_nsamplerates_table; i++) { + tmpList = g_list_append (tmpList, + (gpointer) xs_samplerates_table[i]); + } + gtk_combo_set_popdown_strings(GTK_COMBO(LUW("cfg_samplerate_combo")), tmpList); + g_list_free(tmpList); + /* Create the custom filter curve widget for libSIDPlay2 */ xs_cfg_sp2_presets_update(); tmpCurve = xs_curve_new();