MAX/MSP SDK学习02:普通入口、出口 代理入口的创建和使用

1. 普通入口、出口的创建和使用

#include "ext.h"			// you must include this - it contains the external object's link to available Max functions
#include "ext_obex.h"		// this is required for all objects using the newer style for writing objects.typedef struct _plussz {	// defines our object's internal variables for each instance in a patcht_object p_ob;			// object header - ALL objects MUST begin with this...long p_value0;			// 存储入口0的值long p_value1;			// 存储入口1的值long p_value2;			// 存储入口2的值void* p_outlet0;		// 定义出口指针void* p_outlet1;		// 定义出口指针
} t_plussz;// these are prototypes for the methods that are defined below
void plussz_bang(t_plussz* x);
void plussz_int(t_plussz* x, long n);
void plussz_in1(t_plussz* x, long n);
void plussz_in2(t_plussz* x, long n);
void plussz_assist(t_plussz* x, void* b, long m, long a, char* s);
void* plussz_new(long n);t_class* plussz_class;		// global pointer to the object class - so max can reference the objectvoid ext_main(void* r) {t_class* c;c = class_new("plussz", (method)plussz_new, (method)NULL, sizeof(t_plussz), 0L, A_DEFLONG, 0);class_addmethod(c, (method)plussz_bang, "bang", 0);			// the method it uses when it gets a bang in the left inletclass_addmethod(c, (method)plussz_int, "int", A_LONG, 0);	// 若最左入口传递long(double)数据,其消息必须为"int"("float"). 其余入口依次为"in1"("ft1")、"in2"("ft2")... class_addmethod(c, (method)plussz_in1, "in1", A_LONG, 0);	// 中间入口class_addmethod(c, (method)plussz_in2, "in2", A_LONG, 0);	// 最右入口// "ft1" is the special message for floatsclass_addmethod(c, (method)plussz_assist, "assist", A_CANT, 0);	// (optional) assistance method needs to be declared like thisclass_register(CLASS_BOX, c);plussz_class = c;post("plussz object loaded...", 0);	// post any important info to the max window when our class is loaded
}void* plussz_new(long n) {		// n = int argument typed into object box (A_DEFLONG) -- defaults to 0 if no args are typedt_plussz* x;				// local variable (pointer to a t_plussz data structure)x = (t_plussz*)object_alloc(plussz_class); // create a new instance of this object// 入口创建顺序:从右向左. 入口0默认存在intin(x, 2);					// 创建入口2intin(x, 1);					// 创建入口1// 出口创建顺序:从右向左. 默认无出口,需自己创建x->p_outlet1 = bangout(x);  // 创建出口2,发送bang消息x->p_outlet0 = intout(x);	// 创建出口1,发送int消息x->p_value0 = n;			// set initial (default) left operand value in the instance's data structurex->p_value1 = n;			// set initial (default) right operand value (n = variable passed to plussz_new)x->p_value2 = n;			// set initial (default) right operand value (n = variable passed to plussz_new)post("new plussz object instance added to patch...", 0); // post important info to the max window when new instance is createdreturn(x);					// return a reference to the object instance
}void plussz_assist(t_plussz* x, void* b, long m, long a, char* s) { // 4 final arguments are always the same for the assistance methodif (m == ASSIST_OUTLET)sprintf(s, "Sum of Left and Right Inlets");else {switch (a) {case 0:sprintf(s, "Inlet %ld: Left Operand (Causes Output)", a);break;case 1:sprintf(s, "Inlet %ld: Right Operand (Added to Left)", a);break;}}
}void plussz_bang(t_plussz* x) {		// x = reference to this instance of the objectlong sum;							// local variable for this methodsum = x->p_value0 + x->p_value1;		// add left and right operandsoutlet_int(x->p_outlet0, sum);		// 求和结果从入口0发出outlet_bang(x->p_outlet1);			// bang消息从入口1发出post("int: %d, in1: %d, in2: %d", x->p_value0, x->p_value1, x->p_value2);
}void plussz_int(t_plussz* x, long n) {  // x = the instance of the object; n = the int received in the left inletx->p_value0 = n;					// store left operand value in instance's data structureplussz_bang(x);						// ... call the bang method to sum and send out our outlet
}void plussz_in1(t_plussz* x, long n) {	// x = the instance of the object, n = the int received in the right inletx->p_value1 = n;					// just store right operand value in instance's data structure and do nothing else
}void plussz_in2(t_plussz* x, long n) {x->p_value2 = n;
}

2. 代理入口的创建和使用

#include "ext.h"				// you must include this - it contains the external object's link to available Max functions
#include "ext_obex.h"			// this is required for all objects using the newer style for writing objects.typedef struct _proxyTest {t_object ob;t_atom	l;			// stored value from left inlett_atom	r;			// stored value from right inletvoid* proxy;		// 代理入口void* outlet;		// 出口long proxy_inletnum;	// 当前正在使用的入口
} t_proxyTest;// these are prototypes for the methods that are defined below
void* proxyTest_new(long n);
void proxyTest_free(t_proxyTest* x);
void proxyTest_assist(t_proxyTest* x, void* b, long m, long a, char* s);
void proxyTest_bang(t_proxyTest* x);
void proxyTest_int(t_proxyTest* x, long n);
void proxyTest_float(t_proxyTest* x, double f);t_class* proxyTest_class;		// global pointer to the object class - so max can reference the object//--------------------------------------------------------------------------
void ext_main(void* r) {t_class* c;c = class_new("proxyTest", (method)proxyTest_new, (method)proxyTest_free, sizeof(t_proxyTest), 0L, A_DEFLONG, 0);class_addmethod(c, (method)proxyTest_bang, "bang", 0);			 // the method it uses when it gets a bang in the left inletclass_addmethod(c, (method)proxyTest_int, "int", A_LONG, 0);		 // the method for ints in any inletclass_addmethod(c, (method)proxyTest_float, "float", A_FLOAT, 0);	 // the method for floats in any inletclass_addmethod(c, (method)proxyTest_assist, "assist", A_CANT, 0); // (optional) assistance method needs to be declared like thisclass_register(CLASS_BOX, c);proxyTest_class = c;post("proxyTest object loaded...", 0);	// post any important info to the max window when our class is loaded
}//--------------------------------------------------------------------------
void* proxyTest_new(long n) {  	// n = int argument typed into object box (A_DEFLONG) -- defaults to 0 if no args are typedt_proxyTest* x;				// local variable (pointer to a t_proxyTest data structure)x = (t_proxyTest*)object_alloc(proxyTest_class); // create a new instance of this objectif (x) {x->proxy = proxy_new(x, 1, &x->proxy_inletnum);	// 创建代理入口x->outlet = outlet_new(x, NULL);				// fully-flexible outlet for any type// 赋初值atom_setlong(&x->l, 0);atom_setlong(&x->r, 0);post(" new proxyTest object instance added to patch...", 0); // post important info to the max window when new instance is created}return(x);					// return a reference to the object instance
}void proxyTest_free(t_proxyTest* x) {object_free(x->proxy);		// frees all resources associated with the proxy
}//--------------------------------------------------------------------------
void proxyTest_assist(t_proxyTest* x, void* b, long m, long a, char* s) { // 4 final arguments are always the same for the assistance methodif (m == ASSIST_INLET) {switch (a) {case 0:sprintf(s, "Inlet %ld: Left Operand (Causes Output)", a);break;case 1:sprintf(s, "Inlet %ld: Right Operand (Added to Left)", a);break;}} elsesprintf(s, "Sum of Left and Right Inlets");
}void proxyTest_bang(t_proxyTest* x) {long lop;float fop;if (x->l.a_type == A_LONG && x->r.a_type == A_LONG) {lop = atom_getlong(&x->l) + atom_getlong(&x->r);outlet_int(x->outlet, lop);  // 输出long} else { // OUTPUT A FLOATfop = atom_getfloat(&x->l) + atom_getfloat(&x->r);outlet_float(x->outlet, fop);  // 输出double}
}void proxyTest_int(t_proxyTest* x, long n) {  // 有入口收到long型值long inlet = proxy_getinlet((t_object*)x); // 用proxy_getinlet函数判断哪个入口接收到值,本质是判断proxy_inletnum的值post("int came in via inlet %ld", inlet);if (inlet == 1) { // RIGHT INLETatom_setlong(&x->r, n); // SET INT VAL} else { // LEFT INLET  左入口有值则触发bangatom_setlong(&x->l, n);proxyTest_bang(x); // bang for left inlet, trigger calculation}
}void proxyTest_float(t_proxyTest* x, double f) { // 有入口收到double型值long inlet = proxy_getinlet((t_object*)x); // 用proxy_getinlet函数判断哪个入口接收到值post("float came in via inlet %ld", inlet);if (inlet == 1) { // RIGHT INLETatom_setfloat(&x->r, f); // SET FLOAT VAL} else { // LEFT INLETatom_setfloat(&x->l, f);proxyTest_bang(x); // bang for left inlet, trigger calculation}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/156761.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

学习Rust适合写什么练手项目?【云驻共创】

Rust是一门备受关注的系统级编程语言,因其出色的内存安全性、高性能和并发性能而备受赞誉。对于那些希望学习和掌握Rust编程语言的人来说,练手项目是一个不可或缺的环节。通过实际动手完成项目,你可以加深对Rust语言特性和最佳实践的理解&…

【SpringBoot系列教程-目录大纲】

《SpringBoot系列教程-目录大纲》 教程分为5大章节,内容包括SpringBoot基本概念、SpringBoot好处、SpringBoot快速入门、yml语法、SpringBoot自动配置原理、自动配置类、属性配置类、TypeExcludeFilter排除器、AutoConfigurationExcludeFilter排除器、自定义场景启…

DAY59 503.下一个更大元素II + 42. 接雨水

503.下一个更大元素II 题目要求: 给定一个循环数组(最后一个元素的下一个元素是数组的第一个元素),输出每个元素的下一个更大元素。数字 x 的下一个更大的元素是按数组遍历顺序,这个数字之后的第一个比它更大的数&am…

HSV色彩空间 GRAY色彩空间

HSV色彩空间 BGR色彩空间是基于三基色而言,即红色、绿色、蓝色。而HSV色彩空间则是基于色调、饱和度和亮度而言的。 色调(H)是指光的颜色,例如,彩虹中的赤,橙,黄,绿,青…

【TCP连接的状态】

linux查看tcp的状态命令: 1)、netstat -nat 查看TCP各个状态的数量 2)、lsof -i:port 可以检测到打开套接字的状况 3)、 sar -n SOCK 查看tcp创建的连接数 4)、tcpdump -iany tcp port 9000 对tcp端口为9000的进行抓包 查看占用端口…

【运维】永久关闭selinux不当,导致无法启动

现象: 卡centos loading进度条 按esc键发现,启动报错: Failed to load SElinux policy ,freezing 可能的原因: selinuxdisabled 写错成disable 或者 错误的把selinuxtype改了,要改文中红框的部分。 解决方案: 1. 重启 2. 出现选择画面的时候 按e 3. 方向下键…

5-4计算一串字符的空格数字字符其他

#include<stdio.h> int main(){char c;int space0;//空格int letters0;//英文字母int numbers0;//数字int others0;//其他字符printf("请输入一行字符&#xff1a;");while((cgetchar())!\n)//获取字符的内容&#xff0c;到\n停止{if(c>a&&c<z|…

c语言常见的面试问题

在C语言编程中&#xff0c;面试官可能会询问你以下一些常见问题&#xff1a; 什么是C语言&#xff1f; C语言是一种通用的、过程式的计算机编程语言&#xff0c;由Dennis Ritchie在1972年创建。它是Unix操作系统的核心语言&#xff0c;也是许多其他编程语言&#xff08;如Go、…

树与二叉树堆:二叉树

二叉树的概念&#xff1a; 二叉树是树的一种&#xff0c;二叉树是一个节点&#xff0c;最多只有两个子节点&#xff0c;二叉树是一个特殊的树二叉树的度最大为2 从上图可得一棵二叉树是结点的一个有限集合&#xff0c;该集合: 或者为空由一个根结点加上两棵别称为左子树和右子…

【c++】前缀和教程

今天来讲前缀和 前缀和是什么&#xff1f; 我们先来看一个问题&#xff1a; 读入n和m&#xff0c;读入n个数&#xff0c;接下来m行&#xff0c;每行读入两个数a和b&#xff0c;输出第a个数加到第b个数 输入样例&#xff1a; 5 1 2 3 4 5 2 1 2 3 5 输出样例&#xff1…

P2 C++变量

前言 一 C变量的作用 本期我们来讨论一下c 中的变量。 在一个 C 程序中&#xff0c;大部分内容实际上都是在使用数据。我们操作任何类型的数据&#xff0c;如包括我们想要改变、想要修改&#xff0c; 想要读和写数据。我们都需要把数据存储进叫做变量的东西里面。变量允许我们…

SQL Server Count()函数

SQL Server Count()函数 SQL Server COUNT() 是一个聚合函数&#xff0c;它返回在集合中找到的项目数。 COUNT() 函数语法&#xff1a; COUNT([ALL | DISTINCT ] expression)ALL 指示COUNT() 函数应用于所有值。ALL是默认值。返回非NULL值的数量&#xff08;包括重复值&…

电子科技大学 分布式系统 期末复习笔记

第一章 为什么需要分布式系统&#xff1a;功能分离&#xff0c;固有的分布性&#xff0c;负载均衡&#xff0c;可靠性&#xff0c;经济性。 定义&#xff1a;分布式系统是这样一种系统&#xff0c;其中位于联网计算机上的组件仅通过传递消息来通信和协调它们的操作。 特点&am…

多模态大一统:通向全模态学习和通用人工智能的未来之路

随着AI技术的不断发展&#xff0c;研究者们正试图构建一种真正通用的人工智能&#xff0c;它能像人们那样以统一的方式处理和理解多种模态的信息。多模态大一统是这一愿景的关键&#xff0c;它旨在开启全模态LLM&#xff08;深度学习语言模型&#xff09;和通用AI时代的大门。在…

【ctfshow】web入门-信息搜集-web11~20

【ctfshow】web入门-信息搜集-web11~17 web11_域名其实也可以隐藏信息&#xff0c;比如flag.ctfshow.com 就隐藏了一条信息web12_有时候网站上的公开信息&#xff0c;就是管理员常用密码web13_技术文档里面不要出现敏感信息&#xff0c;部署到生产环境后及时修改默认密码web14_…

异行星低代码平台--第三方插件对接:钉钉平台对接(一)

异行星低代码平台可以集成钉钉&#xff0c;实现单点登录、消息推送和组织机构同步。 提示 此功能需要企业版授权才能使用。 钉钉集成​ 单点登录 异行星低代码平台集成到钉钉后&#xff0c;只要使用钉钉账户登录钉钉客户端&#xff0c;即可在钉钉中直接使用管理后台&#…

【漏洞复现】IP-guard WebServer 存在远程命令执行漏洞

漏洞描述 IP-guard是由溢信科技股份有限公司开发的一款终端安全管理软件,旨在帮助企业保护终端设备安全、数据安全、管理网络使用和简化IT系统管理。 免责声明 技术文章仅供参考,任何个人和组织使用网络应当遵守宪法法律,遵守公共秩序,尊重社会公德,不得利用网络从事危…

【C++】map multimap

文章目录 1.map介绍2.map的使用3.multimap介绍4.multimap的使用 1.map介绍 map的文档 翻译&#xff1a; map是关联容器&#xff0c;它按照特定的次序(按照key来比较)存储由键值key和值value组合而成的元素。 在map中&#xff0c;键值key通常用于排序和惟一地标识元素&#x…

Arthas查看数据库durid数据源情况

1、下载arthas curl -O https://arthas.aliyun.com/arthas-boot.jar 2、启动arthas java -jar arthas-boot.jar 3、查看数据库连接池配置 vmtool --action getInstances --className com.alibaba.druid.pool.DruidDataSource --express instances.{? #this.dbTypeName&qu…

动态时钟实现

前端HTMLCSS3JavaScript实现动态时钟 一、实现思路概述二、源代码(包含HTML、CSS、JS)三、图片资源与效果截图1. 图片资源2. 效果截图 一、实现思路概述 1. 通过HTML搭建基本时钟的页面结构(这里将时钟图片资源作为背景图&#xff09;2. 将时钟背景和时/分/秒图片进行CSS位置居…