![]() |
![]() ![]() ![]() ![]() ![]()
|
next newest topic | next oldest topic |
Author | Topic: spectrum from array & smalltalk headaches |
Denis Goekdag Member |
![]() ![]() ![]() 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
{ ....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)})]}
Cheers! [This message has been edited by Denis Goekdag (edited 07 March 2010).] IP: Logged |
LuddyHarrison Member |
![]() ![]() ![]() 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 |
![]() ![]() ![]() 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: 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 |
![]() ![]() ![]() quote: 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 |
![]() ![]() ![]() 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, IP: Logged |
SSC Administrator |
![]() ![]() ![]() quote: You can concatenate two Arrays using the comma operator. For example: code: 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 |
![]() ![]() ![]() quote: Thanks - It's a little odd, but it works! IP: Logged |
cristian_vogel Member |
![]() ![]() ![]() 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 |
![]() ![]() ![]() Yes, that's right. IP: Logged |
Denis Goekdag Member |
![]() ![]() ![]() 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 |
![]() ![]() |
This forum is provided solely for the support and edification of the customers of Symbolic Sound Corporation.