list as inlet of a MSP to?

    May 09 2009 | 6:33 pm
    Hello everybody, I have not understood how can I manage a list of float taken from an inlet of a MSP object. I studied the tutorial of SDK 5 and the examples but I have not found the answer ;-(
    For example I just want to use a method that prints the numbers in the list. The list is just a message with the numbers and no other words. I tryed to do this (but I do not if this is correct):
    I declare a method: void myobject_printlist(t_myobject *x, t_symbol *s, long argc, t_atom *argv);
    In the main I write: class_addmethod(c, (method)myobject_printlist, "list", A_GIMME, 0);
    In the new method what have I to write in order to create an inlet that receive the list? I can´t use floatin((t_pxobject *)x, 1); So what have I to use?
    Thanks in advance
    Best regards

    • May 11 2009 | 12:49 am
      I'm only just learning this stuff myself, but, assuming your object is named "typetest", if you prototype
      void typetest_list(t_typetest *x, t_symbol *msg, short argc, t_atom *argv);
      then in your main declaration:
      class_addmethod(c, (method)typetest_list, "list", A_GIMME, 0);
      and finally, the method
      void typetest_list(t_typetest *x, t_symbol *msg, short argc, t_atom *argv){ if(x->thru_on) outlet_anything(x->outlet,msg,argc,argv); }
      will simply pass a list "1 2 3" to the outlet as a list "1 2 3"
      If you want your list method to do something more complicated, assuming you have declared the outlets properly, the following will parse out the elements of the list according to type:
      void typetest_list(t_typetest *x, t_symbol *msg, short argc, t_atom *argv){ if(x->thru_on) outlet_anything(x->outlet_thru,msg,argc,argv); int i; for(i=0; i t_atom a = argv[i]; switch(argv[i].a_type){ case(A_LONG): outlet_int(x->outlet_i,a.a_w.w_long); break;
      case(A_FLOAT): outlet_float(x->outlet_f,a.a_w.w_float); break;
      case(A_SYM): outlet_anything(x->outlet_s,a.a_w.w_sym,0,NULL); break; } } }
      a complete .c file is attached.
      Special thanks to John MacCallum and the CNMAT dev workshop last week
    • May 11 2009 | 10:59 am
      Hi, really really thanks!!! My problem was that I had to use a proxy!!
      Now it works.
      All the best
    • May 11 2009 | 10:48 pm
      I would recommend to use the atom_gettype, atom_getlong, and co from ext_obex.h instead of accessing the atom structure's elements directly. IMHO, it's more elegant, but the other advantage is that you don't need to worry about how things are handled inside, but just use the methods to access to the specific items. Furthermore in the (highly unlikely) case that the atom structure changed, you wouldn't have to change anything to your code to work because you don't access items directly.
    • May 11 2009 | 10:50 pm
      Definitely! I agree with you.
    • May 12 2009 | 3:26 pm
      yes, i agree, too. The atom_getlong came up after this example
    • May 12 2009 | 6:34 pm
      I'm sure they did. Just thought I would mention the "nice" way. It's good to know both when you want to do some source code archeology anyway