Scripting Question: Callbacks possible?

Get answers to your questions about color grading, editing and finishing with DaVinci Resolve.
  • Author
  • Message
Offline
User avatar

SeldomSeenKid

  • Posts: 391
  • Joined: Mon May 31, 2021 1:16 pm
  • Location: Germany
  • Real Name: Michael Adrian

Scripting Question: Callbacks possible?

PostThu Dec 02, 2021 3:41 pm

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 :)
Good judgement comes from experience. Experience comes from bad judgement.
# Threadripper 32 core / 160GB / RTX4000 8GB / WIN10 #
# BMCC / DVR17.4.6 Studio / Speed Editor / Tangent Ripple / X-Touch One / X-Touch mini / Space Explorer / 5.1 HDMI#
Offline
User avatar

Andrew Hazelden

  • Posts: 536
  • Joined: Sat Dec 06, 2014 12:10 pm
  • Location: West Dover, Nova Scotia, Canada

Re: Scripting Question: Callbacks possible?

PostThu Dec 02, 2021 4:06 pm

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!
Mac Studio M2 Ultra / Threadripper 3990X | Fusion Studio 18.6.4 | Kartaverse 6
Offline
User avatar

SeldomSeenKid

  • Posts: 391
  • Joined: Mon May 31, 2021 1:16 pm
  • Location: Germany
  • Real Name: Michael Adrian

Re: Scripting Question: Callbacks possible?

PostThu Dec 02, 2021 9:59 pm

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.
Good judgement comes from experience. Experience comes from bad judgement.
# Threadripper 32 core / 160GB / RTX4000 8GB / WIN10 #
# BMCC / DVR17.4.6 Studio / Speed Editor / Tangent Ripple / X-Touch One / X-Touch mini / Space Explorer / 5.1 HDMI#
Offline
User avatar

Andrew Hazelden

  • Posts: 536
  • Joined: Sat Dec 06, 2014 12:10 pm
  • Location: West Dover, Nova Scotia, Canada

Re: Scripting Question: Callbacks possible?

PostThu Dec 02, 2021 10:03 pm

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.
Mac Studio M2 Ultra / Threadripper 3990X | Fusion Studio 18.6.4 | Kartaverse 6
Offline
User avatar

Igor Riđanović

  • Posts: 1596
  • Joined: Thu Jul 02, 2015 5:11 am
  • Location: Los Angeles, Calif.

Re: Scripting Question: Callbacks possible?

PostThu Dec 02, 2021 10:30 pm

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.
www.metafide.com - DaVinci Resolve™ Apps
Offline
User avatar

SeldomSeenKid

  • Posts: 391
  • Joined: Mon May 31, 2021 1:16 pm
  • Location: Germany
  • Real Name: Michael Adrian

Re: Scripting Question: Callbacks possible?

PostThu Dec 02, 2021 11:44 pm

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.
Good judgement comes from experience. Experience comes from bad judgement.
# Threadripper 32 core / 160GB / RTX4000 8GB / WIN10 #
# BMCC / DVR17.4.6 Studio / Speed Editor / Tangent Ripple / X-Touch One / X-Touch mini / Space Explorer / 5.1 HDMI#
Offline
User avatar

Igor Riđanović

  • Posts: 1596
  • Joined: Thu Jul 02, 2015 5:11 am
  • Location: Los Angeles, Calif.

Re: Scripting Question: Callbacks possible?

PostFri Dec 03, 2021 8:47 pm

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.
www.metafide.com - DaVinci Resolve™ Apps
Offline
User avatar

SeldomSeenKid

  • Posts: 391
  • Joined: Mon May 31, 2021 1:16 pm
  • Location: Germany
  • Real Name: Michael Adrian

Re: Scripting Question: Callbacks possible?

PostTue Dec 07, 2021 9:07 am

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.
Good judgement comes from experience. Experience comes from bad judgement.
# Threadripper 32 core / 160GB / RTX4000 8GB / WIN10 #
# BMCC / DVR17.4.6 Studio / Speed Editor / Tangent Ripple / X-Touch One / X-Touch mini / Space Explorer / 5.1 HDMI#

Return to DaVinci Resolve

Who is online

Users browsing this forum: Bing [Bot], naviajoana, Shrinivas Ramani, Steve Alexander, Zanshin and 167 guests