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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Scripting<br />

MIDI Scripts<br />

<strong>The</strong>re are two different kinds of scripts in <strong>Kyma</strong>: Event Value-generating scripts (found in the MIDIVoice<br />

and the MIDIMapper <strong>Sound</strong>s), and <strong>Sound</strong>-constructing scripts (Scripts and FileInterpreters).<br />

MIDIVoice and MIDIMapper scripts provide an algorithmic way to generate events indistinguishable<br />

from events coming from a MIDI file or a MIDI device. You can use these scripts to generate control signals<br />

or note events algorithmically. MIDI scripts are intended to replace the older scripting <strong>Sound</strong>s in<br />

applications that model an “instrument” playing from a “score”.<br />

MIDIVoice and MIDIMapper scripts do not run in real time. When you compile a MIDI script, the script<br />

is executed first and the generated events are saved. <strong>The</strong>n the remainder of the <strong>Sound</strong> is compiled and<br />

loaded along with the events saved from the script. When you start the <strong>Sound</strong>, the generated events will<br />

be started at the appointed time.<br />

<strong>The</strong> Script and FileInterpreter <strong>Sound</strong>s construct new <strong>Sound</strong>s that are combinations of Mixers and<br />

TimeOffsets. Scripting <strong>Sound</strong>s do not generate events. Instead, they assist you in the process of building<br />

<strong>Sound</strong>s the way you would build them in the graphic <strong>Sound</strong> editor. When there is a describable pattern<br />

to the <strong>Sound</strong> parameters and the way the <strong>Sound</strong>s are put together, you can use a scripting <strong>Sound</strong> to construct<br />

complex <strong>Sound</strong> structures automatically. For example, say you wanted to construct a reverberation<br />

algorithm out of six ReverbSection <strong>Sound</strong>s, each with a slightly different DecayTime and Delay. Using a<br />

scripting <strong>Sound</strong>, you could use a loop to construct a Mixer of ReverbSection <strong>Sound</strong>s, each with its own<br />

DecayTime and Delay. That way, you could save time by writing a single loop instead of setting all<br />

twelve parameters by hand.<br />

When you compile a scripting <strong>Sound</strong>, it first constructs the equivalent combination of Mixers and<br />

TimeOffsets; then it compiles, loads and starts that automatically-constructed <strong>Sound</strong>.<br />

<strong>The</strong> MIDIVoice and MIDIMapper modules give you three choices <strong>for</strong> the source of MIDI events: the live<br />

MIDI input stream (originating from external controllers, or from a sequencer or other software running<br />

in parallel with <strong>Kyma</strong>), a MIDI file stored on disk, or a script (which generates events algorithmically and<br />

then emits them). To the <strong>Kyma</strong> <strong>Sound</strong>, events coming from a script are indistinguishable from events<br />

coming from a MIDI file.<br />

<strong>The</strong>re are two main ways of working with the MIDI scripts:<br />

1. Creating low-level notes and controller events at specific times<br />

2. Creating and manipulating high level EventCollections: combinations of Note and Rest objects<br />

Creating Notes and Controller Events<br />

<strong>The</strong> syntax <strong>for</strong> a basic note event is:<br />

self keyDownAt: aTime duration: aDur frequency: aFreq velocity: aVel.<br />

Where aTime is a time specified with units (<strong>for</strong> example, 1 s or 2 beats), aDur is a duration specified<br />

with units, aFreq is a frequency specified with units (<strong>for</strong> example, 440 hz, 60 nn, or 4c), and aVel is a<br />

velocity value between 0 and 1. <strong>The</strong> duration:, frequency:, and velocity: tags are optional, the<br />

default values are 10 ms, 0 nn, and 1, respectively.<br />

For example, to send a note event <strong>for</strong> a middle C lasting <strong>for</strong> one second, you would use:<br />

self keyDownAt: 0 s duration: 1 s frequency: 4 c.<br />

Note events cause the following to happen:<br />

♦ At the given time, !KeyDown is set to -1.<br />

♦ After 5 ms, !KeyDown is set to 1, !KeyNumber is set to the pitch equivalent of the frequency, and<br />

!KeyVelocity is set to the velocity value.<br />

♦ After the given duration has passed, !KeyDown is set to 0.

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

Saved successfully!

Ooh no, something went wrong!