First time here? Check out the FAQ!
x

EventVariable definition

0 votes
298 views
Hello everybody, I have some problems with the concept of Event Variable. Is there somebody that could help me with a definition of it and an example of where to use it? Thanks.
asked Feb 9, 2017 in Capytalk & Smalltalk by domenico-cipriani (Master) (3,110 points)

1 Answer

+3 votes
 
Best answer

An EventVariable is a variable whose value can be changed during run time in a Capytalk expression using the assignment operators <+ or <~.

This is different from a Smalltalk variable which can change state during compile time using the assignment operator, :=, and is no longer referenced or updated while the Sound is running. 

It's pretty rare to need an EventVariable, but if you want to create a Capytalk expression where the current value depends on the previous value, you can use an EventVariable to hold onto the previous state.  For example, if you wanted to increment the value of a parameter each time you received a trigger, you would need to keep track of the previous value in order to increment it when the next button press comes in.  To hold onto the previous value, you could use an EventVariable, for example:

| prev |
prev := EventVariable new initialValue: 0.
!Trigger
    true: (prev <+ (prev + 1))
    false: (prev)

Let's say, instead, that you wanted to create a Capytalk expression using Smalltalk to build it up.  In this case, you might use a Smalltalk variable to hold onto the previous Capytalk expression as you add new extensions to it, for example:

| kernel |
kernel := !Value.
1 to: 4 do: [ :i | kernel := kernel + (!Offset suffix: i)].
kernel

which, if you select it and evalute it using Ctrl+Y evaluates to:

 !Value + !Offset1 + !Offset2 + !Offset3 + !Offset4

In this case, you are building an expression at compile time, and then sending that expression to the Pacarana where it can be evaluated while the Sound is running and respond to changes in !Value in the !Offsets.

answered Feb 9, 2017 by ssc (Savant) (127,060 points)
selected Feb 14, 2017 by domenico-cipriani
it's indeed rare to need this. Whenever I think about EventVariables iterative equations like strange attractors come to my mind ;)
I am trying to build a real time recording with a kind of grid quantization using EventVariables and an EventVariable array.
let´s see what happens :)
...