aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xclr.c158
-rwxr-xr-xexternal/External.cs83
-rwxr-xr-xexternal/pd.cs223
-rwxr-xr-xtest-clr.pd4
4 files changed, 176 insertions, 292 deletions
diff --git a/clr.c b/clr.c
index 28ad5e9..cce99b9 100755
--- a/clr.c
+++ b/clr.c
@@ -103,7 +103,7 @@ static void mono_clean(t_clr *x)
void registerMonoMethod(void *x, MonoString *selectorString, MonoString *methodString, int type);
void createInlet(void *x1, MonoString *selectorString, int type);
void createOutlet(void *x1, int type);
-void out2outlet(void *x, int outlet, int type, unsigned char *val /* TODO */);
+void out2outlet(void *x1, int outlet, int atoms_length, atom_simple *atoms);
void post2pd(MonoString *mesString);
void error2pd(MonoString *mesString);
@@ -140,6 +140,9 @@ static void mono_load(t_clr *x)
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
@@ -298,131 +301,54 @@ void clr_manage_list(t_clr *x, t_symbol *sl, int argc, t_atom *argv)
case 3:
{
gpointer args [1];
- MonoString *strmono;
+ MonoString *stringtmp;
+ double *floattmp;
+ t_atomtype_simple *typetmp;
t_symbol *strsymbol;
- float ftmp;
- char *str;
- char strtmp[265], strtmp2[256];
- MonoArray * arystr;
+ MonoArray *atoms;
+ atom_simple *atom_array;
int j;
- atom_simple *atmp;
- atom_simple *atmp2, *atmp3;
-
- int *tipo;
- float *fp;
-
- MonoClass *c = mono_class_from_name (x->image, "PureData", "Atom2");
- if (!c)
- error("----> can't find Atom");
- //arystr = mono_array_new (x->domain, atom_simple, argc);
- arystr = mono_array_new (x->domain, c /*mono_get_string_class ()*/, argc);
- //arystr = mono_array_new (x->domain, c, 2);
- /*
+ char strfloat[256], strnull[256];
+ sprintf(strfloat, "float");
+ 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++)
{
- atmp = malloc(sizeof(atom_simple));
switch ((argv+j)->a_type)
{
case A_FLOAT:
-post("setting type float in position %i", j);
- //atmp->a_type = 1;
- sprintf(strtmp, "1");
- // atmp->a_type = mono_string_new (x->domain, strtmp);
- ftmp = atom_getfloat(argv+j);
- atmp->float_value = ftmp;
+ atom_array[j].a_type = A_S_FLOAT;
+ atom_array[j].float_value = (double) atom_getfloat(argv+j);
+ atom_array[j].string_value = mono_string_new (x->domain, strfloat);
break;
case A_SYMBOL:
-post("setting type symbol in position %i", j);
- //atmp->a_type = 2;
- sprintf(strtmp, "2");
- // atmp->a_type = mono_string_new (x->domain, strtmp);
+ atom_array[j].a_type = A_S_SYMBOL;
strsymbol = atom_getsymbol(argv+j);
- atmp->string_value = mono_string_new (x->domain, strsymbol->s_name);
+ atom_array[j].string_value = mono_string_new (x->domain, strsymbol->s_name);
+ atom_array[j].float_value = 0;
break;
default:
-post("setting type null in position %i", j);
- //atmp->a_type = 0;
- sprintf(strtmp, "0");
- // atmp->a_type = mono_string_new (x->domain, strtmp);
+ atom_array[j].a_type = A_S_NULL;
+ atom_array[j].float_value = 0;
+ atom_array[j].string_value = mono_string_new (x->domain, strnull);
}
- // mono_array_set (arystr, MonoString *, j, atmp->a_type);
- mono_array_set (arystr, atom_simple *, j, atmp);
- //int * ftmp = malloc(sizeof(int));
- //*ftmp = j;
- //float ftmp = atom_getfloat(argv+j);
- //strsymbol = atom_getsymbol(argv+j);
- //MonoString *arg = mono_string_new (x->domain, strsymbol->s_name);
- //mono_array_set (arystr, MonoString *, j, arg);
- // gpointer
-
- //mono_array_set (arystr, gint32 , j, *ftmp);
- //mono_array_set (arystr, gint32 , j, ftmp);
-
+ mono_array_set (atoms, atom_simple , j, atom_array[j]);
}
- */
- // debug:
- // send just 1 atom
-
-
- atmp2 = malloc(sizeof(atom_simple));
- atmp2->a_type = 121;
- atmp2->float_value = atom_getfloat(argv);
- strsymbol = atom_getsymbol(argv);
-printf("strsymbol->s_name = %s\n", strsymbol->s_name);
- atmp2->string_value = mono_string_new (x->domain, strsymbol->s_name);
- args[0] = atmp2;
-
-
- /*
- atmp2 = malloc(sizeof(atom_simple));
- atmp2->a = 121;
- atmp2->b = 1;
- args[0] = atmp2;
- */
-
- /*
- // a list of atoms
- for (j=0; j<argc; j++)
- {
- atmp2 = malloc(sizeof(atom_simple));
- atmp2->a_type = 4;
- atmp2->float_value = atom_getfloat(argv+j);
- strsymbol = atom_getsymbol(argv+j);
- atmp2->string_value = mono_string_new (x->domain, strsymbol->s_name);
- mono_array_set (arystr, atom_simple *, j, atmp2);
- }
- */
-
-
- /*
- atmp3 = malloc(sizeof(atom_simple));
- atmp3->a_type = 2;
- atmp3->float_value = 0.5;
- sprintf(strtmp2, "abracadabra");
- atmp3->string_value = mono_string_new (x->domain, strtmp2);
- mono_array_set (arystr, atom_simple *, 1, atmp3);
- */
- //args[0] = arystr;
-
- //args[0] = strings;
+ args[0] = atoms;
mono_runtime_invoke (x->selectors[i].func, x->obj, args, NULL);
break;
}
}
-
- //result = mono_runtime_invoke (x->selectors[i].func, x->obj, args, NULL);
- //val = *(int*)mono_object_unbox (result);
- //x->n = val;
return;
}
}
if (x->selectors[i].func == 0)
i = MAX_SELECTORS;
}
-
error("clr: selector not recognized");
-
}
// this function is called by mono when it wants to register a selector callback
@@ -555,12 +481,14 @@ void createOutlet(void *x1, int type)
}
// out to outlet
-void out2outlet(void *x1, int outlet, int type, unsigned char *val /* TODO */)
+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))
{
error("outlet number out of range, max is %i", MAX_OUTLETS);
@@ -571,16 +499,28 @@ void out2outlet(void *x1, int outlet, int type, unsigned char *val /* TODO */)
error("outlet %i not registered", outlet);
return;
}
-printf("ricevuto %i %i\n", val[0], val[1]);
-if (val[0]==0x01)
- printf("val[0]==0x00");
+ lista = (t_atom *) malloc(sizeof(t_atom) * atoms_length);
+ for (n=0; n<atoms_length; n++)
+ {
+ char *mesCstring;
+ switch (atoms[n].a_type)
+ {
+ case A_S_NULL:
+ SETFLOAT(lista+n, (float) 0);
+ 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;
+ }
- lista = (t_atom *) malloc(sizeof(t_atom) * 2);
- SETFLOAT(lista, (float) val[0]);
- SETFLOAT(lista+1, (float) val[1]);
+ }
outlet_anything(x->outlets[outlet].outlet_pointer,
gensym("list") ,
- 2,
+ atoms_length,
lista);
free(lista);
}
diff --git a/external/External.cs b/external/External.cs
index 215461c..820c7ca 100755
--- a/external/External.cs
+++ b/external/External.cs
@@ -30,9 +30,6 @@ namespace PureData
pd.AddSelector(x, "sel2", "Sel2", ParametersType.None);
pd.AddSelector(x, "selFloat", "SelFloat", ParametersType.Float);
pd.AddSelector(x, "selString", "SelString", ParametersType.Symbol);
- pd.AddSelector(x, "selList", "SelList", ParametersType.List);
- pd.AddSelector(x, "selStringList", "SelStringList", ParametersType.List);
- pd.AddSelector(x, "selFloatList", "SelFloatList", ParametersType.List);
pd.AddSelector(x, "selGenericList", "SelGenericList", ParametersType.List);
Console.WriteLine("selectors set");
pd.AddOutlet(x, ParametersType.Float);
@@ -49,80 +46,54 @@ namespace PureData
public void Sel2()
{
pd.PostMessage("Sel2 invoked!");
+
+ // testing outlets
+ Atom[] atoms = new Atom[2];
+ atoms[0] = new Atom("ciao");
+ atoms[1] = new Atom(1.5f);
+ pd.ToOutlet(x, 0, atoms.Length, atoms);
+
}
public void SelFloat(float f)
{
pd.PostMessage("SelFloat received " + f);
- }
- public void SelString(ref string s)
- {
- pd.PostMessage("SelString received " + s);
- }
- public void SelList(int [] list)
- {
- pd.PostMessage("SelList received " + list.Length + " elements");
- for (int i = 0; i<list.Length; i++)
- {
- pd.PostMessage("int " + i + " = " + list[i]);
- }
- }
-
- public void SelStringList(string [] list)
- {
- pd.PostMessage("SetStringList received a " + list.Length + " long list");
- for (int i = 0; i<list.Length; i++)
- {
- pd.PostMessage("string " + i + " = " + list[i]);
- }
}
- public void SelFloatList(float [] list)
+ public void SelString(ref string s)
{
- pd.PostMessage("SetStringList received a " + list.Length + " long list");
- for (int i = 0; i<list.Length; i++)
- {
- pd.PostMessage("float " + i + " = " + list[i]);
- }
+ pd.PostMessage("SelString received " + s);
}
-
- public void SelGenericList(Atom a)
- {
-
- Console.WriteLine("a is type " + a.type);
- Console.WriteLine("float = " + a.float_value);
- Console.WriteLine("stringa = " + a.string_value);
-
- }
-
-
-/*
public void SelGenericList(Atom [] list)
{
- pd.PostMessage("SetStringList received a " + list.Length + " long list");
for (int i = 0; i<list.Length; i++)
{
Atom a = (Atom) list[i];
- Console.WriteLine("a is type " + a.type);
- Console.WriteLine("float = " + a.float_value);
- Console.WriteLine("stringa = " + a.string_value);
- pd.PostMessage("a is type " + a.type);
- pd.PostMessage("float = " + a.float_value);
- pd.PostMessage("stringa = " + a.string_value);
+ switch (a.type)
+ {
+ case (AtomType.Null):
+ {
+ pd.PostMessage("element null");
+ break;
+ }
+ case (AtomType.Float):
+ {
+ pd.PostMessage("" + a.float_value);
+ break;
+ }
+ case (AtomType.Symbol):
+ {
+ pd.PostMessage(a.string_value);
+ break;
+ }
+ }
}
}
-*/
- public int test(int a)
- {
-
- Console.WriteLine("test("+a+")");
- return a+1;
- }
}
diff --git a/external/pd.cs b/external/pd.cs
index 4f05734..87478ae 100755
--- a/external/pd.cs
+++ b/external/pd.cs
@@ -20,7 +20,11 @@ namespace PureData
// TODO
// send stuff to an outlet
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static void ToOutlet (IntPtr x, int outlet, int type /*, ? array of values */);
+ public extern static void ToOutlet (IntPtr x, int outlet, int atoms_length, [In, Out] Atom [] atoms);
+ public static void SendToOutlet (IntPtr x, int outlet, [In, Out] Atom [] atoms)
+ {
+ ToOutlet (x, outlet, atoms.Length, atoms);
+ }
// create an outlet
[MethodImplAttribute (MethodImplOptions.InternalCall)]
@@ -47,153 +51,122 @@ namespace PureData
public extern static void ErrorMessage (string message);
+ /*
+ // simplyfied atom
+ typedef struct atom_simple atom_simple;
+ typedef enum
+ {
+ A_S_NULL=0,
+ A_S_FLOAT=1,
+ A_S_SYMBOL=2,
+ } t_atomtype_simple;
+ typedef struct atom_simple
+ {
+ t_atomtype_simple a_type;
+ union{
+ float float_value;
+ MonoString *string_value;
+ } stuff;
+ };
+ */
}
-
-/*
-// simplyfied atom
-typedef struct atom_simple atom_simple;
-typedef enum
-{
- A_S_NULL=0,
- A_S_FLOAT=1,
- A_S_SYMBOL=2,
-} t_atomtype_simple;
-typedef struct atom_simple
-{
- t_atomtype_simple a_type;
- union{
- float float_value;
- MonoString *string_value;
- } stuff;
-};
-*/
-
public enum AtomType {Null = 0, Float=1, Symbol=2, List=3};
-
- [StructLayout (LayoutKind.Explicit)]
-// [StructLayout (LayoutKind.Sequential)]
- public class Atom2
+ //[StructLayout (LayoutKind.Explicit)]
+ [StructLayout (LayoutKind.Sequential)]
+ public struct Atom
{
- //[FieldOffset (0)] AtomType type;
- //[FieldOffset (0)] public int type;
- [FieldOffset (0)]
- public int type;
-
- [FieldOffset (4)]
+ public AtomType type;
public float float_value;
-
-// [FieldOffset (4)]
- [FieldOffset (8)]
public string string_value;
-
-
- public Atom2()
+ public Atom(float f)
{
- this.type = 0;
- this.float_value = 0;
- this.string_value = "";
+ this.type = AtomType.Float;
+ this.float_value = f;
+ this.string_value = "float";
}
-
- public Atom2(string string_value)
+ public Atom(string s)
{
- this.type = 2;
+ this.type = AtomType.Symbol;
this.float_value = 0;
- this.string_value = string_value;
- }
- public Atom2(float float_value)
- {
- this.type = 1;
- this.string_value = "";
- this.float_value = float_value;
+ this.string_value = s;
}
}
-
-
- //[StructLayout (LayoutKind.Explicit)]
- [StructLayout (LayoutKind.Sequential)]
- public struct Atom
- {
- public int type;
- public float float_value;
- public string string_value;
- }
-
-/*
- typedef float t_floatarg;
+ /*
+ typedef float t_floatarg;
-typedef struct _symbol
-{
- char *s_name;
- struct _class **s_thing;
- struct _symbol *s_next;
- } t_symbol;
+ typedef struct _symbol
+ {
+ char *s_name;
+ struct _class **s_thing;
+ struct _symbol *s_next;
+ } t_symbol;
- EXTERN_STRUCT _array;
-#define t_array struct _array
+ EXTERN_STRUCT _array;
+ #define t_array struct _array
-#define GP_NONE 0
-#define GP_GLIST 1
-#define GP_ARRAY 2
+ #define GP_NONE 0
+ #define GP_GLIST 1
+ #define GP_ARRAY 2
-typedef struct _gstub
- {
- union
- {
- struct _glist *gs_glist;
- struct _array *gs_array;
- } gs_un;
- int gs_which;
- int gs_refcount;
- } t_gstub;
-
-typedef struct _gpointer
- {
- union
- {
- struct _scalar *gp_scalar;
- union word *gp_w;
- } gp_un;
- int gp_valid;
- t_gstub *gp_stub;
- } t_gpointer;
+ typedef struct _gstub
+ {
+ union
+ {
+ struct _glist *gs_glist;
+ struct _array *gs_array;
+ } gs_un;
+ int gs_which;
+ int gs_refcount;
+ } t_gstub;
-typedef union word
+ typedef struct _gpointer
{
-t_float w_float;
-t_symbol *w_symbol;
-t_gpointer *w_gpointer;
-t_array *w_array;
-struct _glist *w_list;
- int w_index;
-} t_word;
+ union
+ {
+ struct _scalar *gp_scalar;
+ union word *gp_w;
+ } gp_un;
+ int gp_valid;
+ t_gstub *gp_stub;
+ } t_gpointer;
-typedef enum
- {
- A_NULL,
- A_FLOAT,
- A_SYMBOL,
- A_POINTER,
- A_SEMI,
- A_COMMA,
- A_DEFFLOAT,
- A_DEFSYM,
- A_DOLLAR,
- A_DOLLSYM,
- A_GIMME,
- A_CANT
- } t_atomtype;
+ typedef union word
+ {
+ t_float w_float;
+ t_symbol *w_symbol;
+ t_gpointer *w_gpointer;
+ t_array *w_array;
+ struct _glist *w_list;
+ int w_index;
+ } t_word;
-#define A_DEFSYMBOL A_DEFSYM
+ typedef enum
+ {
+ A_NULL,
+ A_FLOAT,
+ A_SYMBOL,
+ A_POINTER,
+ A_SEMI,
+ A_COMMA,
+ A_DEFFLOAT,
+ A_DEFSYM,
+ A_DOLLAR,
+ A_DOLLSYM,
+ A_GIMME,
+ A_CANT
+ } t_atomtype;
-typedef struct _atom
- {
- t_atomtype a_type;
- union word a_w;
- } t_atom;
-*/
+ #define A_DEFSYMBOL A_DEFSYM
+
+ typedef struct _atom
+ {
+ t_atomtype a_type;
+ union word a_w;
+ } t_atom;
+ */
}
diff --git a/test-clr.pd b/test-clr.pd
index 18c0730..e2a754d 100755
--- a/test-clr.pd
+++ b/test-clr.pd
@@ -1,4 +1,4 @@
-#N canvas 0 0 738 486 12;
+#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;
@@ -21,8 +21,8 @@
#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 239 387 selGenericList 0.001 abaco 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;