From c12a00ba4d29bedcae4165e0ff18e79f809c1036 Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 20 Aug 2024 12:38:13 +0200 Subject: [PATCH] Add activate and preload commands Signed-off-by: falkTX --- README.md | 13 ++++++++++++- src/effects.c | 37 +++++++++++++++++++++++++++++++++++-- src/effects.h | 3 ++- src/mod-host.c | 18 +++++++++++++++++- src/mod-host.h | 2 ++ 5 files changed, 68 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 42b7f2a..b1f2fcd 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Commands (or Protocol) The commands supported by mod-host are: add - * add an LV2 plugin encapsulated as a jack client + * add an LV2 plugin encapsulated as a jack client, in activated state e.g.: add "http://lv2plug.in/plugins/eg-amp" 0 instance_number must be any value between 0 ~ 9990, inclusively @@ -116,6 +116,17 @@ The commands supported by mod-host are: e.g.: remove 0 when instance_number is -1 all plugins will be removed + activate + * toggle effect activated state + e.g.: activate 0 1 + if bypass_value = 1 activate effect + if bypass_value = 0 deactivate effect + + preload + * add an LV2 plugin encapsulated as a jack client, in deactivated state + e.g.: preload "http://lv2plug.in/plugins/eg-amp" 0 + instance_number must be any value between 0 ~ 9990, inclusively + preset_load * load a preset state of an effect instance e.g.: preset_load 0 "http://drobilla.net/plugins/mda/presets#JX10-moogcury-lite" diff --git a/src/effects.c b/src/effects.c index 5281193..c0df983 100644 --- a/src/effects.c +++ b/src/effects.c @@ -428,6 +428,8 @@ typedef struct EFFECT_T { jack_ringbuffer_t *events_out_buffer; char *events_in_buffer_helper; + bool activated; + // previous transport state bool transport_rolling; uint32_t transport_frame; @@ -1713,7 +1715,7 @@ static int ProcessPlugin(jack_nframes_t nframes, void *arg) if (arg == NULL) return 0; effect = arg; - if (!g_processing_enabled || ( + if (!g_processing_enabled || !effect->activated || ( (effect->hints & HINT_STATE_UNSAFE) && pthread_mutex_trylock(&effect->state_restore_mutex) != 0)) { for (i = 0; i < effect->output_audio_ports_count; i++) @@ -4538,7 +4540,7 @@ int effects_finish(int close_client) return SUCCESS; } -int effects_add(const char *uri, int instance) +int effects_add(const char *uri, int instance, int activate) { unsigned int ports_count; char effect_name[32], port_name[MAX_CHAR_BUF_SIZE+1]; @@ -4579,6 +4581,7 @@ int effects_add(const char *uri, int instance) /* Init the struct */ mod_memset(effect, 0, sizeof(effect_t)); effect->instance = instance; + effect->activated = activate; /* Init the pointers */ plugin_uri = NULL; @@ -5967,6 +5970,36 @@ int effects_remove(int effect_id) return SUCCESS; } +int effects_activate(int effect_id, int value) +{ + if (!InstanceExist(effect_id)) + { + return ERR_INSTANCE_NON_EXISTS; + } + + effect_t *effect = &g_effects[effect_id]; + + if (value) + { + if (! effect->activated) + { + lilv_instance_deactivate(effect->lilv_instance); + lilv_instance_activate(effect->lilv_instance); + + effect->activated = true; + } + } + else + { + if (effect->activated) + { + effect->activated = false; + } + } + + return SUCCESS; +} + int effects_connect(const char *portA, const char *portB) { int ret; diff --git a/src/effects.h b/src/effects.h index c0adebe..b0f550a 100644 --- a/src/effects.h +++ b/src/effects.h @@ -135,8 +135,9 @@ typedef struct { int effects_init(void* client); int effects_finish(int close_client); -int effects_add(const char *uri, int instance); +int effects_add(const char *uri, int instance, int activate); int effects_remove(int effect_id); +int effects_activate(int effect_id, int value); int effects_preset_load(int effect_id, const char *uri); int effects_preset_save(int effect_id, const char *dir, const char *file_name, const char *label); int effects_preset_show(const char *uri, char **state_str); diff --git a/src/mod-host.c b/src/mod-host.c index 4b4d5d9..302aada 100644 --- a/src/mod-host.c +++ b/src/mod-host.c @@ -131,7 +131,7 @@ static pthread_t intclient_socket_thread; static void effects_add_cb(proto_t *proto) { int resp; - resp = effects_add(proto->list[1], atoi(proto->list[2])); + resp = effects_add(proto->list[1], atoi(proto->list[2]), 1); protocol_response_int(resp, proto); } @@ -142,6 +142,20 @@ static void effects_remove_cb(proto_t *proto) protocol_response_int(resp, proto); } +static void effects_activate_cb(proto_t *proto) +{ + int resp; + resp = effects_activate(atoi(proto->list[1]), atoi(proto->list[2])); + protocol_response_int(resp, proto); +} + +static void effects_preload_cb(proto_t *proto) +{ + int resp; + resp = effects_add(proto->list[1], atoi(proto->list[2]), 0); + protocol_response_int(resp, proto); +} + static void effects_preset_save_cb(proto_t *proto) { int resp; @@ -674,6 +688,8 @@ static int mod_host_init(jack_client_t* client, int socket_port, int feedback_po /* Setup the protocol */ protocol_add_command(EFFECT_ADD, effects_add_cb); protocol_add_command(EFFECT_REMOVE, effects_remove_cb); + protocol_add_command(EFFECT_ACTIVATE, effects_activate_cb); + protocol_add_command(EFFECT_PRELOAD, effects_preload_cb); protocol_add_command(EFFECT_PRESET_LOAD, effects_preset_load_cb); protocol_add_command(EFFECT_PRESET_SAVE, effects_preset_save_cb); protocol_add_command(EFFECT_PRESET_SHOW, effects_preset_show_cb); diff --git a/src/mod-host.h b/src/mod-host.h index 3ded3d2..5690c05 100644 --- a/src/mod-host.h +++ b/src/mod-host.h @@ -53,6 +53,8 @@ /* Protocol commands definition */ #define EFFECT_ADD "add %s %i" #define EFFECT_REMOVE "remove %i" +#define EFFECT_ACTIVATE "activate %i %i" +#define EFFECT_PRELOAD "preload %s %i" #define EFFECT_PRESET_LOAD "preset_load %i %s" #define EFFECT_PRESET_SAVE "preset_save %i %s %s %s" #define EFFECT_PRESET_SHOW "preset_show %s"