aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xclr.c85
-rwxr-xr-xexternal/External.cs20
-rwxr-xr-xexternal/pd.cs30
-rwxr-xr-xtest-clr.pd4
4 files changed, 116 insertions, 23 deletions
diff --git a/clr.c b/clr.c
index 52c6f42..bdafd74 100755
--- a/clr.c
+++ b/clr.c
@@ -53,10 +53,11 @@ typedef struct atom_simple
{
//t_atomtype_simple a_type;
int a_type;
- union{
+ //MonoString *a_type;
+ //union{
float float_value;
MonoString *string_value;
- } stuff;
+ //} stuff;
};
@@ -70,6 +71,7 @@ typedef struct _clr
MonoDomain *domain;
MonoAssembly *assembly;
MonoObject *obj;
+ MonoImage *image;
MonoMethod *method, *setUp;
MonoClass *klass;
int n;
@@ -102,7 +104,7 @@ static void mono_load(t_clr *x)
{
// const char *file="D:\\Davide\\cygwin\\home\\Davide\\externalTest1.dll";
const char *file="PureData.dll";
- MonoImage *image;
+
MonoMethod *m = NULL, *ctor = NULL, *fail = NULL, *mvalues;
gpointer iter;
gpointer args [1];
@@ -146,12 +148,12 @@ printf("will load %s, random_name %s\n", file, random_name_str);
error("clr: assembly not found!");
}
- image = mono_assembly_get_image (x->assembly);
+ x->image = mono_assembly_get_image (x->assembly);
- x->klass = mono_class_from_name (image, "PureData", "External");
+ 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 (image));
+ error("Can't find MyType in assembly %s\n", mono_image_get_filename (x->image));
//exit (1);
}
x->obj = mono_object_new (x->domain, x->klass);
@@ -292,31 +294,47 @@ void clr_manage_list(t_clr *x, t_symbol *sl, int argc, t_atom *argv)
t_symbol *strsymbol;
float ftmp;
char *str;
+ char strtmp[265], strtmp2[256];
MonoArray * arystr;
- int j;
- arystr = mono_array_new (x->domain, mono_get_string_class (), argc);
+ int j;
+ atom_simple *atmp;
+ atom_simple *atmp2, *atmp3;
+
+ int *tipo;
+ float *fp;
+
+ MonoClass *c = mono_class_from_name (x->image, "PureData", "Atom");
+ arystr = mono_array_new (x->domain, c /*mono_get_string_class ()*/, argc);
+ //arystr = mono_array_new (x->domain, c, 2);
+ /*
for (j=0; j<argc; j++)
{
- atom_simple *atmp = malloc(sizeof(atom_simple));
+ 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;
+ //atmp->a_type = 1;
+ sprintf(strtmp, "1");
+ // atmp->a_type = mono_string_new (x->domain, strtmp);
ftmp = atom_getfloat(argv+j);
- atmp->stuff.float_value = ftmp;
+ atmp->float_value = ftmp;
break;
case A_SYMBOL:
post("setting type symbol in position %i", j);
- atmp->a_type = 2;
+ //atmp->a_type = 2;
+ sprintf(strtmp, "2");
+ // atmp->a_type = mono_string_new (x->domain, strtmp);
strsymbol = atom_getsymbol(argv+j);
- atmp->stuff.string_value = mono_string_new (x->domain, strsymbol->s_name);
+ atmp->string_value = mono_string_new (x->domain, strsymbol->s_name);
break;
default:
post("setting type null in position %i", j);
- atmp->a_type = 0;
+ //atmp->a_type = 0;
+ sprintf(strtmp, "0");
+ // atmp->a_type = mono_string_new (x->domain, strtmp);
}
-
+ // mono_array_set (arystr, MonoString *, j, atmp->a_type);
mono_array_set (arystr, atom_simple *, j, atmp);
//int * ftmp = malloc(sizeof(int));
//*ftmp = j;
@@ -330,7 +348,42 @@ post("setting type null in position %i", j);
//mono_array_set (arystr, gint32 , j, ftmp);
}
- args[0] = arystr;
+ */
+
+ // debug:
+ // send just 1 atom
+
+ atmp2 = malloc(sizeof(atom_simple));
+ atmp2->a_type = 121;
+ atmp2->float_value = atom_getfloat(argv);
+ strsymbol = atom_getsymbol(argv);
+ atmp2->string_value = mono_string_new (x->domain, strsymbol->s_name);
+ 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;
mono_runtime_invoke (x->selectors[i].func, x->obj, args, NULL);
diff --git a/external/External.cs b/external/External.cs
index bc3d361..f09487d 100755
--- a/external/External.cs
+++ b/external/External.cs
@@ -89,16 +89,32 @@ namespace PureData
}
}
+
+ 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];
- pd.PostMessage("list[" + i + "] is type " + a.type + " stringa = " + a.string_value);
- // pd.PostMessage("float " + i + " = " + 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);
+
}
+
}
+*/
public int test(int a)
{
diff --git a/external/pd.cs b/external/pd.cs
index 67befdf..33f7f1f 100755
--- a/external/pd.cs
+++ b/external/pd.cs
@@ -71,13 +71,35 @@ typedef struct atom_simple
public enum AtomType {Null = 0, Float=1, Symbol=2};
[StructLayout (LayoutKind.Explicit)]
- public struct Atom
+// [StructLayout (LayoutKind.Sequential)]
+ public class Atom
{
//[FieldOffset (0)] AtomType type;
- [FieldOffset (0)] public int type;
+ //[FieldOffset (0)] public int type;
+ [FieldOffset (0)]
+ public int type;
/* union members */
- [FieldOffset (4)] public long string_value;
- [FieldOffset (4)] public float float_value;
+ [FieldOffset (4)]
+ public float float_value;
+
+// [FieldOffset (4)]
+ [FieldOffset (8)]
+ public string string_value;
+
+
+
+ public Atom(string string_value)
+ {
+ this.type = 2;
+ this.float_value = 0;
+ this.string_value = string_value;
+ }
+ public Atom(float float_value)
+ {
+ this.type = 1;
+ this.string_value = "";
+ this.float_value = float_value;
+ }
}
diff --git a/test-clr.pd b/test-clr.pd
index a9e508d..18c0730 100755
--- a/test-clr.pd
+++ b/test-clr.pd
@@ -1,4 +1,4 @@
-#N canvas 0 0 734 482 12;
+#N canvas 0 0 738 486 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;
@@ -22,6 +22,7 @@
#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 connect 0 0 14 0;
#X connect 1 0 0 0;
#X connect 2 0 0 0;
@@ -40,3 +41,4 @@
#X connect 17 0 0 0;
#X connect 18 0 0 0;
#X connect 19 0 0 0;
+#X connect 20 0 0 0;