-
Notifications
You must be signed in to change notification settings - Fork 85
/
SourceStatusMonitor.lua
1641 lines (1464 loc) · 48.1 KB
/
SourceStatusMonitor.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
----------------------------------------------------------
Open Broadcaster Software®️
OBS > Tools > Scripts
@midnight-studios
Source Monitor
----------------------------------------------------------
]]
--Globals
obs = obslua
gversion = 0.7
luafileTitle = "Source Status Monitor"
luafile = "SourceStatusMonitor.lua"
obsurl = "audio-status-monitor.1381/"
script_settings = nil
active_color = 0xFF0FF781
inactive_color = 0xFF3838FF
active_font = 0xFF0B0E10
inactive_font = 0xFF0B0E10
mode = ""
monitor_state = false
-- global context information
props = nil -- property
props_mode = nil -- property
props_monitor = nil -- property
props_scene = nil -- property
props_color = nil -- property
props_text = nil -- property
-- Add ',' if this list continues
source_id_whitelist = {}
icon="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAJ3klEQVR4nO2cCZAdRRnH/5uAkGQhIQi4JAExRBFmTAhR8CBKiphECYgYNYSyHMuKFfACj8ITxKwHVCEogkIVg4ASAkaMgiEqSoFIVHDDTKFACLIeUQ5NxGxYcllf8u+tb3vnem/nbWaW/lVtvfdmpnt6+uv+ru5ZOBwOh8PhcDgcDofD4XA4HA6Hw+FwOByOFzFt+tF37tyJW044oW69cRAAH0AHgG4AXQCeq0C7CrHg/vt3XdbWtlsUe1W8vWlI6xcAOBvAiQBGqOu2AfglgG8CuKNazc5nxGAr2AO8jB1+M4A3JzyDDLI5AG4H8BMA4+r0cHUTyBEAfgPgpILXnwLgbqq1WlAngewL4EcAXtFgudcAWAZgZIvaVSp1EshnAUxtsuws2pvKUxeBHAjg3EHW8XkA7SW1p2XURSDvLaEzDwbw7pLa0zLqIpCFJdWzoKR6WkYdBCIzo6xo9U1VN+51EMjRJXaiCPeVJdXVEuogkJeUXF+lDXsdBLJfyfXtU3J9pVIHgZTdxrJnXKnUQSBjSq5vVMn1lUodBFLXjHRT1DHbO6xxAqkYTiAVwwmkYjiBVIx+AmlvL9vDdOQhfa77vZBLGcSRpBsmD5EL+nTo+d1DcJ9dBHF02B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+9Pyi+tpmFIOuQgY9peGnUhcbf10M/rncMFC0jg6qQOO1vdDE5g1NOxOHm4oX6dcecXV/wXp846kZgaTty/o4P+8O4mhuyjV5bBmMMLDbnqzkGoQJ2iRv9ngQRxcGcXRoVlnZkRjE0VKqPiMMyR2dPghhmDqaFYbkyH7O1Mri0PMHZJ6TVJZhFgOd0QwYM41UCYi3c2tKNdPp4+tVuu10QtZQn29koDVZJQL1gHuYsUeakzG/xbtlOhjFixP0QQDX6ZNmhmQlF+/iborrGJt0tLCxyNlf+yA9pvO4VnEA1caJCalym2eZPr80YTVSM5HeUSvppjFfmXaPrBliGEF/udUv3N9bIPcDpqrP4Br2DKb49YrcDrqkv+cMX1FwGfhYa828THoZO61OW0JONeo15RqqgW9bq5q1Ic+o1w0zQ2r/PMNFIJX+7wyN4F5pqxhOIBXDCaRiOIFUDCeQilGHf+yyb4H/4GOSj/voXYAp9GRsJ93j1CEwPJ/7a8vibL7pVSmGW2A4bKiDylrFjQplce+efRyHw+FwOBwOh8PhcDgcDofD4XA4HA6Hw+FIBMD/AW9OQDhrU/ZXAAAAAElFTkSuQmCC"
desc = [[
<hr/><center><h2>]] .. luafileTitle ..[[</h2>(Version: %s)</center>
<br><center><img width=50 height=50 src=']] .. icon .. [['/></center>
<br><center><a href="https://github.com/midnight-studios/obs-lua/blob/main/]] .. luafile ..[[">Find it on GitHub</a></center>
<br><p>Select an Item to minitor</p>
<p>Create a <b>New Scene</b> and add the following:
<ol>
<li><tt>`Colour Source`</tt></li>
<li><tt>`Text Source`</tt></li>
</ol></p>
<p>Add The New Scene to a new Source dock.</p>
<b>Dependencies</b>
<ol>
<li><a href="https://obsproject.com/forum/resources/source-dock.1317//">Source Dock</a></li><br></li>
</ol>
<p>Find help on the <a href="https://obsproject.com/forum/resources/]] .. obsurl ..[[">OBS Forum Thread</a>.</p>
<p><hr/></p>]]
--[[
--------------------------------------------------------------------
custom function:helper
-- If testing and log event writing is needed
----------------------------------------------------------
]]
local function log( name, msg )
if msg ~= nil then
msg = " > " .. tostring( msg )
else
msg = ""
end
obs.script_log( obs.LOG_DEBUG, name .. msg )
end
--[[
--------------------------------------------------------------------
script_description()
--------------------------------------------------------------------
this let OBS know this is a script
--------------------------------------------------------------------
]]
function script_description()
return string.format( desc, tostring( gversion ) )
end
--[[
--------------------------------------------------------------------
custom function:helper
set source visibility
----------------------------------------------------------
]]
function set_visible( target_name, visible )
--[[
Get Scene list, check scene items recursively for a match
Documentation suggets to release with 'obs_frontend_source_list_free',
but it does not work here, instead release with 'source_list_release'
]]
local scenes = obs.obs_frontend_get_scenes() -- incremented scenes. Release with source_list_release
--[[
Found Scene Sources (Scenes)
]]
if scenes ~= nil then
--[[
Check scene source one by one
]]
for _, scn in ipairs(scenes) do
--[[
get scene from source so that we can look at scene items
]]
local scene = obs.obs_scene_from_source( scn ) -- Does not increase the reference
--[[
Check recursively to include any groups in scenes
]]
local sceneitem = obs.obs_scene_find_source_recursive( scene, target_name )
--[[
Found what we are looking for:
]]
if sceneitem ~= nil then
--[[
Set item visibility
]]
obs.obs_sceneitem_set_visible( sceneitem, visible )
--[[
we found the target, break out the loop
]]
break
end
end --end for
--[[
Frees allocated memory
]]
obs.bfree( scn )
--[[
Documentation suggets to release with 'obs_frontend_source_list_free',
but it does not work here, instead release with 'source_list_release'
]]
obs.source_list_release( scenes )
end
end
--[[
--------------------------------------------------------------------
custom function: helper
--------------------------------------------------------------------
Check if a value exist in table
returns: boolean (bool)
--------------------------------------------------------------------
]]
function in_table( tbl, value )
local found = false
for k, v in pairs( tbl ) do
if value == v then
found = true
break
end
end
return found
end
--[[
--------------------------------------------------------------------
custom function
--------------------------------------------------------------------
Sets Scene Item Settings for the Status Source
--------------------------------------------------------------------
]]
function set_color_bounds( settings )
--[[
Monitor scene is where status results are sent
]]
monitor_scene = obs.obs_data_get_string( settings, "monitor_scene" )
--[[
Get Source for Monitor scene.
We want the Video Frame Size: Width and Height
to set the child elements (Scene Items) to match.
]]
source = obs.obs_get_source_by_name( monitor_scene ) -- Increments the source reference counter, use obs_source_release() to release it when complete.
--[[
Found Source:
]]
if source ~= nil then
--[[
Fetch parent current Settings: Width
]]
scene_width = obs.obs_source_get_width( source )
--[[
Fetch parent current Settings: Height
]]
scene_height = obs.obs_source_get_height( source )
--[[
We're done, release referrence
]]
obs.obs_source_release( source )
--[[
Lets apply the Width and Height to the 'Text Source'
We do this so that we can fill the frame with the color
Get the Source Name as defined by user in Script Settings
]]
text_source = obs.obs_data_get_string( settings, "color_source" )
--[[
Sources have unique names
Load the Source, from the Name
]]
source = obs.obs_get_source_by_name( text_source ) -- Increments the source reference counter, use obs_source_release() to release it when complete.
--[[
Found Source:
]]
if source ~= nil then
--[[
Fetch the Source settings so we can edit them
]]
local source_settings = obs.obs_source_get_settings( source)
--[[
Set width from previously retrieved scene width
]]
obs.obs_data_set_int( source_settings, "width", scene_width )
--[[
Set width from previously retrieved scene height
]]
obs.obs_data_set_int( source_settings, "height", scene_height )
--[[
All set, send the updated settings
]]
obs.obs_source_update( source, source_settings )
--[[
We are done with the source settings,
let's release the referrence
]]
obs.obs_data_release( source_settings )
end
--[[
We are done with the source,
let's release the referrence
]]
obs.obs_source_release( source )
end
end
--[[
--------------------------------------------------------------------
custom function
--------------------------------------------------------------------
--------------------------------------------------------------------
]]
function set_text_bounds( settings )
--[[
Monitor scene is where status results are sent
]]
monitor_scene = obs.obs_data_get_string( settings, "monitor_scene" )
--[[
Get Source for Monitor scene.
We want the Video Frame Size: Width and Height
to set the child elements (Scene Items) to match.
]]
source = obs.obs_get_source_by_name( monitor_scene ) -- Increments the source reference counter, use obs_source_release() to release it when complete.
--[[
Found Source:
]]
if source ~= nil then
--[[
Fetch parent current Settings: Width
]]
scene_width = obs.obs_source_get_width( source )
--[[
Fetch parent current Settings: Height
]]
scene_height = obs.obs_source_get_height( source )
--[[
We're done, release referrence
]]
obs.obs_source_release( source )
--[[
Lets apply the Width and Height to the 'Text Source'
We do this so that we can center the text properly
Get the Source Name as defined by user in Script Settings
]]
text_source = obs.obs_data_get_string( settings, "text_source" )
--[[
Sources have unique names
Load the Source, from the Name
]]
source = obs.obs_get_source_by_name( text_source ) -- Increments the source reference counter, use obs_source_release() to release it when complete.
--[[
Found Source:
]]
if source ~= nil then
--[[
Fetch the Source settings so we can edit them
]]
local source_settings = obs.obs_source_get_settings( source )
--[[
set text bounds width
]]
obs.obs_data_set_int( source_settings, "extents_cx", scene_width )
--[[
set text bounds height
]]
obs.obs_data_set_int( source_settings, "extents_cy", scene_height )
--[[
Use extends
]]
obs.obs_data_set_bool( source_settings, "extents", true )
--[[
set text wrap
]]
obs.obs_data_set_bool( source_settings, "extents_wrap", true )
--[[
set text antialiasing
]]
obs.obs_data_set_bool( source_settings, "antialiasing", true )
--[[
text align horizontal
]]
obs.obs_data_set_string( source_settings, "align", "center" )
--[[
text align verticle
]]
obs.obs_data_set_string( source_settings, "valign", "center" )
--[[
All set, send the updated settings
]]
obs.obs_source_update( source, source_settings )
--[[
We are done with the source settings,
let's release the referrence
]]
obs.obs_data_release( source_settings )
end
--[[
we are done with the source, let's release the referrence
]]
obs.obs_source_release( source )
end
end
--[[
--------------------------------------------------------------------
custom function
--------------------------------------------------------------------
Update Source
--------------------------------------------------------------------
]]
function source_settings_update( a_settings )
if a_settings ~= nil then
script_settings = a_settings
end
--[[
exit her if script is disabled
]]
if obs.obs_data_get_bool( script_settings, "disable_script" ) then
return
end
--[[
]]
local color, text = nil, nil
--[[
]]
if monitor_state ~= nil then
--[[
]]
if monitor_state then
color_background = obs.obs_data_get_int( script_settings, "active_color" )
color_text = obs.obs_data_get_int( script_settings, "active_font" )
text = obs.obs_data_get_string( script_settings, "active_text" )
else
color_background = obs.obs_data_get_int( script_settings, "inactive_color" )
color_text = obs.obs_data_get_int( script_settings, "inactive_font" )
text = obs.obs_data_get_string( script_settings, "inactive_text" )
end
--[[
]]
if obs.obs_data_get_bool( script_settings, "include_name" ) then
text = name .. ' ' .. text .. ' '
end
--[[
]]
else
color_background = 0xFFFF9900
color_text = 0xFF0B0E10
text = "Source Not Defined"
end
--[[
]]
color_source = obs.obs_data_get_string( script_settings, "color_source" )
--[[
]]
text_source = obs.obs_data_get_string( script_settings, "text_source" )
--[[
]]
set_visible( color_source, true )
--[[
]]
set_visible( text_source, true )
--[[
Sources have unique names
Load the Source, from the Name
]]
source = obs.obs_get_source_by_name( color_source ) -- Increments the source reference counter, use obs_source_release() to release it when complete.
--[[
Found Source:
]]
if source ~= nil then
--[[
]]
local source_settings = obs.obs_source_get_settings( source )
--[[
]]
obs.obs_data_set_int( source_settings, "color", color_background )
--[[
]]
obs.obs_source_update( source, source_settings )
--[[
]]
obs.obs_data_release( source_settings )
end
--[[
we are done with the source, let's release the referrence
]]
obs.obs_source_release(source)
--[[
Sources have unique names
Load the Source, from the Name
]]
source = obs.obs_get_source_by_name( text_source ) -- Increments the source reference counter, use obs_source_release() to release it when complete.
--[[
Found Source:
]]
if source ~= nil then
--[[
]]
local source_settings = obs.obs_source_get_settings( source )
--[[
]]
obs.obs_data_set_string( source_settings, "text", text )
--[[
]]
obs.obs_data_set_int( source_settings, "color", color_text )
--[[
]]
obs.obs_source_update( source, source_settings )
--[[
]]
obs.obs_data_release( source_settings )
--[[
]]
end
--[[
]]
obs.obs_source_release( source )
end
--[[
--------------------------------------------------------------------
--------------------------------------------------------------------
--------------------------------------------------------------------
]]
function scene_items_by_scene_name( scene_name, source_id, prop_ref )
local enumerated = false
--[[
'source' selected to provide monitor information
Sources have unique names
Load the Source, from the Name
]]
local source = obs.obs_get_source_by_name( scene_name ) -- Increments the source reference counter, use obs_source_release() to release it when complete.
--[[
'source' selected to provide monitor information
]]
if source ~= nil then
--[[
]]
local scene = obs.obs_scene_from_source( source ) -- Does not increase the reference
--[[
]]
local sceneitems = obs.obs_scene_enum_items( scene ) -- Release with sceneitem_list_release()
--[[
selected 'scene' has scene items
]]
if sceneitems ~= nil then
--[[
cycle through scene items
]]
for key_sceneitem, value_sceneitem in pairs( sceneitems ) do
--[[
get source for current scene item
]]
local sceneitem_source = obs.obs_sceneitem_get_source( value_sceneitem ) -- Does not increment the reference
--[[
check if 'source' is 'group'
]]
local group = obs.obs_group_from_source( sceneitem_source ) -- Does not increase the reference
--[[
get 'source' name, id and display name
]]
local name = obs.obs_source_get_name( sceneitem_source )
local id = obs.obs_source_get_id( sceneitem_source )
local display_name = obs.obs_source_get_display_name( id )
--[[
if we find the source we want
add it to the list
match it with 'display name'
TODO> instead of checking this one by one, lets perhaps use a json object
NOTE: We use type_ID as this is not affected by language packs, display_name is dependent on language setting
]]
if id == source_id then
enumerated = true
obs.obs_property_list_add_string( prop_ref, name, name )
end
--[[
if 'source' is 'group', lets check the group items
]]
if group ~= nil then
--[[
load 'group' items
]]
local groupitems = obs.obs_scene_enum_items( group ) -- Release with sceneitem_list_release()
--[[
does 'group' have items?
]]
if groupitems ~= nil then
--[[
cycle through group items
]]
for key_groupitem, value_groupitem in pairs( groupitems ) do
--[[
get source for the current group item
]]
local groupitemsource = obs.obs_sceneitem_get_source( value_groupitem ) -- Does not increment the reference
--[[
get 'source' name, id and display name
]]
name = obs.obs_source_get_name( groupitemsource )
id = obs.obs_source_get_id( groupitemsource )
display_name = obs.obs_source_get_display_name( id )
--[[
if we find the source we want
add it to the list
match it with 'display name'
TODO> instead of checking this one by one, lets perhaps use a json object
NOTE: We use type_ID as this is not affected by language packs, display_name is dependent on language setting
]]
if id == source_id then
enumerated = true
obs.obs_property_list_add_string( prop_ref, name, name )
end
end -- end for
obs.sceneitem_list_release( groupitems ) -- release the reference of scene item list for groups
end
--obs.bfree(group)
end
end -- end for sceneitems
obs.sceneitem_list_release( sceneitems ) -- release the reference of scene items
end
else -- source == nil
end -- source ~= nil
--obs.bfree(scene)
obs.obs_source_release( source ) -- release reference to source [scene_name]
return enumerated
end
--[[
--------------------------------------------------------------------
custom function
--------------------------------------------------------------------
--------------------------------------------------------------------
]]
function update_properties_list_items(ref)
--[[
]]
if ref == "monitor_source" then
--[[
]]
obs.obs_property_list_clear( props_monitor )
--[[
]]
t_type = {"None"}
--[[
]]
for i,v in ipairs( t_type) do obs.obs_property_list_add_string( props_monitor, v, v ) end
--[[
build list
add to property
]]
local sources = obs.obs_enum_sources() -- Release with source_list_release().
--[[
]]
if sources ~= nil then
--[[
]]
for _, source in pairs( sources ) do
--[[
]]
local name = obs.obs_source_get_name( source )
--[[
]]
source_id = obs.obs_source_get_unversioned_id( source )
--[[
]]
if in_table( source_id_whitelist, source_id ) then
--[[
]]
obs.obs_property_list_add_string( props_monitor, name, name )
end
end
end
--[[
]]
obs.source_list_release( sources ) -- releases the references of source list
end
--[[
]]
if ref == "monitor_scene" then
--[[
]]
obs.obs_property_list_clear( props_scene )
--[[
]]
t_type = {"None"}
--[[
]]
for i,v in ipairs( t_type ) do obs.obs_property_list_add_string( props_scene, v, v ) end
--[[
build list
add to property
]]
local scenes = obs.obs_frontend_get_scene_names() -- The list is stored within one contiguous segment of memory, so freeing the returned pointer with bfree() will free the entire list
--[[
]]
if scenes ~= nil then
--[[
]]
for i, scene in ipairs( scenes ) do
--[[
]]
obs.obs_property_list_add_string( props_scene, scene, scene )
end
end
--[[
]]
obs.bfree( scene )
end
-- IMPORTANT: returns true to trigger refresh of the properties
return true
end
--[[
----------------------------------------------------------
Callback on property modification
----------------------------------------------------------
]]
function property_onchange( props, property, settings )
--[[
get mode for Monitor Type
use this here to determine visibility
for property list item
]]
mode = obs.obs_data_get_string( settings, "mode" )
prop_names = {
"monitor_source",
"monitor_scene",
"color_source",
"text_source",
"active_color",
"inactive_color",
"active_font",
"inactive_font",
"active_text",
"inactive_text",
"include_name",
}
--[[
]]
if mode ~= "select" then
for i,v in ipairs( prop_names ) do obs.obs_property_set_visible(obs.obs_properties_get( props, v ), true ) end
else
for i,v in ipairs( prop_names ) do obs.obs_property_set_visible(obs.obs_properties_get( props, v ), false ) end
return true
end
--[[
]]
monitor_source = obs.obs_data_get_string( script_settings, "monitor_source" )
if monitor_source == "None" then
monitor_state = nil
end
--[[
]]
mode_item_set_status()
source_settings_update()
--[[
define list that will show a property list item
if 'mode' is not in this list it will set visible to false
Set the Monitor Source List available only if one of the
options are selected
Audio Mute / Unmute types
"Input Audio Device", "Output Audio Device", "Browser Audio", "Capture Device Audio"
]]
local monitor_source_list = {
a = "Input Audio Device",
b = "Output Audio Device",
c = "Browser Audio",
d = "Capture Device Audio",
e = "Media State"
}
--[[
set visibility for property list item
]]
obs.obs_property_set_visible(obs.obs_properties_get( props, "monitor_source" ), in_table( monitor_source_list, mode ) )
--[[
]]
assign_whitelist()
--[[
build list
add to property
]]
update_properties_list_items("monitor_source")
--[[
get the value in property list item
]]
local monitor_scene = obs.obs_data_get_string( settings, "monitor_scene" )
--[[
get the value in property list item
]]
local color_source = obs.obs_properties_get( props, "color_source" )
--[[
get the value in property list item
]]
local text_source = obs.obs_properties_get( props, "text_source" )
--[[
if a 'scene' was defined to provide monitor information
]]
if monitor_scene ~= "None" then
--[[
clear property list item, rebuild from fresh
]]
obs.obs_property_list_clear( color_source )
obs.obs_property_list_clear( text_source )
--[[
nothing available for the list, instead of leaving it empty,
display a messasge to the user
]]
if not scene_items_by_scene_name( monitor_scene, "text_gdiplus_v2", text_source ) then
obs.obs_property_list_add_string( text_source, 'Nothing Available', 'none' )
end
--[[
nothing available for the list, instead of leaving it empty,
display a messasge to the user
]]
if not scene_items_by_scene_name( monitor_scene, "color_source_v3", color_source ) then
obs.obs_property_list_add_string( color_source, 'Nothing Available', 'none' )
end
end
-- IMPORTANT: returns true to trigger refresh of the properties
return true
end
--[[
--------------------------------------------------------------------
script_properties()
--------------------------------------------------------------------
Called to define user properties associated with the script.
These properties are used to define how to show settings
properties to a user.
Returns:
obs_properties_t object created via obs_properties_create().
--------------------------------------------------------------------
]]
function script_properties()
-- create new properties
props = obs.obs_properties_create()
local sources = obs.obs_enum_sources() -- Release with source_list_release().
--[[
new property item: list
Monitor Scene
Audio Mute / Unmute types
"Input Audio Device", "Output Audio Device", "Browser Audio", "Capture Device Audio"
]]
props_mode = obs.obs_properties_add_list( props, "mode", "<i>Monitor Mode</i>", obs.OBS_COMBO_TYPE_LIST, obs.OBS_COMBO_FORMAT_STRING )
t_type = {"Input Audio Device", "Output Audio Device", "Browser Audio", "Capture Device Audio", "Recording", "Streaming", "Media State"}
obs.obs_property_list_add_string(props_mode, "Select", "select")
obs.obs_property_set_long_description( props_mode, "\nWhat do you wish to monitor?\n" )
for i,v in ipairs( t_type ) do obs.obs_property_list_add_string( props_mode, v, v ) end
--[[
new property item: list
What do you want to monitor?
if not a source, then hide this list
]]
props_monitor = obs.obs_properties_add_list( props, "monitor_source", "<i>Monitor Source</i>", obs.OBS_COMBO_TYPE_LIST, obs.OBS_COMBO_FORMAT_STRING )
obs.obs_property_set_long_description( props_monitor, "\nThe actual Audio Source to watch\n" )
--[[
build list
add to property
]]
update_properties_list_items("monitor_source")
--[[
new property item: list
This is where we create the feedback
Monitor Scene
]]
props_scene = obs.obs_properties_add_list( props, "monitor_scene", "<i>Status Scene</i>", obs.OBS_COMBO_TYPE_LIST, obs.OBS_COMBO_FORMAT_STRING )
obs.obs_property_set_long_description( props_scene, "\nThe scene with sources to give feedback.\n" )
update_properties_list_items("monitor_scene")
--[[
new property item: list
]]
props_color = obs.obs_properties_add_list( props, "color_source", "<i>Colour Source</i>", obs.OBS_COMBO_TYPE_LIST, obs.OBS_COMBO_FORMAT_STRING )
t_type = {"None"}
for i,v in ipairs( t_type ) do obs.obs_property_list_add_string(props_color, v, v ) end
--[[
new property item: list
]]
props_text = obs.obs_properties_add_list( props, "text_source", "<i>Text Source</i>", obs.OBS_COMBO_TYPE_LIST, obs.OBS_COMBO_FORMAT_STRING )
t_type = {"None"}
for i,v in ipairs( t_type ) do obs.obs_property_list_add_string( props_text, v, v ) end
--[[
new property item: color
]]
obs.obs_properties_add_color_alpha( props, "active_color", "<font color=#c8ffb7>On Air Background</font>" )
--[[
new property item: color
]]
obs.obs_properties_add_color_alpha( props, "inactive_color", "<font color=#ffb7b7>Stand-By Background</font>" )
--[[
new property item: color
]]
obs.obs_properties_add_color_alpha( props, "active_font", "<font color=#c8ffb7>On Air Font</font>" )
--[[
new property item: color
]]
obs.obs_properties_add_color_alpha( props, "inactive_font", "<font color=#ffb7b7>Stand-By Font</font>" )
--[[
new property item: color
]]
obs.source_list_release( sources ) -- releases the references of source list
--[[
new property item: text
]]
local p_e = obs.obs_properties_add_text( props, "active_text", "<font color=#c8ffb7>On Air Text</font>", obs.OBS_TEXT_DEFAULT )
obs.obs_property_set_long_description( p_e, "\nThe text updated in the text layer\n" )
--[[
new property item: text
]]
local p_f = obs.obs_properties_add_text( props, "inactive_text", "<font color=#ffb7b7>Stand-By Text</font>", obs.OBS_TEXT_DEFAULT )
obs.obs_property_set_long_description( p_f, "\nThe text updated in the text layer\n" )
--[[
new property item: text
]]
local p_g = obs.obs_properties_add_bool( props, "include_name", "Include Source Name" )
obs.obs_property_set_long_description( p_g, "\nInclude in the text updated in the text layer\n" )
--[[
new property item: bool
]]
obs.obs_properties_add_bool( props, "disable_script", "Disable Script" )
-- create clone button
obs.obs_properties_add_button(props, "refresh_settings", "Refresh Settings", refresh_settings)
--[[
OnChange Events
]]
obs.obs_property_set_modified_callback( props_mode, property_onchange )
obs.obs_property_set_modified_callback( props_monitor, property_onchange )
obs.obs_property_set_modified_callback( props_scene, property_onchange )
--[[
Calls the callback once to set-up current visibility
]]
obs.obs_properties_apply_settings( props, script_settings )
--[[
End of function
return
]]
return props
end
--[[
--------------------------------------------------------------------
--------------------------------------------------------------------
--------------------------------------------------------------------
]]
function is_audio_device()
--[[
load mode if available
]]
mode = obs.obs_data_get_string( script_settings, "mode" )
--[[
]]
return ( mode == "Input Audio Device" or mode == "Output Audio Device" or mode == "Browser Audio" or mode == "Capture Device Audio" )
end
--[[
--------------------------------------------------------------------
--------------------------------------------------------------------
--------------------------------------------------------------------
]]
function assign_whitelist()
--[[
Audio Mute / Unmute types
"Input Audio Device", "Output Audio Device", "Browser Audio", "Capture Device Audio"
]]
if mode == "Input Audio Device" then
source_id_whitelist = {
a = "wasapi_input_capture",
--b = "wasapi_output_capture",
--c = "dshow_input",
--d = "browser_source"
--e = "ffmpeg_source",
--f = "monitor_capture",
--g = "streamlink_source",
}
end