forked from unanimated/luaegisub
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unanimated
committed
Jun 24, 2014
1 parent
11132d1
commit 68265ef
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
script_name="Duplicate and Shift" | ||
script_description="old Aegisub's Ctrl+D function" | ||
script_author="unanimated" | ||
script_version="1.1" | ||
|
||
all_at_the_end=true -- if true, all new lines go after the end time of the last line. if false, each new line goes right after its original. | ||
|
||
function duplishift(subs, sel) | ||
last=subs[sel[#sel]] | ||
endtime=last.end_time | ||
ms2fr=aegisub.frame_from_ms | ||
fr2ms=aegisub.ms_from_frame | ||
shiftframe=ms2fr(endtime) | ||
newsel={} | ||
for i=#sel,1,-1 do | ||
line=subs[sel[i]] | ||
l2=line | ||
startfr=ms2fr(l2.start_time) | ||
endfr=ms2fr(l2.end_time) | ||
if all_at_the_end then | ||
if line.end_time==endtime then line.end_time=fr2ms(shiftframe) subs[sel[i]]=line end | ||
l2.start_time=fr2ms(shiftframe) | ||
l2.end_time=fr2ms(shiftframe+1) | ||
else | ||
line.start_time=fr2ms(startfr) | ||
line.end_time=fr2ms(endfr) subs[sel[i]]=line | ||
l2.start_time=fr2ms(endfr) | ||
l2.end_time=fr2ms(endfr+1) | ||
end | ||
subs.insert(sel[#sel]+1,l2) | ||
table.insert(newsel,sel[#sel]+i) | ||
end | ||
return newsel | ||
end | ||
|
||
aegisub.register_macro(script_name, script_description, duplishift) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
-- This is a quick snap-to-keyframe script for timers who would like to have this hotkeyed for whatever reason. Works on selected lines. | ||
|
||
script_name="Snap" | ||
script_description="Snaps to nearby keyframes" | ||
script_author="unanimated" | ||
script_version="1.1" | ||
|
||
-- SETTINGS | ||
|
||
kfsb=6 -- starts before | ||
kfeb=10 -- ends before | ||
kfsa=8 -- starts after | ||
kfea=15 -- ends after | ||
|
||
-- END OF SETTINGS | ||
|
||
function keyframesnap(subs, sel) | ||
keyframes=aegisub.keyframes() | ||
ms2fr=aegisub.frame_from_ms | ||
fr2ms=aegisub.ms_from_frame | ||
|
||
if subs[sel[1]].effect=="gui" then | ||
gui={ | ||
{x=0,y=0,width=1,height=1,class="label",label="Starts before "}, | ||
{x=0,y=1,width=1,height=1,class="label",label="Ends before "}, | ||
{x=0,y=2,width=1,height=1,class="label",label="Starts after "}, | ||
{x=0,y=3,width=1,height=1,class="label",label="Ends after "}, | ||
{x=1,y=0,width=1,height=1,class="floatedit",name="sb",value=6}, | ||
{x=1,y=1,width=1,height=1,class="floatedit",name="eb",value=10}, | ||
{x=1,y=2,width=1,height=1,class="floatedit",name="sa",value=8}, | ||
{x=1,y=3,width=1,height=1,class="floatedit",name="ea",value=12}, | ||
} | ||
buttons={"OK","Cancel"} | ||
pressed,res=aegisub.dialog.display(gui,buttons,{ok='OK',close='Cancel'}) | ||
if pressed=="Cancel" then aegisub.cancel() end | ||
kfsb=res.sb | ||
kfeb=res.eb | ||
kfsa=res.sa | ||
kfea=res.ea | ||
end | ||
|
||
for z, i in ipairs(sel) do | ||
line=subs[i] | ||
start=line.start_time | ||
endt=line.end_time | ||
startn=start | ||
endtn=endt | ||
startf=ms2fr(start) | ||
endf=ms2fr(endt) | ||
diff=250 | ||
diffe=250 | ||
startkf=keyframes[1] | ||
endkf=keyframes[#keyframes] | ||
|
||
for k,kf in ipairs(keyframes) do | ||
if kf>=startf-kfsa and kf<=startf+kfsb then | ||
sdiff=math.abs(startf-kf) | ||
if sdiff<=diff then diff=sdiff startkf=kf startn=fr2ms(startkf) end | ||
end | ||
if kf>=endf-kfea and kf<=endf+kfeb then | ||
ediff=math.abs(endf-kf) | ||
if ediff<diffe then diffe=ediff endkf=kf endtn=fr2ms(endkf) end | ||
end | ||
end | ||
|
||
if startn==nil then startn=start end | ||
if endtn==nil then endtn=endt end | ||
line.start_time=startn | ||
line.end_time=endtn | ||
subs[i]=line | ||
end | ||
aegisub.set_undo_point(script_name) | ||
return sel | ||
end | ||
|
||
aegisub.register_macro(script_name, script_description, keyframesnap) |