aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-01-18 11:26:34 +0100
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-01-18 11:26:34 +0100
commit6ede93794e2ce14a5f279e421f166b370546424b (patch)
treeadeab7f5961e1abb9873e0e4628e56ad07849df7
parent1cb4f59708279c8fba18eb670baed759a535a72b (diff)
downloadsynthpod-6ede93794e2ce14a5f279e421f166b370546424b.zip
synthpod-6ede93794e2ce14a5f279e421f166b370546424b.tar.gz
synthpod-6ede93794e2ce14a5f279e421f166b370546424b.tar.bz2
synthpod-6ede93794e2ce14a5f279e421f166b370546424b.tar.xz
nsmc/bin: externalize fallback path.
-rw-r--r--VERSION2
-rw-r--r--bin/synthpod_bin.c20
-rw-r--r--nsmc/nsmc.h41
3 files changed, 32 insertions, 31 deletions
diff --git a/VERSION b/VERSION
index 22bee49..cef6afc 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.5891
+0.1.5893
diff --git a/bin/synthpod_bin.c b/bin/synthpod_bin.c
index 2c476b0..79b8ccb 100644
--- a/bin/synthpod_bin.c
+++ b/bin/synthpod_bin.c
@@ -417,13 +417,31 @@ __realtime void
bin_run(bin_t *bin, char **argv, const nsmc_driver_t *nsm_driver,
void (*idle)(void *data), void *data)
{
+ char *fallback_path = NULL;
+
bin->argv = argv;
bin->optind = optind;
+ if(!argv[optind])
+ {
+ const char *home_dir = getenv("HOME");
+
+ if(asprintf(&fallback_path, "%s/.lv2/Synthpod_default.preset.lv2/", home_dir) == -1)
+ {
+ fallback_path = NULL;
+ }
+ }
+
// NSM init
const char *exe = strrchr(argv[0], '/');
exe = exe ? exe + 1 : argv[0]; // we only want the program name without path
- bin->nsm = nsmc_new(exe, argv[optind], nsm_driver, bin); //TODO check
+ bin->nsm = nsmc_new("Synthpod", exe, fallback_path ? fallback_path : argv[optind],
+ nsm_driver, bin); //TODO check
+
+ if(fallback_path)
+ {
+ free(fallback_path);
+ }
pthread_t self = pthread_self();
diff --git a/nsmc/nsmc.h b/nsmc/nsmc.h
index 138749e..814c3d6 100644
--- a/nsmc/nsmc.h
+++ b/nsmc/nsmc.h
@@ -26,6 +26,8 @@ extern "C" {
# define NSMC_API static
#endif
+#include <stdbool.h>
+
typedef struct _nsmc_t nsmc_t;
typedef struct _nsmc_driver_t nsmc_driver_t;
@@ -43,7 +45,7 @@ struct _nsmc_driver_t {
};
NSMC_API nsmc_t *
-nsmc_new(const char *exe, const char *path,
+nsmc_new(const char *call, const char *exe, const char *fallback_path,
const nsmc_driver_t *driver, void *data);
NSMC_API void
@@ -333,7 +335,7 @@ static const LV2_OSC_Driver driver = {
};
NSMC_API nsmc_t *
-nsmc_new(const char *exe, const char *path,
+nsmc_new(const char *call, const char *exe, const char *fallback_path,
const nsmc_driver_t *nsm_driver, void *data)
{
if(!nsm_driver)
@@ -346,7 +348,7 @@ nsmc_new(const char *exe, const char *path,
nsm->driver = nsm_driver;
nsm->data = data;
- nsm->call = strdup("Synthpod");
+ nsm->call = call ? strdup(call) : NULL;
nsm->exe = exe ? strdup(exe) : NULL;
nsm->url = getenv("NSM_URL");
@@ -374,34 +376,15 @@ nsmc_new(const char *exe, const char *path,
if(lv2_osc_stream_init(&nsm->stream, nsm->url, &driver, nsm) != 0)
return NULL;
}
- else
+ else if(fallback_path)
{
- nsm->managed = false;
-
- if(path)
- {
- char tmp [PATH_MAX];
- const char *resolvedpath = realpath(path, tmp);
- if(!resolvedpath)
- resolvedpath = path;
+ char tmp [PATH_MAX];
+ const char *resolvedfallback_path = realpath(fallback_path, tmp);
+ if(!resolvedfallback_path)
+ resolvedfallback_path = fallback_path;
- if(nsm->driver->open && nsm->driver->open(resolvedpath, nsm->call, nsm->exe, nsm->data))
- fprintf(stderr, "NSM load failed: '%s'\n", path);
- }
- else
- {
- const char *home_dir = getenv("HOME");
-
- char *synthpod_dir = NULL;
- asprintf(&synthpod_dir, "%s/.lv2/Synthpod_default.preset.lv2", home_dir);
- if(synthpod_dir)
- {
- if(nsm->driver->open && nsm->driver->open(synthpod_dir, nsm->call, nsm->exe, nsm->data))
- fprintf(stderr, "NSM load failed: '%s'\n", synthpod_dir);
-
- free(synthpod_dir);
- }
- }
+ if(nsm->driver->open && nsm->driver->open(resolvedfallback_path, nsm->call, nsm->exe, nsm->data))
+ fprintf(stderr, "NSM load failed: '%s'\n", fallback_path);
}
return nsm;