Created
February 6, 2024 23:32
-
-
Save vurpo/9cecfaef391a16ec3dedd0cfdd82f211 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
obs = obslua | |
hotkey_ids = {} | |
show_all_id = nil | |
sources = {} | |
function script_description() | |
local description = [[adds hotkeys to toggle sources]] | |
return description | |
end | |
function script_load(settings) | |
local scenes = obslua.obs_frontend_get_scene_names() | |
if scenes == nil or #scenes == 0 then | |
obslua.obs_frontend_add_event_callback( | |
function(e) | |
if e == obslua.OBS_FRONTEND_EVENT_FINISHED_LOADING then | |
register_hotkeys(settings) | |
obslua.remove_current_callback() | |
end | |
end | |
) | |
else | |
register_hotkeys(settings) | |
end | |
end | |
function script_save(settings) | |
for i, hotkey_id in pairs(hotkey_ids) do | |
local hotkey_save_array = obslua.obs_hotkey_save(hotkey_id) | |
obslua.obs_data_set_array(settings, "jam_switch_"..i, hotkey_save_array) | |
obslua.obs_data_array_release(hotkey_save_array) | |
end | |
local hotkey_save_array = obslua.obs_hotkey_save(show_all_id) | |
obslua.obs_data_set_array(settings, "jam_show_all", hotkey_save_array) | |
obslua.obs_data_array_release(hotkey_save_array) | |
end | |
function register_hotkeys(settings) | |
local current_scene_as_source = obs.obs_frontend_get_current_scene() | |
if current_scene_as_source then | |
local current_scene = obs.obs_scene_from_source(current_scene_as_source) | |
sources = {} | |
for i=1,100 do | |
local scene_item = obs.obs_scene_find_source_recursive(current_scene, tostring(i)) | |
if scene_item then | |
table.insert(sources, i) | |
hotkey_ids[i] = obslua.obs_hotkey_register_frontend( | |
"jam_switch_"..i, | |
"Switch to "..i, | |
function(pressed) | |
if not pressed then | |
return | |
end | |
for j=1,#sources do | |
local scene_item = obs.obs_scene_find_source_recursive(current_scene, tostring(sources[j])) | |
if scene_item and sources[j] == i then | |
obs.obs_sceneitem_set_visible(scene_item, true) | |
elseif scene_item then | |
obs.obs_sceneitem_set_visible(scene_item, false) | |
end | |
end | |
end | |
) | |
local hotkey_save_array = obslua.obs_data_get_array(settings, "jam_switch_"..i) | |
obslua.obs_hotkey_load(hotkey_ids[i], hotkey_save_array) | |
obslua.obs_data_array_release(hotkey_save_array) | |
end | |
end | |
show_all_id = obslua.obs_hotkey_register_frontend( | |
"jam_show_all", | |
"Show all", | |
function(pressed) | |
if not pressed then | |
return | |
end | |
for j=1,#sources do | |
local scene_item = obs.obs_scene_find_source_recursive(current_scene, tostring(sources[j])) | |
if scene_item then | |
obs.obs_sceneitem_set_visible(scene_item, true) | |
end | |
end | |
end | |
) | |
local hotkey_save_array = obslua.obs_data_get_array(settings, "jam_show_all") | |
obslua.obs_hotkey_load(show_all_id, hotkey_save_array) | |
obslua.obs_data_array_release(hotkey_save_array) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment