Code:
// Grid of videos - automatically draws any number of videos from tracks with grid
//@param 1:boss "Lead Track Number" 2 2 10 6 1
//@param 2:Nbig "Lead Grid Size" 1 1 9 5 1
//@param 3:bossexpand "Expand Lead Track" 0 0 1 0.5 0.01
//@param 4:bossfront "Lead to Front" 0 0 1 0.5 1
//@param 5:yposratio "Y Offset" 0 0 1 0.5 0.01
//@param 6:border "Grid Borders" 5 0 720 360 1
//@param 7:presasp "Stretch/Crop/Full" 0.5 0 1 0.5 0.5
//@param 8:portrait "Landscape/Sq/Portrait" 0 0 1 0.5 0.5
//@param 9:background "Backdrop Color/Video" 0 0 1 0.5 1
//@param 10:R "Backdrop Red" 0.1 0 1 0.5 0.01
//@param 11:G "Backdrop Green" 0.1 0 1 0.5 0.01
//@param 12:B "Backdrop Blue" 0.5 0 1 0.5 0.01
//@param 13:LeadDoubled "Lead Track Doubled" 0 0 1 0.5 1
presasp == 0.5 ? (crop = 1; presasp = 0) : crop = 0; //presasp = 0.5 means crop videos
aspect = project_w/project_h; // aspect ratio of project
boss = boss - 1; // boss is now relative to video processor track
ypos = yposratio*project_h;
Ntracks = input_track_count(); // Number of video files
boss>Ntracks ? boss = Ntracks; // If the lead video track set is greater than Ntracks use last
((boss>0)&(bossexpand==1)&(bossfront==1)) ? // if there is a lead track fully expanded on front then plot it
(
crop == 1 ? //crop code
(
input_info(input_track(boss-1),prewidth,preheight);
project_w/project_h<prewidth/preheight ? //crop from width
(wsrc_expand = (preheight*(project_w/project_h));//source width
hsrc_expand = preheight;//source height
xsrc_expand = (prewidth - wsrc_expand)/2;//source x
ysrc_expand = 0;)//source y
: //else crop from height
(wsrc_expand = prewidth;
hsrc_expand = (prewidth*(project_h/project_w));
xsrc_expand = 0;
ysrc_expand = (preheight - hsrc_expand)/2;);
)
:
(xsrc_expand = 0;ysrc_expand = 0;wsrc_expand = prewidth; hsrc_expand = preheight);
gfx_blit(
input_track(boss-1),
presasp,// preserve aspect ratio
0, 0, project_w, project_h, // output x, y, width and height
xsrc_expand,ysrc_expand,wsrc_expand,hsrc_expand // source x, y, width and height
);
)
: // if there isn't a lead track on front then do the rest of the code
(
gfx_set(0);
gfx_fillrect(0,0,project_w,project_h);
x=0; // Counter for looping
Ntracks > 0 // If there are video tracks
?
count_tracks = Ntracks + Nbig^2 - 1 + LeadDoubled// Number of grid locations
: //else
count_tracks = 0
;
portrait == 0
?// if landscape source videos
(
xoffset = 0;
border_h = border;
border_w = border*aspect;
height = project_h - border_h;
width = project_w - border_w;
cols = ceil(sqrt(count_tracks));
rows = ceil(count_tracks/cols);
vHeight = height / cols - border_h; // Video height
vWidth = width / cols - border_w; // Video Width
)
: portrait == 0.5 ? //else if sqaure grid
(
xoffset = 0;
rows = ceil(sqrt(count_tracks/aspect));
cols = ceil(count_tracks/rows);
border_h = border;
border_w = border*aspect*rows/cols;
height = project_h - border_h;
width = project_w - border_w;
vHeight = height / rows - border_h;
vWidth = width / cols - border_w;
)
: // else we assume portrait source videos
(
border_h = border*aspect;
border_w = border;
height = project_h - border_h;
width = project_w - border_w;
rows = ceil((sqrt(count_tracks))/aspect);
cols = ceil(count_tracks/rows);
rows_alt = rows - 1;
cols_alt = ceil(count_tracks/rows_alt);
rows*(aspect^2)>cols_alt ? (cols = cols_alt;rows = rows_alt;); // if reducing rows by one is better
rows<Nbig ? (rows = Nbig; cols = ceil(count_tracks/rows);); // if number of rows is less than Nbig
vWidth = width / cols - border_w;
vHeight = height / rows - border_h;
aspect < (vHeight/vWidth) // if fitting to width
?
(xoffset = 0;
vHeight = vWidth*aspect;)
: // else fitting to height
(vWidth = vHeight / aspect;
xoffset = (project_w - (cols*vWidth + (cols+1)*border_w))/2;
);
);
Nbig>1 ? // if one of the videos is chosen to be big then put lead track in centre
(
left_cols = floor((cols - Nbig)/2); // Number of columns before big central video
top_rows = floor((rows - Nbig)/2); // Number of rows before big central video
)
: // else all videos same size then lead tracks stays where it is
(
top_rows = floor((boss-1)/cols);
left_cols = (boss-1) % cols;
);
background == 1
?
gfx_blit(0) // If background is 1 then show current track image or video as background
:
(
gfx_set(R,G,B,1); //Set color for background
gfx_fillrect(0,0,project_w,project_h); // show color as background
);
bossfront==0 // if the lead track is behind plot it first
?
(
(boss-1 >= (cols*rows - cols)) // Is it the last line?
?
(
lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row
lastLineOffset = (project_w - (lastLineCount*vWidth + (lastLineCount+1)*border_w))/2;
xpos = left_cols*vWidth + lastLineOffset + border_w*left_cols; // x position last line
)
:
xpos = left_cols*vWidth + border_w*left_cols + xoffset; // x position non-last line
input_info(input_track(boss-1),prewidth,preheight);
xpos_expand = (1-bossexpand)*(border_w + xpos);
ypos_expand = (1-bossexpand)*(border_h + vHeight*(top_rows) + border_h*(top_rows) + ypos);
vWidth_expand = (1-bossexpand)*(Nbig*vWidth+(Nbig-1)*border_w) + bossexpand*project_w;
vHeight_expand = (1-bossexpand)*(Nbig*vHeight+(Nbig-1)*border_h) + bossexpand*project_h;
crop == 1 ? //crop code
(
vWidth_expand/vHeight_expand<prewidth/preheight ? //crop from width
(wsrc_expand = (preheight*(vWidth_expand/vHeight_expand));
hsrc_expand = preheight;
xsrc_expand = (prewidth - wsrc_expand)/2;
ysrc_expand = 0;)
: //else
(wsrc_expand = prewidth;
hsrc_expand = (prewidth*(vHeight_expand/vWidth_expand));
xsrc_expand = 0;
ysrc_expand = (preheight - hsrc_expand)/2;);
)
:
(
xsrc_expand = 0;ysrc_expand = 0;wsrc_expand = prewidth; hsrc_expand = preheight;
);
//plot code
gfx_blit(
input_track(boss-1), presasp,
xpos_expand, ypos_expand, vWidth_expand, vHeight_expand,
xsrc_expand,ysrc_expand,wsrc_expand,hsrc_expand
);
);
bosscount = 0; // Counter for taking into account boss video
loop(count_tracks + LeadDoubled, //main loop
row = floor(x/cols); // Column position (starts at 0)
col = x % cols; // Row position (starts at 0)
lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row
lastLineOffset = (project_w - (lastLineCount*vWidth + (lastLineCount+1)*border_w))/2;
((x >= (cols*rows - cols))&(bosscount > Nbig^2 - 2)) // Is it the last line and after any big video?
? xpos = col*vWidth + lastLineOffset + border_w*col // last line
: xpos = col*vWidth + border_w*col + xoffset // non-last line
;
((row>top_rows-1)&(col>left_cols-1)&(row<top_rows+Nbig)&(col<left_cols+Nbig))
? // if the grid number is part of big video
bosscount = bosscount + 1 // increment counter
: // else
x-bosscount+1-LeadDoubled < Ntracks // if video exists
?
(vidnum = x-bosscount+1;
((vidnum < boss) | (LeadDoubled)) ? vidnum = vidnum - 1;
//crop code
input_info(input_track(vidnum),prewidth,preheight);//get dimensions
vxpos = border_w + xpos; //x position
vypos = border_h + vHeight*(row) + border_h*(row) + ypos; //y position
crop == 1 ? //crop code
(
vWidth/vHeight<prewidth/preheight ? //crop from width
(wsrc = preheight*(vWidth/vHeight);//source width
hsrc = preheight;//source height
xsrc = (prewidth - wsrc)/2;//source x
ysrc = 0;)//source y
: //else
(wsrc = prewidth;
hsrc = prewidth*(vHeight/vWidth);
xsrc = 0;
ysrc = (preheight - hsrc)/2;);
)
:
(xsrc = 0; ysrc = 0; wsrc = prewidth; hsrc = preheight);
//plot code
gfx_blit(
input_track(vidnum), presasp,
vxpos, vypos, vWidth, vHeight,
xsrc,ysrc,wsrc,hsrc
);
);
x += 1;
);
bossfront==1 //If the boss is in front plot
?
(
(boss-1 >= (cols*rows - cols)) // Is it the last line?
?
(
lastLineCount = (count_tracks-1) % cols + 1; // Number of videos in last row
lastLineOffset = (project_w - (lastLineCount*vWidth + (lastLineCount+1)*border_w))/2;
xpos = left_cols*vWidth + lastLineOffset + border_w*left_cols; // last line
)
: //else not the last line
xpos = left_cols*vWidth + border_w*left_cols + xoffset; // non-last line
//crop code
input_info(input_track(boss-1),prewidth,preheight);
xpos_expand = (1-bossexpand)*(border_w + xpos);
ypos_expand = (1-bossexpand)*(border_h + vHeight*(top_rows) + border_h*(top_rows) + ypos);
vWidth_expand = (1-bossexpand)*(Nbig*vWidth+(Nbig-1)*border_w) + bossexpand*project_w;
vHeight_expand = (1-bossexpand)*(Nbig*vHeight+(Nbig-1)*border_h) + bossexpand*project_h;
crop == 1 ? //crop code
(
vWidth_expand/vHeight_expand<prewidth/preheight ? //crop from width
(wsrc_expand = (preheight*(vWidth_expand/vHeight_expand));
hsrc_expand = preheight;
xsrc_expand = (prewidth - wsrc_expand)/2;
ysrc_expand = 0;)
: //else
(wsrc_expand = prewidth;
hsrc_expand = (prewidth*(vHeight_expand/vWidth_expand));
xsrc_expand = 0;
ysrc_expand = (preheight - hsrc_expand)/2;);
)
:
(
xsrc_expand = 0; ysrc_expand = 0; wsrc_expand = prewidth; hsrc_expand = preheight;
);
gfx_blit(
input_track(boss-1), presasp,
xpos_expand, ypos_expand, vWidth_expand, vHeight_expand,
xsrc_expand,ysrc_expand,wsrc_expand,hsrc_expand
);
);
);