1title:: Event types 2summary:: Different ways that an Event can "play" 3categories:: Streams-Patterns-Events>Events 4related:: Classes/Event 5 6 7An link::Classes/Event:: responds to a code::play:: message by evaluating ~play in the event, and the default behaviour of ~play is determined by the value of ~type.footnote::To see how event types are normally invoked, here is a slightly simplified version of the default definition of ~play as defined in the Event class: 8 9code::{ ~eventTypes[~type].value(server); }:: 10 11The function uses the value of ~type to select a function from the Dictionary held in ~eventTypes. :: 12 13 14code:: 15a = (play: { ~word.scramble.postln }, word: "hello word"); 16a.play; 17 18a = (type: \note, freq: [1310, 1321]); // choosing a play function by specifying type 19a.play; 20:: 21 22 23The collection of eventTypes can be readily extended using link::Classes/Event#*addEventType#*addEventType::: 24 25code:: 26Event.addEventType(\test, { "Your word is: ".post; ~word.scramble.postln }); 27(type: \test, word: "annahme").play; 28:: 29 30 31section::Currently existing event types: 32Note:: this documentation is incomplete. :: 33 34definitionlist:: 35 36## note || Instantiate a synth on the server, with specified arguments, and later to free it. The choice of link::Classes/SynthDef:: is specified using the \instrument key. This event type is what code::Event.default:: returns. 37 38code::(degree: [0, 5, 7, 11]).play;:: 39 40Actually plays this event type: 41 42code::(type: \note, degree: [0, 5, 7, 11], instrument: \default).play;:: 43 44## set || used to set parameters of some already-running node(s). 45 46code:: 47a = (degree: 3, sustain: 40).play; 48fork { 10.do { (type: \set, id: a[\id], \degree: [0, 5, 8, 11].choose).play; 0.3.wait } }; 49:: 50 51(See also: note in link::Classes/Pmono:: helpfile) 52 53 54## group || creates a new group 55optional parameters: 56table:: 57## ~id || node ID, or node object 58## ~group || outer group id or object 59## ~addAction / ~lag / ~timingOffset || determine how and when the group is created 60:: 61 62Example: 63code:: 64(type: \group, id: 2).play // create a group with nodeID 2 65(type: \note, freq: 500, group: 2).play // play a synth in that group 66:: 67 68 69## midi || send note parameters to midi device 70parameters: 71table:: 72## ~midicmd || A Symbol, for the MIDI command to issue 73## ~midiout || A MIDIOut object 74## ~chan || The MIDI channel number (0-15) 75:: 76 77See link::Tutorials/A-Practical-Guide/PG_08_Event_Types_and_Parameters#MIDI output:: for details on available midicmds. 78 79## on || play synth, ~id must be specified 80## off || release synth (or free if no gate) 81## kill || free synth 82 83## rest || do nothing for a specified amount of time 84 85## composite || perform any number of event types, given as ~types 86code:: 87MIDIClient.init; 88m = MIDIOut(0); 89 90// should play a synth *and* an external MIDI note simultaneously 91(type: \composite, types: [\note, \midi], midiout: m, degree: 0, dur: 3).play; 92:: 93 94## bus || write ~array to control buses starting at ~out 95## audioBus || allocate ~channels consecutive audio buses 96## controlBus || allocate ~channels consecutive control buses 97 98## alloc || allocate ~bufnum with ~numframes and ~numchannels 99## allocRead || load a file from ~path, starting at ~firstFileFrame, reading ~numFrames sample frames 100## cue || cue a file for DiskIn, with ~bufferSize frames 101 102## free || free ~bufnum 103## gen || send ~gencmd to ~bufnum 104## load || load ~filename starting at ~frame into ~bufnum 105## read || 106 107## table || load ~amps directly into a buffer 108## sine1 || generate a buffer from ~amps 109## sine2 || generate a buffer from ~freqs, ~amps 110## sine3 || generate a buffer from ~freqs, ~amps, ~phases 111## cheby || generate a waveshape buffer from ~amps 112 113## setProperties || sends setter messages to ~receiver for each key in ~args that has a nonNil value in the Event. 114 115## tree || creates a tree of groups. ~tree can be an array of nodeIDs, and may contain associations to further nested arrays. 116 117## phrase || instead of playing a single synth from a SynthDef with ~instrument, it looks up a Pdef and plays a cluster of sounds. 118 119 120:: 121 122subsection::Some event types are used internally, e.g.: 123definitionlist:: 124## monoNote || used by Pmono 125## monoSet || used by Pmono 126## monoOff || used by Pmono 127:: 128