Skip to content

Commit

Permalink
Add activate and preload commands
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Aug 20, 2024
1 parent 5ae41b2 commit c12a00b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 5 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Commands (or Protocol)
The commands supported by mod-host are:

add <lv2_uri> <instance_number>
* 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

Expand All @@ -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 <instance_number> <activate_value>
* toggle effect activated state
e.g.: activate 0 1
if bypass_value = 1 activate effect
if bypass_value = 0 deactivate effect

preload <lv2_uri> <instance_number>
* 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 <instance_number> <preset_uri>
* load a preset state of an effect instance
e.g.: preset_load 0 "http://drobilla.net/plugins/mda/presets#JX10-moogcury-lite"
Expand Down
37 changes: 35 additions & 2 deletions src/effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 17 additions & 1 deletion src/mod-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/mod-host.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c12a00b

Please sign in to comment.