2 summary:: combine several value patterns to one event stream by binding keys to values
3 related:: Classes/Pattern, Classes/Event, Classes/Pmono, Classes/Rest
4 categories:: Streams-Patterns-Events>Patterns>Event
8 Pbind combines several value streams into one event stream. Each value stream is assigned to one or more keys in the resulting event stream. It specifies a stream of strong::Events:: in terms of different patterns that are strong::bound:: to different keys in the Event.
9 The patterns bound to keys are referred to as emphasis::value patterns:: and the Pbind itself is termed an event pattern.
11 The keys used in a Pbind are usually determined by link::Classes/Event::'s default mechanism and the controls defined for the link::Classes/SynthDef:: to be played. (See link::#synthdef_and_event:: below for a brief discussion of both in relation to Pbind.)
16 The arguments to Pbind are an alternating sequence of keys and patterns. A pattern can also be bount to an array of keys. In this case, the pattern must specify a sequence whose elements are arrays with at least as many elements as there are keys.
22 a = Pbind(\x, Pseq([1, 2, 3]), \y, Prand([100, 300, 200], inf), \zzz, 99);
26 x.next(()); // pass in an event ()
29 x.next(()); // end: nil
35 // using the default synth def
36 Pbind(\freq, Prand([300, 500, 231.2, 399.2], inf), \dur, 0.1).play;
37 Pbind(\freq, Prand([300, 500, 231.2, 399.2], inf), \dur, Prand([0.1, 0.3], inf)).play;
39 Pbind(\freq, Prand([1, 1.2, 2, 2.5, 3, 4], inf) * 200, \dur, 0.1).play;
45 SynthDef(\test, { | out, freq = 440, amp = 0.1, nharms = 10, pan = 0, gate = 1 |
46 var audio = Blip.ar(freq, nharms, amp);
47 var env = Linen.kr(gate, doneAction: 2);
48 OffsetOut.ar(out, Pan2.ar(audio, pan, env) );
52 Pbind(\instrument, \test, \freq, Prand([1, 1.2, 2, 2.5, 3, 4], inf) * 200, \dur, 0.1).play;
56 // standard syntax, arguments alternate symbols and patterns
60 \nharms, Pseq([4, 10, 40], inf),
61 \dur, Pseq([1, 1, 2, 1]/10, inf),
62 #[freq, sustain], Ptuple([ // assignment to multiple keys
63 Pseq( (1..16) * 50, 4),
64 Pseq([1/10, 0.5, 1, 2], inf)
70 It is possible to specify a Pbind with an link::Classes/Array:: preceded by *. Arrays treat identifiers ending with a colon as link::Classes/Symbol::s, making the syntax of the Pbind specification a bit more concise:
74 // Alternative syntax, using a key/pattern array:
77 nharms: Pseq([4, 10, 40], inf),
78 dur: Pseq([1, 1, 2, 1]/10, inf),
79 #[freq, sustain], Ptuple([
80 Pseq( (1..16) * 50, 4),
81 Pseq([1/10, 0.5, 1, 2], inf)
87 subsection::SynthDef and Event
89 The keys used in a Pbind are determined by the link::Classes/SynthDef:: used and the structure of the extensive default mechanism provided by link::Classes/Event::. This section provides a brief review of both.
91 A link::Classes/SynthDef:: assigns a name to an interconnection of unit generators to be run as a synth on a server. It also assigns strong::control names:: to the synth's control inputs. In the following example the SynthDef \test has control inputs strong::out::, strong::freq::, strong::amp::, strong::nharms::, strong::pan::, and strong::gate::.
94 SynthDef(\test, { | out, freq = 440, amp = 0.1, nharms = 10, pan = 0, gate = 1 |
95 var audio = Blip.ar(freq, nharms, amp);
96 var env = Linen.kr(gate, doneAction: 2);
97 OffsetOut.ar(out, Pan2.ar(audio, pan, env) );
101 The SynthDef needs to be downloaded to the server upon which it is to be run. Use strong::.add:: instead of .send to ensure that any patterns using this SynthDef have information about the available control inputs (see link::Classes/SynthDesc::). Alternately, strong::.store:: may be used to save the SynthDef to disk and add the SynthDesc to the library.
103 An link::Classes/Event:: is a Dictionary that specifies an action to be taken in response to strong::play:: and a time increment to be returned in response to strong::delta::. Events can be written as a series of key value pairs enclosed in parentheses. Empty parentheses create an empty event.
105 By default, Events play synths on a server. Such emphasis::note events:: use the following keys:
108 ## instrument (\default) || The synthdef to be played
109 ## variant (nil, optional) || The set of variant control defaults to use (see link::Classes/SynthDef::)
110 ## server (Server.default) || The server that plays the synth
111 ## group (1) || The new synth's or the synth the new synth is placed before or after
112 ## addAction (0) || How the synth is placed relative to the target specified by strong::group::
114 ## 0 || head of group
115 ## 1 || tail of group
116 ## 2 || before group (could be a Synth)
117 ## 3 || after group (could be a Synth)
119 ## delta (function) || The time until the next event in a sequence of events, generally specified indirectly through strong::dur::
122 When the Event is played, it creates an OSC command to play a synth. It uses the name assigned to strong::instrument:: to the select the SynthDef to be played. The SynthDef's control names (found in its link::Classes/SynthDesc::) are looked up in the event and the corresponding values included in the command.
124 Playing a synth is the normal action taken by an Event. The default event structure defines several other event types that can perform a wide variety of server actions. See the link::Classes/Event:: help file for a list of event types.
126 There are a number of coventional names typically used to identify controls in a synth.
129 ## out || output bus index
130 ## in || input bus index (for filters, modulators, etc)
131 ## gate || envelope gate (not level!) - should default to 1.0, deletes synth when released
132 ## trig || envelope gate (not level!) - should default to 1.0, does not delete synth when released
133 ## pan || panning position
134 ## bufnum || buffer number (used in synths that utilize link::Classes/PlayBuf::, link::Classes/DiskIn::, etc)
135 ## sustain || duration of the synth
136 ## amp || amplitude of the synth
137 ## freq || base pitch of the synth
140 Event implements a layered specification scheme for some of these controls. In the following list, the first and leftmost name is the actual control name, names below and indented are more abstract ways to specify the control.
143 ## delta || The time until the next event. Generally determined by:
145 ## dur || The time until next event in a sequence of events
146 ## stretch || Scales event timings (i.e. stretch == 2 => durations are twice as long)
148 ## sustain || Duration of the synth, typically determined (in stretched time units) by:
150 ## legato || The ratio of the synth's duration to the event's duration
152 ## amp || synth amplitude (typically ranging from 0 to 1), often determined by
154 ## db || Amplitude in decibels
156 ## detunedFreq || actual "pitch" of a synth, determined by:
158 ## freq + detune; || freq is determined by:
160 ## (midinote + ctranspose).midicps * harmonic; || midinote is determined by:
162 ## (note + gtranspose + root)/stepsPerOctave * octave * 12; || note is determined by:
164 ## (degree + mtranspose).degreeToKey(scale, stepsPerOctave) ||
174 SynthDef(\test, { | out, freq = 440, amp = 0.1, nharms = 10, pan = 0, gate = 1 |
175 var audio = Blip.ar(freq, nharms, amp);
176 var env = Linen.kr(gate, doneAction: 2);
177 OffsetOut.ar(out, Pan2.ar(audio, pan, env) );
180 // Events are written as parantheses enclosing key/value pairs
181 (instrument: \test).play;
182 (instrument: \test, freq: 20, nharms: 50).play;
188 See link::Classes/Rest:: for a discussion of marking events as rests in Pbind.
190 subsection::The Play Method
192 While the play method is actually defined in the class link::Classes/Pattern::, it is useful to review it here:
195 ## play (clock, protoEvent, quant) || returns an link::Classes/EventStreamPlayer::.
196 ## clock || The clock that schedules the EventStreamPlayer, defaults to TempoClock.default. Patterns that change graphics must use link::Classes/AppClock::.
197 ## protoEvent || The initial event modified by Pbind, defaults to Event.default.
198 ## quant || A quantization value used by clock. When a number, the pattern will start at the next even multiple of that number. May also be a link::Classes/Quant::, which specifies quantization, time position within that quantization, and a timingOffset. See link::Classes/Quant:: for details.
201 subsection::Realtime Control with EventStreamPlayer
203 The link::Classes/EventStreamPlayer:: provides realtime control through strong::mute::, strong::unmute::, strong::stop::, strong::play:: and strong::reset::.
207 SynthDef(\cfstring1, { arg i_out, freq = 360, gate = 1, pan, amp=0.1;
208 var out, eg, fc, osc, a, b, w;
209 fc = LinExp.kr(LFNoise1.kr(Rand(0.25, 0.4)), -1, 1, 500, 2000);
210 osc = Mix.fill(8, {LFSaw.ar(freq * [Rand(0.99, 1.01), Rand(0.99, 1.01)], 0, amp) }).distort * 0.2;
211 eg = EnvGen.kr(Env.asr(1, 1, 1), gate, doneAction:2);
212 out = eg * RLPF.ar(osc, fc, 0.1);
214 Out.ar(i_out, Mix.ar(PanAz.ar(4, [a, b], [pan, pan+0.3])));
218 \degree, Pseq((0..12), inf),
220 \instrument, \cfstring1
221 ).play; // returns an EventStream
224 ( // an interactive session
229 e.mute; // keeps playing, but replaces notes with rests
233 e.reset; // reset the stream.
234 e.reset; // reset the stream.
235 e.reset; // reset the stream.
236 e.reset; // reset the stream.
238 e.pause; // will resume where paused.
242 e.stop; // will reset before resume.
248 In addition, the stream the EventStreamPlayer plays can be altered while it is running through the method
249 strong::stream_(aStream)::.
254 \degree, Pseq([0, 1, 2, 4, 6, 3, 4, 8], inf),
255 \dur, Prand([0.2, 0.4, 0.8], inf),
256 \amp, 0.05, \octave, 5,
257 \instrument, \cfstring1, \ctranspose, 0
263 \degree, Pseq([0, 1, 2, 4, 6, 3, 4, 8], inf),
264 \dur, Prand([0.2, 0.4, 0.8], inf),
265 \amp, 0.05, \octave, 5,
266 \instrument, \cfstring1, \ctranspose, 0
272 \degree, Pxrand([0, 1, 2, 4, 6, 3, 5, 7, 8], inf),
273 \dur, Prand([0.2, 0.4, 0.8], inf), \amp, 0.05,
274 \octave, 5, \instrument, \cfstring1
279 subsection::Additional arguments
281 Here is an example with more bindings. Here we have added a filter with cutoff and resonance arguments.
282 You will need to hit command '.' before executing the next few pbind ex. without having them stack up.
283 also, due to the synthdef's and synthdeclib, if the server is shut down you will have to reload the
284 synthdef and re-read the synthdesclib.
288 SynthDef(\acid, { arg out, freq = 1000, gate = 1, pan = 1, cut = 4000, rez = 0.8, amp = 1;
292 Pulse.ar(freq, 0.05),
294 pan) * EnvGen.kr(Env.linen(0.01, 1, 0.3), gate, amp, doneAction:2);
300 Pbind(\instrument, \acid, \dur, Pseq([0.25, 0.5, 0.25], inf), \root, -12,
301 \degree, Pseq([0, 3, 5, 7, 9, 11, 5, 1], inf), \pan, Pfunc({1.0.rand2}),
302 \cut, Pxrand([1000, 500, 2000, 300], inf), \rez, Pfunc({0.7.rand +0.3}), \amp, 0.2).play;
306 The link::Classes/ListPattern::s can be put around Event Streams to create sequences of Event Streams.
311 Pbind(\instrument, \acid, \dur, Pseq([0.25, 0.5, 0.25], 4), \root, -24,
312 \degree, Pseq([0, 3, 5, 7, 9, 11, 5, 1], inf), \pan, Pfunc({1.0.rand2}),
313 \cut, Pxrand([1000, 500, 2000, 300], inf), \rez, Pfunc({0.7.rand +0.3}), \amp, 0.2),
315 Pbind(\instrument, \acid, \dur, Pseq([0.25], 6), \root, -24, \degree, Pseq([18, 17, 11, 9], inf),
316 \pan, Pfunc({1.0.rand2}), \cut, 1500, \rez, Pfunc({0.7.rand +0.3}), \amp, 0.16)
322 'Pseq' in the above ex. can be any pattern object:
327 Pbind(\instrument, \acid, \dur, Pseq([0.25, 0.5, 0.25], 4), \root, -24,
328 \degree, Pseq([0, 3, 5, 7, 9, 11, 5, 1], inf), \pan, Pfunc({1.0.rand2}),
329 \cut, Pxrand([1000, 500, 2000, 300], inf), \rez, Pfunc({0.7.rand +0.3}),
332 Pbind(\instrument, \acid, \dur, Pseq([0.25], 6), \root, -24, \degree, Pseq([18, 17, 11, 9], inf),
333 \pan, Pfunc({1.0.rand2}), \cut, 1500, \rez, Pfunc({0.7.rand +0.3}), \amp, 0.16)
339 subsection::Multichannel Expansion
341 If we supply an array for any argument, the synth node will automatically replicate to handle the additional arguments. When we give the 'root' argument an array, we should hear a chord....
346 \instrument, \acid, \dur, Pseq([0.25, 0.5, 0.25], inf),
348 \degree, Pseq([0, 3, 5, 7, 9, 11, 5, 1], inf),
349 \pan, Pfunc({1.0.rand2}), \cut, Pxrand([1000, 500, 2000, 300], inf), \rez, Pfunc({0.7.rand +0.3}),
354 Using link::Classes/Pdef:: (provided by link::Overviews/JITLib::) makes it easy to replace patterns on the fly:
358 Pdef(\buckyball).play;
362 Pdef(\buckyball, Pbind(\instrument, \acid, \dur, Pseq([0.25, 0.5, 0.25], inf), \root, [-24, -17],
363 \degree, Pseq([0, 3, 5, 7, 9, 11, [5, 17], 1], inf), \pan, Pfunc({[1.0.rand2, 1.0.rand2]}),
364 \cut, Pxrand([1000, 500, 2000, 300], inf), \rez, Pfunc({0.7.rand +0.3}), \amp, [0.15, 0.22]));
367 Pdef(\buckyball, Pbind(\instrument, \acid, \dur, Pseq([0.25, 0.5, 0.25], inf), \root, [-24, -17],
368 \degree, Pseq([0b, 3b, 5b, 7b, 9b, 11b, 5b, 0b], inf), \pan, Pfunc({1.0.rand2}), //notice the flats
369 \cut, Pxrand([1000, 500, 2000, 300], inf), \rez, Pfunc({0.7.rand +0.3}), \amp, 0.2));
373 Pdef(\buckyball).stop;
376 Pdef(\buckyball).resume;
379 Pdef.remove(\buckyball);
382 subsection::Sending to effects
384 Assignment to effect processors can be achieved by setting the 'out' argument to the desired efx's input bus. The effect Synth must also be created. Synth.new is one way of doing this.
388 // efx synthdef- dig the timing on the delay and the pbind. :-P
389 SynthDef(\pbindefx, { arg out, in, time1=0.25, time2=0.5;
391 audio = In.ar([20, 21], 2);
392 efx=CombN.ar(audio, 0.5, [time1, time2], 10, 1, audio);
397 a = Synth.after(1, \pbindefx);
399 // if you don't like the beats change to 0.4, 0.24
400 // a.set(\time1, 0.4, \time2, 0.24);
402 SynthDef(\acid, { arg out, freq = 1000, gate = 1, pan = 0, cut = 4000, rez = 0.8, amp = 1;
406 Pulse.ar(freq, 0.05),
408 pan) * EnvGen.kr(Env.linen(0.02, 1, 0.3), gate, amp, doneAction:2);
414 Pbind(\instrument, \acid, \out, 20, \dur, Pseq([0.25, 0.5, 0.25], inf), \root, [-24, -17],
415 \degree, Pseq([0, 3, 5, 7, 9, 11, 5, 1], inf), \pan, Pfunc({1.0.rand2}),
416 \cut, Pxrand([1000, 500, 2000, 300], inf), \rez, Pfunc({0.7.rand +0.3}), \amp, 0.12).play;
420 subsection::Additional examples
424 SynthDef(\berlinb, { arg out=0, freq = 80, amp = 0.01, pan=0, gate=1;
426 env = Decay2.kr(gate, 0.05, 8, 0.0003);
428 LFPulse.ar(freq, 0, SinOsc.kr(0.12, [0, 0.5pi], 0.48, 0.5)),
429 freq * SinOsc.kr(0.21, 0, 18, 20),
433 DetectSilence.ar(a, 0.1, doneAction: 2);
434 Out.ar(out, amp * Mix.ar(PanAz.ar(4, [a, b], [pan, pan+1])));
440 \degree, Pseq([0, 1, 2, 4, 6, 3, 4, 8], inf),
441 \dur, 0.5, \octave, 3, \instrument, \berlinb
447 \degree, Pseq([0, 1, 2, 4, 6, 3, 4, 8], inf),
448 \dur, 0.5, \octave, [2, 1],
449 \instrument, \berlinb,
450 \pan, Pfunc({1.0.rand2})