How to test widget values and send message to external controller

i have a new SoftStep 2 and i want each rackspace on activation to turn on and the LEDs as needed - in each rackspace some of my plugins begin on, and some off.

i figured out how to send the correct messages. but, what i really need is for each rackspace on activation to clear all the LEDs, test each button widget to see if it is on or not when the rackspace is activated, and send the “LED on” message to those LEDs which should be on. (Or, i could have it test all the button widgets and send an “on” message if its on, and an “off” message if it’s off).

the script here gets stuck on the “If” line, it seems there has to be something before the “If” to activate the “If”. however, i just want it to check the values that i’ve got, and send the correct LED messages. I can’t add the “If” to the “On Activate” part of the script, apparently. how can i make GP script check the values?

additionally, i would think there’s a way to simplify this all by using arrays, and/or loops, but i don’t understand how to do that.

var 
    SSTC : MidiOutBlock
    Button1, Button2, Button3, Button4, Button5, Button6, Button7, Button8, Button9, Button10 : Widget
    b1, b2, b3, b4, b5, b6, b7, b8, b9, b10 : double
    l1, l2, l3, l4, l5, l6, l7, l8, l9, l0 : ControlChangeMessage
    

// gets initial widget values
On Activate
    b1 = GetWidgetValue(Button1)
    b2 = GetWidgetValue(Button2)
    b3 = GetWidgetValue(Button3)
    b4 = GetWidgetValue(Button4)
    b5 = GetWidgetValue(Button5)
    b6 = GetWidgetValue(Button6)
    b7 = GetWidgetValue(Button7)
    b8 = GetWidgetValue(Button8)
    b9 = GetWidgetValue(Button9)
    b10 = GetWidgetValue(Button10)
End


// tests whether values are 1 or 0 and sends appropriate LED state message to SST
    If
     b1 == 0
     l1 = MakeControlChangeMessage(20,0)
      else 
      l1 = MakeControlChangeMessage(20, 1)
    End

    SendNowExternal(SSTC, l1)

GP Scripts are organized in callbacks activated by certain events. It is not a large program executed sequentially. Your “If” is out of any callback structure and it cannot work like that.

The script you would like to do could be something like that:

var
    SSTC : MidiOutBlock
    Button1, Button2, Button3, Button4, Button5, Button6, Button7, Button8, Button9, Button10 : Widget

On Activate
  SSTC.SendNowExternal(MakeControlChangeMessage(20,Round(GetWidgetValue(Button1))));
  SSTC.SendNowExternal(MakeControlChangeMessage(20,Round(GetWidgetValue(Button2))));
  SSTC.SendNowExternal(MakeControlChangeMessage(20,Round(GetWidgetValue(Button3))));
  SSTC.SendNowExternal(MakeControlChangeMessage(20,Round(GetWidgetValue(Button4))));
  SSTC.SendNowExternal(MakeControlChangeMessage(20,Round(GetWidgetValue(Button5))));
  SSTC.SendNowExternal(MakeControlChangeMessage(20,Round(GetWidgetValue(Button6))));
  SSTC.SendNowExternal(MakeControlChangeMessage(20,Round(GetWidgetValue(Button7))));
  SSTC.SendNowExternal(MakeControlChangeMessage(20,Round(GetWidgetValue(Button8))));
  SSTC.SendNowExternal(MakeControlChangeMessage(20,Round(GetWidgetValue(Button9))));
  SSTC.SendNowExternal(MakeControlChangeMessage(20,Round(GetWidgetValue(Button10))));
End

But, I have got the feeling that you could be on the wrong track. Don’t you think you could simply associate your widget buttons to the plugin parameters you want to control and to the MIDI controller you use ? Using the “sync” option in the widget properties, you should be able to synchronize the state of your MIDI controller and of the widget buttons without the need of any script.

thank you, david-san!

i neglected to mention that i only wrote the code for switching the LED for key #1. i will look at the script you kindly sent and see if it can help me.

about the “Sync” option - i tried using it, but it didn’t seem to do anything. the SoftStep requires specific messages to control its LEDs - for example, to turn on and off the red LED for Key #1, you have to send it CC20 with a value of 1 or 0; to turn on and off the green LED for the same key you need to send CC110 with those values…and each LED for key needs a different CC. does GP know this, or is there another way to get it to send these messages automatically?

the script you created fails to compile on the first line after “On Activate” with this message:
“Semantic error: Line 6, Col 3: Types are not compatible”
i’ll see what i can figure out…

addendum: needs to be “SendNowExternal”

further addendum: with that change, the script works perfectly - and i even almost understand why! thank you so much. now, i’d like to understand what the “sync” option actually does, and why it doesn’t work for me.

and a final addendum…thank you for the excellent script…however, sadly, of course turning an LED on on the SoftStep does not actually change the state of the key. so, if i turn the LED for Key#1 on, pressing the key will not turn it - or its associated plugin - off. looking into how i might deal with this.

Yes of course, you are right, it is SendNowExternal for a MIDIoutBlock :wink:

It is supposed to synchronize the state of your physical MIDI controller knobs, faders, buttons or whatever with the state of their widget counterparts in GP. However, I cannot help you a lot regarding the controller you use. What do the different LED colors stand for ? Is a LED related to the value of the controller ?

I took a quick look at some pictures of your controller and it seems that acting on a unique pad of your controller can generate several different MIDI messages. This could be tricky for the learn option in the MIDI section of the widget properties. Perhaps you should open a MIDI monitor and see what kind of message you are sending to GP when learning your MIDI controller ? This could help to understand what happens…

I have an older SoftStep 1; Later I’ll take a look at the script/ideas…

On macosx this is quite nice MIDI monitor ‎Pocket MIDI on the Mac App Store

Yes, but the one of GP will be enough for that.

For the Mac, I prefer Snoize from https://www.snoize.com/

It has all sorts of extra functionality including the ability to spy on outgoing messages