First time here? Check out the FAQ!
x

ramp between 2 array values

0 votes
190 views
Hi everyone - my brain is not working well today and I am trying to make a script which ramps up and down continuously between 2 frequecies from two arrays at a rate set by !Glide.  It should do this until a new index arrives. in tis case Index L is a SoundToGlobalController which generates a new index under cretain conditions - in the end under LinnStrument control.  I dont really understand why we need to do an 'of:' into the 2 arrays - would I be better off making a Smalltakm script with 2 variable?  this just looked inviting

(( ((1 bpm: 5 s) abs * 2 ) of: #(
    {  Index L  of: #(519.5 529.2 543.2 586.0 598.5 647 661 686.5 716 723 806 876 942)}
    {   Index L of: #(520.1 530 544.8 587 599 648 662.2 687.5 717 748.5 820 877 944)})) smooth: !Glide s)
asked Dec 19, 2017 in Capytalk & Smalltalk by garth-paine (200 points)
I looked at another way

{| x y r| x :=  Index L  of: #(519.5 529.2 543.2 586.0 598.5 647 661 686.5 716 723 806 876 942).
    y :=   Index L of: #(520.1 530 544.8 587 599 648 662.2 687.5 717 748.5 820 877 944).
        r := (y - x).

(((1 repeatingFullRamp: 3 s) * r) +  x)

}
The issue here is that x, y, r do not update when Index L changes

1 Answer

0 votes
I wonder if it's because your [Index] L has to be scaled to a range of 0 12 in order to access all the elements of the two Arrays? For example:

((((5 s tick) nextIndexMod: 2 ) of: #(
    {12 * !Index of: #(519.5 529.2 543.2 586.0 598.5 647 661 686.5 716 723 806 876 942)}
    {12 * !Index  of: #(520.1 530 544.8 587 599 648 662.2 687.5 717 748.5 820 877 944)})) smooth: !Glide s)

seems to work as expected. I also changed it to use tick in place of bpm: since it looks like you'd prefer to specify the rate in terms of seconds. (The difference in frequency is really subtle so I tested it with larger differences between the two Arrays just to make sure that it was switching between them every 5 seconds).
answered Dec 20, 2017 by ssc (Savant) (68,670 points)
Thanks - yes that works - the reason for my other approach was that I want to ramp between the values in the array, but when a new index is selected I want to jump to that set of numbers rather than go there through all frequencies.  

this works

{| x y r| x := 17 * !ShinyIndex  of: #(0 266 328 342 374 490 497 512 582 635 662 670 700 723.5 783 868 988 1066).
    y :=  17 * !ShinyIndex of: #(0 268 333 345 384 494 501 522 590 655 665 675 720 736 815 898 1010 1114  ).
        r := (y - x).
(((1 repeatingTriangle: 4 s) * r) +  x)
}
...