Kyma Forum
  Kyma Support
  spectrum from array & smalltalk headaches

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   spectrum from array & smalltalk headaches
Denis Goekdag
Member
posted 07 March 2010 22:27         Edit/Delete Message   Reply w/Quote
I've been trying to get my head round this for a couple of hours now and I'm just not getting it --- my (very limited) grasp on Smalltalk doesn't appear to suffice. Maybe someone would be so kind and point me in the right direction ;-)

Basically, I want to algorithmically populate the amplitudes field of a Synthetic Spectrum From Array with n array elements. That's easily accomplished with something like

{ | n | n := 8. (1 to: n) collect: [:i | (1 * i inverse)]}

(which gives 8 partials with a 1/n amplitude slope)

Where it gets difficult (at least for *me*....) is when I try to add the following functionality ;-)

Basically, I want a VCS fader that interpolates between all amplitudes at 1 in the fader's middle position, the aforementioned 1/n slope at it's maximum position and the inverse of that slope at minimum position (so partial 1 gets 1/n, 2 gets 1/(n-1) and n gets 1).

So the resulting values would look something like this

1/8 <> 1 <> 1/1
1/7 <> 1 <> 1/2
1/6 <> 1 <> 1/3
...<snip>...
1/1 <> 1 <> 1/8


So far I've tried using an into: array inside the loop, kind of like this (!Slope supposedly being in the range -1...1):

{
| n |
n := 8.
(1 to: n) collect: [:i | !Slope into: #({(-1)@(1/((n+1)-i))} {0@1} {1@(1/i)})]
}

....which doesn't work and evaluates to

Error during literal evaluation ->{ | n | n := 8. (1 to: n) collect: [:i | !Slope into: #(Error during literal evaluation ->{(-1)@(1/((variable undeclared -> n+1)-i))} {0@1} {1@(1/i)})]}


So my best guess at this point is that the scope of the variable n does not extend into the into: array (and probably i doesn't "reach" the array, either...).


Which leads to the question: is it possible to pas the values of n (and i for that matter) on into the into: array? If not: any ideas of how to do the "Slope" thing differently?

Cheers!
d


[This message has been edited by Denis Goekdag (edited 07 March 2010).]

IP: Logged

LuddyHarrison
Member
posted 19 March 2010 12:56         Edit/Delete Message   Reply w/Quote
Yeah, I guess the problem is that the literal array of points #( ... ) has to be a constant expression, whereas you have a variable in yours. I don't know of an "unquote" mechanism in Smalltalk, but that's what you would need to allow a non-constant expression to be embedded in a literal array.

Perhaps you can use a second collect expression inside the first one, to construct the inner array in terms of n?

-Luddy

IP: Logged

SSC
Administrator
posted 19 March 2010 19:46         Edit/Delete Message   Reply w/Quote
Luddy's right regarding the literal Arrays. One way around it is to construct the Array using an instance creation method rather than trying to make a literal array when some of the elements include variables. For example, you could modify your code to:

code:

{
| n |
n := 8.
(1 to: n) collect: [:i | !Slope into: (Array with: (-1@(1/((n+1)-i))) with: (0@1) with: (1@(1/i)))]
}

For example, to make the Array #(1 2 3), one can instead construct it using:

Array with: 1 with: 2 with: 3.

But in the case of a simple literal Array, it's often easier to just use the literal Array directly.

IP: Logged

Phi Curtis
Member
posted 21 March 2010 11:13         Edit/Delete Message   Reply w/Quote
quote:
Originally posted by SSC:
Array with: 1 with: 2 with: 3.

This lead to a question I was just about to ask on a new thread:

I often would like to create long arrays containing expressions with variables (especially when filling MultiSample players with long lists of audiofiles, for example). I have found that when using the Array: with: with: expression, it stops working after about 35 "with:s." Is there another way to do this? Or could it be extended out to say 100 in the next version of Kyma?

Phil

IP: Logged

Denis Goekdag
Member
posted 22 March 2010 01:47         Edit/Delete Message   Reply w/Quote
Thanks, Luddy & SSC! The Array "with:" does the trick. I guess it's really my lack of fundamental Smalltalk skills showing in the fact that I didn't know that the #(...) Array type doesn't take variables at all huh ;-)

My next learning project: make another fader balance odd and even numbered partials.

Thx & laterz,
d

IP: Logged

SSC
Administrator
posted 22 March 2010 10:52         Edit/Delete Message   Reply w/Quote
quote:
I have found that when using the Array: with: with: expression, it stops working after about 35 "with:s." Is there another way to do this?

You can concatenate two Arrays using the comma operator. For example:

code:

(Array with: 1 with: 2 with: 3), (Array with: 'hi' with: 'there' with: 'brother')


Just to clarify my earlier post, a Smalltalk Array can contain variables (or any other object) as its elements. It's just that there is a shortcut you can use to create Literal Arrays (arrays where all the objects' literal values are known). For example, instead of using the normal creation method (Array with: 1 with: 2 with: 3) you can use the shortcut #(1 2 3).

IP: Logged

Phi Curtis
Member
posted 22 March 2010 15:24         Edit/Delete Message   Reply w/Quote
quote:
Originally posted by SSC:
code:

(Array with: 1 with: 2 with: 3), (Array with: 'hi' with: 'there' with: 'brother')



Thanks - It's a little odd, but it works!

IP: Logged

cristian_vogel
Member
posted 23 March 2010 04:42         Edit/Delete Message   Reply w/Quote
is that a method for interpolating into an array with hotvalues at runtime? I dont have my kyma rig at the moment, but I remember always coming to an error with something like

!Index into: #( {100@!floor} {1000@!ceiling} )

IP: Logged

Denis Goekdag
Member
posted 23 March 2010 10:51         Edit/Delete Message   Reply w/Quote
Yes, that's right.

IP: Logged

Denis Goekdag
Member
posted 23 March 2010 10:53         Edit/Delete Message   Reply w/Quote
Or at least with *variables* inside the array. Not sure what that means for hot values.

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply

Contact Us | Symbolic Sound Home

This forum is provided solely for the support and edification of the customers of Symbolic Sound Corporation.


Ultimate Bulletin Board 5.45c