made the whole plugin more efficient
Signed-off-by: Ebbe Baß <ebbe.bass>
This commit is contained in:
+52
-75
@@ -5,6 +5,7 @@
|
|||||||
local osc_config = 1
|
local osc_config = 1
|
||||||
local osc_template = 'SendOSC %i "/%s%i,i,%i"'
|
local osc_template = 'SendOSC %i "/%s%i,i,%i"'
|
||||||
local osc_str_template = 'SendOSC %i "/%s%i,s,%s"'
|
local osc_str_template = 'SendOSC %i "/%s%i,s,%s"'
|
||||||
|
local enabled = false
|
||||||
local debug = false
|
local debug = false
|
||||||
local executor_table = {
|
local executor_table = {
|
||||||
101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
|
101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
|
||||||
@@ -31,115 +32,91 @@ local color_map = {
|
|||||||
Timer = {103, 103, 110}
|
Timer = {103, 103, 110}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local cached_states = {}
|
||||||
|
|
||||||
function debug_print(msg)
|
function debug_print(msg)
|
||||||
if debug then
|
if debug then
|
||||||
Printf(msg)
|
Printf(msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tablelength(T)
|
|
||||||
local count = 0
|
|
||||||
for _ in pairs(T) do
|
|
||||||
count = count + 1
|
|
||||||
end
|
|
||||||
return count
|
|
||||||
end
|
|
||||||
|
|
||||||
function send_osc(etype, exec_no, value)
|
function send_osc(etype, exec_no, value)
|
||||||
local cmd_str = osc_template:format(osc_config, etype, exec_no, value)
|
local cache_key = etype .. exec_no
|
||||||
debug_print(cmd_str)
|
if cached_states[cache_key] ~= value then
|
||||||
Cmd(cmd_str)
|
cached_states[cache_key] = value
|
||||||
|
Cmd(osc_template:format(osc_config, etype, exec_no, value))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function to reset all button LEDs to off (set RGB to 0)
|
local function reset_all_leds()
|
||||||
function reset_all_leds()
|
cached_states = {}
|
||||||
for _, exec_no in ipairs(executor_table) do
|
for _, exec_no in ipairs(executor_table) do
|
||||||
send_osc("ExecCol_R", exec_no, 0)
|
send_osc("ExecCol_R", exec_no, 0)
|
||||||
send_osc("ExecCol_G", exec_no, 0)
|
send_osc("ExecCol_G", exec_no, 0)
|
||||||
send_osc("ExecCol_B", exec_no, 0)
|
send_osc("ExecCol_B", exec_no, 0)
|
||||||
|
if exec_no >= 191 and exec_no <= 298 then
|
||||||
-- If the executor is in the xKey range, clear the xKey label
|
|
||||||
if (exec_no >= 291 and exec_no <= 298) or (exec_no >= 191 and exec_no <= 198) then
|
|
||||||
Cmd(osc_str_template:format(osc_config, "xKey", exec_no, ""))
|
Cmd(osc_str_template:format(osc_config, "xKey", exec_no, ""))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
debug_print("All LEDs have been reset to off.")
|
debug_print("All LEDs have been reset.")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Reuse function to handle empty playback
|
local function handle_empty_playback(exec_no)
|
||||||
function handle_empty_playback(exec_no)
|
debug_print("Empty playback: " .. exec_no)
|
||||||
debug_print('Empty playback found on:' .. tostring(exec_no))
|
|
||||||
if (exec_no >= 291 and exec_no <= 298) or (exec_no >= 191 and exec_no <= 198) then
|
|
||||||
Cmd(osc_str_template:format(osc_config, "xKey", exec_no, ""))
|
|
||||||
end
|
|
||||||
send_osc("ExecCol_R", exec_no, 0)
|
send_osc("ExecCol_R", exec_no, 0)
|
||||||
send_osc("ExecCol_G", exec_no, 0)
|
send_osc("ExecCol_G", exec_no, 0)
|
||||||
send_osc("ExecCol_B", exec_no, 0)
|
send_osc("ExecCol_B", exec_no, 0)
|
||||||
|
if exec_no >= 191 and exec_no <= 198 or exec_no >= 291 and exec_no <= 298 then
|
||||||
|
local label = ""
|
||||||
|
if cached_states["xKey" .. exec_no] ~= label then
|
||||||
|
cached_states["xKey" .. exec_no] = label
|
||||||
|
Cmd(osc_str_template:format(osc_config, "xKey", exec_no, label))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function poll(exec_no)
|
local function poll(exec_no, appearances)
|
||||||
local exec = GetExecutor(exec_no)
|
local exec = GetExecutor(exec_no)
|
||||||
local execAssObjNoClass = exec and exec:GetAssignedObj()
|
local execObj = exec and exec:GetAssignedObj()
|
||||||
|
|
||||||
if not execAssObjNoClass then
|
if not execObj then
|
||||||
handle_empty_playback(exec_no)
|
handle_empty_playback(exec_no)
|
||||||
else
|
return
|
||||||
-- Extract object appearance and class
|
end
|
||||||
local execAssObj = execAssObjNoClass:GetClass()
|
|
||||||
local colors = color_map[execAssObj] or {0, 0, 0} -- fallback colors
|
|
||||||
|
|
||||||
-- Check if assObjApp exists and is valid
|
|
||||||
local assObjApp = execAssObjNoClass:Get("Appearance")
|
|
||||||
if assObjApp then
|
|
||||||
-- Make sure assObjApp is valid and is a string, then remove "Appearance " prefix
|
|
||||||
assObjApp = tostring(assObjApp):gsub("Appearance ", "")
|
|
||||||
local app_id = tonumber(assObjApp) -- Convert the string to a number after cleanup
|
|
||||||
|
|
||||||
-- Ensure app_id is valid and the appearance exists in ShowData
|
local execClass = execObj:GetClass()
|
||||||
if app_id and ShowData().Appearances[app_id] then
|
local colors = color_map[execClass] or {0, 0, 0}
|
||||||
local app_data = ShowData().Appearances[app_id]
|
|
||||||
colors = {tonumber(app_data.BackR), tonumber(app_data.BackG), tonumber(app_data.BackB)}
|
local appearance = execObj:Get("Appearance")
|
||||||
else
|
local app_id = appearance and tonumber(tostring(appearance):match("%d+"))
|
||||||
-- If app_id is invalid, fallback to default colors
|
|
||||||
colors = {0, 0, 0}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Send colors through OSC
|
if app_id and appearances[app_id] then
|
||||||
send_osc("ExecCol_R", exec_no, colors[1])
|
local app_data = appearances[app_id]
|
||||||
send_osc("ExecCol_G", exec_no, colors[2])
|
colors = {tonumber(app_data.BackR), tonumber(app_data.BackG), tonumber(app_data.BackB)}
|
||||||
send_osc("ExecCol_B", exec_no, colors[3])
|
end
|
||||||
|
|
||||||
-- Handle special xKey case
|
send_osc("ExecCol_R", exec_no, colors[1])
|
||||||
if (exec_no >= 291 and exec_no <= 298) or (exec_no >= 191 and exec_no <= 198) then
|
send_osc("ExecCol_G", exec_no, colors[2])
|
||||||
local exec_label = execAssObjNoClass:Get("Name")
|
send_osc("ExecCol_B", exec_no, colors[3])
|
||||||
Cmd(osc_str_template:format(osc_config, "xKey", exec_no, exec_label))
|
|
||||||
|
if exec_no >= 191 and exec_no <= 198 or exec_no >= 291 and exec_no <= 298 then
|
||||||
|
local label = execObj:Get("Name") or ""
|
||||||
|
if cached_states["xKey" .. exec_no] ~= label then
|
||||||
|
cached_states["xKey" .. exec_no] = label
|
||||||
|
Cmd(osc_str_template:format(osc_config, "xKey", exec_no, label))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function callback()
|
local function main()
|
||||||
for i=1, tablelength(executor_table) do
|
enabled = not enabled
|
||||||
poll(executor_table[i])
|
|
||||||
end
|
|
||||||
debug_print("Updated")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Get the handle to this Lua component.
|
|
||||||
local luaComponentHandle = select(4,...)
|
|
||||||
|
|
||||||
function main()
|
|
||||||
reset_all_leds()
|
reset_all_leds()
|
||||||
callback()
|
local appearances = ShowData().Appearances
|
||||||
-- Setup hooks for all executors
|
while enabled do
|
||||||
local pluginHandle = luaComponentHandle:Parent()
|
for _, exec_no in ipairs(executor_table) do
|
||||||
|
poll(exec_no, appearances)
|
||||||
local hookedObj = DataPool().Pages
|
end
|
||||||
HookObjectChange(callback, hookedObj, pluginHandle)
|
end
|
||||||
debug_print("Hooking changes to pages.")
|
|
||||||
local hookedObj = DataPool().Sequences
|
|
||||||
HookObjectChange(callback, hookedObj, pluginHandle)
|
|
||||||
debug_print("Hooking changes to sequences.")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return main
|
return main
|
||||||
Reference in New Issue
Block a user