diff options
-rwxr-xr-x | clr.c | 65 | ||||
-rwxr-xr-x | external/External.cs | 16 | ||||
-rwxr-xr-x | external/pd.cs | 114 | ||||
-rwxr-xr-x | makefile | 4 | ||||
-rwxr-xr-x | test-clr.pd | 8 |
5 files changed, 187 insertions, 20 deletions
@@ -38,9 +38,28 @@ typedef struct outletList outletList; typedef struct outletList
{
t_outlet *outlet_pointer;
-// selectorList *next; // next element of the list
+// outletList *next; // next element of the list
+};
+
+// 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;
+ int a_type;
+ union{
+ float float_value; + MonoString *string_value;
+ } stuff;
};
+
static t_class *clr_class;
typedef struct _clr
@@ -55,6 +74,7 @@ typedef struct _clr MonoClass *klass;
int n;
+ // TODO: dynamic memory allocation
selectorList selectors[MAX_SELECTORS];
outletList outlets[MAX_OUTLETS];
@@ -237,7 +257,6 @@ void clr_manage_list(t_clr *x, t_symbol *sl, int argc, t_atom *argv) if (strcmp(x->selectors[i].sel, sl->s_name) == 0) { // I've found the selector! -printf("selector %s, func %s\n", sl->s_name, x->selectors[i].sel); if (x->selectors[i].func) { // ParametersType {None = 0, Float=1, Symbol=2, List=3}; @@ -271,30 +290,50 @@ printf("selector %s, func %s\n", sl->s_name, x->selectors[i].sel); gpointer args [1]; MonoString *strmono; t_symbol *strsymbol; + float ftmp; char *str; MonoArray * arystr; - int j; -printf("preparo l'array\n"); - + int j; arystr = mono_array_new (x->domain, mono_get_string_class (), argc); for (j=0; j<argc; j++) { - int * ftmp = malloc(sizeof(int)); - *ftmp = j; - strsymbol = atom_getsymbol(argv+j); - MonoString *arg = mono_string_new (x->domain, strsymbol->s_name);
- mono_array_set (arystr, MonoString *, j, arg); + 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; + ftmp = atom_getfloat(argv+j); + atmp->stuff.float_value = ftmp; + break; + case A_SYMBOL: +post("setting type symbol in position %i", j); + atmp->a_type = 2; + strsymbol = atom_getsymbol(argv+j); + atmp->stuff.string_value = mono_string_new (x->domain, strsymbol->s_name); + break; + default: +post("setting type null in position %i", j); + atmp->a_type = 0; + } + + 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); - } args[0] = arystr; //args[0] = strings; -printf("mando a mono\n"); mono_runtime_invoke (x->selectors[i].func, x->obj, args, NULL); -printf("ho mandatao a mono\n"); break; } } diff --git a/external/External.cs b/external/External.cs index 3923f06..bc3d361 100755 --- a/external/External.cs +++ b/external/External.cs @@ -33,6 +33,7 @@ namespace PureData 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);
pd.AddInlet(x, "selFloat", ParametersType.Float);
@@ -79,12 +80,23 @@ namespace PureData }
}
- public void SelFloatList(int [] list)
+ public void SelFloatList(float [] list)
{
pd.PostMessage("SetStringList received a " + list.Length + " long list");
for (int i = 0; i<list.Length; i++)
{
- pd.PostMessage("float " + i + " = " + list[0]);
+ pd.PostMessage("float " + i + " = " + list[i]);
+ }
+ }
+
+ 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]);
}
}
diff --git a/external/pd.cs b/external/pd.cs index c844195..67befdf 100755 --- a/external/pd.cs +++ b/external/pd.cs @@ -1,5 +1,7 @@ using System;
-using System.Runtime.CompilerServices;
+using System.Runtime.CompilerServices; // for extern import
+using System.Runtime.InteropServices; // for structures
+
namespace PureData
{
@@ -46,4 +48,114 @@ namespace PureData }
+
+/*
+// 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};
+
+ [StructLayout (LayoutKind.Explicit)]
+ public struct Atom
+ {
+ //[FieldOffset (0)] AtomType type;
+ [FieldOffset (0)] public int type;
+ /* union members */
+ [FieldOffset (4)] public long string_value;
+ [FieldOffset (4)] public float float_value;
+ }
+
+
+
+/* + typedef float t_floatarg; + +typedef struct _symbol +{ + char *s_name; + struct _class **s_thing; + struct _symbol *s_next; + } t_symbol; + + EXTERN_STRUCT _array; +#define t_array struct _array + + + +#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 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; + +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; + +#define A_DEFSYMBOL A_DEFSYM + +typedef struct _atom + { + t_atomtype a_type; + union word a_w; + } t_atom; +*/
+
}
@@ -20,8 +20,8 @@ LINUXCFLAGS = -DPD -O2 -mno-cygwin LINUXINCLUDE = -I../../src -I$PDPATH
-MONOSRC = -ID:/Davide/cygwin/tmp/build_deps/include -ID:/Davide/cygwin/tmp/build_deps/include/glib-2.0 -ID:/Davide/cygwin/tmp/build_deps/lib/glib-2.0/include -ID:/Davide/cygwin/home/Davide/mono/include
-MONOLIB = -LD:/Davide/cygwin/tmp/build_deps/lib -LD:/Davide/cygwin/home/Davide/mono/lib -lmono -lm -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl -liconv
+MONOSRC = -IC:/cygwin/tmp/build_deps/include -IC:/cygwin/tmp/build_deps/include/glib-2.0 -IC:/cygwin/tmp/build_deps/lib/glib-2.0/include -IC:/cygwin/home/Davide/mono/include
+MONOLIB = -LC:/cygwin/tmp/build_deps/lib -LC:/cygwin/home/Davide/mono/lib -lmono -lm -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl -liconv
.c.dll:
# gcc $(LINUXCFLAGS) $(LINUXINCLUDE) `pkg-config --cflags --libs mono` -lm -ID:/Davide/cygwin/home/Davide/mono/include -LD:/Davide/cygwin/home/Davide/mono/lib $*.c
diff --git a/test-clr.pd b/test-clr.pd index 91f24dd..a9e508d 100755 --- a/test-clr.pd +++ b/test-clr.pd @@ -1,4 +1,4 @@ -#N canvas 0 0 726 474 12;
+#N canvas 0 0 734 482 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;
@@ -18,8 +18,10 @@ #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 248 360 selFloatList 1 2 3 4;
#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 connect 0 0 14 0;
#X connect 1 0 0 0;
#X connect 2 0 0 0;
@@ -36,3 +38,5 @@ #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;
|