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 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
|
title:: Understanding Streams, Patterns and Events - Part 5
summary:: Event.default
related:: Tutorials/Streams-Patterns-Events1, Tutorials/Streams-Patterns-Events2, Tutorials/Streams-Patterns-Events3, Tutorials/Streams-Patterns-Events4, Tutorials/Streams-Patterns-Events6, Tutorials/Streams-Patterns-Events7
categories:: Tutorials>Streams-Patterns-Events
More about the default Event:
section::protoEvents
The protoEvent contains default values for many useful parameters.
The default protoEvent is code::Event.default::. It provides default bindings for duration, envelope, instrument, making a very simple Pattern directly playable:
code::
(
// an endless sequence of middle Cs
Pbind.new.play
)
::
By adding other bindings, you can override the defaults in the protoEvent.
code::
(
// duration 0.25 beats (16th notes)
Pbind( \dur, 0.25 ).play
)
::
code::
(
// specifying the pitch in terms of midinote
// see also The pitch model below
Pbind(
\dur, 0.125,
\legato, 0.2,
\midinote, Pseq(#[60, 62, 64, 65, 67, 69, 71, 72], inf)
).play
)
::
section::~finish
Event.default contains a function bound to the Symbol code::'finish':: which is called for each new event generated in order to complete any computations that depend on the other values in the event.
section::The pitch model
Event.default implements a multi level pitch model which allows composition using modal scale degrees, equal division note values, midi note values, or frequencies in Hertz. These different ways of specifying the pitch can all be used interchangeably.
The way this works is due to the default values bound to the Symbols of the pitch model.
The lowest level Symbol in the pitch model is code::'freq'::. The default binding for code::'freq':: is a link::Classes/Function:: which calculates the frequency by getting the value of code::'midinote'::, adding a transpose value and converting it to Hertz using code::midicps::.
code::
~freq = {
(~midinote.value + ~ctranspose).midicps;
};
::
If you compose with code::'freq':: directly then this default function is overridden.
code::
(
Pbind(
\dur, 0.25,
\freq, Pseq(#[300, 400, 500, 700, 900], inf)
).play;
)
::
Event.default's code::'finish':: function sends the value message to the current binding of code::'freq':: in order to get the value for the frequency and adds a detune value to it which transposes the frequency in Hertz.
code::
(
Pbind(
\dur, 0.25,
\detune, -20,
\freq, Pseq(#[300, 400, 500, 700, 900], inf)
).play
)
::
The next level is code::'midinote':: which is by default bound to this function:
code::
~midinote = {
(~note.value + ~gtranspose + (~octave * divs) + ~root)
* 12.0 / ~stepsPerOctave;
};
::
This function gets the value bound to code::'note':: which is a value expressed in some equal temperament, not necessarily 12. It adds a gamut transpose value code::'gtranspose'::, and scales from the number of notes per octave being used into 12 notes per octave MIDI key values. If you compose with code::'midinote':: directly then that will override this function.
code::
(
Pbind(
\dur, 0.2,
\midinote, Pseq([ Pshuf(#[60, 61, 62, 63, 64, 65, 66, 67], 3) ], inf)
).play
)
::
Another level higher is code::'note':: which is defined by default by this function:
code::
~note = {
var divs;
divs = ~stepsPerOctave;
(~degree + ~mtranspose).degreeToKey(~scale, divs);
};
::
This function derives the note value from the next higher level variables which specify a pitch from a scale. These variables are defined as follows:
code::
~stepsPerOctave = 12.0;
::
The number of equal divisions of an octave for this tuning. The equal temperament defined by this variable is known as the gamut. If you wanted to work in cents for example you could set this to 1200.0.
code::
~octave = 5.0;
::
The current octave. Middle C is the lowest note in octave 5.
code::
~root = 0.0;
::
The root of the scale given in equal divisions defined by code::~stepsPerOctave::.
code::
~scale = #[0, 2, 4, 5, 7, 9, 11]; // diatonic major scale
::
A set of scale pitches given in equal divisions defined by code::~stepsPerOctave::.
code::
~degree = 0;
::
A scale degree index into the code::~scale::. 0 is the root and the scale wraps in the manner defined by code::degreeToKey::.
code::
~mtranspose = 0;
::
A modal transposition value that is added to the scale degree.
code::
~gtranspose = 0;
::
A gamut transposition value that is added to the gamut pitch.
code::
~ctranspose = 0;
::
A chromatic transposition value expressed in semitones.
section::Pitch model Examples
code::
(
// a simple scale degree sequence
Pbind(
// -7 is 8ve below, -3 is a 4th below,
// 0 is root, 2 is 3rd above, 4 is 5th above, 7 is 8ve above.
\degree, Pseq([ Pshuf(#[-7,-3,0,2,4,7], 4), Pseq([0,1,2,3,4,5,6,7]) ], inf),
\dur, 0.15
).play
)
(
// change the octave
Pbind(
\dur, 0.15,
\octave, 4,
\degree, Pseq([ Pshuf(#[-7,-3,0,2,4,7], 4), Pseq([0,1,2,3,4,5,6,7]) ], inf)
).play
)
(
// change the scale
Pbind(
\dur, 0.15,
\scale, [0, 2, 3, 5, 7, 8, 10],
\degree, Pseq([ Pshuf(#[-7,-3,0,2,4,7], 4), Pseq([0,1,2,3,4,5,6,7]) ], inf)
).play
)
(
// modal transposition
var notes;
notes = Pseq([ Pshuf(#[-7,-3,0,2,4,7], 4), Pseq([0,1,2,3,4,5,6,7]) ], 1);
Pseq([
Pbind(
\dur, 0.15,
\mtranspose, 0,
\degree, notes
),
Pbind(
\dur, 0.15,
\mtranspose, 1,
\degree, notes
),
Pbind(
\dur, 0.15,
\mtranspose, 2,
\degree, notes
)
], inf).play
)
(
// chromatic transposition
var notes;
notes = Pseq([ Pshuf(#[-7,-3,0,2,4,7], 4), Pseq([0,1,2,3,4,5,6,7]) ], 1);
Pseq([
Pbind(
\dur, 0.15,
\ctranspose, 0,
\degree, notes
),
Pbind(
\dur, 0.15,
\ctranspose, 3,
\degree, notes
),
Pbind(
\dur, 0.15,
\ctranspose, -3,
\degree, notes
)
], inf).play
)
(
// frequency detuning
var notes;
notes = Pseq([ Pshuf(#[-7,-3,0,2,4,7], 4), Pseq([0,1,2,3,4,5,6,7]) ], 1);
Pseq([
Pbind(
\dur, 0.15,
\detune, 0,
\degree, notes
),
Pbind(
\dur, 0.15,
\detune, 20,
\degree, notes
),
Pbind(
\dur, 0.15,
\detune, 40,
\degree, notes
)
], inf).play
)
(
// chords. If an Array of pitches is returned by a Stream for pitch, then a chord
// will be played.
Pbind(
\dur, 0.15,
\degree, Pseq([
Pshuf(#[-7,-3,0,2,4,7], 4)+[0,4],
Pseq( [0,1,2,3,4,5,6,7] )+[0,2]
], inf)
).play
)
(
// composing in non 12 equal temperaments. 72 tone equal temp.
Pbind(
\stepsPerOctave, 72,
\note, Pseq([
// 1/1, 7/6, 3/2, 7/4, 9/8
Pseq([ [0,16,42,58,84], Pseq([ 0, 16, 42, 58, 72, 84 ], 2), [0,16,42,58,84] ], 1),
// 1/1, 6/5, 3/2, 9/5, 9/8
Pseq([ [0,19,42,61,84], Pseq([ 0, 19, 42, 61, 72, 84 ], 2), [0,19,42,61,84] ], 1),
// 1/1, 5/4, 3/2, 15/8, 9/8
Pseq([ [0,23,42,65,84], Pseq([ 0, 23, 42, 65, 72, 84 ], 2), [0,23,42,65,84] ], 1),
// 1/1, 9/7, 3/2, 27/14, 9/8
Pseq([ [0,26,42,68,84], Pseq([ 0, 26, 42, 68, 72, 84 ], 2), [0,26,42,68,84] ], 1)
], inf),
\dur, Pseq([ 1.2, Pseq([0.15], 12), 1.2], inf)
).play
)
::
section::The duration model
Duration is expressed in beats and is bound to the code::'dur':: symbol. The sustain time of a note can be expressed directly in beats or by using a legato value which is multiplied by the note duration to get the sustain time.
code::
(
// changing duration
Pbind(
\dur, Pseq([ Pgeom(0.05, 1.1, 24), Pgeom(0.5, 0.909, 24) ], inf),
\midinote, Pseq(#[60, 58], inf)
).play
)
(
// changing legato value
Pbind(
\dur, 0.2,
\legato, Pseq([ Pseries(0.05, 0.05, 40), Pseries(2.05, -0.05, 40) ], inf),
\midinote, Pseq(#[48, 51, 55, 58, 60, 58, 55, 51], inf)
).play
)
::
To go to the next file:
link::Tutorials/Streams-Patterns-Events6::
|