On TimerTick

I’ve seen a few examples in the forums of people using an “On TimerTick” callback, but for the life of me I can’t find the documentation for it.

I’m sure I’m looking in the wrong place, but I am at Introduction to GPScript for Gig Performer 4 and I don’t get any search results for “TimerTick”, “timertick”, “timer”, or “tick”. I also scanned through the entire Callbacks chapter and didn’t find it.

Thanks in advance.

Yeah, it seems to be missing in the docs.

This is the most basic use of the callback I’ve found in the forum. You just need to start the timer with SetTimersRunning(true)

After that, the callback will be called every 50ms or so (can’t recall the exact timing)


Thanks! And is it advisable to turn it off when it’s not needed?

Every cpu cycle counts, so yes. Furthermore I would keep the processing in the timer as little as needed. As far as I can see, gpscript runs on the gui-thread (@dhj will know for sure) and there is only one. But you should not have sleepless nights about it :grinning:

1 Like

Yes, but this is a good advice for any other callback. :wink:

1 Like

I use it in a script and do quite some functionality inside, like checking peak values of sixteen channels and change widget properties based on it. Of course for a computer this is still not much.

Also the time is not exactly fifty seconds, as far as I can remember the time varies a lot.

You could also try to use a ramp callback which is more precise, but I haven’t tried that myself. This callback is useful when you need exact period callbacks.

The timer may stop (and not restart) when you open the options dialog (for instance to check midi ports or audio).

‘Recompile all scripts’ can resolve that, but that is not always desirable

No, it doesn’t.


That’s nice. Takes some burden away. :slightly_smiling_face:

1 Like

Note however, that certain functions require running on the GUI thread which is why there can be some asynchronous behavior

1 Like

What other Timer-related functions are still undocumented in Version 4.7?

The only functions that I have found in the documentation relating to timers are:

GetTimersRunning : Indicates whether global timers are running or stopped

SetTimersRunning : Start or stop the global timers

TimeSinceStartup : Gets the time since computer was started in milliseconds

Can I tell GP to call “On Timertick” every 10ms? For example, something like: “On Timertick(10)”?

If have found a function which goes great with “On Timertick”, and that is “TimeSinceStartup()”.

On TimerTick(ms : double)
  if NotesAreQueued() and TimeSinceStartup() > NoteReleaseAt then
end // On TimerTick

The timer tick callback is not intended for any kind of accurate timing, it’s really just intended for performing periodic non-critical activities.


Thanks David.

@pianopaul provided an eloquent solution to solving the problem of setting a timer and then getting a callback when that timer goes off. I am thinking that people reading this thread would like to see his solution:

1 Like

The only thing is that you are not satisfied with the TimerTick not being called every 10ms, but the solution you are trying to follow won’t necessary guaranty this. The MIDI note will indeed be sent after 10ms, but the MIDI callback need a little time to response to the MIDI event. The overall process will probably be close to 10ms, but no guaranty to have exactly 10ms.

That’s OK, because I can adjust the delay until I find the right combination. I am trying to catch a bunch of MIDI notes that are close together when they are played. If they are played within 10ms, I will consider them notes in a chord.

Have you looked into the NoteTracker functions? They could possibly help as well.

Note Tracker is the reason I want to access MIDI notes in a more primitive way. I have not been successful using NT in the past.

What was the issue?