Merge lp:~mttronchetti/novacut/container into lp:novacut
- container
- Merge into trunk
Proposed by
Matteo Ronchetti
Status: | Merged |
---|---|
Merged at revision: | 286 |
Proposed branch: | lp:~mttronchetti/novacut/container |
Merge into: | lp:novacut |
Diff against target: |
3825 lines (+3806/-0) 4 files modified
ui/bucket2.css (+640/-0) ui/bucket2.html (+94/-0) ui/bucket2.js (+2656/-0) ui/novacut2.js (+416/-0) |
To merge this branch: | bzr merge lp:~mttronchetti/novacut/container |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Novacut Dev | Pending | ||
Review via email: mp+119593@code.launchpad.net |
Commit message
Description of the change
My work on the container
it is accessible with novacut-gtk --page=
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'ui/bucket2.css' | |||
2 | --- ui/bucket2.css 1970-01-01 00:00:00 +0000 | |||
3 | +++ ui/bucket2.css 2012-08-14 17:10:21 +0000 | |||
4 | @@ -0,0 +1,640 @@ | |||
5 | 1 | * { | ||
6 | 2 | font-family: Ubuntu; | ||
7 | 3 | line-height: 24px; | ||
8 | 4 | -webkit-user-select: none; | ||
9 | 5 | } | ||
10 | 6 | |||
11 | 7 | img { | ||
12 | 8 | -webkit-user-select: none; | ||
13 | 9 | } | ||
14 | 10 | |||
15 | 11 | .fgrid_row { | ||
16 | 12 | white-space: nowrap; | ||
17 | 13 | font-size: 0; | ||
18 | 14 | line-height: 0; | ||
19 | 15 | } | ||
20 | 16 | |||
21 | 17 | .fgrid_row > * { | ||
22 | 18 | font-size: 15px; | ||
23 | 19 | display: inline-block; | ||
24 | 20 | margin: 8px; | ||
25 | 21 | box-sizing: border-box !important; | ||
26 | 22 | vertical-align: top; | ||
27 | 23 | } | ||
28 | 24 | |||
29 | 25 | |||
30 | 26 | .fgrid_cell > * { | ||
31 | 27 | display: block; | ||
32 | 28 | width: 100%; | ||
33 | 29 | box-sizing: border-box !important; | ||
34 | 30 | } | ||
35 | 31 | |||
36 | 32 | .fgrid_1 { | ||
37 | 33 | width: 50px; | ||
38 | 34 | } | ||
39 | 35 | |||
40 | 36 | .fgrid_2 { | ||
41 | 37 | width: 116px; | ||
42 | 38 | } | ||
43 | 39 | |||
44 | 40 | .fgrid_3 { | ||
45 | 41 | width: 182px; | ||
46 | 42 | } | ||
47 | 43 | |||
48 | 44 | .fgrid_4 { | ||
49 | 45 | width: 248px; | ||
50 | 46 | } | ||
51 | 47 | |||
52 | 48 | .fgrid_5 { | ||
53 | 49 | width: 314px; | ||
54 | 50 | } | ||
55 | 51 | |||
56 | 52 | .fgrid_6 { | ||
57 | 53 | width: 380px; | ||
58 | 54 | } | ||
59 | 55 | |||
60 | 56 | .fgrid_7 { | ||
61 | 57 | width: 446px; | ||
62 | 58 | } | ||
63 | 59 | |||
64 | 60 | .fgrid_8 { | ||
65 | 61 | width: 512px; | ||
66 | 62 | } | ||
67 | 63 | |||
68 | 64 | .fgrid_9 { | ||
69 | 65 | width: 578px; | ||
70 | 66 | } | ||
71 | 67 | |||
72 | 68 | .fgrid_10 { | ||
73 | 69 | width: 644px; | ||
74 | 70 | } | ||
75 | 71 | |||
76 | 72 | .fgrid_11 { | ||
77 | 73 | width: 710px; | ||
78 | 74 | } | ||
79 | 75 | |||
80 | 76 | .fgrid_12 { | ||
81 | 77 | width: 776px; | ||
82 | 78 | } | ||
83 | 79 | |||
84 | 80 | #flyout .version { | ||
85 | 81 | text-shadow: 0px 0px 10px #e81f3b; | ||
86 | 82 | } | ||
87 | 83 | |||
88 | 84 | |||
89 | 85 | #flyout_capture { | ||
90 | 86 | position: fixed; | ||
91 | 87 | z-index: 10; | ||
92 | 88 | top: 0; | ||
93 | 89 | right: 0; | ||
94 | 90 | bottom: 0; | ||
95 | 91 | left: 0; | ||
96 | 92 | /* | ||
97 | 93 | background: rgba(0,0,0,0.5); | ||
98 | 94 | */ | ||
99 | 95 | } | ||
100 | 96 | |||
101 | 97 | |||
102 | 98 | #flyout { | ||
103 | 99 | position: absolute; | ||
104 | 100 | top: 18px; | ||
105 | 101 | right: 18px; | ||
106 | 102 | width: 800px; | ||
107 | 103 | height: 448px; | ||
108 | 104 | /* | ||
109 | 105 | background: -webkit-linear-gradient(top, #333, #2a2a2a); | ||
110 | 106 | */ | ||
111 | 107 | background-color: rgba(15, 15, 15, 0.9); | ||
112 | 108 | box-shadow: 0px 0px 10px 0px #e81f3b; | ||
113 | 109 | border-radius: 12px; | ||
114 | 110 | font-size: 16px; | ||
115 | 111 | color: #ddd; | ||
116 | 112 | box-sizing: border-box !important; | ||
117 | 113 | padding: 4px; | ||
118 | 114 | } | ||
119 | 115 | |||
120 | 116 | #flyout a { | ||
121 | 117 | color: #e81f3b; | ||
122 | 118 | text-decoration: none; | ||
123 | 119 | } | ||
124 | 120 | |||
125 | 121 | #flyout a:hover { | ||
126 | 122 | color: #f82f4b; | ||
127 | 123 | text-decoration: underline; | ||
128 | 124 | } | ||
129 | 125 | |||
130 | 126 | #logo { | ||
131 | 127 | position: fixed; | ||
132 | 128 | z-index: 11; | ||
133 | 129 | right: 6px; | ||
134 | 130 | top: 6px; | ||
135 | 131 | width: 48px; | ||
136 | 132 | height: 48px; | ||
137 | 133 | -webkit-transition: -webkit-transform 300ms linear; | ||
138 | 134 | } | ||
139 | 135 | |||
140 | 136 | #logo.open { | ||
141 | 137 | -webkit-transform: rotate(-180deg); | ||
142 | 138 | } | ||
143 | 139 | |||
144 | 140 | #open_clips { | ||
145 | 141 | z-index: 4; | ||
146 | 142 | position: fixed; | ||
147 | 143 | top: 0; | ||
148 | 144 | right: 50%; | ||
149 | 145 | width: 80px; | ||
150 | 146 | color: #ddd; | ||
151 | 147 | padding-left: 6px; | ||
152 | 148 | padding-right: 6px; | ||
153 | 149 | cursor: default; | ||
154 | 150 | box-shadow: 0px 1px 4px 0px rgba(0,0,0,0.6); | ||
155 | 151 | text-align: center; | ||
156 | 152 | border-radius: 0 0 2px 2px; | ||
157 | 153 | border:1px solid transparent; | ||
158 | 154 | border-top:none; | ||
159 | 155 | border-bottom:1px solid #383838; | ||
160 | 156 | background: -webkit-linear-gradient(top, #444, #333); | ||
161 | 157 | text-shadow: 0px -1px 0px rgba(0,0,0,0.5); | ||
162 | 158 | } | ||
163 | 159 | |||
164 | 160 | #clips_outer { | ||
165 | 161 | z-index: 3; | ||
166 | 162 | position: fixed; | ||
167 | 163 | top: -140px; | ||
168 | 164 | height: 139px; | ||
169 | 165 | left: 0; | ||
170 | 166 | right: 0; | ||
171 | 167 | overflow: hidden; | ||
172 | 168 | -webkit-transition: top 250ms ease-in-out; | ||
173 | 169 | box-shadow: 0px 2px 6px 0px rgba(0,0,0,0.6); | ||
174 | 170 | } | ||
175 | 171 | |||
176 | 172 | |||
177 | 173 | #clips_outer.open { | ||
178 | 174 | top: 0px; | ||
179 | 175 | } | ||
180 | 176 | |||
181 | 177 | .grid_row { | ||
182 | 178 | font-size: 0; | ||
183 | 179 | white-space: nowrap; | ||
184 | 180 | font-size: 0; | ||
185 | 181 | } | ||
186 | 182 | |||
187 | 183 | #clips_nav { | ||
188 | 184 | height: 41px; | ||
189 | 185 | } | ||
190 | 186 | |||
191 | 187 | #clips_nav label, #clips_nav select { | ||
192 | 188 | margin: 8px; | ||
193 | 189 | } | ||
194 | 190 | |||
195 | 191 | |||
196 | 192 | #clips { | ||
197 | 193 | width: 100%; | ||
198 | 194 | overflow-y: hidden; | ||
199 | 195 | overflow-x: scroll; | ||
200 | 196 | white-space: nowrap; | ||
201 | 197 | font-size: 0; | ||
202 | 198 | line-height: 0; | ||
203 | 199 | height: 97px; | ||
204 | 200 | |||
205 | 201 | /* | ||
206 | 202 | Dear James, you are looking especially tall today, and tough and handsome. | ||
207 | 203 | Could you please make this scrollbar less horible looking? | ||
208 | 204 | |||
209 | 205 | Love, | ||
210 | 206 | Jason | ||
211 | 207 | */ | ||
212 | 208 | } | ||
213 | 209 | |||
214 | 210 | ::-webkit-scrollbar{ | ||
215 | 211 | width:5px; | ||
216 | 212 | height:5px; | ||
217 | 213 | background:#222; | ||
218 | 214 | } | ||
219 | 215 | |||
220 | 216 | ::-webkit-scrollbar-thumb{ | ||
221 | 217 | border-radius:2px; | ||
222 | 218 | background:#999; | ||
223 | 219 | } | ||
224 | 220 | |||
225 | 221 | #clips img { | ||
226 | 222 | width: 160px; | ||
227 | 223 | height: 90px; | ||
228 | 224 | display: inline-block; | ||
229 | 225 | border: 1px solid #333; | ||
230 | 226 | -webkit-user-select: none; | ||
231 | 227 | } | ||
232 | 228 | |||
233 | 229 | #clips img.selected { | ||
234 | 230 | border-color: #e81f3b; | ||
235 | 231 | } | ||
236 | 232 | |||
237 | 233 | #bucket { | ||
238 | 234 | position: fixed; | ||
239 | 235 | top: 0px; | ||
240 | 236 | bottom: 246px; | ||
241 | 237 | left: 0; | ||
242 | 238 | right: 0; | ||
243 | 239 | /* | ||
244 | 240 | background: #333; | ||
245 | 241 | */ | ||
246 | 242 | background: #301438; | ||
247 | 243 | overflow: hidden; | ||
248 | 244 | } | ||
249 | 245 | |||
250 | 246 | .seq-preview { | ||
251 | 247 | position: fixed; | ||
252 | 248 | top: 0; | ||
253 | 249 | left: 0; | ||
254 | 250 | right: 0; | ||
255 | 251 | bottom: 246px; | ||
256 | 252 | z-index: 3; | ||
257 | 253 | background-color: black; | ||
258 | 254 | } | ||
259 | 255 | |||
260 | 256 | .seq-preview video { | ||
261 | 257 | position: absolute; | ||
262 | 258 | top: 0px; | ||
263 | 259 | left: 0px; | ||
264 | 260 | width: 100%; | ||
265 | 261 | height: 100%; | ||
266 | 262 | } | ||
267 | 263 | |||
268 | 264 | |||
269 | 265 | #sequence { | ||
270 | 266 | position: fixed; | ||
271 | 267 | height: 221px; | ||
272 | 268 | bottom: 0; | ||
273 | 269 | left: 0; | ||
274 | 270 | right: 0; | ||
275 | 271 | background-color: #eee; | ||
276 | 272 | |||
277 | 273 | overflow: hidden; | ||
278 | 274 | white-space: nowrap; | ||
279 | 275 | font-size: 0; | ||
280 | 276 | line-height: 0; | ||
281 | 277 | |||
282 | 278 | padding-top: 25px; | ||
283 | 279 | background-image: url(grip-short.png); | ||
284 | 280 | /* | ||
285 | 281 | background-image: url(grip-short.png), -webkit-linear-gradient(top, #222, #333); | ||
286 | 282 | */ | ||
287 | 283 | background-repeat: repeat-x; | ||
288 | 284 | } | ||
289 | 285 | |||
290 | 286 | .slice { | ||
291 | 287 | border-top: 1px solid #666; | ||
292 | 288 | border-left: 1px solid #555; | ||
293 | 289 | border-right: 1px solid #444; | ||
294 | 290 | border-bottom:1px solid #333; | ||
295 | 291 | } | ||
296 | 292 | |||
297 | 293 | .slice.selected { | ||
298 | 294 | border-color: #e81f3b; | ||
299 | 295 | z-index: 1; | ||
300 | 296 | } | ||
301 | 297 | |||
302 | 298 | .slice, .slice * { | ||
303 | 299 | -webkit-user-select: none; | ||
304 | 300 | } | ||
305 | 301 | |||
306 | 302 | #bucket .slice { | ||
307 | 303 | position: absolute; | ||
308 | 304 | box-shadow: 0px 2px 5px 1px rgba(0,0,0,0.5); | ||
309 | 305 | |||
310 | 306 | -webkit-transition-timing-function: ease; | ||
311 | 307 | -webkit-transition-duration: 250ms; | ||
312 | 308 | -webkit-transition-property: left, top; | ||
313 | 309 | } | ||
314 | 310 | |||
315 | 311 | #sequence .slice { | ||
316 | 312 | display: inline-block; | ||
317 | 313 | } | ||
318 | 314 | |||
319 | 315 | |||
320 | 316 | .frame { | ||
321 | 317 | position: relative; | ||
322 | 318 | } | ||
323 | 319 | |||
324 | 320 | .frame div { | ||
325 | 321 | position: absolute; | ||
326 | 322 | top: 0; | ||
327 | 323 | right: 0; | ||
328 | 324 | padding: 2px 6px; | ||
329 | 325 | |||
330 | 326 | cursor: default; | ||
331 | 327 | text-align: right; | ||
332 | 328 | font-family: "Ubuntu Mono"; | ||
333 | 329 | font-size: 14px; | ||
334 | 330 | line-height: 1.6em; | ||
335 | 331 | font-weight: bold; | ||
336 | 332 | color: white; | ||
337 | 333 | text-shadow: 0 0 2px black; | ||
338 | 334 | /* | ||
339 | 335 | -webkit-text-stroke: 1px #000; | ||
340 | 336 | */ | ||
341 | 337 | } | ||
342 | 338 | |||
343 | 339 | .frame img { | ||
344 | 340 | margin: 0; | ||
345 | 341 | padding: 0; | ||
346 | 342 | border: none; | ||
347 | 343 | display: block; | ||
348 | 344 | background-color: white; | ||
349 | 345 | } | ||
350 | 346 | |||
351 | 347 | /* | ||
352 | 348 | Interesting 16:9 thumbnail sizes we might want to use: | ||
353 | 349 | 112 63 | ||
354 | 350 | 128 72 | ||
355 | 351 | 144 81 | ||
356 | 352 | 160 90 | ||
357 | 353 | 176 99 | ||
358 | 354 | 192 108 | ||
359 | 355 | 208 117 | ||
360 | 356 | 224 126 | ||
361 | 357 | */ | ||
362 | 358 | |||
363 | 359 | #bucket img { | ||
364 | 360 | width: 128px; | ||
365 | 361 | height: 72px; | ||
366 | 362 | } | ||
367 | 363 | |||
368 | 364 | #sequence img { | ||
369 | 365 | width: 192px; | ||
370 | 366 | height: 108px; | ||
371 | 367 | } | ||
372 | 368 | |||
373 | 369 | |||
374 | 370 | .indicator { | ||
375 | 371 | height: 3px; | ||
376 | 372 | /*background:-webkit-linear-gradient(top, #111, #222);*/ | ||
377 | 373 | background-color: #333; | ||
378 | 374 | position: relative; | ||
379 | 375 | pointer-events: none; | ||
380 | 376 | } | ||
381 | 377 | |||
382 | 378 | .indicator div { | ||
383 | 379 | position: absolute; | ||
384 | 380 | top: 1px; | ||
385 | 381 | bottom: 1px; | ||
386 | 382 | left: 0%; | ||
387 | 383 | right: 0%; | ||
388 | 384 | background:-webkit-linear-gradient(top, #ddd, #fff); | ||
389 | 385 | } | ||
390 | 386 | |||
391 | 387 | .indicator div:before{ | ||
392 | 388 | position:absolute; | ||
393 | 389 | top:-1px; | ||
394 | 390 | bottom:-1px; | ||
395 | 391 | left:0px; | ||
396 | 392 | width:1px; | ||
397 | 393 | background:white; | ||
398 | 394 | content:""; | ||
399 | 395 | } | ||
400 | 396 | |||
401 | 397 | .indicator div:after{ | ||
402 | 398 | position:absolute; | ||
403 | 399 | top:-1px; | ||
404 | 400 | bottom:-1px; | ||
405 | 401 | right:0px; | ||
406 | 402 | width:1px; | ||
407 | 403 | background:white; | ||
408 | 404 | content:""; | ||
409 | 405 | } | ||
410 | 406 | |||
411 | 407 | |||
412 | 408 | |||
413 | 409 | .over { | ||
414 | 410 | margin-left: 194px; | ||
415 | 411 | } | ||
416 | 412 | |||
417 | 413 | .over-right { | ||
418 | 414 | margin-right: 194px; | ||
419 | 415 | } | ||
420 | 416 | |||
421 | 417 | |||
422 | 418 | .right { | ||
423 | 419 | position: relative; | ||
424 | 420 | left: 194px; | ||
425 | 421 | } | ||
426 | 422 | |||
427 | 423 | .left { | ||
428 | 424 | position: relative; | ||
429 | 425 | left: -194px; | ||
430 | 426 | } | ||
431 | 427 | |||
432 | 428 | .animated { | ||
433 | 429 | position: relative; | ||
434 | 430 | -webkit-transition: left 150ms ease; | ||
435 | 431 | } | ||
436 | 432 | |||
437 | 433 | .grabbed { | ||
438 | 434 | -webkit-transition-property: none !important; | ||
439 | 435 | position: fixed !important; | ||
440 | 436 | } | ||
441 | 437 | |||
442 | 438 | |||
443 | 439 | #roughcut { | ||
444 | 440 | position: fixed; | ||
445 | 441 | top: 139px; | ||
446 | 442 | bottom: 0; | ||
447 | 443 | left: 0; | ||
448 | 444 | right: 0; | ||
449 | 445 | background-color: black; | ||
450 | 446 | z-index: 4; | ||
451 | 447 | } | ||
452 | 448 | |||
453 | 449 | |||
454 | 450 | |||
455 | 451 | #roughcut .frames { | ||
456 | 452 | position: absolute; | ||
457 | 453 | left: 0; | ||
458 | 454 | right: 0; | ||
459 | 455 | bottom: 30px; | ||
460 | 456 | font-size: 0px; | ||
461 | 457 | line-height: 0px; | ||
462 | 458 | } | ||
463 | 459 | |||
464 | 460 | .videoframe { | ||
465 | 461 | display: inline-block; | ||
466 | 462 | width: 50%; | ||
467 | 463 | position: relative; | ||
468 | 464 | } | ||
469 | 465 | |||
470 | 466 | |||
471 | 467 | .videoframe video { | ||
472 | 468 | pointer-events: none; | ||
473 | 469 | width: 100%; | ||
474 | 470 | margin: 0; | ||
475 | 471 | display: block; | ||
476 | 472 | } | ||
477 | 473 | |||
478 | 474 | .videoframe div { | ||
479 | 475 | position: absolute; | ||
480 | 476 | top: 0; | ||
481 | 477 | right: 0; | ||
482 | 478 | padding: 2px 6px; | ||
483 | 479 | |||
484 | 480 | cursor: default; | ||
485 | 481 | text-align: right; | ||
486 | 482 | font-family: "Ubuntu Mono"; | ||
487 | 483 | font-size: 16px; | ||
488 | 484 | line-height: 1.6em; | ||
489 | 485 | font-weight: bold; | ||
490 | 486 | color: white; | ||
491 | 487 | text-shadow: 0 0 2px black; | ||
492 | 488 | } | ||
493 | 489 | |||
494 | 490 | |||
495 | 491 | |||
496 | 492 | #roughcut .scrubber { | ||
497 | 493 | position: absolute; | ||
498 | 494 | bottom: 0; | ||
499 | 495 | height: 30px; | ||
500 | 496 | left: 0; | ||
501 | 497 | right: 0; | ||
502 | 498 | background-color: #999; | ||
503 | 499 | } | ||
504 | 500 | |||
505 | 501 | |||
506 | 502 | #roughcut .scrubber * { | ||
507 | 503 | pointer-events: none; | ||
508 | 504 | } | ||
509 | 505 | |||
510 | 506 | #roughcut .bar { | ||
511 | 507 | position: absolute; | ||
512 | 508 | top: 4px; | ||
513 | 509 | bottom: 4px; | ||
514 | 510 | background-color: #e81f3b; | ||
515 | 511 | } | ||
516 | 512 | |||
517 | 513 | #roughcut .playhead { | ||
518 | 514 | position: absolute; | ||
519 | 515 | top: 0; | ||
520 | 516 | bottom: 0; | ||
521 | 517 | width: 2px; | ||
522 | 518 | background-color: green; | ||
523 | 519 | /* | ||
524 | 520 | -webkit-transition: left 150ms linear; | ||
525 | 521 | */ | ||
526 | 522 | } | ||
527 | 523 | |||
528 | 524 | #player { | ||
529 | 525 | position: fixed; | ||
530 | 526 | z-index: 20; | ||
531 | 527 | background-color: black; | ||
532 | 528 | top: 0; | ||
533 | 529 | bottom: 246px; | ||
534 | 530 | left: 0; | ||
535 | 531 | right: 0; | ||
536 | 532 | } | ||
537 | 533 | |||
538 | 534 | #player video { | ||
539 | 535 | position: absolute; | ||
540 | 536 | bottom: 0; | ||
541 | 537 | width: 100%; | ||
542 | 538 | height: 100%; | ||
543 | 539 | margin: 0; | ||
544 | 540 | pointer-events: none; | ||
545 | 541 | } | ||
546 | 542 | |||
547 | 543 | #shortcuts{ | ||
548 | 544 | position:fixed; | ||
549 | 545 | background-color: rgba(15, 15, 15, 0.85); | ||
550 | 546 | text-shadow: 2px 2px 3px rgba(255, 0, 0, 0.5); | ||
551 | 547 | box-shadow: 0px 0px 10px 0px #e81f3b; | ||
552 | 548 | border-radius: 12px; | ||
553 | 549 | font-size: 16px; | ||
554 | 550 | display:none; | ||
555 | 551 | z-index:999; | ||
556 | 552 | } | ||
557 | 553 | #shortcuts table{ | ||
558 | 554 | padding: 20px; | ||
559 | 555 | } | ||
560 | 556 | #shortcuts td{ | ||
561 | 557 | padding-top :4px; | ||
562 | 558 | padding-left: 15px; | ||
563 | 559 | padding-right: 15px; | ||
564 | 560 | } | ||
565 | 561 | |||
566 | 562 | .cont{ | ||
567 | 563 | border-top: 1px solid rgb(102, 102, 102); | ||
568 | 564 | border-left: 1px solid rgb(85, 85, 85); | ||
569 | 565 | border-right: 1px solid rgb(68, 68, 68); | ||
570 | 566 | border-bottom: 1px solid rgb(51, 51, 51); | ||
571 | 567 | } | ||
572 | 568 | |||
573 | 569 | #bucket .cont{ | ||
574 | 570 | position: absolute; | ||
575 | 571 | min-width:128px; | ||
576 | 572 | height:147px; | ||
577 | 573 | } | ||
578 | 574 | |||
579 | 575 | .cont ,.cont * { | ||
580 | 576 | -webkit-user-select: none; | ||
581 | 577 | } | ||
582 | 578 | |||
583 | 579 | .cont{ | ||
584 | 580 | /*-webkit-animation-duration: 0.2s; | ||
585 | 581 | -webkit-animation-iteration-count: 1; | ||
586 | 582 | -webkit-animation-timing-function: ease;*/ | ||
587 | 583 | background:gray; | ||
588 | 584 | /*position: fixed;*/ | ||
589 | 585 | } | ||
590 | 586 | |||
591 | 587 | |||
592 | 588 | /*#sequence .cont{ | ||
593 | 589 | height: 219px !important; | ||
594 | 590 | }*/ | ||
595 | 591 | |||
596 | 592 | /*#sequence .comp div{ | ||
597 | 593 | height: 109px; | ||
598 | 594 | }*/ | ||
599 | 595 | |||
600 | 596 | |||
601 | 597 | .cont .slice{ | ||
602 | 598 | position: relative !important; | ||
603 | 599 | float: left; | ||
604 | 600 | } | ||
605 | 601 | |||
606 | 602 | #sequence .cont{ | ||
607 | 603 | display: inline-block; | ||
608 | 604 | height:219px !important; | ||
609 | 605 | } | ||
610 | 606 | |||
611 | 607 | .top{ | ||
612 | 608 | height: 75px; | ||
613 | 609 | } | ||
614 | 610 | |||
615 | 611 | .bot{ | ||
616 | 612 | height: 72px; | ||
617 | 613 | } | ||
618 | 614 | |||
619 | 615 | #sequence .top{ | ||
620 | 616 | height: 111px; | ||
621 | 617 | } | ||
622 | 618 | |||
623 | 619 | #sequence .bot{ | ||
624 | 620 | height: 108px; | ||
625 | 621 | } | ||
626 | 622 | |||
627 | 623 | .cont.selected{ | ||
628 | 624 | border-color: rgb(232, 31, 59); | ||
629 | 625 | z-index: 1; | ||
630 | 626 | } | ||
631 | 627 | |||
632 | 628 | @-webkit-keyframes enter{ | ||
633 | 629 | from{-webkit-transform: translateX(-200px) translateY(-200px) scale(0.3);} | ||
634 | 630 | to{-webkit-transform: translateX(0px) translateY(0px) scale(1);} | ||
635 | 631 | } | ||
636 | 632 | |||
637 | 633 | .selector{ | ||
638 | 634 | border: 1px solid red; | ||
639 | 635 | position:absolute; | ||
640 | 636 | box-shadow: inset 0px 0px 10px rgba(255,0,0,0.5); | ||
641 | 637 | border-radius: 5px; | ||
642 | 638 | background-color: rgba(255, 0, 0, 0.13); | ||
643 | 639 | z-index: 10; | ||
644 | 640 | } | ||
645 | 0 | 641 | ||
646 | === added file 'ui/bucket2.html' | |||
647 | --- ui/bucket2.html 1970-01-01 00:00:00 +0000 | |||
648 | +++ ui/bucket2.html 2012-08-14 17:10:21 +0000 | |||
649 | @@ -0,0 +1,94 @@ | |||
650 | 1 | <!DOCTYPE html> | ||
651 | 2 | <html> | ||
652 | 3 | |||
653 | 4 | <head> | ||
654 | 5 | <link rel="stylesheet" href="/_apps/userwebkit/base.css" /> | ||
655 | 6 | <link rel="stylesheet" href="/_apps/dmedia/common.css" /> | ||
656 | 7 | <link rel="stylesheet" href="/_apps/dmedia/grid.css" /> | ||
657 | 8 | <link rel="stylesheet" href="bucket2.css" /> | ||
658 | 9 | <script src="/_apps/userwebkit/couch.js"></script> | ||
659 | 10 | <script src="/_apps/userwebkit/base.js"></script> | ||
660 | 11 | <script src="novacut2.js"></script> | ||
661 | 12 | <script src="bucket2.js"></script> | ||
662 | 13 | </head> | ||
663 | 14 | |||
664 | 15 | <body> | ||
665 | 16 | <div id="open_clips">Clips</div> | ||
666 | 17 | <div id="clips_outer" class="bar"> | ||
667 | 18 | <div id="clips_nav"> | ||
668 | 19 | <label>Dmedia Project: <select id="dmedia_project"></select></lable> | ||
669 | 20 | </div> | ||
670 | 21 | <div id="clips"></div> | ||
671 | 22 | </div> | ||
672 | 23 | |||
673 | 24 | <div id="flyout_capture" class="hide"> | ||
674 | 25 | <div id="flyout"> | ||
675 | 26 | <div class="fgrid_row"> | ||
676 | 27 | <a class="fgrid_4" href="projects.html"><strong>Projects</strong></a> | ||
677 | 28 | <button class="fgrid_3" id="render-btn" onclick="UI.render()">Render</button> | ||
678 | 29 | </div> | ||
679 | 30 | <div class="fgrid_row"> | ||
680 | 31 | <a class="fgrid_4" href="projects.html">(Most recent project)</a> | ||
681 | 32 | </div> | ||
682 | 33 | <div class="fgrid_row"> | ||
683 | 34 | <a class="fgrid_4" href="projects.html">(2nd most recent project)</a> | ||
684 | 35 | </div> | ||
685 | 36 | <div class="fgrid_row"> | ||
686 | 37 | <a class="fgrid_4" href="projects.html">(3rd most recent project)</a> | ||
687 | 38 | </div> | ||
688 | 39 | |||
689 | 40 | <div class="fgrid_row"><strong class="fgrid_2">.</strong></div> | ||
690 | 41 | <div class="fgrid_row"><strong class="fgrid_2">.</strong></div> | ||
691 | 42 | <div class="fgrid_row"><strong class="fgrid_2">.</strong></div> | ||
692 | 43 | <div class="fgrid_row"><strong class="fgrid_2">.</strong></div> | ||
693 | 44 | <div class="fgrid_row"><strong class="fgrid_2">.</strong></div> | ||
694 | 45 | <div class="fgrid_row"><strong class="fgrid_2">.</strong></div> | ||
695 | 46 | |||
696 | 47 | <div class="fgrid_row"> | ||
697 | 48 | <strong class="fgrid_4 version">Novacut 12.08.0</strong> | ||
698 | 49 | <a onclick="showShort(event);" style="cursor: pointer; margin-right:135px;">Keyboard Shortcuts</a> | ||
699 | 50 | <a href="http://www.kickstarter.com/projects/novacut/novacut-pro-video-editor/backers" class="fgrid_5">Thanks to our Kickstarter backers!</a> | ||
700 | 51 | </div> | ||
701 | 52 | </div> | ||
702 | 53 | </div> | ||
703 | 54 | |||
704 | 55 | <div id="bucket"> | ||
705 | 56 | <div id="shortcuts" > | ||
706 | 57 | <table border="0"> | ||
707 | 58 | <tr> | ||
708 | 59 | <td>D</td> | ||
709 | 60 | <td>Duplicate slice</td> | ||
710 | 61 | </tr> | ||
711 | 62 | <tr> | ||
712 | 63 | <td>Del</td> | ||
713 | 64 | <td>Delete slice</td> | ||
714 | 65 | </tr> | ||
715 | 66 | <tr> | ||
716 | 67 | <td>Space bar</td> | ||
717 | 68 | <td>Play/Pause</td> | ||
718 | 69 | </tr> | ||
719 | 70 | <tr> | ||
720 | 71 | <td>Esc</td> | ||
721 | 72 | <td>Close</td> | ||
722 | 73 | </tr> | ||
723 | 74 | <tr> | ||
724 | 75 | <td>Mouse wheel</td> | ||
725 | 76 | <td>Move of one frame</td> | ||
726 | 77 | </tr> | ||
727 | 78 | <tr> | ||
728 | 79 | <td>Shift+Mouse Wheel</td> | ||
729 | 80 | <td>Move of ten frames</td> | ||
730 | 81 | </tr> | ||
731 | 82 | </table> | ||
732 | 83 | </div> | ||
733 | 84 | </div> | ||
734 | 85 | <div id="sequence" clas="lower"></div> | ||
735 | 86 | <div id="roughcut" class="hide"> | ||
736 | 87 | <div class="grid_row"> | ||
737 | 88 | <button class="grid_2" id="close_roughcut">Done</button> | ||
738 | 89 | <button class="grid_2" id="create_slice">New Slice</button> | ||
739 | 90 | </div> | ||
740 | 91 | </div> | ||
741 | 92 | </body> | ||
742 | 93 | |||
743 | 94 | </html> | ||
744 | 0 | 95 | ||
745 | === added file 'ui/bucket2.js' | |||
746 | --- ui/bucket2.js 1970-01-01 00:00:00 +0000 | |||
747 | +++ ui/bucket2.js 2012-08-14 17:10:21 +0000 | |||
748 | @@ -0,0 +1,2656 @@ | |||
749 | 1 | "use strict"; | ||
750 | 2 | |||
751 | 3 | |||
752 | 4 | var Thumbs = { | ||
753 | 5 | db: new couch.Database('thumbnails'), | ||
754 | 6 | |||
755 | 7 | docs: {}, | ||
756 | 8 | |||
757 | 9 | has_frame: function(file_id, index) { | ||
758 | 10 | if (!Thumbs.docs[file_id]) { | ||
759 | 11 | try { | ||
760 | 12 | Thumbs.docs[file_id] = Thumbs.db.get_sync(file_id); | ||
761 | 13 | } | ||
762 | 14 | catch (e) { | ||
763 | 15 | return false; | ||
764 | 16 | } | ||
765 | 17 | } | ||
766 | 18 | if (Thumbs.docs[file_id]._attachments[index]) { | ||
767 | 19 | return true; | ||
768 | 20 | } | ||
769 | 21 | return false; | ||
770 | 22 | }, | ||
771 | 23 | |||
772 | 24 | q: {}, | ||
773 | 25 | |||
774 | 26 | active: {}, | ||
775 | 27 | |||
776 | 28 | need_init: true, | ||
777 | 29 | |||
778 | 30 | init: function() { | ||
779 | 31 | console.assert(Thumbs.need_init); | ||
780 | 32 | Thumbs.need_init = false; | ||
781 | 33 | var ids = Object.keys(Thumbs.q); | ||
782 | 34 | if (ids.length == 0) { | ||
783 | 35 | Thumbs.frozen = false; | ||
784 | 36 | return; | ||
785 | 37 | } | ||
786 | 38 | Thumbs.db.post(Thumbs.on_docs, {keys: ids}, '_all_docs', {include_docs: true}); | ||
787 | 39 | }, | ||
788 | 40 | |||
789 | 41 | on_docs: function(req) { | ||
790 | 42 | try { | ||
791 | 43 | var rows = req.read().rows; | ||
792 | 44 | rows.forEach(function(row) { | ||
793 | 45 | var id = row.key; | ||
794 | 46 | if (row.doc) { | ||
795 | 47 | Thumbs.docs[id] = row.doc; | ||
796 | 48 | } | ||
797 | 49 | else { | ||
798 | 50 | Thumbs.docs[id] = {'_id': id, '_attachments': {}}; | ||
799 | 51 | } | ||
800 | 52 | }); | ||
801 | 53 | } | ||
802 | 54 | catch (e) { | ||
803 | 55 | var ids = Object.keys(Thumbs.q); | ||
804 | 56 | ids.forEach(function(id) { | ||
805 | 57 | Thumbs.docs[id] = {'_id': id, '_attachments': {}}; | ||
806 | 58 | }); | ||
807 | 59 | } | ||
808 | 60 | Thumbs.unfreeze(); | ||
809 | 61 | }, | ||
810 | 62 | |||
811 | 63 | enqueue: function(frame) { | ||
812 | 64 | if (!Thumbs.q[frame.file_id]) { | ||
813 | 65 | Thumbs.q[frame.file_id] = {}; | ||
814 | 66 | } | ||
815 | 67 | Thumbs.q[frame.file_id][frame.key] = frame; | ||
816 | 68 | }, | ||
817 | 69 | |||
818 | 70 | frozen: false, | ||
819 | 71 | |||
820 | 72 | freeze: function() { | ||
821 | 73 | Thumbs.frozen = true; | ||
822 | 74 | }, | ||
823 | 75 | |||
824 | 76 | unfreeze: function() { | ||
825 | 77 | console.log('unfreeze'); | ||
826 | 78 | if (this.need_init) { | ||
827 | 79 | this.init(); | ||
828 | 80 | return; | ||
829 | 81 | } | ||
830 | 82 | Thumbs.frozen = false; | ||
831 | 83 | Thumbs.flush(); | ||
832 | 84 | }, | ||
833 | 85 | |||
834 | 86 | flush: function() { | ||
835 | 87 | if (Thumbs.frozen) { | ||
836 | 88 | return; | ||
837 | 89 | } | ||
838 | 90 | var ids = Object.keys(Thumbs.q); | ||
839 | 91 | if (ids.length == 0) { | ||
840 | 92 | console.log('no thumbnails in queue'); | ||
841 | 93 | return; | ||
842 | 94 | } | ||
843 | 95 | while (ids.length > 0 && Object.keys(Thumbs.active).length <= 4) { | ||
844 | 96 | var id = ids.shift(); | ||
845 | 97 | if (Thumbs.active[id]) { | ||
846 | 98 | console.log('already waiting for ' + id); | ||
847 | 99 | continue; | ||
848 | 100 | } | ||
849 | 101 | var frames = Thumbs.q[id]; | ||
850 | 102 | delete Thumbs.q[id]; | ||
851 | 103 | |||
852 | 104 | var needed = []; | ||
853 | 105 | var key, frame; | ||
854 | 106 | for (key in frames) { | ||
855 | 107 | frame = frames[key]; | ||
856 | 108 | if (Thumbs.has_frame(id, frame.index)) { | ||
857 | 109 | frame.request_thumbnail.call(frame); | ||
858 | 110 | } | ||
859 | 111 | else { | ||
860 | 112 | needed.push(frame.index); | ||
861 | 113 | } | ||
862 | 114 | } | ||
863 | 115 | if (needed.length > 0) { | ||
864 | 116 | Thumbs.active[id] = frames; | ||
865 | 117 | Hub.send('thumbnail', id, needed); | ||
866 | 118 | } | ||
867 | 119 | } | ||
868 | 120 | }, | ||
869 | 121 | |||
870 | 122 | on_thumbnail_finished: function(file_id) { | ||
871 | 123 | if (!Thumbs.active[file_id]) { | ||
872 | 124 | return; | ||
873 | 125 | } | ||
874 | 126 | var frames = Thumbs.active[file_id]; | ||
875 | 127 | delete Thumbs.active[file_id]; | ||
876 | 128 | Thumbs.docs[file_id] = Thumbs.db.get_sync(file_id); | ||
877 | 129 | |||
878 | 130 | var key, frame; | ||
879 | 131 | for (key in frames) { | ||
880 | 132 | frame = frames[key]; | ||
881 | 133 | if (Thumbs.has_frame(file_id, frame.index)) { | ||
882 | 134 | frame.request_thumbnail.call(frame); | ||
883 | 135 | } | ||
884 | 136 | } | ||
885 | 137 | Thumbs.flush(); | ||
886 | 138 | }, | ||
887 | 139 | } | ||
888 | 140 | |||
889 | 141 | Hub.connect('thumbnail_finished', Thumbs.on_thumbnail_finished); | ||
890 | 142 | |||
891 | 143 | |||
892 | 144 | function $halt(event) { | ||
893 | 145 | event.preventDefault(); | ||
894 | 146 | event.stopPropagation(); | ||
895 | 147 | } | ||
896 | 148 | |||
897 | 149 | |||
898 | 150 | function $unparent(id) { | ||
899 | 151 | var child = $(id); | ||
900 | 152 | if (child && child.parentNode) { | ||
901 | 153 | child.parentNode.removeChild(child); | ||
902 | 154 | } | ||
903 | 155 | return child; | ||
904 | 156 | } | ||
905 | 157 | |||
906 | 158 | |||
907 | 159 | function $position(element) { | ||
908 | 160 | element = $(element); | ||
909 | 161 | var pos = { | ||
910 | 162 | left: element.offsetLeft, | ||
911 | 163 | top: element.offsetTop, | ||
912 | 164 | width: element.offsetWidth, | ||
913 | 165 | height: element.offsetHeight, | ||
914 | 166 | }; | ||
915 | 167 | while (element.offsetParent) { | ||
916 | 168 | element = element.offsetParent; | ||
917 | 169 | pos.left += (element.offsetLeft - element.scrollLeft); | ||
918 | 170 | pos.top += (element.offsetTop - element.scrollTop); | ||
919 | 171 | } | ||
920 | 172 | pos.right = pos.left + pos.width; | ||
921 | 173 | pos.bottom = pos.top + pos.height; | ||
922 | 174 | return pos; | ||
923 | 175 | } | ||
924 | 176 | |||
925 | 177 | |||
926 | 178 | function $hscroll(child, center) { | ||
927 | 179 | child = $(child); | ||
928 | 180 | if (!child.parentNode) { | ||
929 | 181 | return; | ||
930 | 182 | } | ||
931 | 183 | var parent = child.parentNode | ||
932 | 184 | //var mid = child.offsetLeft + (child.offsetWidth - parent.clientWidth) / 2; | ||
933 | 185 | if (child.offsetLeft < parent.scrollLeft) { | ||
934 | 186 | parent.scrollLeft = child.offsetLeft; | ||
935 | 187 | } | ||
936 | 188 | else if (child.offsetLeft + child.offsetWidth > parent.scrollLeft + parent.clientWidth) { | ||
937 | 189 | parent.scrollLeft = child.offsetLeft + child.offsetWidth - parent.clientWidth; | ||
938 | 190 | } | ||
939 | 191 | } | ||
940 | 192 | |||
941 | 193 | |||
942 | 194 | |||
943 | 195 | var DragEvent = function(event, element) { | ||
944 | 196 | $halt(event); | ||
945 | 197 | this.x = event.clientX; | ||
946 | 198 | this.y = event.clientY; | ||
947 | 199 | this.ox = this.x; | ||
948 | 200 | this.oy = this.y; | ||
949 | 201 | this.dx = 0; | ||
950 | 202 | this.dy = 0; | ||
951 | 203 | |||
952 | 204 | if (element) { | ||
953 | 205 | var pos = $position(element); | ||
954 | 206 | this.offsetX = this.x - pos.left; | ||
955 | 207 | this.offsetY = this.y - pos.top; | ||
956 | 208 | } | ||
957 | 209 | else { | ||
958 | 210 | this.offsetX = event.offsetX; | ||
959 | 211 | this.offsetY = event.offsetY; | ||
960 | 212 | } | ||
961 | 213 | |||
962 | 214 | this.ondragstart = null; | ||
963 | 215 | this.ondragcancel = null; | ||
964 | 216 | this.ondrag = null; | ||
965 | 217 | this.ondrop = null; | ||
966 | 218 | this.started = false; | ||
967 | 219 | |||
968 | 220 | var self = this; | ||
969 | 221 | var tmp = {}; | ||
970 | 222 | tmp.on_mousemove = function(event) { | ||
971 | 223 | self.on_mousemove(event); | ||
972 | 224 | } | ||
973 | 225 | tmp.on_mouseup = function(event) { | ||
974 | 226 | window.removeEventListener('mousemove', tmp.on_mousemove); | ||
975 | 227 | window.removeEventListener('mouseup', tmp.on_mouseup); | ||
976 | 228 | self.on_mouseup(event); | ||
977 | 229 | } | ||
978 | 230 | window.addEventListener('mousemove', tmp.on_mousemove); | ||
979 | 231 | window.addEventListener('mouseup', tmp.on_mouseup); | ||
980 | 232 | } | ||
981 | 233 | DragEvent.prototype = { | ||
982 | 234 | update: function(event) { | ||
983 | 235 | $halt(event); | ||
984 | 236 | this.event = event; | ||
985 | 237 | var html = document.body.parentNode; | ||
986 | 238 | this.x = Math.max(0, Math.min(event.clientX, html.clientWidth)); | ||
987 | 239 | this.y = Math.max(0, Math.min(event.clientY, html.clientHeight)); | ||
988 | 240 | // this.x = event.clientX; | ||
989 | 241 | // this.y = event.clientY; | ||
990 | 242 | this.dx = this.x - this.ox; | ||
991 | 243 | this.dy = this.y - this.oy; | ||
992 | 244 | }, | ||
993 | 245 | |||
994 | 246 | on_mousemove: function(event) { | ||
995 | 247 | this.update(event); | ||
996 | 248 | if (!this.started) { | ||
997 | 249 | if (Math.max(Math.abs(this.dx), Math.abs(this.dy)) > 3) { | ||
998 | 250 | this.started = true; | ||
999 | 251 | if (this.ondragstart) { | ||
1000 | 252 | this.ondragstart(this); | ||
1001 | 253 | } | ||
1002 | 254 | } | ||
1003 | 255 | else { | ||
1004 | 256 | return; | ||
1005 | 257 | } | ||
1006 | 258 | } | ||
1007 | 259 | if (this.ondrag) { | ||
1008 | 260 | this.ondrag(this); | ||
1009 | 261 | } | ||
1010 | 262 | }, | ||
1011 | 263 | |||
1012 | 264 | on_mouseup: function(event) { | ||
1013 | 265 | if (!this.started) { | ||
1014 | 266 | if (this.ondragcancel) { | ||
1015 | 267 | this.ondragcancel(this); | ||
1016 | 268 | } | ||
1017 | 269 | return; | ||
1018 | 270 | } | ||
1019 | 271 | if (this.ondrop) { | ||
1020 | 272 | this.update(event); | ||
1021 | 273 | this.ondrop(this); | ||
1022 | 274 | } | ||
1023 | 275 | }, | ||
1024 | 276 | } | ||
1025 | 277 | |||
1026 | 278 | |||
1027 | 279 | var Frame = function(file_id, key) { | ||
1028 | 280 | this.file_id = file_id; | ||
1029 | 281 | this.key = key; | ||
1030 | 282 | this.index = null; | ||
1031 | 283 | this.element = $el('div', {'class': 'frame'}); | ||
1032 | 284 | this.img = $el('img'); | ||
1033 | 285 | this.element.appendChild(this.img); | ||
1034 | 286 | this.info = $el('div'); | ||
1035 | 287 | this.element.appendChild(this.info); | ||
1036 | 288 | } | ||
1037 | 289 | Frame.prototype = { | ||
1038 | 290 | destroy: function() { | ||
1039 | 291 | $unparent(this.info); | ||
1040 | 292 | $unparent(this.img); | ||
1041 | 293 | $unparent(this.element); | ||
1042 | 294 | delete this.info; | ||
1043 | 295 | delete this.img; | ||
1044 | 296 | delete this.element; | ||
1045 | 297 | }, | ||
1046 | 298 | |||
1047 | 299 | set_index: function(index) { | ||
1048 | 300 | if (index === this.index) { | ||
1049 | 301 | return; | ||
1050 | 302 | } | ||
1051 | 303 | this.index = index; | ||
1052 | 304 | this.info.textContent = index + 1; | ||
1053 | 305 | Thumbs.enqueue(this); | ||
1054 | 306 | }, | ||
1055 | 307 | |||
1056 | 308 | request_thumbnail: function() { | ||
1057 | 309 | this.img.src = Thumbs.db.att_url(this.file_id, this.index.toString()); | ||
1058 | 310 | }, | ||
1059 | 311 | |||
1060 | 312 | } | ||
1061 | 313 | |||
1062 | 314 | |||
1063 | 315 | function SliceIndicator() { | ||
1064 | 316 | this.element = $el('div', {'class': 'indicator'}); | ||
1065 | 317 | this.bar = $el('div'); | ||
1066 | 318 | this.element.appendChild(this.bar); | ||
1067 | 319 | } | ||
1068 | 320 | SliceIndicator.prototype = { | ||
1069 | 321 | destroy: function() { | ||
1070 | 322 | $unparent(this.bar); | ||
1071 | 323 | $unparent(this.element); | ||
1072 | 324 | delete this.bar; | ||
1073 | 325 | delete this.element; | ||
1074 | 326 | }, | ||
1075 | 327 | |||
1076 | 328 | update: function(start, stop, count) { | ||
1077 | 329 | var left = 100 * start / count; | ||
1078 | 330 | var right = 100 - (100 * stop / count); | ||
1079 | 331 | this.bar.style.left = left.toFixed(1) + '%'; | ||
1080 | 332 | this.bar.style.right = right.toFixed(1) + '%'; | ||
1081 | 333 | }, | ||
1082 | 334 | } | ||
1083 | 335 | |||
1084 | 336 | |||
1085 | 337 | function wheel_delta(event) { | ||
1086 | 338 | var delta = event.wheelDeltaY; | ||
1087 | 339 | if (delta == 0) { | ||
1088 | 340 | return 0; | ||
1089 | 341 | } | ||
1090 | 342 | var scale = (event.shiftKey) ? -10 : -1; | ||
1091 | 343 | return scale * (delta / Math.abs(delta)); | ||
1092 | 344 | } | ||
1093 | 345 | |||
1094 | 346 | function addCont(){ | ||
1095 | 347 | var doc = create_cont(); | ||
1096 | 348 | console.log(UI.session.save(doc)); | ||
1097 | 349 | console.log(doc); | ||
1098 | 350 | var cont = new Cont(UI.session,doc); | ||
1099 | 351 | UI.bucket.appendChild(cont.element); | ||
1100 | 352 | UI.sequence.do_reorder(); | ||
1101 | 353 | } | ||
1102 | 354 | |||
1103 | 355 | //TODO:HERE | ||
1104 | 356 | var Cont = function(session,doc){ | ||
1105 | 357 | session.subscribe(doc._id, this.on_change, this); | ||
1106 | 358 | UI.conts.push(this); | ||
1107 | 359 | this.doc = doc; | ||
1108 | 360 | this.id = doc._id; | ||
1109 | 361 | this.session=session; | ||
1110 | 362 | this.element = $el('div', {'class': 'cont','id': doc._id}); | ||
1111 | 363 | this.list = $el('ul', {'style': 'display = "none"'}); | ||
1112 | 364 | this.comp = $el('div', {'class': 'comp'}) | ||
1113 | 365 | this.element.appendChild(this.list); | ||
1114 | 366 | this.element.appendChild(this.comp); | ||
1115 | 367 | this.element.onmousedown = $bind(this.on_mousedown, this); | ||
1116 | 368 | this.element.ondblclick = $bind(this.on_dblclick, this); | ||
1117 | 369 | this.element.onclick = $bind(this.on_click, this); | ||
1118 | 370 | this.expanded = true; | ||
1119 | 371 | this.over = null; | ||
1120 | 372 | this.x = 150; | ||
1121 | 373 | this.y = 150; | ||
1122 | 374 | this.width = 192 + 2; | ||
1123 | 375 | this.threshold = this.width * 0.65; | ||
1124 | 376 | this.on_change(doc); | ||
1125 | 377 | this.close(); | ||
1126 | 378 | } | ||
1127 | 379 | |||
1128 | 380 | Cont.prototype = { | ||
1129 | 381 | set x(value) { | ||
1130 | 382 | if (typeof value == 'number') { | ||
1131 | 383 | this.element.style.left = value + 'px'; | ||
1132 | 384 | } | ||
1133 | 385 | else { | ||
1134 | 386 | this.element.style.left = null; | ||
1135 | 387 | } | ||
1136 | 388 | }, | ||
1137 | 389 | |||
1138 | 390 | set y(value) { | ||
1139 | 391 | if (typeof value == 'number') { | ||
1140 | 392 | this.element.style.top = value + 'px'; | ||
1141 | 393 | } | ||
1142 | 394 | else { | ||
1143 | 395 | this.element.style.top = null; | ||
1144 | 396 | } | ||
1145 | 397 | }, | ||
1146 | 398 | |||
1147 | 399 | get x() { | ||
1148 | 400 | if(this.element)return parseInt(this.element.style.left); | ||
1149 | 401 | else return -1; | ||
1150 | 402 | }, | ||
1151 | 403 | |||
1152 | 404 | get y() { | ||
1153 | 405 | if(this.element)return parseInt(this.element.style.top); | ||
1154 | 406 | else return -1; | ||
1155 | 407 | }, | ||
1156 | 408 | |||
1157 | 409 | get inbucket() { | ||
1158 | 410 | return this.element.parentNode.id == 'bucket'; | ||
1159 | 411 | }, | ||
1160 | 412 | |||
1161 | 413 | get frombucket() { | ||
1162 | 414 | return this.parent.id == 'bucket'; | ||
1163 | 415 | }, | ||
1164 | 416 | |||
1165 | 417 | save: function(){ | ||
1166 | 418 | this.doc.node.src = Array(); | ||
1167 | 419 | for(var a in this.list.childNodes){ | ||
1168 | 420 | if(this.list.childNodes[a].id)this.doc.node.src.push(this.list.childNodes[a].id); | ||
1169 | 421 | } | ||
1170 | 422 | this.session.save(this.doc,true); | ||
1171 | 423 | }, | ||
1172 | 424 | |||
1173 | 425 | refresh: function(){ | ||
1174 | 426 | this.comp.innerHTML = '<div class="top">' + this.list.firstChild.firstChild.firstChild.outerHTML + '</div>'; | ||
1175 | 427 | this.comp.innerHTML += '<div class="bot">'+ this.list.lastChild.lastChild.firstChild.outerHTML + '</div>'; | ||
1176 | 428 | }, | ||
1177 | 429 | |||
1178 | 430 | expand: function(){ | ||
1179 | 431 | this.expanded = true; | ||
1180 | 432 | this.list.style.display = 'block'; | ||
1181 | 433 | this.comp.style.display = 'none'; | ||
1182 | 434 | }, | ||
1183 | 435 | close: function(){ | ||
1184 | 436 | if(!this.expanded)return; | ||
1185 | 437 | this.expanded = false; | ||
1186 | 438 | console.log("close"); | ||
1187 | 439 | this.comp.innerHTML = ""; | ||
1188 | 440 | var len = this.list.childNodes.length; | ||
1189 | 441 | console.log(len); | ||
1190 | 442 | if(len){ | ||
1191 | 443 | this.refresh(); | ||
1192 | 444 | }else{ | ||
1193 | 445 | if(len == 1){ | ||
1194 | 446 | console.log("save frist child"); | ||
1195 | 447 | var el = this.list.childNodes[0]; | ||
1196 | 448 | el.style.top = this.y + 'px'; | ||
1197 | 449 | el.style.left = this.x + 'px'; | ||
1198 | 450 | el.style.marginLeft = '0px'; | ||
1199 | 451 | el.style.marginRight = '0px'; | ||
1200 | 452 | $unparent(el); | ||
1201 | 453 | UI.bucket.appendChild(el); | ||
1202 | 454 | } | ||
1203 | 455 | UI.bucket.removeChild(this.element); | ||
1204 | 456 | UI.sequence.do_reorder(); | ||
1205 | 457 | for(var a in UI.conts)if(UI.conts[a].id == this.id)UI.conts.splice(a,1); | ||
1206 | 458 | return; | ||
1207 | 459 | } | ||
1208 | 460 | this.list.style.display = 'none'; | ||
1209 | 461 | this.comp.style.display = 'block'; | ||
1210 | 462 | |||
1211 | 463 | }, | ||
1212 | 464 | reset_margin: function(){ | ||
1213 | 465 | for(var a = 0;a<this.list.childNodes.length;a++){ | ||
1214 | 466 | this.list.childNodes[a].style.marginLeft = 0 + 'px'; | ||
1215 | 467 | this.list.childNodes[a].style.marginRight = 0 + 'px'; | ||
1216 | 468 | } | ||
1217 | 469 | }, | ||
1218 | 470 | slice_on: function(x){ | ||
1219 | 471 | if(this.list.childNodes.length == 0){ | ||
1220 | 472 | this.pos = -1; | ||
1221 | 473 | return; | ||
1222 | 474 | } | ||
1223 | 475 | this.reset_margin(); | ||
1224 | 476 | this.pos = parseInt(x/130); | ||
1225 | 477 | if(this.pos >= this.list.childNodes.length) this.list.lastChild.style.marginRight = 130 + 'px'; | ||
1226 | 478 | else if(this.list.childNodes[this.pos].classList[1] != 'selected') this.list.childNodes[this.pos].style.marginLeft = 130 + 'px'; | ||
1227 | 479 | }, | ||
1228 | 480 | on_dblclick: function(event) { | ||
1229 | 481 | this.expand(); | ||
1230 | 482 | }, | ||
1231 | 483 | on_mousedown: function(event) { | ||
1232 | 484 | UI.select(this.doc._id); | ||
1233 | 485 | if (UI.player.active) { | ||
1234 | 486 | UI.player.hold(); | ||
1235 | 487 | } | ||
1236 | 488 | this.pos = $position(this.element); | ||
1237 | 489 | this.dnd = new DragEvent(event, this.element); | ||
1238 | 490 | this.dnd.ondragcancel = $bind(this.on_dragcancel, this); | ||
1239 | 491 | this.dnd.ondragstart = $bind(this.on_dragstart, this); | ||
1240 | 492 | this.dnd.ondrag = $bind(this.on_drag, this); | ||
1241 | 493 | this.dnd.ondrop = $bind(this.on_drop, this); | ||
1242 | 494 | }, | ||
1243 | 495 | |||
1244 | 496 | on_dragcancel: function(dnd) { | ||
1245 | 497 | console.log('dragcancel'); | ||
1246 | 498 | if (UI.player.active) { | ||
1247 | 499 | UI.player.resume(); | ||
1248 | 500 | } | ||
1249 | 501 | this.stop_scrolling(); | ||
1250 | 502 | if (this.inbucket && UI.bucket.lastChild != this.element) { | ||
1251 | 503 | console.log('moving to end of bucket'); | ||
1252 | 504 | $unparent(this.element); | ||
1253 | 505 | UI.bucket.appendChild(this.element); | ||
1254 | 506 | UI.sequence.do_reorder(); | ||
1255 | 507 | } | ||
1256 | 508 | }, | ||
1257 | 509 | |||
1258 | 510 | on_dragstart: function(dnd) { | ||
1259 | 511 | console.log('dragstart'); | ||
1260 | 512 | this.offsetX = this.dnd.offsetX; | ||
1261 | 513 | this.offsetY = this.dnd.offsetY; | ||
1262 | 514 | this.offsetWidth = this.element.offsetWidth; | ||
1263 | 515 | this.offsetHeight = this.element.offsetHeight; | ||
1264 | 516 | |||
1265 | 517 | this.parent = this.element.parentNode; | ||
1266 | 518 | this.x = dnd.x - this.offsetX; | ||
1267 | 519 | if (this.inbucket) { | ||
1268 | 520 | this.y = dnd.y - this.offsetY; | ||
1269 | 521 | } | ||
1270 | 522 | else { | ||
1271 | 523 | this.nextSibling = this.element.nextSibling; | ||
1272 | 524 | if (this.element.nextSibling) { | ||
1273 | 525 | this.over = this.element.nextSibling; | ||
1274 | 526 | this.over.classList.add('over'); | ||
1275 | 527 | } | ||
1276 | 528 | else if (this.element.previousSibling) { | ||
1277 | 529 | this.over = this.element.previousSibling; | ||
1278 | 530 | this.over.classList.add('over-right'); | ||
1279 | 531 | } | ||
1280 | 532 | this.target = this.element; | ||
1281 | 533 | var seq = this.element.parentNode; | ||
1282 | 534 | var i, child; | ||
1283 | 535 | for (i=0; i<seq.children.length; i++) { | ||
1284 | 536 | child = seq.children[i]; | ||
1285 | 537 | if (child == this.element) { | ||
1286 | 538 | this.i = i; | ||
1287 | 539 | this.orig_i = i; | ||
1288 | 540 | } | ||
1289 | 541 | } | ||
1290 | 542 | this.y = UI.sequence.top - 14; | ||
1291 | 543 | } | ||
1292 | 544 | this.element.classList.add('grabbed'); | ||
1293 | 545 | }, | ||
1294 | 546 | |||
1295 | 547 | on_drag: function(dnd) { | ||
1296 | 548 | var top = UI.sequence.top; | ||
1297 | 549 | var height = this.element.clientHeight; | ||
1298 | 550 | var y = dnd.y - this.offsetY; | ||
1299 | 551 | var f = 0.65; | ||
1300 | 552 | if (this.inbucket) { | ||
1301 | 553 | if (y > top - height * (1 - f)) { | ||
1302 | 554 | this.move_into_sequence(dnd); | ||
1303 | 555 | } | ||
1304 | 556 | } | ||
1305 | 557 | else { | ||
1306 | 558 | if (y < top - height * f) { | ||
1307 | 559 | this.move_into_bucket(dnd); | ||
1308 | 560 | } | ||
1309 | 561 | } | ||
1310 | 562 | if (this.inbucket) { | ||
1311 | 563 | this.on_mousemove_bucket(dnd); | ||
1312 | 564 | } | ||
1313 | 565 | else { | ||
1314 | 566 | this.on_mousemove_sequence(dnd); | ||
1315 | 567 | } | ||
1316 | 568 | this.on_mousemove_bucket(dnd); | ||
1317 | 569 | }, | ||
1318 | 570 | on_click: function(dnd){ | ||
1319 | 571 | dnd.stopPropagation(); | ||
1320 | 572 | }, | ||
1321 | 573 | |||
1322 | 574 | on_drop: function(dnd) { | ||
1323 | 575 | this.stop_scrolling(); | ||
1324 | 576 | this.element.classList.remove('grabbed'); | ||
1325 | 577 | this.clear_over(); | ||
1326 | 578 | UI.sequence.reset(); | ||
1327 | 579 | if (this.inbucket) { | ||
1328 | 580 | if (UI.player.active) { | ||
1329 | 581 | UI.player.hide(); | ||
1330 | 582 | } | ||
1331 | 583 | if (UI.bucket.lastChild != this.element) { | ||
1332 | 584 | $unparent(this.element); | ||
1333 | 585 | UI.bucket.appendChild(this.element); | ||
1334 | 586 | } | ||
1335 | 587 | var pos = $position(UI.bucket); | ||
1336 | 588 | this.x = Math.max(0, dnd.x - this.offsetX - pos.left); | ||
1337 | 589 | this.y = Math.max(0, dnd.y - this.offsetY - pos.top); | ||
1338 | 590 | } | ||
1339 | 591 | else { | ||
1340 | 592 | console.log(this.orig_i + ' => ' + this.i); | ||
1341 | 593 | this.x = null; | ||
1342 | 594 | this.y = null; | ||
1343 | 595 | var seq = $('sequence'); | ||
1344 | 596 | if (this.i == this.orig_i) { | ||
1345 | 597 | console.assert(seq.children[this.i] == this.element); | ||
1346 | 598 | } | ||
1347 | 599 | else { | ||
1348 | 600 | if (this.i < this.orig_i) { | ||
1349 | 601 | var ref = seq.children[this.i]; | ||
1350 | 602 | } | ||
1351 | 603 | else { | ||
1352 | 604 | var ref = seq.children[this.i].nextSibling; | ||
1353 | 605 | } | ||
1354 | 606 | $unparent(this.element); | ||
1355 | 607 | seq.insertBefore(this.element, ref); | ||
1356 | 608 | } | ||
1357 | 609 | } | ||
1358 | 610 | UI.sequence.do_reorder(); | ||
1359 | 611 | if (UI.player.active) { | ||
1360 | 612 | UI.player.resume(); | ||
1361 | 613 | } | ||
1362 | 614 | }, | ||
1363 | 615 | on_mousemove_bucket: function(dnd) { | ||
1364 | 616 | this.x = dnd.x - this.offsetX; | ||
1365 | 617 | this.y = dnd.y - this.offsetY; | ||
1366 | 618 | }, | ||
1367 | 619 | move_into_bucket: function(dnd) { | ||
1368 | 620 | if (UI.player.active) { | ||
1369 | 621 | UI.player.soft_hide(); | ||
1370 | 622 | } | ||
1371 | 623 | this.stop_scrolling(); | ||
1372 | 624 | $unparent(this.element); | ||
1373 | 625 | $('bucket').appendChild(this.element); | ||
1374 | 626 | if (this.frombucket) { | ||
1375 | 627 | this.clear_over(); | ||
1376 | 628 | UI.sequence.reset(); | ||
1377 | 629 | } | ||
1378 | 630 | this.update_offset(); | ||
1379 | 631 | }, | ||
1380 | 632 | on_mousemove_sequence: function(dnd) { | ||
1381 | 633 | var mid_x = dnd.x - this.offsetX + (this.element.offsetWidth / 2); | ||
1382 | 634 | var width = UI.sequence.element.clientWidth; | ||
1383 | 635 | var left = Math.min(dnd.x, mid_x); | ||
1384 | 636 | var right = Math.max(dnd.x, mid_x); | ||
1385 | 637 | |||
1386 | 638 | if (this.scrolling) { | ||
1387 | 639 | if (left > 0 && right < width) { | ||
1388 | 640 | this.stop_scrolling(); | ||
1389 | 641 | } | ||
1390 | 642 | else { | ||
1391 | 643 | return; | ||
1392 | 644 | } | ||
1393 | 645 | } | ||
1394 | 646 | else { | ||
1395 | 647 | if (left <= 0) { | ||
1396 | 648 | this.start_scrolling('left'); | ||
1397 | 649 | } | ||
1398 | 650 | else if (right >= width) { | ||
1399 | 651 | this.start_scrolling('right'); | ||
1400 | 652 | } | ||
1401 | 653 | } | ||
1402 | 654 | this.do_mousemove_sequence(); | ||
1403 | 655 | }, | ||
1404 | 656 | |||
1405 | 657 | do_mousemove_sequence: function() { | ||
1406 | 658 | var x = this.dnd.x - this.offsetX; | ||
1407 | 659 | var parent = UI.sequence.element; | ||
1408 | 660 | var scroll_x = x + parent.scrollLeft; | ||
1409 | 661 | var ix = this.i * this.width; | ||
1410 | 662 | var dx = scroll_x - ix; | ||
1411 | 663 | |||
1412 | 664 | this.x = x; | ||
1413 | 665 | this.y = UI.sequence.top - 14; | ||
1414 | 666 | |||
1415 | 667 | if (dx < -this.threshold) { | ||
1416 | 668 | this.shift_right(); | ||
1417 | 669 | } | ||
1418 | 670 | else if (dx > this.threshold) { | ||
1419 | 671 | this.shift_left(); | ||
1420 | 672 | } | ||
1421 | 673 | }, | ||
1422 | 674 | move_into_sequence: function(dnd) { | ||
1423 | 675 | if (UI.player.active) { | ||
1424 | 676 | UI.player.soft_show(); | ||
1425 | 677 | } | ||
1426 | 678 | if (!this.frombucket) { | ||
1427 | 679 | this.clear_over(); | ||
1428 | 680 | UI.sequence.reset(); | ||
1429 | 681 | } | ||
1430 | 682 | var seq = UI.sequence.element; | ||
1431 | 683 | if (seq.children.length == 0) { | ||
1432 | 684 | this.i = 0; | ||
1433 | 685 | this.orig_i = 0; | ||
1434 | 686 | this.target = this.element; | ||
1435 | 687 | seq.appendChild(this.element); | ||
1436 | 688 | this.update_offset(); | ||
1437 | 689 | return; | ||
1438 | 690 | } | ||
1439 | 691 | |||
1440 | 692 | var x = this.pos.left + dnd.dx; | ||
1441 | 693 | |||
1442 | 694 | var scroll_x = x + seq.scrollLeft; | ||
1443 | 695 | |||
1444 | 696 | var unclamped = Math.round(scroll_x / this.width); | ||
1445 | 697 | this.i = Math.max(0, Math.min(unclamped, seq.children.length)); | ||
1446 | 698 | this.orig_i = this.i; | ||
1447 | 699 | if (this.i == seq.children.length) { | ||
1448 | 700 | this.over = seq.children[this.i - 1]; | ||
1449 | 701 | this.over.classList.add('over-right'); | ||
1450 | 702 | } | ||
1451 | 703 | else { | ||
1452 | 704 | this.over = seq.children[this.i]; | ||
1453 | 705 | this.over.classList.add('over'); | ||
1454 | 706 | } | ||
1455 | 707 | |||
1456 | 708 | var ref = seq.children[this.i]; | ||
1457 | 709 | $unparent(this.element); | ||
1458 | 710 | seq.insertBefore(this.element, ref); | ||
1459 | 711 | if (!ref) { | ||
1460 | 712 | seq.scrollLeft += this.width; | ||
1461 | 713 | } | ||
1462 | 714 | this.target = this.element; | ||
1463 | 715 | this.update_offset(); | ||
1464 | 716 | }, | ||
1465 | 717 | update_offset: function() { | ||
1466 | 718 | this.offsetX = Math.round(this.dnd.offsetX * this.element.offsetWidth / this.offsetWidth); | ||
1467 | 719 | this.offsetY = Math.round(this.dnd.offsetY * this.element.offsetHeight / this.offsetHeight); | ||
1468 | 720 | }, | ||
1469 | 721 | clear_over: function() { | ||
1470 | 722 | if (this.over) { | ||
1471 | 723 | this.over.classList.remove('over'); | ||
1472 | 724 | this.over.classList.remove('over-right'); | ||
1473 | 725 | this.over = null; | ||
1474 | 726 | } | ||
1475 | 727 | UI.animate(null); | ||
1476 | 728 | }, | ||
1477 | 729 | |||
1478 | 730 | start_scrolling: function(direction) { | ||
1479 | 731 | this.direction = direction; | ||
1480 | 732 | this.scrolling = true; | ||
1481 | 733 | this.interval_id = setInterval($bind(this.on_interval, this), 300); | ||
1482 | 734 | }, | ||
1483 | 735 | stop_scrolling: function() { | ||
1484 | 736 | this.scrolling = false; | ||
1485 | 737 | clearInterval(this.interval_id); | ||
1486 | 738 | this.interval_id = null; | ||
1487 | 739 | }, | ||
1488 | 740 | on_interval: function() { | ||
1489 | 741 | var d = (this.direction == 'left') ? -1 : 1; | ||
1490 | 742 | UI.sequence.element.scrollLeft += (d * this.width); | ||
1491 | 743 | this.do_mousemove_sequence(); | ||
1492 | 744 | }, | ||
1493 | 745 | shift_right: function() { | ||
1494 | 746 | if (!this.target.previousSibling) { | ||
1495 | 747 | return; | ||
1496 | 748 | } | ||
1497 | 749 | this.i -= 1; | ||
1498 | 750 | if (this.target.classList.contains('left')) { | ||
1499 | 751 | this.target.classList.remove('left'); | ||
1500 | 752 | UI.animate(this.target); | ||
1501 | 753 | } | ||
1502 | 754 | else { | ||
1503 | 755 | this.target.previousSibling.classList.add('right'); | ||
1504 | 756 | UI.animate(this.target.previousSibling); | ||
1505 | 757 | } | ||
1506 | 758 | this.target = this.target.previousSibling; | ||
1507 | 759 | }, | ||
1508 | 760 | |||
1509 | 761 | shift_left: function() { | ||
1510 | 762 | if (!this.target.nextSibling) { | ||
1511 | 763 | return; | ||
1512 | 764 | } | ||
1513 | 765 | this.i += 1; | ||
1514 | 766 | if (this.target.classList.contains('right')) { | ||
1515 | 767 | this.target.classList.remove('right'); | ||
1516 | 768 | UI.animate(this.target); | ||
1517 | 769 | } | ||
1518 | 770 | else { | ||
1519 | 771 | this.target.nextSibling.classList.add('left'); | ||
1520 | 772 | UI.animate(this.target.nextSibling); | ||
1521 | 773 | } | ||
1522 | 774 | this.target = this.target.nextSibling; | ||
1523 | 775 | |||
1524 | 776 | }, | ||
1525 | 777 | destroy: function() { | ||
1526 | 778 | $unparent(this.element); | ||
1527 | 779 | delete this.element; | ||
1528 | 780 | }, | ||
1529 | 781 | on_change: function(doc) { | ||
1530 | 782 | if (doc._deleted) { | ||
1531 | 783 | console.log('deleted ' + doc._id); | ||
1532 | 784 | this.destroy(); | ||
1533 | 785 | UI.sequence.do_reorder(); | ||
1534 | 786 | return; | ||
1535 | 787 | } | ||
1536 | 788 | this.doc = doc; | ||
1537 | 789 | for(var a in doc.node.src){ | ||
1538 | 790 | console.log(doc.node.src[a]); | ||
1539 | 791 | var tdoc = UI.session.get_doc(doc.node.src[a]); | ||
1540 | 792 | var slice = new Slice(UI.session, tdoc); | ||
1541 | 793 | slice.start.request_thumbnail(); | ||
1542 | 794 | slice.end.request_thumbnail(); | ||
1543 | 795 | $unparent(slice.element); | ||
1544 | 796 | this.list.appendChild(slice.element); | ||
1545 | 797 | } | ||
1546 | 798 | }, | ||
1547 | 799 | } | ||
1548 | 800 | |||
1549 | 801 | var Slice = function(session, doc) { | ||
1550 | 802 | session.subscribe(doc._id, this.on_change, this); | ||
1551 | 803 | this.session = session; | ||
1552 | 804 | this.element = $el('div', {'class': 'slice', 'id': doc._id}); | ||
1553 | 805 | |||
1554 | 806 | var file_id = doc.node.src; | ||
1555 | 807 | |||
1556 | 808 | this.start = new Frame(file_id, doc._id + '.start'); | ||
1557 | 809 | this.element.appendChild(this.start.element); | ||
1558 | 810 | |||
1559 | 811 | this.indicator = new SliceIndicator(); | ||
1560 | 812 | this.element.appendChild(this.indicator.element); | ||
1561 | 813 | |||
1562 | 814 | this.end = new Frame(file_id, doc._id + '.end'); | ||
1563 | 815 | this.element.appendChild(this.end.element); | ||
1564 | 816 | |||
1565 | 817 | this.start.element.onmousewheel = $bind(this.on_mousewheel_start, this); | ||
1566 | 818 | this.end.element.onmousewheel = $bind(this.on_mousewheel_end, this); | ||
1567 | 819 | this.element.onmousedown = $bind(this.on_mousedown, this); | ||
1568 | 820 | this.element.ondblclick = $bind(this.on_dblclick, this); | ||
1569 | 821 | |||
1570 | 822 | this.frames = session.get_doc(doc.node.src).duration.frames; | ||
1571 | 823 | this.on_change(doc); | ||
1572 | 824 | |||
1573 | 825 | this.i = null; | ||
1574 | 826 | this.over = null; | ||
1575 | 827 | this.width = 192 + 2; | ||
1576 | 828 | this.threshold = this.width * 0.65; | ||
1577 | 829 | this.timeout_id = null; | ||
1578 | 830 | |||
1579 | 831 | this.oncont = false; | ||
1580 | 832 | this.contn = 0; | ||
1581 | 833 | this.id = doc._id; | ||
1582 | 834 | UI.slices.push(this); | ||
1583 | 835 | } | ||
1584 | 836 | Slice.prototype = { | ||
1585 | 837 | destroy: function() { | ||
1586 | 838 | this.start.destroy(); | ||
1587 | 839 | delete this.start; | ||
1588 | 840 | this.end.destroy(); | ||
1589 | 841 | delete this.end; | ||
1590 | 842 | this.indicator.destroy(); | ||
1591 | 843 | delete this.indicator; | ||
1592 | 844 | $unparent(this.element); | ||
1593 | 845 | delete this.element; | ||
1594 | 846 | }, | ||
1595 | 847 | |||
1596 | 848 | set x(value) { | ||
1597 | 849 | if (typeof value == 'number') { | ||
1598 | 850 | this.element.style.left = value + 'px'; | ||
1599 | 851 | } | ||
1600 | 852 | else { | ||
1601 | 853 | this.element.style.left = null; | ||
1602 | 854 | } | ||
1603 | 855 | }, | ||
1604 | 856 | |||
1605 | 857 | set y(value) { | ||
1606 | 858 | if (typeof value == 'number') { | ||
1607 | 859 | this.element.style.top = value + 'px'; | ||
1608 | 860 | } | ||
1609 | 861 | else { | ||
1610 | 862 | this.element.style.top = null; | ||
1611 | 863 | } | ||
1612 | 864 | }, | ||
1613 | 865 | |||
1614 | 866 | get x() { | ||
1615 | 867 | if(this.element)return parseInt(this.element.style.left); | ||
1616 | 868 | else return -1; | ||
1617 | 869 | }, | ||
1618 | 870 | |||
1619 | 871 | get y() { | ||
1620 | 872 | return parseInt(this.element.style.top); | ||
1621 | 873 | }, | ||
1622 | 874 | |||
1623 | 875 | get inbucket() { | ||
1624 | 876 | return this.element.parentNode.id == 'bucket'; | ||
1625 | 877 | }, | ||
1626 | 878 | |||
1627 | 879 | get frombucket() { | ||
1628 | 880 | return this.parent.id == 'bucket'; | ||
1629 | 881 | }, | ||
1630 | 882 | |||
1631 | 883 | on_change: function(doc) { | ||
1632 | 884 | if (doc._deleted) { | ||
1633 | 885 | console.log('deleted ' + doc._id); | ||
1634 | 886 | this.destroy(); | ||
1635 | 887 | UI.sequence.do_reorder(); | ||
1636 | 888 | return; | ||
1637 | 889 | } | ||
1638 | 890 | this.doc = doc; | ||
1639 | 891 | var node = doc.node; | ||
1640 | 892 | this.start.set_index(node.start.frame); | ||
1641 | 893 | this.end.set_index(node.stop.frame - 1); | ||
1642 | 894 | this.indicator.update(node.start.frame, node.stop.frame, this.frames); | ||
1643 | 895 | Thumbs.flush(); | ||
1644 | 896 | }, | ||
1645 | 897 | |||
1646 | 898 | reset_adjustment_ux: function() { | ||
1647 | 899 | if (this.timeout_id == null) { | ||
1648 | 900 | UI.player.hold(); | ||
1649 | 901 | UI.select(this.doc._id); | ||
1650 | 902 | } | ||
1651 | 903 | clearTimeout(this.timeout_id); | ||
1652 | 904 | this.timeout_id = setTimeout($bind(this.on_timeout, this), 750); | ||
1653 | 905 | }, | ||
1654 | 906 | |||
1655 | 907 | on_timeout: function() { | ||
1656 | 908 | console.log('timeout'); | ||
1657 | 909 | this.timeout_id = null; | ||
1658 | 910 | UI.player.resume(); | ||
1659 | 911 | }, | ||
1660 | 912 | |||
1661 | 913 | on_mousewheel_start: function(event) { | ||
1662 | 914 | $halt(event); | ||
1663 | 915 | if (UI.player.active) { | ||
1664 | 916 | this.reset_adjustment_ux(); | ||
1665 | 917 | } | ||
1666 | 918 | var delta = wheel_delta(event); | ||
1667 | 919 | var start = this.doc.node.start.frame; | ||
1668 | 920 | var stop = this.doc.node.stop.frame; | ||
1669 | 921 | var proposed = Math.max(0, Math.min(start + delta, stop - 1)); | ||
1670 | 922 | if (start != proposed) { | ||
1671 | 923 | this.doc.node.start.frame = proposed; | ||
1672 | 924 | this.session.save(this.doc); | ||
1673 | 925 | this.session.delayed_commit(); | ||
1674 | 926 | } | ||
1675 | 927 | }, | ||
1676 | 928 | |||
1677 | 929 | on_mousewheel_end: function(event) { | ||
1678 | 930 | $halt(event); | ||
1679 | 931 | if (UI.player.active) { | ||
1680 | 932 | this.reset_adjustment_ux(); | ||
1681 | 933 | } | ||
1682 | 934 | var delta = wheel_delta(event); | ||
1683 | 935 | var start = this.doc.node.start.frame; | ||
1684 | 936 | var stop = this.doc.node.stop.frame; | ||
1685 | 937 | var proposed = Math.max(start + 1, Math.min(stop + delta, this.frames)); | ||
1686 | 938 | if (stop != proposed) { | ||
1687 | 939 | this.doc.node.stop.frame = proposed; | ||
1688 | 940 | this.session.save(this.doc); | ||
1689 | 941 | this.session.delayed_commit(); | ||
1690 | 942 | } | ||
1691 | 943 | }, | ||
1692 | 944 | |||
1693 | 945 | on_mousedown: function(event) { | ||
1694 | 946 | UI.select(this.doc._id); | ||
1695 | 947 | if (UI.player.active) { | ||
1696 | 948 | UI.player.hold(); | ||
1697 | 949 | } | ||
1698 | 950 | this.pos = $position(this.element); | ||
1699 | 951 | this.dnd = new DragEvent(event, this.element); | ||
1700 | 952 | this.dnd.ondragcancel = $bind(this.on_dragcancel, this); | ||
1701 | 953 | this.dnd.ondragstart = $bind(this.on_dragstart, this); | ||
1702 | 954 | this.dnd.ondrag = $bind(this.on_drag, this); | ||
1703 | 955 | this.dnd.ondrop = $bind(this.on_drop, this); | ||
1704 | 956 | }, | ||
1705 | 957 | |||
1706 | 958 | on_dblclick: function(event) { | ||
1707 | 959 | $halt(event); | ||
1708 | 960 | if (UI.player.active) { | ||
1709 | 961 | return; | ||
1710 | 962 | } | ||
1711 | 963 | UI.edit_slice(this.doc); | ||
1712 | 964 | }, | ||
1713 | 965 | |||
1714 | 966 | on_dragcancel: function(dnd) { | ||
1715 | 967 | console.log('dragcancel'); | ||
1716 | 968 | if (UI.player.active) { | ||
1717 | 969 | UI.player.resume(); | ||
1718 | 970 | } | ||
1719 | 971 | this.stop_scrolling(); | ||
1720 | 972 | if (this.inbucket && UI.bucket.lastChild != this.element) { | ||
1721 | 973 | console.log('moving to end of bucket'); | ||
1722 | 974 | $unparent(this.element); | ||
1723 | 975 | UI.bucket.appendChild(this.element); | ||
1724 | 976 | UI.sequence.do_reorder(); | ||
1725 | 977 | } | ||
1726 | 978 | }, | ||
1727 | 979 | |||
1728 | 980 | on_dragstart: function(dnd) { | ||
1729 | 981 | console.log('dragstart'); | ||
1730 | 982 | UI.dragging = true; | ||
1731 | 983 | this.offsetX = this.dnd.offsetX; | ||
1732 | 984 | this.offsetY = this.dnd.offsetY; | ||
1733 | 985 | this.offsetWidth = this.element.offsetWidth; | ||
1734 | 986 | this.offsetHeight = this.element.offsetHeight; | ||
1735 | 987 | |||
1736 | 988 | this.parent = this.element.parentNode; | ||
1737 | 989 | this.x = dnd.x - this.offsetX; | ||
1738 | 990 | if (this.inbucket) { | ||
1739 | 991 | this.y = dnd.y - this.offsetY; | ||
1740 | 992 | } | ||
1741 | 993 | else { | ||
1742 | 994 | this.nextSibling = this.element.nextSibling; | ||
1743 | 995 | if (this.element.nextSibling) { | ||
1744 | 996 | this.over = this.element.nextSibling; | ||
1745 | 997 | this.over.classList.add('over'); | ||
1746 | 998 | } | ||
1747 | 999 | else if (this.element.previousSibling) { | ||
1748 | 1000 | this.over = this.element.previousSibling; | ||
1749 | 1001 | this.over.classList.add('over-right'); | ||
1750 | 1002 | } | ||
1751 | 1003 | this.target = this.element; | ||
1752 | 1004 | var seq = this.element.parentNode; | ||
1753 | 1005 | var i, child; | ||
1754 | 1006 | for (i=0; i<seq.children.length; i++) { | ||
1755 | 1007 | child = seq.children[i]; | ||
1756 | 1008 | if (child == this.element) { | ||
1757 | 1009 | this.i = i; | ||
1758 | 1010 | this.orig_i = i; | ||
1759 | 1011 | } | ||
1760 | 1012 | } | ||
1761 | 1013 | this.y = UI.sequence.top - 14; | ||
1762 | 1014 | } | ||
1763 | 1015 | this.element.classList.add('grabbed'); | ||
1764 | 1016 | }, | ||
1765 | 1017 | |||
1766 | 1018 | on_drag: function(dnd) { | ||
1767 | 1019 | var top = UI.sequence.top; | ||
1768 | 1020 | var height = this.element.clientHeight; | ||
1769 | 1021 | var y = dnd.y - this.offsetY; | ||
1770 | 1022 | var x = dnd.x - this.offsetX; | ||
1771 | 1023 | var f = 0.65; | ||
1772 | 1024 | //if(this.oncont)UI.conts[oncontn].reset_margin(); | ||
1773 | 1025 | this.oncont = false; | ||
1774 | 1026 | for(var a in UI.conts){ | ||
1775 | 1027 | var b = UI.conts[a]; | ||
1776 | 1028 | if(b.element && b.x < x && b.y < y && b.x+parseInt(b.element.offsetWidth) > x && b.y+parseInt(b.element.offsetHeight) > y){ | ||
1777 | 1029 | b.expand(); | ||
1778 | 1030 | this.oncont = true; | ||
1779 | 1031 | this.oncontn = a; | ||
1780 | 1032 | } | ||
1781 | 1033 | else b.close(); | ||
1782 | 1034 | } | ||
1783 | 1035 | |||
1784 | 1036 | if(this.oncont) UI.conts[this.oncontn].slice_on(x-UI.conts[this.oncontn].x); | ||
1785 | 1037 | |||
1786 | 1038 | if (this.inbucket) { | ||
1787 | 1039 | if (y > top - height * (1 - f)) { | ||
1788 | 1040 | this.move_into_sequence(dnd); | ||
1789 | 1041 | } | ||
1790 | 1042 | } | ||
1791 | 1043 | else { | ||
1792 | 1044 | if (y < top - height * f) { | ||
1793 | 1045 | this.move_into_bucket(dnd); | ||
1794 | 1046 | } | ||
1795 | 1047 | } | ||
1796 | 1048 | if (this.inbucket) { | ||
1797 | 1049 | this.on_mousemove_bucket(dnd); | ||
1798 | 1050 | } | ||
1799 | 1051 | else { | ||
1800 | 1052 | this.on_mousemove_sequence(dnd); | ||
1801 | 1053 | } | ||
1802 | 1054 | }, | ||
1803 | 1055 | |||
1804 | 1056 | move_into_sequence: function(dnd) { | ||
1805 | 1057 | if (UI.player.active) { | ||
1806 | 1058 | UI.player.soft_show(); | ||
1807 | 1059 | } | ||
1808 | 1060 | if (!this.frombucket) { | ||
1809 | 1061 | this.clear_over(); | ||
1810 | 1062 | UI.sequence.reset(); | ||
1811 | 1063 | } | ||
1812 | 1064 | var seq = UI.sequence.element; | ||
1813 | 1065 | if (seq.children.length == 0) { | ||
1814 | 1066 | this.i = 0; | ||
1815 | 1067 | this.orig_i = 0; | ||
1816 | 1068 | this.target = this.element; | ||
1817 | 1069 | seq.appendChild(this.element); | ||
1818 | 1070 | this.update_offset(); | ||
1819 | 1071 | return; | ||
1820 | 1072 | } | ||
1821 | 1073 | |||
1822 | 1074 | var x = this.pos.left + dnd.dx; | ||
1823 | 1075 | |||
1824 | 1076 | var scroll_x = x + seq.scrollLeft; | ||
1825 | 1077 | |||
1826 | 1078 | var unclamped = Math.round(scroll_x / this.width); | ||
1827 | 1079 | this.i = Math.max(0, Math.min(unclamped, seq.children.length)); | ||
1828 | 1080 | this.orig_i = this.i; | ||
1829 | 1081 | if (this.i == seq.children.length) { | ||
1830 | 1082 | this.over = seq.children[this.i - 1]; | ||
1831 | 1083 | this.over.classList.add('over-right'); | ||
1832 | 1084 | } | ||
1833 | 1085 | else { | ||
1834 | 1086 | this.over = seq.children[this.i]; | ||
1835 | 1087 | this.over.classList.add('over'); | ||
1836 | 1088 | } | ||
1837 | 1089 | |||
1838 | 1090 | var ref = seq.children[this.i]; | ||
1839 | 1091 | $unparent(this.element); | ||
1840 | 1092 | seq.insertBefore(this.element, ref); | ||
1841 | 1093 | if (!ref) { | ||
1842 | 1094 | seq.scrollLeft += this.width; | ||
1843 | 1095 | } | ||
1844 | 1096 | this.target = this.element; | ||
1845 | 1097 | this.update_offset(); | ||
1846 | 1098 | }, | ||
1847 | 1099 | |||
1848 | 1100 | move_into_bucket: function(dnd) { | ||
1849 | 1101 | if (UI.player.active) { | ||
1850 | 1102 | UI.player.soft_hide(); | ||
1851 | 1103 | } | ||
1852 | 1104 | this.stop_scrolling(); | ||
1853 | 1105 | $unparent(this.element); | ||
1854 | 1106 | $('bucket').appendChild(this.element); | ||
1855 | 1107 | if (this.frombucket) { | ||
1856 | 1108 | this.clear_over(); | ||
1857 | 1109 | UI.sequence.reset(); | ||
1858 | 1110 | } | ||
1859 | 1111 | this.update_offset(); | ||
1860 | 1112 | }, | ||
1861 | 1113 | |||
1862 | 1114 | update_offset: function() { | ||
1863 | 1115 | this.offsetX = Math.round(this.dnd.offsetX * this.element.offsetWidth / this.offsetWidth); | ||
1864 | 1116 | this.offsetY = Math.round(this.dnd.offsetY * this.element.offsetHeight / this.offsetHeight); | ||
1865 | 1117 | }, | ||
1866 | 1118 | |||
1867 | 1119 | on_mousemove_bucket: function(dnd) { | ||
1868 | 1120 | this.x = dnd.x - this.offsetX; | ||
1869 | 1121 | this.y = dnd.y - this.offsetY; | ||
1870 | 1122 | }, | ||
1871 | 1123 | |||
1872 | 1124 | start_scrolling: function(direction) { | ||
1873 | 1125 | this.direction = direction; | ||
1874 | 1126 | this.scrolling = true; | ||
1875 | 1127 | this.interval_id = setInterval($bind(this.on_interval, this), 300); | ||
1876 | 1128 | }, | ||
1877 | 1129 | |||
1878 | 1130 | stop_scrolling: function() { | ||
1879 | 1131 | this.scrolling = false; | ||
1880 | 1132 | clearInterval(this.interval_id); | ||
1881 | 1133 | this.interval_id = null; | ||
1882 | 1134 | }, | ||
1883 | 1135 | |||
1884 | 1136 | on_interval: function() { | ||
1885 | 1137 | var d = (this.direction == 'left') ? -1 : 1; | ||
1886 | 1138 | UI.sequence.element.scrollLeft += (d * this.width); | ||
1887 | 1139 | this.do_mousemove_sequence(); | ||
1888 | 1140 | }, | ||
1889 | 1141 | |||
1890 | 1142 | on_mousemove_sequence: function(dnd) { | ||
1891 | 1143 | var mid_x = dnd.x - this.offsetX + (this.element.offsetWidth / 2); | ||
1892 | 1144 | var width = UI.sequence.element.clientWidth; | ||
1893 | 1145 | var left = Math.min(dnd.x, mid_x); | ||
1894 | 1146 | var right = Math.max(dnd.x, mid_x); | ||
1895 | 1147 | |||
1896 | 1148 | if (this.scrolling) { | ||
1897 | 1149 | if (left > 0 && right < width) { | ||
1898 | 1150 | this.stop_scrolling(); | ||
1899 | 1151 | } | ||
1900 | 1152 | else { | ||
1901 | 1153 | return; | ||
1902 | 1154 | } | ||
1903 | 1155 | } | ||
1904 | 1156 | else { | ||
1905 | 1157 | if (left <= 0) { | ||
1906 | 1158 | this.start_scrolling('left'); | ||
1907 | 1159 | } | ||
1908 | 1160 | else if (right >= width) { | ||
1909 | 1161 | this.start_scrolling('right'); | ||
1910 | 1162 | } | ||
1911 | 1163 | } | ||
1912 | 1164 | this.do_mousemove_sequence(); | ||
1913 | 1165 | }, | ||
1914 | 1166 | |||
1915 | 1167 | do_mousemove_sequence: function() { | ||
1916 | 1168 | var x = this.dnd.x - this.offsetX; | ||
1917 | 1169 | var parent = UI.sequence.element; | ||
1918 | 1170 | var scroll_x = x + parent.scrollLeft; | ||
1919 | 1171 | var ix = this.i * this.width; | ||
1920 | 1172 | var dx = scroll_x - ix; | ||
1921 | 1173 | |||
1922 | 1174 | this.x = x; | ||
1923 | 1175 | this.y = UI.sequence.top - 14; | ||
1924 | 1176 | |||
1925 | 1177 | if (dx < -this.threshold) { | ||
1926 | 1178 | this.shift_right(); | ||
1927 | 1179 | } | ||
1928 | 1180 | else if (dx > this.threshold) { | ||
1929 | 1181 | this.shift_left(); | ||
1930 | 1182 | } | ||
1931 | 1183 | }, | ||
1932 | 1184 | |||
1933 | 1185 | shift_right: function() { | ||
1934 | 1186 | if (!this.target.previousSibling) { | ||
1935 | 1187 | return; | ||
1936 | 1188 | } | ||
1937 | 1189 | this.i -= 1; | ||
1938 | 1190 | if (this.target.classList.contains('left')) { | ||
1939 | 1191 | this.target.classList.remove('left'); | ||
1940 | 1192 | UI.animate(this.target); | ||
1941 | 1193 | } | ||
1942 | 1194 | else { | ||
1943 | 1195 | this.target.previousSibling.classList.add('right'); | ||
1944 | 1196 | UI.animate(this.target.previousSibling); | ||
1945 | 1197 | } | ||
1946 | 1198 | this.target = this.target.previousSibling; | ||
1947 | 1199 | }, | ||
1948 | 1200 | |||
1949 | 1201 | shift_left: function() { | ||
1950 | 1202 | if (!this.target.nextSibling) { | ||
1951 | 1203 | return; | ||
1952 | 1204 | } | ||
1953 | 1205 | this.i += 1; | ||
1954 | 1206 | if (this.target.classList.contains('right')) { | ||
1955 | 1207 | this.target.classList.remove('right'); | ||
1956 | 1208 | UI.animate(this.target); | ||
1957 | 1209 | } | ||
1958 | 1210 | else { | ||
1959 | 1211 | this.target.nextSibling.classList.add('left'); | ||
1960 | 1212 | UI.animate(this.target.nextSibling); | ||
1961 | 1213 | } | ||
1962 | 1214 | this.target = this.target.nextSibling; | ||
1963 | 1215 | |||
1964 | 1216 | }, | ||
1965 | 1217 | |||
1966 | 1218 | clear_over: function() { | ||
1967 | 1219 | if (this.over) { | ||
1968 | 1220 | this.over.classList.remove('over'); | ||
1969 | 1221 | this.over.classList.remove('over-right'); | ||
1970 | 1222 | this.over = null; | ||
1971 | 1223 | } | ||
1972 | 1224 | UI.animate(null); | ||
1973 | 1225 | }, | ||
1974 | 1226 | |||
1975 | 1227 | on_drop: function(dnd) { | ||
1976 | 1228 | UI.dragging = false; | ||
1977 | 1229 | this.stop_scrolling(); | ||
1978 | 1230 | this.element.classList.remove('grabbed'); | ||
1979 | 1231 | this.clear_over(); | ||
1980 | 1232 | if(this.oncont){ | ||
1981 | 1233 | this.x = null; | ||
1982 | 1234 | this.y = null; | ||
1983 | 1235 | var pos = UI.conts[this.contn].pos; | ||
1984 | 1236 | console.log(pos); | ||
1985 | 1237 | $unparent(this.element); | ||
1986 | 1238 | $unselect(UI.selected); | ||
1987 | 1239 | if(pos == -1) UI.conts[this.contn].list.appendChild(this.element); | ||
1988 | 1240 | else UI.conts[this.contn].list.insertBefore(this.element,UI.conts[this.contn].list.childNodes[pos]); | ||
1989 | 1241 | //UI.conts[this.contn].list.appendChild(this.element); | ||
1990 | 1242 | //UI.conts[this.contn].doc.node.src.push(this.id); | ||
1991 | 1243 | //this.session.save( UI.conts[this.contn].doc,true); | ||
1992 | 1244 | UI.conts[this.contn].reset_margin(); | ||
1993 | 1245 | UI.conts[this.contn].save(); | ||
1994 | 1246 | UI.sequence.do_reorder(); | ||
1995 | 1247 | for(var a in UI.slices)if(UI.slices[a].id == this.id)UI.slices.splice(a,1); | ||
1996 | 1248 | return; | ||
1997 | 1249 | } | ||
1998 | 1250 | UI.sequence.reset(); | ||
1999 | 1251 | if (this.inbucket) { | ||
2000 | 1252 | if (UI.player.active) { | ||
2001 | 1253 | UI.player.hide(); | ||
2002 | 1254 | } | ||
2003 | 1255 | if (UI.bucket.lastChild != this.element) { | ||
2004 | 1256 | $unparent(this.element); | ||
2005 | 1257 | UI.bucket.appendChild(this.element); | ||
2006 | 1258 | } | ||
2007 | 1259 | var pos = $position(UI.bucket); | ||
2008 | 1260 | this.x = Math.max(0, dnd.x - this.offsetX - pos.left); | ||
2009 | 1261 | this.y = Math.max(0, dnd.y - this.offsetY - pos.top); | ||
2010 | 1262 | } | ||
2011 | 1263 | else { | ||
2012 | 1264 | console.log(this.orig_i + ' => ' + this.i); | ||
2013 | 1265 | this.x = null; | ||
2014 | 1266 | this.y = null; | ||
2015 | 1267 | var seq = $('sequence'); | ||
2016 | 1268 | if (this.i == this.orig_i) { | ||
2017 | 1269 | console.assert(seq.children[this.i] == this.element); | ||
2018 | 1270 | } | ||
2019 | 1271 | else { | ||
2020 | 1272 | if (this.i < this.orig_i) { | ||
2021 | 1273 | var ref = seq.children[this.i]; | ||
2022 | 1274 | } | ||
2023 | 1275 | else { | ||
2024 | 1276 | var ref = seq.children[this.i].nextSibling; | ||
2025 | 1277 | } | ||
2026 | 1278 | $unparent(this.element); | ||
2027 | 1279 | seq.insertBefore(this.element, ref); | ||
2028 | 1280 | } | ||
2029 | 1281 | } | ||
2030 | 1282 | if(UI.conts[this.contn]) UI.conts[this.contn].save(); | ||
2031 | 1283 | UI.sequence.do_reorder(); | ||
2032 | 1284 | if (UI.player.active) { | ||
2033 | 1285 | UI.player.resume(); | ||
2034 | 1286 | } | ||
2035 | 1287 | }, | ||
2036 | 1288 | } | ||
2037 | 1289 | |||
2038 | 1290 | |||
2039 | 1291 | function $compare(one, two) { | ||
2040 | 1292 | if (! (one instanceof Array && two instanceof Array)) { | ||
2041 | 1293 | return false; | ||
2042 | 1294 | } | ||
2043 | 1295 | if (one.length != two.length) { | ||
2044 | 1296 | return false; | ||
2045 | 1297 | } | ||
2046 | 1298 | var i; | ||
2047 | 1299 | for (i in one) { | ||
2048 | 1300 | if (one[i] != two[i]) { | ||
2049 | 1301 | return false; | ||
2050 | 1302 | } | ||
2051 | 1303 | } | ||
2052 | 1304 | return true; | ||
2053 | 1305 | } | ||
2054 | 1306 | |||
2055 | 1307 | |||
2056 | 1308 | var Sequence = function(session, doc) { | ||
2057 | 1309 | this.element = $('sequence'); | ||
2058 | 1310 | this.bucket = $('bucket'); | ||
2059 | 1311 | session.subscribe(doc._id, this.on_change, this); | ||
2060 | 1312 | this.session = session; | ||
2061 | 1313 | this.on_change(doc); | ||
2062 | 1314 | |||
2063 | 1315 | this.element.onmousedown = $bind(this.on_mousedown, this); | ||
2064 | 1316 | this.element.onscroll = $bind(this.on_scroll, this); | ||
2065 | 1317 | this.element.onchildselect = $bind(this.on_childselect, this); | ||
2066 | 1318 | } | ||
2067 | 1319 | Sequence.prototype = { | ||
2068 | 1320 | get top() { | ||
2069 | 1321 | return this.element.offsetTop + 24; | ||
2070 | 1322 | }, | ||
2071 | 1323 | |||
2072 | 1324 | on_childselect: function(id) { | ||
2073 | 1325 | console.log('childselect ' + id); | ||
2074 | 1326 | $hscroll($(id)); | ||
2075 | 1327 | }, | ||
2076 | 1328 | |||
2077 | 1329 | on_change: function(doc) { | ||
2078 | 1330 | console.log('Sequence.on_change()'); | ||
2079 | 1331 | this.doc = doc; | ||
2080 | 1332 | |||
2081 | 1333 | Thumbs.freeze(); | ||
2082 | 1334 | |||
2083 | 1335 | var i, _id, child, element; | ||
2084 | 1336 | for (i in doc.node.src) { | ||
2085 | 1337 | _id = doc.node.src[i]; | ||
2086 | 1338 | child = this.element.children[i]; | ||
2087 | 1339 | if (!child || child.id != _id) { | ||
2088 | 1340 | element = UI.get_slice(_id); | ||
2089 | 1341 | if (element) { | ||
2090 | 1342 | this.element.insertBefore(element, child); | ||
2091 | 1343 | } | ||
2092 | 1344 | } | ||
2093 | 1345 | } | ||
2094 | 1346 | |||
2095 | 1347 | if (! doc.doodle instanceof Array) { | ||
2096 | 1348 | UI.sequence.doc.doodle = []; | ||
2097 | 1349 | } | ||
2098 | 1350 | |||
2099 | 1351 | var obj; | ||
2100 | 1352 | for (i in doc.doodle) { | ||
2101 | 1353 | obj = doc.doodle[i]; | ||
2102 | 1354 | child = this.bucket.children[i]; | ||
2103 | 1355 | if (!child || child.id != obj.id) { | ||
2104 | 1356 | element = UI.get_slice(obj.id); | ||
2105 | 1357 | if (element) { | ||
2106 | 1358 | this.bucket.insertBefore(element, child); | ||
2107 | 1359 | } | ||
2108 | 1360 | child = element; | ||
2109 | 1361 | } | ||
2110 | 1362 | if (child) { | ||
2111 | 1363 | child.style.left = obj.x + 'px'; | ||
2112 | 1364 | child.style.top = obj.y + 'px'; | ||
2113 | 1365 | } | ||
2114 | 1366 | } | ||
2115 | 1367 | |||
2116 | 1368 | UI.select(doc.selected); | ||
2117 | 1369 | |||
2118 | 1370 | Thumbs.unfreeze(); | ||
2119 | 1371 | |||
2120 | 1372 | console.assert( | ||
2121 | 1373 | $compare(this.doc.node.src, this.get_src()) | ||
2122 | 1374 | ); | ||
2123 | 1375 | }, | ||
2124 | 1376 | |||
2125 | 1377 | on_scroll: function(event) { | ||
2126 | 1378 | this.element.style.setProperty('background-position', -this.element.scrollLeft + 'px 0px'); | ||
2127 | 1379 | }, | ||
2128 | 1380 | |||
2129 | 1381 | on_mousedown: function(event) { | ||
2130 | 1382 | console.log('sequence mousedown'); | ||
2131 | 1383 | this.dnd = new DragEvent(event, this.element); | ||
2132 | 1384 | this.dnd.ondrag = $bind(this.on_drag, this); | ||
2133 | 1385 | this.dnd.scrollLeft = this.element.scrollLeft; | ||
2134 | 1386 | }, | ||
2135 | 1387 | |||
2136 | 1388 | on_drag: function(dnd) { | ||
2137 | 1389 | this.element.scrollLeft = dnd.scrollLeft - dnd.dx; | ||
2138 | 1390 | }, | ||
2139 | 1391 | |||
2140 | 1392 | get_src: function() { | ||
2141 | 1393 | var i; | ||
2142 | 1394 | var src = []; | ||
2143 | 1395 | for (i=0; i<this.element.children.length; i++) { | ||
2144 | 1396 | src.push(this.element.children[i].id); | ||
2145 | 1397 | } | ||
2146 | 1398 | return src; | ||
2147 | 1399 | }, | ||
2148 | 1400 | |||
2149 | 1401 | get_doodle: function() { | ||
2150 | 1402 | var i, child; | ||
2151 | 1403 | var doodle = []; | ||
2152 | 1404 | for (i=0; i<this.bucket.children.length; i++) { | ||
2153 | 1405 | var child = this.bucket.children[i]; | ||
2154 | 1406 | doodle.push({ | ||
2155 | 1407 | id: child.id, | ||
2156 | 1408 | x: parseInt(child.style.left), | ||
2157 | 1409 | y: parseInt(child.style.top), | ||
2158 | 1410 | }); | ||
2159 | 1411 | } | ||
2160 | 1412 | return doodle; | ||
2161 | 1413 | }, | ||
2162 | 1414 | |||
2163 | 1415 | do_reorder: function() { | ||
2164 | 1416 | console.log('do_reorder'); | ||
2165 | 1417 | var src = this.get_src(); | ||
2166 | 1418 | var doodle = this.get_doodle(); | ||
2167 | 1419 | this.doc.node.src = src; | ||
2168 | 1420 | this.doc.doodle = doodle; | ||
2169 | 1421 | this.session.save(this.doc, true); // no_emit=true | ||
2170 | 1422 | this.session.commit(); | ||
2171 | 1423 | }, | ||
2172 | 1424 | |||
2173 | 1425 | reset: function() { | ||
2174 | 1426 | console.log('Sequence.reset()'); | ||
2175 | 1427 | var i, child; | ||
2176 | 1428 | for (i=0; i<this.element.children.length; i++) { | ||
2177 | 1429 | child = this.element.children[i]; | ||
2178 | 1430 | if (!child.classList.contains('grabbed')) { | ||
2179 | 1431 | child.classList.remove('left'); | ||
2180 | 1432 | child.classList.remove('right'); | ||
2181 | 1433 | } | ||
2182 | 1434 | } | ||
2183 | 1435 | }, | ||
2184 | 1436 | } | ||
2185 | 1437 | |||
2186 | 1438 | var VideoFrame = function(which) { | ||
2187 | 1439 | this.element = $el('div', {'class': 'videoframe ' + which}); | ||
2188 | 1440 | this.video = $el('video'); | ||
2189 | 1441 | this.element.appendChild(this.video); | ||
2190 | 1442 | this.info = $el('div'); | ||
2191 | 1443 | this.element.appendChild(this.info); | ||
2192 | 1444 | this.ready = false; | ||
2193 | 1445 | this.pending = null; | ||
2194 | 1446 | this.video.addEventListener('canplaythrough', | ||
2195 | 1447 | $bind(this.on_canplaythrough, this) | ||
2196 | 1448 | ); | ||
2197 | 1449 | this.video.addEventListener('seeked', | ||
2198 | 1450 | $bind(this.on_seeked, this) | ||
2199 | 1451 | ); | ||
2200 | 1452 | } | ||
2201 | 1453 | VideoFrame.prototype = { | ||
2202 | 1454 | set_index: function(index) { | ||
2203 | 1455 | this.info.textContent = index + 1; | ||
2204 | 1456 | this.seek(index); | ||
2205 | 1457 | }, | ||
2206 | 1458 | |||
2207 | 1459 | on_canplaythrough: function(event) { | ||
2208 | 1460 | this.ready = true; | ||
2209 | 1461 | this.do_seek(); | ||
2210 | 1462 | }, | ||
2211 | 1463 | |||
2212 | 1464 | on_seeked: function(event) { | ||
2213 | 1465 | if (this.pending != null) { | ||
2214 | 1466 | this.do_seek(); | ||
2215 | 1467 | } | ||
2216 | 1468 | }, | ||
2217 | 1469 | |||
2218 | 1470 | set_clip: function(clip) { | ||
2219 | 1471 | this.ready = false; | ||
2220 | 1472 | this.framerate = clip.framerate; | ||
2221 | 1473 | this.frames = clip.duration.frames; | ||
2222 | 1474 | this.pending = null; | ||
2223 | 1475 | this.video.src = 'dmedia:' + clip._id; | ||
2224 | 1476 | }, | ||
2225 | 1477 | |||
2226 | 1478 | play: function() { | ||
2227 | 1479 | this.video.play(); | ||
2228 | 1480 | }, | ||
2229 | 1481 | |||
2230 | 1482 | pause: function() { | ||
2231 | 1483 | this.video.pause(); | ||
2232 | 1484 | }, | ||
2233 | 1485 | |||
2234 | 1486 | seek: function(index) { | ||
2235 | 1487 | this.pending = frame_to_seconds(index, this.framerate); | ||
2236 | 1488 | if (this.ready && ! this.video.seeking) { | ||
2237 | 1489 | this.do_seek(); | ||
2238 | 1490 | } | ||
2239 | 1491 | }, | ||
2240 | 1492 | |||
2241 | 1493 | do_seek: function() { | ||
2242 | 1494 | var t = this.pending; | ||
2243 | 1495 | this.pending = null; | ||
2244 | 1496 | this.video.currentTime = t; | ||
2245 | 1497 | }, | ||
2246 | 1498 | |||
2247 | 1499 | show: function() { | ||
2248 | 1500 | this.element.classList.remove('hide'); | ||
2249 | 1501 | }, | ||
2250 | 1502 | |||
2251 | 1503 | hide: function() { | ||
2252 | 1504 | this.video.pause(); | ||
2253 | 1505 | this.element.classList.add('hide'); | ||
2254 | 1506 | }, | ||
2255 | 1507 | |||
2256 | 1508 | get_x: function(width) { | ||
2257 | 1509 | return Math.round(width * this.video.currentTime / this.video.duration); | ||
2258 | 1510 | }, | ||
2259 | 1511 | |||
2260 | 1512 | get_frame: function() { | ||
2261 | 1513 | return Math.round(this.frames * this.video.currentTime / this.video.duration); | ||
2262 | 1514 | }, | ||
2263 | 1515 | } | ||
2264 | 1516 | |||
2265 | 1517 | |||
2266 | 1518 | var RoughCut = function(session) { | ||
2267 | 1519 | this.session = session; | ||
2268 | 1520 | this.active = false; | ||
2269 | 1521 | |||
2270 | 1522 | this.element = $('roughcut'); | ||
2271 | 1523 | this.frames = $el('div', {'class': 'frames'}); | ||
2272 | 1524 | this.element.appendChild(this.frames); | ||
2273 | 1525 | |||
2274 | 1526 | this.done = $('close_roughcut'); | ||
2275 | 1527 | this.done.onclick = function() { | ||
2276 | 1528 | this.blur(); | ||
2277 | 1529 | UI.hide_roughcut(); | ||
2278 | 1530 | } | ||
2279 | 1531 | |||
2280 | 1532 | this.create_button = $('create_slice'); | ||
2281 | 1533 | this.create_button.onclick = $bind(this.create_slice, this); | ||
2282 | 1534 | |||
2283 | 1535 | this.startvideo = new VideoFrame('start'); | ||
2284 | 1536 | this.frames.appendChild(this.startvideo.element); | ||
2285 | 1537 | |||
2286 | 1538 | this.endvideo = new VideoFrame('end hide'); | ||
2287 | 1539 | this.frames.appendChild(this.endvideo.element); | ||
2288 | 1540 | |||
2289 | 1541 | this.scrubber = $el('div', {'class': 'scrubber'}); | ||
2290 | 1542 | this.element.appendChild(this.scrubber); | ||
2291 | 1543 | |||
2292 | 1544 | this.bar = $el('div', {'class': 'bar hide'}); | ||
2293 | 1545 | this.scrubber.appendChild(this.bar); | ||
2294 | 1546 | |||
2295 | 1547 | this.playhead = $el('div', {'class': 'playhead hide'}); | ||
2296 | 1548 | this.scrubber.appendChild(this.playhead); | ||
2297 | 1549 | |||
2298 | 1550 | this.scrubber.onmouseover = $bind(this.on_mouseover, this); | ||
2299 | 1551 | this.scrubber.onmousedown = $bind(this.on_mousedown, this); | ||
2300 | 1552 | |||
2301 | 1553 | this.startvideo.video.addEventListener('timeupdate', | ||
2302 | 1554 | $bind(this.on_timeupdate, this) | ||
2303 | 1555 | ); | ||
2304 | 1556 | this.startvideo.video.addEventListener('ended', | ||
2305 | 1557 | $bind(this.on_ended, this) | ||
2306 | 1558 | ); | ||
2307 | 1559 | |||
2308 | 1560 | this.startvideo.element.addEventListener('mousewheel', | ||
2309 | 1561 | $bind(this.on_mousewheel_start, this) | ||
2310 | 1562 | ); | ||
2311 | 1563 | this.endvideo.element.addEventListener('mousewheel', | ||
2312 | 1564 | $bind(this.on_mousewheel_end, this) | ||
2313 | 1565 | ); | ||
2314 | 1566 | } | ||
2315 | 1567 | RoughCut.prototype = { | ||
2316 | 1568 | on_ended: function() { | ||
2317 | 1569 | if (! this.playing) { | ||
2318 | 1570 | return; | ||
2319 | 1571 | } | ||
2320 | 1572 | var frame = (this.mode == 'edit' && this.inside) ? this.start : 0; | ||
2321 | 1573 | this.startvideo.seek(frame); | ||
2322 | 1574 | this.startvideo.video.play(); | ||
2323 | 1575 | this.pframe = frame; | ||
2324 | 1576 | }, | ||
2325 | 1577 | |||
2326 | 1578 | on_timeupdate: function() { | ||
2327 | 1579 | if (! this.playing) { | ||
2328 | 1580 | return; | ||
2329 | 1581 | } | ||
2330 | 1582 | if (this.dnd) { | ||
2331 | 1583 | return; | ||
2332 | 1584 | } | ||
2333 | 1585 | var frame = this.startvideo.get_frame(); | ||
2334 | 1586 | if (this.mode == 'edit' && this.inside && frame >= this.stop - 1) { | ||
2335 | 1587 | this.startvideo.seek(this.start, true); | ||
2336 | 1588 | frame = this.start; | ||
2337 | 1589 | } | ||
2338 | 1590 | this.pframe = frame; | ||
2339 | 1591 | }, | ||
2340 | 1592 | |||
2341 | 1593 | hide: function() { | ||
2342 | 1594 | this.active = false; | ||
2343 | 1595 | this.mode = null; | ||
2344 | 1596 | this.pause(); | ||
2345 | 1597 | $hide(this.element); | ||
2346 | 1598 | }, | ||
2347 | 1599 | |||
2348 | 1600 | show: function(id) { | ||
2349 | 1601 | console.log('show ' + id); | ||
2350 | 1602 | if (! this.element.classList.contains('hide')) { | ||
2351 | 1603 | this.x = this.x + 130 + 10 + (this.xf * 3); | ||
2352 | 1604 | if (this.x > document.body.clientWidth - 130) { | ||
2353 | 1605 | this.x = 0; | ||
2354 | 1606 | } | ||
2355 | 1607 | } | ||
2356 | 1608 | else { | ||
2357 | 1609 | this.x = 0; | ||
2358 | 1610 | } | ||
2359 | 1611 | this.y = 0; | ||
2360 | 1612 | this.count = 0; | ||
2361 | 1613 | this.active = true; | ||
2362 | 1614 | this.clip = this.session.get_doc(id); | ||
2363 | 1615 | this.frames = this.clip.duration.frames; | ||
2364 | 1616 | this.startvideo.set_clip(this.clip); | ||
2365 | 1617 | this.endvideo.set_clip(this.clip); | ||
2366 | 1618 | $show(this.element); | ||
2367 | 1619 | }, | ||
2368 | 1620 | |||
2369 | 1621 | reset: function() { | ||
2370 | 1622 | delete this.dnd; | ||
2371 | 1623 | this._start = 0; | ||
2372 | 1624 | this._stop = this.frames; | ||
2373 | 1625 | this.pframe = null; | ||
2374 | 1626 | this.startvideo.pause(); | ||
2375 | 1627 | this.playing = false; | ||
2376 | 1628 | this.scrubber.onmousemove = null; | ||
2377 | 1629 | }, | ||
2378 | 1630 | |||
2379 | 1631 | get_x: function(frame) { | ||
2380 | 1632 | return Math.round(this.scrubber.clientWidth * frame / this.frames); | ||
2381 | 1633 | }, | ||
2382 | 1634 | |||
2383 | 1635 | get_frame: function(x, key_unit) { | ||
2384 | 1636 | var frame = Math.round(this.frames * x / this.scrubber.clientWidth); | ||
2385 | 1637 | if (key_unit) { | ||
2386 | 1638 | return 1 + Math.round(frame / 15) * 15; | ||
2387 | 1639 | } | ||
2388 | 1640 | return frame; | ||
2389 | 1641 | }, | ||
2390 | 1642 | |||
2391 | 1643 | set start(value) { | ||
2392 | 1644 | this._start = Math.max(0, Math.min(value, this._stop - 1)); | ||
2393 | 1645 | this.startvideo.set_index(this._start); | ||
2394 | 1646 | }, | ||
2395 | 1647 | |||
2396 | 1648 | get start() { | ||
2397 | 1649 | return this._start; | ||
2398 | 1650 | }, | ||
2399 | 1651 | |||
2400 | 1652 | set stop(value) { | ||
2401 | 1653 | this._stop = Math.max(this._start + 1, Math.min(value, this.frames)); | ||
2402 | 1654 | this.endvideo.set_index(this._stop - 1); | ||
2403 | 1655 | }, | ||
2404 | 1656 | |||
2405 | 1657 | get stop() { | ||
2406 | 1658 | return this._stop; | ||
2407 | 1659 | }, | ||
2408 | 1660 | |||
2409 | 1661 | get left() { | ||
2410 | 1662 | return this.get_x(this._start); | ||
2411 | 1663 | }, | ||
2412 | 1664 | |||
2413 | 1665 | get right() { | ||
2414 | 1666 | return this.get_x(this._stop); | ||
2415 | 1667 | }, | ||
2416 | 1668 | |||
2417 | 1669 | set pframe(value) { | ||
2418 | 1670 | if (value == null) { | ||
2419 | 1671 | this._pframe = null; | ||
2420 | 1672 | this.playhead.classList.add('hide'); | ||
2421 | 1673 | } | ||
2422 | 1674 | else { | ||
2423 | 1675 | this._pframe = Math.max(0, Math.min(value, this.frames - 1)); | ||
2424 | 1676 | this.playhead.classList.remove('hide'); | ||
2425 | 1677 | this.playhead.style.left = this.get_x(this._pframe) + 'px'; | ||
2426 | 1678 | } | ||
2427 | 1679 | }, | ||
2428 | 1680 | |||
2429 | 1681 | get pframe() { | ||
2430 | 1682 | return this._pframe; | ||
2431 | 1683 | }, | ||
2432 | 1684 | |||
2433 | 1685 | on_mousewheel_start: function(event) { | ||
2434 | 1686 | $halt(event); | ||
2435 | 1687 | var orig = this._start; | ||
2436 | 1688 | this.start = orig + wheel_delta(event); | ||
2437 | 1689 | if (this.start != orig) { | ||
2438 | 1690 | this.save_to_slice(); | ||
2439 | 1691 | this.session.delayed_commit(); | ||
2440 | 1692 | if (this.mode == 'create') { | ||
2441 | 1693 | this.bar.style.left = this.left + 'px'; | ||
2442 | 1694 | } | ||
2443 | 1695 | else { | ||
2444 | 1696 | this.update_bar(); | ||
2445 | 1697 | } | ||
2446 | 1698 | } | ||
2447 | 1699 | }, | ||
2448 | 1700 | |||
2449 | 1701 | on_mousewheel_end: function(event) { | ||
2450 | 1702 | $halt(event); | ||
2451 | 1703 | var orig = this._stop; | ||
2452 | 1704 | this.stop = orig + wheel_delta(event); | ||
2453 | 1705 | if (this.stop != orig) { | ||
2454 | 1706 | this.save_to_slice(); | ||
2455 | 1707 | this.session.delayed_commit(); | ||
2456 | 1708 | this.update_bar(); | ||
2457 | 1709 | } | ||
2458 | 1710 | }, | ||
2459 | 1711 | |||
2460 | 1712 | playpause: function() { | ||
2461 | 1713 | if (this.playing) { | ||
2462 | 1714 | this.pause(); | ||
2463 | 1715 | } | ||
2464 | 1716 | else { | ||
2465 | 1717 | this.play(); | ||
2466 | 1718 | } | ||
2467 | 1719 | }, | ||
2468 | 1720 | |||
2469 | 1721 | play: function() { | ||
2470 | 1722 | this.playing = true; | ||
2471 | 1723 | this.scrubber.onmousemove = null; | ||
2472 | 1724 | if (this._pframe == null) { | ||
2473 | 1725 | this.pframe = this.start; | ||
2474 | 1726 | } | ||
2475 | 1727 | this.startvideo.seek(this.pframe); | ||
2476 | 1728 | this.startvideo.play(); | ||
2477 | 1729 | }, | ||
2478 | 1730 | |||
2479 | 1731 | pause: function() { | ||
2480 | 1732 | this.startvideo.pause(); | ||
2481 | 1733 | this.startvideo.seek(this.start); | ||
2482 | 1734 | this.playing = false; | ||
2483 | 1735 | if (this.mode == 'create') { | ||
2484 | 1736 | this.bind_mousemove(); | ||
2485 | 1737 | } | ||
2486 | 1738 | }, | ||
2487 | 1739 | |||
2488 | 1740 | update_bar: function() { | ||
2489 | 1741 | var left = this.left; | ||
2490 | 1742 | var width = Math.max(2, this.right - left); | ||
2491 | 1743 | this.bar.style.left = left + 'px'; | ||
2492 | 1744 | this.bar.style.width = width + 'px'; | ||
2493 | 1745 | }, | ||
2494 | 1746 | |||
2495 | 1747 | sync_from_slice: function() { | ||
2496 | 1748 | this._start = 0; | ||
2497 | 1749 | this._stop = this.frames; | ||
2498 | 1750 | this.start = this.slice.node.start.frame; | ||
2499 | 1751 | this.stop = this.slice.node.stop.frame; | ||
2500 | 1752 | this.update_bar(); | ||
2501 | 1753 | }, | ||
2502 | 1754 | |||
2503 | 1755 | save_to_slice: function() { | ||
2504 | 1756 | /* | ||
2505 | 1757 | Store start & stop in slice doc, mark doc as dirty. | ||
2506 | 1758 | |||
2507 | 1759 | Note that this *only* marks the slice doc as dirty, does *not* call | ||
2508 | 1760 | session.commit(). This is for cases when you also need to update the | ||
2509 | 1761 | sequence doc, so you can send both in a single CouchDB request. | ||
2510 | 1762 | */ | ||
2511 | 1763 | this.slice.node.start.frame = this.start; | ||
2512 | 1764 | this.slice.node.stop.frame = this.stop; | ||
2513 | 1765 | this.session.save(this.slice); | ||
2514 | 1766 | }, | ||
2515 | 1767 | |||
2516 | 1768 | create_slice: function() { | ||
2517 | 1769 | console.log('create_slice'); | ||
2518 | 1770 | this.create_button.blur(); | ||
2519 | 1771 | this.count += 1; | ||
2520 | 1772 | this.mode = 'create'; | ||
2521 | 1773 | this.endvideo.hide(); | ||
2522 | 1774 | this.reset(); | ||
2523 | 1775 | this.start = 0; | ||
2524 | 1776 | this.bar.style.left = this.left + 'px'; | ||
2525 | 1777 | this.bar.style.width = '1px'; | ||
2526 | 1778 | this.slice = create_slice(this.clip._id, this.frames); | ||
2527 | 1779 | this.bind_mousemove(); | ||
2528 | 1780 | }, | ||
2529 | 1781 | |||
2530 | 1782 | edit_slice: function(slice) { | ||
2531 | 1783 | console.log('edit_slice ' + slice._id); | ||
2532 | 1784 | this.mode = 'edit'; | ||
2533 | 1785 | this.inside = true; | ||
2534 | 1786 | this.slice = slice; | ||
2535 | 1787 | this.endvideo.show(); | ||
2536 | 1788 | this.reset(); | ||
2537 | 1789 | $show(this.bar); | ||
2538 | 1790 | this.sync_from_slice(); | ||
2539 | 1791 | }, | ||
2540 | 1792 | |||
2541 | 1793 | bind_mousemove: function() { | ||
2542 | 1794 | this.scrubber.onmousemove = $bind(this.on_mousemove, this); | ||
2543 | 1795 | }, | ||
2544 | 1796 | |||
2545 | 1797 | on_mouseover: function(event) { | ||
2546 | 1798 | if (this.mode == 'create' && !this.playing && !this.dnd) { | ||
2547 | 1799 | $show(this.bar); | ||
2548 | 1800 | } | ||
2549 | 1801 | }, | ||
2550 | 1802 | |||
2551 | 1803 | on_mousemove: function(event) { | ||
2552 | 1804 | this.start = this.get_frame(event.clientX); | ||
2553 | 1805 | this.bar.style.left = this.left + 'px'; | ||
2554 | 1806 | }, | ||
2555 | 1807 | |||
2556 | 1808 | on_mousedown: function(event) { | ||
2557 | 1809 | this.scrubber.onmousemove = null; | ||
2558 | 1810 | this.dnd = new DragEvent(event); | ||
2559 | 1811 | this.dnd.ondragcancel = $bind(this.on_dragcancel, this); | ||
2560 | 1812 | this.dnd.ondragstart = $bind(this.on_dragstart, this); | ||
2561 | 1813 | |||
2562 | 1814 | if (this.playing) { | ||
2563 | 1815 | this.startvideo.pause(); | ||
2564 | 1816 | return this.scrub_playhead(this.dnd); | ||
2565 | 1817 | } | ||
2566 | 1818 | if (this.mode == 'edit') { | ||
2567 | 1819 | var mid = (this.left + this.right) / 2; | ||
2568 | 1820 | this.point = (event.clientX <= mid) ? 'left' : 'right'; | ||
2569 | 1821 | var frame = this.get_frame(event.clientX); | ||
2570 | 1822 | if (this.point == 'left') { | ||
2571 | 1823 | this.start = frame; | ||
2572 | 1824 | } | ||
2573 | 1825 | else { | ||
2574 | 1826 | this.stop = frame + 1; | ||
2575 | 1827 | } | ||
2576 | 1828 | this.update_bar(); | ||
2577 | 1829 | } | ||
2578 | 1830 | }, | ||
2579 | 1831 | |||
2580 | 1832 | scrub_playhead: function(dnd) { | ||
2581 | 1833 | var frame = this.get_frame(dnd.x); | ||
2582 | 1834 | if (this.start <= frame && frame < this.stop) { | ||
2583 | 1835 | this.inside = true; | ||
2584 | 1836 | } | ||
2585 | 1837 | else { | ||
2586 | 1838 | this.inside = false; | ||
2587 | 1839 | } | ||
2588 | 1840 | this.pframe = frame; | ||
2589 | 1841 | this.startvideo.seek(frame); | ||
2590 | 1842 | }, | ||
2591 | 1843 | |||
2592 | 1844 | on_dragcancel: function(dnd) { | ||
2593 | 1845 | delete this.dnd; | ||
2594 | 1846 | if (this.playing) { | ||
2595 | 1847 | this.startvideo.play(); | ||
2596 | 1848 | return; | ||
2597 | 1849 | } | ||
2598 | 1850 | if (this.mode == 'create') { | ||
2599 | 1851 | this.bindmousemove(); | ||
2600 | 1852 | } | ||
2601 | 1853 | else { | ||
2602 | 1854 | this.save_to_slice(); | ||
2603 | 1855 | this.session.delayed_commit(); | ||
2604 | 1856 | } | ||
2605 | 1857 | }, | ||
2606 | 1858 | |||
2607 | 1859 | on_dragstart: function(dnd) { | ||
2608 | 1860 | this.dnd.ondrag = $bind(this.on_drag, this); | ||
2609 | 1861 | this.dnd.ondrop = $bind(this.on_drop, this); | ||
2610 | 1862 | if (!this.playing && this.mode == 'create') { | ||
2611 | 1863 | this.endvideo.show(); | ||
2612 | 1864 | this.orig_start = this.start; | ||
2613 | 1865 | } | ||
2614 | 1866 | }, | ||
2615 | 1867 | |||
2616 | 1868 | on_drag: function(dnd) { | ||
2617 | 1869 | var frame = this.get_frame(dnd.x); | ||
2618 | 1870 | if (this.playing) { | ||
2619 | 1871 | return this.scrub_playhead(dnd); | ||
2620 | 1872 | } | ||
2621 | 1873 | if (this.mode == 'create') { | ||
2622 | 1874 | if (frame < this.orig_start) { | ||
2623 | 1875 | this.start = frame; | ||
2624 | 1876 | this.stop = this.orig_start + 1; | ||
2625 | 1877 | } | ||
2626 | 1878 | else { | ||
2627 | 1879 | this.start = this.orig_start; | ||
2628 | 1880 | this.stop = frame + 1; | ||
2629 | 1881 | } | ||
2630 | 1882 | } | ||
2631 | 1883 | else { | ||
2632 | 1884 | if (this.point == 'left') { | ||
2633 | 1885 | this.start = frame; | ||
2634 | 1886 | } | ||
2635 | 1887 | else { | ||
2636 | 1888 | this.stop = frame + 1; | ||
2637 | 1889 | } | ||
2638 | 1890 | } | ||
2639 | 1891 | this.update_bar(); | ||
2640 | 1892 | }, | ||
2641 | 1893 | |||
2642 | 1894 | xf: 25, | ||
2643 | 1895 | |||
2644 | 1896 | yf: 50, | ||
2645 | 1897 | |||
2646 | 1898 | on_drop: function(dnd) { | ||
2647 | 1899 | delete this.dnd; | ||
2648 | 1900 | if (this.playing) { | ||
2649 | 1901 | this.startvideo.play(); | ||
2650 | 1902 | return; | ||
2651 | 1903 | } | ||
2652 | 1904 | if (this.mode == 'create') { | ||
2653 | 1905 | this.save_to_slice(); | ||
2654 | 1906 | var x = this.x + (this.count * this.xf); | ||
2655 | 1907 | var y = this.y + (this.count * this.yf); | ||
2656 | 1908 | UI.sequence.doc.doodle.push({id: this.slice._id, x: x, y: y}); | ||
2657 | 1909 | this.session.save(UI.sequence.doc); | ||
2658 | 1910 | this.session.delayed_commit(); | ||
2659 | 1911 | this.edit_slice(this.slice); | ||
2660 | 1912 | } | ||
2661 | 1913 | else { | ||
2662 | 1914 | this.save_to_slice(); | ||
2663 | 1915 | this.session.delayed_commit(); | ||
2664 | 1916 | } | ||
2665 | 1917 | }, | ||
2666 | 1918 | } | ||
2667 | 1919 | |||
2668 | 1920 | |||
2669 | 1921 | function Clips() { | ||
2670 | 1922 | this.selected = null; | ||
2671 | 1923 | this.dropdown = $('dmedia_project'); | ||
2672 | 1924 | this.dropdown.onchange = $bind(this.on_dropdown_change, this); | ||
2673 | 1925 | this.div = $('clips'); | ||
2674 | 1926 | this.container = $('clips_outer'); | ||
2675 | 1927 | this.session = UI.session; | ||
2676 | 1928 | this.doc = this.session.get_doc(UI.project_id); | ||
2677 | 1929 | this.session.subscribe(this.doc._id, this.on_change, this); | ||
2678 | 1930 | this.id = null; | ||
2679 | 1931 | this.db = null; | ||
2680 | 1932 | this.load_projects(); | ||
2681 | 1933 | this.open = $('open_clips'); | ||
2682 | 1934 | this.open.onclick = $bind(this.on_open_click, this); | ||
2683 | 1935 | |||
2684 | 1936 | this.div.onchildselect = $bind(this.on_childselect, this); | ||
2685 | 1937 | } | ||
2686 | 1938 | Clips.prototype = { | ||
2687 | 1939 | on_childselect: function(id) { | ||
2688 | 1940 | console.log('childselect ' + id); | ||
2689 | 1941 | $hscroll($(id)); | ||
2690 | 1942 | if (this.doc.selected_clips[this.id] != id) { | ||
2691 | 1943 | this.doc.selected_clips[this.id] = id; | ||
2692 | 1944 | this.session.save(this.doc, true); | ||
2693 | 1945 | this.session.delayed_commit(); | ||
2694 | 1946 | } | ||
2695 | 1947 | }, | ||
2696 | 1948 | |||
2697 | 1949 | on_change: function(doc) { | ||
2698 | 1950 | console.log('Clips.on_change'); | ||
2699 | 1951 | this.doc = doc; | ||
2700 | 1952 | if (!this.doc.selected_clips) { | ||
2701 | 1953 | this.doc.selected_clips = {}; | ||
2702 | 1954 | } | ||
2703 | 1955 | var id = doc.dmedia_project_id; | ||
2704 | 1956 | this.dropdown.value = id; | ||
2705 | 1957 | if (this.load(id)) { | ||
2706 | 1958 | this.div.innerHTML = null; | ||
2707 | 1959 | this.load_clips(); | ||
2708 | 1960 | } | ||
2709 | 1961 | }, | ||
2710 | 1962 | |||
2711 | 1963 | load: function(id) { | ||
2712 | 1964 | console.log('load ' + id); | ||
2713 | 1965 | if (!id) { | ||
2714 | 1966 | this.id = null; | ||
2715 | 1967 | this.db = null; | ||
2716 | 1968 | return false; | ||
2717 | 1969 | } | ||
2718 | 1970 | if (id == this.id) { | ||
2719 | 1971 | return false; | ||
2720 | 1972 | } | ||
2721 | 1973 | this.id = id; | ||
2722 | 1974 | this.db = dmedia_project_db(id); | ||
2723 | 1975 | return true; | ||
2724 | 1976 | }, | ||
2725 | 1977 | |||
2726 | 1978 | load_projects: function() { | ||
2727 | 1979 | var callback = $bind(this.on_projects, this); | ||
2728 | 1980 | dmedia.view(callback, 'project', 'title'); | ||
2729 | 1981 | }, | ||
2730 | 1982 | |||
2731 | 1983 | on_projects: function(req) { | ||
2732 | 1984 | var rows = req.read().rows; | ||
2733 | 1985 | this.dropdown.innerHTML = null; | ||
2734 | 1986 | this.placeholder = $el('option'); | ||
2735 | 1987 | this.dropdown.appendChild(this.placeholder); | ||
2736 | 1988 | rows.forEach(function(row) { | ||
2737 | 1989 | var option = $el('option', {textContent: row.key, value: row.id}); | ||
2738 | 1990 | this.dropdown.appendChild(option); | ||
2739 | 1991 | }, this); | ||
2740 | 1992 | }, | ||
2741 | 1993 | |||
2742 | 1994 | on_dropdown_change: function(event) { | ||
2743 | 1995 | if (this.placeholder) { | ||
2744 | 1996 | $unparent(this.placeholder); | ||
2745 | 1997 | delete this.placeholder; | ||
2746 | 1998 | } | ||
2747 | 1999 | this.doc.dmedia_project_id = this.dropdown.value; | ||
2748 | 2000 | this.dropdown.blur(); | ||
2749 | 2001 | this.session.save(this.doc); | ||
2750 | 2002 | this.session.delayed_commit(); | ||
2751 | 2003 | }, | ||
2752 | 2004 | |||
2753 | 2005 | load_clips: function() { | ||
2754 | 2006 | var callback = $bind(this.on_clips, this); | ||
2755 | 2007 | this.db.view(callback, 'user', 'video'); | ||
2756 | 2008 | }, | ||
2757 | 2009 | |||
2758 | 2010 | on_clips: function(req) { | ||
2759 | 2011 | var rows = req.read().rows; | ||
2760 | 2012 | this.div.innerHTML = null; | ||
2761 | 2013 | var self = this; | ||
2762 | 2014 | rows.forEach(function(row) { | ||
2763 | 2015 | var id = row.id; | ||
2764 | 2016 | var img = new Image(); | ||
2765 | 2017 | img.id = id; | ||
2766 | 2018 | img.src = this.att_url(id); | ||
2767 | 2019 | img.onmousedown = function(event) { | ||
2768 | 2020 | self.on_mousedown(id, event); | ||
2769 | 2021 | } | ||
2770 | 2022 | img.ondblclick = function(event) { | ||
2771 | 2023 | self.on_dblclick(id, event); | ||
2772 | 2024 | } | ||
2773 | 2025 | this.div.appendChild(img); | ||
2774 | 2026 | }, this); | ||
2775 | 2027 | UI.select(this.doc.selected_clips[this.id]); | ||
2776 | 2028 | }, | ||
2777 | 2029 | |||
2778 | 2030 | on_open_click: function(event) { | ||
2779 | 2031 | if (!this.container.classList.toggle('open')) { | ||
2780 | 2032 | var element = $(UI.selected); | ||
2781 | 2033 | if (element && element.parentNode.id == 'clips') { | ||
2782 | 2034 | UI.select(null); | ||
2783 | 2035 | } | ||
2784 | 2036 | } | ||
2785 | 2037 | }, | ||
2786 | 2038 | |||
2787 | 2039 | on_mousedown: function(id, event) { | ||
2788 | 2040 | UI.select(id); | ||
2789 | 2041 | this.dnd = new DragEvent(event); | ||
2790 | 2042 | this.dnd.id = id; | ||
2791 | 2043 | this.dnd.ondragcancel = $bind(this.on_dragcancel, this); | ||
2792 | 2044 | this.dnd.ondragstart = $bind(this.on_dragstart, this); | ||
2793 | 2045 | }, | ||
2794 | 2046 | |||
2795 | 2047 | on_dragcancel: function(dnd) { | ||
2796 | 2048 | delete this.dnd; | ||
2797 | 2049 | }, | ||
2798 | 2050 | |||
2799 | 2051 | on_dragstart: function(dnd) { | ||
2800 | 2052 | this.dnd.ondrag = $bind(this.on_drag, this); | ||
2801 | 2053 | this.dnd.ondrop = $bind(this.on_drop, this); | ||
2802 | 2054 | }, | ||
2803 | 2055 | |||
2804 | 2056 | on_drag: function(dnd) { | ||
2805 | 2057 | if (dnd.dy > 50) { | ||
2806 | 2058 | console.log('creating ' + dnd.dy); | ||
2807 | 2059 | dnd.ondrag = null; | ||
2808 | 2060 | UI.copy_clip(dnd.id); | ||
2809 | 2061 | var clip = this.session.get_doc(dnd.id); | ||
2810 | 2062 | var doc = create_slice(clip._id, clip.duration.frames); | ||
2811 | 2063 | this.session.save(doc, true); | ||
2812 | 2064 | var slice = new Slice(UI.session, doc); | ||
2813 | 2065 | slice.x = dnd.x - 64; | ||
2814 | 2066 | slice.y = dnd.y - 36; | ||
2815 | 2067 | UI.bucket.appendChild(slice.element); | ||
2816 | 2068 | slice.on_mousedown(dnd.event); | ||
2817 | 2069 | } | ||
2818 | 2070 | }, | ||
2819 | 2071 | |||
2820 | 2072 | on_drop: function(dnd) { | ||
2821 | 2073 | delete this.dnd; | ||
2822 | 2074 | }, | ||
2823 | 2075 | |||
2824 | 2076 | on_dblclick: function(id, event) { | ||
2825 | 2077 | UI.copy_clip(id); | ||
2826 | 2078 | UI.create_slice(id); | ||
2827 | 2079 | }, | ||
2828 | 2080 | |||
2829 | 2081 | att_url: function(doc_or_id, name) { | ||
2830 | 2082 | if (!this.db) { | ||
2831 | 2083 | return null; | ||
2832 | 2084 | } | ||
2833 | 2085 | return this.db.att_url(doc_or_id, name); | ||
2834 | 2086 | }, | ||
2835 | 2087 | |||
2836 | 2088 | att_css_url: function(doc_or_id, name) { | ||
2837 | 2089 | if (!this.db) { | ||
2838 | 2090 | return null; | ||
2839 | 2091 | } | ||
2840 | 2092 | return this.db.att_css_url(doc_or_id, name); | ||
2841 | 2093 | }, | ||
2842 | 2094 | } | ||
2843 | 2095 | |||
2844 | 2096 | |||
2845 | 2097 | var LoveOrb = function() { | ||
2846 | 2098 | this.logo = $el('img', {'id': 'logo', 'src': 'novacut.png'}); | ||
2847 | 2099 | document.body.appendChild(this.logo); | ||
2848 | 2100 | this.capture = $('flyout_capture'); | ||
2849 | 2101 | this.flyout = $('flyout'); | ||
2850 | 2102 | this.logo.onmousedown = $bind(this.on_mousedown, this); | ||
2851 | 2103 | this.logo.onclick = $bind(this.on_click, this); | ||
2852 | 2104 | this.capture.onclick = $bind(this.on_capture_click, this); | ||
2853 | 2105 | this.flyout.onclick = $bind(this.on_flyout_click, this); | ||
2854 | 2106 | } | ||
2855 | 2107 | LoveOrb.prototype = { | ||
2856 | 2108 | get active() { | ||
2857 | 2109 | return !this.capture.classList.contains('hide'); | ||
2858 | 2110 | }, | ||
2859 | 2111 | |||
2860 | 2112 | toggle: function() { | ||
2861 | 2113 | if(this.capture.classList.toggle('hide')) { | ||
2862 | 2114 | this.logo.classList.remove('open'); | ||
2863 | 2115 | } | ||
2864 | 2116 | else { | ||
2865 | 2117 | this.logo.classList.add('open'); | ||
2866 | 2118 | } | ||
2867 | 2119 | }, | ||
2868 | 2120 | |||
2869 | 2121 | on_mousedown: function(event) { | ||
2870 | 2122 | // Needed to prevent annoying drag behavior | ||
2871 | 2123 | $halt(event); | ||
2872 | 2124 | }, | ||
2873 | 2125 | |||
2874 | 2126 | on_click: function(event) { | ||
2875 | 2127 | $halt(event); | ||
2876 | 2128 | this.toggle(); | ||
2877 | 2129 | }, | ||
2878 | 2130 | |||
2879 | 2131 | on_capture_click: function(event) { | ||
2880 | 2132 | console.log('capture click'); | ||
2881 | 2133 | $halt(event); | ||
2882 | 2134 | this.toggle(); | ||
2883 | 2135 | }, | ||
2884 | 2136 | |||
2885 | 2137 | on_flyout_click: function(event) { | ||
2886 | 2138 | console.log('flyout click'); | ||
2887 | 2139 | event.stopPropagation(); | ||
2888 | 2140 | }, | ||
2889 | 2141 | } | ||
2890 | 2142 | |||
2891 | 2143 | function closeAll(){ | ||
2892 | 2144 | for(var a in UI.conts)UI.conts[a].close(); | ||
2893 | 2145 | } | ||
2894 | 2146 | |||
2895 | 2147 | |||
2896 | 2148 | function unselectAll(){ | ||
2897 | 2149 | for(var a in UI.selected){ | ||
2898 | 2150 | var b = UI.selected[a]; | ||
2899 | 2151 | $unselect(b); | ||
2900 | 2152 | } | ||
2901 | 2153 | UI.selected = Array(); | ||
2902 | 2154 | } | ||
2903 | 2155 | |||
2904 | 2156 | var selector = { | ||
2905 | 2157 | init: function(){ | ||
2906 | 2158 | selector.down = false; | ||
2907 | 2159 | selector.el = ""; | ||
2908 | 2160 | selector.xs = 1; | ||
2909 | 2161 | selector.ys = 1; | ||
2910 | 2162 | }, | ||
2911 | 2163 | on_mouse_down: function(ev){ | ||
2912 | 2164 | closeAll(); | ||
2913 | 2165 | unselectAll(); | ||
2914 | 2166 | selector.down = true; | ||
2915 | 2167 | selector.el = $el('div', {'class': 'selector','id': 'sel'}); | ||
2916 | 2168 | selector.stx = ev.x; | ||
2917 | 2169 | selector.sty = ev.y; | ||
2918 | 2170 | selector.el.style.left = ev.x +'px'; | ||
2919 | 2171 | selector.el.style.top = ev.y +'px'; | ||
2920 | 2172 | UI.bucket.appendChild(selector.el); | ||
2921 | 2173 | }, | ||
2922 | 2174 | on_mouse_up: function(ev){ | ||
2923 | 2175 | console.log("mouse up"); | ||
2924 | 2176 | if(selector.down && selector.el && selector.el.parentNode){ | ||
2925 | 2177 | selector.el.parentNode.removeChild(selector.el); | ||
2926 | 2178 | if(document.getElementById('sel'))document.getElementById('sel').parentNode.removeChild(document.getElementById('sel')); | ||
2927 | 2179 | selector.down = false; | ||
2928 | 2180 | var stx = selector.stx; | ||
2929 | 2181 | var endx = selector.stx+selector.xs*parseInt(selector.el.style.width); | ||
2930 | 2182 | var sty = selector.sty; | ||
2931 | 2183 | var endy = selector.sty+selector.ys*parseInt(selector.el.style.height); | ||
2932 | 2184 | if(stx > endx){ | ||
2933 | 2185 | var tmp = stx; | ||
2934 | 2186 | stx = endx; | ||
2935 | 2187 | endx = tmp; | ||
2936 | 2188 | } | ||
2937 | 2189 | if(sty > endy){ | ||
2938 | 2190 | var tmp = sty; | ||
2939 | 2191 | sty = endy; | ||
2940 | 2192 | endy = tmp; | ||
2941 | 2193 | } | ||
2942 | 2194 | for(var a in UI.slices){ | ||
2943 | 2195 | var b = UI.slices[a]; | ||
2944 | 2196 | if(b.x > stx && b.x < endx && b.y > sty && b.y < endy){ | ||
2945 | 2197 | UI.selected.push(b.id); | ||
2946 | 2198 | $select(b.id); | ||
2947 | 2199 | } | ||
2948 | 2200 | } | ||
2949 | 2201 | for(var a in UI.conts){ | ||
2950 | 2202 | var b = UI.conts[a]; | ||
2951 | 2203 | if(b.x > stx && b.x < endx && b.y > sty && b.y < endy){ | ||
2952 | 2204 | UI.selected.push(b.id); | ||
2953 | 2205 | $select(b.id); | ||
2954 | 2206 | } | ||
2955 | 2207 | } | ||
2956 | 2208 | } | ||
2957 | 2209 | }, | ||
2958 | 2210 | on_mouse_move: function(ev){ | ||
2959 | 2211 | if(selector.down){ | ||
2960 | 2212 | var w = ev.x - selector.stx; | ||
2961 | 2213 | var h = ev.y - selector.sty; | ||
2962 | 2214 | selector.el.style.width = ev.x - selector.stx +'px'; | ||
2963 | 2215 | selector.el.style.height = ev.y - selector.sty +'px'; | ||
2964 | 2216 | selector.xs = 1; | ||
2965 | 2217 | selector.ys = 1; | ||
2966 | 2218 | if(w < 0){ | ||
2967 | 2219 | selector.el.style.width = -w + 'px'; | ||
2968 | 2220 | selector.el.style.left = ev.x + 'px'; | ||
2969 | 2221 | selector.xs = -1; | ||
2970 | 2222 | } | ||
2971 | 2223 | if(h < 0){ | ||
2972 | 2224 | selector.el.style.height = -h + 'px'; | ||
2973 | 2225 | selector.el.style.top = ev.y + 'px'; | ||
2974 | 2226 | selector.ys = -1; | ||
2975 | 2227 | } | ||
2976 | 2228 | } | ||
2977 | 2229 | } | ||
2978 | 2230 | |||
2979 | 2231 | } | ||
2980 | 2232 | |||
2981 | 2233 | function compare(a,b){ | ||
2982 | 2234 | return a.x-b.x; | ||
2983 | 2235 | } | ||
2984 | 2236 | |||
2985 | 2237 | function generateAnimation(id,x,y,ex){//generate the animation | ||
2986 | 2238 | var keyframeprefix = "-webkit-"; | ||
2987 | 2239 | var keyframes = '@' + keyframeprefix + 'keyframes '+id+' { '+'0% {' + keyframeprefix + 'transform:scale(1)}'+'50% {' + keyframeprefix + 'transform:translatex('+x+'px) translatey('+y+'px)}'+'100% {' + keyframeprefix + 'transform:translatex('+ex+'px) translatey('+y+'px)}'+'}'; | ||
2988 | 2240 | keyframes += '#'+id+'{-webkit-animation-duration: 0.5s;-webkit-animation-iteration-count: 1;-webkit-animation-timing-function:linear;}'; | ||
2989 | 2241 | var s = document.createElement( 'style' ); | ||
2990 | 2242 | s.innerHTML = keyframes; | ||
2991 | 2243 | document.getElementsByTagName( 'head' )[ 0 ].appendChild( s ); | ||
2992 | 2244 | } | ||
2993 | 2245 | |||
2994 | 2246 | |||
2995 | 2247 | var UI = { | ||
2996 | 2248 | init: function() { | ||
2997 | 2249 | Hub.connect('edit_hashed', UI.on_edit_hashed); | ||
2998 | 2250 | Hub.connect('job_hashed', UI.on_job_hashed); | ||
2999 | 2251 | Hub.connect('job_rendered', UI.on_job_rendered); | ||
3000 | 2252 | |||
3001 | 2253 | // Figure out what project we're in: | ||
3002 | 2254 | var parts = parse_hash(); | ||
3003 | 2255 | UI.project_id = parts[0]; | ||
3004 | 2256 | UI.db = novacut_project_db(UI.project_id); | ||
3005 | 2257 | |||
3006 | 2258 | // Bit of UI setup | ||
3007 | 2259 | window.addEventListener('keyup', UI.on_keyup); | ||
3008 | 2260 | UI.bucket = $('bucket'); | ||
3009 | 2261 | UI.orb = new LoveOrb(); | ||
3010 | 2262 | document.getElementById('shortcuts').style.marginTop = window.innerHeight/2-200+"px"; | ||
3011 | 2263 | document.getElementById('shortcuts').style.marginLeft = window.innerWidth/2-255+"px"; | ||
3012 | 2264 | |||
3013 | 2265 | //selector | ||
3014 | 2266 | UI.selected = Array(); | ||
3015 | 2267 | UI.bucket.addEventListener('mousedown', selector.on_mouse_down, false); | ||
3016 | 2268 | UI.bucket.addEventListener('mousemove', selector.on_mouse_move, false); | ||
3017 | 2269 | document.addEventListener('mouseup', selector.on_mouse_up, false); | ||
3018 | 2270 | |||
3019 | 2271 | // Create and start the CouchDB session | ||
3020 | 2272 | UI.session = new couch.Session(UI.db, UI.on_new_doc); | ||
3021 | 2273 | UI.session.start(); | ||
3022 | 2274 | |||
3023 | 2275 | UI.dragging = false; | ||
3024 | 2276 | UI.slices = Array(); | ||
3025 | 2277 | UI.conts = Array(); | ||
3026 | 2278 | document.body.onclick = $bind(closeAll); | ||
3027 | 2279 | }, | ||
3028 | 2280 | |||
3029 | 2281 | animated: null, | ||
3030 | 2282 | |||
3031 | 2283 | animate: function(element) { | ||
3032 | 2284 | if (UI.animated) { | ||
3033 | 2285 | UI.animated.classList.remove('animated'); | ||
3034 | 2286 | } | ||
3035 | 2287 | UI.animated = $(element); | ||
3036 | 2288 | if (UI.animated) { | ||
3037 | 2289 | UI.animated.classList.add('animated'); | ||
3038 | 2290 | } | ||
3039 | 2291 | }, | ||
3040 | 2292 | |||
3041 | 2293 | copy_clip: function(id) { | ||
3042 | 2294 | try { | ||
3043 | 2295 | UI.session.get_doc(id); | ||
3044 | 2296 | } | ||
3045 | 2297 | catch (e) { | ||
3046 | 2298 | console.log('copying ' + id); | ||
3047 | 2299 | var doc = UI.clips.db.get_sync(id, {attachments: true}); | ||
3048 | 2300 | delete doc._rev; | ||
3049 | 2301 | UI.session.save(doc, true); | ||
3050 | 2302 | } | ||
3051 | 2303 | }, | ||
3052 | 2304 | |||
3053 | 2305 | select: function(id) { | ||
3054 | 2306 | unselectAll(); | ||
3055 | 2307 | var element = $select(id); | ||
3056 | 2308 | if (element) { | ||
3057 | 2309 | UI.selected.push(id); | ||
3058 | 2310 | if (element.parentNode && element.parentNode.onchildselect) { | ||
3059 | 2311 | element.parentNode.onchildselect(id); | ||
3060 | 2312 | } | ||
3061 | 2313 | } | ||
3062 | 2314 | else { | ||
3063 | 2315 | UI.selected = Array(); | ||
3064 | 2316 | } | ||
3065 | 2317 | if (UI.sequence) { | ||
3066 | 2318 | var doc = UI.sequence.doc; | ||
3067 | 2319 | if (doc.selected != UI.selected) { | ||
3068 | 2320 | doc.selected = UI.selected; | ||
3069 | 2321 | UI.session.save(doc, true); // No local emit | ||
3070 | 2322 | UI.session.delayed_commit(); | ||
3071 | 2323 | } | ||
3072 | 2324 | } | ||
3073 | 2325 | }, | ||
3074 | 2326 | |||
3075 | 2327 | delete_selected: function() { | ||
3076 | 2328 | for(var a in UI.selected){ | ||
3077 | 2329 | var id = UI.selected[a]; | ||
3078 | 2330 | var element = $(UI.selected[a]); | ||
3079 | 2331 | if (element) { | ||
3080 | 2332 | if (element.parentNode && element.parentNode.id == 'clips') { | ||
3081 | 2333 | console.log('no delete in clips browser'); | ||
3082 | 2334 | return; | ||
3083 | 2335 | } | ||
3084 | 2336 | try { | ||
3085 | 2337 | var doc = UI.session.get_doc(element.id); | ||
3086 | 2338 | UI.previous(); | ||
3087 | 2339 | doc._deleted = true; | ||
3088 | 2340 | UI.session.save(doc); | ||
3089 | 2341 | if(doc.node.type == 'cont')for(var a in UI.conts){ | ||
3090 | 2342 | if(UI.conts[a].id == id)UI.conts.splice(a,1); | ||
3091 | 2343 | } | ||
3092 | 2344 | if(doc.node.type == 'slice')for(var a in UI.slices){ | ||
3093 | 2345 | if(UI.slices[a].id == id)UI.slices.splice(a,1); | ||
3094 | 2346 | } | ||
3095 | 2347 | } | ||
3096 | 2348 | catch (e) { | ||
3097 | 2349 | return; | ||
3098 | 2350 | } | ||
3099 | 2351 | } | ||
3100 | 2352 | } | ||
3101 | 2353 | }, | ||
3102 | 2354 | |||
3103 | 2355 | group_selected: function(){ | ||
3104 | 2356 | var ndoc = create_cont(); | ||
3105 | 2357 | var list = Array(); | ||
3106 | 2358 | if(UI.selected.length < 2)return; | ||
3107 | 2359 | for(var a in UI.selected){//get all the slices | ||
3108 | 2360 | var doc = UI.session.get_doc(UI.selected[a]); | ||
3109 | 2361 | if(doc.node.type == 'slice'){ | ||
3110 | 2362 | for(var b in UI.slices)if(UI.slices[b].id == UI.selected[a]){ | ||
3111 | 2363 | list.push(UI.slices[b]); | ||
3112 | 2364 | UI.slices.splice(b,1); | ||
3113 | 2365 | } | ||
3114 | 2366 | //UI.bucket.removeChild(document.getElementById(UI.selected[a])) | ||
3115 | 2367 | //ndoc.node.src.push(UI.selected[a]); | ||
3116 | 2368 | } | ||
3117 | 2369 | } | ||
3118 | 2370 | if(list.length < 2)return; | ||
3119 | 2371 | list.sort(compare);//sort for x position | ||
3120 | 2372 | var y = 0; | ||
3121 | 2373 | for(var a in list){//add the slices in the doc and compute the average y | ||
3122 | 2374 | ndoc.node.src.push(list[a].id); | ||
3123 | 2375 | y += list[a].y; | ||
3124 | 2376 | } | ||
3125 | 2377 | y /= list.length; | ||
3126 | 2378 | UI.session.save(ndoc); | ||
3127 | 2379 | var ncont = new Cont(UI.session,ndoc); | ||
3128 | 2380 | ncont.x = list[0].x; | ||
3129 | 2381 | ncont.y = y; | ||
3130 | 2382 | for(var a in list){//animate to form a line | ||
3131 | 2383 | generateAnimation(list[a].id,list[0].x+(a*130)-list[a].x,y-list[a].y,list[0].x-list[a].x); | ||
3132 | 2384 | list[a].element.style.webkitAnimationName = list[a].id; | ||
3133 | 2385 | console.log('animate'); | ||
3134 | 2386 | list[a].element.addEventListener('webkitAnimationEnd',function(ev){ | ||
3135 | 2387 | //console.log('end'); | ||
3136 | 2388 | /*this.style.webkitAnimationName = ""; | ||
3137 | 2389 | this.style.top = "0px"; | ||
3138 | 2390 | this.style.left = "0px"; | ||
3139 | 2391 | $unparent(this); | ||
3140 | 2392 | ncont.list.appendChild(this); | ||
3141 | 2393 | ncont.close();*/ | ||
3142 | 2394 | UI.bucket.removeChild(this); | ||
3143 | 2395 | UI.sequence.do_reorder(); | ||
3144 | 2396 | |||
3145 | 2397 | }); | ||
3146 | 2398 | } | ||
3147 | 2399 | //setTimeout(UI.sequence.do_reorder(),530); | ||
3148 | 2400 | //setTimeout(function(){for(var a in list)UI.bucket.removeChild(document.getElementById(list[a].id));},530,list); | ||
3149 | 2401 | UI.bucket.appendChild(ncont.element); | ||
3150 | 2402 | }, | ||
3151 | 2403 | |||
3152 | 2404 | duplicate_selected: function() { | ||
3153 | 2405 | for(var a in UI.selected){ | ||
3154 | 2406 | var element = $(UI.selected[a]); | ||
3155 | 2407 | var doc = UI.session.get_doc(element.id); | ||
3156 | 2408 | if(doc.node.type == 'slice'){ | ||
3157 | 2409 | var ndoc = create_slice(doc.node.src,doc.node.stop.frame); | ||
3158 | 2410 | ndoc.node.start.frame = doc.node.start.frame; | ||
3159 | 2411 | UI.session.save(ndoc); | ||
3160 | 2412 | var slice = new Slice(UI.session, ndoc); | ||
3161 | 2413 | } | ||
3162 | 2414 | if(doc.node.type == 'cont'){ | ||
3163 | 2415 | var ndoc = create_cont(); | ||
3164 | 2416 | ndoc.node.src = doc.node.src; | ||
3165 | 2417 | UI.session.save(ndoc); | ||
3166 | 2418 | var slice = new Cont(UI.session, ndoc); | ||
3167 | 2419 | } | ||
3168 | 2420 | slice.x = parseInt(element.style.left)-30; | ||
3169 | 2421 | slice.y = parseInt(element.style.top)-30; | ||
3170 | 2422 | UI.bucket.appendChild(slice.element); | ||
3171 | 2423 | } | ||
3172 | 2424 | UI.sequence.do_reorder(); | ||
3173 | 2425 | }, | ||
3174 | 2426 | |||
3175 | 2427 | first: function() { | ||
3176 | 2428 | var element = $(UI.selected); | ||
3177 | 2429 | if (element && element.parentNode) { | ||
3178 | 2430 | UI.select(element.parentNode.children[0].id); | ||
3179 | 2431 | } | ||
3180 | 2432 | }, | ||
3181 | 2433 | |||
3182 | 2434 | previous: function() { | ||
3183 | 2435 | var element = $(UI.selected); | ||
3184 | 2436 | if (element && element.previousSibling) { | ||
3185 | 2437 | UI.select(element.previousSibling.id); | ||
3186 | 2438 | } | ||
3187 | 2439 | }, | ||
3188 | 2440 | |||
3189 | 2441 | next: function() { | ||
3190 | 2442 | var element = $(UI.selected); | ||
3191 | 2443 | if (element && element.nextSibling) { | ||
3192 | 2444 | UI.select(element.nextSibling.id); | ||
3193 | 2445 | } | ||
3194 | 2446 | }, | ||
3195 | 2447 | |||
3196 | 2448 | last: function() { | ||
3197 | 2449 | var element = $(UI.selected); | ||
3198 | 2450 | if (element && element.parentNode) { | ||
3199 | 2451 | var i = element.parentNode.children.length - 1; | ||
3200 | 2452 | UI.select(element.parentNode.children[i].id); | ||
3201 | 2453 | } | ||
3202 | 2454 | }, | ||
3203 | 2455 | |||
3204 | 2456 | |||
3205 | 2457 | get_slice: function(_id) { | ||
3206 | 2458 | var element = $unparent(_id); | ||
3207 | 2459 | if (element) { | ||
3208 | 2460 | console.log(_id); | ||
3209 | 2461 | return element; | ||
3210 | 2462 | } | ||
3211 | 2463 | try { | ||
3212 | 2464 | var doc = UI.session.get_doc(_id); | ||
3213 | 2465 | } | ||
3214 | 2466 | catch (e) { | ||
3215 | 2467 | return null; | ||
3216 | 2468 | } | ||
3217 | 2469 | console.log(_id); | ||
3218 | 2470 | if(doc.node.type == 'slice'){ | ||
3219 | 2471 | var slice = new Slice(UI.session, doc); | ||
3220 | 2472 | return slice.element; | ||
3221 | 2473 | } | ||
3222 | 2474 | if(doc.node.type == 'cont'){ | ||
3223 | 2475 | var slice = new Cont(UI.session, doc); | ||
3224 | 2476 | return slice.element; | ||
3225 | 2477 | } | ||
3226 | 2478 | }, | ||
3227 | 2479 | |||
3228 | 2480 | on_new_doc: function(doc) { | ||
3229 | 2481 | if (doc._id == UI.project_id) { | ||
3230 | 2482 | UI.doc = doc; | ||
3231 | 2483 | |||
3232 | 2484 | // FIXME: create default sequence if needed | ||
3233 | 2485 | if (!UI.doc.root_id) { | ||
3234 | 2486 | console.log('creating default sequence'); | ||
3235 | 2487 | var seq = create_sequence(); | ||
3236 | 2488 | UI.doc.root_id = seq._id; | ||
3237 | 2489 | UI.session.save(UI.doc, true); | ||
3238 | 2490 | UI.session.save(seq, true); | ||
3239 | 2491 | UI.session.delayed_commit(); | ||
3240 | 2492 | } | ||
3241 | 2493 | |||
3242 | 2494 | UI.sequence = new Sequence(UI.session, UI.session.get_doc(UI.doc.root_id)); | ||
3243 | 2495 | UI.clips = new Clips(dmedia); | ||
3244 | 2496 | UI.player= new SequencePlayer(UI.session, UI.sequence.doc); | ||
3245 | 2497 | //closeAll(); | ||
3246 | 2498 | |||
3247 | 2499 | } | ||
3248 | 2500 | }, | ||
3249 | 2501 | |||
3250 | 2502 | _roughcut: null, | ||
3251 | 2503 | |||
3252 | 2504 | get roughcut() { | ||
3253 | 2505 | if (UI._roughcut == null) { | ||
3254 | 2506 | UI._roughcut = new RoughCut(UI.session); | ||
3255 | 2507 | } | ||
3256 | 2508 | return UI._roughcut; | ||
3257 | 2509 | }, | ||
3258 | 2510 | |||
3259 | 2511 | create_slice: function(id) { | ||
3260 | 2512 | UI.roughcut.show(id); | ||
3261 | 2513 | UI.roughcut.create_slice(); | ||
3262 | 2514 | }, | ||
3263 | 2515 | |||
3264 | 2516 | edit_slice: function(doc) { | ||
3265 | 2517 | UI.roughcut.show(doc.node.src); | ||
3266 | 2518 | UI.roughcut.edit_slice(doc); | ||
3267 | 2519 | }, | ||
3268 | 2520 | |||
3269 | 2521 | hide_roughcut: function() { | ||
3270 | 2522 | UI.roughcut.hide(); | ||
3271 | 2523 | }, | ||
3272 | 2524 | |||
3273 | 2525 | // Key bindings | ||
3274 | 2526 | actions: { | ||
3275 | 2527 | // Left arrow | ||
3276 | 2528 | 'Left': function(event) { | ||
3277 | 2529 | if (event.shiftKey) { | ||
3278 | 2530 | UI.first(); | ||
3279 | 2531 | } | ||
3280 | 2532 | else { | ||
3281 | 2533 | UI.previous(); | ||
3282 | 2534 | } | ||
3283 | 2535 | if (UI.player.active) { | ||
3284 | 2536 | UI.player.hold_and_resume(); | ||
3285 | 2537 | } | ||
3286 | 2538 | }, | ||
3287 | 2539 | |||
3288 | 2540 | // Right arrow | ||
3289 | 2541 | 'Right': function(event) { | ||
3290 | 2542 | if (event.shiftKey) { | ||
3291 | 2543 | UI.last(); | ||
3292 | 2544 | } | ||
3293 | 2545 | else { | ||
3294 | 2546 | UI.next(); | ||
3295 | 2547 | } | ||
3296 | 2548 | if (UI.player.active) { | ||
3297 | 2549 | UI.player.hold_and_resume(); | ||
3298 | 2550 | } | ||
3299 | 2551 | }, | ||
3300 | 2552 | //G | ||
3301 | 2553 | 'U+0047': function(event){ | ||
3302 | 2554 | UI.group_selected(); | ||
3303 | 2555 | }, | ||
3304 | 2556 | //D | ||
3305 | 2557 | 'U+0044': function(event) { | ||
3306 | 2558 | UI.duplicate_selected(); | ||
3307 | 2559 | }, | ||
3308 | 2560 | |||
3309 | 2561 | // The David Fulde key | ||
3310 | 2562 | // aka Backspace aka Big Delete on a mac keyboard | ||
3311 | 2563 | 'U+0008': function(event) { | ||
3312 | 2564 | UI.delete_selected(); | ||
3313 | 2565 | }, | ||
3314 | 2566 | |||
3315 | 2567 | // Delete | ||
3316 | 2568 | 'U+007F': function(event) { | ||
3317 | 2569 | UI.delete_selected(); | ||
3318 | 2570 | }, | ||
3319 | 2571 | |||
3320 | 2572 | // SpaceBar | ||
3321 | 2573 | 'U+0020': function(event) { | ||
3322 | 2574 | if (UI.roughcut.active) { | ||
3323 | 2575 | UI.roughcut.playpause(); | ||
3324 | 2576 | } | ||
3325 | 2577 | else { | ||
3326 | 2578 | if (UI.player.active) { | ||
3327 | 2579 | UI.player.playpause(); | ||
3328 | 2580 | } | ||
3329 | 2581 | else { | ||
3330 | 2582 | UI.player.show(); | ||
3331 | 2583 | } | ||
3332 | 2584 | } | ||
3333 | 2585 | }, | ||
3334 | 2586 | |||
3335 | 2587 | // Escape | ||
3336 | 2588 | 'U+001B': function(event) { | ||
3337 | 2589 | if (UI.player.active) { | ||
3338 | 2590 | UI.player.hide(); | ||
3339 | 2591 | } | ||
3340 | 2592 | }, | ||
3341 | 2593 | }, | ||
3342 | 2594 | |||
3343 | 2595 | on_keyup: function(event) { | ||
3344 | 2596 | console.log('keyup ' + event.keyIdentifier); | ||
3345 | 2597 | if (document.activeElement != document.body) { | ||
3346 | 2598 | console.log('document body not focused'); | ||
3347 | 2599 | return; | ||
3348 | 2600 | } | ||
3349 | 2601 | if (UI.orb.active) { | ||
3350 | 2602 | if (event.keyIdentifier == 'U+001B') { | ||
3351 | 2603 | UI.orb.toggle(); | ||
3352 | 2604 | } | ||
3353 | 2605 | return; | ||
3354 | 2606 | } | ||
3355 | 2607 | var action = UI.actions[event.keyIdentifier]; | ||
3356 | 2608 | if (action) { | ||
3357 | 2609 | $halt(event); | ||
3358 | 2610 | action(event); | ||
3359 | 2611 | } | ||
3360 | 2612 | }, | ||
3361 | 2613 | |||
3362 | 2614 | render: function() { | ||
3363 | 2615 | $("render-btn").disabled = true; | ||
3364 | 2616 | $("render-btn").blur(); | ||
3365 | 2617 | UI.orb.toggle(); | ||
3366 | 2618 | console.log('render'); | ||
3367 | 2619 | }, | ||
3368 | 2620 | |||
3369 | 2621 | on_edit_hashed: function(project_id, node_id, intrinsic_id) { | ||
3370 | 2622 | console.log(['edit_hashed', project_id, node_id, intrinsic_id].join(' ')); | ||
3371 | 2623 | // null for default settings_id: | ||
3372 | 2624 | Hub.send('hash_job', intrinsic_id, null); | ||
3373 | 2625 | }, | ||
3374 | 2626 | |||
3375 | 2627 | on_job_hashed: function(intrinsic_id, settings_id, job_id) { | ||
3376 | 2628 | console.log(['job_hashed', intrinsic_id, settings_id, job_id].join(' ')); | ||
3377 | 2629 | Hub.send('render_job', job_id); | ||
3378 | 2630 | }, | ||
3379 | 2631 | |||
3380 | 2632 | on_job_rendered: function(job_id, file_id, link) { | ||
3381 | 2633 | console.log(['job_rendered', job_id, file_id, link].join(' ')); | ||
3382 | 2634 | //UI.player.src = 'dmedia:' + file_id; | ||
3383 | 2635 | //UI.player.play(); | ||
3384 | 2636 | $("render-btn").disabled = false; | ||
3385 | 2637 | }, | ||
3386 | 2638 | } | ||
3387 | 2639 | |||
3388 | 2640 | function showShort(event){ | ||
3389 | 2641 | console.log('show'); | ||
3390 | 2642 | UI.orb.toggle(); | ||
3391 | 2643 | document.getElementById("shortcuts").style.display = "block"; | ||
3392 | 2644 | event.stopPropagation(); | ||
3393 | 2645 | document.body.onclick = $bind(hideShort); | ||
3394 | 2646 | } | ||
3395 | 2647 | |||
3396 | 2648 | function hideShort(event){ | ||
3397 | 2649 | console.log('hide'); | ||
3398 | 2650 | document.getElementById("shortcuts").style.display = "none"; | ||
3399 | 2651 | event.stopPropagation(); | ||
3400 | 2652 | } | ||
3401 | 2653 | |||
3402 | 2654 | window.addEventListener('load', UI.init); | ||
3403 | 2655 | |||
3404 | 2656 | |||
3405 | 0 | 2657 | ||
3406 | === added file 'ui/novacut2.js' | |||
3407 | --- ui/novacut2.js 1970-01-01 00:00:00 +0000 | |||
3408 | +++ ui/novacut2.js 2012-08-14 17:10:21 +0000 | |||
3409 | @@ -0,0 +1,416 @@ | |||
3410 | 1 | "use strict"; | ||
3411 | 2 | |||
3412 | 3 | var novacut = new couch.Database('novacut-0'); | ||
3413 | 4 | var dmedia = new couch.Database('dmedia-0'); | ||
3414 | 5 | |||
3415 | 6 | function parse_hash() { | ||
3416 | 7 | return window.location.hash.slice(1).split('/'); | ||
3417 | 8 | } | ||
3418 | 9 | |||
3419 | 10 | function set_title(id, value) { | ||
3420 | 11 | var el = $(id); | ||
3421 | 12 | if (value) { | ||
3422 | 13 | el.textContent = value; | ||
3423 | 14 | } | ||
3424 | 15 | else { | ||
3425 | 16 | el.textContent = ''; | ||
3426 | 17 | el.appendChild($el('em', {textContent: 'Untitled'})); | ||
3427 | 18 | } | ||
3428 | 19 | return el; | ||
3429 | 20 | } | ||
3430 | 21 | |||
3431 | 22 | |||
3432 | 23 | function project_db(base, ver, project_id) { | ||
3433 | 24 | var name = [base, ver, project_id.toLowerCase()].join('-'); | ||
3434 | 25 | return new couch.Database(name); | ||
3435 | 26 | } | ||
3436 | 27 | |||
3437 | 28 | |||
3438 | 29 | function novacut_project_db(project_id) { | ||
3439 | 30 | return project_db('novacut', 0, project_id); | ||
3440 | 31 | } | ||
3441 | 32 | |||
3442 | 33 | |||
3443 | 34 | function dmedia_project_db(project_id) { | ||
3444 | 35 | return project_db('dmedia', 0, project_id); | ||
3445 | 36 | } | ||
3446 | 37 | |||
3447 | 38 | |||
3448 | 39 | function frame_to_seconds(frame, framerate) { | ||
3449 | 40 | return frame * framerate.denom / framerate.num; | ||
3450 | 41 | } | ||
3451 | 42 | |||
3452 | 43 | |||
3453 | 44 | function seconds_to_frame(seconds, framerate) { | ||
3454 | 45 | return Math.round(seconds * framerate.num / framerate.denom); | ||
3455 | 46 | } | ||
3456 | 47 | |||
3457 | 48 | |||
3458 | 49 | |||
3459 | 50 | function create_node(node) { | ||
3460 | 51 | return { | ||
3461 | 52 | '_id': couch.random_id(), | ||
3462 | 53 | 'ver': 0, | ||
3463 | 54 | 'type': 'novacut/node', | ||
3464 | 55 | 'time': couch.time(), | ||
3465 | 56 | 'node': node, | ||
3466 | 57 | } | ||
3467 | 58 | } | ||
3468 | 59 | |||
3469 | 60 | |||
3470 | 61 | function create_slice(src, frame_count) { | ||
3471 | 62 | var node = { | ||
3472 | 63 | 'type': 'slice', | ||
3473 | 64 | 'src': src, | ||
3474 | 65 | 'start': {'frame': 0}, | ||
3475 | 66 | 'stop': {'frame': frame_count}, | ||
3476 | 67 | 'stream': 'both', | ||
3477 | 68 | } | ||
3478 | 69 | return create_node(node); | ||
3479 | 70 | } | ||
3480 | 71 | |||
3481 | 72 | function create_cont() { | ||
3482 | 73 | var node = { | ||
3483 | 74 | 'type': 'cont', | ||
3484 | 75 | 'src': [], | ||
3485 | 76 | } | ||
3486 | 77 | return create_node(node); | ||
3487 | 78 | } | ||
3488 | 79 | |||
3489 | 80 | function create_sequence() { | ||
3490 | 81 | var node = { | ||
3491 | 82 | 'type': 'sequence', | ||
3492 | 83 | 'src': [], | ||
3493 | 84 | } | ||
3494 | 85 | var doc = create_node(node); | ||
3495 | 86 | doc.doodle = []; | ||
3496 | 87 | return doc; | ||
3497 | 88 | } | ||
3498 | 89 | |||
3499 | 90 | |||
3500 | 91 | function SlicePlayer() { | ||
3501 | 92 | this.video = document.createElement('video'); | ||
3502 | 93 | //this.video.muted = true; | ||
3503 | 94 | this.video.addEventListener('canplaythrough', | ||
3504 | 95 | $bind(this.on_canplaythrough, this) | ||
3505 | 96 | ); | ||
3506 | 97 | this.video.addEventListener('seeked', | ||
3507 | 98 | $bind(this.on_seeked, this) | ||
3508 | 99 | ); | ||
3509 | 100 | this.video.addEventListener('ended', | ||
3510 | 101 | $bind(this.on_ended, this) | ||
3511 | 102 | ); | ||
3512 | 103 | |||
3513 | 104 | this.timeout_id = null; | ||
3514 | 105 | |||
3515 | 106 | this.playing = false; | ||
3516 | 107 | this.ready = false; | ||
3517 | 108 | this.ended = false; | ||
3518 | 109 | |||
3519 | 110 | this.onready = null; | ||
3520 | 111 | this.onended = null; | ||
3521 | 112 | } | ||
3522 | 113 | SlicePlayer.prototype = { | ||
3523 | 114 | log_event: function(name, point) { | ||
3524 | 115 | var frame = seconds_to_frame(this.video.currentTime, this.clip.framerate); | ||
3525 | 116 | var parts = [name, frame, point, frame == point]; | ||
3526 | 117 | console.log(parts.join(' ')); | ||
3527 | 118 | }, | ||
3528 | 119 | |||
3529 | 120 | on_canplaythrough: function(event) { | ||
3530 | 121 | this.seek(this.slice.node.start.frame); | ||
3531 | 122 | }, | ||
3532 | 123 | |||
3533 | 124 | on_seeked: function(event) { | ||
3534 | 125 | //this.log_event('seeked', this.slice.node.start.frame); | ||
3535 | 126 | if (!this.ready) { | ||
3536 | 127 | this.ready = true; | ||
3537 | 128 | if (this.onready) { | ||
3538 | 129 | this.onready(this); | ||
3539 | 130 | } | ||
3540 | 131 | } | ||
3541 | 132 | }, | ||
3542 | 133 | |||
3543 | 134 | on_ended: function(event) { | ||
3544 | 135 | this.video.pause(); | ||
3545 | 136 | this.clear_timeout(); | ||
3546 | 137 | //this.log_event('ended', this.slice.node.stop.frame); | ||
3547 | 138 | this.ended = true; | ||
3548 | 139 | if (this.onended) { | ||
3549 | 140 | this.onended(this); | ||
3550 | 141 | } | ||
3551 | 142 | }, | ||
3552 | 143 | |||
3553 | 144 | seek: function(frame) { | ||
3554 | 145 | this.video.currentTime = this.frame_to_seconds(frame); | ||
3555 | 146 | }, | ||
3556 | 147 | |||
3557 | 148 | frame_to_seconds: function(frame) { | ||
3558 | 149 | return frame_to_seconds(frame, this.clip.framerate); | ||
3559 | 150 | }, | ||
3560 | 151 | |||
3561 | 152 | clear_timeout: function() { | ||
3562 | 153 | if (this.timeout_id != null) { | ||
3563 | 154 | clearTimeout(this.timeout_id); | ||
3564 | 155 | this.timeout_id = null; | ||
3565 | 156 | } | ||
3566 | 157 | }, | ||
3567 | 158 | |||
3568 | 159 | set_timeout: function(duration) { | ||
3569 | 160 | this.clear_timeout(); | ||
3570 | 161 | var callback = $bind(this.on_ended, this); | ||
3571 | 162 | this.timeout_id = setTimeout(callback, duration); | ||
3572 | 163 | }, | ||
3573 | 164 | |||
3574 | 165 | playpause: function() { | ||
3575 | 166 | if (this.playing) { | ||
3576 | 167 | this.pause(); | ||
3577 | 168 | } | ||
3578 | 169 | else { | ||
3579 | 170 | this.play(); | ||
3580 | 171 | } | ||
3581 | 172 | }, | ||
3582 | 173 | |||
3583 | 174 | play: function() { | ||
3584 | 175 | if (this.playing || !this.ready) { | ||
3585 | 176 | return; | ||
3586 | 177 | } | ||
3587 | 178 | this.playing = true; | ||
3588 | 179 | this.video.style.visibility = 'visible'; | ||
3589 | 180 | if (this.slice.node.stop.frame != this.clip.duration.frames) { | ||
3590 | 181 | var stop = this.frame_to_seconds(this.slice.node.stop.frame); | ||
3591 | 182 | var duration = 1000 * (stop - this.video.currentTime); | ||
3592 | 183 | this.set_timeout(duration); | ||
3593 | 184 | } | ||
3594 | 185 | this.video.play(); | ||
3595 | 186 | }, | ||
3596 | 187 | |||
3597 | 188 | pause: function() { | ||
3598 | 189 | if (!this.ready) { | ||
3599 | 190 | return; | ||
3600 | 191 | } | ||
3601 | 192 | this.playing = false; | ||
3602 | 193 | this.video.style.visibility = 'visible'; | ||
3603 | 194 | this.clear_timeout(); | ||
3604 | 195 | this.video.pause(); | ||
3605 | 196 | }, | ||
3606 | 197 | |||
3607 | 198 | stop: function() { | ||
3608 | 199 | this.video.style.visibility = 'hidden'; | ||
3609 | 200 | this.video.pause(); | ||
3610 | 201 | this.clear_timeout(); | ||
3611 | 202 | this.ended = false; | ||
3612 | 203 | this.ready = false; | ||
3613 | 204 | this.playing = false; | ||
3614 | 205 | }, | ||
3615 | 206 | |||
3616 | 207 | load_slice: function(clip, slice) { | ||
3617 | 208 | this.stop(); | ||
3618 | 209 | this.clip = clip; | ||
3619 | 210 | this.slice = slice; | ||
3620 | 211 | this.video.src = 'dmedia:' + this.clip._id; | ||
3621 | 212 | //setTimeout($bind(this.do_load, this), 50); | ||
3622 | 213 | }, | ||
3623 | 214 | |||
3624 | 215 | do_load: function() { | ||
3625 | 216 | this.video.src = 'dmedia:' + this.clip._id; | ||
3626 | 217 | }, | ||
3627 | 218 | } | ||
3628 | 219 | |||
3629 | 220 | |||
3630 | 221 | |||
3631 | 222 | function SequencePlayer(session, doc) { | ||
3632 | 223 | this.session = session; | ||
3633 | 224 | this.doc = doc; | ||
3634 | 225 | |||
3635 | 226 | this.element = $el('div', {'id': 'player', 'class': 'hide'}); | ||
3636 | 227 | |||
3637 | 228 | this.player1 = new SlicePlayer(); | ||
3638 | 229 | this.player1.i = 0; | ||
3639 | 230 | this.player2 = new SlicePlayer(); | ||
3640 | 231 | this.player2.i = 1; | ||
3641 | 232 | |||
3642 | 233 | this.players = [this.player1, this.player2]; | ||
3643 | 234 | var on_ready = $bind(this.on_ready, this); | ||
3644 | 235 | var on_ended = $bind(this.on_ended, this); | ||
3645 | 236 | this.players.forEach(function(player) { | ||
3646 | 237 | player.onready = on_ready; | ||
3647 | 238 | player.onended = on_ended; | ||
3648 | 239 | this.element.appendChild(player.video); | ||
3649 | 240 | }, this); | ||
3650 | 241 | |||
3651 | 242 | this.ready = false; | ||
3652 | 243 | this.playing = false; | ||
3653 | 244 | this.active = false; | ||
3654 | 245 | |||
3655 | 246 | this.timeout_id == null | ||
3656 | 247 | |||
3657 | 248 | this.element.onclick = $bind(this.playpause, this); | ||
3658 | 249 | |||
3659 | 250 | document.body.appendChild(this.element); | ||
3660 | 251 | |||
3661 | 252 | } | ||
3662 | 253 | SequencePlayer.prototype = { | ||
3663 | 254 | show: function() { | ||
3664 | 255 | console.log('show'); | ||
3665 | 256 | if (this.doc.node.src.length == 0) { | ||
3666 | 257 | return; | ||
3667 | 258 | } | ||
3668 | 259 | $show(this.element); | ||
3669 | 260 | this.active = true; | ||
3670 | 261 | this.playing = true; | ||
3671 | 262 | this.play_from_slice(UI.selected); | ||
3672 | 263 | }, | ||
3673 | 264 | |||
3674 | 265 | soft_hide: function() { | ||
3675 | 266 | $hide(this.element); | ||
3676 | 267 | console.assert(!this.playing); | ||
3677 | 268 | }, | ||
3678 | 269 | |||
3679 | 270 | soft_show: function() { | ||
3680 | 271 | $show(this.element); | ||
3681 | 272 | console.assert(!this.playing); | ||
3682 | 273 | }, | ||
3683 | 274 | |||
3684 | 275 | hide: function() { | ||
3685 | 276 | console.log('hide'); | ||
3686 | 277 | $hide(this.element); | ||
3687 | 278 | this.active = false; | ||
3688 | 279 | this.stop(); | ||
3689 | 280 | }, | ||
3690 | 281 | |||
3691 | 282 | playpause: function() { | ||
3692 | 283 | if (this.playing) { | ||
3693 | 284 | this.pause(); | ||
3694 | 285 | } | ||
3695 | 286 | else { | ||
3696 | 287 | this.play(); | ||
3697 | 288 | } | ||
3698 | 289 | }, | ||
3699 | 290 | |||
3700 | 291 | hold: function() { | ||
3701 | 292 | this.was_playing = this.playing; | ||
3702 | 293 | this.playing = false; | ||
3703 | 294 | this.activate_target(true); | ||
3704 | 295 | }, | ||
3705 | 296 | |||
3706 | 297 | hold_and_resume: function() { | ||
3707 | 298 | if (this.timeout_id == null) { | ||
3708 | 299 | console.log('first hold'); | ||
3709 | 300 | this.hold(); | ||
3710 | 301 | } | ||
3711 | 302 | clearTimeout(this.timeout_id); | ||
3712 | 303 | this.timeout_id = setTimeout($bind(this.on_timeout, this), 500); | ||
3713 | 304 | }, | ||
3714 | 305 | |||
3715 | 306 | on_timeout: function() { | ||
3716 | 307 | console.log('timeout'); | ||
3717 | 308 | this.timeout_id = null; | ||
3718 | 309 | this.resume(); | ||
3719 | 310 | }, | ||
3720 | 311 | |||
3721 | 312 | resume: function() { | ||
3722 | 313 | this.playing = this.was_playing; | ||
3723 | 314 | if (UI.selected) { | ||
3724 | 315 | this.play_from_slice(UI.selected); | ||
3725 | 316 | } | ||
3726 | 317 | else { | ||
3727 | 318 | this.activate_target(true); | ||
3728 | 319 | } | ||
3729 | 320 | }, | ||
3730 | 321 | |||
3731 | 322 | stop: function() { | ||
3732 | 323 | this.players.forEach(function(player) { | ||
3733 | 324 | player.stop(); | ||
3734 | 325 | }); | ||
3735 | 326 | this.ready = false; | ||
3736 | 327 | this.target = null; | ||
3737 | 328 | }, | ||
3738 | 329 | |||
3739 | 330 | play: function() { | ||
3740 | 331 | this.playing = true; | ||
3741 | 332 | this.activate_target(); | ||
3742 | 333 | }, | ||
3743 | 334 | |||
3744 | 335 | pause: function() { | ||
3745 | 336 | this.playing = false; | ||
3746 | 337 | this.activate_target(); | ||
3747 | 338 | }, | ||
3748 | 339 | |||
3749 | 340 | play_from_slice: function(slice_id) { | ||
3750 | 341 | if (this.doc.node.src.length == 0) { | ||
3751 | 342 | return; | ||
3752 | 343 | } | ||
3753 | 344 | this.stop(); | ||
3754 | 345 | if (!slice_id) { | ||
3755 | 346 | slice_id = UI.selected; | ||
3756 | 347 | } | ||
3757 | 348 | console.log('play_from_slice ' + slice_id); | ||
3758 | 349 | var index = Math.max(0, this.doc.node.src.indexOf(slice_id)); | ||
3759 | 350 | this.load_slice(this.player1, index); | ||
3760 | 351 | this.load_slice(this.player2, index + 1); | ||
3761 | 352 | }, | ||
3762 | 353 | |||
3763 | 354 | get_player: function(i) { | ||
3764 | 355 | return this.players[i % this.players.length]; | ||
3765 | 356 | }, | ||
3766 | 357 | |||
3767 | 358 | next_slice_index: function(player) { | ||
3768 | 359 | return this.doc.node.src.indexOf(player.slice._id) + 1; | ||
3769 | 360 | }, | ||
3770 | 361 | |||
3771 | 362 | load_slice: function(player, index) { | ||
3772 | 363 | var src = this.doc.node.src; | ||
3773 | 364 | var slice_id = src[index % src.length]; | ||
3774 | 365 | var slice = this.session.get_doc(slice_id); | ||
3775 | 366 | var clip = this.session.get_doc(slice.node.src); | ||
3776 | 367 | player.load_slice(clip, slice); | ||
3777 | 368 | }, | ||
3778 | 369 | |||
3779 | 370 | on_ready: function(player) { | ||
3780 | 371 | if (!this.ready) { | ||
3781 | 372 | if (this.player1.ready && this.player2.ready) { | ||
3782 | 373 | console.log('now ready'); | ||
3783 | 374 | this.ready = true; | ||
3784 | 375 | this.target = this.players[0]; | ||
3785 | 376 | this.activate_target(); | ||
3786 | 377 | } | ||
3787 | 378 | } | ||
3788 | 379 | else if (this.target.ended) { | ||
3789 | 380 | this.swap(); | ||
3790 | 381 | } | ||
3791 | 382 | }, | ||
3792 | 383 | |||
3793 | 384 | activate_target: function(no_select) { | ||
3794 | 385 | if (!this.target) { | ||
3795 | 386 | return; | ||
3796 | 387 | } | ||
3797 | 388 | if (this.playing) { | ||
3798 | 389 | this.target.play(); | ||
3799 | 390 | } | ||
3800 | 391 | else { | ||
3801 | 392 | this.target.pause(); | ||
3802 | 393 | } | ||
3803 | 394 | if (!no_select) { | ||
3804 | 395 | UI.select(this.target.slice._id, true); | ||
3805 | 396 | } | ||
3806 | 397 | }, | ||
3807 | 398 | |||
3808 | 399 | swap: function() { | ||
3809 | 400 | var current = this.target; | ||
3810 | 401 | var next = this.get_player(current.i + 1); | ||
3811 | 402 | if (next.ready) { | ||
3812 | 403 | this.target = next; | ||
3813 | 404 | var index = this.next_slice_index(next); | ||
3814 | 405 | this.activate_target(); | ||
3815 | 406 | this.load_slice(current, index); | ||
3816 | 407 | } | ||
3817 | 408 | }, | ||
3818 | 409 | |||
3819 | 410 | on_ended: function(player) { | ||
3820 | 411 | this.swap(); | ||
3821 | 412 | }, | ||
3822 | 413 | } | ||
3823 | 414 | |||
3824 | 415 | |||
3825 | 416 |