ddb_dsp_preset_t * dsp_preset_load (const char *fname) { ddb_dsp_preset_t *p = dsp_preset_alloc (); if (!p) { return NULL; } memset (p, 0, sizeof (ddb_dsp_preset_t)); const char *end = strrchr (fname, '.'); if (!end) { end = fname + strlen (fname); } const char *start = strrchr (fname, '/'); if (!start) { start = fname; } else { start++; } p->title = malloc (end-start+1); memcpy (p->title, start, end-start); p->title[end-start] = 0; int err = deadbeef->dsp_preset_load (fname, &p->chain); if (err != 0) { dsp_preset_free (p); return NULL; } return p; }
int dsp_preset_load (const char *fname, ddb_dsp_context_t **head) { if (!head) { return -1; } int err = 1; FILE *fp = fopen (fname, "rt"); if (!fp) { return -1; } ddb_dsp_context_t *tail = NULL; char temp[100]; for (;;) { // plugin { int err = fscanf (fp, "%100s {\n", temp); if (err == EOF) { break; } else if (1 != err) { fprintf (stderr, "error plugin name\n"); goto error; } DB_dsp_t *plug = (DB_dsp_t *)plug_get_for_id (temp); if (!plug) { fprintf (stderr, "ddb_dsp_preset_load: plugin %s not found. preset will not be loaded\n", temp); goto error; } ddb_dsp_context_t *ctx = plug->open (); if (!ctx) { fprintf (stderr, "ddb_dsp_preset_load: failed to open ctxance of plugin %s\n", temp); goto error; } if (tail) { tail->next = ctx; tail = ctx; } else { tail = *head = ctx; } int n = 0; for (;;) { char value[1000]; if (!fgets (temp, sizeof (temp), fp)) { fprintf (stderr, "unexpected eof while reading plugin params\n"); goto error; } if (!strcmp (temp, "}\n")) { break; } else if (1 != sscanf (temp, "\t%1000[^\n]\n", value)) { fprintf (stderr, "error loading param %d\n", n); goto error; } if (plug->num_params) { plug->set_param (ctx, n, value); } n++; } } err = 0; error: if (err) { fprintf (stderr, "error loading %s\n", fname); } if (fp) { fclose (fp); } if (err && *head) { dsp_preset_free (*head); *head = NULL; } return err ? -1 : 0; }