How to get parameter or widget value on init in scriptlet

Greetings! :grinning:

I have a knob connected to a scriptlet parameter that changes the tempo of a BeatBuddy. It works fine for changing the tempo but it can not restore the tempo from the saved widget value on initialization.

It seems like functions like GetParameter is not available in scriptlets but is available in scripts. Do I have to use scripts for this ? If so can I send tempo changes to BeatBuddy via ordinary script ? :nerd_face:

Hi @kjetilge. What messages are being sent in order to change the tempo in the BeatBuddy?

And is it when you’re switching rackspaces that it’s not sending out a message to the BeatBuddy, or when you first load the gig file, or some other situation?

Is the scriptlet in each local rackspace or in the global rackspace?

This seemed to fix the problem:

bpm : Subrange Parameter 40..300 = GetSubrangePreviousValue (bpm)

I started GP scripting yesterday so it took some time to figure out what function to use. I was lucky with this one :laughing:

The knob just sends valuses to a scriplet parameter.

The script looks like this:

// Declare various kinds of parameters
var
   msb : Integer = 0
   lsb : Integer = 0
   bpm : Subrange Parameter 40..300 = GetSubrangePreviousValue (bpm) // 100
   param : Integer = 0
// Called automatically after script is loaded
Initialization
    // param = GetParameter (BMP, 0)
    bpm = GetSubrangePreviousValue (bpm)
select 
   bpm > 255 do
      msb = 2
      lsb = bpm - 256
    Print("msb 255, lsb: " + lsb)
   bpm > 127 do
	  msb = 1
	  lsb = bpm - 126
   true do
   	  msb = 0
	  lsb = bpm
end
End

// Called when rackspace is activated
On Activate
  
  Print("Active bmp# "+ bpm#)
  Print("param " + param)
  param = GetSubrangePreviousValue (bpm)
   // param = GetParameter (BMP, 0)
    // <statements>
    Print("value on active: " + bpm)
End



   // Called when a parameter value has changed
On ParameterValueChanged matching bpm

select 
   bpm > 255 do
      msb = 2
      lsb = bpm - 256
    Print("msb 255, lsb: " + lsb)
   bpm > 127 do
	  msb = 1
	  lsb = bpm - 126
   true do
   	  msb = 0
	  lsb = bpm
end

Print("value changed to " + bpm)

SendNowToMidiOutDevice("BeatBuddy Bluetooth", MakeControlChangeMessage(106,msb))
SendNowToMidiOutDevice("BeatBuddy Bluetooth", MakeControlChangeMessage(107,lsb))


end

I’m glad you got it working.
I wouldn’t have thought that the ‘PreviousValue’ function would be required, but I haven’t tried to test your code.

As you start to use scripts more, anytime you find yourself repeating the same lines of code, you could create your own Function. It’s mentioned here in the Language Manual:

My other comment would be about where you’re sending directly to a midi out device. Because scriptlets exist as a plugin in Wiring view, you can instead just use the general SendNow function, and then connect the scriptlet midi out port to your beat buddy midi out port. This gives you the benefit of a more visual indicator of where the messages are being sent to, and one less thing to have to edit in the script code if you ever need to change the routing.

I have adjusted your post to put triple backquotes before and after your script so that it shows up properly indented, etc.

1 Like

A great tip!. Seems obvious now :rofl:. It worked immediately :+1::smiley:.

By the way, how do I edit my comments in here ?

There’s a pencil icon at the bottom of your posts, which allows you to edit them. It may only be visible after you’ve made a few posts.

Welcome to the GP Community!

1 Like

That doesn’t appear until the system has decided you have posted enough legitimate items so that you’re not a spammer :slight_smile: However, you have been manually incremented to the next trust level so that pencil should be available now

1 Like

Hi @kjetilge, welcome to the GP community forum. Glad to have one more GPScripter! :wink:

GetParameter is necessary to get the parameter value of a plugin, not to get the parameter value within a Scriptlet. Scriptlet parameters are directly available using their variable name within the Scriptlet code. You cannot access directly a plugin parameter from a Scriptlet, as Scriptlet are plugins and are therefore not aware of other plugins.

Having said that, a Scriptlet is perfectly adapted to what you want to do here:

  • a widget mapped to a bmp parameter of your Scriptlet to adjust the tempo
  • if the Scriptlet bmp parameter is changed the Scriptlet sends the proper MIDI messages to its output (using SendNow as mentioned by @rank13 and not by sending directly to a MIDI port)
  • when you switch to a rackspace the tempo widget will initialize the bmp parameter of your Scriptlet which is equivalent to changing the bmp parameter manually (On ParameterValueChanged patching bmp will than send the MIDI message)

So indeed, I agree with @rank13, use SendNow and connect the MIDI output of your Scriptlet to the BeaatBudd MIDI out port. Use perhaps your own custom SendBMPNow(bmp) function. And possibly don’t use GetSubRangePreviousValue (bmp), but bmp directly (or perhaps I missed something).

Great job for your first Scriptlet :+1:

1 Like