Skip to content

Instantly share code, notes, and snippets.

@KMConner
Created April 15, 2020 22:16
Show Gist options
  • Save KMConner/9550533f8109ec69d3f0d42a27fcf72c to your computer and use it in GitHub Desktop.
Save KMConner/9550533f8109ec69d3f0d42a27fcf72c to your computer and use it in GitHub Desktop.
When a specified source is shown, the specifed scene will appear within the specied duration.
obs = obslua
showing_slide = false
slide_name_from = ""
slide_name_to = ""
duration_ms = 1000000
function scene_active_from_name(name)
local sceneSources = obs.obs_enum_sources()
local ret = false
for _, sceneSource in ipairs(sceneSources) do
local active = obs.obs_source_active(sceneSource)
local scene_name = obs.obs_source_get_name(sceneSource)
if active and scene_name == name then
ret = true
break
end
end
obs.source_list_release(sceneSources)
return ret
end
function find_source_by_name_in_list(source_list, name)
for i, source in pairs(source_list) do
local source_name = obs.obs_source_get_name(source)
if source_name == name then
return source
end
end
return nil
end
function activate_scene(switch_scene_name)
local scenes = obs.obs_frontend_get_scenes()
local switch_scene = find_source_by_name_in_list(scenes, switch_scene_name)
if switch_scene ~= nil then
obs.obs_frontend_set_current_scene(switch_scene)
end
obs.source_list_release(scenes)
end
function transition_timer_tick()
obs.remove_current_callback()
if not scene_active_from_name(slide_name_from) then
return
end
activate_scene(slide_name_to)
end
function source_activated(cd)
local source = obs.calldata_source(cd, "source")
if source == nil then
return
end
if obs.obs_source_get_type(source) ~= obs.OBS_SOURCE_TYPE_INPUT then
return
end
if obs.obs_source_get_name(source) == slide_name_from then
obs.timer_add(transition_timer_tick, duration_ms)
end
end
function script_properties()
local props = obs.obs_properties_create()
local scenechoice_from = obs.obs_properties_add_list(props, "scenechoice", "Switch from scene", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
obs.obs_property_list_add_string(scenechoice_from, CURRENT_SCENE_OPTION, CURRENT_SCENE_OPTION)
local scenechoice_to = obs.obs_properties_add_list(props, "scenechoice2", "Switch to scene", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
obs.obs_property_list_add_string(scenechoice_to, CURRENT_SCENE_OPTION, CURRENT_SCENE_OPTION)
local sceneSources = obs.obs_frontend_get_scenes()
for _, sceneSource in ipairs(sceneSources) do
local name = obs.obs_source_get_name(sceneSource)
obs.obs_property_list_add_string(scenechoice_to, name, name)
end
obs.source_list_release(sceneSources)
local sources = obs.obs_enum_sources()
if sources ~= nil then
for _, source in ipairs(sources) do
local name = obs.obs_source_get_name(source)
obs.obs_property_list_add_string(scenechoice_from, name, name)
end
end
obs.source_list_release(sources)
obs.obs_properties_add_int(props, "duration", "Duration (ms)", 1, 1000000, 1)
return props
end
function script_description()
return "Sutomatic scene transition."
end
function script_load(settings)
local sh = obs.obs_get_signal_handler()
obs.signal_handler_connect(sh, "source_activate", source_activated)
end
function script_update(settings)
slide_name_from = obs.obs_data_get_string(settings,"scenechoice")
slide_name_to = obs.obs_data_get_string(settings,"scenechoice2")
duration_ms = obs.obs_data_get_int(settings,"duration")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment