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