实现自定义Obejct,要求将传入的一组数据+100后传出。
#include "ext.h"
#include "ext_obex.h" typedef struct _listTrans {t_object ob;void* outLet;t_atom* fArr;long listNum;} t_listTrans;void* listTrans_new(t_symbol* s, long argc, t_atom* argv);
void listTrans_free(t_listTrans* x);
void listTrans_assist(t_listTrans* x, void* b, long m, long a, char* s);
void listTrans_recv_list(t_listTrans* x, t_symbol* s, long argc, t_atom* argv);
void listTrans_snd_list(t_listTrans* x);void* listTrans_class;void ext_main(void* r) {t_class* c;c = class_new("listTrans", (method)listTrans_new, (method)listTrans_free, (long)sizeof(t_listTrans),0L /* leave NULL!! */, A_GIMME, 0);class_addmethod(c, (method)listTrans_assist, "assist", A_CANT, 0);class_addmethod(c, (method)listTrans_recv_list, "list", A_GIMME, 0);class_addmethod(c, (method)listTrans_snd_list, "bang", 0);class_register(CLASS_BOX, c); /* CLASS_NOBOX */listTrans_class = c;post("I am the listTrans object");
}void listTrans_assist(t_listTrans* x, void* b, long m, long a, char* s) {if (m == ASSIST_INLET) { // inletsprintf(s, "I am inlet %ld", a);} else { // outletsprintf(s, "I am outlet %ld", a);}
}void listTrans_free(t_listTrans* x) {sysmem_freeptr(x->fArr);
}void* listTrans_new(t_symbol* s, long argc, t_atom* argv) {t_listTrans* x = NULL;x = (t_listTrans*)object_alloc(listTrans_class);x->outLet = outlet_new(x, NULL);x->listNum = 0;return (x);
}void listTrans_recv_list(t_listTrans* x, t_symbol* s, long argc, t_atom* argv) {x->fArr = (t_atom*)sysmem_newptr(sizeof(t_atom) * argc);x->listNum = argc;for (int i = 0; i < argc; i++) {atom_setfloat(&(x->fArr[i]), atom_getfloat(&argv[i]) + 100);}
}void listTrans_snd_list(t_listTrans* x) {//for (int i = 0; i < x->listNum; i++) {// outlet_float(x->outLet, atom_getfloat(&(x->fArr[i])) + 100);//}outlet_anything(x->outLet, gensym("list"), x->listNum, x->fArr);
}
运行结果:
补充:
除了使用outlet_anything外,还可使用outlet_list输出list.