Update of /cvsroot/pure-data/externals/clr
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28004
Modified Files:
clr.c test-clr.pd
Log Message:
outlet ready, multi-instance, split assembly in 2
Index: test-clr.pd
===================================================================
RCS file: /cvsroot/pure-data/externals/clr/test-clr.pd,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** test-clr.pd 13 Jan 2006 19:02:36 -0000 1.4
--- test-clr.pd 14 Jan 2006 02:34:17 -0000 1.5
***************
*** 1,44 ****
! #N canvas 0 0 742 490 12;
! #X obj 97 383 clr;
! #X obj 105 80 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
! #X msg 239 110 1 2 3;
! #X msg 238 136 sel3 a b c;
! #X msg 236 176 selFloat 0.5;
! #X msg 247 221 selString ciao;
! #X msg 247 263 selList 1 2 3;
! #X msg 344 161 selFloat \$1;
! #X obj 344 121 hsl 128 15 1 2 0 0 empty empty empty -2 -6 0 8 -262144
-1 -1 0 1;
! #X floatatom 360 142 5 0 0 0 - - -;
! #X msg 242 59 sel1;
! #X msg 240 87 sel2;
! #X obj 428 260 hsl 128 15 1 2 0 0 empty empty empty -2 -6 0 8 -262144
-1 -1 0 1;
! #X text 424 239 2nd inlet mapped to selFloat;
! #X obj 71 429 print a;
! #X msg 239 297 selStringList abba baab caac dede;
! #X msg 240 319 selStringList ego filose;
! #X msg 239 342 selFloatList 1.1 2.2 3.3 4.4;
! #X msg 239 364 selFloatList 0.001 1000;
! #X msg 238 409 selGenericList abaco 1.1;
! #X msg 239 387 selGenericList 0.001 abaco 1000 poroppoppero;
#X connect 0 0 14 0;
#X connect 1 0 0 0;
#X connect 2 0 0 0;
#X connect 3 0 0 0;
- #X connect 4 0 0 0;
#X connect 5 0 0 0;
#X connect 6 0 0 0;
! #X connect 7 0 0 0;
! #X connect 8 0 7 0;
! #X connect 8 0 9 0;
! #X connect 10 0 0 0;
! #X connect 11 0 0 0;
! #X connect 12 0 0 1;
! #X connect 15 0 0 0;
! #X connect 16 0 0 0;
! #X connect 17 0 0 0;
! #X connect 18 0 0 0;
! #X connect 19 0 0 0;
! #X connect 20 0 0 0;
--- 1,30 ----
! #N canvas 73 31 623 538 12;
! #X obj 115 402 clr External External.dll;
! #X obj 122 51 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
! #X floatatom 138 70 5 0 0 0 - - -;
! #X symbolatom 153 93 10 0 0 0 - - -;
! #X text 219 66 simple messages;
! #X msg 200 130 sel1;
! #X msg 214 153 sel2;
! #X text 261 142 selectors;
! #X msg 223 196 selFloat \$1;
! #X obj 226 177 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 8 -262144
-1 -1 0 1;
! #X obj 325 354 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 8 -262144
-1 -1 0 1;
! #X text 322 333 mapped to selFloat;
! #X msg 245 274 selGenericList 12 a 0.5 b;
! #X text 244 252 complex list;
! #X obj 114 432 print;
! #X text 204 433 arguments: Class name \, Filename;
#X connect 0 0 14 0;
#X connect 1 0 0 0;
#X connect 2 0 0 0;
#X connect 3 0 0 0;
#X connect 5 0 0 0;
#X connect 6 0 0 0;
! #X connect 8 0 0 0;
! #X connect 9 0 8 0;
! #X connect 10 0 0 1;
! #X connect 12 0 0 0;
Index: clr.c
===================================================================
RCS file: /cvsroot/pure-data/externals/clr/clr.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** clr.c 13 Jan 2006 19:02:36 -0000 1.5
--- clr.c 14 Jan 2006 02:34:17 -0000 1.6
***************
*** 55,72 ****
//t_atomtype_simple a_type;
int a_type;
! //MonoString *a_type;
! //union{
! float float_value;
! MonoString *string_value;
! //} stuff;
! };
- /*
- typedef struct atom_simple
- {
- int a;
- int b;
};
- */
static t_class *clr_class;
--- 55,62 ----
//t_atomtype_simple a_type;
int a_type;
! float float_value;
! MonoString *string_value;
};
static t_class *clr_class;
***************
*** 76,85 ****
t_object x_obj; // myself
t_outlet *l_out;
// mono stuff
MonoDomain *domain;
! MonoAssembly *assembly;
MonoObject *obj;
! MonoImage *image;
! MonoMethod *method, *setUp;
MonoClass *klass;
int n;
--- 66,78 ----
t_object x_obj; // myself
t_outlet *l_out;
+ t_symbol *assemblyname;
+ t_symbol *filename;
+ int loaded;
// mono stuff
MonoDomain *domain;
! MonoAssembly *assembly, *assemblyPureData;
MonoObject *obj;
! MonoImage *image, *imagePureData;
! MonoMethod *method, *setUp, *manageBang, *manageSymbol, *manageFloat, *manageList;
MonoClass *klass;
int n;
***************
*** 97,102 ****
{
// clean up stuff
! mono_jit_cleanup (x->domain);
!
}
--- 90,95 ----
{
// clean up stuff
! //mono_jit_cleanup (x->domain);
! //mono_domain_free(x->domain);
}
***************
*** 104,116 ****
void createInlet(void *x1, MonoString *selectorString, int type);
void createOutlet(void *x1, int type);
! void out2outlet(void *x1, int outlet, int atoms_length, atom_simple *atoms);
void post2pd(MonoString *mesString);
void error2pd(MonoString *mesString);
// load the variables and init mono
static void mono_load(t_clr *x)
{
// const char *file="D:\\Davide\\cygwin\\home\\Davide\\externalTest1.dll";
! const char *file="PureData.dll";
MonoMethod *m = NULL, *ctor = NULL, *fail = NULL, *mvalues;
--- 97,114 ----
void createInlet(void *x1, MonoString *selectorString, int type);
void createOutlet(void *x1, int type);
! void out2outlet(void *x1, int outlet, int atoms_length, MonoArray *array);
void post2pd(MonoString *mesString);
void error2pd(MonoString *mesString);
+ static void mono_initialize()
+ {
+ mono_jit_init ("PureData");
+ }
+
// load the variables and init mono
static void mono_load(t_clr *x)
{
// const char *file="D:\\Davide\\cygwin\\home\\Davide\\externalTest1.dll";
! //const char *file="External.dll";
MonoMethod *m = NULL, *ctor = NULL, *fail = NULL, *mvalues;
***************
*** 119,129 ****
int val;
int i;
! double rnd;
! int random_name_int;
! char random_name_str[256];
! srand( (unsigned)time( NULL ) );
! rnd = rand()/((double)RAND_MAX + 1);
! random_name_int =(int) (rnd * RAND_MAX);
! sprintf(random_name_str, "%s-%i",file, random_name_int);
// prepare the selectors list
--- 117,127 ----
int val;
int i;
!
!
! if (x->loaded == 0)
! {
! error("assembly not specified");
! return;
! }
// prepare the selectors list
***************
*** 137,158 ****
{
x->outlets[i].outlet_pointer = 0;
! }
!
! printf("will load %s, random_name %s\n", file, random_name_str);
//mono_set_dirs (NULL, NULL);
//mono_config_parse (NULL);
! x->domain = mono_jit_init (random_name_str);
! // add mono to C hooks
! mono_add_internal_call ("PureData.pd::RegisterSelector", registerMonoMethod);
! mono_add_internal_call ("PureData.pd::ToOutlet", out2outlet);
! mono_add_internal_call ("PureData.pd::PostMessage", post2pd);
! mono_add_internal_call ("PureData.pd::ErrorMessage", error2pd);
! mono_add_internal_call ("PureData.pd::CreateOutlet", createOutlet);
! mono_add_internal_call ("PureData.pd::CreateInlet", createInlet);
- x->assembly = mono_domain_assembly_open (x->domain, file);
if (!x->assembly)
{
--- 135,150 ----
{
x->outlets[i].outlet_pointer = 0;
! }
//mono_set_dirs (NULL, NULL);
//mono_config_parse (NULL);
! //mono_jit_init (random_name_str);
! x->domain = mono_domain_get();
! x->assembly = mono_domain_assembly_open (x->domain, x->filename->s_name);
!
! x->assemblyPureData = mono_domain_assembly_open (x->domain, "PureData.dll");
if (!x->assembly)
{
***************
*** 162,167 ****
x->image = mono_assembly_get_image (x->assembly);
! x->klass = mono_class_from_name (x->image, "PureData", "External");
if (!x->klass) {
error("Can't find MyType in assembly %s\n", mono_image_get_filename (x->image));
--- 154,161 ----
x->image = mono_assembly_get_image (x->assembly);
+ x->imagePureData = mono_assembly_get_image (x->assemblyPureData);
+
! x->klass = mono_class_from_name (x->image, "PureData", x->assemblyname->s_name);
if (!x->klass) {
error("Can't find MyType in assembly %s\n", mono_image_get_filename (x->image));
***************
*** 255,258 ****
--- 249,282 ----
}
+ static void clr_bang(t_clr *x)
+ {
+ if (x->manageBang)
+ {
+ mono_runtime_invoke (x->manageBang, x->obj, NULL, NULL);
+ }
+ }
+
+ static void clr_symbol(t_clr *x, t_symbol *sl)
+ {
+ gpointer args [1];
+ MonoString *strmono;
+ strmono = mono_string_new (x->domain, sl->s_name);
+ args[0] = &strmono;
+ if (x->manageSymbol)
+ {
+ mono_runtime_invoke (x->manageSymbol, x->obj, args, NULL);
+ }
+ }
+
+ static void clr_float(t_clr *x, float f)
+ {
+ gpointer args [1];
+ args [0] = &f;
+ if (x->manageFloat)
+ {
+ mono_runtime_invoke (x->manageFloat, x->obj, args, NULL);
+ }
+ }
+
// here i look for the selector and call the right mono method
void clr_manage_list(t_clr *x, t_symbol *sl, int argc, t_atom *argv)
***************
*** 264,268 ****
int i;
// first i extract the first atom which should be a symbol
! //post("clr_manage_list, got symbol = %s", sl->s_name);
for (i=0; i<MAX_SELECTORS; i++)
--- 288,292 ----
int i;
// first i extract the first atom which should be a symbol
! post("clr_manage_list, got symbol = %s", sl->s_name);
for (i=0; i<MAX_SELECTORS; i++)
***************
*** 313,317 ****
sprintf(strnull, "null");
atom_array = malloc(sizeof(atom_simple)*argc);
! MonoClass *c = mono_class_from_name (x->image, "PureData", "Atom");
atoms = mono_array_new (x->domain, c, argc);
for (j=0; j<argc; j++)
--- 337,341 ----
sprintf(strnull, "null");
atom_array = malloc(sizeof(atom_simple)*argc);
! MonoClass *c = mono_class_from_name (x->imagePureData, "PureData", "Atom");
atoms = mono_array_new (x->domain, c, argc);
for (j=0; j<argc; j++)
***************
*** 378,382 ****
}
! post("registerMonoMethod: associating %s to %s", selCstring, metCstring);
this_selector = MAX_SELECTORS;
--- 402,426 ----
}
! //post("registerMonoMethod: associating %s to %s", selCstring, metCstring);
!
! if (selectorString->length == 0)
! {
! printf("selectorString->length == 0");
! switch (type)
! {
! case 1: // float
! x->manageFloat = met;
! break;
! case 2: // string
! x->manageSymbol = met;
! break;
! case 3: // list
! x->manageList = met;
! break;
! case 4: // bang
! x->manageBang = met;
! break;
! }
! }
this_selector = MAX_SELECTORS;
***************
*** 482,493 ****
// out to outlet
! void out2outlet(void *x1, int outlet, int atoms_length, atom_simple *atoms)
{
t_clr *x;
x = (t_clr *)x1;
t_atom *lista;
int n;
- printf("outlet = %i\n" + outlet);
- printf("atoms_length = %i\n" + atoms_length);
if ((outlet>MAX_OUTLETS) || (outlet<0))
{
--- 526,536 ----
// out to outlet
! void out2outlet(void *x1, int outlet, int atoms_length, MonoArray *array)
{
t_clr *x;
x = (t_clr *)x1;
t_atom *lista;
+ atom_simple *atoms;
int n;
if ((outlet>MAX_OUTLETS) || (outlet<0))
{
***************
*** 501,506 ****
--- 544,551 ----
}
lista = (t_atom *) malloc(sizeof(t_atom) * atoms_length);
+ atoms = (atom_simple *) malloc(sizeof(atom_simple) * atoms_length);
for (n=0; n<atoms_length; n++)
{
+ atoms[n] = mono_array_get(array, atom_simple, n);
char *mesCstring;
switch (atoms[n].a_type)
***************
*** 510,517 ****
break;
case A_S_FLOAT:
- mesCstring = mono_string_to_utf8 (atoms[n].string_value);
SETFLOAT(lista+n, (float) atoms[n].float_value);
break;
case A_S_SYMBOL:
SETSYMBOL(lista+n, gensym(mesCstring));
break;
--- 555,562 ----
break;
case A_S_FLOAT:
SETFLOAT(lista+n, (float) atoms[n].float_value);
break;
case A_S_SYMBOL:
+ mesCstring = mono_string_to_utf8 (atoms[n].string_value);
SETSYMBOL(lista+n, gensym(mesCstring));
break;
***************
*** 560,567 ****
// x->l_out = outlet_new(&x->x_obj, &s_list);
// x->l_out = outlet_new(&x->x_obj, gensym("float"));
- x->n = 0;
// load mono, init the needed vars
mono_load(x);
--- 605,634 ----
// x->l_out = outlet_new(&x->x_obj, &s_list);
// x->l_out = outlet_new(&x->x_obj, gensym("float"));
+
+ char strtmp[256];
+ x->manageBang = 0;
+ x->manageSymbol = 0;
+ x->manageFloat = 0;
+ x->manageList = 0;
+ if (argc==0)
+ {
+ x->loaded = 0;
+ error("clr: you must provide an assembly as the first argument");
+ return (x);
+ }
+ x->loaded = 1;
+ x->assemblyname = atom_gensym(argv);
+
+ if (argc==1)
+ {
+ // only main class passed
+ // filename by default
+ sprintf(strtmp, "%s.dll", x->assemblyname->s_name);
+ x->filename = atom_gensym(strtmp);
+ }
+ x->filename = atom_gensym(argv+1);
// load mono, init the needed vars
mono_load(x);
***************
*** 574,581 ****
clr_class = class_new(gensym("clr"), (t_newmethod)clr_new,
(t_method)clr_free, sizeof(t_clr), CLASS_DEFAULT, A_GIMME, 0);
- //class_addbang(clr_class, (t_method)clr_bang);
- // ext_class_addbang((t_method) clr_bang);
class_addlist(clr_class, (t_method)clr_manage_list);
}
--- 641,658 ----
clr_class = class_new(gensym("clr"), (t_newmethod)clr_new,
(t_method)clr_free, sizeof(t_clr), CLASS_DEFAULT, A_GIMME, 0);
class_addlist(clr_class, (t_method)clr_manage_list);
+ class_addbang(clr_class, (t_method)clr_bang);
+ class_addsymbol(clr_class, (t_method)clr_symbol);
+ class_addfloat(clr_class, (t_method)clr_float);
+ mono_initialize();
+
+ // add mono to C hooks
+ mono_add_internal_call ("PureData.pd::RegisterSelector", registerMonoMethod);
+ mono_add_internal_call ("PureData.pd::ToOutlet", out2outlet);
+ mono_add_internal_call ("PureData.pd::PostMessage", post2pd);
+ mono_add_internal_call ("PureData.pd::ErrorMessage", error2pd);
+ mono_add_internal_call ("PureData.pd::CreateOutlet", createOutlet);
+ mono_add_internal_call ("PureData.pd::CreateInlet", createInlet);
}