forked from sambler/myblendercontrib
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVSEQuickFunctions.py
More file actions
1535 lines (1462 loc) · 68.9 KB
/
VSEQuickFunctions.py
File metadata and controls
1535 lines (1462 loc) · 68.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#VSE Quick Functions
#
#
#Features that this script includes:
#
#Quickfades -
# Can be found in the sequence editor properties panel, or by pressing the
# 'f' key over the sequencer.
# Fade Length - The target length for fade editing or creating.
# Set Fadein/Set Fadeout - Allows easy adding, detecting and changing of
# fade in/out. The script will check the curve for any fades already
# applied to the clip (either manually or by the script), and edit them
# if found. Can apply the same fade to multiple clips at once.
# Transition Type - Selects the type of transition for adding.
# Crossfade Prev/Next Clip - Allows easy adding of transitions between clips.
# Will simply find an overlapping clip from the active clip and add
# a transition.
# Smart Cross to Prev/Next - Adjust the length of the active clip and the
# next clip to create a transition of the target fade length. Will also
# attempt to avoid extending the clips past their end points if possible.
#
#Quicksnaps -
# Can be found in the sequence editor 'Strip' menu, or by pressing the
# 's' key over the sequencer.
# Allows quickly snapping clips to each other or moving the cursor to clips.
# Cursor To Nearest Second - Will round the cursor position to the nearest
# second, based on framerate.
# Cursor To Beginning/End Of Clip - Will move the cursor to the beginning or
# end of the active clip.
# Clip Beginning/End To Cursor - Moves all selected clips so their
# beginning/end is at the cursor.
# Clip To Previous/Next Clip - Detects the previous or next clip in the
# timeline from the active clip. Moves the active clip so it's beginning
# or end matches the previous clip's end or beginning.
#
#Quickzooms -
# Can be found in the sequence editor 'View' menu, or by pressing the
# 'z' key over the sequencer.
# Zoom All - Zooms the sequencer out to show all clips.
# Zoom Selected - Zooms the sequencer to show the currently selected clip(s).
# Zoom Cursor - Zooms the sequencer to an amount of frames around the cursor.
# Size - How many frames should be shown by using Zoom Cursor.
# Changing this value will automatically activate Zoom Cursor.
#
#Quickparents -
# Can be found in the sequence editor properties panel, or by pressing the
# 'Ctrl-p' key over the sequencer.
# This implements a parenting system for sequencer clips, allowing easy
# selecting of multiple related clips. Note that any relationships will
# be broken if a clip is renamed!
# Select Children - Selects any child clips found for the currently selected
# clip(s). Also can be accomplished with the shortcut 'Shift-p'
# Set Active As Parent - If multiple clips are selected, this will set
# selected clips as children of the active (lastly selected) clip.
# Clear Parent - Removes parent relationships from selected children clips.
# Clear Children - Removes child relationships from selected parent clips.
# Children or Parents of selected clip will be shown at the bottom of
# the Panel/Menu.
#
#Quickcontinuous -
# Settings can be found in the sequence editor 'View' menu.
# When Quickcontinuous is enabled, it will constantly run and detect clip
# editing events.
# Cursor Following - Automatically moves the sequencer timeline to try and
# follow the cursor. Unfortunately, this can be fooled if the cursor is
# offscreen, or if the cursor is moved a large amount.
# Clip Auto Snapping - If a clip is grabbed and placed, the closest clip will
# be found, if this clip is within the snapping distance, the dropped
# clip will be snapped to the closest clip.
# Cut/Move Clip Children - Works with Quickparents by finding any children
# of a moved or cut clip and performing the same operation on them.
# If the clip is cut, any children under the cursor will be cut as well,
# and the script will attempt to duplicate parent/child relationships to
# the cut clips. Note, if you cut a clip with the mouse on the left
# side of the cursor this will not work because the cut parent isnt
# selected (so keep the mouse on the right side of the cursor).
#
#Quicktitling -
# Can be found in the sequence editor properties panel.
# This will create and edit simple scenes for title overlays.
# Create Title Scene - This will create a title scene with the settings
# shown below.
# Update Title Scene - If an already-created title scene is selected,
# this will apply the current settings to that scene.
# Scene Length - The length in frames of the title scene.
# Text Font - A menu of the currently loaded fonts in the blend file.
# Text Material - A menu of all materials in the blend file.
# Text X/Y Location - Determines the center point of the text with 0,0 being
# the center of the screen.
# Text Size - Scale of the text.
# Extrude - Amount of extrusion to create a 3D look.
# Bevel Size - Amount of beveling to apply to the text.
# Bevel Resolution - Subdivisions of the bevel.
# Text - Title text.
# Shadow Amount - Determines the opacity of the drop shadow.
# Distance - How far away the shadow plane is from the text object, larger
# values result in a larger shadow
# Soft - The amount of blur applied to the drop shadow.
#
#Quicklist -
# Can be found in the sequence editor properties panel.
# Displays a list of loaded clips and allows you to change various settings.
# Sort by - Reorders the list based on timeline position, title, or length.
# Eye Icon - Mutes/unmutes clip.
# Padlock Icon - Locks/unlocks clip.
# Clip Type Button - Allows selecting and deselecting clip.
# Clip Title - Allows editing of clip name.
# Length/Position - Move or resize the clip.
# Proxy settings - Enable/disable proxy and sizes.
#
#
#Todo:
# fix:
# parent/child relationship copy info not showing
# detecting cut clips isn't currently possible when the first clip isnt selected after the cut
# fades get really screwed up when the in/out points of a clip are changed after fade is added
# cursor following is pretty buggy
# continuous mode may stop working and need to be disabled and re-enabled
# add:
# add functions for quicklist - swap clip with previous or next if in position sort
# make quicklist more streamlined, maybe put it in a modal dialog
import bpy
import math
import os
from bpy.app.handlers import persistent
bl_info = {
"name": "VSE Quick Functions",
"description": "Improves funcionality of the sequencer by adding new menus for snapping, adding fades, zooming, strip parenting, and playback speed",
"author": "Hudson Barkley (Snu)",
"version": (0, 88),
"blender": (2, 71, 0),
"location": "Sequencer Panels; Sequencer Menus; Sequencer S, F, Z, Ctrl-P, Shift-P Shortcuts",
"wiki_url": "http://blenderaddonlist.blogspot.com.au/2014/06/addon-vse-quick-functions.html",
"category": "Sequencer"
}
#Functions used by various features
def find_next_clip(sequences, clip, mode='overlap'):
#if mode is overlap, will only return overlapping sequences
#if mode is channel, will only return sequences in clip's channel
#if mode is set to other, all clips are considered
overlaps = []
nexts = []
for sequence in sequences:
if (sequence.type != 'SOUND'):
if (mode == 'channel'):
if ((clip.frame_final_end <= sequence.frame_final_start) & (clip.channel == sequence.channel)):
nexts.append(sequence)
else:
#if clip's end point overlaps the sequence, and the sequence begins after the clip
if ((clip.frame_final_end > sequence.frame_final_start) & (clip.frame_final_end < sequence.frame_final_end) & (clip.frame_final_start < sequence.frame_final_start)):
overlaps.append(sequence)
if (mode != 'overlap'):
if (clip.frame_final_end == sequence.frame_final_start):
overlaps.append(sequence)
if (clip.frame_final_end <= sequence.frame_final_start):
nexts.append(sequence)
if (len(overlaps) > 0):
return min(overlaps, key=lambda overlap: abs(overlap.channel - clip.channel))
elif ((mode != 'overlap') & (len(nexts) > 0)):
return min(nexts, key=lambda next: (next.frame_final_start - clip.frame_final_end))
else:
return False
def find_previous_clip(sequences, clip, mode='overlap'):
overlaps = []
previous = []
for sequence in sequences:
if (mode == 'channel'):
if ((clip.frame_final_start >= sequence.frame_final_end) & (clip.channel == sequence.channel)):
previous.append(sequence)
else:
if ((clip.frame_final_start > sequence.frame_final_start) & (clip.frame_final_start < sequence.frame_final_end) & (clip.frame_final_end > sequence.frame_final_end)):
overlaps.append(sequence)
if (mode != 'overlap'):
if (clip.frame_final_start == sequence.frame_final_end):
overlaps.append(sequence)
if (clip.frame_final_start >= sequence.frame_final_end):
previous.append(sequence)
if (len(overlaps) > 0):
return min(overlaps, key=lambda overlap: abs(overlap.channel - clip.channel))
elif ((mode != 'overlap') & (len(previous) > 0)):
return min(previous, key=lambda prev: (clip.frame_final_start - prev.frame_final_end))
else:
return False
def timecode_from_frames(frame, framespersecond, levels=0, subsecondtype='miliseconds'):
if (levels > 4):
levels = 4
if (subsecondtype == 'frames'):
subseconddivisor = framespersecond
else:
subseconddivisor = 100
totalhours = math.modf(frame/framespersecond/60/60)
totalminutes = math.modf(totalhours[0] * 60)
remainingseconds = math.modf(totalminutes[0] * 60)
hours = int(totalhours[1])
minutes = int(totalminutes[1])
seconds = int(remainingseconds[1])
subseconds = int(remainingseconds[0] * subseconddivisor)
time = str(hours).zfill(2)+':'+str(minutes).zfill(2)+':'+str(seconds).zfill(2)+':'+str(subseconds).zfill(2)[-2:]
if (levels == 0):
while (time[0:3] == '00:'):
time = time[3:len(time)]
return time
else:
return time.split(':', 4 - levels)[-1]
#Functions related to continuous update
def draw_quickcontinuous_menu(self, context):
layout = self.layout
layout.menu('vseqf.continuous_menu', text="Quick Continuous Settings")
def find_sound_clip(clipname, clips):
soundclip = None
os.path.splitext(clipname)[0]
for clip in clips:
if ((os.path.splitext(clip.name)[0] == os.path.splitext(clipname)[0]) & (clip.type == 'SOUND')):
return clip
@persistent
def toggle_continuous(self, context=bpy.context):
bpy.ops.vseqf.continuous('INVOKE_DEFAULT')
#Functions related to QuickTitling
def titling_scene():
sequence = bpy.context.scene.sequence_editor.active_strip
if (sequence == None):
scene = bpy.context.scene
elif (('QuickTitle: ' in sequence.name) & (sequence.type == 'SCENE')):
scene = sequence.scene
else:
scene = bpy.context.scene
return scene
#Functions related to QuickSpeed
@persistent
def frame_step(scene):
scene = bpy.context.scene
step = scene.step
if (step == 1):
if (scene.frame_current % 3 == 0):
scene.frame_current = scene.frame_current + 1
if (step > 1):
scene.frame_current = scene.frame_current + (step - 1)
def draw_quickspeed_header(self, context):
layout = self.layout
scene = context.scene
self.layout_width = 30
layout.prop(scene, 'step', text="Speed Step")
#Functions related to QuickZoom
def draw_quickzoom_menu(self, context):
layout = self.layout
layout.menu('vseqf.quickzooms_menu', text="Quick Zoom")
def zoom_custom(begin, end):
scene = bpy.context.scene
selected = []
try:
sequences = bpy.context.sequences
except:
scene.sequence_editor_create()
sequences = bpy.context.sequences
for sequence in sequences:
if (sequence.select):
selected.append(sequence)
sequence.select = False
zoomClip = scene.sequence_editor.sequences.new_effect(name='temp', type='ADJUSTMENT', channel=1, frame_start=begin, frame_end=end)
active = bpy.context.scene.sequence_editor.active_strip
scene.sequence_editor.active_strip = zoomClip
for region in bpy.context.area.regions:
if (region.type == 'WINDOW'):
override = {'region': region, 'window': bpy.context.window, 'screen': bpy.context.screen, 'area': bpy.context.area, 'scene': bpy.context.scene}
bpy.ops.sequencer.view_selected(override)
scene.sequence_editor.sequences.remove(zoomClip)
for sequence in selected:
sequence.select = True
bpy.context.scene.sequence_editor.active_strip = active
def zoom_cursor(self=None, context=None):
cursor = bpy.context.scene.frame_current
zoom_custom(cursor, (cursor + bpy.context.scene.zoom))
#Functions related to QuickFades
def crossfade(firstClip, secondClip):
type = bpy.context.scene.transition
sequences = bpy.context.sequences
bpy.ops.sequencer.select_all(action='DESELECT')
firstClip.select = True
secondClip.select = True
bpy.context.scene.sequence_editor.active_strip = secondClip
bpy.ops.sequencer.effect_strip_add(type=type)
def fades(strip, fade, type, mode):
#strip = vse strip
#fade = positive value of fade in frames
#type = 'in' or 'out'
#mode = 'detect' or 'set' or 'clear'
scene = bpy.context.scene
#these functions check for the needed variables and create them if in set mode. Otherwise, ends the function.
if (scene.animation_data == None):
#no animation data in scene, create it
if (mode == 'set'):
scene.animation_data_create()
else:
return 0
if (scene.animation_data.action == None):
#no action in scene, create it
if (mode == 'set'):
action = bpy.data.actions.new(scene.name+"Action")
scene.animation_data.action = action
else:
return 0
fcurves = scene.animation_data.action.fcurves
fadeZero = False
fadeFull = False
keyframes = False
if (strip.type == 'SOUND'):
fadeVariable = 'volume'
else:
fadeVariable = 'blend_alpha'
#attempts to find the fade keyframes
for curve in fcurves:
if (curve.data_path == 'sequence_editor.sequences_all["'+strip.name+'"].'+fadeVariable):
#keyframes found
fcurve = curve
if (mode == 'clear'):
fcurves.remove(curve)
return 0
keyframes = curve.keyframe_points
if (type == 'in'):
if (len(keyframes) > 0):
fadeZero = keyframes[0]
if (len(keyframes) > 1):
fadeFull = keyframes[1]
elif (type == 'out'):
if (len(keyframes) > 0):
fadeZero = keyframes[len(keyframes) - 1]
if (len(keyframes) > 1):
fadeFull = keyframes[len(keyframes) - 2]
if (keyframes == False):
#no keyframes found, create them if instructed to
if (mode == 'set'):
curve = fcurves.new(data_path=strip.path_from_id(fadeVariable))
keyframes = curve.keyframe_points
else:
return 0
alpha = 1
if (type == 'in'):
stripFadeEnd = strip.frame_final_start
elif (type == 'out'):
stripFadeEnd = strip.frame_final_end
fade = -fade
if (fadeZero):
#keyframes found, need to be adjusted
if (fadeZero.co[0] == stripFadeEnd):
if (fadeFull):
#start and end are present, start is where it needs to be
if (mode == 'set'):
if (fade != 0):
offset = ((stripFadeEnd + fade) - fadeFull.co[0])
fadeFull.co = (((fadeFull.co[0] + offset), alpha))
fadeFull.handle_left = ((fadeFull.handle_left[0] + offset, alpha))
fadeFull.handle_right = ((fadeFull.handle_right[0] + offset, alpha))
fadeZero.co = ((fadeZero.co[0], 0))
elif (fade == 0):
keyframes.remove(fadeZero)
else:
return abs(fadeFull.co[0] - fadeZero.co[0])
else:
#start is present and where it needs to be, no second, set alpha to start
if (mode == 'set'):
alpha = fadeZero.co[1]
fadeZero.co = ((fadeZero.co[0], 0))
keyframes.insert(frame=(stripFadeEnd + fade), value=alpha)
else:
return 0
else:
#no start and end where they need to be, but keyframe exists to set alpha
if (mode == 'set'):
#determine alpha from value at stripFadeEnd
alpha = fcurve.evaluate(stripFadeEnd)
#clear any keyframes before the beginning or after the end
index = len(keyframes) - 1
while index >= 0:
keyframe = keyframes[index]
if (type == 'in'):
if (keyframe.co[0] < stripFadeEnd):
keyframes.remove(keyframe)
elif (type == 'out'):
if (keyframe.co[0] > stripFadeEnd):
keyframes.remove(keyframe)
index = index - 1
keyframes.insert(frame=stripFadeEnd, value=0)
keyframes.insert(frame=(stripFadeEnd + fade), value=alpha)
else:
return 0
else:
#no keyframes found, create them
if (mode == 'set'):
alpha = getattr(strip, fadeVariable)
keyframes.insert(frame=stripFadeEnd, value=0)
keyframes.insert(frame=(stripFadeEnd + fade), value=alpha)
else:
return 0
#Functions related to QuickParents
def select_children(parent):
clean_relationships()
sequences = bpy.context.sequences
childrennames = find_children(parent)
for sequence in sequences:
if (sequence.name in childrennames):
sequence.select = True
def add_children(parent, children):
clean_relationships()
for child in children:
if (child.name != parent.name):
children = parent.name
if (child.name not in children):
relationship = bpy.context.scene.parenting.add()
relationship.parent = parent.name
relationship.child = child.name
def clear_children(parent):
clean_relationships()
if (type(parent) == str):
parentname = parent
else:
parentname = parent.name
scene = bpy.context.scene
index = 0
while index < len(scene.parenting):
if (scene.parenting[index].parent == parentname):
scene.parenting.remove(index)
else:
index = index + 1
def clear_parent(child):
clean_relationships()
if (type(child) == str):
childname = child
else:
childname = child.name
scene = bpy.context.scene
for index, relationship in enumerate(scene.parenting):
if (relationship.child == childname):
scene.parenting.remove(index)
def find_parent(child):
if (type(child) == str):
childname = child
else:
childname = child.name
scene = bpy.context.scene
for relationship in scene.parenting:
if (relationship.child == childname):
return relationship.parent
return "None"
def find_children(parent):
if (type(parent) == str):
parentname = parent
else:
parentname = parent.name
scene = bpy.context.scene
childrennames = []
for relationship in scene.parenting:
if (relationship.parent == parentname):
childrennames.append(relationship.child)
return childrennames
def clean_relationships():
scene = bpy.context.scene
sequences = scene.sequence_editor.sequences_all
for index, relationship in enumerate(scene.parenting):
if ( (sequences.find(relationship.parent) == -1) | (sequences.find(relationship.child) == -1) ):
scene.parenting.remove(index)
#Functions related to QuickSnaps
def draw_quicksnap_menu(self, context):
layout = self.layout
layout.menu('vseqf.quicksnaps_menu', text="Quick Snaps")
#Classes related to QuickList
class VSEQFQuickListPanel(bpy.types.Panel):
bl_label = "Quick List"
bl_space_type = 'SEQUENCE_EDITOR'
bl_region_type = 'UI'
@classmethod
def poll(self, context):
if (bpy.context.sequences):
if (len(bpy.context.sequences) > 0):
return True
else:
return False
else:
return False
def draw(self, contex):
layout = self.layout
scene = bpy.context.scene
sequencer = scene.sequence_editor
sequences = bpy.context.sequences
row = layout.row()
row.operator('vseqf.quicklist_select', text='Select/Deselect All Clips').clip = ''
row = layout.row(align=True)
row.alignment = 'EXPAND'
row.label('Sort By:')
sub = row.column(align=True)
sub.operator('vseqf.quicklist_sortby', text='Position').method = 'Position'
if (scene.quicklistsort == 'Position'):
sub.active = True
else:
sub.active = False
sub = row.column(align=True)
sub.operator('vseqf.quicklist_sortby', text='Title').method = 'Title'
if (scene.quicklistsort == 'Title'):
sub.active = True
else:
sub.active = False
sub = row.column(align=True)
sub.operator('vseqf.quicklist_sortby', text='Length').method = 'Length'
if (scene.quicklistsort == 'Length'):
sub.active = True
else:
sub.active = False
sorted = list(sequences)
if (scene.quicklistsort == 'Title'):
sorted.sort(key=lambda sequence: sequence.name)
elif (scene.quicklistsort =='Length'):
sorted.sort(key=lambda sequence: sequence.frame_final_duration)
else:
sorted.sort(key=lambda sequence: sequence.frame_final_start)
for clip in sorted:
if (hasattr(clip, 'input_1')):
resort = sorted.pop(sorted.index(clip))
parentindex = sorted.index(clip.input_1)
sorted.insert(parentindex + 1, resort)
for index, sequence in enumerate(sorted):
if (hasattr(sequence, 'input_1')):
row = layout.row()
row.separator()
row.separator()
outline = row.box()
else:
outline = layout.box()
box = outline.column()
row = box.row(align=True)
split = row.split(align=True)
split.prop(sequence, 'mute', text='')
split.prop(sequence, 'lock', text='')
split = row.split(align=True, percentage=0.2)
col = split.column(align=True)
col.operator('vseqf.quicklist_select', text="("+sequence.type+")").clip = sequence.name
col.active = sequence.select
col = split.column(align=True)
col.prop(sequence, 'name', text='')
row = box.row()
split = row.split(percentage=0.8)
col = split.row(align=True)
col.prop(sequence, 'frame_final_duration', text="Length: ("+timecode_from_frames(sequence.frame_final_duration, scene.render.fps)+"), Frame")
col.prop(sequence, 'frame_start', text="Position: ("+timecode_from_frames(sequence.frame_start, scene.render.fps)+"), Frame")
col = split.row()
if (sequence.type != 'SOUND'):
col.prop(sequence, 'use_proxy', text='Proxy')
if (sequence.use_proxy):
row = box.row()
split = row.split(percentage=0.33)
col = split.row(align=True)
col.prop(sequence.proxy, 'quality')
col = split.row(align=True)
col.prop(sequence.proxy, 'build_25')
col.prop(sequence.proxy, 'build_50')
col.prop(sequence.proxy, 'build_75')
col.prop(sequence.proxy, 'build_100')
children = find_children(sequence)
if (len(children) > 0):
row = box.row()
split = row.split(percentage=0.25)
col = split.column()
col.label('Children:')
col = split.column()
for child in children:
col.label(child)
if (sequence.type == 'META'):
row = box.row()
split = row.split(percentage=0.25)
col = split.column()
col.label('Subclips:')
col = split.column()
for subclip in sequence.sequences:
col.label(subclip.name)
class VSEQFQuickListSortBy(bpy.types.Operator):
bl_idname = "vseqf.quicklist_sortby"
bl_label = "VSEQF Quick List Sort By"
method = bpy.props.StringProperty()
def execute(self, context):
scene = context.scene
scene.quicklistsort = self.method
return {'FINISHED'}
class VSEQFQuickListSelect(bpy.types.Operator):
bl_idname = "vseqf.quicklist_select"
bl_label = "VSEQF Quick List Select Clip"
clip = bpy.props.StringProperty()
def execute(self, context):
sequences = context.sequences
if (self.clip == ''):
bpy.ops.sequencer.select_all(action='TOGGLE')
else:
for sequence in sequences:
if (sequence.name == self.clip):
sequence.select = not sequence.select
return {'FINISHED'}
#Classes related to continuous update
class VSEQFContinuousMenu(bpy.types.Menu):
bl_idname = "vseqf.continuous_menu"
bl_label = "Continuous Settings"
def draw(self, context):
layout = self.layout
scene = bpy.context.scene
layout.prop(scene, 'quickcontinuousenable')
if (scene.quickcontinuousenable):
layout.separator()
layout.prop(scene, 'quickcontinuousfollow')
layout.prop(scene, 'quickcontinuoussnap')
layout.prop(scene, 'quickcontinuoussnapdistance')
layout.prop(scene, 'quickcontinuouschildren')
class VSEQFContinuous(bpy.types.Operator):
bl_idname = "vseqf.continuous"
bl_label = "VSEQF Continuous Modal Operator"
lastScene = bpy.props.StringProperty()
lastClip = bpy.props.StringProperty()
lastClipStart = bpy.props.IntProperty()
lastClipLength = bpy.props.IntProperty()
lastClipChannel = bpy.props.IntProperty()
lastCursor = bpy.props.IntProperty()
lastNumberOfClips = bpy.props.IntProperty()
def set_old_variables(self):
scene = bpy.context.scene
sequencer = scene.sequence_editor
sequences = bpy.context.sequences
if (hasattr(sequencer, 'active_strip')):
clip = sequencer.active_strip
else:
clip = None
self.lastScene = scene.name
if (hasattr(clip, 'name')):
self.lastClip = clip.name
self.lastClipStart = clip.frame_final_start
self.lastClipLength = clip.frame_final_duration
self.lastClipChannel = clip.channel
self.lastNumberOfClips = len(sequencer.sequences_all)
else:
self.lastClip = 'None'
self.lastClipStart = 0
self.lastClipLength = 0
self.lastClipChannel = 0
self.lastNumberOfClips = 0
self.lastCursor = scene.frame_current
def modal(self, context, event):
scene = context.scene
if (scene.quickcontinuousenable):
if (self.lastScene == scene.name):
if (self.lastClip != 'None'):
sequencer = scene.sequence_editor
sequences = bpy.context.sequences
clip = sequencer.active_strip
if (clip.name == self.lastClip):
if ((clip.frame_final_start != self.lastClipStart) & (clip.frame_final_duration == self.lastClipLength)):
if (scene.quickcontinuoussnap):
nextclip = find_next_clip(sequences, clip, mode='channel')
previousclip = find_previous_clip(sequences, clip, mode='channel')
try:
nextdistance = nextclip.frame_final_start - clip.frame_final_end
except:
nextdistance = scene.quickcontinuoussnapdistance + 1
try:
previousdistance = clip.frame_final_start - previousclip.frame_final_end
except:
previousdistance = scene.quickcontinuoussnapdistance + 1
snapclip = min([[nextdistance, 'next'], [previousdistance, 'previous']])
if (snapclip[0] <= scene.quickcontinuoussnapdistance):
if (snapclip[1] == 'next'):
clip.frame_start = clip.frame_start + nextdistance
else:
clip.frame_start = clip.frame_start - previousdistance
if (scene.quickcontinuouschildren):
childrennames = find_children(clip)
if (childrennames):
offset = clip.frame_final_start - self.lastClipStart
for childname in childrennames:
for sequence in sequences:
if (sequence.name == childname):
sequence.frame_start = sequence.frame_start + offset
elif (clip.frame_final_duration != self.lastClipLength):
if ((clip.frame_final_start == self.lastClipStart) & (len(sequencer.sequences_all) == self.lastNumberOfClips + 1)):
#clip was cut because beginning point is the same, duration is different, and total clips are increased by one
if (scene.quickcontinuouschildren):
childrennames = find_children(clip)
if (childrennames):
cutchildren = []
#unfortunately, cutting doesnt always select both parts of the cut...
#and there seems to be no way of finding the second part
#so if the cut parent isnt selected, the children arent copied over
cutparent = bpy.context.selected_sequences[0]
if ((cutparent.name == clip.name) | (cutparent.name.split('.')[0] != clip.name.split('.')[0])):
cutparent = False
for childname in childrennames:
for child in sequences:
if (child.name == childname):
if ((child.frame_final_start < scene.frame_current) & (child.frame_final_end > scene.frame_current)):
bpy.ops.sequencer.select_all(action='DESELECT')
child.select = True
bpy.ops.sequencer.cut(frame=scene.frame_current)
selected = bpy.context.selected_sequences
selected.remove(child)
cutchildren.extend(selected)
bpy.ops.sequencer.select_all(action='DESELECT')
if (cutparent):
cutparent.select = True
sequencer.active_strip = cutparent
add_children(cutparent, cutchildren)
self.report({'INFO'}, "Duplicated child cut clips to cut parent")
#report doesnt work so we have to fall back to print, lame
print("Duplicated child cut clips to cut parent")
else:
self.report({'WARNING'}, "Could not determine cut parent clip")
print("Could not determine cut parent clip")
else:
#clip was resized
pass
else:
if (len(sequencer.sequences_all) > self.lastNumberOfClips):
#clip was added
selected = bpy.context.selected_sequences
if (len(selected) > 1):
for clip in selected:
if (clip.type == 'MOVIE'):
soundclip = find_sound_clip(clip.name, selected)
if (soundclip):
self.report({'INFO'}, "Parenting "+soundclip.name+" to "+clip.name)
add_children(clip, [soundclip])
if (scene.frame_current != self.lastCursor):
if (scene.quickcontinuousfollow):
#move timeline to follow cursor
for area in bpy.context.screen.areas:
if (area.type == 'SEQUENCE_EDITOR'):
for region in area.regions:
if (region.type == 'WINDOW'):
if (area.spaces[0].view_type == 'SEQUENCER'):
override = {'area': area, 'window': bpy.context.window, 'region': region, 'screen': bpy.context.screen}
offset = scene.frame_current - self.lastCursor
bpy.ops.view2d.pan(override, deltax=offset)
self.set_old_variables()
return {'PASS_THROUGH'}
else:
return {'FINISHED'}
def invoke(self, context, event):
if (context.scene.quickcontinuousenable):
self.set_old_variables()
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
else:
return {'CANCELLED'}
#Classes related to QuickTitling
class VSEQFQuickTitlingPanel(bpy.types.Panel):
bl_label = "Quick Titling"
bl_space_type = 'SEQUENCE_EDITOR'
bl_region_type = 'UI'
def draw(self, contex):
layout = self.layout
row = layout.row()
try:
sequence = bpy.context.scene.sequence_editor.active_strip
if (('QuickTitle: ' in sequence.name) & (sequence.type == 'SCENE')):
row.operator('vseqf.quicktitling', text='Update Title Scene').action = 'update'
scene = sequence.scene
else:
row.operator('vseqf.quicktitling', text='Create Title Scene').action = 'create'
scene = bpy.context.scene
except:
row.operator('vseqf.quicktitling', text='Create Title Scene').action = 'create'
scene = bpy.context.scene
row = layout.row()
row.prop(scene, 'quicktitlerlength')
row = layout.row()
row.prop(scene, 'quicktitlertext')
outline = layout.box()
row = outline.row()
row.label('Text Font:')
row.menu('vseqf.quicktitler_fonts_menu', text=scene.quicktitlerfont)
row = outline.row(align=True)
split = row.split()
split.label('Material:')
split = row.split(percentage=0.66, align=True)
split.menu('vseqf.quicktitler_materials_menu', text=scene.quicktitlermaterial)
split.operator('vseqf.quicktitler_new_material', text='+')
index = bpy.data.materials.find(scene.quicktitlermaterial)
if (index >= 0):
material = bpy.data.materials[index]
split.prop(material, 'diffuse_color', text='')
outline = layout.box()
row = outline.row()
split = row.split(align=True)
split.prop(scene, 'quicktitlerx', text='X Loc:')
split.prop(scene, 'quicktitlery', text='Y Loc:')
row = outline.row()
row.prop(scene, 'quicktitlersize', text='Size')
outline = layout.box()
row = outline.row()
row.prop(scene, 'quicktitlerextrude')
row = outline.row()
split = row.split(align=True)
split.prop(scene, 'quicktitlerbevelsize')
split.prop(scene, 'quicktitlerbevelresolution')
outline = layout.box()
row = outline.row()
row.prop(scene, 'quicktitlershadow')
row = outline.row()
row.prop(scene, 'quicktitlershadowsize', text='Distance')
row.prop(scene, 'quicktitlershadowsoft', text='Soft')
class VSEQFQuickTitlingNewMaterial(bpy.types.Operator):
bl_idname = 'vseqf.quicktitler_new_material'
bl_label = 'New Material'
bl_description = 'Creates A New Material, Duplicates Current If Available'
def execute(self, context):
scene = bpy.context.scene
index = bpy.data.materials.find(scene.quicktitlermaterial)
if (index >= 0):
material = bpy.data.materials[index].copy()
else:
material = bpy.data.materials.new('QuickTitler Material')
scene.quicktitlermaterial = material.name
return {'FINISHED'}
class VSEQFQuickTitling(bpy.types.Operator):
bl_idname = 'vseqf.quicktitling'
bl_label = 'VSEQF Quick Titling'
bl_description = 'Creates or updates a titler scene'
action = bpy.props.StringProperty()
def execute(self, context):
scene = titling_scene()
sequencer = bpy.context.scene.sequence_editor
if (self.action == 'create'):
bpy.ops.scene.new(type='EMPTY')
titleScene = bpy.context.scene
titleScene.quicktitlerfont = scene.quicktitlerfont
titleScene.quicktitlerx = scene.quicktitlerx
titleScene.quicktitlery = scene.quicktitlery
titleScene.quicktitlersize = scene.quicktitlersize
titleScene.quicktitlerextrude = scene.quicktitlerextrude
titleScene.quicktitlerbevelsize = scene.quicktitlerbevelsize
titleScene.quicktitlerbevelresolution = scene.quicktitlerbevelresolution
titleScene.quicktitlertext = scene.quicktitlertext
titleScene.quicktitlerlength = scene.quicktitlerlength
titleScene.name = "QuickTitle: "+titleScene.quicktitlertext
titleScene.frame_end = titleScene.quicktitlerlength
titleScene.layers = [True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True]
bpy.ops.object.camera_add()
camera = bpy.context.scene.objects.active
titleScene.camera = camera
camera.location = ((0, 0, 15))
camera.name = "QuickTitlerCamera"
lampEnergy = 0.5
bpy.ops.object.lamp_add(location=(-4, -2.5, 2))
lamp1 = bpy.context.scene.objects.active
lamp1.data.energy = lampEnergy
lamp1.data.shadow_method = 'NOSHADOW'
bpy.ops.object.lamp_add(location=(4, -2.5, 2))
lamp2 = bpy.context.scene.objects.active
lamp2.data.energy = lampEnergy
lamp2.data.shadow_method = 'NOSHADOW'
bpy.ops.object.lamp_add(location=(-4, 2.5, 2))
lamp3 = bpy.context.scene.objects.active
lamp3.data.energy = lampEnergy
lamp3.data.shadow_method = 'NOSHADOW'
bpy.ops.object.lamp_add(location=(4, 2.5, 2))
lamp4 = bpy.context.scene.objects.active
lamp4.data.energy = lampEnergy
lamp4.data.shadow_method = 'NOSHADOW'
bpy.ops.object.lamp_add(type= 'SPOT', location=(0, 0, 4))
shadowLamp = bpy.context.scene.objects.active
shadowLamp.name = 'QuickTitlerLamp'
shadowLamp.data.use_only_shadow = True
shadowLamp.data.shadow_method = 'BUFFER_SHADOW'
shadowLamp.data.shadow_buffer_type = 'REGULAR'
shadowLamp.data.shadow_buffer_soft = 10
shadowLamp.data.shadow_buffer_bias = 0.1
shadowLamp.data.shadow_buffer_size = 512
shadowLamp.data.shadow_buffer_samples = 8
shadowLamp.data.spot_size = 2.182
bpy.ops.object.text_add()
text = bpy.context.scene.objects.active
text.data.align = 'CENTER'
text.name = "QuickTitlerText"
bpy.ops.mesh.primitive_plane_add(radius=10)
shadow = bpy.context.scene.objects.active
shadow.name = "QuickTitlerShadow"
shadow.draw_type = 'WIRE'
shadowMaterial = bpy.data.materials.new('QuickTitlerShadow')
shadowMaterial.diffuse_color = (0, 0, 0)
shadowMaterial.diffuse_intensity = 1
shadowMaterial.specular_intensity = 0
shadowMaterial.use_transparency = True
shadowMaterial.use_cast_buffer_shadows = False
shadowMaterial.shadow_only_type = 'SHADOW_ONLY'
shadowMaterial.use_only_shadow = True
shadow.data.materials.append(shadowMaterial)
titleScene.render.engine = 'BLENDER_RENDER'
titleScene.render.alpha_mode = 'TRANSPARENT'
titleScene.render.image_settings.file_format = 'PNG'
titleScene.render.image_settings.color_mode = 'RGBA'
bpy.context.screen.scene = scene
bpy.ops.sequencer.scene_strip_add(frame_start=scene.frame_current, scene=titleScene.name)
sequence = sequencer.active_strip
sequence.blend_type = 'ALPHA_OVER'
scene = titleScene
else:
sequence = bpy.context.scene.sequence_editor.active_strip
text = None
shadow = None
shadowLamp = None
for object in scene.objects:
if (object.type == 'FONT'):
text = object
if ("QuickTitlerShadow" in object.name):
shadow = object
if ("QuickTitlerLamp" in object.name):
shadowLamp = object
if ((text == None) or (shadow == None) or (shadowLamp == None)):
self.report({'WARNING'}, 'Selected Title Scene Is Incomplete')
return {'CANCELLED'}
scene.frame_end = scene.quicktitlerlength
index = bpy.data.materials.find(scene.quicktitlermaterial)
if (index >= 0):
text.data.materials.clear()
text.data.materials.append(bpy.data.materials[index])
else:
material = bpy.data.materials.new('QuickTitler Material')
scene.quicktitlermaterial = material.name
text.location = (scene.quicktitlerx, scene.quicktitlery, 0)
text.scale = (scene.quicktitlersize, scene.quicktitlersize, scene.quicktitlersize)
text.data.extrude = scene.quicktitlerextrude
text.data.bevel_depth = scene.quicktitlerbevelsize
text.data.bevel_resolution = scene.quicktitlerbevelresolution
text.data.body = scene.quicktitlertext
text.data.font = bpy.data.fonts[scene.quicktitlerfont]
shadow.material_slots[0].material.alpha = scene.quicktitlershadow
shadowLamp.data.shadow_buffer_soft = scene.quicktitlershadowsoft * 10
shadow.location = (0, 0, -(scene.quicktitlershadowsize / 8))
scene.name = "QuickTitle: "+scene.quicktitlertext
sequence.name = "QuickTitle: "+scene.quicktitlertext
bpy.ops.sequencer.reload(adjust_length=True)
bpy.ops.sequencer.refresh_all()
return {'FINISHED'}
class VSEQFQuickTitlingFontMenu(bpy.types.Menu):
bl_idname = 'vseqf.quicktitler_fonts_menu'
bl_label = 'List of loaded fonts'
def draw(self, context):
fonts = bpy.data.fonts
layout = self.layout
for font in fonts:
layout.operator('vseqf.quicktitler_change_font', text=font.name).font = font.name
class VSEQFQuickTitlingMaterialMenu(bpy.types.Menu):
bl_idname = 'vseqf.quicktitler_materials_menu'
bl_label = 'List of loaded materials'
def draw(self, context):
materials = bpy.data.materials
layout = self.layout
for material in materials:
layout.operator('vseqf.quicktitler_change_material', text=material.name).material = material.name
class VSEQFQuickTitlingChangeFont(bpy.types.Operator):
bl_idname = 'vseqf.quicktitler_change_font'