-
Notifications
You must be signed in to change notification settings - Fork 45
/
source-cycler.lua
138 lines (124 loc) · 4.9 KB
/
source-cycler.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
obs = obslua
source_name = ""
visible_index = 1
hotkey_id = obs.OBS_INVALID_HOTKEY_ID
hotkey2_id = obs.OBS_INVALID_HOTKEY_ID
function group_loop_step_button_clicked(props, p)
group_loop_step(true)
return false
end
function group_loop_step(pressed)
if pressed then
group_loop(1)
end
end
function group_loop_back_button_clicked(props, p)
group_loop_back(true)
return false
end
function group_loop_back(pressed)
if pressed then
group_loop(-1)
end
end
function group_loop(diff)
local scenes = obs.obs_frontend_get_scenes()
if scenes ~= nil then
for _, scenesource in ipairs(scenes) do
local scenename = obs.obs_source_get_name(scenesource)
local scene = obs.obs_scene_from_source(scenesource)
local sceneitems = obs.obs_scene_enum_items(scene)
local maxindex = 0
local index = 1
for i, sceneitem in ipairs(sceneitems) do
if scenename == source_name then
obs.obs_sceneitem_set_visible(sceneitem, index == visible_index)
maxindex = index
index = index + 1
else
local source = obs.obs_sceneitem_get_source(sceneitem)
local sourcename = obs.obs_source_get_name(source)
if sourcename == source_name then
local group = obs.obs_group_from_source(source)
local groupitems = obs.obs_scene_enum_items(group)
for j, groupitem in ipairs(groupitems) do
obs.obs_sceneitem_set_visible(groupitem, index == visible_index)
maxindex = index
index = index + 1
end
visible_index = visible_index + 1
if visible_index > maxindex then
visible_index = 1
end
end
end
end
obs.sceneitem_list_release(sceneitems)
if scenename == source_name then
visible_index = visible_index + diff
if visible_index > maxindex then
visible_index = 1
elseif visible_index < 1 then
visible_index = maxindex
end
end
end
obs.source_list_release(scenes)
--obs.obs_frontend_source_list_free(scenes)
end
end
function script_properties()
local props = obs.obs_properties_create()
local p = obs.obs_properties_add_list(props, "source", "Group Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
local sources = obs.obs_enum_sources()
if sources ~= nil then
for _, source in ipairs(sources) do
source_id = obs.obs_source_get_id(source)
if source_id == "group" then
local name = obs.obs_source_get_name(source)
obs.obs_property_list_add_string(p, name, name)
end
end
obs.source_list_release(sources)
end
local scenes = obs.obs_frontend_get_scene_names()
if scenes ~= nil then
for _, scene in ipairs(scenes) do
obs.obs_property_list_add_string(p, scene, scene)
end
end
obs.obs_properties_add_button(props, "step_button", "Step loop", group_loop_step_button_clicked)
obs.obs_properties_add_button(props, "back_button", "Back loop", group_loop_back_button_clicked)
return props
end
function script_description()
return "Sets a group source to act as a visibility loop"
end
function script_update(settings)
local sn = obs.obs_data_get_string(settings, "source")
if source_name ~= sn then
obs.obs_hotkey_unregister(group_loop_step)
source_name = sn
hotkey_id = obs.obs_hotkey_register_frontend("group_loop_step_" .. sn, "Group Loop " .. sn, group_loop_step)
local hotkey_save_array = obs.obs_data_get_array(settings, "group_loop_hotkey")
obs.obs_hotkey_load(hotkey_id, hotkey_save_array)
obs.obs_data_array_release(hotkey_save_array)
hotkey2_id = obs.obs_hotkey_register_frontend("group_loop_back_" .. sn, "Group Back " .. sn, group_loop_back)
hotkey_save_array = obs.obs_data_get_array(settings, "group_loop_hotkey2")
obs.obs_hotkey_load(hotkey2_id, hotkey_save_array)
obs.obs_data_array_release(hotkey_save_array)
end
end
function script_defaults(settings)
end
function script_save(settings)
local hotkey_save_array = obs.obs_hotkey_save(hotkey_id)
obs.obs_data_set_array(settings, "group_loop_hotkey", hotkey_save_array)
obs.obs_data_array_release(hotkey_save_array)
hotkey_save_array = obs.obs_hotkey_save(hotkey2_id)
obs.obs_data_set_array(settings, "group_loop_hotkey2", hotkey_save_array)
obs.obs_data_array_release(hotkey_save_array)
end
function script_load(settings)
script_update(settings)
end