Skip to content

Commit 80f23e6

Browse files
committed
I'm crushing your head!
1 parent 16e1cb6 commit 80f23e6

2 files changed

Lines changed: 107 additions & 31 deletions

File tree

apps/media/VideoCutter.js

Lines changed: 106 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ playbackRate callback every n secs of the video's timeline
6262
I'm not sure what the supposed "snap to boundaries" stuff @FWPHUNKM is *really*
6363
doing. Particularly, the 'cur_clust' array is not used for anything at all.
6464
65+
* * *
66+
67+
Setting USE_TIMELINE_X > 0 below means that we will be able to see all of the first preview image,
68+
but when we are at the start of the video, it means that the first time marker is at the
69+
position of USE_TIMELINE_X (so that everything to the left of it would be negative time). Doing
70+
this then messes up our calculations for get_visual_time_bounds(), with the result being
71+
that it is possible for the marker to move off the right edge of the window, but it
72+
is still taken to be visible by the logic. So to be perfectly "pixel precise" about everything,
73+
we need to figure out how to account for USE_TIMELINE_X.
74+
6575
»*/
6676
/*9/9/25:«
6777
@@ -209,6 +219,8 @@ ALL OF THE ISSUES CENTER AROUND THE PADDING GIMMICK @WJHGLVG.
209219

210220
//let GRID_W = 125;
211221
let GRID_W = 175;
222+
let USE_TIMELINE_X = GRID_W / 2;
223+
//let USE_TIMELINE_X = 0;
212224

213225
//Vars«
214226

@@ -308,7 +320,6 @@ let total_scroll;
308320
//let TIMELINE_H = 35;
309321
let TIMELINE_H = 42;
310322
//let TIMELINE_H = 35;
311-
let USE_TIMELINE_X = 0;
312323
let PIX_PER_SEC = 10;
313324

314325
let MAX_MAG_LEVEL = 10000;
@@ -364,6 +375,8 @@ let TLX;
364375

365376
let use_padl=0;
366377

378+
let USE_ADJ_SEC = USE_TIMELINE_X / mag_pix_per_sec;
379+
367380
//»
368381

369382
//DOM«
@@ -491,14 +504,17 @@ Main._add(overdiv);
491504
const bot_wrap = make('div');
492505
bot_wrap._pos = "absolute";
493506
bot_wrap._b = 0;
507+
bot_wrap._bgcol = "#000";
494508
bot_wrap._w="100%";
495509
bot_wrap._add(img_div);
496510
bot_wrap._add(timeline);
497511

512+
//bot_wrap._x = USE_TIMELINE_X;
513+
bot_wrap._padl = USE_TIMELINE_X;
514+
//bot_wrap._padl = USE_TIMELINE_X;
498515
//bot_wrap._padl = GRID_W_HALF/2;
499516

500517
Main._add(bot_wrap);
501-
502518
//log(img_div);
503519
//log(timeline);
504520

@@ -1123,7 +1139,7 @@ cwarn("No output");
11231139
}
11241140
is_waiting = false;
11251141
};//»
1126-
1142+
/*
11271143
const scroll_elem = (elem, tm, x_off, bounds_start_arg)=>{//«
11281144
let offset = get_timeline_offset(tm, bounds_start_arg);
11291145
if (offset < -10||offset>Main._w+10) elem._dis = "none";
@@ -1137,6 +1153,20 @@ mark._scroll = ()=>{
11371153
scroll_elem(mark, vid.currentTime, TIME_MARK_X_OFF);
11381154
}
11391155
//»
1156+
*/
1157+
const scroll_elem = (elem, tm, x_off, bounds_start_arg)=>{//«
1158+
let offset = get_timeline_offset(tm, bounds_start_arg);
1159+
// if (offset < -10||offset>Main._w+10) elem._dis = "none";
1160+
// else{
1161+
elem._dis = "";
1162+
elem._x = x_off + offset;
1163+
elem._padl = use_padl;
1164+
// }
1165+
};
1166+
mark._scroll = ()=>{
1167+
scroll_elem(mark, vid.currentTime, TIME_MARK_X_OFF);
1168+
}
1169+
//»
11401170
const scroll_timeline = (which, opts={}) => {//«
11411171
/*
11421172
This is either called by scroll_time_marker or by handle_arrow.
@@ -1161,8 +1191,8 @@ This is either called by scroll_time_marker or by handle_arrow.
11611191
}
11621192
let gotx = tm_x + inc;
11631193

1164-
let diff = Main._w - ((viddur+(gotx/mag_pix_per_sec)) * mag_pix_per_sec);
11651194
let did_adjust = false;
1195+
let diff = Main._w - ((viddur+(gotx/mag_pix_per_sec)) * mag_pix_per_sec);
11661196
if(diff > 0){
11671197
//log("DID ADJUST", diff);
11681198
// did_adjust = true;
@@ -1215,12 +1245,12 @@ const scroll_time_marker = (which, opts={}) => {//«
12151245
else if (gotto < 0) gotto = 0;
12161246
let round_to = round_ms(gotto);
12171247
if (dir > 0){
1218-
if (round_to > round_ms(get_visual_time_bounds().end)){
1248+
if (round_to > round_ms(get_visual_time_bounds().end - USE_ADJ_SEC)){
12191249
scroll_timeline("RIGHT");
12201250
}
12211251
}
12221252
else{
1223-
if (round_to < round_ms(get_visual_time_bounds().start)){
1253+
if (round_to < round_ms(get_visual_time_bounds().start - USE_ADJ_SEC)){
12241254
scroll_timeline("LEFT");
12251255
}
12261256
}
@@ -1478,9 +1508,13 @@ if (flush_right_edge()){
14781508
return;
14791509
}
14801510
let bounds = get_visual_time_bounds();
1481-
let ctr_time = (bounds.end + bounds.start)/2;
1511+
// let ctr_time = (bounds.end + bounds.start)/2;
1512+
let ctr_time = ((bounds.end + bounds.start)/2) - USE_ADJ_SEC;
14821513
let off_secs = tm - ctr_time;
1483-
off_secs -= (off_secs % mag_sec_per_grid);
1514+
//If we don't make this adjustment, then all times on the right side are one grid square too far to the right
1515+
if (off_secs > 0) off_secs++;
1516+
//log(off_secs);
1517+
off_secs -= (off_secs % mag_sec_per_grid);//Snap to grid so the ruler times are "nice"
14841518
let pix_off = mag_pix_per_sec * off_secs;
14851519
timeline._xLoc-=pix_off;
14861520
//If the start marker is past the left edge of the app window, always flush it to to the left
@@ -1511,7 +1545,8 @@ The video stays at the end.
15111545
return true;
15121546
}//»
15131547
const seek_to_end=async()=>{//«
1514-
timeline._xLoc = Main._w - timeline._width - GRID_W_HALF;
1548+
timeline._xLoc = Main._w - timeline._width - GRID_W;
1549+
// timeline._xLoc = Main._w - timeline._width - GRID_W_HALF;
15151550
align_timeline();
15161551
//AQUEORK
15171552
// await seek_to_time(viddur-0.001, true);
@@ -1557,16 +1592,55 @@ mark._maybeScroll=()=>{
15571592

15581593
//»
15591594
const get_timeline_rect = ()=>{//«
1560-
return {
1561-
left: timeline._xLoc,
1562-
right: timeline._xLoc+timeline._width,
1563-
width: timeline._width
1564-
};
1595+
let use_off = 0;
1596+
//let use_off = USE_TIMELINE_X;
1597+
return {
1598+
left: timeline._xLoc-use_off,
1599+
right: timeline._xLoc+timeline._width-use_off,
1600+
width: timeline._width
1601+
};
1602+
};//»
1603+
1604+
const get_visual_time_bounds = () => {//«
1605+
1606+
let tr = get_timeline_rect();
1607+
let mw = Main._w;
1608+
1609+
let left_edge = 0 > tr.left ? 0 : tr.left;
1610+
let right_edge = mw < tr.right ? mw : tr.right;
1611+
1612+
let viz_duration = (right_edge - left_edge)/mag_pix_per_sec;
1613+
1614+
let viz_start;
1615+
let viz_end;
1616+
1617+
let left_diff = tr.left;
1618+
if (left_diff > 0){
1619+
if (tr.left > mw){
1620+
return {invalid: true, type: 1};
1621+
}
1622+
viz_start = 0;
1623+
}
1624+
else {
1625+
if (tr.right < 0){
1626+
return {invalid: true, type: 2, diff: -tr.right};
1627+
}
1628+
viz_start = -left_diff/mag_pix_per_sec;
1629+
}
1630+
viz_end = viz_start + viz_duration;
1631+
1632+
return {
1633+
start: viz_start,
1634+
end: viz_end,
1635+
duration: viz_duration,
1636+
width: viz_duration * mag_pix_per_sec
1637+
};
1638+
15651639
};//»
1566-
const get_visual_time_bounds=()=>{//«
1640+
/*
1641+
const get_visual_time_bounds = () => {//«
15671642
15681643
let rr = get_timeline_rect();
1569-
//log("RR", rr);
15701644
let mw = Main._w;
15711645
15721646
let left_edge = 0 > rr.left ? 0 : rr.left;
@@ -1582,7 +1656,6 @@ let viz_end;
15821656
let left_diff = rr.left;
15831657
if (left_diff > 0){
15841658
let diff = rr.left - mw;
1585-
//log(1, diff);
15861659
if (rr.left > mw){
15871660
return {invalid: true, type: 1};
15881661
}
@@ -1600,12 +1673,11 @@ return {
16001673
start: viz_start,
16011674
end: viz_end,
16021675
duration: viz_duration,
1603-
startDiff: left_diff,
16041676
width: viz_duration * mag_pix_per_sec
16051677
};
16061678
16071679
};//»
1608-
1680+
*/
16091681
const scroll_to_time = (tm, which)=>{//«
16101682
vid.currentTime = tm;
16111683
tmdiv.innerHTML = get_main_time_str(tm);
@@ -1701,14 +1773,14 @@ v.onloadedmetadata=async()=>{//«
17011773
d._op = VID_IMG_OP;
17021774
d._add(im);
17031775
img_div._add(d);
1704-
if (tm==viddur){
1776+
// if (tm==viddur){
17051777
// d._x = m._x;
1706-
d._x = use_padl + m._x;
1707-
}
1708-
else{
1778+
// d._x = use_padl + m._x;
1779+
// }
1780+
// else{
17091781
d._x = use_padl + m._x - w/2;
17101782
// d._x = use_padl + m._x;
1711-
}
1783+
// }
17121784
d._z = 10;
17131785
d.style.borderRight = PREV_IMG_BORDER;
17141786
d.style.borderLeft = PREV_IMG_BORDER;
@@ -1734,11 +1806,9 @@ for (let im of cur_images) im._del();
17341806

17351807
let {
17361808
invalid,
1737-
startDiff: left_diff,
17381809
start: viz_start,
17391810
end: viz_end,
17401811
duration: viz_duration,
1741-
width: viz_width
17421812
} = get_visual_time_bounds();
17431813

17441814
if (invalid) {
@@ -1767,7 +1837,7 @@ grid_marks = [];
17671837
cur_images = [];
17681838
//images_showing = true;
17691839
let last_x;
1770-
let first_x;
1840+
//let first_x;
17711841
for (let i=-1; i < num_grids; i++){
17721842
let g = mkdv();
17731843
grid_marks.push(g);
@@ -1776,6 +1846,7 @@ for (let i=-1; i < num_grids; i++){
17761846
g._bgcol="#555";
17771847
g._h="100%";
17781848
g._x = ((i + 1) * GRID_W)-1;
1849+
last_x = g._x;
17791850
g._y = 0;
17801851
g._z = 1;
17811852
ruler._add(g);
@@ -1821,7 +1892,9 @@ if (Math.abs(viz_end-viddur) < 0.01){
18211892
*/
18221893
// if (opts.addLast) {
18231894
// grid_time_elems.push({});
1824-
// grid_marks.push(g);
1895+
//If the x value is < GRID_W_HALF from the previous one, do not add this
1896+
//log(g._x - last_x,GRID_W_HALF);
1897+
if (g._x - last_x >= GRID_W_HALF) grid_marks.push(g);
18251898
// }
18261899
ruler._add(g);
18271900

@@ -1930,6 +2003,7 @@ return;
19302003
let bnds = get_visual_time_bounds();
19312004
cur_mag_level++;
19322005
mag_pix_per_sec = MAG_PIX_PER_SEC_ARR[cur_mag_level];
2006+
USE_ADJ_SEC = USE_TIMELINE_X / mag_pix_per_sec;
19332007
mag_sec_per_grid = GRID_W/mag_pix_per_sec;
19342008
timeline_sig_figs = (mag_pix_per_sec+"").length-2;
19352009
if (timeline_sig_figs < 0) timeline_sig_figs = 0;
@@ -1955,6 +2029,7 @@ if (cur_mag_level-1 < 0){
19552029
}
19562030
cur_mag_level--;
19572031
mag_pix_per_sec = MAG_PIX_PER_SEC_ARR[cur_mag_level];
2032+
USE_ADJ_SEC = USE_TIMELINE_X / mag_pix_per_sec;
19582033
mag_sec_per_grid = GRID_W/mag_pix_per_sec;
19592034
let w = timeline._width;
19602035
timeline._width = viddur * mag_pix_per_sec;
@@ -2353,7 +2428,7 @@ slice, and if so, seek to the start of the next slice.
23532428
23542429
Otherwise, we can do the check for being past the end of the current visual boundary as below.
23552430
*/
2356-
if (ctime > get_visual_time_bounds().end) {
2431+
if (ctime > get_visual_time_bounds().end - USE_ADJ_SEC) {
23572432
// handle_arrow("RIGHT_S"); //For some reason, using handle_arrow does NOT render the preview images
23582433
scroll_timeline("RIGHT"); //This automatically renders the preview images
23592434
}
@@ -2420,7 +2495,8 @@ this.onkeydown=(e,k)=>{//«
24202495
}
24212496
else if (k=="c_"){
24222497
let {start, end} = get_visual_time_bounds();
2423-
seek_to_time((start+end)/2);
2498+
// seek_to_time((start+end)/2);
2499+
seek_to_time(((start+end)/2)-USE_ADJ_SEC);
24242500
}
24252501
else if (k=="s_C"){
24262502
try_save();

list.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["README.md/2181","app",["3d",["index.html/1098"]],"apps",["Audio.js/4093","BinView.js/9814","Folder.js/11196","Help.js/979","MediaPlayer.js/2074","Music.js/4844","Terminal.js/100191","TextEdit.js/5301","WorkMan.js/3808","YourApp.js/418","dev",["GetPoint.js/551","Grok.js/14796","Poker.js/36551","Three.js/5119"],"games",["Arcade.js/12599"],"hw",["MidiCtl.js/3691"],"media",["2Cameras.js/3258","Camera.js/3673","MediaPlayer.js/16115","VideoCutter.js/59340"],"template",["Basic.js/489","Template.js/396","WebAudio.js/2877"],"util",["HTML.js/1428","ImageView.js/2703","Unicoder.js/16896"]],"coms",["audio.js/1766","esprima.js/171872","extra.js/11288","fs.js/28766","games",["cfr.js/115420","poker.js/107498","slum.js/71075","zhold",["poker1.js/25062"]],"mail.js/44010","shell.js/175037","template.js/336","test",["dummy.js/21"],"test.js/2086","yt.js/66863","zhold",["mail.js/22724"]],"desk",["index.html/1184"],"index.html/486","mods",["audio",["multi_freq_worklet.js/1502","random_walk_worklet.js/3039"],"games",["GBEmulator.js/9708","NESEmulator.js/222309","binjgb.wasm/87232"],"help",["shell.js/3591"],"hw",["midi.js/2323"],"lang",["shell.js/185134"],"term",["email.js/10406","less.js/19318","log.js/13292","vim.js/162675"],"util",["libwabt.js/1299054","math.js/12125","pretty.js/93856","showdown.js/87205","walt.js/204893","wasm.js/42764","wasmparser.js/34331","webmparser.js/58730"],"workers",["poker.js/37420"]],"node",["server.js/7792","svcs",["imap.js/17772","mount.js/16553","smtp.js/1359","template.js/1831","ws.js/2156","ytdl.js/11982"]],"shell",["index.html/959"],"sys",["config.js/9365","desk.js/219168","fs.js/67626","terminal.js/4300","three.js/3443","util.js/32970"],"www",["blog.css/181","desk.css/1831","docs",["blog-template.html/291","help.html/9104","what-it-is.html/4370"],"examples",["test.sh/66"],"favicon.ico/15086","lotw256.png/41075","lotw48.png/2966","stuff",["noise.html/1669"]]]
1+
["README.md/2181","app",["3d",["index.html/1098"]],"apps",["Audio.js/4093","BinView.js/9814","Folder.js/11196","Help.js/979","MediaPlayer.js/2074","Music.js/4844","Terminal.js/100191","TextEdit.js/5301","WorkMan.js/3808","YourApp.js/418","dev",["GetPoint.js/551","Grok.js/14796","Poker.js/36551","Three.js/5119"],"games",["Arcade.js/12599"],"hw",["MidiCtl.js/3691"],"media",["2Cameras.js/3258","Camera.js/3673","MediaPlayer.js/16115","VideoCutter.js/61851"],"template",["Basic.js/489","Template.js/396","WebAudio.js/2877"],"util",["HTML.js/1428","ImageView.js/2703","Unicoder.js/16896"]],"coms",["audio.js/1766","esprima.js/171872","extra.js/11288","fs.js/28766","games",["cfr.js/115420","poker.js/107498","slum.js/71075","zhold",["poker1.js/25062"]],"mail.js/44010","shell.js/175037","template.js/336","test",["dummy.js/21"],"test.js/2086","yt.js/66863","zhold",["mail.js/22724"]],"desk",["index.html/1184"],"index.html/486","mods",["audio",["multi_freq_worklet.js/1502","random_walk_worklet.js/3039"],"games",["GBEmulator.js/9708","NESEmulator.js/222309","binjgb.wasm/87232"],"help",["shell.js/3591"],"hw",["midi.js/2323"],"lang",["shell.js/185134"],"term",["email.js/10406","less.js/19318","log.js/13292","vim.js/162675"],"util",["libwabt.js/1299054","math.js/12125","pretty.js/93856","showdown.js/87205","walt.js/204893","wasm.js/42764","wasmparser.js/34331","webmparser.js/58730"],"workers",["poker.js/37420"]],"node",["server.js/7792","svcs",["imap.js/17772","mount.js/16553","smtp.js/1359","template.js/1831","ws.js/2156","ytdl.js/11982"]],"shell",["index.html/959"],"sys",["config.js/9365","desk.js/219168","fs.js/67626","terminal.js/4300","three.js/3443","util.js/32970"],"www",["blog.css/181","desk.css/1831","docs",["blog-template.html/291","help.html/9104","what-it-is.html/4370"],"examples",["test.sh/66"],"favicon.ico/15086","lotw256.png/41075","lotw48.png/2966","stuff",["noise.html/1669"]]]

0 commit comments

Comments
 (0)