events

what it is
using
the MIDI event
the OSC event
creating custom events

Events

In addition to the built-in(嵌入的) timing mechanisms(机制) for internal(内部的) control, ChucK has an event class to allow exact synchronization(精确同步) across an arbitrary(任意的) number of shreds.
事件类允许在任意的进程间实现精确同步

View sample code for events

what they are

ChucK events are a native class(原始类) within the ChucK language. We can create an event objects, and then chuck (=>) that event to now.
The event places the current shred on the event’s waiting list, suspends(暂停) the current shred (letting time advance from that shred’s point of view).
时间放置在当前进程的事件的等待列表里,暂停当前进程(从时间的观测点推进时间)
When the event is triggered(引发), one or more of the shreds on its waiting list is shreduled to run immediately.
时间被引发时,在进程的等待列表里调用运行
This trigger(触发器) may originate(引起) from another ChucK shred, or from activities taking place outside the Virtual Machine ( MIDI, OSC, or IPC ).

// declare event
Event e;// function for shred
fun void eventshred( Event event, string msg )
{// infinite loopwhile ( true ){// wait on eventevent => now;// print<<<msg>>>;}
}// create shreds
spork ~ eventshred ( e, "fee" );
spork ~ eventshred ( e, "fi" );
spork ~ eventshred ( e, "fo" );
spork ~ eventshred ( e, "fum" );// infinite time loop
while ( true )
{// either signal or broadcast(信号或广播)if( maybe ){ <<<"signaling...">>>;e.signal();}else{ <<<"broadcasting...">>>;e.broadcast();}// advance time0.5::second => now;
}

use

Chucking an event to now suspends the current shred, letting time advance:

// declare Event
Event e;// ...// wait on the event
e => now;// after the event is trigger
<<< "I just woke up" >>>;

as shown above, events can be triggered in two ways, depending on the desired behavior(行为).

// signal one shred waiting on the event e
e.signal();

signal() releases the first shred in that event’s queue, and shredule it to run at the current time, respecting(考虑) the order in which shreds were added to the queue.

// wake up all shreds waiting on the event e
e.broadcast();

broadcast() releases all shreds queued by that event, in the order they were added, and at the same instant in time(在同一瞬间).

The released shreds are shreduled to run immediately. But of course they will respect(涉及) other shreds also shreduled to run at the same time. Furthermore(此外), the shred that called signal() or broadcast() will continue to run until it advances time itself, or yield the virtual(虚拟的) machine without advancing time. (see me.yield() under concurrency)

MIDI events

ChucK contains built-in(嵌入的) MIDI classes to allow for interaction(相互作用) with MIDI based software or devices(装置).

MidiIn min;
MidiMsg msg;// open midi receiver, exit on fail
if ( !min.open(0) ) me.exit(); while( true )
{// wait on midi eventmin => now;// receive midimsg(s)while( min.recv( msg ) ){// print content<<< msg.data1, msg.data2, msg.data3 >>>;}
}...

MidiIn is a subclass(子类) of Event, and as such can be ChucKed to now. MidiIn then takes a MidiMsg object to its .recv() method to access the MIDI data.
As a default, MidiIn events trigger(引发) the broadcast() event behavior.

OSC events

In addition to MIDI, ChucK has OSC communication classes as well:

...// create our OSC receiver
OscRecv orec;
// port 6449
6449 => orec.port;
// start listening (launch thread)
orec.listen();function void rate_control_shred()
{ // create an address in the receiver // and store it in a new variable.orec.event("/sndbuf/buf/rate,f") @=> OscEvent rate_event; while ( true ){ rate_event => now; // wait for events to arrive.// grab the next message from the queue. while( rate_event.nextMsg() != 0 ){ // getFloat fetches the expected float// as indicated in the type string ",f"buf.play( rate_event.getFloat() );0 => buf.pos;}}
}...

The OscRecv class listens for incoming OSC packets on the specified(特定的) port. Each instance(实例) of OscRecv can create OscEvent objects using its event() method to listen for packets at any valid OSC Address pattern.(在任何合法的OSC地址模式,使用事件方法来监听数据包)

An OscEvent object can then be ChucKed to now
to wait for messages to arrive,
after which the nextMsg() and get{Float|String|Int}() methods can be used
to fetch message data.

creating custom events

Events, like any other class, can be subclassed to add functionality(功能) and transmit(传输) data:

// extended event扩充事件
class TheEvent extends Event
{int value;
}// the event
TheEvent e;// handler
fun int hi( TheEvent event )
{while( true ){// wait on eventevent => now;// get the data<<<e.value>>>;}
}// spork
spork ~ hi( e );
spork ~ hi( e );
spork ~ hi( e );
spork ~ hi( e );// infinite time loop
while( true )
{// advance time1::second => now;// set dataMath.rand2( 0, 5 ) => e.value;// signal one waiting shrede.signal();
}

ChucK初步(13)相关推荐

  1. 机器视觉初步13:3D相机介绍

    文章目录 1. 结构光(Structured Light) 2. 飞行时间(Time of Flight,ToF) 3. 双目视觉(Stereo Vision) 4. 线扫描(Line Scan) 5 ...

  2. 仙剑奇侠传 游戏 开发 教程 Xianjian qixia development Game development tutorial

    仙剑奇侠传 开发  游戏 开发 教程 Xianjian qixia development Game development tutorial 作者:韩梦飞沙 Author:han_meng_fei_ ...

  3. matlab高等数学实验章栋恩,MATLAB高等数学实验(第2版)

    第一篇 准 备 实 验 MATLAB软件操作1 0.1 MATLAB软件的启动1 0.2 MATLAB常用命令.符号2 0.3 数组及其运算6 0.4 MATLAB文件与编程9 0.5 符号运算初步1 ...

  4. mahout安装测试

    Mahout 是 Apache Software Foundation(ASF) 旗下的一个开源项目,提供一些可扩展的机器学习领域经典算法的实现,旨在帮助开发人员更加方便快捷地创建智能应用程序.Apa ...

  5. Linux Kernel 5.13 稳定版发布:初步支持 M1 芯片

    责编 | 张红月 出品 | CSDN(ID:CSDNnews) Linus Torvalds 发布了Linux Kernel 5.13 稳定版,该内核以全新的"Opossums on Par ...

  6. 蔚来回应测试车坠楼:初步确认为意外事故;首发苹果M2,新MacBook Pro 13英寸正式开售:9999元起|极客头条

    「极客头条」-- 技术人员的新闻圈! CSDN 的读者朋友们早上好哇,「极客头条」来啦,快来看今天都有哪些值得我们技术人关注的重要新闻吧. 整理 | 梦依丹 出品 | CSDN(ID:CSDNnews ...

  7. 初步使用计算机ppt课件,《计算机应用基础教程》第13课:网页制作初步课件.ppt...

    <<计算机应用基础教程>第13课:网页制作初步课件.ppt>由会员分享,提供在线免费全文阅读可下载,此文档格式为ppt,更多相关<<计算机应用基础教程>第13 ...

  8. 多元函数概念思维导图_(重要!)高中数学概念品味+思维导图(全)-2020年1月13日更新 第16章(最后一章) 统计初步...

    作者:本质教育 李泽宇 (有问题请私信联系) 本文将用思维导图的形式,通过文字和视频 1)总结整个高中数学的知识点 2)带着大家精读,理解每一个概念定理 从而建立扎实的数学基础.本文工作量很大,我会持 ...

  9. SAM4E单片机之旅——13、LCD之ASF初步

    在Atmel Studio 6中,集成了Atmel Software Framework(ASF框架).通过它提供的库,可以很快速地完成新的项目. 这次的最终目标使用ASF在LCD上显示出文字&quo ...

  10. android蓝牙4.0(BLE)开发之ibeacon初步

    一个april beacon里携带的信息如下 ? 1 <code class=" hljs ">0201061AFF4C0002159069BDB88C11416BAC ...

最新文章

  1. C#读写文件:编码和转换(string和byte[]转换为例)
  2. FFmpeg转码指令(测试通过)
  3. .NET Core系列 : 1、.NET Core 环境搭建和命令行CLI入门
  4. 2017年计算机基础知识答题宝典,最全全国计算机基础知识试题及答案考级宝典(2018)..pdf...
  5. 虚拟机“此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态”的问题
  6. 虚拟光驱安装WIN7(client mac addr: no DHCP问题)
  7. 时频分析 matlab 例程,《Matlab时频分析及其应用》的详细代码
  8. gephi mysql_用Gephi移动多个节点(Moving multiple nodes with Gephi)
  9. 吴晓波罗振宇2019跨年演讲感想
  10. 重装系统后电脑图片显示不出来怎么办
  11. 破解网页文字无法复制的方法
  12. android优化启动时间
  13. Ableton Live Suite 10.1.15 WiN 音乐制作宿主软件下载
  14. 网络项目实施方案介绍
  15. vb.net合伙数据库access(一)——连接数据库
  16. PAT 1130 Infix Expression——什么才是DFS?由“柳神遍历”写法引发的思考
  17. 显示器 如何切换输入源
  18. 没有植入的内容就是TM在逗我
  19. 解决 git@gitlab.com: Permission denied (publickey,gssapi-with-mic,password)
  20. Python办公自动化之收发邮件--163和qq邮箱

热门文章

  1. 简单扑克牌游戏C语言,【算法】C语言实现简易的扑克牌游戏
  2. nn.Sigmoid torch
  3. 批量替换Excel超级链接
  4. Unity - Timeline 之Creating a Timeline Asset and Timeline instance(创建Timeline Asset和Timeline 实例)
  5. android 系统vr,Android系统中的PowerVR成像框架
  6. 公司官网建站笔记(六):域名进行公安备案并将备案号显示在网页底部
  7. drools学习笔记-rule组织方式
  8. 360校招笔试题总结2
  9. 填充因子设置的一般性准则和指导
  10. CF374C Inna and Dima 题解