Page 1 of 1

Playhead Lock on-off Lua Resolve Script

PostPosted: Wed Oct 16, 2024 4:02 pm
by DorinDXN
IMPORTANT!
Scripts with UI require Studio license since 19.1.
This script will work in the Free version of DaVinci Resolve only if DR is prior to 19.1



Use Cases Scenarios:
1) Playhead Lock when needed
Then:
2) When Locked, It acts like "Playhead Return" or "Stop and Go to Last Position" even in the Color Page:
a) Pressing space once will start playing; pressing space again will stop playing and return to the locked position.
or
b) JKL keys (Shuttle Controls) play as usual, but when stopped (K), the playhead will return to the locked position.

This is a Lua script for DaVinci Resolve (tested on DR 19.0.2 - the free one).
It creates a small on-top tool, movable, with a button to lock/unlock the playhead
- it is beta, might not work as expected but seems quite light and reliable on my early tests.

A short video about it is here:


Code: Select all
-- Playhead Lock ON-OFF Lua Resolve Script by DorinDXN
-- version 0.6 -- beta
-- license CC0
--
--[[
Save this file as:
Windows
C:\ProgramData\Blackmagic Design\DaVinci Resolve\Fusion\Scripts\Utility\DXN Playhead Lock ON-OFF.lua
Mac
/Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Scripts/Utility/DXN Playhead Lock ON-OFF.lua

then you can launch it using the menu:
Workspace \ Scripts \ DXN Playhead Lock ON-OFF
 --]]

local ui = fu.UIManager
local disp = bmd.UIDispatcher(ui)
local resolve = app:GetResolve()
local projectManager = resolve:GetProjectManager()
local project = projectManager:GetCurrentProject()
local timeline = project:GetCurrentTimeline()
if not timeline then
    print("No timeline is open.")
    return
end
local isPlayheadLocked = false
local lockedTimecode = timeline:GetCurrentTimecode()
local function lockPlayhead()
    if isPlayheadLocked then
        local currentPlayheadTimecode = timeline:GetCurrentTimecode()
        if currentPlayheadTimecode ~= lockedTimecode then
            timeline:SetCurrentTimecode(lockedTimecode)
        end
     end
end
local win = disp:AddWindow({
    ID = "Playhead",
    WindowTitle = "DXN Playhead Lock",
    Geometry = { 100, 100, 150, 50 },
     WindowFlags = {
            Tool = true,
            MSWindowsFixedSizeDialogHint = true
        },
    ui:VGroup {
        ID = "playground",
        ui:HGroup {
            Weight = 0,
            ui:Button { ID = "btnLock", Text = "PLAYHEAD FREE" },
        },
    },
})
local itm = win:GetItems()
function win.On.btnLock.Clicked(ev)
    if itm.btnLock.Text == "PLAYHEAD FREE" then
        itm.btnLock.Text = "PLAYHEAD LOCKED"
      lockedTimecode = timeline:GetCurrentTimecode()
        isPlayheadLocked = true
    else
        itm.btnLock.Text = "PLAYHEAD FREE"
        isPlayheadLocked = false
    end
end
local timer_func = {}
local timerPH = ui:Timer {
    ID = "TimerPH",
    Interval = 200,
    SingleShot = false
}
timer_func[timerPH.ID] = function()
    lockPlayhead()
end
function disp.On.Timeout(ev)
    timer_func[ev.who]()
end
function win.On.Playhead.Close(ev)
    disp:ExitLoop()
   timerPH:Stop()
end
win:Show()
timerPH:Start()
disp:RunLoop()
win:Hide()


cheers,
Dorin

Re: Playhead Lock ON-OFF Lua Resolve Script

PostPosted: Sat Feb 01, 2025 4:18 pm
by hyuston
Hello! Thank you for an amazing work!

I recently stared to use this script for grading multicam clips. And recognized that it don't work in multicam clips. Is there any possibity to modify this script to work in multicam clips?

It would be such a life saver

Re: Playhead Lock ON-OFF Lua Resolve Script

PostPosted: Wed Feb 19, 2025 7:21 am
by DorinDXN
Scripts with UI require Studio license since 19.1.
I can no longer run or test my scripts, so I have stopped scripting in Resolve.

cheers,
Dorin