09.12.2012 Views

The Kyma Language for Sound Design, Version 4.5

The Kyma Language for Sound Design, Version 4.5

The Kyma Language for Sound Design, Version 4.5

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Recursion<br />

First we create a TimedEventSequence from a MIDI file. § <strong>The</strong>n we get rid of any polyphony using the<br />

asMonophonicEventSequence message. <strong>The</strong>n we create a MarkovChain (length 3), using the events<br />

from the TimedEventCollection. We then ask the MarkovChain to create a new sequence. Finally, we<br />

create a new EventSequence, supplying the Markov-generated sequence as the events. When the example<br />

plays, you will hear one part of the original sequence, followed by the Markov-generated sequence.<br />

Take a look at the <strong>Sound</strong> called self similar melody. This script is an example of how you can create a<br />

Smalltalk “block” and then call it recursively:<br />

| pitchShape durationShape shapingFunction selfSimMel |<br />

pitchShape := #(0 7 -12).<br />

durationShape := #({2/5} {1/5} {2/5}).<br />

shapingFunction := [ :seq :count |<br />

count = 0<br />

ifTrue: [seq]<br />

ifFalse: [<br />

EventSequence events:<br />

((1 to: pitchShape size) collect: [ :i |<br />

shapingFunction<br />

value:<br />

((seq trsp: (pitchShape at: i))<br />

dim: (durationShape at: i))<br />

value: count - 1])]].<br />

selfSimMel :=<br />

shapingFunction<br />

value: (Note frequency: 4 c durationInBeats: 16)<br />

value: 4.<br />

selfSimMel playOnVoice: self onBeat: 0 bpm: 45.<br />

As usual, we start by declaring the variables. <strong>The</strong>n we set pitchShape to an Array of intervals specified<br />

in half steps, and we set durationShape to an Array of ratios, each of which corresponds to an amount<br />

by which to scale a duration:<br />

| pitchShape durationShape shapingFunction selfSimMel |<br />

pitchShape := #(0 7 -12).<br />

durationShape := #({2/5} {1/5} {2/5}).<br />

Next we store an entire block of code (i.e., everything within the square brackets) in a variable called<br />

shapingFunction. This block has two arguments (:seq and :count), and they are listed at the very<br />

beginning of the block, separated from the rest of the block by a vertical bar. <strong>The</strong> code within the block is<br />

not executed at this point; it is just stored in a variable so it can be executed later:<br />

shapingFunction := [ :seq :count |<br />

count = 0<br />

ifTrue: [seq]<br />

ifFalse: [<br />

EventSequence events:<br />

((1 to: pitchShape size) collect: [ :i |<br />

shapingFunction<br />

value:<br />

((seq trsp: (pitchShape at: i))<br />

dim: (durationShape at: i))<br />

value: count - 1])]].<br />

§ Thanks to Bill Walker (walker@taurus.apple.com) <strong>for</strong> the MIDI file DESAFIN1.MID.<br />

146

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!