Page 1 of 1

Scripting Question: Callbacks possible?

PostPosted: Thu Dec 02, 2021 3:41 pm
by SeldomSeenKid
Hi All,

Can I install callbacks in Lua or Python? I remember I read something about it in an old Fusion manual but I am still a bit confused about the difference between Fusion and "regular" scripting.
In an ideal world I would like to trigger a callback function whenever the playhead has moved...
... just dreaming :)

Re: Scripting Question: Callbacks possible?

PostPosted: Thu Dec 02, 2021 4:06 pm
by Andrew Hazelden
SeldomSeenKid wrote:Can I install callbacks in Lua or Python?


If you search on the Steakunderwater forum you will see several threads that discuss the revised way to use callbacks that was added by BMD in Fusion v8.2.1+ and Resolve Fusion page v15+. This functionality is implemented with an approach that is called events/actions inside of Fusion Standalone, and inside the Resolve Fusion page area.

A new callback is created by placing your Lua or Python code block inside a quoted text string that is saved in a text file with the .fu file extension. The structure of this file is known as a "Lua table" and it looks vaguely like a JSON file but is slightly different in formatting rules that can be read about in the Lua programming language manual.

That .fu file document is saved into your Fusion user prefs "Config" folder. This location is also known as "Config:/" in the relative filepath system in Fusion called the PathMap system.

The .fu files are scanned at startup of Fusion so you need to relaunch Fusion or Resolve for your most recent .fu edits to be activated. You can make your own sub-folders inside the "Config:/" PathMap folder to categorize your custom .fu based events/actions/hotkey bindings/custom Fusion Studio menu entries into their own tidy hierarchies.

There is also another variant on a .fu text file called a .zfu which is a store-compressed zip archive which holds the .fu file along with any companion resources like lua scripts (with UI Manager based GUIs defined), or custom icons you want, etc. These resources are placed side-by-side in the root level of zip file, typically with no sub-folders wrapping the content. There is a syntax you use when running scripts and accessing resources from inside this zipped archive which is described on the Steakunderwater forum posts about events/actions.

Good Luck!

Re: Scripting Question: Callbacks possible?

PostPosted: Thu Dec 02, 2021 9:59 pm
by SeldomSeenKid
Wow! Thank you a lot for this in depth description. Now I know where to start my descent into this snakepit...

But one more question: Do you know if this callback mechanism only works in the Fusion tab?

I just started to get my head around the scripting in DVR and I am still unsure about what works where. I know DVR since version 16 and it looks like the scripting engine was primarily designed for fusion and is now getting a more general role.

Re: Scripting Question: Callbacks possible?

PostPosted: Thu Dec 02, 2021 10:03 pm
by Andrew Hazelden
SeldomSeenKid wrote:Do you know if this callback mechanism only works in the Fusion tab?


If you look in the Resolve Developer documentation notes that were installed automatically on your hard disk by Resolve's installer, you could explore the "Delivery page encoder plugin" system, and the Resolve native "Workflow Integration" scripting system.

Alternatively, you could have an external script running in Resolve Studio that would probe the Resolve API on a fixed timer to query the status of settings.

Re: Scripting Question: Callbacks possible?

PostPosted: Thu Dec 02, 2021 10:30 pm
by Igor Riđanović
I'm currently using the movement of the playhead as one of the criteria to determine if Resolve is in use. There is a fundamental difference in how this works across the Resolve's pages. In the edit page the return is blocked. It doesn't report the timecode until the playback is stopped. In color and deivery pages the return is not blocked regardless if the timeline is playing back or not.

Re: Scripting Question: Callbacks possible?

PostPosted: Thu Dec 02, 2021 11:44 pm
by SeldomSeenKid
In Fairlight it is also not blocked. I wonder if the blocking in EDIT is by accident or by intention.
I am looking for an elegant way to update the timecode display on my midi controller. Currently I am running an infinite loop in a lua script reading the timecode and pushing it through a midi channel.
Problem is that this approach is wasting CPU cycles even if it is on standby. A callback like "OnTimecodeChange" would be much more elegant.
As mentioned above with my approach I also discovered that no TC updates happen on the EDIT page and I decided to live with it... Will examine the callback thingy and see if it saves some computation time.

Re: Scripting Question: Callbacks possible?

PostPosted: Fri Dec 03, 2021 8:47 pm
by Igor Riđanović
I don't know if it's accidental. The TCP/IP control protocol works the same way like the API. I have an Android controller that reads the timecode when it can. When it can't it just freerolls the numbers. Kind of how the timecode jam sync works it you're familiar with that. It generally works fine. Even if it's several frames off the user can't see that in real time. Once the playback is stopped the timecode display in the app is updated with the accurate timecode.

Re: Scripting Question: Callbacks possible?

PostPosted: Tue Dec 07, 2021 9:07 am
by SeldomSeenKid
Very clever. It reminds me of my old days when we were developing multi-player networks for gaming 8-) . Synchronizing the network time uses techniques like the one you're using.
I don't know if I will put this much effort into it but will keep it in the back of my head.
Currently I am requesting the TC in a LUA script and if a digit has changed, I send it through midi to my controller so there is no instance to do the sync.