1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
title:: Understanding Streams, Patterns and Events - Part 6
summary:: Parallel Patterns
related:: Tutorials/Streams-Patterns-Events1, Tutorials/Streams-Patterns-Events2, Tutorials/Streams-Patterns-Events3, Tutorials/Streams-Patterns-Events4, Tutorials/Streams-Patterns-Events5, Tutorials/Streams-Patterns-Events7
categories:: Tutorials>Streams-Patterns-Events
section::Parallel Patterns
subsection::Ppar
The link::Classes/Ppar:: pattern allows you to merge multiple event streams to play in parallel.
Ppar is a link::Classes/ListPattern:: and so like most ListPatterns it takes two arguments, a strong::list:: of event patterns to play in parallel and a strong::repeats:: count.
Ppar's child patterns must be event patterns. Using value patterns in a Ppar is an error because value patterns contain no duration data.
A Ppar is done when all of its subpatterns are done.
code::
(
Ppar([
Pbind(\dur, 0.2, \midinote, Pseq([62, 65, 69, 72], inf)),
Pbind(\dur, 0.4, \midinote, Pseq([50, 45], inf))
]).play
)
(
// Ppars can be nested
Ppar([
Pbind(
\dur, Prand([0.2, 0.4, 0.6], inf),
\midinote, Prand([72, 74, 76, 77, 79, 81], inf),
\db, -26,
\legato, 1.1
),
Pseq([
Pbind(\dur, 3.2, \freq, Pseq([\rest]) ),
Prand([
Ppar([
Pbind(\dur, 0.2, \pan, 0.5, \midinote, Pseq([60, 64, 67, 64])),
Pbind(\dur, 0.4, \pan, -0.5, \midinote, Pseq([48, 43]))
]),
Ppar([
Pbind(\dur, 0.2, \pan, 0.5, \midinote, Pseq([62, 65, 69, 65])),
Pbind(\dur, 0.4, \pan, -0.5, \midinote, Pseq([50, 45]))
]),
Ppar([
Pbind(\dur, 0.2, \pan, 0.5, \midinote, Pseq([64, 67, 71, 67])),
Pbind(\dur, 0.4, \pan, -0.5, \midinote, Pseq([52, 47]))
])
], 12)
], inf)
], inf).play;
)
::
subsection::Ptpar
The link::Classes/Ppar:: pattern starts all of its subpatterns at the same time.
A link::Classes/Ptpar:: pattern includes a start time parameter before each subpattern which allow the subpatterns to be started at some time delay within the pattern. The start time is given in beats.
code::
(
var makePattern, durpat;
durpat = Pseq([ Pgeom(0.05, 1.1, 24), Pgeom(0.5, 0.909, 24) ], 2);
makePattern = { arg note, db, pan;
Pbind( \dur, durpat, \db, db, \pan, pan, \midinote, Pseq([note, note-4], inf) );
};
Ptpar([
0.0, makePattern.value(53, -20, -0.9),
2.0, makePattern.value(60, -23, -0.3),
4.0, makePattern.value(67, -26, 0.3),
6.0, makePattern.value(74, -29, 0.9)
], inf).play;
)
::
The time arguments are sent the code::value:: message when the Ptpar pattern is started, so you may use functions to specify the times.
code::
(
var makePattern, durpat;
durpat = Pseq([ Pgeom(0.05, 1.1, 24), Pgeom(0.5, 0.909, 24) ], 2);
makePattern = { arg note, db, pan;
Pbind( \dur, durpat, \db, db, \pan, pan, \midinote, Pseq([note, note-4], inf) );
};
Ptpar([
{ 0.0 }, makePattern.value(53, -20, -0.9),
{ 8.0.rand }, makePattern.value(60, -23, -0.3),
{ 8.0.rand }, makePattern.value(67, -26, 0.3),
{ 8.0.rand }, makePattern.value(74, -29, 0.9)
], inf).play;
)
::
section::FilterPatterns and transformation
FilterPatterns take an existing pattern and apply some modification to its properties.
subsection::Padd, Pmul, Pset, Pstretch
There is a simpler way to write the modal transposition example given in part 5. In fact the earlier examples are setting the values of code::mtranspose:: and code::ctranspose:: which is not the best way to change those variables, because it wipes out any modifications to them by parent patterns. It is better to take the current value of those properties and add a value to them.
The link::Classes/Padd:: filter takes the current value of a property and adds a value to it.
code::
(
// modal transposition
var pattern;
// define the basic pattern
pattern = Pbind(
\dur, 0.15,
\degree, Pseq([ Pshuf(#[-7,-3,0,2,4,7], 4), Pseq([0,1,2,3,4,5,6,7]) ], 1)
);
Pseq([
pattern, // untransposed
Padd(\mtranspose, 1, pattern), // modal transpose up 1 degree
Padd(\mtranspose, 2, pattern) // modal transpose up 2 degrees
], inf).play
)
::
Similarly, link::Classes/Pmul:: multiplies the current value of a property by a value. link::Classes/Pset:: sets the property to a value.
In order to process duration correctly link::Classes/Pstretch:: should be used.
code::
(
// beat stretching using Pstretch
var pattern;
// define the basic pattern
pattern = Pbind(
\dur, 0.15,
\degree, Pseq([ Pshuf(#[-7,-3,0,2,4,7], 4), Pseq([0,1,2,3,4,5,6,7]) ], 1)
);
Pseq([
pattern, // normal
Pstretch(0.5, pattern), // stretch durations by a factor of 1/2
Pstretch(2.0, pattern) // stretch durations by a factor of 2
], inf).play
)
::
subsection::Paddp, Pmulp, Psetp, Pstretchp
In fact there is an even shorter version of the modal transposition example. link::Classes/Paddp:: reads one pattern to get values for adding to a property and plays the second pattern once through modified with each new value.
code::
(
// modal transposition
var pattern;
// define the basic pattern
pattern = Pbind(
\dur, 0.15,
\degree, Pseq([ Pshuf(#[-7,-3,0,2,4,7], 4), Pseq([0,1,2,3,4,5,6,7]) ], 1)
);
Paddp(
\mtranspose, // property to be modified
Pseq([0,1,2], inf), // a value pattern as a source of values for adding to mtranspose
pattern // the pattern to be modified
).play
)
::
Nested modifications:
code::
(
// modal transposition
var pat1, pat2;
// define the basic pattern
pat1 = Pbind(
\dur, 0.15,
\degree, Pseq([ Pshuf(#[-7,-3,0,2,4,7], 4), Pseq([0,1,2,3,4,5,6,7]) ], 1)
);
pat2 = Paddp(
\mtranspose, // property to be modified
Pseq([0,1,2]), // a value pattern as a source of values for adding to mtranspose
Ppar([
pat1,
Padd(\mtranspose, -3, pat1), // down a 4th
Padd(\mtranspose, 2, pat1) // up a 3rd
])
);
Pseq([
pat1, // unmodified pattern
pat2, // parallel sequence
Pstretch(1.5, pat2) // parallel sequence stretched by 3/2
], inf).play
)
::
Another example using Paddp:
code::
(
var chord;
chord = Prand([[53, 58, 64],[53, 60, 64],[57,60,65]]);
Paddp(\ctranspose, Prand([-1,0,2,4,5], inf),
Ppar([
Pbind( // melody part
\dur, Prand([0.2, 0.4, 0.6], inf),
\midinote, Pxrand([71, 72, 74, 76, 77, 79], 10),
\db, -26,
\legato, 1.1
),
Pbind( // harmony part
\pan, 0.4,
\dur, Pseq([0.1, 0.5, 0.4, 0.6], 4),
\midinote, Pseq([chord,\rest,chord,\rest], 4)
),
Pbind( // bass part
\pan, -0.4,
\dur, 0.4,
\midinote, Pseq([38, 45, 38, 36], 4)
)
])
).play
)
(
// chromatic transposition
var pattern;
// define the basic pattern
pattern = Pbind(
\dur, 0.1,
\degree, Pseq([0,1,2,3,4,5,6,7])
);
Paddp(
\ctranspose, // property to be modified
Pseries(0,1,12), // a value pattern as a source of values for multiplying with ctranspose
pattern // the pattern to be modified
).play
)
(
// beat time stretching
var pattern;
// define the basic pattern
pattern = Pbind(
\dur, 0.1,
\degree, Pseq([0,1,2,3,4,5,6,7])
);
Pstretchp(
Pseq([1,2,3], inf), // a value pattern as a source of values for multiplying with stretch
pattern // the pattern to be modified
).play
)
::
subsection::Pbindf
link::Classes/Pbindf:: is like link::Classes/Pbind:: except that it merges all the bound symbols into events that it gets from a subpattern. It takes the same initial arguments in pairs as Pbind does, with an additional pattern to be modified as the last argument.
code::
(
var pattern;
pattern = Pbind( \midinote, Pseq(#[60, 62, 64, 65, 67, 69, 71, 72]) );
Pseq([
Pbindf(pattern, \legato, 0.1, \dur, 0.2),
Pbindf(pattern, \legato, 1.0, \dur, 0.125),
Pbindf(pattern, \legato, 2.0, \dur, 0.3)
], inf).play
)
::
Patterns can be used as the arguments to Pbindf.
code::
(
var pattern;
pattern = Pbind( \midinote, Pseq(#[60, 62, 64, 65, 67, 69, 71, 72, 74, 76, 77, 79]) );
Pseq([
Pbindf(pattern,\legato, 0.1, \dur, Pgeom(0.3, 0.85, inf)),
Pbindf(pattern,\legato, 1.0, \dur, Pseq([0.3, 0.15], inf)),
Pbindf(pattern,\legato, 2.0, \dur, Pseq([0.2, 0.2, 0.4], inf))
], inf).play
)
::
To go to the next file:
link::Tutorials/Streams-Patterns-Events7::
|