Help with arrays, please

hi all,

i use a SoftStep 2, and i’m just now learning to use the Direct Access property of GP to have keys 1-4 select variations 1-4 in my rackspaces. i want to have the LED lights on keys 1-4 reflect which key was last pressed. there is no easy way on the SST to have each of the keys turn off the LEDs of the other 3 keys, but you can send LED on/off messages to it. so, i want to do this:

Step on key1: send cc21, 1; cc22, 0; cc23, 0; cc24, 0 (send all these to the SST)
Step on key2: send cc21, 0; cc22, 1; cc23, 0; cc24, 0
Step on key3: send cc21, 0; cc22, 0; cc23, 1; cc24, 0
Step on key4: send cc21, 0; cc22, 0; cc23, 0; cc24, 1

the SST MidiOutBlock is called “SST”

i have set this up to work by brute force, declaring 4 ControlChangeMessage variables, k1,k2,k3,k4, and creating and sending those for with the appropriate values when the widget value corresponding to each key is changed. the script gets long, and there are other things in it too.

i gather that i can create an “array” that will make creating and sending the actual midi messages simpler/shorter. is there someone who could help me walk through this?

thank you in advance!

tony

Hi Tony,
maybe you can find some ideas for it in this thread:


I think you can adapt the logic behind it…

Ahhh, some kind of radio button behavior needed here? :face_with_monocle:

@tonycore, don’t hesitate to post your script if you want us to have a look. :wink:

I think this should be a job for the Deskew summer intern!

1 Like

thanks, all! i will look at the radio button script (i forgot the name of this functionality - “radio buttons,” of course) and report back.

btw, i also stole a function called "TurnOffAllLightsExcept(index : integer) for this, so that my GP rackspace that looks like my pedal setup would do the same thing - i guess maybe i can adapt that function to do what i want with sending midi messages to the SST.

i realized after going to bed that i should have posted my script…here is the relevant part:

var

    Button1 : Widget //clean button
    Button2 : Widget //crunch button
    Button3 : Widget //rhythm button
    Button4 : Widget //lead button
    cl : Widget //clean light
    cr : Widget //crunch light
    rh : Widget //rhythm light
    ld : Widget //lead light
    SST : MidiOutBlock // softstep
    k1 : ControlChangeMessage //for setting LED for key 1
    k2 : ControlChangeMessage //for setting LED for key 2    
    k3 : ControlChangeMessage //for setting LED for key 3
    k4 : ControlChangeMessage //for setting LED for key 4

Initialization
  lights = [cl, cr, rh, ld]

function TurnOffAllLightsExcept(index : integer)
   var
      i : integer

   for i = 0; i < Size(lights); i = i + 1 do
     if i <> index
        then SetWidgetValue(lights[i], 0)
        else SetWidgetValue(lights[i], 1)
     end
   end
end     

//switch to clean
On WidgetValueChanged(newValue : double) from Button1

                k1 = MakeControlChangeMessage(20,1)
                k2 = MakeControlChangeMessage(21,0)
                k3 = MakeControlChangeMessage(22,0)
                k4 = MakeControlChangeMessage(23,0)
                SendNowExternal(SST, k1)
                SendNowExternal(SST, k2)
                SendNowExternal(SST, k3)
                SendNowExternal(SST, k4)

end

//switch to crunch
On WidgetValueChanged(newValue : double) from Button2

                k1 = MakeControlChangeMessage(20,0)
                k2 = MakeControlChangeMessage(21,1)
                k3 = MakeControlChangeMessage(22,0)
                k4 = MakeControlChangeMessage(23,0)
                SendNowExternal(SST, k1)
                SendNowExternal(SST, k2)
                SendNowExternal(SST, k3)
                SendNowExternal(SST, k4)
                                   
end

//switch to rhythm
On WidgetValueChanged(newValue : double) from Button3

                k1 = MakeControlChangeMessage(20,0)
                k2 = MakeControlChangeMessage(21,0)
                k3 = MakeControlChangeMessage(22,1)
                k4 = MakeControlChangeMessage(23,0)
                SendNowExternal(SST, k1)
                SendNowExternal(SST, k2)
                SendNowExternal(SST, k3)
                SendNowExternal(SST, k4)
                                
end

//switch to lead
On WidgetValueChanged(newValue : double) from Button4

                k1 = MakeControlChangeMessage(20,0)
                k2 = MakeControlChangeMessage(21,0)
                k3 = MakeControlChangeMessage(22,0)
                k4 = MakeControlChangeMessage(23,1)
                SendNowExternal(SST, k1)
                SendNowExternal(SST, k2)
                SendNowExternal(SST, k3)
                SendNowExternal(SST, k4)
                     
end
1 Like

Oh, I have a SoftStep 1… think I can help :wink:

Here you are — pass in the CC number of the message you want to be 1 and this will send out messages to the four items, with the CC number you passed in being 1, the rest will be 0

function UpdateCC(ccNumber : integer) 
   var
      i : integer
      k : ControlChangeMessage
      
   for i = 20; i <= 23; i = i + 1 do
      if i == ccNumber
         then
            k = MakeControlChangeMessage(i,1)
         else
            k = MakeControlChangeMessage(i,0)
      end
      SendNowExternal(SST, k)
   end
   
end

Edit:
Make sure that SST is declared before this function. Then just call it by writing

 updateCC(21)

or

updateCC(23)

You’ll probably want to give the function a better name though.

1 Like

david, thank you. works a peach and i even understand it! final version:

var

    Button1 : Widget //clean button
    Button2 : Widget //crunch button
    Button3 : Widget //rhythm button
    Button4 : Widget //lead button
    cl : Widget //clean light
    cr : Widget //crunch light
    rh : Widget //rhythm light
    ld : Widget //lead light
    SST : MidiOutBlock // softstep
    k1 : ControlChangeMessage //for setting LED for key 1
    k2 : ControlChangeMessage //for setting LED for key 2    
    k3 : ControlChangeMessage //for setting LED for key 3
    k4 : ControlChangeMessage //for setting LED for key 4


Initialization
  lights = [cl, cr, rh, ld]

function TurnOffAllLightsExcept(index : integer)
   var
      i : integer

   for i = 0; i < Size(lights); i = i + 1 do
     if i <> index
        then SetWidgetValue(lights[i], 0)
        else SetWidgetValue(lights[i], 1)
     end
   end
 
end 

function UpdateSSkeys(ccNumber : integer) 
   var
      i : integer
      k : ControlChangeMessage
      
   for i = 20; i <= 23; i = i + 1 do
      if i == ccNumber
         then
            k = MakeControlChangeMessage(i,1)
         else
            k = MakeControlChangeMessage(i,0)
      end
      SendNowExternal(SST, k)
   end
   
end    


//switch to clean
On WidgetValueChanged(newValue : double) from Button1
	     TurnOffAllLightsExcept(0)
                UpdateSSkeys(20)
end



//switch to crunch
On WidgetValueChanged(newValue : double) from Button2
	     TurnOffAllLightsExcept(1)	      
                UpdateSSkeys(21)                                   
end

//switch to rhythm
On WidgetValueChanged(newValue : double) from Button3
	     TurnOffAllLightsExcept(2)
                UpdateSSkeys(22)                          
end

//switch to lead
On WidgetValueChanged(newValue : double) from Button4
	     TurnOffAllLightsExcept(3)
                UpdateSSkeys(23)
end
1 Like

NB, you could get really cute and combine the two functions you’re calling in every On WidgetValueChanged callback

E.g. noticing that the LED number is CC number of SSkey - 20 …

 function TurnOnOneLightAndUpdateSSKeys(ccNumber : integer)
    TurnOffAllLightsExcept(ccNumber-20)
    UpdateSSkeys(ccNumber)
 end

Now you can just write (for example)

On WidgetValueChanged(newValue : double) from Button4
     TurnOnOneLightAndUpdateSSKeys(23)
end

i was wondering about something like that - if it’s actually possible to combine the functions themselves into a single function that does both things.

Functions can call other functions!

don’t tell anyone, but GP is giving me programming skilz!

Not if you spell it “skilz” it isn’t!

1 Like

what, are you some kind of traditionalist?

btw, i am very excited that i can use just those 4 keys on the SST for variation changes, and leave the rest for other uses. (the fact that this excites me does indicate a certain level of geekness, i suppose…) also, with SST presets being recalled by GP rackspace scripts, there are some rackspaces without variations where i can use those 4 keys for other purposes.

It’s the hippy mode of GP Script. Funk-shuns, arrayzz, boo-yah-lean, intajah.

2 Likes

Honestly, I hate spelling and grammatical mistakes. I notice them immediately (much like noticing bum notes from someone during a performance) and find them very distracting. I cannot tell you how many books I have returned to Amazon and a couple of other tech publishers due to poor content editing.

1 Like

Shouldn’t that be ‘grammatical’ mistakes ?..:nerd_face:

Touché. But I don’t care about my own mistakes :slight_smile: I fixed it!

1 Like

This looked really interesting, as I was currently trying to do something similar with a SoftStep 2. Copied and pasted your script, but got a compilation error at the TurnOffAllLightsExcept function. Not sure why.

The error message is complaining that it saw a “function” but it was expecting an “End”

Your Initialization callback needs an End after the assignments inside it