From 7844efa60c29a617dcf3b434e4cab3f0ff85e216 Mon Sep 17 00:00:00 2001 From: Jamie Bullock Date: Wed, 10 Apr 2013 15:33:12 +0000 Subject: svn path=/trunk/externals/postlude/; revision=17084 --- pluginhost~/ph_common.c | 276 +++++++++++++++++++++++++----------------------- 1 file changed, 146 insertions(+), 130 deletions(-) (limited to 'pluginhost~/ph_common.c') diff --git a/pluginhost~/ph_common.c b/pluginhost~/ph_common.c index b81e276..e85f6fa 100644 --- a/pluginhost~/ph_common.c +++ b/pluginhost~/ph_common.c @@ -43,7 +43,8 @@ #include #include #include /* for exit() */ -#include /* for fork() */ +//#include /* for fork() */ +#include #include /* for kill() */ #include /* for readdir() */ #include /* for dlsym() */ @@ -408,96 +409,6 @@ static void ph_init_programs(ph *x, unsigned int i) } } -/* TODO:OSC */ -#if 0 -static void ph_load_gui(ph *x, int instance) -{ - t_int err = 0; - char *gui_path; - struct dirent *dir_entry = NULL; - char *gui_base; - size_t baselen; - DIR *dp; - char *gui_str; - - gui_base = (char *)malloc((baselen = sizeof(char) * (strlen(x->plugin_full_path) - strlen(".so"))) + 1); - - strncpy(gui_base, x->plugin_full_path, baselen); - gui_base[baselen] = '\0'; - - /* don't use strndup - GNU only */ - /* gui_base = strndup(x->plugin_full_path, baselen);*/ - ph_debug_post("gui_base: %s", gui_base); - - - gui_str = (char *)malloc(sizeof(char) * (strlen("channel 00") + 1)); - sprintf (gui_str,"channel %02d", instance); - - ph_debug_post("GUI name string, %s", gui_str); - - - if(!(dp = opendir(gui_base))){ - post("pluginhost~: unable to find GUI in %s, continuing without...", gui_base); - return; - } - else { - while((dir_entry = readdir(dp))){ - if (dir_entry->d_name[0] == '.') continue; - if (strchr(dir_entry->d_name, '_')){ - if (strstr(dir_entry->d_name, "gtk") || - strstr(dir_entry->d_name, "qt") || - strstr(dir_entry->d_name, "text")) - break; - } - } - ph_debug_post("GUI filename: %s", dir_entry->d_name); - - } - - gui_path = (char *)malloc(sizeof(char) * (strlen(gui_base) + strlen("/") + - strlen(dir_entry->d_name) + 1)); - - sprintf(gui_path, "%s/%s", gui_base, dir_entry->d_name); - - free(gui_base); - ph_debug_post("gui_path: %s", gui_path); - - - /* osc_url_base was of the form: - * osc.udp://127.0.0.1:9997/dssi - */ - osc_url = (char *)malloc - (sizeof(char) * (strlen(x->osc_url_base) + - strlen(instance->osc_url_path) + 2)); - - sprintf(osc_url, "%s/%s", x->osc_url_base, - instance->osc_url_path); - post("pluginhost~: instance %d URL: %s",instance, osc_url); - ph_debug_post("Trying to open GUI!"); - - - instance->gui_pid = fork(); - if (instance->gui_pid == 0){ - err = execlp(gui_path, gui_path, osc_url, dir_entry->d_name, - x->descriptor->LADSPA_Plugin->Label, gui_str, NULL); - perror("exec failed"); - exit(1); /* terminates the process */ - } - - ph_debug_post("errorcode = %d", err); - - - free(gui_path); - free(osc_url); - free(gui_str); - if(dp){ - - ph_debug_post("directory handle closed = %d", closedir(dp)); - - } -} -#endif - static t_int ph_configure_buffer_free(ph *x) { ph_configure_pair *curr, *prev; @@ -587,25 +498,26 @@ static void osc_setup(ph *x, unsigned int i) { ph_instance *instance = &x->instances[i]; + assert(x->plugin_basename); + if(i == 0){ x->osc_port = OSC_PORT; } instance->osc_url_path = malloc(sizeof(char) * (strlen(x->plugin_basename) + strlen(x->descriptor->LADSPA_Plugin->Label) + - //strlen("chan00") + 3)); - 6 + 3)); + strlen("chan00") + 3)); + //6 + 3)); sprintf(instance->osc_url_path, "%s/%s/chan%02d", x->plugin_basename, x->descriptor->LADSPA_Plugin->Label, i); ph_debug_post("OSC Path is: %s", instance->osc_url_path); - } /* ==================================== */ void ph_debug_post(const char *fmt, ...) { -#if DEBUG == 1 +#ifdef DEBUG unsigned int currpos; char newfmt[DEBUG_STRING_SIZE]; char result[DEBUG_STRING_SIZE]; @@ -762,15 +674,18 @@ char *ph_send_configure(ph *x, const char *key, const char *value, { char *debug; + ph_instance *instance = &x->instances[i]; + t_atom argv[3]; + t_int argc = 3; + debug = x->descriptor->configure(x->instance_handles[i], key, value); - /* TODO:OSC */ - /* if(instance->ui_target != NULL && x->is_dssi) { - lo_send(instance->ui_target, - instance->ui_osc_configure_path, - "ss", key, value); - } - */ + if(instance->ui_target != NULL && x->is_dssi) { + SETSYMBOL(argv, gensym(instance->ui_osc_configure_path)); + SETSYMBOL(argv+1, gensym(key)); + SETSYMBOL(argv+2, gensym(value)); + ph_instance_send_osc(x->message_out, instance, argc, argv); + } ph_query_programs(x, i); return debug; @@ -787,13 +702,102 @@ void ph_instance_send_osc(t_outlet *outlet, ph_instance *instance, } +void ph_load_gui(ph *x, unsigned int i) +{ + t_int err = 0; + char *gui_path = NULL; + struct dirent *dir_entry = NULL; + char *gui_base = NULL; + size_t baselen; + DIR *dp = NULL; + char *gui_str = NULL; + char *osc_url = NULL; + ph_instance *instance = &x->instances[i]; + + gui_base = (char *)malloc((baselen = sizeof(char) * (strlen(x->plugin_full_path) - strlen(".so"))) + 1); + + strncpy(gui_base, x->plugin_full_path, baselen); + gui_base[baselen] = '\0'; + + /* don't use strndup - GNU only */ + /* gui_base = strndup(x->plugin_full_path, baselen);*/ + ph_debug_post("gui_base: %s", gui_base); + + + gui_str = (char *)malloc(sizeof(char) * (strlen("channel 00") + 1)); + sprintf (gui_str,"channel %02d", i); + + ph_debug_post("GUI name string, %s", gui_str); + + + if(!(dp = opendir(gui_base))){ + post("pluginhost~: unable to find GUI in %s, continuing without...", gui_base); + return; + } + else { + while((dir_entry = readdir(dp))){ + if (dir_entry->d_name[0] == '.') continue; + if (strchr(dir_entry->d_name, '_')){ + if (strstr(dir_entry->d_name, "gtk") || + strstr(dir_entry->d_name, "qt") || + strstr(dir_entry->d_name, "text")) + break; + } + } + ph_debug_post("GUI filename: %s", dir_entry->d_name); + + } + + gui_path = (char *)malloc(sizeof(char) * (strlen(gui_base) + strlen("/") + + strlen(dir_entry->d_name) + 1)); + + sprintf(gui_path, "%s/%s", gui_base, dir_entry->d_name); + + free(gui_base); + ph_debug_post("gui_path: %s", gui_path); + + + /* osc_url_base was of the form: + * osc.udp://127.0.0.1:9997/dssi + */ + osc_url = (char *)malloc + (sizeof(char) * (strlen(x->osc_url_base) + + strlen(instance->osc_url_path) + 2)); + + sprintf(osc_url, "%s/%s", x->osc_url_base, + instance->osc_url_path); + post("pluginhost~: instance %d URL: %s",instance, osc_url); + ph_debug_post("Trying to open GUI!"); + + + instance->gui_pid = fork(); + if (instance->gui_pid == 0){ + err = execlp(gui_path, gui_path, osc_url, dir_entry->d_name, + x->descriptor->LADSPA_Plugin->Label, gui_str, NULL); + perror("exec failed"); + exit(1); /* terminates the process */ + } + + ph_debug_post("errorcode = %d", err); + + + free(gui_path); + free(osc_url); + free(gui_str); + if(dp){ + ph_debug_post("directory handle closed = %d", closedir(dp)); + } +} + void *ph_load_plugin(ph *x, t_int argc, t_atom *argv) { - char *plugin_basename = NULL, - *plugin_full_path = NULL, - *tmpstr, - *plugin_label, - plugin_dir[MAXPDSTRING]; + char *plugin_basename = NULL; + char *plugin_full_path = NULL; + char *tmpstr = NULL; + char *plugin_label = NULL; + LADSPA_Descriptor_Function ladspa_desc_func = NULL; + DSSI_Descriptor_Function dssi_desc_func = NULL; + char plugin_dir[MAXPDSTRING]; ph_debug_post("argc = %d", argc); @@ -856,7 +860,9 @@ void *ph_load_plugin(ph *x, t_int argc, t_atom *argv) tmpstr = &plugin_dir[pathlen]; sprintf(tmpstr, "/%s", plugin_basename); tmpstr = plugin_dir; + ph_debug_post("plugin full path is %s", tmpstr); x->plugin_handle = loadLADSPAPluginLibrary(tmpstr); + ph_debug_post("plugin handle address: %p", x->plugin_handle); } else { /* try to load as is: this will work if plugin_full_path is an * absolute path, or the name of a library that is in DSSI_PATH @@ -873,7 +879,7 @@ void *ph_load_plugin(ph *x, t_int argc, t_atom *argv) tmpstr = strdup(plugin_full_path); /* Don't bother working out the plugin name if we used canvas_open() * to get the path */ - if(plugin_basename == NULL){ + if(fd < 0){ if(!strstr(tmpstr, ".so")){ pd_error(x, "invalid plugin path, must end in .so"); return x; @@ -886,16 +892,34 @@ void *ph_load_plugin(ph *x, t_int argc, t_atom *argv) ph_debug_post("plugin basename = %s", x->plugin_basename); } free(tmpstr); - if((x->desc_func = (DSSI_Descriptor_Function)dlsym(x->plugin_handle, - "dssi_descriptor"))){ + dssi_desc_func = (DSSI_Descriptor_Function)dlsym(x->plugin_handle, + "dssi_descriptor"); + + if(!dssi_desc_func){ + pd_error(x, "Couldn't get DSSI descriptor function: %s\n", + dlerror()); + + ladspa_desc_func = (LADSPA_Descriptor_Function)dlsym(x->plugin_handle, + "ladspa_descriptor"); + + if(!ladspa_desc_func){ + pd_error(x, "Couldn't get LADSPA descriptor function: %s\n", + dlerror()); + } + } + + if(dssi_desc_func){ x->is_dssi = true; - x->descriptor = (DSSI_Descriptor *)x->desc_func(0); + x->descriptor = (DSSI_Descriptor *)dssi_desc_func(0); } - else if((x->desc_func = - (DSSI_Descriptor_Function)dlsym(x->plugin_handle, - "ladspa_descriptor"))){ + else if(ladspa_desc_func){ x->is_dssi = false; - x->descriptor = ladspa_to_dssi((LADSPA_Descriptor *)x->desc_func(0)); + x->descriptor = ladspa_to_dssi((LADSPA_Descriptor *)ladspa_desc_func(0)); + } + + if(!x->descriptor){ + pd_error(x, "error: couldn't get plugin descriptor"); + return x; } if(argc >= 2) { @@ -906,15 +930,10 @@ void *ph_load_plugin(ph *x, t_int argc, t_atom *argv) ph_debug_post("n_instances = %d", x->n_instances); - x->instances = (ph_instance *)malloc(sizeof(ph_instance) * + x->instances = (ph_instance *)malloc(sizeof(ph_instance) * x->n_instances); - if(!x->descriptor){ - pd_error(x, "error: couldn't get plugin descriptor"); - return x; - } - - ph_debug_post("%s loaded successfully!", + ph_debug_post("%s loaded successfully!", x->descriptor->LADSPA_Plugin->Label); x->port_info = (ph_port_info *)malloc @@ -946,10 +965,9 @@ void *ph_load_plugin(ph *x, t_int argc, t_atom *argv) if(x->is_dssi){ for(i = 0;i < x->n_instances; i++) osc_setup(x, i); -#if LOADGUI + for(i = 0;i < x->n_instances; i++) ph_load_gui(x, i); -#endif for(i = 0;i < x->n_instances; i++) ph_init_programs(x, i); @@ -1053,13 +1071,11 @@ void ph_free_plugin(ph *x) while(i--){ ph_instance *instance = &x->instances[i]; - /* TODO:OSC */ - /* - if(instance->gui_pid){ - ph_debug_post("Killing GUI process PID = %d", instance->gui_pid); + if(instance->gui_pid){ + ph_debug_post("Killing GUI process PID = %d", instance->gui_pid); - kill(instance->gui_pid, SIGINT); - } */ + kill(instance->gui_pid, SIGINT); + } if (instance->plugin_pgms) { for (n = 0; n < instance->plugin_pgm_count; n++) { free((void *)instance->plugin_pgms[n].Name); -- cgit v1.2.1