Skip to content

Instantly share code, notes, and snippets.

@insin
Created April 23, 2020 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insin/a376b2fb52566a3e0ddf20255ac1c2d0 to your computer and use it in GitHub Desktop.
Save insin/a376b2fb52566a3e0ddf20255ac1c2d0 to your computer and use it in GitHub Desktop.
Repro of obs.obs_sceneitem_group_enum_items() bug
local obs = obslua
--- name of a scene item
local source_name = ''
--- get the name of the current scene
local function current_scene_name()
local source = obs.obs_frontend_get_current_scene()
local name = obs.obs_source_get_name(source)
obs.obs_source_release(source)
return name
end
--- find the named scene item
local function find_scene_item()
local source = obs.obs_get_source_by_name(current_scene_name())
if source then
local scene = obs.obs_scene_from_source(source)
obs.obs_source_release(source)
if scene then
local items = obs.obs_scene_enum_items(scene)
for _, item in ipairs(items) do
local item_source = obs.obs_sceneitem_get_source(item)
local item_name = obs.obs_source_get_name(item_source)
print(item_name)
if obs.obs_sceneitem_is_group(item) then
local group_items = obs.obs_sceneitem_group_enum_items(item)
for _, group_item in ipairs(group_items) do
local group_item_source = obs.obs_sceneitem_get_source(group_item)
local group_item_name = obs.obs_source_get_name(group_item_source)
print(group_item_name)
end
end
end
obs.sceneitem_list_release(items)
end
end
print(source_name..' not found')
scene_item = nil
return false
end
function script_description()
return [[Repro of obs.obs_sceneitem_group_enum_items() bug
Open a scene with a Group and select the name of a Source within it]]
end
function script_properties()
local props = obs.obs_properties_create()
local source = obs.obs_properties_add_list(
props,
'source',
'Source:',
obs.OBS_COMBO_TYPE_EDITABLE,
obs.OBS_COMBO_FORMAT_STRING)
for _, name in ipairs(get_source_names()) do
obs.obs_property_list_add_string(source, name, name)
end
return props
end
function script_update(settings)
source_name = obs.obs_data_get_string(settings, 'source')
find_scene_item()
end
--- gets a list of source names, sorted alphabetically
function get_source_names()
local sources = obs.obs_enum_sources()
local source_names = {}
if sources then
for _, source in ipairs(sources) do
-- exclude Desktop Audio and Mic/Aux by their capabilities
local capability_flags = obs.obs_source_get_output_flags(source)
if bit.band(capability_flags, obs.OBS_SOURCE_DO_NOT_SELF_MONITOR) == 0 and
capability_flags ~= bit.bor(obs.OBS_SOURCE_AUDIO, obs.OBS_SOURCE_DO_NOT_DUPLICATE) then
table.insert(source_names, obs.obs_source_get_name(source))
end
end
end
obs.source_list_release(sources)
table.sort(source_names, function(a, b)
return string.lower(a) < string.lower(b)
end)
return source_names
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment