MAX/MSP SDK学习07:list传递

实现自定义Obejct,要求将传入的一组数据+100后传出。

#include "ext.h"		
#include "ext_obex.h"		

typedef struct _listTrans {
	t_object	ob;
	void* outLet;
	t_atom* fList;   // 经常发送较大的list,则建议使用t_atom数组保存
	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) { // inlet
		sprintf(s, "I am inlet %ld", a);
	} else {	// outlet
		sprintf(s, "I am outlet %ld", a);
	}
}

void listTrans_free(t_listTrans* x) {
	sysmem_freeptr(x->fList);
}

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->outLet = listout(x);
	x->listNum = 0;

	return (x);
}

void listTrans_recv_list(t_listTrans* x, t_symbol* s, long argc, t_atom* argv) {
	x->fList = (t_atom*)sysmem_newptr(sizeof(t_atom) * argc);
	x->listNum = argc;
	//outlet_list(x->outLet, gensym("list"), argc, argv);

	for (int i = 0; i < argc; i++) {  // 经常发送较大的list,则建议使用t_atom数组
		atom_setfloat(&(x->fList[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->fList[i])) + 100);
	//}
	outlet_list(x->outLet, gensym("list"), x->listNum, x->fList);
	//outlet_anything(x->outLet, gensym("list"), x->listNum, x->fList); 
}

运行结果:


补充:

除了使用outlet_anything外,还可使用outlet_list输出list.

相关推荐

  1. <span style='color:red;'>03</span>_<span style='color:red;'>list</span>

    03_list

    2023-12-06 06:00:04      35 阅读
  2. C++学习-List学习

    2023-12-06 06:00:04       29 阅读
  3. 01.Linked-List-Sort

    2023-12-06 06:00:04       19 阅读
  4. 第三题——LCP 07. 传递信息

    2023-12-06 06:00:04       25 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-06 06:00:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-06 06:00:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-06 06:00:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-06 06:00:04       18 阅读

热门阅读

  1. day70

    day70

    2023-12-06 06:00:04      32 阅读
  2. Qt与Sqlite3

    2023-12-06 06:00:04       41 阅读
  3. gitlab 迁移-安装-还原

    2023-12-06 06:00:04       27 阅读
  4. gitlab 迁移-安装-还原

    2023-12-06 06:00:04       33 阅读
  5. 驱动模块--内核模块

    2023-12-06 06:00:04       42 阅读
  6. UI界面程序鼠标右键弹出菜单的一些事

    2023-12-06 06:00:04       39 阅读
  7. 学习TypeScrip3(接口和对象类型)

    2023-12-06 06:00:04       38 阅读
  8. vue自定义指令配置小程序按钮权限

    2023-12-06 06:00:04       36 阅读