First time here? Check out the FAQ!
x

Can I make an OrderedCollection reference Event values?

0 votes
509 views

In a Tool, I have some local variables scale1, scale2, scale3... which have Event values !Scale1, !Scale2, !Scale3. There are places in the code where I want to iterate over all the scales, and pull values from another ordered collection. If that isn't clear, maybe the snippet below will explain better:

"This doesn't work: It stores the values of scale1
through scale8. Need to store references to them in
order to pass back hot-values !Scale1 - !Scale8."

scales := OrderedCollection new add: scale1; add: scale2; ... yourself.

"(The following doesn't work: scales contains values not variable pointers.)"
  1 to: 8 do: [:source|
    scales at: source put: (1 - 0.9 * ((Sources at: source) at: 'distance') / ((Sources at: source) at: 'radius')).
].

asked Jun 12, 2015 in Capytalk & Smalltalk by kevin-cole (Adept) (1,050 points)

2 Answers

0 votes
 
Best answer

Unfortunately, Smalltalk doesn't allow for an array of pointers.  It seems that you'll have to unroll the loop and do them one by one:

scale1 := (1 - 0.9 * ((Sources at: 1) at: 'distance') / ((Sources at: 1) at: 'radius')).
scale2 := (1 - 0.9 * ((Sources at: 2) at: 'distance') / ((Sources at: 2) at: 'radius')).

..

scale8 := (1 - 0.9 * ((Sources at: 8) at: 'distance') / ((Sources at: 8) at: 'radius')).
 

On a higher level, what is it that you are trying to make happen here?  If you're assigning sources to positions, maybe you could put a Pan module or MultichannelPan module on each source and control the angle and radius EventValues of those (rather than doing the scaling inside the Tool)?

answered Jun 18, 2015 by ssc (Savant) (128,080 points)
selected Jun 19, 2015 by kevin-cole
Yes, I have 8 loudspeakers with 8 different Sounds (audio sample files) positioned around a test subject. I think I looked at Pan and MultichannelPan, but maybe not. I'll look again, though I've got something I'm moderately pleased with now, scaling from within the Tool.
Upon sitting down with Kyma today, I see I did look at Pan and MultichannelPan before, and couldn't see an obvious way to keep eight separate sources attached to eight separate loudspeakers with those.
If you want to associate a source with a channel, then maybe Output8 would do the trick?  Or SelectableAudioOutput with a fixed channel value?
0 votes

Hi Kevin,

Was working on a solution to a different question and realized this solution might work for your case as well.  Here's an example of a Tool that uses a 3d array.  If you look in the InitialState onEntry response you'll see a code block definition:


UpdateSequencers := [
    0 to: 4 do: [:i |
        0 to: 4 do: [:j |
            0 to: 4 do: [:k |
                | eventValueName |
                eventValueName := ('Gate' & i, '_'& j, '_' & k) asSymbol.
                SignalProcessor postEventValueNamed: eventValueName dspValue: (Space at: i at: j at: k)]]]].


Each loop in the block creates the eventValueName algorithmically with string concatenation, changes it to a Symbol, and then asks the SignalProcessor to post a value from the array to that EventValue.

Since your EventValue names are quite systematic (!Scale1, !Scale2, etc), this might be a solution to the problem you ran into.  Rather than keep an Array of EventValues, you could keep an Array of values in the Tool and loop through that Array to send values to the DSP (to EventValues you construct using string concatenation).  

Just a thought...

answered Jul 21, 2015 by ssc (Savant) (128,080 points)
Is this also possible the other way around? something like SignalProcessor getEventValueNamed: aSymbol dspValue: aNumber?
...