-
Notifications
You must be signed in to change notification settings - Fork 84
/
StopWatch-[5.0].lua
7781 lines (7151 loc) · 323 KB
/
StopWatch-[5.0].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
Stopwatch
***************************************************************************************************************************************
Version 5
Published / Released: 2023-07-01 21:54
NEW FEATURES
- Added multiple Time stamps
- Added multiple media files
- Added option to Reset time stamp after defined time to normal colour. 0 will disable this feature.
- Added option to Hide Marker A and Marker B Note (text source) afetx amount of seconds. 0 will disable this feature.
- Added a debug mode
OPTIMIZATION
- Several parts of the Script have been updated.
USER EXPERIENCE & FEATURE ENHANCEMENTS
- Merged Auto Recording and Recording Properties
BUGS
- Fixed several bugs
***************************************************************************************************************************************
]]
--Globals
obs = obslua;
gversion = "5";
luafile = "StopWatch.lua";
obsurl = "comprehensive-stopwatch-countdown-timer.1364/";
patch_notes = "Patch Notes";
icon="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAACpF6WWAAAENElEQVQ4jY1UTUgjZxh+ksl/JuMkMYb4F40bNZqK0KJFqBZqS9ddyl76dyhdKPRQShH2sNDSnnopCz11D10KS/dSKNiDoD2I7KXFQ0XSSGpM1llFMYn5mZiMY2IymfIOhgazXfaDj5n53u975vme531fnaqqeMHxJYCvAOgAlABcAyA1jxLO1tYW1tbWoL+Kd3x8jGg0imw2C0VRWkMEYgNgBeAFYKTFRqOh7aVnE9xwFTSZTGJ7exszMzPQ6XSQZRk8z9P7YrVa/Y5hmKLBYHCpqirW63Wcn5/j7OwMHo9HA6bvNqY2mw1Op1N70qaTkxPkcjmbLMsDZrN5hOO4NxuNhlMUxTFiSCA0FEW5GQ6H/wmHwzfamDavUKlUYDKZAoFA4Gue52/r9f/9v6OjQ5uKojwpFAr3RFF8UCwWjW63OzQ/P/9yGyiBnZ6eEtN3eZ7/9XJZrlQqP2cymcf5fL4QDAbHdTrd2yzLXvd4PD9yHHdLEISFXC7nsdvtuTb3c7kcEokEJiYmhliWtaiqWs5ms4f1el0lE2lOTU0hn8/DYrF09vb23jebze9JkvRXNBqdMpvNaIJaLh1tHScAzpvsSd+joyOkUimEQiFNa4vFAlEU4Xa7HwYCgduFQuHRxsbGx5p+qqq+o/7/SF7uQSaTwcHBgZYdgiBMqKqa2dnZ8S8tLaFcLicIIR6PjzU13Qew+gzPKNEj9JJOp5tag+O41/v7+x/v7u7+sLOzc8BxHN1icXR0dMXlcn3xQhW1v7+PSCSC6enptxwOx3WWZRcbjcbTjY2NAJ1nWRYGgwHj4+OqoigFYnr/UlPlClYFwJ1arVYjU8bGxhZ8Pt9KMxiLxd5gGEbTlTSv1WqQJOmJw+G4RqCfPYfkN4qiFDs7O9HT0/Nqa4BhmKd2u10DrFaruLi4oJmncibQSUCrLHJabDlHzItGo1E7FIvFvg+FQjMmkykkCMK9eDwOivl8PvqhBspxXJAOEujfz2HazzBMdXh4OJNMJoupVGre7/cbBEGor6+vY2RkROsLlwY6jUajS5KkSGvtf0oVemUeAPiDgsFgUHMeQJ3MmZycxNzcnMZWkiT4/f67FJRl+UFrmcYB/N7y3UyLSHOBzNjb20MgEMDg4CC6urqwublJZo12d3ffVRRFEQTh4TNTqlQqaawoTShOVdOsqMPDQ8zOzmqFQK3PZrO91NPTs2U0GkmWG4lEYrWt9cViMSwvL1Ntvw9gRafT/aTX6z8AwFKcuhU5zjDMkNfr/XZgYCBKgMfHx3eSyeSqw+Fob9LEipxMp9MRp9P5uclkWuB5/hOKWa3Wvb6+vjLP8wNer5fXUkRRLkql0ofZbPY3ug019TZQ6jKU0AzD7Iqi+Josy6+4XK6P7Hb7LbvdPkS5SXpXKpU/ZVn+5ezs7FG9Xi9brVZNLr1ej38BVDs6EbSfFQsAAAAASUVORK5CYII=";
desc =
[[
<hr/><center><h2>Advanced Timer</h2>( Version: %s )</center>
<br><center><img width=38 height=42 src="]] .. icon .. [["/></center>
<br><center><a href="https://github.com/midnight-studios/obs-lua/blob/main/]] .. luafile ..[[">Find it on GitHub</a></center>
<center><a href="https://obsproject.com/forum/resources/]] .. obsurl ..[[updates">]] .. patch_notes ..[[</a></center>
<br><p>The Properties for this script will adjust visibility as needed. Some advanced properties will only be visible if the Layout setting is set to "Advanced". If the Layout setting is set to "Basic" any defined values will still be active, so ensure you define those correctly.</p><p>Find help on the <a href="https://obsproject.com/forum/resources/]] .. obsurl ..[[">OBS Forum Thread</a>.</p><hr/>
]];
debug_file = ""
debug_file_name = "Debug Log"
text_prefix = "";
text_suffix = "";
last_text = "";
custom_time_format = "";
timer_source = "";
countdown_type = "";
backup_folder = "";
import_list = "";
longtimetext_s = "";
longtimetext_p = "";
last_split_data = "";
split_source = "";
active_source = "";
next_scene = "";
stop_text = "";
toggle_mili_trigger = "";
sec_add_1 = "";
sec_add_2 = "";
sec_add_3 = "";
sec_sub_1 = "";
sec_sub_2 = "";
sec_sub_3 = "";
output_file_name = "-backup($date_stamp).json";
font_normal = "#ffffff";
font_dimmed = "#bfbbbf";
font_highlight = "#fffdcf";
add_limit_note_source = "";
sub_limit_note_source = "";
note_source_marker_a = "";
note_source_marker_b = "";
audio_marker_a = "";
audio_marker_b = "";
current_count_direction = "UP";
count_orientation = "NORMAL";
debug_entry = 0;
debug_entry = 0;
add_limit_note_source_visible = 0;
sub_limit_note_source_visible = 0;
sources_loaded = 0;
timer_manipulation = 1;
sec_add_limit = 0;
sec_add_limit_used = 0;
sec_sub_limit_used = 0;
sec_sub_limit = 0;
total_sources = 0;
sw_hours_saved = 0;
sw_minutes_saved = 0;
sw_seconds_saved = 0;
sw_milliseconds_saved = 0;
split_type = 2;
current_seconds = 0;
cycle_direction = 1;
default_seconds = 0;
split_count = 0;
timer_year = 0;
timer_month = 0;
timer_day = 0;
timer_hours = 0;
timer_minutes = 0;
timer_seconds = 0;
timer_mode = 0;
last_timer_mode = 0;
timer_format = 1;
timer_display = 1;
start_recording = 1;
media_playback_limit = 0;
enable_marker_notes = 1;
orig_time = 0;
time_frequency = 0;
completed_cycles = 0;
ns_last = 0;
cycle_index = 1;
timer_cycle = 10; --milliseconds
split_itm = {};
required_sources = {
"ffmpeg_source",
"text_gdiplus_v2",
"color_source_v3"
}
ignore_list = {
"",
"none",
"None",
"Select",
"select",
"list"
};
split_data = nil;
minute_format = nil;
local ctx = {
propsDef = nil, -- property definition
propsDefSrc = nil, -- property definition (source scene)
propsSet = nil, -- property settings (model)
propsVal = {}, -- property values
propsValSrc = nil, -- property values (first source scene)
};
props = nil;
timer_event_active = false;
timer_mode_changed = false;
debug_enabled = false; -- careful, may use more system memory
script_ready = false;
set_timer_activated = false;
color_normal_updated = false;
activated = false;
prevent_callback = false;
timer_active = false;
reset_activated = false;
start_on_visible = false;
force_reset_on_visible = false;
force_reset_on_scene_active = false;
active_source_force_visible = false;
start_on_scene_active = false;
disable_script = false;
enable_direction_toggle = false;
show_mili = true;
timer_expired = true;
mili_toggle_triggered = false;
direction_changed = false;
prevent_negative_time = false;
record_timer_set = false;
media = { -- table start
text_marker_a = "",
text_marker_b = "",
source_name_audio_marker_a = "",
source_name_audio_marker_b = "",
source_name_audio_marker_end = "",
note_source_marker_a = "",
note_source_marker_b = "",
note_marker_a = "",
note_marker_b = "",
activated_marker_a = false,
activated_marker_b = false,
activated_media_marker_a = false,
activated_media_marker_b = false,
activated_time_marker_a = 0,
activated_time_marker_b = 0,
cycle_direction_marker_a = 2;
cycle_direction_marker_b = 2;
cycle_index_marker_a = 1; -- index from 1-based table
cycle_index_marker_b = 1; -- index from 1-based table
current_seconds_marker_a = 0,
current_seconds_marker_b = 0,
duration_marker_a = 0,
duration_marker_b = 0,
reset_text_marker_a = 0,
reset_text_marker_b = 0,
hide_note_marker_a = 0,
hide_note_marker_b = 0,
duration_marker_end = 0,
last_orientation_marker_a = "NORMAL";
last_orientation_marker_b = "NORMAL";
media_ended_marker_a = false,
media_ended_marker_b = false,
color_normal = 4294967295, -- 4294967295 0xFFFFFFFF
color_marker_a = 4256749, -- 4256749 0x40f3ed
color_marker_b = 329050, -- 329050 0x05055a
last_state_marker_a = obs.OBS_MEDIA_STATE_NONE,
last_state_marker_b = obs.OBS_MEDIA_STATE_NONE
}; -- table end
selected_source_list = {};
hotkey_id_reset = obs.OBS_INVALID_HOTKEY_ID;
hotkey_id_pause = obs.OBS_INVALID_HOTKEY_ID;
hotkey_id_split = obs.OBS_INVALID_HOTKEY_ID;
hotkey_id_mili = obs.OBS_INVALID_HOTKEY_ID;
hotkey_id_direction = obs.OBS_INVALID_HOTKEY_ID;
hotkey_id_sec_add_1 = obs.OBS_INVALID_HOTKEY_ID;
hotkey_id_sec_add_2 = obs.OBS_INVALID_HOTKEY_ID;
hotkey_id_sec_add_3 = obs.OBS_INVALID_HOTKEY_ID;
hotkey_id_sec_sub_1 = obs.OBS_INVALID_HOTKEY_ID;
hotkey_id_sec_sub_2 = obs.OBS_INVALID_HOTKEY_ID;
hotkey_id_sec_sub_3 = obs.OBS_INVALID_HOTKEY_ID;
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: A function named script_description returns the description shown to
the user
Credit: OBS
Modified: User dependent
function: Script Description
type: OBS Core
input type: data
returns: string
----------------------------------------------------------------------------------------------------------------------------------------
]]
function script_description()
debug_log( 'script_description() -- function variable names: ' )
return string.format( desc, tostring( gversion ) );
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: Get the name of this script
Credit: midnight-studios, et al
Modified:
function: regular expression
type: Support
input type: string
returns: string
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function filename()
local str = debug.getinfo(2).source:sub(2);
return str:match("^.*/(.*).lua$") or str;
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: Dumps input to string, if input is a table it returns the expanded table
Credit: et al
Modified: yes
function:
type: Support (debug tool)
input type: variable
returns: string
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function pre_dump(input)
if type(input) ~= "table" then
return tostring(input)
else
local tbl = {}
for key, value in pairs(input) do
local keyStr = (type(key) ~= "number") and "'" .. key .. "'" or tostring(key)
tbl[#tbl + 1] = "[" .. keyStr .. "] = " .. "'" .. pre_dump(value) .. "'"
end
return "{ " .. table.concat(tbl, ", ") .. " }"
end
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: Use this to create a Script Log Output used in testing
Credit: et al
Modified: No
function:
type: Support (debug tool)
input type: string
returns: print(string)
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function log( name, msg )
if msg ~= nil then
msg = " > " .. tostring( msg );
else
msg = "";
end;
obs.script_log( obs.LOG_DEBUG, tostring( name ) .. msg );
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description:
Credit:
Modified:
function:
type:
input type:
returns:
----------------------------------------------------------------------------------------------------------------------------------------
]]
function debug_log( content )
if not debug_enabled then
return
end
if debug_file == "" then
debug_file = create_debug_file( debug_file_name, content )
else
update_debug_file( debug_file, content )
end
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description:
Credit:
Modified:
function:
type:
input type:
returns:
----------------------------------------------------------------------------------------------------------------------------------------
]]
function create_debug_file( input_file_name, content )
content = content or string.format( "%s [%s]\n", "Debug Information", os.date("%Y-%m-%d_%H.%M.%S"))
local file_name = string.format( "%s-%s[%s]%s", filename(), input_file_name, os.date("%Y-%m-%d_%H.%M.%S"), ".txt");
-- set output path as the script path by default
local script_path = script_path();
local output_path = script_path .. file_name;
-- if specified output path exists, then set this as the new output path
output_path = script_path .. file_name;
output_path = output_path:gsub( [[\]], "/" );
log( "create_debug_file", output_path )
-- Open file in write mode, this will create the file if it does not exist
local file = io.open( output_path, "w" )
-- If the file has been opened successfully
if file then
-- Write content to the file
file:write( content )
-- Close the file
file:close()
else
-- Print error message
print("Failed to open file " .. file_name .. " for writing")
end
return output_path;
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description:
Credit:
Modified:
function:
type:
input type:
returns:
----------------------------------------------------------------------------------------------------------------------------------------
]]
function rewrite_line_debug_file( filename, line_num, content )
-- Store all lines in memory
local lines = {}
-- Open the file in read mode
local file = io.open(filename, 'r')
-- If the file has been opened successfully
if file then
-- Loop over all lines in the file
for line in file:lines() do
table.insert(lines, line)
end
-- Close the file
file:close()
else
-- Print error message
print("Failed to open file " .. filename .. " for reading")
end
-- Replace the line at the specified line number
if line_num <= #lines then
lines[line_num] = content
end
-- Open the file in write mode
file = io.open(filename, 'w')
-- If the file has been opened successfully
if file then
for i = 1, #lines do
-- Only add a newline if it's not the last line
if i < #lines then
file:write(lines[i] .. "\n")
else
file:write(lines[i])
end
end
-- Close the file
file:close()
else
-- Print error message
print("Failed to open file " .. filename .. " for writing")
end
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description:
Credit:
Modified:
function:
type:
input type:
returns:
----------------------------------------------------------------------------------------------------------------------------------------
]]
function update_debug_file( filename, content )
if filename ~= nil then
debug_entry = debug_entry + 1
content = tostring(debug_entry) .. ") " .. string.rep( " ", string.len(debug_entry) ) .. content
-- Open file in append mode
local file = io.open( filename, "a" )
-- If the file has been opened successfully
if file then
-- Write new content on a new line
file:write( "\n" .. content )
-- Close the file
file:close()
else
-- Print error message
print("Failed to open file " .. tostring(filename) .. " for appending. Could not add content: " .. pre_dump(content))
end
-- adds unnecessary processing
--rewrite_line_debug_file( filename, 2, "Last item entered: " .. content )
else
--print("Failed " .. tostring(filename) .. " Does not exist. Could not add content: " .. pre_dump(content))
end
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: Builds a table by splitting a string by defined character or sequence of characters marking
the beginning or end of a unit of data. That which delimits, that separates.
Credit: midnight-studios, et al
Modified:
function: breaks string into sections by a reference that is returned in a table
type:
input type: string, delimiter
returns: table
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function explode_alt( str, delim )
debug_log( 'explode_alt(' .. pre_dump(str) .. ", " .. pre_dump(delim) .. ') -- function variable names: str, delim ' )
local tbl, index;
tbl = {};
index = 0;
if( #str == 1 ) then return {str} end; -- returns a table with the input string as the only value
while true do
local trace_index = string.find( str, delim, index, true ); -- find the next d in the string
if trace_index ~= nil then -- if "not not" found then..
table.insert( tbl, string.sub( str, index, trace_index - 1 ) ); -- Save it in our array.
index = trace_index + 1; -- save just after where we found it for searching next time.
else
table.insert( tbl, string.sub( str, index ) ); -- Save what's left in our array.
break; -- Break at end, as it should be, according to the lua manual.
end;
end;
return tbl;
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: Builds a table by splitting a string by defined character or sequence of characters marking
the beginning or end of a unit of data. That which delimits, that separates.
Credit: midnight-studios, et al
Modified:
function: breaks string into sections by a reference that is returned in a table
type:
input type: string, delimiter
returns: table
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function explode( str, div )
debug_log( 'explode(' .. pre_dump(str) .. ", " .. pre_dump(delim) .. ') -- function variable names: str, delim ' )
if ( div == nil or div == '' ) or ( str == nil or str == '' ) then return {} end
local pos, arr = 0, {}
for st, sp in function() return string.find(str, div, pos, true) end do
table.insert(arr, string.sub(str, pos, st - 1))
pos = sp + 1
end
table.insert(arr, string.sub(str, pos))
return arr
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: Gives you an iterator that moves through an
ordinary table (eg. string keys) but sorted
into key sequence.
It does that by copying the table keys into
a temporary table and sorting that.
Possibly being string referenced the list
will be compiled chronologically, thus the
list names (values) may appear unordered and
random. To reorganise and arrange the list
alphabetically we will use pairsByKeys().
This will make it easier for the user to review
and select the desired item from the list.
Credit: https://github.com/nickgammon/mushclient/blob/master/lua/pairsbykeys.lua
https://github.com/nickgammon/mushclient/tree/master/lua
If you need to sort keys other than strings, see:
See: http://lua-users.org/wiki/SortedIteration
Modified: Yes, minor changes
function: support: This prints the math functions in key order
type: sort table
input type: table, function (optional)
returns: table
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function pairsByKeys( tbl, input_function )
debug_log( 'pairsByKeys(' .. pre_dump( tbl ) .. ", " .. pre_dump( input_function ) .. ')')
if type( tbl ) ~= "table" then return tbl end
-- instead of creating a new table and inserting all items into it, just get the keys
local keys = {}
for k in pairs(tbl) do keys[#keys+1] = k end
table.sort( keys, input_function )
local i = 0
local iter = function ()
i = i + 1
if keys[i] == nil then
return nil
else
-- use keys[i] to get value from tbl
return keys[i], tbl[keys[i]]
end
end
return iter
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: Provides the length of a table
(how many items the table contains)
Credit: midnight-studios, et al
Modified: Author
function: Create a table with unique items
type: Support
input type: table
returns: integer
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function tablelength( tbl )
debug_log( 'tablelength(' .. pre_dump(tbl) .. ') -- function variable names: tbl ' )
local count = 0;
if type( tbl ) == "table" then -- if the input table is not of type table return 0
for _ in pairs( tbl ) do count = count + 1 end;
end;
return count;
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: Remove duplicated values from table
Credit: midnight-studios, et al
Modified: Author
function: Create a table with unique items
type: Support
input type: table, string
returns: bool
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function tableHasKey( tbl, key )
debug_log( 'tableHasKey(' .. pre_dump(tbl) .. ", " .. pre_dump(key) .. ') -- function variable names: tbl, key ' )
if type( tbl ) ~= "table" or key == nil then return false end; -- if the input table is not of type table return bool(false)
return tbl[key] ~= nil;
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: Remove duplicated values from table
Credit: midnight-studios, et al
Modified: Author
function: Create a table with unique items
type: Support
input type: table, string
returns: bool
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function in_table( tbl, input_value, sh )
debug_log( 'in_table(' .. pre_dump(tbl) .. ", " .. pre_dump(input_value) .. ') -- function variable names: tbl, input_value ' )
if type( tbl ) ~= "table" or input_value == nil then return false end; -- if the input table is not of type table return bool(false)
for _, value in pairs( tbl ) do
if value == input_value then
return true
end;
end;
return false
end
--[[
----------------------------------------------------------
Description:
Credit:
Modified:
function:
type:
input type:
returns:
----------------------------------------------------------
]]
function refresh_properties()
debug_log( 'refresh_properties() -- function variable names: ' )
return true;
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description:
Credit:
Modified:
function:
type:
input type:
returns:
----------------------------------------------------------------------------------------------------------------------------------------
]]
function checkTimeString(str)
debug_log( 'checkTimeString(' .. pre_dump(str) .. ') -- function variable names: str' )
-- Pattern to match the format '00:00:00'
local pattern = "^%d%d:%d%d:%d%d$"
-- Check if the string matches the pattern
if string.match(str, pattern) then
return true
else
return false
end
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description:
Credit:
Modified:
function:
type:
input type:
returns:
----------------------------------------------------------------------------------------------------------------------------------------
]]
function removeDuplicates( tbl )
debug_log( 'removeDuplicates(' .. pre_dump( tbl ) .. ') -- function variable names: tbl' )
if type( tbl ) ~= "table" or tbl == nil then return tbl end; -- if the input table is not of type table return input
local seen = {}
local result = {}
for _, value in ipairs(tbl) do
if not seen[value] then
table.insert(result, value)
seen[value] = true
end
end
return result
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: A function named script_update will be called when settings are changed
Credit:
Modified:
function: Called upon settings initialization and modification
type:
input type:
returns:
----------------------------------------------------------------------------------------------------------------------------------------
]]
function convertToSeconds(timeString)
debug_log( 'convertToSeconds(' .. pre_dump(timeString) .. ') -- function variable names: timeString' )
local hours, minutes, seconds = string.match(timeString, "(%d%d):(%d%d):(%d%d)")
-- Convert hours, minutes, and seconds to integers
hours = tonumber(hours)
minutes = tonumber(minutes)
seconds = tonumber(seconds)
-- Calculate the total seconds
local totalSeconds = (hours * 3600) + (minutes * 60) + seconds
return totalSeconds
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: set source visibility
Credit: midnight-studios, et al
Modified:
function: Update Text Source
type: Support, Render
input type:
returns: bool
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function set_visible( source_name, visible )
debug_log( 'set_visible(' .. pre_dump(source_name) .. ", " .. pre_dump(visible) .. ') -- function variable names: source_name, visible ' )
visible = visible or false;
local action_completed = false;
if source_name == nil then
debug_log( 'set_visible: ' .. pre_dump(action_completed) )
return action_completed;
end;
if in_table( ignore_list, source_name ) then
debug_log( 'ignore_list set_visible: ' .. pre_dump(action_completed) )
return action_completed;
end;
local scenes = obs.obs_frontend_get_scenes();
if scenes ~= nil then
debug_log( 'got scenes set_visible' )
for i, scn in ipairs( scenes ) do
local scene = obs.obs_scene_from_source( scn );
local sceneitem = obs.obs_scene_find_source_recursive( scene, source_name );
if sceneitem ~= nil then
debug_log( 'got sceneitem set_visible' )
if visible and not obs.obs_sceneitem_visible( sceneitem ) then -- only set visible if not visible
obs.obs_sceneitem_set_visible( sceneitem, visible );
end
if not visible and obs.obs_sceneitem_visible( sceneitem ) then -- only hide if visible
obs.obs_sceneitem_set_visible( sceneitem, visible );
end;
action_completed = true;
break;
end;
end; --end for
obs.bfree( scn );
obs.source_list_release( scenes );
end;
return action_completed;
end
--[[
----------------------------------------------------------
Description: check source visibility
Credit: midnight-studios, et al
Modified:
function: Check source visibility state by name
type:
input type: source name (string)
returns: boolean
----------------------------------------------------------
]]
local function is_visible( source_name )
debug_log( 'is_visible(' .. pre_dump(source_name) .. ') -- function variable names: source_name ' )
if source_name == nil or in_table( ignore_list, source_name ) then
debug_log( 'is_visible: ' .. pre_dump(source_name) )
return false;
end;
local isvisible = false;
if source_name ~= nil then
local scenes = obs.obs_frontend_get_scenes();
if scenes ~= nil then
for i, scn in ipairs( scenes ) do
local scene = obs.obs_scene_from_source( scn );
local sceneitem = obs.obs_scene_find_source_recursive( scene, source_name );
if sceneitem ~= nil then
isvisible = obs.obs_sceneitem_visible( sceneitem );
break;
end;
end; --end for
obs.bfree( scn );
obs.source_list_release( scenes );
end; --end scenes ~= nil
end;
debug_log( 'is_visible: ' .. pre_dump(isvisible) )
return isvisible;
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: Function to compare two time strings
Credit:
Modified:
function:
type:
input type:
returns:
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function compareTimeStrings( timeString1, timeString2 )
debug_log( 'compareTimeStrings(' .. pre_dump(timeString1) .. ", " .. pre_dump(timeString2) .. ') -- function variable names: timeString1, timeString2' )
-- Extract hours, minutes, and seconds from time strings
local hours1, minutes1, seconds1 = string.match(timeString1, "(%d%d):(%d%d):(%d%d)")
local hours2, minutes2, seconds2 = string.match(timeString2, "(%d%d):(%d%d):(%d%d)")
-- Convert hours, minutes, and seconds to integers
hours1 = tonumber(hours1)
minutes1 = tonumber(minutes1)
seconds1 = tonumber(seconds1)
hours2 = tonumber(hours2)
minutes2 = tonumber(minutes2)
seconds2 = tonumber(seconds2)
-- Calculate the total seconds for each time string
local totalSeconds1 = (hours1 * 3600) + (minutes1 * 60) + seconds1
local totalSeconds2 = (hours2 * 3600) + (minutes2 * 60) + seconds2
-- Compare the total seconds
return totalSeconds1 < totalSeconds2
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: Function to sort the table items
Credit:
Modified:
function:
type:
input type:
returns:
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function sortTimeTable( tbl )
debug_log( 'sortTimeTable(' .. pre_dump(tbl) .. ') -- function variable names: tbl' )
if type( tbl ) ~= "table" or tbl == nil then return tbl end; -- if the input table is not of type table return input
table.sort(tbl, compareTimeStrings)
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description: custom function
we use this to get a count of essential sources
Credit:
Modified:
function:
type:
input type:
returns: interger
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function count_required_sources()
debug_log( 'count_required_sources() -- function variable names: ' )
local sources = obs.obs_enum_sources();
local i = 0;
if sources ~= nil then
for _, source in ipairs( sources ) do -- ipairs cycles auto incrimented items
local name = obs.obs_source_get_name( source ); -- Get the source name, this will be a unique identifier
local id = obs.obs_source_get_id( source )
if in_table( required_sources, id ) then
i = i + 1;
end
end
obs.bfree(source); -- free memory, release source as it is no longer needed
end;
obs.source_list_release( sources ); -- free memory, release
total_sources = i;
return i;
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description:
Credit:
Modified:
function:
type:
input type:
returns:
----------------------------------------------------------------------------------------------------------------------------------------
]]
function getNextItemMatchingTime( tbl, currentTime )
debug_log( 'getNextItemMatchingTime(' .. pre_dump(tbl) .. ", " .. pre_dump(currentTime) .. ') -- function variable names: tbl, currentTime ' )
if type( tbl ) ~= "table" or tbl == nil then return nil end; -- if the input table is not of type table return input
local nextItem = nil
local currentTimeString = string.format( "%02d:%02d:%02d", math.floor( currentTime / 3600 ), math.floor( ( currentTime % 3600 ) / 60 ), currentTime % 60 )
for _, value in ipairs( tbl ) do
if value > currentTimeString then
nextItem = value
break
end
end
if tbl[1] ~= nil and nextItem == nil then
-- loop to first item
-- nextItem = tbl[1]
end
return nextItem
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description:
Credit:
Modified:
function:
type:
input type:
returns:
----------------------------------------------------------------------------------------------------------------------------------------
]]
function getPreviousItemMatchingTime( table, currentTime )
debug_log( 'getPreviousItemMatchingTime(' .. pre_dump(table) .. ", " .. pre_dump(currentTime) .. ') -- function variable names: table, currentTime ' )
local previousItem = nil
local currentTimeString = string.format( "%02d:%02d:%02d", math.floor( currentTime / 3600 ), math.floor( ( currentTime % 3600 ) / 60 ), currentTime % 60 )
for _, value in ipairs(table) do
if value < currentTimeString then
previousItem = value
else
break
end
end
if table[#table] ~= nil and previousItem == nil then
-- loop to last item
--previousItem = table[#table]
end
return previousItem
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Function to convert OBS data array to table
obs_data_array_to_table( settings, "reference" )
Description: Grab OBS data array and return in a table
Credit: midnight-studios
Modified:
function: data array to table
type: Support
input type: Settings, property reference
returns: table
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function obs_data_array_to_table( set, item )
debug_log( 'obs_data_array_to_table(' .. pre_dump(set) .. ", " .. pre_dump(item) .. ') -- function variable names: set, item ' )
local array = obs.obs_data_get_array( set, item );
local count = obs.obs_data_array_count( array );
local list = {};
for i = 1, count do
local array_item = obs.obs_data_array_item( array, i-1 );
local value = obs.obs_data_get_string( array_item, "value" );
table.insert( list, value )
end;
obs.obs_data_array_release( array );
return list;
end
--[[
----------------------------------------------------------------------------------------------------------------------------------------
Description:
Credit:
Modified:
function:
type:
input type:
returns:
----------------------------------------------------------------------------------------------------------------------------------------
]]
local function getMarkerTime( ref, currentTime )
debug_log( 'getMarkerTime(' .. pre_dump(ref) .. ", " .. pre_dump(currentTime) .. ') -- function variable names: ref, currentTime ' )
--[[
Create a table for a list
]]
local result = nil
local i = 0; -- create interger variable
local list = {}; -- create temporary table variable
local data_list = obs_data_array_to_table( ctx.propsSet, "text_arr_" .. ref ); -- fetch obs userdata from property settings and return in table
--[[
Build a cycle list
We only include valid string formats '00:00:00'
any other format will be excluded
]]