Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new commands #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ The commands supported by mod-host are:
* show the preset information of requested instance / URI
e.g.: preset_show 0 http://drobilla.net/plugins/mda/presets#EPiano-bright

list_uris
* list current effect instances with its URIs

list_bundles
* list current effect instances with its bundle names

list_uris
* list current effect instances with its URIs

list_bundles
* list current effect instances with its bundle names

connect <origin_port> <destination_port>
* connect two effect audio ports
e.g.: connect system:capture_1 effect_0:in
Expand All @@ -122,6 +134,14 @@ The commands supported by mod-host are:
if bypass_value = 1 bypass effect
if bypass_value = 0 process effect

preset_list <instance_number>
* show the preset list of requested instance
e.g.: preset_list 0

preset_list <instance_number>
* show the preset list of requested instance
e.g.: preset_list 0

param_set <instance_number> <param_symbol> <param_value>
* set a value to given control
e.g.: param_set 0 gain 2.50
Expand All @@ -130,6 +150,14 @@ The commands supported by mod-host are:
* get the value of the request control
e.g.: param_get 0 gain

param_info <instance_number> <param_symbol>
* get range info and scale points for a given instance's parameter
e.g.: param_info 0 gain

param_info <instance_number> <param_symbol>
* get range info and scale points for a given instance's parameter
e.g.: param_info 0 gain

param_monitor <instance_number> <param_symbol> <cond_op> <value>
* do monitoring a effect instance control port according given condition
e.g: param_monitor 0 gain > 2.50
Expand Down
36 changes: 35 additions & 1 deletion src/effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -3633,6 +3633,40 @@ int effects_disconnect(const char *portA, const char *portB)
return ret;
}

int effects_list_uris(int *instances, const char **effects)
{
int i;
int n=0;
for (i=0;i<MAX_INSTANCES;i++) {
if (InstanceExist(i)) {
const LilvNode *lilv_uri = lilv_plugin_get_uri(g_effects[i].lilv_plugin);
if (lilv_uri) {
instances[n]=i;
effects[n++] = lilv_node_as_uri(lilv_uri);
}
}
}
effects[n] = NULL;
return n;
}

int effects_list_bundles(int *instances, const char **effects)
{
int i;
int n=0;
for (i=0;i<MAX_INSTANCES;i++) {
if (InstanceExist(i)) {
const LilvNode *lilv_uri = lilv_plugin_get_bundle_uri(g_effects[i].lilv_plugin);
if (lilv_uri) {
instances[n]=i;
effects[n++] = lilv_node_as_uri(lilv_uri);
}
}
}
effects[n] = NULL;
return n;
}

int effects_set_parameter(int effect_id, const char *control_symbol, float value)
{
port_t *port;
Expand Down Expand Up @@ -3867,7 +3901,7 @@ int effects_get_presets_uris(int effect_id, const char **uris)

uris[i] = NULL;

return SUCCESS;
return effect->presets_count;
}

int effects_get_parameter_info(int effect_id, const char *control_symbol, float **range, const char **scale_points)
Expand Down
2 changes: 2 additions & 0 deletions src/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ int effects_preset_save(int effect_id, const char *dir, const char *file_name, c
int effects_preset_show(const char *uri, char **state_str);
int effects_connect(const char *portA, const char *portB);
int effects_disconnect(const char *portA, const char *portB);
int effects_list_uris(int *instances, const char **effects);
int effects_list_bundles(int *instances, const char **effects);
int effects_set_parameter(int effect_id, const char *control_symbol, float value);
int effects_set_property(int effect_id, const char *label, const char *value);
int effects_get_parameter(int effect_id, const char *control_symbol, float *value);
Expand Down
119 changes: 118 additions & 1 deletion src/mod-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,58 @@ static void effects_remove_cb(proto_t *proto)
protocol_response(buffer, proto);
}

static void effects_list_uris_cb(proto_t *proto)
{
int resp;
const char **effects = (const char **) calloc(MAX_INSTANCES, sizeof(char *));
int *instances = (int *) malloc(MAX_INSTANCES*sizeof(int));
char *buffer = NULL;

resp = effects_list_uris(instances, effects);
if (resp >0) {
uint32_t i;
buffer = (char *) malloc(resp*128*sizeof(char));
sprintf(buffer, "resp %i", resp);
for (i = 0; effects[i]; i++) {
sprintf(buffer+strlen(buffer), " %d:%s", instances[i], effects[i]);
if (effects[i+1]) sprintf(buffer+strlen(buffer), ",");
}
} else {
buffer = (char *) malloc(128*sizeof(char));
sprintf(buffer, "resp %i", resp);
}
protocol_response(buffer, proto);

free(effects);
free(buffer);
}

static void effects_list_bundles_cb(proto_t *proto)
{
int resp;
const char **effects = (const char **) calloc(MAX_INSTANCES, sizeof(char *));
int *instances = (int *) malloc(MAX_INSTANCES*sizeof(int));
char *buffer = NULL;

resp = effects_list_bundles(instances, effects);
if (resp >0) {
uint32_t i;
buffer = (char *) malloc(resp*128*sizeof(char));
sprintf(buffer, "resp %i", resp);
for (i = 0; effects[i]; i++) {
sprintf(buffer+strlen(buffer), " %d:%s", instances[i], effects[i]);
if (effects[i+1]) sprintf(buffer+strlen(buffer), ",");
}
} else {
buffer = (char *) malloc(128*sizeof(char));
sprintf(buffer, "resp %i", resp);
}
protocol_response(buffer, proto);

free(effects);
free(buffer);
}

static void effects_preset_save_cb(proto_t *proto)
{
int resp;
Expand Down Expand Up @@ -179,6 +231,31 @@ static void effects_preset_show_cb(proto_t *proto)
protocol_response("", proto);
}

static void effects_preset_list_cb(proto_t *proto)
{
int resp;
char **presets = (char **) calloc(32*128, sizeof(char *));
char *buffer = NULL;

resp = effects_get_presets_uris(atoi(proto->list[1]), presets);
if (resp>0) {
uint32_t i;
buffer = (char *) malloc(resp*128*sizeof(char));
sprintf(buffer, "resp %i", resp);
for (i = 0; presets[i]; i++) {
sprintf(buffer+strlen(buffer)," %s", presets[i]);
if (presets[i+1]) sprintf(buffer+strlen(buffer),",");
}
} else {
buffer = (char *) malloc(128*sizeof(char));
sprintf(buffer, "resp %i", resp);
}
protocol_response(buffer, proto);

free(presets);
free(buffer);
}

static void effects_connect_cb(proto_t *proto)
{
int resp;
Expand Down Expand Up @@ -238,6 +315,43 @@ static void effects_get_param_cb(proto_t *proto)
protocol_response(buffer, proto);
}

static void effects_get_param_info_cb(proto_t *proto)
{
int resp;
/* Create a array of strings for scale points */
const char **scale_points = (const char **) calloc(256, sizeof(char *));
/* Allocates memory to parameter range */
float **param_range = (float **) calloc(4, sizeof(float *));
param_range[0] = (float *) malloc(sizeof(float));
param_range[1] = (float *) malloc(sizeof(float));
param_range[2] = (float *) malloc(sizeof(float));
param_range[3] = (float *) malloc(sizeof(float));

resp = effects_get_parameter_info(atoi(proto->list[1]), proto->list[2], param_range, scale_points);
char buffer[1024];
if (resp >= 0) {
sprintf(buffer, "resp %i def: %.03f, min: %.03f, max: %.03f, curr: %.03f",
resp, *param_range[0], *param_range[1], *param_range[2], *param_range[3]);
if (scale_points[0]) {
uint32_t i;
sprintf(buffer,", scale points: ");
for (i = 0; scale_points[i]; i+=2) {
sprintf(buffer,"(%s: %s)", scale_points[i], scale_points[i+1]);
}
}
} else {
sprintf(buffer, "resp %i", resp);
}
protocol_response(buffer, proto);

/*Free memory*/
free(scale_points);
free(param_range[0]);
free(param_range[1]);
free(param_range[2]);
free(param_range[3]);
}

static void effects_monitor_param_cb(proto_t *proto)
{
int resp;
Expand Down Expand Up @@ -578,14 +692,18 @@ 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_LIST_URIS, effects_list_uris_cb);
protocol_add_command(EFFECT_LIST_BUNDLES, effects_list_bundles_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);
protocol_add_command(EFFECT_PRESET_LIST, effects_preset_list_cb);
protocol_add_command(EFFECT_CONNECT, effects_connect_cb);
protocol_add_command(EFFECT_DISCONNECT, effects_disconnect_cb);
protocol_add_command(EFFECT_BYPASS, effects_bypass_cb);
protocol_add_command(EFFECT_PARAM_SET, effects_set_param_cb);
protocol_add_command(EFFECT_PARAM_GET, effects_get_param_cb);
protocol_add_command(EFFECT_PARAM_INFO, effects_get_param_info_cb);
protocol_add_command(EFFECT_PARAM_MON, effects_monitor_param_cb);
protocol_add_command(EFFECT_LICENSEE, effects_licensee_cb);
protocol_add_command(MONITOR_ADDR_SET, monitor_addr_set_cb);
Expand Down Expand Up @@ -635,7 +753,6 @@ static void* intclient_socket_run(void* ptr)
(void)ptr;
}


/*
************************************************************************************************************************
* MAIN FUNCTION
Expand Down
4 changes: 4 additions & 0 deletions src/mod-host.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@
/* Protocol commands definition */
#define EFFECT_ADD "add %s %i"
#define EFFECT_REMOVE "remove %i"
#define EFFECT_LIST_URIS "list_uris"
#define EFFECT_LIST_BUNDLES "list_bundles"
#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"
#define EFFECT_PRESET_LIST "preset_list %i"
#define EFFECT_CONNECT "connect %s %s"
#define EFFECT_DISCONNECT "disconnect %s %s"
#define EFFECT_BYPASS "bypass %i %i"
#define EFFECT_PARAM_SET "param_set %i %s %s"
#define EFFECT_PARAM_GET "param_get %i %s"
#define EFFECT_PARAM_INFO "param_info %i %s"
#define EFFECT_PARAM_MON "param_monitor %i %s %s %f"
#define EFFECT_LICENSEE "licensee %i"
#define MONITOR_ADDR_SET "monitor %s %i %i"
Expand Down