View Full Version : Implicit last in user function


gyth
14th February 2012, 03:14
I'm trying to make a user function that adds onto last implicitly.
I was having trouble getting it to work when last hadn't been defined yet.
This is working now, but I was wondering about alternatives, because this seems pretty hacky.
GLOBAL clip_a=openA("M:\sush\1.avi")
GLOBAL clip_b=openB("M:\dk\1.avi")
GLOBAL clip_c=openC("M:\DW\1.avi")
GLOBAL clip_d=open("M:\Shia\1.avi")

GLOBAL last_a=0
GLOBAL last_b=0
GLOBAL last_c=0
GLOBAL last_d=0

function multi_trim(val last_clip, int a, int b, int c, int d){
v1=clip_a.trim(last_a,a-1)
v2=clip_b.trim(last_b,b-1).ChangeFPS(30)
v3=clip_c.trim(last_c,c-1)
v4=clip_d.trim(last_d,d-1).convertFPS(30)
GLOBAL last_a=a
GLOBAL last_b=b
GLOBAL last_c=c
GLOBAL last_d=d
out=stackvertical(stackhorizontal(v1,v2),
\ stackhorizontal(v3,v4))
isclip(last_clip) ? last_clip ++ out : out
}

multi_trim("not a clip",58,1069,68,531) #New Game
multi_trim(231,1470,283,617) #beach
multi_trim(6205,13837,6414,3081) # dr. speech bubble
multi_trim(6535,14560,6775,3224) # confirm

Gavino
14th February 2012, 12:06
Perhaps a 'cleaner' way is to separate the construction and the appending into two different functions:
function multi_trim1(int a, int b, int c, int d){
v1=clip_a.trim(last_a,a-1)
v2=clip_b.trim(last_b,b-1).ChangeFPS(30)
v3=clip_c.trim(last_c,c-1)
v4=clip_d.trim(last_d,d-1).convertFPS(30)
GLOBAL last_a=a
GLOBAL last_b=b
GLOBAL last_c=c
GLOBAL last_d=d
out=stackvertical(stackhorizontal(v1,v2),
\ stackhorizontal(v3,v4))
return out
}

function multi_trim(clip last_clip, int a, int b, int c, int d){
return last_clip ++ multi_trim1(a, b, c, d)}

multi_trim1(58,1069,68,531) #New Game
multi_trim(231,1470,283,617) #beach
multi_trim(6205,13837,6414,3081) # dr. speech bubble
multi_trim(6535,14560,6775,3224) # confirm

However, I don't understand the point of calling the function several times. Since each time it starts from where the previous one ended, it seems your 4 calls do the same as the last one on its own:
multi_trim(6535,14560,6775,3224)

Or is the idea that you can reset last_a, etc, between calls? (in which case they might as well be parameters instead of globals)

gyth
14th February 2012, 17:11
Perhaps a 'cleaner' way is to separate the construction and the appending into two different functions:

That looks better, thank you.

However, I don't understand the point of calling the function several times. Since each time it starts from where the previous one ended, it seems your 4 calls do the same as the last one on its own:
multi_trim(6535,14560,6775,3224)

The v1-4 aren't all the same length.
Stacking them will repeat the last frame of the ones that finish early until the slowest one is done.
http://www.youtube.com/watch?v=nSZ2pwiBpec

Gavino
14th February 2012, 17:43
The v1-4 aren't all the same length.
Stacking them will repeat the last frame of the ones that finish early until the slowest one is done.
Ah yes, sorry, I hadn't spotted that.
It makes more sense to me now.