GP Scripting and the different callbacks when switching rackspaces / songs

Christmastime and some longer afternoons to try out implement things of my todo lists :slight_smile:
I’m still in the phase of reworking and expanding my main gigfile after migrating to a new MBP, and I’m struggling with some functionality where I did not find complete answers so far.

Part II

I have been twiddling around with the different possibilities to implement some functionality in my rackspaces with GP Script.

Most of the ‘when is a On xxx’ called in the different levels of GP scripting (Gig Script, Global Rackspace Script, Local Rackspace, Scriptlet) I figured out with Print() statements to understand the basic sequence of the callbacks. However I’m struggling to see when the widgets are initialized - or synced, especially, if this are local widgets tied to widgets in the global rackspace by Global Parameter Assignments.

Is there something like a flowchart available, what happens, when one invokes a rackspace or songlist change?

E.g.

On Deactivate() from old rackspace → On Activate() from new rackspace → On Song() on Gig level → ???

This is still confusing me a little bit. Maybe I tried to long yesterday evening… However I figured out a workaround with a single shot timer to initialize a local/global rackspace linked widget when entering a new rackspace, and resetting this (global) widget when leaving the rackspace.

Till now, I am not able to save the state of a global rackspace widget, when entering a local rackspace, and reset it to this saved state, when leaving…

NB: I did not (and I don’t want to) add a widget to every single rackspace, only, where this functionality is needed. This of course would make this type of scripting mainly redundant…

BBB

For my understanding:
You have local rackspaces with widgets linked to global widgets.
Now when a local rackspace is switched you want all global widgets set to an initial value?

Yes and no: I have a local rackspace with one widget linked to one widget in global rackspace. This is basically working fine.

When I now switch to a different rackspace I want to reset this global rackspace widget (as this may not be linked in any other local rackspace)

I currently do this in On Deactivate “hard to on”, but not to the previous state before entering this dedicated rackspace.

I hope this makes it more clear :thinking:

I do not understand, you said that this global widget is linked to a local rackspace and now you say it is not linked to any other local rackspace?

Can your create a simple Gig File with 2 rackspaces and a global rackspace?
With this gig file I can check, maybe there is a “smart” solution.

The link is only in one of the local rackspaces, all other local rackspaces do not even provide a widget to link to this in global rackspace…

I’ll try to do an excerpt of my current gig in the evening - currently the sun is shining at -4°C - time to do a christmas walk :slight_smile:

Made a sample gig, which uses OSC callbacks.
Just set the listen port for OSC to 8001 in the OSC preferences.

SetGW.gig (59.1 KB)

This is the script in the global rackspace

var GW : Widget

// Called when a specific osc message is received
On OSCMessageReceived(m : OSCMessage) Matching "/SetGW"
 GW.SetWidgetValue(GW.GetWidgetResetValue())
 //Print("OSC")
End

It reacts on the incoming OSC message and sets the global widget to the predefined default value

And this is the script of the 2nd rackspaces

var mOSC : OSCMessage

On Activate
 OSC_SetAddress(mOSC, "/SetGW")
 OSC_ClearArgs(mOSC)
 OSC_AppendIntArg(mOSC, 1)
 OSC_SendSpecific(mOSC, "127.0.0.1", 8001)
 
end

Now you can include this code in all rackspaces where you need the global widget to be set to the default value.

1 Like

Another option is to use a widget in the local rackspace with direct OSC.
This way you need only the global rackspace script.
And with the widget you define if the global widget should be resetted.

And this is the changed global rackspace script:

var GW : Widget

// Called when a specific osc message is received
On OSCMessageReceived(m : OSCMessage) Matching "/SetGW"
 if OSC_GetArgAsDouble(m, 0) == 1.0 then
  GW.SetWidgetValue(GW.GetWidgetResetValue())
  Print("OSC")
 end
End

SetGW.gig (70.9 KB)

1 Like

I like using the function to get the GP listening port - that way it’s completely dynamic if the global listening port needs to be changed. Can also skip the integer argument if it’s not serving any purpose.

var mOSC : OSCMessage

On Activate
 OSC_SetAddress(mOSC, "/SetGW")
 OSC_SendSpecific(mOSC, "127.0.0.1", OSC_GetGPListeningPort())
end
1 Like

This brings me to an idea:

With Widget Direct OSC access it would be handy when we could use something like “listening Port” instead of giving the correct port.

1 Like

Wow, new ideas :sunglasses: OSC seems to be promising :+1:

Attached you will find a small test gig - which is partly working, just to demonstrate what I tried the last two days.

I had a similar idea as OSC and used the Local GP MIDI port on gig script level first, when i figured out that On Activate of a rackspace is called before On Rackspace on gig level…

So I made a separate intermediate workaround which basically works for one dedicated local rackspace. However I figured out this afternoon, that’s there’s something other strange happening in my gig I need to sort out first. I already have an idea :thinking:

Nevertheless: what you also can see in this test gig is the strange accent/beat behaviour.

Check the following:

  • open the gig in rackspace view and select 0 ‘A fancy Rackspace’
  • press F#1 on a MIDI keyboard to activate the metronome, the accent/beat indicators will start to work
  • preset F1 to start an imaginary ARP

→ now you will see, that the indicators will stop for some seconds

Add On: if you remove the comment on Global Rackspace Script level you can mess up the link between the two blue buttons… :scream:

BBB

LinkingAndScripting.gig (198.8 KB)

Just tested on Mac, but cannot reproduce.

Which version are you using?

When I play G2 then the metronome stops for some seconds, because in scripting you react on G2.
But when I play F1 nothing strange happens.

Question: Why do you disable and enable the playhead immediately in sequence in your scriptlet?

Thanks for taking the time @pianopaul!

To your last question: typically I didn’t use the playhead so far. I just used the metronome on/off in my main gig file while rehearsing. Therefore I just scripted to enable playhead and metronome at the trigger of a widget (-> when I push a button on my keyboard the metronome starts at beat 1…)

As I extended the gig to start an ARP at beat 1 I did similar, however I want my metronome just to switch on/off at the current beat, as the arp is already running. Therefore I tried to disable this sync with a script let control.

After some more reading of my scripts I have the impression that I’m doing something basically wrong - also as direct metronome on/off by System action will of course not reset my global rackspace widget control… Also in many scripts I have seen some additional IsPlayheadEnabeled() and IsMetronomeEnabled() checks.

I’m running the latest official GP Release 4.1.5 on an intel iMac Monterey 12.1 - but on my M1 MBP it behaves the same…

I’ve attached the following screen video to demonstrate the weird accent/beat behaviour. At ~10s you can see the accent/beat stopping when sending F1, however the playhead/metronome still play ahead. After some seconds waiting the indicators start again…

Thx
BBB

@pianopaul: where did you see which script reacting on G2?

// Sync Playhead to 1st Note
On NoteEvent(m : NoteMessage) matching B2

if IsNoteOn(m) then
    EnablePlayhead(false)
    EnablePlayhead(true)
else
    EnablePlayhead(false)
end


SendNow (m)
end

I misread, it is B2

Try to change the scriptlet code to this

// Sync Playhead to 1st Note
On NoteEvent(m : NoteMessage) matching B2

if IsNoteOn(m) then
    //EnablePlayhead(false)
    EnablePlayhead(true)
else
    EnablePlayhead(false)
end


SendNow (m)
end

I think the subsequent EnablePlayhead(false) and EnablePlayhead(true) are the root cause of this issue.

Ahh, that’s OK! The B2 is ‘remapped’ from the ‘Trigger an Arp (F1)’ widget :wink:

I also suspect the subsequent EnablePlayhead() commands. However I still need to stop the playhead if it is already running to get to beat 1 … So I will try to add a suitable if IsPlayheadEnabled() condition here.

Unfortunatly I’m now in the in-between-phase of the year and need to do some typical after-christmas jobs at home now - I’ll get back later - hopefully this year :joy:

Thanks for all the suggestions so far!