Update of /cvsroot/pure-data/externals/postlude/dssi/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5541
Modified Files:
dssi~.c dssi~.h
Log Message:
Numerous bug fixes
Index: dssi~.c
===================================================================
RCS file: /cvsroot/pure-data/externals/postlude/dssi/src/dssi~.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** dssi~.c 3 Feb 2006 14:36:55 -0000 1.2
--- dssi~.c 16 Feb 2006 10:21:39 -0000 1.3
***************
*** 63,66 ****
--- 63,67 ----
char *ui_osc_show_path;
char *ui_osc_hide_path;
+ char *ui_osc_quit_path;
int *plugin_PortControlInNumbers; /*not sure if this should go here?*/
***************
*** 71,74 ****
--- 72,84 ----
} t_dssi_instance;
+ struct dssi_configure_pair {
+ t_int instance;
+ char *key,
+ *value;
+ struct dssi_configure_pair *next;
+ };
+
+ typedef struct dssi_configure_pair t_dssi_configure_pair;
+
typedef struct _dssi_tilde {
t_object x_obj;
***************
*** 112,115 ****
--- 122,127 ----
t_float **outlets;
+
+ t_dssi_configure_pair *configure_buffer_head;
} t_dssi_tilde;
***************
*** 117,120 ****
--- 129,134 ----
static void dssi_load_gui(t_dssi_tilde *x, int instance);
+ static char *dssi_send_configure(t_dssi_tilde *x, char *key,
+ char *value, t_int instance);
static int osc_message_handler(const char *path, const char *types,
lo_arg **argv, int argc, void *data, void *user_data);
***************
*** 178,182 ****
--- 192,208 ----
}
+ /*
+ * dx7_bulk_dump_checksum
+ ** Taken from dx7_voice_data.c by Sean Bolton **
+ */
+ int
+ dx7_bulk_dump_checksum(uint8_t *data, int length)
+ {
+ int sum = 0;
+ int i;
+ for (i = 0; i < length; sum -= data[i++]);
+ return sum & 0x7F;
+ }
***************
*** 281,284 ****
--- 307,311 ----
x->instances[instance].ui_osc_show_path = NULL;
x->instances[instance].ui_osc_hide_path = NULL;
+ x->instances[instance].ui_osc_quit_path = NULL;
x->instances[instance].ui_osc_configure_path = NULL;
x->instances[instance].uiNeedsProgramUpdate = 0;
***************
*** 375,378 ****
--- 402,406 ----
for (i = 0; i < x->instances[instance].plugin_ProgramCount; i++)
free((void *)x->instances[instance].pluginPrograms[i].Name);
+ free((char *)x->instances[instance].pluginPrograms);
x->instances[instance].pluginPrograms = NULL;
x->instances[instance].plugin_ProgramCount = 0;
***************
*** 387,390 ****
--- 415,419 ----
/* Count the plugins first */
+ /*FIX ?? */
for (i = 0; x->descriptor->
get_program(x->instanceHandles[instance], i); ++i);
***************
*** 669,673 ****
--- 698,705 ----
post("exiting handler called: Freeing ui_osc");
#endif
+ if(x->instances[instance].uiTarget){
lo_address_free(x->instances[instance].uiTarget);
+ x->instances[instance].uiTarget = NULL;
+ }
free(x->instances[instance].ui_osc_control_path);
free(x->instances[instance].ui_osc_configure_path);
***************
*** 675,678 ****
--- 707,711 ----
free(x->instances[instance].ui_osc_program_path);
free(x->instances[instance].ui_osc_show_path);
+ free(x->instances[instance].ui_osc_quit_path);
x->instances[instance].uiTarget = NULL;
x->instances[instance].ui_osc_control_path = NULL;
***************
*** 681,684 ****
--- 714,718 ----
x->instances[instance].ui_osc_program_path = NULL;
x->instances[instance].ui_osc_show_path = NULL;
+ x->instances[instance].ui_osc_quit_path = NULL;
x->instances[instance].ui_hidden = 1;
***************
*** 693,696 ****
--- 727,733 ----
t_int i;
char *host, *port;
+ t_dssi_configure_pair *p;
+
+ p = x->configure_buffer_head;
#if DEBUG
***************
*** 698,702 ****
#endif
-
if (x->instances[instance].uiTarget)
lo_address_free(x->instances[instance].uiTarget);
--- 735,738 ----
***************
*** 727,730 ****
--- 763,771 ----
sprintf(x->instances[instance].ui_osc_program_path, "%s/program", path);
+ if (x->instances[instance].ui_osc_quit_path)
+ free(x->instances[instance].ui_osc_quit_path);
+ x->instances[instance].ui_osc_quit_path = (char *)malloc(strlen(path) + 10);
+ sprintf(x->instances[instance].ui_osc_hide_path, "%s/quit", path);
+
if (x->instances[instance].ui_osc_show_path)
free(x->instances[instance].ui_osc_show_path);
***************
*** 737,751 ****
sprintf(x->instances[instance].ui_osc_hide_path, "%s/hide", path);
free((char *)path);
! /* At this point a more substantial host might also call
! * configure() on the UI to set any state that it had remembered
! * for the plugin x. But we don't remember state for
! * plugin xs (see our own configure() implementation in
! * osc_configure_handler), and so we have nothing to send except
! * the optional project directory. */
- if (x->dir)
- lo_send(x->instances[instance].uiTarget, x->instances[instance].ui_osc_configure_path, "ss",DSSI_PROJECT_DIRECTORY_KEY, x->dir);
--- 778,793 ----
sprintf(x->instances[instance].ui_osc_hide_path, "%s/hide", path);
+
free((char *)path);
!
! while(p){
! if(p->instance == instance)
! dssi_send_configure(x, p->key,
! p->value, instance);
! p = p->next;
! }
!
***************
*** 845,851 ****
char *gui_str;
! gui_base = (char *)malloc(baselen = sizeof(char) * (strlen(x->dll_path) - strlen(".so")));
strncpy(gui_base, x->dll_path, baselen);
/* gui_base = strndup(x->dll_path, baselen);*/
#if DEBUG
--- 887,896 ----
char *gui_str;
! gui_base = (char *)malloc((baselen = sizeof(char) * (strlen(x->dll_path) - strlen(".so"))) + 1);
strncpy(gui_base, x->dll_path, baselen);
+ gui_base[baselen] = '\0';
+
+ /* don't use strndup - GNU only */
/* gui_base = strndup(x->dll_path, baselen);*/
#if DEBUG
***************
*** 994,998 ****
--- 1039,1093 ----
}
+
+
+
+ static void dssi_list(t_dssi_tilde *x, t_symbol *s, int argc, t_atom *argv) {
+ char *msg_type;
+ int ev_type = 0;
+ msg_type = (char *)malloc(TYPE_STRING_SIZE);
+ atom_string(argv, msg_type, TYPE_STRING_SIZE);
+ int chan = (int)atom_getfloatarg(1, argc, argv) - 1;
+ int param = (int)atom_getfloatarg(2, argc, argv);
+ int val = (int)atom_getfloatarg(3, argc, argv);
+ switch (msg_type[0]){
+ case ASCII_n: ev_type = SND_SEQ_EVENT_NOTEON;
+ break;
+ case ASCII_c: ev_type = SND_SEQ_EVENT_CONTROLLER;
+ break;
+ case ASCII_p: ev_type = SND_SEQ_EVENT_PGMCHANGE;
+ break;
+ case ASCII_b: ev_type = SND_SEQ_EVENT_PITCHBEND;
+ break;
+ }
+ #if DEBUG
+ post("initial midi NOTE:, arg1 = %d, arg2 = %d, arg3 = %d, arg4 = %d",ev_type,chan,param,val);
+ #endif
+ if(ev_type != 0){
+ MIDIbuf(ev_type, chan, param, val, x);
+ }
+ free(msg_type);
+ }
+
+ static char *dssi_send_configure(t_dssi_tilde *x, char *key,
+ char *value, t_int instance){
+
+ char *debug;
+
+ debug = x->descriptor->configure(
+ x->instanceHandles[instance],
+ key, value);
+ /* if(!strcmp(msg_type, "load"))*/
+ if(x->instances[instance].uiTarget != NULL)
+ lo_send(x->instances[instance].uiTarget,
+ x->instances[instance].ui_osc_configure_path,
+ "ss", key, value);
+ query_programs(x, instance);
+
+ return debug;
+ }
+
static void dssi_show(t_dssi_tilde *x, t_int instance, t_int toggle){
+
+
if(x->instances[instance].uiTarget){
if (x->instances[instance].ui_hidden && toggle) {
***************
*** 1010,1013 ****
--- 1105,1109 ----
x->instances[instance].ui_show = 1;
dssi_load_gui(x, instance);
+
}
/* if(x->instances[instance].uiTarget){
***************
*** 1020,1051 ****
}
! static void dssi_list(t_dssi_tilde *x, t_symbol *s, int argc, t_atom *argv) {
! char *msg_type;
! int ev_type = 0;
! msg_type = (char *)malloc(TYPE_STRING_SIZE);
! atom_string(argv, msg_type, TYPE_STRING_SIZE);
! int chan = (int)atom_getfloatarg(1, argc, argv) - 1;
! int param = (int)atom_getfloatarg(2, argc, argv);
! int val = (int)atom_getfloatarg(3, argc, argv);
! switch (msg_type[0]){
! case ASCII_n: ev_type = SND_SEQ_EVENT_NOTEON;
! break;
! case ASCII_c: ev_type = SND_SEQ_EVENT_CONTROLLER;
! break;
! case ASCII_p: ev_type = SND_SEQ_EVENT_PGMCHANGE;
! break;
! case ASCII_b: ev_type = SND_SEQ_EVENT_PITCHBEND;
! break;
}
! #if DEBUG
! post("initial midi NOTE:, arg1 = %d, arg2 = %d, arg3 = %d, arg4 = %d",ev_type,chan,param,val);
! #endif
! if(ev_type != 0){
! MIDIbuf(ev_type, chan, param, val, x);
}
! free(msg_type);
}
/* Method for list data through right inlet */
/*FIX: rewrite at some point - this is bad*/
--- 1116,1184 ----
}
+ static t_int dssi_configure_buffer(t_dssi_tilde *x, char *key,
+ char *value, t_int instance){
! /*#ifdef BLAH*/
! t_dssi_configure_pair *current, *p;
! t_int add_node;
! add_node = 0;
! current = x->configure_buffer_head;
!
! while(current){
! if(!strcmp(current->key, key) &&
! current->instance == instance)
! break;
! current = current->next;
}
! if(current)
! free(current->value);
! else {
! current = (t_dssi_configure_pair *)malloc(sizeof
! (t_dssi_configure_pair));
! current->next = x->configure_buffer_head;
! x->configure_buffer_head = current;
! current->key = (char *)malloc((strlen(key) + 1) *
! sizeof(char));
! strcpy(current->key, key);
! current->instance = instance;
}
! current->value = (char *)malloc((strlen(value) + 1) *
! sizeof(char));
! strcpy(current->value, value);
!
!
! p = x->configure_buffer_head;
!
!
! while(p){
! post("key: %s", p->key);
! post("val: %s", p->value);
! post("instance: %d", p->instance);
! p = p->next;
! }
!
! return 0;
}
+ static t_int dssi_configure_buffer_free(t_dssi_tilde *x){
+ t_dssi_configure_pair *curr, *prev;
+ prev = curr = NULL;
+
+ for(curr = x->configure_buffer_head; curr != NULL; curr = curr->next){
+ if(prev != NULL)
+ free(prev);
+ free(curr->key);
+ free(curr->value);
+ prev = curr;
+ /* free(p);*/
+ }
+ free(curr);
+
+
+ return 0;
+ }
+
+
+
/* Method for list data through right inlet */
/*FIX: rewrite at some point - this is bad*/
***************
*** 1060,1064 ****
unsigned char *raw_patch_data = NULL;
FILE *fp;
! size_t filename_length;
dx7_patch_t *patchbuf, *firstpatch;
atom_string(argv, msg_type, TYPE_STRING_SIZE);
--- 1193,1197 ----
unsigned char *raw_patch_data = NULL;
FILE *fp;
! size_t filename_length, key_size, value_size;
dx7_patch_t *patchbuf, *firstpatch;
atom_string(argv, msg_type, TYPE_STRING_SIZE);
***************
*** 1076,1081 ****
instance = (int)atom_getfloatarg(2, argc, argv) - 1;
-
-
--- 1209,1212 ----
***************
*** 1148,1153 ****
}
fclose(fp);
/* At the moment we only support Hexter patches */
! if(strcmp(x->descriptor->LADSPA_Plugin->Label, "hexter"))
post("Sorry dssi~ only supports dx7 patches at the moment.");
else{
--- 1279,1288 ----
}
fclose(fp);
+ #if DEBUG
+ post("Patch file length is %ul", filelength);
+ #endif
/* At the moment we only support Hexter patches */
! if(strcmp(x->descriptor->LADSPA_Plugin->Label, "hexter") &&
! strcmp(x->descriptor->LADSPA_Plugin->Label, "hexter6"))
post("Sorry dssi~ only supports dx7 patches at the moment.");
else{
***************
*** 1159,1162 ****
--- 1294,1300 ----
/* It's a raw DX7 patch bank */
+ #if DEBUG
+ post("Raw DX7 format patch bank passed");
+ #endif
count = filelength / DX7_VOICE_SIZE_PACKED;
if (count > maxpatches)
***************
*** 1168,1172 ****
raw_patch_data[0] == 0xf0 &&
raw_patch_data[1] == 0x43 &&
! (raw_patch_data[2] & 0xf0) == 0x00 &&
raw_patch_data[3] == 0x09 &&
(raw_patch_data[4] == 0x10 ||
--- 1306,1313 ----
raw_patch_data[0] == 0xf0 &&
raw_patch_data[1] == 0x43 &&
! /*This was used to fix some problem with Galaxy exports - possibly dump in worng format. It is not needed, but it did work, so in future, we may be able to support more formats not just DX7 */
! /* ((raw_patch_data[2] & 0xf0) == 0x00 ||
! raw_patch_data[2] == 0x7e) &&*/
! (raw_patch_data[2] & 0xf0) == 0x00 &&
raw_patch_data[3] == 0x09 &&
(raw_patch_data[4] == 0x10 ||
***************
*** 1176,1179 ****
--- 1317,1324 ----
/* It's a DX7 sys-ex 32 voice dump */
+ #if DEBUG
+ post("SYSEX header check passed");
+ #endif
+
if (filelength != DX7_DUMP_SIZE_BULK ||
raw_patch_data[DX7_DUMP_SIZE_BULK - 1] != 0xf7) {
***************
*** 1288,1307 ****
else if(!strcmp(msg_type, "configure")){
key =
! malloc(strlen(argv[1].a_w.w_symbol->s_name) * sizeof(char));
! atom_string(&argv[1], key, TYPE_STRING_SIZE);
! if (argv[2].a_type == A_FLOAT){
! val = atom_getfloatarg(2, argc, argv);
! value = malloc(TYPE_STRING_SIZE * sizeof(char));
! sprintf(value, "%.2f", val);
! }
! else if(argv[2].a_type == A_SYMBOL){
! value =
! malloc(strlen(argv[2].a_w.w_symbol->s_name) *
! sizeof(char));
! atom_string(&argv[2], value, TYPE_STRING_SIZE);
! }
! if(argv[3].a_type == A_FLOAT)
instance = atom_getfloatarg(3, argc, argv) - 1;
/* else if(argv[3].a_type == A_SYMBOL)
post("Argument 4 should be an integer!");
--- 1433,1461 ----
else if(!strcmp(msg_type, "configure")){
key =
! (char *)malloc(key_size = (strlen(argv[1].a_w.w_symbol->s_name) + 2) * sizeof(char));
! /*atom_string(&argv[1], key, TYPE_STRING_SIZE);*/
! atom_string(&argv[1], key, key_size);
! if(argc >= 3){
! if (argv[2].a_type == A_FLOAT){
! val = atom_getfloatarg(2, argc, argv);
! value = (char *)malloc(TYPE_STRING_SIZE *
! sizeof(char));
! sprintf(value, "%.2f", val);
! }
! else if(argv[2].a_type == A_SYMBOL){
! value =
! (char *)malloc(value_size =
! (strlen(argv[2].a_w.w_symbol->s_name) + 2) *
! sizeof(char));
! atom_string(&argv[2], value, value_size);
! }
! }
!
!
! if(argc == 4 && argv[3].a_type == A_FLOAT)
instance = atom_getfloatarg(3, argc, argv) - 1;
+ else if (n_instances)
+ instance = -1;
/* else if(argv[3].a_type == A_SYMBOL)
post("Argument 4 should be an integer!");
***************
*** 1309,1340 ****
}
if(key != NULL && value != NULL){
if(instance == -1){
while(n_instances--){
! debug =
! x->descriptor->configure(
! x->instanceHandles[n_instances],
! key, value);
! /*FIX - sort out 'pending' system so that new GUI's for instances get updated */
! if(x->instances[n_instances].uiTarget != NULL){
! /* if(!strcmp(msg_type, "load"))*/
! lo_send(x->instances[n_instances].uiTarget, x->instances[n_instances].ui_osc_configure_path, "ss", key, value);
! query_programs(x, n_instances);
! /*FIX: better way to do this - OSC handler?*/
! }
}
}
/*FIX: Put some error checking in here to make sure instance is valid*/
else{
! debug =
! x->descriptor->configure(
! x->instanceHandles[instance],
! key, value);
! /* if(!strcmp(msg_type, "load"))*/
! if(x->instances[n_instances].uiTarget != NULL)
! lo_send(x->instances[instance].uiTarget,
! x->instances[instance].ui_osc_configure_path,
! "ss", key, value);
! query_programs(x, instance);
}
}
--- 1463,1481 ----
}
+
if(key != NULL && value != NULL){
if(instance == -1){
while(n_instances--){
! post("instance = %d, n_instaances = %d",instance, n_instances);
! debug = dssi_send_configure(
! x, key, value, n_instances);
! dssi_configure_buffer(x, key, value, n_instances);
}
}
/*FIX: Put some error checking in here to make sure instance is valid*/
else{
!
! debug = dssi_send_configure(x, key, value, instance);
! dssi_configure_buffer(x, key, value, instance);
}
}
***************
*** 1346,1355 ****
free(msg_type);
free(patchbuf);
! free(value);
if(key != NULL)
! free(key);
! if(x->dir != NULL)
! free(x->dir);
return 0;
--- 1487,1496 ----
free(msg_type);
free(patchbuf);
! /*free(value);
if(key != NULL)
! free(key);*/
! /*if(x->dir != NULL)
! free(x->dir);*/
return 0;
***************
*** 1465,1470 ****
if (argc){
-
x->dll_path = argv[0].a_w.w_symbol->s_name;
dssi_load(x->dll_path, &x->dll_handle);
--- 1606,1613 ----
if (argc){
x->dll_path = argv[0].a_w.w_symbol->s_name;
+ #if DEBUG
+ post("x->dll_path = %s", x->dll_path);
+ #endif
dssi_load(x->dll_path, &x->dll_handle);
***************
*** 1484,1487 ****
--- 1627,1631 ----
x->ports_in = x->ports_out = x->ports_controlIn = x->ports_controlOut = 0;
x->dir = NULL;
+ x->configure_buffer_head = NULL;
x->bufWriteIndex = x->bufReadIndex = 0;
***************
*** 1550,1556 ****
static void dssi_free(t_dssi_tilde *x){
! if(x->n_instances){
t_int instance;
for(instance = 0; instance < x->n_instances; instance++) {
/* no -- see comment in osc_exiting_handler */
/* if (!instances[i].inactive) { */
--- 1694,1711 ----
static void dssi_free(t_dssi_tilde *x){
! t_int i;
!
! #if DEBUG
! post("Calling dssi_free");
! #endif
!
t_int instance;
for(instance = 0; instance < x->n_instances; instance++) {
+ if(x->instances[instance].uiTarget){
+ lo_send(x->instances[instance].uiTarget,
+ x->instances[instance].ui_osc_quit_path, "");
+ lo_address_free(x->instances[instance].uiTarget);
+ x->instances[instance].uiTarget = NULL;
+ }
/* no -- see comment in osc_exiting_handler */
/* if (!instances[i].inactive) { */
***************
*** 1568,1574 ****
- #if DEBUG
- post("Calling dssi_free");
- #endif
if(x->dll_handle){
instance = x->n_instances;
--- 1723,1726 ----
***************
*** 1576,1581 ****
free(x->plugin_ControlInPortNumbers);
free((t_float *)x->plugin_InputBuffers);
- free((t_float *)x->plugin_OutputBuffers);
- free((snd_seq_event_t *)x->instanceEventBuffers);
free(x->instanceEventCounts);
free(x->plugin_ControlDataInput);
--- 1728,1731 ----
***************
*** 1589,1592 ****
--- 1739,1754 ----
kill(x->instances[instance].gui_pid, SIGKILL);
}
+ if (x->instances[instance].pluginPrograms) {
+ for (i = 0; i <
+ x->instances[instance].plugin_ProgramCount; i++)
+ free((void *)
+ x->instances[instance].pluginPrograms[i].Name);
+ free((char *)x->instances[instance].pluginPrograms);
+ x->instances[instance].pluginPrograms = NULL;
+ x->instances[instance].plugin_ProgramCount = 0;
+ }
+
+ free(x->plugin_OutputBuffers[instance]);
+ free(x->instanceEventBuffers[instance]);
free(x->instances[instance].ui_osc_control_path);
free(x->instances[instance].ui_osc_configure_path);
***************
*** 1594,1605 ****
free(x->instances[instance].ui_osc_show_path);
free(x->instances[instance].ui_osc_hide_path);
free(x->instances[instance].osc_url_path);
free(x->instances[instance].plugin_PortControlInNumbers);
}
free((t_float *)x->outlets);
free(x->osc_url_base);
free(x->dll_name);
}
! }
}
--- 1756,1775 ----
free(x->instances[instance].ui_osc_show_path);
free(x->instances[instance].ui_osc_hide_path);
+ free(x->instances[instance].ui_osc_quit_path);
free(x->instances[instance].osc_url_path);
free(x->instances[instance].plugin_PortControlInNumbers);
}
+ free((t_float *)x->plugin_OutputBuffers);
+ free((snd_seq_event_t *)x->instanceEventBuffers);
+ free(x->instances);
+ free(x->dir);
free((t_float *)x->outlets);
free(x->osc_url_base);
free(x->dll_name);
+ dssi_configure_buffer_free(x);
+ /* free(x->configure_buffer_head);*/
+ /* free(x->dll_path);*/
}
!
}
Index: dssi~.h
===================================================================
RCS file: /cvsroot/pure-data/externals/postlude/dssi/src/dssi~.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** dssi~.h 3 Feb 2006 14:39:27 -0000 1.2
--- dssi~.h 16 Feb 2006 10:21:39 -0000 1.3
***************
*** 31,35 ****
#include <unistd.h>
#include <stdio.h>
- #define __USE_GNU /* for strndup */
#include <string.h>
--- 31,34 ----
***************
*** 43,47 ****
! #define VERSION 0.81
#define EVENT_BUFSIZE 1024
#define OSC_BASE_MAX 1024
--- 42,46 ----
! #define VERSION 0.82
#define EVENT_BUFSIZE 1024
#define OSC_BASE_MAX 1024
***************
*** 55,57 ****
#define LOADGUI 1 /* FIX: depracate this */
#define DEBUG 0
!
--- 54,58 ----
#define LOADGUI 1 /* FIX: depracate this */
#define DEBUG 0
! #ifdef DEBUG
! #define CHECKSUM_PATCH_FILES_ON_LOAD 1
! #endif