aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2019-11-02 22:15:18 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2019-11-02 22:15:18 +0100
commit7452282d077a0ca685bee07b9f1a967d5b35bdaa (patch)
treec014a864f8679e2f39afaa2159f471f0ff268e14
parenta60ac771f44054fb3371905cc0e1ed4c612189d2 (diff)
downloadsynthpod-master.tar.xz
nsm: store visibility state in state.HEADmaster
-rw-r--r--VERSION2
-rw-r--r--app/synthpod_app.c24
-rw-r--r--app/synthpod_app_private.h2
-rw-r--r--app/synthpod_app_state.c14
-rw-r--r--bin/synthpod_alsa.c9
-rw-r--r--bin/synthpod_bin.c137
-rw-r--r--bin/synthpod_bin.h3
-rw-r--r--bin/synthpod_dummy.c9
-rw-r--r--bin/synthpod_jack.c9
-rw-r--r--include/synthpod_app.h6
-rw-r--r--include/synthpod_private.h3
-rw-r--r--nsmc/nsmc.h64
12 files changed, 197 insertions, 85 deletions
diff --git a/VERSION b/VERSION
index 1d07d21b..3626a6ed 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.6137
+0.1.6139
diff --git a/app/synthpod_app.c b/app/synthpod_app.c
index 2301d790..edcc73b5 100644
--- a/app/synthpod_app.c
+++ b/app/synthpod_app.c
@@ -808,6 +808,8 @@ sp_app_new(const LilvWorld *world, sp_app_driver_t *driver, void *data)
if(!app)
return NULL;
+ atomic_init(&app->visibility, false);
+
atomic_init(&app->dirty, false);
app->dir.home = getenv("HOME");
@@ -1553,3 +1555,25 @@ sp_app_xrun_report(sp_app_t *app)
atomic_store(&dsp_master->xrun_report, true);
}
+
+void
+sp_app_visibility_set(sp_app_t *app, bool visibility)
+{
+ if(!app)
+ {
+ return;
+ }
+
+ atomic_store(&app->visibility, visibility);
+}
+
+bool
+sp_app_visibility_get(sp_app_t *app)
+{
+ if(!app)
+ {
+ return false;
+ }
+
+ return atomic_load(&app->visibility);
+}
diff --git a/app/synthpod_app_private.h b/app/synthpod_app_private.h
index 514b8a2e..91901e1c 100644
--- a/app/synthpod_app_private.h
+++ b/app/synthpod_app_private.h
@@ -445,6 +445,8 @@ struct _sp_app_t {
sp_app_driver_t *driver;
void *data;
+ atomic_bool visibility;
+
atomic_bool dirty;
unsigned skip_reweighting;
diff --git a/app/synthpod_app_state.c b/app/synthpod_app_state.c
index 224e7829..bd3f8682 100644
--- a/app/synthpod_app_state.c
+++ b/app/synthpod_app_state.c
@@ -906,6 +906,12 @@ sp_app_save(sp_app_t *app, LV2_State_Store_Function store,
}
*/
+ // store visibility
+ const int32_t visibility = sp_app_visibility_get(app);
+ store(hndl, app->regs.synthpod.visibility.urid,
+ &visibility, sizeof(int32_t), app->forge.Bool,
+ LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE);
+
// store minor version
const int32_t minor_version = SYNTHPOD_MINOR_VERSION;
store(hndl, app->regs.core.minor_version.urid,
@@ -1524,6 +1530,14 @@ sp_app_restore(sp_app_t *app, LV2_State_Retrieve_Function retrieve,
uint32_t _flags;
uint32_t type;
+ // retrieve visibility
+ const int32_t *visibility = retrieve(hndl, app->regs.synthpod.visibility.urid,
+ &size, &type, &_flags);
+ if(visibility && (type == app->forge.Bool) && (size == sizeof(int32_t)) )
+ {
+ sp_app_visibility_set(app, *visibility);
+ }
+
// retrieve minor version
const int32_t *minor_version = retrieve(hndl, app->regs.core.minor_version.urid,
&size, &type, &_flags);
diff --git a/bin/synthpod_alsa.c b/bin/synthpod_alsa.c
index 63997039..ae67b24b 100644
--- a/bin/synthpod_alsa.c
+++ b/bin/synthpod_alsa.c
@@ -849,11 +849,20 @@ _hide(void *data)
return bin_hide(bin);
}
+__non_realtime static bool
+_visibility(void *data)
+{
+ bin_t *bin = data;
+
+ return bin_visibility(bin);
+}
+
static const nsmc_driver_t nsm_driver = {
.open = _open,
.save = _save,
.show = _show,
.hide = _hide,
+ .visibility = _visibility,
.supports_switch = true
};
diff --git a/bin/synthpod_bin.c b/bin/synthpod_bin.c
index 1f7fdf60..db44cab5 100644
--- a/bin/synthpod_bin.c
+++ b/bin/synthpod_bin.c
@@ -519,7 +519,10 @@ bin_run(bin_t *bin, const char *name, char **argv, const nsmc_driver_t *nsm_driv
bin->child = 0; // invalidate
if(nsmc_managed())
+ {
+ sp_app_visibility_set(bin->app, false);
nsmc_hidden(bin->nsm);
+ }
if(bin->kill_gui)
atomic_store_explicit(&done, true, memory_order_relaxed);
@@ -577,13 +580,87 @@ bin_run(bin_t *bin, const char *name, char **argv, const nsmc_driver_t *nsm_driv
}
}
+int
+bin_show(bin_t *bin)
+{
+ char srate [32];
+ char urate [32];
+ char wname [384];
+ char minimum [32];
+ snprintf(srate, sizeof(srate), "%"PRIu32, bin->sample_rate);
+ snprintf(urate, sizeof(urate), "%"PRIu32, bin->update_rate);
+ snprintf(wname, sizeof(wname), "Synthpod - %s", bin->socket_path);
+ snprintf(minimum, sizeof(minimum), "%zu", SBOX_BUF_SIZE);
+
+ bin->child = vfork();
+ if(bin->child == 0) // child
+ {
+ char *const args [] = {
+ "synthpod_sandbox_x11",
+ "-p", SYNTHPOD_STEREO_URI,
+ "-P", SYNTHPOD_PLUGIN_DIR,
+#if 0
+ "-u", SYNTHPOD_ROOT_D2TK_URI,
+#else
+ "-u", SYNTHPOD_ROOT_NK_URI,
+#endif
+ "-U", SYNTHPOD_PLUGIN_DIR,
+ "-s", (char *)bin->socket_path,
+ "-w", wname,
+ "-m", minimum,
+ "-r", srate,
+ "-f", urate,
+ NULL
+ };
+
+ execvp(args[0], args);
+ }
+ else if(bin->child == -1)
+ {
+ return -1;
+ }
+
+ sp_app_visibility_set(bin->app, true);
+
+ return 0;
+}
+
+static int
+_bin_hide(bin_t *bin)
+{
+ if(bin->child > 0)
+ {
+ int status;
+
+ kill(bin->child, SIGINT);
+ waitpid(bin->child, &status, WUNTRACED); // blocking waitpid
+ bin->child = 0;
+ }
+
+ return 0;
+}
+
+int
+bin_hide(bin_t *bin)
+{
+ sp_app_visibility_set(bin->app, false);
+
+ return _bin_hide(bin);
+}
+
+bool
+bin_visibility(bin_t *bin)
+{
+ return sp_app_visibility_get(bin->app);
+}
+
__non_realtime void
bin_stop(bin_t *bin)
{
// NSM deinit
nsmc_free(bin->nsm);
- bin_hide(bin);
+ _bin_hide(bin);
if(bin->path)
free(bin->path);
@@ -776,61 +853,3 @@ bin_log_trace(bin_t *bin, const char *fmt, ...)
return ret;
}
-
-int
-bin_show(bin_t *bin)
-{
- char srate [32];
- char urate [32];
- char wname [384];
- char minimum [32];
- snprintf(srate, sizeof(srate), "%"PRIu32, bin->sample_rate);
- snprintf(urate, sizeof(urate), "%"PRIu32, bin->update_rate);
- snprintf(wname, sizeof(wname), "Synthpod - %s", bin->socket_path);
- snprintf(minimum, sizeof(minimum), "%zu", SBOX_BUF_SIZE);
-
- bin->child = vfork();
- if(bin->child == 0) // child
- {
- char *const args [] = {
- "synthpod_sandbox_x11",
- "-p", SYNTHPOD_STEREO_URI,
- "-P", SYNTHPOD_PLUGIN_DIR,
-#if 0
- "-u", SYNTHPOD_ROOT_D2TK_URI,
-#else
- "-u", SYNTHPOD_ROOT_NK_URI,
-#endif
- "-U", SYNTHPOD_PLUGIN_DIR,
- "-s", (char *)bin->socket_path,
- "-w", wname,
- "-m", minimum,
- "-r", srate,
- "-f", urate,
- NULL
- };
-
- execvp(args[0], args);
- }
- else if(bin->child == -1)
- {
- return -1;
- }
-
- return 0;
-}
-
-int
-bin_hide(bin_t *bin)
-{
- if(bin->child > 0)
- {
- int status;
-
- kill(bin->child, SIGINT);
- waitpid(bin->child, &status, WUNTRACED); // blocking waitpid
- bin->child = 0;
- }
-
- return 0;
-}
diff --git a/bin/synthpod_bin.h b/bin/synthpod_bin.h
index 78ad8a50..8f1863e7 100644
--- a/bin/synthpod_bin.h
+++ b/bin/synthpod_bin.h
@@ -169,4 +169,7 @@ bin_show(bin_t *bin);
int
bin_hide(bin_t *bin);
+bool
+bin_visibility(bin_t *bin);
+
#endif // _SYNTHPOD_BIN_H
diff --git a/bin/synthpod_dummy.c b/bin/synthpod_dummy.c
index 4179e8e5..9ffc620b 100644
--- a/bin/synthpod_dummy.c
+++ b/bin/synthpod_dummy.c
@@ -394,11 +394,20 @@ _hide(void *data)
return bin_hide(bin);
}
+__non_realtime static bool
+_visibility(void *data)
+{
+ bin_t *bin = data;
+
+ return bin_visibility(bin);
+}
+
static const nsmc_driver_t nsm_driver = {
.open = _open,
.save = _save,
.show = _show,
.hide = _hide,
+ .visibility = _visibility,
.supports_switch = true
};
diff --git a/bin/synthpod_jack.c b/bin/synthpod_jack.c
index 7f93a9c5..57ed6aa3 100644
--- a/bin/synthpod_jack.c
+++ b/bin/synthpod_jack.c
@@ -934,11 +934,20 @@ _hide(void *data)
return bin_hide(bin);
}
+__non_realtime static bool
+_visibility(void *data)
+{
+ bin_t *bin = data;
+
+ return bin_visibility(bin);
+}
+
static const nsmc_driver_t nsm_driver = {
.open = _open,
.save = _save,
.show = _show,
.hide = _hide,
+ .visibility = _visibility,
.supports_switch = true
};
diff --git a/include/synthpod_app.h b/include/synthpod_app.h
index 563d5398..5fbe539b 100644
--- a/include/synthpod_app.h
+++ b/include/synthpod_app.h
@@ -207,6 +207,12 @@ void
sp_app_bundle_save(sp_app_t *app, LV2_URID urn, bool via_app);
void
+sp_app_visibility_set(sp_app_t *app, bool visibility);
+
+bool
+sp_app_visibility_get(sp_app_t *app);
+
+void
sp_app_xrun_report(sp_app_t *app);
#endif // _SYNTHPOD_APP_H
diff --git a/include/synthpod_private.h b/include/synthpod_private.h
index 7f7744e6..50fbd4af 100644
--- a/include/synthpod_private.h
+++ b/include/synthpod_private.h
@@ -408,6 +408,7 @@ struct _reg_t {
reg_item_t learning;
reg_item_t placeholder;
+ reg_item_t visibility;
} synthpod;
struct {
@@ -702,6 +703,7 @@ sp_regs_init(reg_t *regs, LilvWorld *world, LV2_URID_Map *map)
_register(&regs->synthpod.learning, world, map, SYNTHPOD_PREFIX"learning");
_register(&regs->synthpod.placeholder, world, map, SYNTHPOD_PREFIX"placeholder");
+ _register(&regs->synthpod.visibility, world, map, SYNTHPOD_PREFIX"visibility");
_register(&regs->midi.Controller, world, map, LV2_MIDI__Controller);
_register(&regs->midi.channel, world, map, LV2_MIDI__channel);
@@ -961,6 +963,7 @@ sp_regs_deinit(reg_t *regs)
_unregister(&regs->synthpod.learning);
_unregister(&regs->synthpod.placeholder);
+ _unregister(&regs->synthpod.visibility);
_unregister(&regs->midi.Controller);
_unregister(&regs->midi.channel);
diff --git a/nsmc/nsmc.h b/nsmc/nsmc.h
index 93e9b4ee..8dd73f02 100644
--- a/nsmc/nsmc.h
+++ b/nsmc/nsmc.h
@@ -36,12 +36,14 @@ typedef int (*nsmc_open_t)(const char *path, const char *name,
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);
struct _nsmc_driver_t {
nsmc_open_t open;
nsmc_save_t save;
nsmc_show_t show;
nsmc_hide_t hide;
+ nsmc_visibility_t visibility;
bool supports_switch;
};
@@ -162,6 +164,41 @@ _client_open(LV2_OSC_Reader *reader, nsmc_t *nsm)
if(nsm->driver->open && nsm->driver->open(resolvedpath, name, id, nsm->data))
fprintf(stderr, "NSM load failed: '%s'\n", dir);
+
+ const bool has_gui = nsm->driver->show && nsm->driver->hide;
+ const bool visibility = nsm->driver->visibility
+ ? nsm->driver->visibility(nsm->data)
+ : false;
+
+ if(has_gui)
+ {
+ uint8_t *tx;
+ size_t max;
+ if( (tx = varchunk_write_request_max(nsm->tx, 1024, &max)) )
+ {
+ LV2_OSC_Writer writer;
+ lv2_osc_writer_initialize(&writer, tx, max);
+
+ if(visibility && (nsm->driver->show(nsm->data) == 0) )
+ {
+ lv2_osc_writer_message_vararg(&writer, "/nsm/client/gui_is_shown", "");
+ }
+ else
+ {
+ lv2_osc_writer_message_vararg(&writer, "/nsm/client/gui_is_hidden", "");
+ }
+
+ size_t written;
+ if(lv2_osc_writer_finalize(&writer, &written))
+ {
+ varchunk_write_advance(nsm->tx, written);
+ }
+ else
+ {
+ fprintf(stderr, "OSC sending failed\n");
+ }
+ }
+ }
}
static void
@@ -225,31 +262,8 @@ _announce(nsmc_t *nsm)
LV2_OSC_Writer writer;
lv2_osc_writer_initialize(&writer, tx, max);
- LV2_OSC_Writer_Frame bndl = {0}, itm = {0};
- lv2_osc_writer_push_bundle(&writer, &bndl, LV2_OSC_IMMEDIATE);
- {
- lv2_osc_writer_push_item(&writer, &itm);
- lv2_osc_writer_message_vararg(&writer, "/nsm/server/announce", "sssiii",
- nsm->call, capabilities, nsm->exe, 1, 2, pid);
- lv2_osc_writer_pop_item(&writer, &itm);
- }
- if(has_gui)
- {
- // report initial gui visibility //FIXME should be saved in state somewhere
- if(nsm->driver->show(nsm->data) == 0)
- {
- lv2_osc_writer_push_item(&writer, &itm);
- lv2_osc_writer_message_vararg(&writer, "/nsm/client/gui_is_shown", "");
- lv2_osc_writer_pop_item(&writer, &itm);
- }
- else
- {
- lv2_osc_writer_push_item(&writer, &itm);
- lv2_osc_writer_message_vararg(&writer, "/nsm/client/gui_is_hidden", "");
- lv2_osc_writer_pop_item(&writer, &itm);
- }
- }
- lv2_osc_writer_pop_bundle(&writer, &bndl);
+ lv2_osc_writer_message_vararg(&writer, "/nsm/server/announce", "sssiii",
+ nsm->call, capabilities, nsm->exe, 1, 2, pid);
size_t written;
if(lv2_osc_writer_finalize(&writer, &written))