summaryrefslogtreecommitdiff
path: root/plugins/sndfile/sndfile.c
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2011-03-26 14:21:13 +0100
committerGravatar waker <wakeroid@gmail.com>2011-03-26 14:21:13 +0100
commitad50ad9b4b80028c2f76161a8e41c23bd169b4f8 (patch)
tree9eb5e705d87a0b295b6cfaa7aed8600e53b60b11 /plugins/sndfile/sndfile.c
parent1c1da4bb688f0e912faeea76b91fbef73a81887a (diff)
sndfile: added support for selecting file extensions
Diffstat (limited to 'plugins/sndfile/sndfile.c')
-rw-r--r--plugins/sndfile/sndfile.c78
1 files changed, 74 insertions, 4 deletions
diff --git a/plugins/sndfile/sndfile.c b/plugins/sndfile/sndfile.c
index f9a7369f..1117788e 100644
--- a/plugins/sndfile/sndfile.c
+++ b/plugins/sndfile/sndfile.c
@@ -22,6 +22,7 @@
#include <string.h>
#include <sndfile.h>
#include <math.h>
+#include <stdlib.h>
#include "../../deadbeef.h"
#define min(x,y) ((x)<(y)?(x):(y))
@@ -368,9 +369,75 @@ sndfile_insert (DB_playItem_t *after, const char *fname) {
return after;
}
-static const char * exts[] = { "wav", "aif", "aiff", "snd", "au", "paf", "svx", "nist", "voc", "ircam", "w64", "mat4", "mat5", "pvf", "xi", "htk", "sds", "avr", "wavex", "sd2", "caf", "wve", NULL };
+#define DEFAULT_EXTS "wav;aif;aiff;snd;au;paf;svx;nist;voc;ircam;w64;mat4;mat5;pvf;xi;htk;sds;avr;wavex;sd2;caf;wve"
+
+#define EXT_MAX 100
+
+static char *exts[EXT_MAX] = {NULL};
static const char *filetypes[] = { "WAV", NULL };
+
+static void
+sndfile_init_exts (void) {
+ const char *new_exts = deadbeef->conf_get_str ("sndfile.extensions", DEFAULT_EXTS);
+ for (int i = 0; exts[i]; i++) {
+ free (exts[i]);
+ }
+ exts[0] = NULL;
+
+ int n = 0;
+ while (*new_exts) {
+ if (n >= EXT_MAX) {
+ fprintf (stderr, "sndfile: too many extensions, max is %d\n", EXT_MAX);
+ break;
+ }
+ const char *e = new_exts;
+ while (*e && *e != ';') {
+ e++;
+ }
+ if (e != new_exts) {
+ char *ext = malloc (e-new_exts+1);
+ memcpy (ext, new_exts, e-new_exts);
+ ext[e-new_exts] = 0;
+ exts[n++] = ext;
+ }
+ if (*e == 0) {
+ break;
+ }
+ new_exts = e+1;
+ }
+ exts[n] = NULL;
+}
+
+
+static int
+sndfile_on_configchanged (DB_event_t *ev, uintptr_t data) {
+ sndfile_init_exts ();
+ return 0;
+}
+
+static int
+sndfile_start (void) {
+ sndfile_init_exts ();
+ deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (sndfile_on_configchanged), 0);
+ return 0;
+}
+
+static int
+sndfile_stop (void) {
+ deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (sndfile_on_configchanged), 0);
+ for (int i = 0; exts[i]; i++) {
+ free (exts[i]);
+ }
+ exts[0] = NULL;
+ return 0;
+}
+
+static const char settings_dlg[] =
+ "property \"File Extensions (separate with ';')\" entry sndfile.extensions \"" DEFAULT_EXTS "\";\n"
+;
+
+
// define plugin interface
static DB_decoder_t plugin = {
DB_PLUGIN_SET_API_VERSION
@@ -378,7 +445,7 @@ static DB_decoder_t plugin = {
.plugin.version_minor = 0,
.plugin.type = DB_PLUGIN_DECODER,
.plugin.id = "sndfile",
- .plugin.name = "pcm player",
+ .plugin.name = "WAV/PCM player",
.plugin.descr = "wav/aiff player using libsndfile",
.plugin.copyright =
"Copyright (C) 2009-2011 Alexey Yakovenko <waker@users.sourceforge.net>\n"
@@ -405,8 +472,11 @@ static DB_decoder_t plugin = {
.seek = sndfile_seek,
.seek_sample = sndfile_seek_sample,
.insert = sndfile_insert,
- .exts = exts,
- .filetypes = filetypes
+ .exts = (const char **)exts,
+ .filetypes = filetypes,
+ .plugin.start = sndfile_start,
+ .plugin.stop = sndfile_stop,
+ .plugin.configdialog = settings_dlg,
};
DB_plugin_t *