On Variation

Hopefully a quick question in GP 4.5 can “On Variation” be used in a scriptlet, I wish to reset some information in the scriptlet when the variation changes.

TIA

Sorry, but your out of luck: The closest thing would be ‘On Activate’, but that’s not good enough for your purpose.

// Called when rackspace is activated
On Activate
    Print("Yep")
End

Reason for this is that Scriptlets are more or less plugins. And plugins are not supposed to be aware of the hosting environment (not in this detail anyway).

What you could do is add a parameter (discrete, or a range), assign that parameter to a (hidden) button widget and set that button to the right value in each variation. In the scriptlet you can check the change of the parameter and act accordingly.

1 Like

I created a small example responding to variation changes. To see results, please open the logger window (Window-> Show Script Logger)

ScriptletVariations.gig (25.1 KB)

2 Likes

If you really need something like that, you could perhaps use OSC to detect a variation change. But, I also use “On Activate”… :nerd_face:

Thanks guys, all working now using On Deactivate, it resets on first load and then after it has been used. What I was trying to get running was a Note On block of a sound layer on the start of a song. just for half a bar. The reset would only be needed if the song was restarted (after a rackspace change).

Originally when trying to do this as a straight variation change, I was getting early and late layered notes due to the playing speed and my manually changing variations. This now works a treat. BTW. the song is Marillion - Punch and Judy opening bar, if you want to hear what I was trying to replicate.

// See below for updated scriptlet

You also need a On NoteOffEvent callback, but I suppose you noticed it in the meantime.:wink:

Un-handled events are not blocked, so Note Off is not blocked by the scriptlet, as I am paranoid about stuck notes!!

I have now also added a manual reset mechanism so that the counters can be reset via a widget in rehearsals without skipping out of the rackspace. So this is the final code, just incase someone finds it useful.

// Block Note On events until a trigger note 
// has been played a number of times
var note ("Note to use as trigger") : Parameter 0..127 = 0
    count ("Active on hit") : Parameter 0..16 = 0
    reset ("Reset the counter") : Parameter 0..1 = 0

var counter : Integer = 0

// Called automatically after script is loaded
Initialization
    SetInfoMessage("Blocks the Note On messages from flowing. "+
                    "Specify the MIDI note number to use as a trigger " + 
                    "and the number of trigger hits to remove the block.")
    counter = 0
    SetDisplayMessage("Initialise")
End

// Reset the counter when selected
On Deactivate
    counter = 0
    SetDisplayMessage("Blocking "+ (count - 1 - counter))
End

// Called when a parameter value has changed
On ParameterValueChanged matching reset
    if reset <> 0 then
        reset = 0
        counter = 0
        SetDisplayMessage("Blocking "+ (count - 1 - counter))
    end
End


//Called when a NoteOn message is received
On NoteOnEvent(m : NoteMessage)
    var n : Integer = GetNoteNumber(m)
    if n== note then
        if counter < count then
            counter = counter +1        
            SetDisplayMessage("Blocking "+ (count - 1 - counter))
        end
        if counter == count then
            SetDisplayMessage("Active")
        end
    end
    
    if counter == count then
        SendNow(m)
    end
End


Then it is new or specific to Scriptlet. When I started scripting with GP I had the issue that I didn’t implement On NoteOffEvent while On NoteOnEvent was implemented. I had an issue and @dhj explained that if you implement On NoteOneEvent you also need On NoteOffEvent. So, I will have to check this again. :wink:

Thanks @David-san, I will keep an eye on this but so far it looks good. This is the output of the blocker. Showing two Note Offs and no Note Ons while blocking and the third and fourth Note Ons of the trigger note are passed through.

@David-san There is that special tickbox for “Block unhandled messages” :slight_smile:

1 Like

OK, I remember now. At the time where we had no Scriptlet but Rackspaces GPScript, when having a NoteOnEvent applying to a specific MIDI in block and catching the Note On messages, the Note Off messages where blocked. This is not due to the On NoteOffEvent not being implemented, but to GP internal NoteTrackers filtering out Note Off messages when the corresponding Note On message were not detected. So everything is fine with implementing On NoteOnEvent only :wink:

2 Likes