== Sequencer ==
[blender-staging.git] / release / scripts / ui / space_sequencer.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22
23 def act_strip(context):
24     try:
25         return context.scene.sequence_editor.active_strip
26     except AttributeError:
27         return None
28
29
30 class SEQUENCER_HT_header(bpy.types.Header):
31     bl_space_type = 'SEQUENCE_EDITOR'
32
33     def draw(self, context):
34         layout = self.layout
35
36         st = context.space_data
37
38         row = layout.row(align=True)
39         row.template_header()
40
41         if context.area.show_menus:
42             sub = row.row(align=True)
43             sub.menu("SEQUENCER_MT_view")
44
45             row.separator()
46
47             if st.display_mode == 'SEQUENCER':
48                 sub.menu("SEQUENCER_MT_select")
49                 sub.menu("SEQUENCER_MT_marker")
50                 sub.menu("SEQUENCER_MT_add")
51                 sub.menu("SEQUENCER_MT_strip")
52
53         layout.prop(st, "display_mode", text="")
54
55         if st.display_mode == 'SEQUENCER':
56             layout.separator()
57             layout.operator("sequencer.refresh_all")
58         else:
59             layout.prop(st, "display_channel", text="Channel")
60
61
62 class SEQUENCER_MT_view(bpy.types.Menu):
63     bl_label = "View"
64
65     def draw(self, context):
66         layout = self.layout
67
68         st = context.space_data
69
70         layout.column()
71
72         """
73     uiBlock *block= uiBeginBlock(C, ar, "seq_viewmenu", UI_EMBOSSP);
74     short yco= 0, menuwidth=120;
75
76     if (sseq->mainb == SEQ_DRAW_SEQUENCE) {
77         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
78                  "Play Back Animation "
79                  "in all Sequence Areas|Alt A", 0, yco-=20,
80                  menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
81     }
82     else {
83         uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL,
84                  "Grease Pencil...", 0, yco-=20,
85                  menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
86         uiDefMenuSep(block);
87
88         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
89                  "Play Back Animation "
90                  "in this window|Alt A", 0, yco-=20,
91                  menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
92     }
93     uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
94              "Play Back Animation in all "
95              "3D Views and Sequence Areas|Alt Shift A",
96              0, yco-=20,
97              menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
98
99         """
100         layout.separator()
101         layout.operator("sequencer.view_all")
102         layout.operator("sequencer.view_selected")
103         layout.separator()
104         layout.operator("screen.screen_full_area", text="Toggle Full Screen")
105         """
106
107
108     /* Lock Time */
109     uiDefIconTextBut(block, BUTM, 1, (v2d->flag & V2D_VIEWSYNC_SCREEN_TIME)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT,
110             "Lock Time to Other Windows|", 0, yco-=20,
111             menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
112
113     /* Draw time or frames.*/
114     uiDefMenuSep(block);
115         """
116
117         layout.prop(st, "draw_frames")
118         layout.prop(st, "show_cframe_indicator")
119         if st.display_mode == 'IMAGE':
120             layout.prop(st, "draw_safe_margin")
121         if st.display_mode == 'WAVEFORM':
122             layout.prop(st, "separate_color_preview")
123
124         """
125     if(!sa->full) uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0,0, "");
126     else uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
127
128         """
129
130
131 class SEQUENCER_MT_select(bpy.types.Menu):
132     bl_label = "Select"
133
134     def draw(self, context):
135         layout = self.layout
136
137         layout.column()
138         layout.operator("sequencer.select_active_side", text="Strips to the Left").side = 'LEFT'
139         layout.operator("sequencer.select_active_side", text="Strips to the Right").side = 'RIGHT'
140         layout.separator()
141         layout.operator("sequencer.select_handles", text="Surrounding Handles").side = 'BOTH'
142         layout.operator("sequencer.select_handles", text="Left Handle").side = 'LEFT'
143         layout.operator("sequencer.select_handles", text="Right Handle").side = 'RIGHT'
144         layout.separator()
145         layout.operator("sequencer.select_linked")
146         layout.operator("sequencer.select_all_toggle")
147         layout.operator("sequencer.select_inverse")
148
149
150 class SEQUENCER_MT_marker(bpy.types.Menu):
151     bl_label = "Marker (TODO)"
152
153     def draw(self, context):
154         layout = self.layout
155
156         layout.column()
157         layout.operator("marker.add", text="Add Marker")
158         layout.operator("marker.duplicate", text="Duplicate Marker")
159         layout.operator("marker.move", text="Grab/Move Marker")
160         layout.operator("marker.delete", text="Delete Marker")
161         layout.separator()
162         layout.label(text="ToDo: Name Marker")
163
164         #layout.operator("sequencer.sound_strip_add", text="Transform Markers") # toggle, will be rna - (sseq->flag & SEQ_MARKER_TRANS)
165
166
167 class SEQUENCER_MT_add(bpy.types.Menu):
168     bl_label = "Add"
169
170     def draw(self, context):
171         layout = self.layout
172         layout.operator_context = 'INVOKE_REGION_WIN'
173
174         layout.column()
175         layout.operator("sequencer.scene_strip_add", text="Scene")
176         layout.operator("sequencer.movie_strip_add", text="Movie")
177         layout.operator("sequencer.image_strip_add", text="Image")
178         layout.operator("sequencer.sound_strip_add", text="Sound")
179
180         layout.menu("SEQUENCER_MT_add_effect")
181
182
183 class SEQUENCER_MT_add_effect(bpy.types.Menu):
184     bl_label = "Effect Strip..."
185
186     def draw(self, context):
187         layout = self.layout
188         layout.operator_context = 'INVOKE_REGION_WIN'
189
190         layout.column()
191         layout.operator("sequencer.effect_strip_add", text="Add").type = 'ADD'
192         layout.operator("sequencer.effect_strip_add", text="Subtract").type = 'SUBTRACT'
193         layout.operator("sequencer.effect_strip_add", text="Alpha Over").type = 'ALPHA_OVER'
194         layout.operator("sequencer.effect_strip_add", text="Alpha Under").type = 'ALPHA_UNDER'
195         layout.operator("sequencer.effect_strip_add", text="Gamma Cross").type = 'GAMMA_CROSS'
196         layout.operator("sequencer.effect_strip_add", text="Multiply").type = 'MULTIPLY'
197         layout.operator("sequencer.effect_strip_add", text="Over Drop").type = 'OVER_DROP'
198         layout.operator("sequencer.effect_strip_add", text="Plugin").type = 'PLUGIN'
199         layout.operator("sequencer.effect_strip_add", text="Wipe").type = 'WIPE'
200         layout.operator("sequencer.effect_strip_add", text="Glow").type = 'GLOW'
201         layout.operator("sequencer.effect_strip_add", text="Transform").type = 'TRANSFORM'
202         layout.operator("sequencer.effect_strip_add", text="Color").type = 'COLOR'
203         layout.operator("sequencer.effect_strip_add", text="Speed Control").type = 'SPEED'
204
205
206 class SEQUENCER_MT_strip(bpy.types.Menu):
207     bl_label = "Strip"
208
209     def draw(self, context):
210         layout = self.layout
211
212         layout.operator_context = 'INVOKE_REGION_WIN'
213
214         layout.column()
215         layout.operator("tfm.transform", text="Grab/Move").mode = 'TRANSLATION'
216         layout.operator("tfm.transform", text="Grab/Extend from frame").mode = 'TIME_EXTEND'
217         #  uiItemO(layout, NULL, 0, "sequencer.strip_snap"); // TODO - add this operator
218         layout.separator()
219
220         layout.operator("sequencer.cut", text="Cut (hard) at frame").type = 'HARD'
221         layout.operator("sequencer.cut", text="Cut (soft) at frame").type = 'SOFT'
222         layout.operator("sequencer.images_separate")
223         layout.separator()
224
225         layout.operator("sequencer.duplicate")
226         layout.operator("sequencer.delete")
227
228         strip = act_strip(context)
229
230         if strip:
231             stype = strip.type
232
233             if  stype == 'EFFECT':
234                 layout.separator()
235                 layout.operator("sequencer.effect_change")
236                 layout.operator("sequencer.effect_reassign_inputs")
237             elif stype == 'IMAGE':
238                 layout.separator()
239                 layout.operator("sequencer.image_change")
240                 layout.operator("sequencer.rendersize")
241             elif stype == 'SCENE':
242                 layout.separator()
243                 layout.operator("sequencer.scene_change", text="Change Scene")
244             elif stype == 'MOVIE':
245                 layout.separator()
246                 layout.operator("sequencer.movie_change")
247                 layout.operator("sequencer.rendersize")
248
249         layout.separator()
250
251         layout.operator("sequencer.meta_make")
252         layout.operator("sequencer.meta_separate")
253
254         #if (ed && (ed->metastack.first || (ed->act_seq && ed->act_seq->type == SEQ_META))) {
255         #       uiItemS(layout);
256         #       uiItemO(layout, NULL, 0, "sequencer.meta_toggle");
257         #}
258
259         layout.separator()
260         layout.operator("sequencer.reload")
261         layout.separator()
262         layout.operator("sequencer.lock")
263         layout.operator("sequencer.unlock")
264         layout.operator("sequencer.mute")
265         layout.operator("sequencer.unmute")
266
267         layout.operator("sequencer.mute", text="Mute Deselected Strips").unselected = True
268
269         layout.operator("sequencer.snap")
270
271         layout.operator("sequencer.swap_right")
272         layout.operator("sequencer.swap_left")
273
274
275 class SequencerButtonsPanel(bpy.types.Panel):
276     bl_space_type = 'SEQUENCE_EDITOR'
277     bl_region_type = 'UI'
278
279     def poll(self, context):
280         return (context.space_data.display_mode == 'SEQUENCER') and (act_strip(context) is not None)
281
282
283 class SequencerButtonsPanel_Output(bpy.types.Panel):
284     bl_space_type = 'SEQUENCE_EDITOR'
285     bl_region_type = 'UI'
286
287     def poll(self, context):
288         return context.space_data.display_mode != 'SEQUENCER'
289
290
291 class SEQUENCER_PT_edit(SequencerButtonsPanel):
292     bl_label = "Edit Strip"
293
294     def draw(self, context):
295         layout = self.layout
296
297         strip = act_strip(context)
298
299         split = layout.split(percentage=0.3)
300         split.label(text="Name:")
301         split.prop(strip, "name", text="")
302
303         split = layout.split(percentage=0.3)
304         split.label(text="Type:")
305         split.prop(strip, "type", text="")
306
307         split = layout.split(percentage=0.3)
308         split.label(text="Blend:")
309         split.prop(strip, "blend_mode", text="")
310
311         row = layout.row()
312         if strip.mute == True:
313             row.prop(strip, "mute", toggle=True, icon='ICON_RESTRICT_VIEW_ON', text="")
314         elif strip.mute is False:
315             row.prop(strip, "mute", toggle=True, icon='ICON_RESTRICT_VIEW_OFF', text="")
316
317         sub = row.row()
318         sub.active = (not strip.mute)
319
320         sub.prop(strip, "blend_opacity", text="Opacity", slider=True)
321
322         row = layout.row()
323         row.prop(strip, "lock")
324         row.prop(strip, "frame_locked", text="Frame Lock")
325
326         col = layout.column()
327         col.enabled = not strip.lock
328         col.prop(strip, "channel")
329         col.prop(strip, "start_frame")
330         col.prop(strip, "length")
331
332         col = layout.column(align=True)
333         col.label(text="Offset:")
334         col.prop(strip, "start_offset", text="Start")
335         col.prop(strip, "end_offset", text="End")
336
337         col = layout.column(align=True)
338         col.label(text="Still:")
339         col.prop(strip, "start_still", text="Start")
340         col.prop(strip, "end_still", text="End")
341
342
343 class SEQUENCER_PT_effect(SequencerButtonsPanel):
344     bl_label = "Effect Strip"
345
346     def poll(self, context):
347         if context.space_data.display_mode != 'SEQUENCER':
348             return False
349
350         strip = act_strip(context)
351         if not strip:
352             return False
353
354         return strip.type in ('ADD','SUBTRACT','ALPHA_OVER','ALPHA_UNDER',
355                               'GAMMA_CROSS','MULTIPLY','OVER_DROP',
356                               'PLUGIN',
357                               'WIPE', 'GLOW', 'TRANSFORM', 'COLOR', 'SPEED')
358
359     def draw(self, context):
360         layout = self.layout
361
362         strip = act_strip(context)
363
364         if strip.type == 'COLOR':
365             layout.prop(strip, "color")
366
367         elif strip.type == 'WIPE':
368
369             col = layout.column()
370             col.prop(strip, "transition_type")
371             col.label(text="Direction:")
372             col.row().prop(strip, "direction", expand=True)
373
374             col = layout.column()
375             col.prop(strip, "blur_width", slider=True)
376             if strip.transition_type in ('SINGLE', 'DOUBLE'):
377                 col.prop(strip, "angle")
378
379         elif strip.type == 'GLOW':
380             flow = layout.column_flow()
381             flow.prop(strip, "threshold", slider=True)
382             flow.prop(strip, "clamp", slider=True)
383             flow.prop(strip, "boost_factor")
384             flow.prop(strip, "blur_distance")
385
386             row = layout.row()
387             row.prop(strip, "quality", slider=True)
388             row.prop(strip, "only_boost")
389
390         elif strip.type == 'SPEED':
391             layout.prop(strip, "global_speed")
392
393             flow = layout.column_flow()
394             flow.prop(strip, "curve_velocity")
395             flow.prop(strip, "curve_compress_y")
396             flow.prop(strip, "frame_blending")
397
398         elif strip.type == 'TRANSFORM':
399
400             col = layout.column()
401             col.prop(strip, "interpolation")
402             col.prop(strip, "translation_unit")
403
404             col = layout.column(align=True)
405             col.label(text="Position X:")
406             col.prop(strip, "translate_start_x", text="Start")
407             col.prop(strip, "translate_end_x", text="End")
408
409             col = layout.column(align=True)
410             col.label(text="Position Y:")
411             col.prop(strip, "translate_start_y", text="Start")
412             col.prop(strip, "translate_end_y", text="End")
413
414             layout.separator()
415
416             col = layout.column(align=True)
417             col.label(text="Scale X:")
418             col.prop(strip, "scale_start_x", text="Start")
419             col.prop(strip, "scale_end_x", text="End")
420
421             col = layout.column(align=True)
422             col.label(text="Scale Y:")
423             col.prop(strip, "scale_start_y", text="Start")
424             col.prop(strip, "scale_end_y", text="End")
425
426             layout.separator()
427
428             col = layout.column(align=True)
429             col.label(text="Rotation:")
430             col.prop(strip, "rotation_start", text="Start")
431             col.prop(strip, "rotation_end", text="End")
432
433         col = layout.column(align=True)
434         if strip.type == 'SPEED':
435             col.prop(strip, "speed_fader", text="Speed fader")
436         else:
437             col.prop(strip, "use_effect_default_fade", "Default fade")
438             if not strip.use_effect_default_fade:
439                 col.prop(strip, "effect_fader", text="Effect fader")
440
441
442 class SEQUENCER_PT_input(SequencerButtonsPanel):
443     bl_label = "Strip Input"
444
445     def poll(self, context):
446         if context.space_data.display_mode != 'SEQUENCER':
447             return False
448
449         strip = act_strip(context)
450         if not strip:
451             return False
452
453         return strip.type in ('MOVIE', 'IMAGE')
454
455     def draw(self, context):
456         layout = self.layout
457
458         strip = act_strip(context)
459
460         split = layout.split(percentage=0.2)
461         col = split.column()
462         col.label(text="Path:")
463         col = split.column()
464         col.prop(strip, "directory", text="")
465
466         # Current element for the filename
467
468         elem = strip.getStripElem(context.scene.current_frame)
469         if elem:
470             split = layout.split(percentage=0.2)
471             col = split.column()
472             col.label(text="File:")
473             col = split.column()
474             col.prop(elem, "filename", text="") # strip.elements[0] could be a fallback
475
476         layout.prop(strip, "use_translation", text="Image Offset:")
477         if strip.transform:
478             col = layout.column(align=True)
479             col.active = strip.use_translation
480             col.prop(strip.transform, "offset_x", text="X")
481             col.prop(strip.transform, "offset_y", text="Y")
482
483         layout.prop(strip, "use_crop", text="Image Crop:")
484         if strip.crop:
485             col = layout.column(align=True)
486             col.active = strip.use_crop
487             col.prop(strip.crop, "top")
488             col.prop(strip.crop, "left")
489             col.prop(strip.crop, "bottom")
490             col.prop(strip.crop, "right")
491
492         col = layout.column(align=True)
493         col.label(text="Trim Duration:")
494         col.prop(strip, "animation_start_offset", text="Start")
495         col.prop(strip, "animation_end_offset", text="End")
496
497
498 class SEQUENCER_PT_sound(SequencerButtonsPanel):
499     bl_label = "Sound"
500
501     def poll(self, context):
502         if context.space_data.display_mode != 'SEQUENCER':
503             return False
504
505         strip = act_strip(context)
506         if not strip:
507             return False
508
509         return (strip.type == 'SOUND')
510
511     def draw(self, context):
512         layout = self.layout
513
514         strip = act_strip(context)
515
516         layout.template_ID(strip, "sound", open="sound.open")
517
518         layout.separator()
519         layout.prop(strip.sound, "filename", text="")
520
521         row = layout.row()
522         if strip.sound.packed_file:
523             row.operator("sound.unpack", icon='ICON_PACKAGE', text="Unpack")
524         else:
525             row.operator("sound.pack", icon='ICON_UGLYPACKAGE', text="Pack")
526
527         row.prop(strip.sound, "caching")
528
529         layout.prop(strip, "volume")
530
531
532 class SEQUENCER_PT_scene(SequencerButtonsPanel):
533     bl_label = "Scene"
534
535     def poll(self, context):
536         if context.space_data.display_mode != 'SEQUENCER':
537             return False
538
539         strip = act_strip(context)
540         if not strip:
541             return False
542
543         return (strip.type == 'SCENE')
544
545     def draw(self, context):
546         layout = self.layout
547
548         strip = act_strip(context)
549
550         layout.template_ID(strip, "scene")
551
552
553 class SEQUENCER_PT_filter(SequencerButtonsPanel):
554     bl_label = "Filter"
555
556     def poll(self, context):
557         if context.space_data.display_mode != 'SEQUENCER':
558             return False
559
560         strip = act_strip(context)
561         if not strip:
562             return False
563
564         return strip.type in ('MOVIE', 'IMAGE', 'SCENE', 'META')
565
566     def draw(self, context):
567         layout = self.layout
568
569         strip = act_strip(context)
570
571         col = layout.column()
572         col.label(text="Video:")
573         col.prop(strip, "strobe")
574         col.prop(strip, "de_interlace")
575
576         col = layout.column()
577         col.label(text="Colors:")
578         col.prop(strip, "multiply_colors", text="Multiply")
579         col.prop(strip, "premultiply")
580         col.prop(strip, "convert_float")
581
582         col = layout.column()
583         col.label(text="Flip:")
584         col.prop(strip, "flip_x", text="X")
585         col.prop(strip, "flip_y", text="Y")
586         col.prop(strip, "reverse_frames", text="Backwards")
587
588         layout.prop(strip, "use_color_balance")
589         if strip.color_balance: # TODO - need to add this somehow
590             row = layout.row()
591             row.active = strip.use_color_balance
592             col = row.column()
593             col.prop(strip.color_balance, "lift")
594             col.prop(strip.color_balance, "inverse_lift", text="Inverse")
595             col = row.column()
596             col.prop(strip.color_balance, "gamma")
597             col.prop(strip.color_balance, "inverse_gamma", text="Inverse")
598             col = row.column()
599             col.prop(strip.color_balance, "gain")
600             col.prop(strip.color_balance, "inverse_gain", text="Inverse")
601
602
603 class SEQUENCER_PT_proxy(SequencerButtonsPanel):
604     bl_label = "Proxy"
605
606     def poll(self, context):
607         if context.space_data.display_mode != 'SEQUENCER':
608             return False
609
610         strip = act_strip(context)
611         if not strip:
612             return False
613
614         return strip.type in ('MOVIE', 'IMAGE', 'SCENE', 'META')
615
616     def draw_header(self, context):
617         strip = act_strip(context)
618
619         self.layout.prop(strip, "use_proxy", text="")
620
621     def draw(self, context):
622         layout = self.layout
623
624         strip = act_strip(context)
625
626         flow = layout.column_flow()
627         flow.prop(strip, "proxy_custom_directory")
628         if strip.proxy: # TODO - need to add this somehow
629             flow.prop(strip.proxy, "directory")
630             flow.prop(strip.proxy, "file")
631
632
633 class SEQUENCER_PT_view(SequencerButtonsPanel_Output):
634     bl_label = "View Settings"
635
636     def draw(self, context):
637         layout = self.layout
638
639         st = context.space_data
640
641         col = layout.column()
642         col.prop(st, "draw_overexposed") # text="Zebra"
643         col.prop(st, "draw_safe_margin")
644
645 bpy.types.register(SEQUENCER_HT_header) # header/menu classes
646 bpy.types.register(SEQUENCER_MT_view)
647 bpy.types.register(SEQUENCER_MT_select)
648 bpy.types.register(SEQUENCER_MT_marker)
649 bpy.types.register(SEQUENCER_MT_add)
650 bpy.types.register(SEQUENCER_MT_add_effect)
651 bpy.types.register(SEQUENCER_MT_strip)
652
653 bpy.types.register(SEQUENCER_PT_edit) # sequencer panels
654 bpy.types.register(SEQUENCER_PT_effect)
655 bpy.types.register(SEQUENCER_PT_input)
656 bpy.types.register(SEQUENCER_PT_sound)
657 bpy.types.register(SEQUENCER_PT_scene)
658 bpy.types.register(SEQUENCER_PT_filter)
659 bpy.types.register(SEQUENCER_PT_proxy)
660
661 bpy.types.register(SEQUENCER_PT_view) # view panels