2018-11-11 15:26:50 -05:00
|
|
|
ardour {
|
|
|
|
["type"] = "EditorHook",
|
|
|
|
name = "Periodically Save Snapshot",
|
|
|
|
author = "Ardour Lua Task Force",
|
2020-04-23 23:47:02 -04:00
|
|
|
description = "Save a session-snapshot periodically (every 15mins) named after the current date-time",
|
2018-11-11 15:26:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
-- subscribe to signals
|
|
|
|
-- http://manual.ardour.org/lua-scripting/class_reference/#LuaSignal.LuaSignal
|
|
|
|
function signals ()
|
2018-11-16 18:13:12 -05:00
|
|
|
return LuaSignal.Set():add ({[LuaSignal.LuaTimerS] = true})
|
2018-11-11 15:26:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
-- create callback function
|
|
|
|
function factory ()
|
|
|
|
local _last_snapshot_time = 0 -- persistent variable
|
2018-11-11 19:58:12 -05:00
|
|
|
local _snapshot_interval = 60 * 15 -- 15 minutes
|
2018-11-11 15:26:50 -05:00
|
|
|
|
|
|
|
-- callback function which invoked when signal is emitted, every 100ms
|
|
|
|
return function (signal, ref, ...)
|
|
|
|
|
|
|
|
local now = os.time (); -- unix-time, seconds since 1970
|
|
|
|
|
|
|
|
-- skip initial save when script is loaded
|
|
|
|
if (_last_snapshot_time == 0) then
|
|
|
|
_last_snapshot_time = now;
|
|
|
|
end
|
|
|
|
|
|
|
|
-- every 15 mins
|
2018-11-11 19:58:12 -05:00
|
|
|
if (now > _last_snapshot_time + _snapshot_interval) then
|
|
|
|
|
|
|
|
-- don't save while recording, may interfere with recording
|
|
|
|
if Session:actively_recording() then
|
|
|
|
-- queue 30 sec after rec-stop
|
|
|
|
_last_snapshot_time = now - _snapshot_interval + 30
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-11-11 15:26:50 -05:00
|
|
|
_last_snapshot_time = now
|
|
|
|
-- format date-time (avoid colon)
|
|
|
|
local snapshot_name = os.date ("%Y-%m-%d %H.%M.%S", now)
|
|
|
|
-- save session -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Session
|
|
|
|
Session:save_state ("backup " .. snapshot_name, false, false, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|