From 447a1fe81422c021e33787ba11c56fa34d379c9d Mon Sep 17 00:00:00 2001 From: Davide Morelli Date: Mon, 16 Jan 2006 16:26:58 +0000 Subject: now selectors take delegates instead of function names, lists without selectors ok, added the PureData.dll assembly to let people compile externals without having to compile the pd project svn path=/trunk/externals/clr/; revision=4424 --- PureData.dll | Bin 0 -> 20480 bytes clr.c | 56 ++++++++++++++++++- external/External.cs | 22 ++++---- pd/Atom.cs | 22 +++++++- pd/pd.cs | 152 +++++++++++++++++++-------------------------------- test-clr.pd | 8 ++- 6 files changed, 147 insertions(+), 113 deletions(-) create mode 100755 PureData.dll diff --git a/PureData.dll b/PureData.dll new file mode 100755 index 0000000..82826a6 Binary files /dev/null and b/PureData.dll differ diff --git a/clr.c b/clr.c index a699f03..9356402 100755 --- a/clr.c +++ b/clr.c @@ -355,13 +355,65 @@ void clr_manage_list(t_clr *x, t_symbol *sl, int argc, t_atom *argv) float valFloat; int i; - // first i extract the first atom which should be a symbol -post("clr_manage_list, got symbol = %s", sl->s_name); if (x->loaded == 0) { error("assembly not specified"); return; } + + // check if a selector is present ! + //printf("clr_manage_list, got symbol = %s\n", sl->s_name); + if (strcmp("list", sl->s_name) == 0) + { + printf("lista senza selector"); + if (x->manageList) + { + gpointer args [1]; + MonoString *stringtmp; + double *floattmp; + t_atomtype_simple *typetmp; + t_symbol *strsymbol; + MonoArray *atoms; + atom_simple *atom_array; + int j; + 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->imagePureData, "PureData", "Atom"); + atoms = mono_array_new (x->domain, c, argc); + for (j=0; ja_type) + { + case A_FLOAT: + 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: + atom_array[j].a_type = A_S_SYMBOL; + strsymbol = atom_getsymbol(argv+j); + atom_array[j].string_value = mono_string_new (x->domain, strsymbol->s_name); + atom_array[j].float_value = 0; + break; + default: + 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 (atoms, atom_simple , j, atom_array[j]); + } + + args[0] = atoms; + mono_runtime_invoke (x->manageList, x->obj, args, NULL); + return; + } else + { + error("you did not specified a function to call for lists without selectors"); + return; + } + } for (i=0; iselectors[i].sel, sl->s_name) == 0) diff --git a/external/External.cs b/external/External.cs index 8abcd68..7e5a69c 100755 --- a/external/External.cs +++ b/external/External.cs @@ -17,15 +17,16 @@ namespace PureData // now you can do what you like... Console.WriteLine("pointer set!"); Console.WriteLine("setting selectors.."); - pd.AddSelector(x, "sel1", "Sel1", ParametersType.None); - pd.AddSelector(x, "sel2", "Sel2", ParametersType.None); - pd.AddSelector(x, "selFloat", "SelFloat", ParametersType.Float); - pd.AddSelector(x, "selString", "SelString", ParametersType.Symbol); - pd.AddSelector(x, "selGenericList", "SelGenericList", ParametersType.List); + pd.AddSelector(x, "sel1", new pd.DelegateWithoutArguments(Sel1)); + pd.AddSelector(x, "sel2", new pd.DelegateWithoutArguments(Sel2)); + pd.AddSelector(x, "selFloat", new pd.DelegateFloat(SelFloat)); + pd.AddSelector(x, "selString", new pd.DelegateString(SelString)); + pd.AddSelector(x, "selGenericList", new pd.DelegateArray(SelGenericList)); + pd.AddSelector(x, new pd.DelegateArray(SelGenericList)); - pd.AddSelector(x, "", "GetBang", ParametersType.Bang); - pd.AddSelector(x, "", "GetFloat", ParametersType.Float); - pd.AddSelector(x, "", "GetSymbol", ParametersType.Symbol); + pd.AddSelector(x, new pd.DelegateWithoutArguments(GetBang)); + pd.AddSelector(x, new pd.DelegateFloat(GetFloat)); + pd.AddSelector(x, new pd.DelegateString(GetSymbol)); Console.WriteLine("selectors set"); pd.AddOutlet(x, ParametersType.Float); @@ -34,7 +35,7 @@ namespace PureData public void GetBang() { - pd.PostMessage("GetBang invoked!"); + pd.PostMessage("GetBang invoked!"); } public void GetFloat(float f) @@ -101,7 +102,7 @@ namespace PureData } case (AtomType.Symbol): { - ret[i] = new Atom(a.string_value + "-lo-giuro"); + ret[i] = new Atom(a.string_value + "-edited"); pd.PostMessage(a.string_value); break; } @@ -111,6 +112,7 @@ namespace PureData } + } diff --git a/pd/Atom.cs b/pd/Atom.cs index 17c7183..e6c723e 100755 --- a/pd/Atom.cs +++ b/pd/Atom.cs @@ -31,4 +31,24 @@ namespace PureData this.string_value = s; } } -} \ No newline at end of file + // this struct is relative to this c struct, see clr.c + + /* + // 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; + }; + */ +} diff --git a/pd/pd.cs b/pd/pd.cs index a0f28aa..1ec0903 100755 --- a/pd/pd.cs +++ b/pd/pd.cs @@ -9,15 +9,47 @@ namespace PureData public class pd { + public delegate void DelegateWithoutArguments(); + public delegate void DelegateFloat(float f); + public delegate void DelegateString(ref string s); + public delegate void DelegateArray(Atom [] atoms); + [MethodImplAttribute (MethodImplOptions.InternalCall)] private extern static void RegisterSelector (IntPtr x, string sel, string met, int type); // function called by the user - public static void AddSelector(IntPtr x, string sel, string met, ParametersType type) + public static void AddSelector(IntPtr x, string sel, DelegateWithoutArguments func) + { + RegisterSelector (x, sel, func.Method.Name, (int) ParametersType.None); + } + public static void AddSelector(IntPtr x, string sel, DelegateFloat func) + { + RegisterSelector (x, sel, func.Method.Name, (int) ParametersType.Float); + } + public static void AddSelector(IntPtr x, string sel, DelegateString func) + { + RegisterSelector (x, sel, func.Method.Name, (int) ParametersType.Symbol); + } + public static void AddSelector(IntPtr x, string sel, DelegateArray func) + { + RegisterSelector (x, sel, func.Method.Name, (int) ParametersType.List); + } + public static void AddSelector(IntPtr x, DelegateWithoutArguments func) + { + RegisterSelector (x, "", func.Method.Name, (int) ParametersType.None); + } + public static void AddSelector(IntPtr x, DelegateFloat func) + { + RegisterSelector (x, "", func.Method.Name, (int) ParametersType.Float); + } + public static void AddSelector(IntPtr x, DelegateString func) + { + RegisterSelector (x, "", func.Method.Name, (int) ParametersType.Symbol); + } + public static void AddSelector(IntPtr x, DelegateArray func) { - RegisterSelector (x, sel, met, (int) type); + RegisterSelector (x, "", func.Method.Name, (int) ParametersType.List); } - // TODO // send stuff to an outlet [MethodImplAttribute (MethodImplOptions.InternalCall)] private extern static void ToOutlet (IntPtr x, int outlet, int atoms_length, Atom [] atoms); @@ -31,6 +63,25 @@ namespace PureData atoms[0] = atom; ToOutlet (x, outlet, atoms.Length, atoms); } + public static void SendToOutlet (IntPtr x, int outlet, float f) + { + Atom [] atoms = new Atom[1]; + atoms[0] = new Atom(f); + ToOutlet (x, outlet, atoms.Length, atoms); + } + public static void SendToOutlet (IntPtr x, int outlet, int i) + { + Atom [] atoms = new Atom[1]; + atoms[0] = new Atom((float) i); + ToOutlet (x, outlet, atoms.Length, atoms); + } + public static void SendToOutlet (IntPtr x, int outlet, string s) + { + Atom [] atoms = new Atom[1]; + atoms[0] = new Atom(s); + ToOutlet (x, outlet, atoms.Length, atoms); + } + // create an outlet [MethodImplAttribute (MethodImplOptions.InternalCall)] private extern static void CreateOutlet (IntPtr x, int type); @@ -55,102 +106,9 @@ namespace PureData [MethodImplAttribute (MethodImplOptions.InternalCall)] 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; - }; - */ } - /* - 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; - */ + } diff --git a/test-clr.pd b/test-clr.pd index 4697138..87bf798 100755 --- a/test-clr.pd +++ b/test-clr.pd @@ -1,4 +1,4 @@ -#N canvas 73 31 756 564 12; +#N canvas 73 31 760 568 12; #X obj 49 51 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X floatatom 65 70 5 0 0 0 - - -; @@ -13,8 +13,8 @@ #X obj 227 263 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X text 224 242 mapped to selFloat; -#X msg 99 216 selGenericList 12 a 0.5 b; -#X text 98 194 complex list; +#X msg 94 210 selGenericList 12 a 0.5 b; +#X text 93 188 complex list; #X obj 82 297 print; #X text 43 329 arguments: Class name \, Filename; #X obj 438 353 clr Counter External.dll 2; @@ -34,6 +34,7 @@ with the stored one; #X text 287 3 more than one class can be compiled in the same assembly ; #X text 37 477 NB: a class corresponding constructor must exist; +#X msg 309 210 1 2 3 a b c; #X connect 0 0 16 0; #X connect 1 0 16 0; #X connect 2 0 16 0; @@ -49,3 +50,4 @@ with the stored one; #X connect 22 0 15 0; #X connect 24 0 15 1; #X connect 26 0 15 0; +#X connect 29 0 16 0; -- cgit v1.2.1