forked from unanimated/luaegisub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ua.Significance.lua
3134 lines (2865 loc) · 124 KB
/
ua.Significance.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
script_name="Significance"
script_description="Import stuff, number stuff, chapter stuff, replace stuff, do a significant amount of other stuff to stuff."
script_author="unanimated"
script_version="3.5"
script_namespace="ua.Significance"
local haveDepCtrl,DependencyControl,depRec=pcall(require,"l0.DependencyControl")
if haveDepCtrl then
script_version="3.5.0"
depRec=DependencyControl{feed="https://raw.githubusercontent.com/unanimated/luaegisub/master/DependencyControl.json"}
end
clipboard=require("aegisub.clipboard")
re=require'aegisub.re'
-- Significance GUI ------------------------------------------------------------------------------------------
function significance(subs,sel,act)
ADD=aegisub.dialog.display
ADP=aegisub.decode_path
ak=aegisub.cancel
ms2fr=aegisub.frame_from_ms
fr2ms=aegisub.ms_from_frame
ATAG="{[*>]?\\[^}]-}"
STAG="^{[*>]?\\[^}]-}"
COMM="{[^\\}]-}"
aegisub.progress.title("Loading...")
datata=datata or ""
sub1=sub1 or ""
sub2=sub2 or ""
sub3=sub3 or 1
for i=1,#subs do if subs[i].class=="dialogue" then line0=i-1 break end end
msg={"If it breaks, it's your fault.","This should be doing something...","Breaking your computer. Please wait.","Unspecified operations in progress.","This may or may not work.","Trying to avoid bugs...","Zero one one zero one zero...","10110101001101101010110101101100001","I'm surprised anyone's using this","If you're seeing this for too long, it's a bad sign.","This might hurt a little.","Please wait... I'm pretending to work.","Close all your programs and run."}
rm=math.random(1,#msg) msge=msg[rm]
if lastimp then dropstuff=lastuff lok=lastlog zerozz=lastzeros fld=lastfield mod0=lastmod0
else dropstuff="replacer" lok=false zerozz="01" fld="effect" mod0="number lines" end
g_impex={"import OP","import ED","import sign","import signs","export sign","import chptrs","update lyrics"}
g_stuff={"save/load","replacer","lua calc","split text to actor/effect","reverse text","reverse words","reverse transforms","fake capitals","format dates","fill columns","split into letters (alpha)","explode","dissolve text","randomised transforms","what is the Matrix?","clone clip","clip2margins","duplicate and shift lines","extrapolate tracking","time by frames","convert framerate","transform \\k to \\t\\alpha","fix kara tags for fbf lines","make style from act. line","make comments visible","switch commented/visible","honorificslaughterhouse"}
LN1=sel[1]-line0
LN2=sel[#sel]-line0
lin=LN1.."-"..LN2
lin=lin:gsub("^(%d+)%-%1$","%1")
if LN2-LN1+1>#sel then lin=lin:gsub("-"," ... #") end
unconfig={
-- Sub --
{x=0,y=16,width=3,class="label",label="Left "},
{x=3,y=16,width=3,class="label",label="Right "},
{x=6,y=16,width=3,class="label",label="Mod "},
{x=0,y=17,width=3,class="edit",name="rep1",value=sub1},
{x=3,y=17,width=3,class="edit",name="rep2",value=sub2},
{x=6,y=17,width=3,class="edit",name="rep3",value=sub3,hint="Numbers: start/repeat[limit]\nreplacer/lua calc: limit"},
-- import
{x=9,y=3,width=2,class="label",label="Import/Export"},
{x=9,y=4,width=2,class="dropdown",name="mega",items=g_impex,value="import signs"},
{x=11,y=4,class="checkbox",name="keep",label="keep line",value=true,},
{x=9,y=5,width=3,class="checkbox",name="restr",label="style restriction (lyrics)",value=false,},
{x=9,y=6,width=3,class="edit",name="rest"},
-- chapters
{x=9,y=7,class="label",label="Chapters"},
{x=10,y=7,width=2,class="checkbox",name="intro",label="autogenerate \"Intro\"",value=true,},
{x=9,y=8,width=2,class="label",label="chapter marker:"},
{x=11,y=8,class="dropdown",name="marker",items={"actor","effect","comment"},value="actor"},
{x=9,y=9,width=2,class="label",label="chapter name:"},
{x=11,y=9,class="dropdown",name="nam",items={"comment","effect"},value="comment"},
{x=9,y=10,width=2,class="label",label="filename from:"},
{x=11,y=10,class="dropdown",name="sav",items={"script","video"},value="script"},
{x=9,y=11,width=2,class="checkbox",name="chmark",label="chapter mark:",value=false,hint="just sets the marker. no xml."},
{x=11,y=11,class="dropdown",name="chap",items={"Intro","OP","Part A","Part B","Part C","ED","Preview"},value="OP"},
{x=9,y=12,width=3,class="edit",name="lang"},
-- numbers
{x=9,y=13,width=2,class="label",label="Numbers"},
{x=9,y=14,width=2,class="dropdown",name="modzero",items={"number lines","number 12321","add to marker","zero fill","random"},value=mod0},
{x=11,y=14,class="dropdown",name="zeros",items={"1","01","001","0001"},value=zerozz},
{x=9,y=15,width=2,class="dropdown",name="field",items={"actor","effect","layer","style","text","left","right","vert","comment"},value=fld},
{x=11,y=15,class="checkbox",name="intxt",label="in text",hint="numbers found in text"},
-- stuff
{x=0,y=15,class="label",label="&Stuff "},
{x=1,y=15,width=2,class="dropdown",name="stuff",items=g_stuff,value=dropstuff}, --dropstuff
{x=3,y=15,class="dropdown",name="regex",items={"lua patterns","perl regexp"},value="perl regexp"},
{x=4,y=15,class="checkbox",name="log",label="log",value=lok,hint="provides some information for many of the functions here"},
{x=8,y=15,class="label",label="Marker:"},
-- textboxes
{x=0,y=0,width=9,height=15,class="textbox",name="dat",value=data},
{x=9,y=1,width=3,class="label",label=" Selected Lines: "..#sel.." [#"..lin.."]"},
-- help
{x=9,y=0,width=3,class="dropdown",name="help",
items={"--- Help menu ---","Import/Export","Update Lyrics","Do Stuff","Numbers","Chapters"},value="--- Help menu ---"},
{x=9,y=17,width=3,class="label",label=" Significance version: "..script_version},
}
loadconfig()
repeat
if P=="&Help" then aegisub.progress.title("Loading Help") aegisub.progress.task("RTFM")
if res.help=="Import/Export" then help=help_i end
if res.help=="Update Lyrics" then help=help_u end
if res.help=="Do Stuff" then help=help_d end
if res.help=="Numbers" then help=help_n end
if res.help=="Chapters" then help=help_c end
if res.help=="--- Help menu ---" then help="Choose something from the menu, dumbass -->" end
for key,val in ipairs(unconfig) do if val.name=="dat" then val.value=help end end
end
if P=="&Info" then aegisub.progress.title("Gathering Info") aegisub.progress.task("...") info(subs,sel,act)
for key,val in ipairs(unconfig) do if val.name=="dat" then val.value=infodump end end
end
P,res=ADD(unconfig,{"Import/Export","Do &Stuff","&Numbers","&Chapters","&Repeat Last","&Info","&Help","Save Config","Cancel"},{ok='Import/Export',cancel='Cancel'})
until P~="&Help" and P~="&Info"
if P=="Cancel" then ak() end
lastimp=true lastuff=res.stuff lastlog=res.log lastzeros=res.zeros lastfield=res.field lastmod0=res.modzero
if P=="&Repeat Last" then if not lastres then ak() end P=lastP res=lastres end
progress("Doing Stuff") aegisub.progress.task(msge)
sub1=res.rep1
sub2=res.rep2
sub3=res.rep3
zer=res.zeros
if P=="Import/Export" then important(subs,sel,act) end
if P=="&Numbers" then numbers(subs,sel) end
if P=="&Chapters" then chopters(subs,sel) end
if P=="Do &Stuff" then
if res.stuff=="convert framerate" then framerate(subs)
elseif res.stuff=="honorificslaughterhouse" then honorifix(subs,sel)
else sel=stuff(subs,sel,act) end
end
lastP=P
lastres=res
if P=="Save Config" then saveconfig() end
return sel
end
-- IMPORT/EXPORT --------------------------------------------------------------------------------------------
function important(subs,sel,act)
aline=subs[act]
atext=aline.text
atags=atext:match("^{(\\[^}]-)}") or ""
atags=atags:gsub("\\move%b()","")
atxt=atext:gsub(STAG,"")
-- create table from user data (lyrics)
sdata={}
if res.mega=="update lyrics" and res.dat=="" then t_error("No lyrics given.",1)
else
res.dat=res.dat.."\n"
for dataline in res.dat:gmatch("(.-)\n") do if dataline~="" then table.insert(sdata,dataline) end end
end
-- user input
sub1=res.rep1
sub2=res.rep2
sub3=res.rep3
zer=res.zeros
rest=res.rest
-- this checks whether the pattern for lines with lyrics was found
songcheck=0
-- paths
scriptpath=ADP("?script")
if script_path=="relative" then path=scriptpath.."\\"..relative_path end
if script_path=="absolute" then path=absolute_path end
-- IMPORT --
if res.mega:match("import") and not res.mega:match("chptrs") then
noshift=false defect=false keeptxt=false deline=false
-- import-single-sign GUI
if res.mega=="import sign" then
press,reslt=ADD({
{x=0,y=0,class="label",label="File name:"},
{x=0,y=1,width=2,class="edit",name="signame"},
{x=1,y=0,width=2,class="dropdown",name="signs",items={"title","eptitle","custom","eyecatch"},value="custom"},
{x=2,y=1,class="label",label=".ass"},
{x=0,y=2,width=3,class="checkbox",name="matchtime",label="keep current line's times",value=true,},
{x=0,y=3,width=3,class="checkbox",name="keeptext",label="keep current line's text",value=false,},
{x=0,y=4,width=3,class="checkbox",name="keeptags",label="combine tags (current overrides) ",value=false,},
{x=0,y=5,width=3,class="checkbox",name="addtags",label="combine tags (imported overrides)",value=false,},
{x=0,y=6,width=3,class="checkbox",name="noshift",label="don't shift times (import as is)",value=false,},
{x=0,y=7,width=3,class="checkbox",name="deline",label="delete original line",value=false,},
},{"OK","Cancel"},{ok='OK',close='Cancel'})
if press=="Cancel" then ak() end
if reslt.signs=="custom" then signame=reslt.signame else signame=reslt.signs end
noshift=reslt.noshift keeptxt=reslt.keeptext deline=reslt.deline
keeptags=reslt.keeptags addtags=reslt.addtags
end
-- read signs.ass
if res.mega=="import signs" then
file=io.open(path.."signs.ass")
if file==nil then ADD({{class="label",label=path.."signs.ass\nNo such file."}},{"ok"},{cancel='ok'}) ak() end
signs=file:read("*all")
io.close(file)
end
-- sort out if using OP, ED, signs, or whatever .ass and read the file
songtype=res.mega:match("import (%a+)")
if songtype=="sign" then songtype=signame end
file=io.open(path..songtype..".ass")
if file==nil then t_error(path..songtype..".ass\nNo such file.",1) end
song=file:read("*all")
io.close(file)
-- cleanup useless stuff
song=song:gsub("^.-(Dialogue:)","%1")
song=song.."\n"
song=song:gsub("\n\n$","\n")
song=song:gsub("%[[^%]]-%]\n","\n")
-- make table out of lines
slines={}
for sline in song:gmatch("(.-)\n") do
if sline~="" then table.insert(slines,sline) end
end
-- save (some) current line properties
btext=atext
basetime=aline.start_time
basend=aline.end_time
basestyle=aline.style
baselayer=aline.layer
-- import-signs list and GUI
if res.mega=="import signs" then
-- make a table of signs in signs.ass
signlist={}
signlistxt=""
for x=1,#slines do
efct=slines[x]:match("%a+: %d+,[^,]-,[^,]-,[^,]-,[^,]-,[^,]-,[^,]-,[^,]-(,[^,]-,).*")
esfct=esc(efct)
if not signlistxt:match(esfct) then signlistxt=signlistxt..efct end
end
for sn in signlistxt:gmatch(",([^,]-),") do table.insert(signlist,sn) end
-- import-signs GUI
button,reslt=ADD({
{x=0,y=0,class="label",label="Choose a sign to import:"},
{x=0,y=1,class="dropdown",name="impsign",items=signlist,value=signlist[1]},
{x=0,y=2,class="checkbox",name="matchtime",label="keep current line's times",value=true,},
{x=0,y=3,class="checkbox",name="keeptext",label="keep current line's text",value=false,},
{x=0,y=4,class="checkbox",name="keeptags",label="combine tags (current overrides) ",value=false,},
{x=0,y=5,class="checkbox",name="addtags",label="combine tags (imported overrides)",value=false,},
{x=0,y=6,class="checkbox",name="noshift",label="don't shift times (import as is)",value=false,},
{x=0,y=7,class="checkbox",name="defect",label="delete 'effect'",value=false,},
{x=0,y=8,class="checkbox",name="deline",label="delete original line",value=false,},
},{"OK","Cancel"},{ok='OK',close='Cancel'})
if button=="Cancel" then ak() end
if button=="OK" then whatsign=reslt.impsign end
noshift=reslt.noshift defect=reslt.defect keeptxt=reslt.keeptext deline=reslt.deline
keeptags=reslt.keeptags addtags=reslt.addtags
-- nuke lines for the other signs
for x=#slines,1,-1 do
efct=slines[x]:match("%a+: %d+,[^,]-,[^,]-,[^,]-,[^,]-,[^,]-,[^,]-,[^,]-,([^,]-),.*")
if efct~=whatsign then table.remove(slines,x) end
end
end
-- check start time of the first line (for overall shifting)
starttime=slines[1]:match("%a+: %d+,([^,]+)")
shiftime=string2time(starttime)
if res.mega:match("sign") and noshift then shiftime=0 end
-- importing lines from whatever .ass
for x=#slines,1,-1 do
local ltype,layer,s_time,e_time,style,actor,margl,margr,margv,eff,txt=slines[x]:match("(%a+): (%d+),([^,]-),([^,]-),([^,]-),([^,]-),([^,]-),([^,]-),([^,]-),([^,]-),(.*)")
l2=aline
if ltype=="Comment" then l2.comment=true else l2.comment=false end
l2.layer=layer
-- timing/shifting depending on settings
if res.mega:match("import sign") and reslt.matchtime then l2.start_time=basetime l2.end_time=basend else
s_time=string2time(s_time)
e_time=string2time(e_time)
if not noshift then s_time=s_time+basetime e_time=e_time+basetime end
l2.start_time=s_time-shiftime
l2.end_time=e_time-shiftime
end
l2.style=style
l2.actor=actor
l2.margin_l=margl
l2.margin_r=margr
l2.margin_t=margv
l2.effect=eff
if defect then l2.effect="" end
l2.text=txt
atext=txt
if keeptxt and actor~="x" then
btext2=btext:gsub("{\\[^}]-}","")
l2.text=l2.text:gsub("^({\\[^}]-}).*","%1"..btext2) atext=btext2
end
if keeptags and actor~="x" then
l2.text=addtag(atags,l2.text)
l2.text=l2.text:gsub("({%*?\\[^}]-})",function(tg) return duplikill(tg) end)
:gsub("({%*?\\[^}]-})",function(tg) return extrakill(tg,2) end)
end
if addtags and actor~="x" then
l2.text="{"..atags.."}"..l2.text
l2.text=l2.text:gsub("{(\\[^}]-)}{(\\[^}]-)}","{%1%2}")
:gsub("({%*?\\[^}]-})",function(tg) return duplikill(tg) end)
:gsub("({%*?\\[^}]-})",function(tg) return extrakill(tg,2) end)
end
subs.insert(act+1,l2)
end
-- delete line if not keeping
if deline then res.keep=false end
if not res.keep then subs.delete(act) else
-- keep line, restore initial state + comment out
atext=btext aline.comment=true aline.start_time=basetime aline.end_time=basend aline.style=basestyle aline.actor="" aline.effect=""
aline.layer=baselayer aline.text=atext subs[act]=aline
end
end
-- EXPORT --
if res.mega=="export sign" then
exportsign=""
for z,i in ipairs(sel) do
line=subs[i]
text=line.text
if z==1 then snam=line.effect end
exportsign=exportsign..line.raw.."\n"
end
press,reslt=ADD({
{x=0,y=0,class="label",label="Target:",},
{x=0,y=1,class="label",label="Name:",},
{x=1,y=0,width=2,class="dropdown",name="addsign",
items={"Add to signs.ass","Save to new file:"},value="Add to signs.ass"},
{x=1,y=1,width=2,class="edit",name="newsign",value=snam},
},{"OK","Cancel"},{ok='OK',close='Cancel'})
if press=="Cancel" then ak() end
if press=="OK" then
if reslt.newsign=="" then t_error("No name supplied.",1) end
newsgn=reslt.newsign:gsub("%.ass$","")
if reslt.addsign=="Add to signs.ass" then
file=io.open(path.."signs.ass")
if not file then file=io.open(path.."signs.ass","w") end
sign=file:read("*all") or ""
file:close()
exportsign=exportsign:gsub("(%u%a+: %d+,[^,]-,[^,]-,[^,]-,[^,]-,[^,]-,[^,]-,[^,]-),[^,]-,(.-)\n","%1,"..reslt.newsign..",%2\n")
sign=sign:gsub("%u%a+: [^\n]+,"..esc(reslt.newsign)..",.-\n","") :gsub("^\n*","")
sign=sign.."\n"..exportsign
file=io.open(path.."signs.ass","w")
file:write(sign)
end
if reslt.addsign=="Save to new file:" then
file=io.open(path..newsgn..".ass","w")
file:write(exportsign)
end
file:close()
end
end
-- IMPORT CHAPTERS
if res.mega=="import chptrs" then
xml=aegisub.dialog.open("Chapters file (xml)","",scriptpath.."\\","*.xml",false,true)
if xml==nil then ak() end
file=io.open(xml)
xmlc=file:read("*all")
io.close(file)
chc=0
for ch in xmlc:gmatch("<ChapterAtom>(.-)</ChapterAtom>") do
chnam=ch:match("<ChapterString>(.-)</ChapterString>")
chtim=ch:match("<ChapterTimeStart>(.-)</ChapterTimeStart>")
chtim=chtim:gsub("(%d%d):(%d%d):(%d%d)%.(%d%d%d?)(.*)",function(a,b,c,d,e) if d:len()==2 then d=d.."0" end return d+c*1000+b*60000+a*3600000 end)
l2=aline
if fr2ms(1)==nil then chs=chtim else chs=fr2ms(ms2fr(chtim)) end
l2.start_time=chs
l2.end_time=chs+1
l2.actor="chptr"
l2.text="{"..chnam.."}"
subs.insert(act+chc,l2)
chc=chc+1
end
end
-- Update Lyrics
if res.mega=="update lyrics" then
sup1=esc(sub1) sup2=esc(sub2)
for z,i in ipairs(sel) do
progress("Updating Lyrics... "..round(z/#sel)*100 .."%")
line=subs[i]
text=line.text
songlyr=sdata
if line.style:match(rest) then stylecheck=1 else stylecheck=0 end
if res.restr and stylecheck==0 then pass=0 else pass=1 end
if res.field=="actor" then marker=line.actor
elseif res.field=="effect" then marker=line.effect end
denumber=marker:gsub("%d","")
-- marked lines
if marker:match(sup1.."%d+"..sup2) and denumber==sub1..sub2 and pass==1 then
index=tonumber(marker:match(sup1.."(%d+)"..sup2))
puretext=text:gsub("{%*?\\[^}]-}","")
lastag=text:match("({\\[^}]-}).$")
if songlyr[index]~=nil and songlyr[index]~=puretext then
text=text:gsub("^({\\[^}]-}).*","%1"..songlyr[index])
if not text:match("^{\\[^}]-}") then text=songlyr[index] end
end
songcheck=1
if songlyr[index]~=puretext then
if lastag~=nil then text=text:gsub("(.)$",lastag.."%1") end
change=" (Changed)"
else change=""
end
aegisub.log("\nupdate: "..puretext.." --> "..songlyr[index]..change)
end
line.text=text
subs[i]=line
end
end
if res.mega=="update lyrics" and songcheck==0 then press,reslt=ADD({{x=0,y=0,class="label",label="The "..res.field.." field of selected lines doesn't match given pattern \""..sub1.."#"..sub2.."\".\n(Or style pattern wasn't matched if restriction enabled.)\n#=number sequence"}},{"ok"},{cancel='ok'}) end
noshift=nil defect=nil keeptxt=nil deline=nil keeptags=nil addtags=nil
end
-- NUMBERS -------------------------------------------------------------------------------------------
function numbers(subs,sel)
zl=zer:len()
if sub3:match("[,/;]") then startn,int=sub3:match("(%d+)[,/;](%d+)") int=tonumber(int) else startn=sub3:gsub("%[.-%]","") int=1 end
if sub3:match("%[") then numcycle=tonumber(sub3:match("%[(%d+)%]")) else numcycle=0 end
if sub3=="" then startn=1 end
startn=tonumber(startn)
mark=res.field:gsub("left","margin_l"):gsub("right","margin_r"):gsub("vert","margin_t")
if res.modzero=="number lines" and res.intxt then res.field='nope' end
if res.modzero=="number 12321" then
NB={}
if numcycle==0 then t_error("You must set a counting limit 'Y': X[Y]",1) end
for q=startn,numcycle do
qq=0
repeat
table.insert(NB,q)
qq=qq+1
until qq>=int
end
for q=numcycle-1,startn+1,-1 do
qq=0
repeat
table.insert(NB,q)
qq=qq+1
until qq>=int
end
end
if res.modzero=="random" then
if not tonumber(sub1) or not tonumber(sub2) then t_error("No valid input. \nUse Left and Right fields to set limits \nfor random number generation.",1) end
if not tonumber(sub3) or tonumber(sub3)<1 then t_error("Error. Mod must be 1 or higher.",1) end
if string.match("layer style text",res.field) then t_error("Invalid marker. \nOnly actor, effect, comment, and margins.",1) end
ranTab={}
local R=math.ceil(#sel/sub3)
for i=1,R do
local rndm=round(math.random(sub1*1000,sub2*1000)/1000,zl-1)
table.insert(ranTab,rndm)
end
end
for z=1,#sel do
i=sel[z]
line=subs[i]
text=line.text
if res.modzero:match"number" then
progress("Numbering... "..round(z/#sel)*100 .."%")
if startn==nil or numcycle>0 and startn>numcycle then t_error("Wrong parameters. Syntax: start/repeat[limit]\nExamples:\n5 (5 6 7 8...)\n5/3 (5 5 5 6 6 6 7 7 7...)\n5/3[6] (5 5 5 6 6 6 5 5 5 6 6 6...)\n5[6] (5 6 5 6 5 6...)",1) end
local Z=z
if res.modzero=="number lines" then
-- regular numbering
count=math.ceil(Z/int)+(startn-1)
if numcycle>0 and count>numcycle then
repeat count=count-(numcycle-startn+1) until count<=numcycle
end
else -- 1 2 3 4 5 4 3 2 1
if Z>#NB then repeat Z=Z-#NB until Z<=#NB end
count=NB[Z]
end
count=tostring(count)
if zl>count:len() then repeat count="0"..count until zl==count:len() end
if not mark:match'margin' and mark~='layer' then number=sub1..count..sub2 else number=count end
if res.intxt then text=text:gsub("%d+",number)
elseif mark=="comment" then text=text..wrap(number)
elseif mark=="text" then text=number
else line[mark]=number
end
end
if res.modzero=="add to marker" then
progress("Adding... "..round(z/#sel)*100 .."%")
if res.field=="actor" then line.actor=sub1..line.actor..sub2
elseif res.field=="effect" then line.effect=sub1..line.effect..sub2
elseif res.field=="text" then text=sub1..text..sub2
end
end
if res.modzero=="zero fill" then
progress("Filling... "..round(z/#sel)*100 .."%")
form="%0"..zl.."d"
mark=res.field
aet="actoreffect"
if aet:match(mark) then
target=line[mark]
target=target:gsub("(%d+)",function(d) return string.format(form,d) end)
line[mark]=target
end
if mark=='text' then
nt=''
repeat
seg,t2=text:match("^(%b{})(.*)")
if not seg then seg,t2=text:match("^([^{]+)(.*)")
if not seg then break end
seg=seg:gsub("(%-?[%d.]+)",function(d)
if tonumber(d)>0 and not d:match("%.%d") then return string.format(form,d) else return d end
end)
end
nt=nt..seg
text=t2
until text==''
text=nt
end
end
if res.modzero=="random" then
li=math.ceil(z/sub3)
local num=0
for t=1,#ranTab do
if li==t then num=ranTab[t] break end
end
if mark:match "margin" and num<0 then num=0-num end
if mark=="comment" then
text=text..wrap("random: "..num)
else
line[mark]=num
end
end
line.text=text
subs[i]=line
end
end
-- CHAPTERS ------------------------------------------------------------------------------------------------
function chopters(subs,sel)
if res.marker=="effect" and res.nam=="effect" then t_error("Error. Both marker and name cannot be 'effect'.",1) end
if res.chmark then
if res.lang~="" then kap=res.lang else kap=res.chap end
for z,i in ipairs(sel) do
line=subs[i]
text=line.text
if res.marker=="actor" then line.actor="chptr" end
if res.marker=="effect" then line.effect="chptr" end
if res.marker=="comment" then text=text.."{chptr}" end
if res.nam=="effect" then line.effect=kap end
if res.nam=="comment" then text=nobra(text) text=wrap(kap)..text end
line.text=text
subs[i]=line
end
else
euid=2013
chptrs={}
subchptrs={}
if res.lang=="" then clang="eng" else clang=res.lang end
for i=1,#subs do
if subs[i].class=="info" then
if subs[i].key=="Video File" then videoname=subs[i].value videoname=videoname:gsub("%.mkv","") end
end
if subs[i].class=="dialogue" then
line=subs[i]
text=line.text
actor=line.actor
effect=line.effect
start=line.start_time
if text:match("{[Cc]hapter}") or text:match("{[Cc]hptr}") or text:match("{[Cc]hap}") then comment="chapter" else comment="" end
if res.marker=="actor" then marker=actor:lower() end
if res.marker=="effect" then marker=effect:lower() end
if res.marker=="comment" then marker=comment:lower() end
if marker=="chapter" or marker=="chptr" or marker=="chap" then
if res.nam=="comment" then
name=text:match("^{([^}]*)}")
name=name:gsub(" [Ff]irst [Ff]rame",""):gsub(" [Ss]tart",""):gsub("part a","Part A"):gsub("part b","Part B"):gsub("preview","Preview")
else
name=effect
end
if name:match("::") then main,subname=name:match("(.+)::(.+)") sub=1
else sub=0
end
lineid=start+2013+i
timecode=math.floor(start/1000)
tc1=math.floor(timecode/60)
tc2=timecode%60
tc3=start%1000
tc4="00"
if tc2==60 then tc2=0 tc1=tc1+1 end
if tc1>119 then tc1=tc1-120 tc4="02" end
if tc1>59 then tc1=tc1-60 tc4="01" end
if tc1<10 then tc1="0"..tc1 end
if tc2<10 then tc2="0"..tc2 end
if tc3<100 then tc3="0"..tc3 end
linetime=tc4..":"..tc1..":"..tc2.."."..tc3
if linetime=="00:00:00.00" then linetime="00:00:00.033" end
if sub==0 then
cur_chptr={id=lineid,name=name,tim=linetime}
table.insert(chptrs,cur_chptr)
else
cur_chptr={id=lineid,subname=subname,tim=linetime,main=main}
table.insert(subchptrs,cur_chptr)
end
end
if line.style=="Default" then euid=euid+text:len() end
end
end
-- subchapters
subchapters={}
for c=1,#subchptrs do
local ch=subchptrs[c]
ch_main=ch.main
ch_uid=ch.id
ch_name=ch.subname
ch_time=ch.tim
schapter=" <ChapterAtom>\n <ChapterDisplay>\n <ChapterString>"..ch_name.."</ChapterString>\n <ChapterLanguage>"..clang.."</ChapterLanguage>\n </ChapterDisplay>\n <ChapterUID>"..ch_uid.."</ChapterUID>\n <ChapterTimeStart>"..ch_time.."</ChapterTimeStart>\n <ChapterFlagHidden>0</ChapterFlagHidden>\n <ChapterFlagEnabled>1</ChapterFlagEnabled>\n </ChapterAtom>\n"
subchapter={main=ch_main,chap=schapter}
table.insert(subchapters,subchapter)
end
-- chapters
insert_chapters=""
if res.intro then
insert_chapters=" <ChapterAtom>\n <ChapterUID>"..#subs.."</ChapterUID>\n <ChapterFlagHidden>0</ChapterFlagHidden>\n <ChapterFlagEnabled>1</ChapterFlagEnabled>\n <ChapterDisplay>\n <ChapterString>Intro</ChapterString>\n <ChapterLanguage>"..clang.."</ChapterLanguage>\n </ChapterDisplay>\n <ChapterTimeStart>00:00:00.033</ChapterTimeStart>\n </ChapterAtom>\n"
end
table.sort(chptrs,function(a,b) return a.tim<b.tim or (a.tim==b.tim and a.id<b.id) end)
for c=1,#chptrs do
local ch=chptrs[c]
ch_uid=ch.id
ch_name=ch.name
ch_time=ch.tim
local subchaps=""
for c=1,#subchapters do
local subc=subchapters[c]
if subc.main==ch_name then subchaps=subchaps..subc.chap end
end
chapter=" <ChapterAtom>\n <ChapterUID>"..ch_uid.."</ChapterUID>\n <ChapterFlagHidden>0</ChapterFlagHidden>\n <ChapterFlagEnabled>1</ChapterFlagEnabled>\n <ChapterDisplay>\n <ChapterString>"..ch_name.."</ChapterString>\n <ChapterLanguage>"..clang.."</ChapterLanguage>\n </ChapterDisplay>\n"..subchaps.." <ChapterTimeStart>"..ch_time.."</ChapterTimeStart>\n </ChapterAtom>\n"
insert_chapters=insert_chapters..chapter
end
chapters="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<Chapters>\n <EditionEntry>\n <EditionFlagHidden>0</EditionFlagHidden>\n <EditionFlagDefault>0</EditionFlagDefault>\n <EditionUID>"..euid.."</EditionUID>\n"..insert_chapters.." </EditionEntry>\n</Chapters>"
scriptpath=ADP("?script")
scriptname=aegisub.file_name()
scriptname=scriptname:gsub("%.ass","")
if ch_script_path=="relative" then path=scriptpath.."\\"..ch_relative_path end
if ch_script_path=="absolute" then path=ch_absolute_path end
path=path:gsub("([^\\])$","%1/"):gsub("\\$","/")
repeat path,r=path:gsub("\\[^\\]+\\%.%.[\\/]","/") until r==0
if not videoname then videoname=aegisub.project_properties().video_file:gsub("^.*\\",""):gsub("%.mkv","") end
if res.sav=="script" then filename=scriptname else filename=videoname end
chdialog={
{x=0,y=0,width=35,class="label",label="Text to export (You can edit it before saving/copying):"},
{x=0,y=1,width=35,height=20,class="textbox",name="copytext",value=chapters},
{x=0,y=21,width=35,class="label",label='File "'..filename..'.xml" will be saved in "'..path..'"\nIf you want to change the path, use Save Config.'},
{x=35,y=0,width=12,class="label",label="You can also edit this && refresh"}, -- #4
}
q=1
for chn in chapters:gmatch("<ChapterString>(.-)</ChapterString>") do
table.insert(chdialog,{x=35,y=q,width=12,name='ch_'..q,class="edit",value=chn})
q=q+1
end
repeat
if pressed=="Refresh" then
q=0
reslt.copytext=reslt.copytext:gsub("(<ChapterString>).-(</ChapterString>)",function(a,b) q=q+1 return a..reslt["ch_"..q]..b end)
for k,v in ipairs(chdialog) do
if v.class=='edit' then v.value=reslt[v.name] end
if v.name=='copytext' then v.value=reslt.copytext end
end
end
pressed,reslt=ADD(chdialog,{"Save xml file","mp4-compatible chapters","Cancel","Copy to clipboard","Refresh"},{cancel='Cancel'})
until pressed~="Refresh"
chapters=reslt.copytext
if pressed=="Copy to clipboard" then clipboard.set(chapters) end
if pressed=="Save xml file" then
local file=io.open(path..filename..".xml","w")
if file==nil then os.execute("mkdir \""..path.."\"") file=io.open(path..filename..".xml","w") end
if file==nil then t_error("File could not be saved. Probably path doesn't exist:\n"..path,1) end
file:write(chapters)
file:close()
end
if pressed=="mp4-compatible chapters" then
mp4chap=""
m4c=1
for ch in chapters:gmatch("<ChapterAtom>(.-)</ChapterAtom>") do
chnam=ch:match("<ChapterString>(.-)</ChapterString>")
chtim=ch:match("<ChapterTimeStart>(.-)</ChapterTimeStart>")
num=tostring(m4c)
if num:len()==1 then num="0"..num end
chnum="CHAPTER"..num
mp4chap=mp4chap..chnum.."="..chtim.."\n"..chnum.."NAME="..chnam.."\n\n"
m4c=m4c+1
end
chapters=mp4chap:gsub("\n\n$","")
chdialog[2].value=chapters
chdialog[3].label=chdialog[3].label:gsub('%.xml','_chapters.txt')
for c=#chdialog,4,-1 do table.remove(chdialog,c) end
pressed,reslt=ADD(chdialog,{"Save txt file","Cancel","Copy to clipboard"},{cancel='Cancel'})
chapters=reslt.copytext
if pressed=="Copy to clipboard" then clipboard.set(chapters) end
if pressed=="Save txt file" then
local file=io.open(path..filename.."_chapters.txt","w")
if file==nil then os.execute("mkdir \""..path.."\"") file=io.open(path..filename.."_chapters.txt","w") end
file:write(chapters)
file:close()
end
end
end
end
-- STUFF ---------------------------------------------------------------------------------------------------
function stuff(subs,sel,act)
STAG="^{\\[^}]-}"
repl=0
data={} raw=res.dat.."\n"
for dataline in raw:gmatch("(.-)\n") do table.insert(data,dataline) end
nsel={} for z,i in ipairs(sel) do table.insert(nsel,i) end
orig_sel=#sel
nope=nil
if res.stuff=="make style from act. line" then
line=subs[act]
text=line.text
sr=stylechk(subs,line.style)
nontra=text:gsub("\\t%b()","")
tags=nontra:match("^{\\[^}]-}") or ""
a1=tags:match("\\1a&H(%x%x)&") or sr.color1:match("&H(%x%x)")
a2=tags:match("\\2a&H(%x%x)&") or sr.color2:match("&H(%x%x)")
a3=tags:match("\\3a&H(%x%x)&") or sr.color3:match("&H(%x%x)")
a4=tags:match("\\4a&H(%x%x)&") or sr.color4:match("&H(%x%x)")
color1=tags:match("\\1?c&H(%x%x%x%x%x%x)&") or sr.color1:match("&H%x%x(%x%x%x%x%x%x)&")
color2=tags:match("\\2c&H(%x%x%x%x%x%x)&") or sr.color2:match("&H%x%x(%x%x%x%x%x%x)&")
color3=tags:match("\\3c&H(%x%x%x%x%x%x)&") or sr.color3:match("&H%x%x(%x%x%x%x%x%x)&")
color4=tags:match("\\4c&H(%x%x%x%x%x%x)&") or sr.color4:match("&H%x%x(%x%x%x%x%x%x)&")
sr.color1="&H"..a1..color1.."&"
sr.color2="&H"..a2..color2.."&"
sr.color3="&H"..a3..color3.."&"
sr.color4="&H"..a4..color4.."&"
sr.bold=tags:match("\\b([01])") or sr.bold
sr.italic=tags:match("\\i([01])") or sr.italic
sr.underline=tags:match("\\u([01])") or sr.underline
sr.strikeout=tags:match("\\s([01])") or sr.strikeout
sr.fontname=tags:match("\\fn([^\\}]+)") or sr.fontname
sr.fontsize=tags:match("\\fs(%d+)") or sr.fontsize
sr.scale_x=tags:match("\\fscx([^\\}]+)") or sr.scale_x
sr.scale_y=tags:match("\\fscx([^\\}]+)") or sr.scale_y
sr.spacing=tags:match("\\fsp([^\\}]+)") or sr.spacing
sr.angle=tags:match("\\frz([^\\}]+)") or sr.angle
sr.outline=tags:match("\\bord([^\\}]+)") or sr.outline
sr.shadow=tags:match("\\shad([^\\}]+)") or sr.shadow
sr.align=tags:match("\\an(%d)") or sr.align
sr.margin_l=line.margin_l or sr.margin_l
sr.margin_r=line.margin_r or sr.margin_r
sr.margin_t=line.margin_t or sr.margin_t
stylename={{class="label",label="Style Name"},{y=1,class="edit",name="snam",value=""},
{y=2,class="checkbox",name="switch",label="switch to new style",value=true},
{y=3,class="checkbox",name="del",label="delete style tags from line",value=true},
}
pres,rez=ADD(stylename,{"OK","Cancel"},{ok='OK',close='Cancel'})
if pres=="Cancel" then ak() end
sr.name=rez.snam:gsub(",",";")
if rez.del then
tags=text:match(STAG)
tags=tags
:gsub("\\t(%b())",function(t) return "\\tra"..t:gsub("\\","/") end)
:gsub("\\%d?[ac]%b&&","")
:gsub("\\f[ns][^\\}]+","")
:gsub("\\frz[^\\}]+","")
:gsub("\\[ibus][01]","")
:gsub("\\...d[^\\}]+","")
:gsub("\\an%d","")
:gsub("\\tra(%b())",function(t) return "\\t"..t:gsub("/","\\") end)
:gsub("{}","")
line.text=text:gsub(STAG,tags)
line.margin_l=0
line.margin_r=0
line.margin_t=0
end
if rez.switch then line.style=sr.name end
subs[act]=line
for i=1,#subs do
if subs[i].class=="style" then
st=subs[i]
if st.name==sr.name then t_error("Style with that name already exists",1) end
end
if subs[i].class=="dialogue" then subs.insert(i,sr)
for z,s in ipairs(sel) do sel[z]=sel[z]+1 end
break end
end
end
-- DATES GUI --
if res.stuff=="format dates" then
dategui=
{{x=0,y=0,class="dropdown",name="date",value="January 1st",items={"January 1","January 1st","1st of January","1st January"}},
{x=1,y=0,class="checkbox",name="log",label="log",value=false,}}
pres,rez=ADD(dategui,{"OK","Cancel"},{ok='OK',close='Cancel'})
if pres=="Cancel" then ak() end
datelog=""
end
-- EXPLODE GUI --
if res.stuff=="explode" then
-- remember values
if exploded then
exx=expl_dist_x exy=expl_dist_y htype=ex_hor vtype=ex_ver expropx=xprop expropy=yprop exf=exfad cfad=cfade
exinvx=xinv exinvy=yinv implo=implode exquence=exseq exkom=excom seqinv=invseq seqpercent=seqpc rmmbr=exremember
else
exx=0 exy=0 htype="all" vtype="all" expropx=false expropy=false exf=0 cfad=0 exinvx=false exinvy=false
implo=false exquence=false exkom=false seqinv=false seqpercent=100 rmmbr=false
end
explodegui={
{x=0,y=0,class="label",label="Horizontal distance: "},
{x=1,y=0,class="floatedit",name="edistx",value=exx,hint="Maximum horizontal distance for move"},
{x=0,y=1,class="label",label="Vertical distance: "},
{x=1,y=1,class="floatedit",name="edisty",value=exy,hint="Maximum vertical distance for move"},
{x=2,y=0,class="label",label="direction: "},
{x=3,y=0,class="dropdown",name="hortype",value=htype,items={"only left","mostly left","all","mostly right","only right"}},
{x=4,y=0,class="checkbox",name="xprop",label="proportional",value=expropx,hint="Uniform move rather than random"},
{x=5,y=0,class="checkbox",name="xinv",label="inverse",value=exinvx,hint="Uniform move in the other direction"},
{x=2,y=1,class="label",label="direction: "},
{x=3,y=1,class="dropdown",name="vertype",value=vtype,items={"only up","mostly up","all","mostly down","only down"}},
{x=4,y=1,class="checkbox",name="yprop",label="proportional",value=expropy,hint="Uniform move rather than random"},
{x=5,y=1,class="checkbox",name="yinv",label="inverse",value=exinvy,hint="Uniform move in the other direction"},
{x=0,y=2,class="checkbox",name="ecfo",label="Custom fade:",hint="Default is line length",value=cfad},
{x=1,y=2,class="floatedit",name="exfad",value=exf},
{x=2,y=2,class="checkbox",name="exseq",label="sequence",value=exquence,hint="move in a sequence instead of all at the same time"},
{x=3,y=2,class="floatedit",name="seqpc",value=seqpercent,step=nil,min=1,max=100,hint="how much time should the sequence take up"},
{x=4,y=2,class="label",label="% of move"},
{x=5,y=2,class="checkbox",name="invseq",label="inverse",value=seqinv,hint="inverse sequence"},
{x=0,y=3,class="checkbox",name="impl",label="Implode",value=implo},
{x=1,y=3,class="checkbox",name="rem",label="Same for all lines",value=rmmbr,hint="use only for layered lines with the same text"},
{x=3,y=3,class="checkbox",name="excom",label="Leave original line commented out",value=exkom,width=3},
}
pres,rez=ADD(explodegui,{"OK","Cancel"},{ok='OK',close='Cancel'})
if pres=="Cancel" then ak() end
expl_dist_x=rez.edistx expl_dist_y=rez.edisty
exfad=rez.exfad cfade=rez.ecfo
ex_hor=rez.hortype ex_ver=rez.vertype
xprop=rez.xprop yprop=rez.yprop
xinv=rez.xinv yinv=rez.yinv
implode=rez.impl exseq=rez.exseq
seqpc=round(rez.seqpc) invseq=rez.invseq
exremember=rez.rem excom=rez.excom
exploded=true
end
-- Randomised Transforms GUI --
if res.stuff=="randomised transforms" then
rine=subs[sel[1]]
durone=rine.end_time-rine.start_time
rtgui={
{x=0,y=0,class="checkbox",name="rtfad",label="Random Fade",width=2,value=true},
{x=0,y=1,class="checkbox",name="rtdur",label="Random Duration",width=2,value=true},
{x=2,y=0,class="label",label="Min: "},
{x=2,y=1,class="label",label="Max: "},
{x=3,y=0,class="floatedit",name="minfad",value=math.floor(durone/5),min=0},
{x=3,y=1,class="floatedit",name="maxfad",value=durone},
{x=4,y=0,class="checkbox",name="rtin",label="Fade In",width=3,value=false,hint="In instead of Out"},
{x=4,y=1,class="checkbox",name="maxisdur",label="Max = Current Duration",width=4,value=true,hint="The maximum will be the duration of each selected line"},
{x=0,y=2,class="checkbox",name="movet",label="t1+t2 in \\move",width=2,hint="use given timecodes in \\move"},
{x=2,y=2,class="label",label="\\t 1"},
{x=4,y=2,class="label",label="\\t 2"},
{x=3,y=2,class="floatedit",name="t1",value=0},
{x=5,y=2,class="floatedit",name="t2",value=0,width=3},
{x=0,y=3,class="label",label="Transform"},
{x=1,y=3,class="dropdown",name="rttag",value="blur",
items={"blur","bord","shad","fs","fsp","fscx","fscy","fax","fay","frz","frx","fry","xbord","ybord","xshad","yshad"}},
{x=2,y=3,class="label",label="Min: "},
{x=4,y=3,class="label",label=" Max: "},
{x=3,y=3,class="floatedit",name="mintfn",value=0,hint="Minimum value for a given tag"},
{x=5,y=3,class="floatedit",name="maxtfn",width=3,value=0,hint="Maximum value for a given tag"},
{x=0,y=4,class="label",width=2,label="Colour Transform"},
{x=2,y=4,class="label",label="Max: "},
{x=3,y=4,class="floatedit",name="rtmaxc",value=100,min=1,max=100,hint="Maximum % of colour change.\nColour tag must be present. Otherwise set to 100%."},
{x=4,y=4,class="label",label="%"},
{x=5,y=4,class="checkbox",name="rtc1",label="\\c ",value=true},
{x=6,y=4,class="checkbox",name="rtc3",label="\\3c ",value=false},
{x=7,y=4,class="checkbox",name="rtc4",label="\\4c ",value=false},
{x=0,y=5,class="checkbox",name="rtacc",label="Use Acceleration",width=2,value=false},
{x=2,y=5,class="label",label="Min: "},
{x=3,y=5,class="floatedit",name="minacc",value=1,min=0},
{x=4,y=5,class="label",label=" Max:"},
{x=5,y=5,class="floatedit",name="maxacc",width=3,value=1,min=0},
{x=0,y=6,class="checkbox",name="rtmx",label="Random Move X",width=2,value=false},
{x=2,y=6,class="label",label="Min: "},
{x=3,y=6,class="floatedit",name="minmx",value=0},
{x=4,y=6,class="label",label=" Max:"},
{x=5,y=6,class="floatedit",name="maxmx",width=3,value=0},
{x=0,y=7,class="checkbox",name="rtmy",label="Random Move Y",width=2,value=false},
{x=2,y=7,class="label",label="Min: "},
{x=3,y=7,class="floatedit",name="minmy",value=0},
{x=4,y=7,class="label",label=" Max:"},
{x=5,y=7,class="floatedit",name="maxmy",width=3,value=0},
}
if rtremember then
for key,val in ipairs(rtgui) do
if val.class~="label" then val.value=rez[val.name] end
end
end
rtchoice={"Fade/Duration","Number Transform","Colour Transform","Help","Cancel"}
rthlp={"Fade/Duration","Number Transform","Colour Transform","Cancel"}
pres,rez=ADD(rtgui,rtchoice,{ok='Fade/Duration',close='Cancel'})
if pres=="Help" then
rthelp={x=0,y=8,width=8,height=6,class="textbox",value="This is supposed to be used after 'split into letters (alpha)' or with gradients.\n\nFade/Duration Example: Min: 500, Max: 2000.\nA random number between those is generated for each line, let's say 850.\nThis line's duration will be 850ms, and it will have a 850ms fade out.\n\nNumber Transform Example: Blur, Min: 0.6, Max: 2.5\nRandom number generated: 1.7. Line will have: \\t(\\blur1.7)\n\nRandom Colour Transform creates transforms to random colours. \nMax % transform limits how much the colour can change.\n\nAccel works with either transform function.\n\nRandom Move works as an additional option with any function.\nIt can be used on its own if you uncheck other stuff. Works with Fade In."}
table.insert(rtgui,rthelp)
pres,rez=ADD(rtgui,rthlp,{ok='Fade/Duration',close='Cancel'})
end
if pres=="Cancel" then ak() end
if pres=="Fade/Duration" then RTM="FD" end
if pres=="Number Transform" then RTM="NT" end
if pres=="Colour Transform" then RTM="CT" end
rtremember=true
RTF=rez.rtfad RTD=rez.rtdur
MnF=rez.minfad MxF=rez.maxfad
RTin=rez.rtin RTMax=rez.maxisdur
RTT=rez.rttag MnT=rez.mintfn MxT=rez.maxtfn
RTA=rez.rtacc MnA=rez.minacc MxA=rez.maxacc
MnX=rez.minmx MxX=rez.maxmx MnY=rez.minmy MxY=rez.maxmy
MxC=round(rez.rtmaxc*255/100)
rtcol={}
if rez.rtc1 then table.insert(rtcol,1) end
if rez.rtc3 then table.insert(rtcol,3) end
if rez.rtc4 then table.insert(rtcol,4) end
t_times=""
end
-- Clone Clip GUI --
if res.stuff=="clone clip" then
if clone_h then cchc=clone_h else cchc=2 end
if clone_v then ccvc=clone_v else ccvc=2 end
if dist_h then cchd=dist_h else cchd=20 end
if dist_v then ccvd=dist_v else ccvd=20 end
if ccshift then ccsh=ccshift else ccsh=0 end
ccgui={
{x=0,y=0,class="label",label="Horizontal distance: "},
{x=1,y=0,class="intedit",name="hdist",value=cchd,min=1},
{x=0,y=1,class="label",label="Horizontal clones: "},
{x=1,y=1,class="intedit",name="hclone",value=cchc,min=1},
{x=0,y=2,class="label",label="Vertical distance: "},
{x=1,y=2,class="intedit",name="vdist",value=ccvd,min=1},
{x=0,y=3,class="label",label="Vertical clones: "},
{x=1,y=3,class="intedit",name="vclone",value=ccvc,min=1},
{x=0,y=4,class="label",label="Shift even rows by:"},
{x=1,y=4,class="intedit",name="ccshift",value=ccsh,min=0},
}
pres,rez=ADD(ccgui,{"OK","Cancel"},{ok='OK',close='Cancel'})
if pres=="Cancel" then ak() end
clone_h=rez.hclone dist_h=rez.hdist
clone_v=rez.vclone dist_v=rez.vdist
ccshift=rez.ccshift
end
-- DISSOLVE GUI ---------------------------------------------------------------------------------------------
if res.stuff=="dissolve text" then
if dlast then ddistance=v_dist ddlines=dlines dshape=shape dalter=alternate dissin=disin otherd=otherdis v2direction=v2d
else ddistance=10 ddlines=10 dshape="square" dalter=true dissin=false otherd=false v2direction="randomly"
end
dissgui={