aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--VERSION2
-rw-r--r--bin/synthpod_alsa.c31
-rw-r--r--bin/synthpod_bin.c5
-rw-r--r--bin/synthpod_bin.h3
-rw-r--r--bin/synthpod_dummy.c31
-rw-r--r--bin/synthpod_jack.c31
-rw-r--r--nsmc/nsmc.h104
7 files changed, 159 insertions, 48 deletions
diff --git a/VERSION b/VERSION
index 8253ceb9..37274f45 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.6259
+0.1.6261
diff --git a/bin/synthpod_alsa.c b/bin/synthpod_alsa.c
index ed49d518..10dfbfb6 100644
--- a/bin/synthpod_alsa.c
+++ b/bin/synthpod_alsa.c
@@ -858,16 +858,37 @@ _visibility(void *data)
}
static const nsmc_driver_t nsm_driver = {
- .open = _open,
- .save = _save,
- .show = _show,
- .hide = _hide,
.visibility = _visibility,
.capability = NSMC_CAPABILITY_MESSAGE
| NSMC_CAPABILITY_SWITCH
| NSMC_CAPABILITY_OPTIONAL_GUI
};
+__non_realtime static int
+_nsm_callback(void *data, const nsmc_event_t *ev)
+{
+ switch(ev->type)
+ {
+ case NSMC_EVENT_TYPE_OPEN:
+ return _open(ev->open.path, ev->open.name, ev->open.id, data);
+ case NSMC_EVENT_TYPE_SAVE:
+ return _save(data);
+ case NSMC_EVENT_TYPE_SHOW:
+ return _show(data);
+ case NSMC_EVENT_TYPE_HIDE:
+ return _hide(data);
+
+ case NSMC_EVENT_TYPE_NONE:
+ // fall-through
+ case NSMC_EVENT_TYPE_MAX:
+ // fall-through
+ default:
+ return 1;
+ }
+
+ return 0;
+}
+
// rt
__realtime static double
_osc_schedule_osc2frames(LV2_OSC_Schedule_Handle instance, uint64_t timestamp)
@@ -1155,7 +1176,7 @@ main(int argc, char **argv)
bin->app_driver.features |= SP_APP_FEATURE_POWER_OF_2_BLOCK_LENGTH;
// run
- bin_run(bin, "Synthpod-ALSA", argv, &nsm_driver);
+ bin_run(bin, "Synthpod-ALSA", argv, &nsm_driver, _nsm_callback);
// stop
bin_stop(bin);
diff --git a/bin/synthpod_bin.c b/bin/synthpod_bin.c
index 0849ca25..9ff8e347 100644
--- a/bin/synthpod_bin.c
+++ b/bin/synthpod_bin.c
@@ -491,7 +491,8 @@ _gui_rolling(bin_t *bin)
}
__realtime void
-bin_run(bin_t *bin, const char *name, char **argv, const nsmc_driver_t *nsm_driver)
+bin_run(bin_t *bin, const char *name, char **argv, const nsmc_driver_t *nsm_driver,
+ nsmc_callback_t nsm_callback)
{
char *fallback_path = NULL;
@@ -512,7 +513,7 @@ bin_run(bin_t *bin, const char *name, char **argv, const nsmc_driver_t *nsm_driv
const char *exe = strrchr(argv[0], '/');
exe = exe ? exe + 1 : argv[0]; // we only want the program name without path
bin->nsm = nsmc_new(name, exe, fallback_path ? fallback_path : argv[optind],
- nsm_driver, bin); //TODO check
+ nsm_driver, nsm_callback, bin); //TODO check
if(fallback_path)
{
diff --git a/bin/synthpod_bin.h b/bin/synthpod_bin.h
index cefa6048..c7f3e2a0 100644
--- a/bin/synthpod_bin.h
+++ b/bin/synthpod_bin.h
@@ -128,7 +128,8 @@ void
bin_init(bin_t *bin, uint32_t sample_rate);
void
-bin_run(bin_t *bin, const char *name, char **argv, const nsmc_driver_t *nsm_driver);
+bin_run(bin_t *bin, const char *name, char **argv, const nsmc_driver_t *nsm_driver,
+ nsmc_callback_t nsm_callback);
void
bin_stop(bin_t *bin);
diff --git a/bin/synthpod_dummy.c b/bin/synthpod_dummy.c
index 1e81295e..bc6656e6 100644
--- a/bin/synthpod_dummy.c
+++ b/bin/synthpod_dummy.c
@@ -403,16 +403,37 @@ _visibility(void *data)
}
static const nsmc_driver_t nsm_driver = {
- .open = _open,
- .save = _save,
- .show = _show,
- .hide = _hide,
.visibility = _visibility,
.capability = NSMC_CAPABILITY_MESSAGE
| NSMC_CAPABILITY_SWITCH
| NSMC_CAPABILITY_OPTIONAL_GUI
};
+__non_realtime static int
+_nsm_callback(void *data, const nsmc_event_t *ev)
+{
+ switch(ev->type)
+ {
+ case NSMC_EVENT_TYPE_OPEN:
+ return _open(ev->open.path, ev->open.name, ev->open.id, data);
+ case NSMC_EVENT_TYPE_SAVE:
+ return _save(data);
+ case NSMC_EVENT_TYPE_SHOW:
+ return _show(data);
+ case NSMC_EVENT_TYPE_HIDE:
+ return _hide(data);
+
+ case NSMC_EVENT_TYPE_NONE:
+ // fall-through
+ case NSMC_EVENT_TYPE_MAX:
+ // fall-through
+ default:
+ return 1;
+ }
+
+ return 0;
+}
+
// rt
__realtime static double
_osc_schedule_osc2frames(LV2_OSC_Schedule_Handle instance, uint64_t timestamp)
@@ -638,7 +659,7 @@ main(int argc, char **argv)
bin->app_driver.features |= SP_APP_FEATURE_POWER_OF_2_BLOCK_LENGTH;
// run
- bin_run(bin, "Synthpod-DUMMY", argv, &nsm_driver);
+ bin_run(bin, "Synthpod-DUMMY", argv, &nsm_driver, _nsm_callback);
// stop
bin_stop(bin);
diff --git a/bin/synthpod_jack.c b/bin/synthpod_jack.c
index 3b296039..a0b3ab0a 100644
--- a/bin/synthpod_jack.c
+++ b/bin/synthpod_jack.c
@@ -976,16 +976,37 @@ _visibility(void *data)
}
static const nsmc_driver_t nsm_driver = {
- .open = _open,
- .save = _save,
- .show = _show,
- .hide = _hide,
.visibility = _visibility,
.capability = NSMC_CAPABILITY_MESSAGE
| NSMC_CAPABILITY_SWITCH
| NSMC_CAPABILITY_OPTIONAL_GUI
};
+__non_realtime static int
+_nsm_callback(void *data, const nsmc_event_t *ev)
+{
+ switch(ev->type)
+ {
+ case NSMC_EVENT_TYPE_OPEN:
+ return _open(ev->open.path, ev->open.name, ev->open.id, data);
+ case NSMC_EVENT_TYPE_SAVE:
+ return _save(data);
+ case NSMC_EVENT_TYPE_SHOW:
+ return _show(data);
+ case NSMC_EVENT_TYPE_HIDE:
+ return _hide(data);
+
+ case NSMC_EVENT_TYPE_NONE:
+ // fall-through
+ case NSMC_EVENT_TYPE_MAX:
+ // fall-through
+ default:
+ return 1;
+ }
+
+ return 0;
+}
+
// rt
__realtime static double
_osc_schedule_osc2frames(LV2_OSC_Schedule_Handle instance, uint64_t timestamp)
@@ -1208,7 +1229,7 @@ main(int argc, char **argv)
bin->app_driver.features = SP_APP_FEATURE_POWER_OF_2_BLOCK_LENGTH; // always true for JACK
// run
- bin_run(bin, "Synthpod-JACK", argv, &nsm_driver);
+ bin_run(bin, "Synthpod-JACK", argv, &nsm_driver, _nsm_callback);
// stop
bin_stop(bin);
diff --git a/nsmc/nsmc.h b/nsmc/nsmc.h
index f114a36a..7814fb8d 100644
--- a/nsmc/nsmc.h
+++ b/nsmc/nsmc.h
@@ -47,25 +47,43 @@ typedef enum _nsmc_capability_t {
NSMC_CAPABILITY_MAX
} nsmc_capability_t;
+typedef enum _nsmc_event_type_t {
+ NSMC_EVENT_TYPE_NONE = 0,
+
+ NSMC_EVENT_TYPE_OPEN,
+ NSMC_EVENT_TYPE_SAVE,
+ NSMC_EVENT_TYPE_SHOW,
+ NSMC_EVENT_TYPE_HIDE,
+
+ NSMC_EVENT_TYPE_MAX
+} nsmc_event_type_t;
+
typedef struct _nsmc_t nsmc_t;
typedef struct _nsmc_driver_t nsmc_driver_t;
+typedef struct _nsmc_event_open_t nsmc_event_open_t;
+typedef struct _nsmc_event_t nsmc_event_t;
-typedef int (*nsmc_open_t)(const char *path, const char *name,
- const char *id, void *data);
-typedef int (*nsmc_save_t)(void *data);
-typedef int (*nsmc_show_t)(void *data);
-typedef int (*nsmc_hide_t)(void *data);
typedef bool (*nsmc_visibility_t)(void *data);
+typedef int (*nsmc_callback_t)(void *data, const nsmc_event_t *ev);
struct _nsmc_driver_t {
- nsmc_open_t open;
- nsmc_save_t save;
- nsmc_show_t show;
- nsmc_hide_t hide;
nsmc_visibility_t visibility;
nsmc_capability_t capability;
};
+struct _nsmc_event_open_t {
+ const char *path;
+ const char *name;
+ const char *id;
+};
+
+struct _nsmc_event_t {
+ nsmc_event_type_t type;
+ union {
+ nsmc_event_open_t open;
+ };
+};
+
static const char *nsmc_capability_labels [NSMC_CAPABILITY_MAX] = {
[NSMC_CAPABILITY_SWITCH] = "switch",
[NSMC_CAPABILITY_DIRTY] = "dirty",
@@ -78,7 +96,7 @@ static const char *nsmc_capability_labels [NSMC_CAPABILITY_MAX] = {
NSMC_API nsmc_t *
nsmc_new(const char *call, const char *exe, const char *fallback_path,
- const nsmc_driver_t *driver, void *data);
+ const nsmc_driver_t *driver, nsmc_callback_t nsm_callback, void *data);
NSMC_API void
nsmc_free(nsmc_t *nsm);
@@ -168,6 +186,7 @@ struct _nsmc_t {
char *exe;
const nsmc_driver_t *driver;
+ nsmc_callback_t callback;
void *data;
LV2_OSC_Stream stream;
@@ -331,7 +350,16 @@ _client_open(LV2_OSC_Reader *reader, LV2_OSC_Arg *arg, const LV2_OSC_Tree *tree,
resolvedpath = dir;
}
- if(nsm->driver->open && nsm->driver->open(resolvedpath, name, id, nsm->data))
+ const nsmc_event_t ev_open = {
+ .type = NSMC_EVENT_TYPE_OPEN,
+ .open = {
+ .path = resolvedpath,
+ .name = name,
+ .id = id
+ }
+ };
+
+ if(nsm->callback(nsm->data, &ev_open) != 0)
{
fprintf(stderr, "NSM load failed: '%s'\n", dir);
}
@@ -342,12 +370,16 @@ _client_open(LV2_OSC_Reader *reader, LV2_OSC_Arg *arg, const LV2_OSC_Tree *tree,
return;
}
+ const nsmc_event_t ev_show = {
+ .type = NSMC_EVENT_TYPE_SHOW
+ };
+
// always show gui if server does not support optional gui
if(!(nsm->capability & NSMC_CAPABILITY_OPTIONAL_GUI))
{
- if(nsm->driver->show)
+ if(nsm->callback(nsm->data, &ev_show) != 0)
{
- nsm->driver->show(nsm->data);
+ //FIXME report error
}
return;
@@ -358,7 +390,7 @@ _client_open(LV2_OSC_Reader *reader, LV2_OSC_Arg *arg, const LV2_OSC_Tree *tree,
? nsm->driver->visibility(nsm->data)
: false;
- if(visibility && nsm->driver->show && (nsm->driver->show(nsm->data) == 0) )
+ if(visibility && (nsm->callback(nsm->data, &ev_show) == 0) )
{
_nsmc_message_vararg(nsm, "/nsm/client/gui_is_shown", "");
}
@@ -373,9 +405,12 @@ _client_save(LV2_OSC_Reader *reader, LV2_OSC_Arg *arg, const LV2_OSC_Tree *tree,
void *data)
{
nsmc_t *nsm = data;
+ const nsmc_event_t ev_save = {
+ .type = NSMC_EVENT_TYPE_SAVE
+ };
// save app
- if(nsm->driver->save && nsm->driver->save(nsm->data))
+ if(nsm->callback(nsm->data, &ev_save) != 0)
{
fprintf(stderr, "NSM save failed:\n");
}
@@ -395,16 +430,16 @@ _client_show_optional_gui(LV2_OSC_Reader *reader, LV2_OSC_Arg *arg,
const LV2_OSC_Tree *tree, void *data)
{
nsmc_t *nsm = data;
+ const nsmc_event_t ev_show = {
+ .type = NSMC_EVENT_TYPE_SHOW
+ };
// show gui
if( (nsm->driver->capability & NSMC_CAPABILITY_OPTIONAL_GUI)
- && nsm->driver->show
- && (nsm->driver->show(nsm->data) == 0) )
+ && (nsm->callback(nsm->data, &ev_show) == 0) )
{
nsmc_shown(nsm);
}
-
- fprintf(stderr, "NSM show GUI failed\n");
}
static void
@@ -412,16 +447,16 @@ _client_hide_optional_gui(LV2_OSC_Reader *reader, LV2_OSC_Arg *arg,
const LV2_OSC_Tree *tree, void *data)
{
nsmc_t *nsm = data;
+ const nsmc_event_t ev_hide = {
+ .type = NSMC_EVENT_TYPE_HIDE
+ };
// hide gui
if( (nsm->driver->capability & NSMC_CAPABILITY_OPTIONAL_GUI)
- && nsm->driver->hide
- && (nsm->driver->hide(nsm->data) == 0) )
+ && (nsm->callback(nsm->data, &ev_hide) == 0) )
{
nsmc_hidden(nsm);
}
-
- fprintf(stderr, "NSM hide GUI failed\n");
}
static int
@@ -516,7 +551,7 @@ static const LV2_OSC_Driver driver = {
NSMC_API nsmc_t *
nsmc_new(const char *call, const char *exe, const char *fallback_path,
- const nsmc_driver_t *nsm_driver, void *data)
+ const nsmc_driver_t *nsm_driver, nsmc_callback_t nsm_callback, void *data)
{
if(!nsm_driver)
{
@@ -530,6 +565,7 @@ nsmc_new(const char *call, const char *exe, const char *fallback_path,
}
nsm->driver = nsm_driver;
+ nsm->callback = nsm_callback;
nsm->data = data;
nsm->call = call ? strdup(call) : NULL;
@@ -543,7 +579,7 @@ nsmc_new(const char *call, const char *exe, const char *fallback_path,
nsm->url = strdup(nsm->url); //FIXME
if(!nsm->url)
{
- return NULL;
+ return NULL; //FIXME free
}
// remove trailing slash
@@ -555,18 +591,18 @@ nsmc_new(const char *call, const char *exe, const char *fallback_path,
nsm->tx = varchunk_new(8192, false);
if(!nsm->tx)
{
- return NULL;
+ return NULL; //FIXME free
}
nsm->rx = varchunk_new(8192, false);
if(!nsm->rx)
{
- return NULL;
+ return NULL; //FIXME free
}
if(lv2_osc_stream_init(&nsm->stream, nsm->url, &driver, nsm) != 0)
{
- return NULL;
+ return NULL; //FIXME free
}
}
else if(fallback_path)
@@ -578,9 +614,19 @@ nsmc_new(const char *call, const char *exe, const char *fallback_path,
resolvedfallback_path = fallback_path;
}
- if(nsm->driver->open && nsm->driver->open(resolvedfallback_path, "unmanaged", nsm->call, nsm->data))
+ const nsmc_event_t ev_open = {
+ .type = NSMC_EVENT_TYPE_OPEN,
+ .open = {
+ .path = resolvedfallback_path,
+ .name = "unmanaged",
+ .id = nsm->call
+ }
+ };
+
+ if(nsm->callback(nsm->data, &ev_open) != 0)
{
fprintf(stderr, "NSM load failed: '%s'\n", fallback_path);
+ return NULL; //FIXME free
}
}