Small updates on pinkified theme for some object types, background gradient and other...
[blender-addons-contrib.git] / sequencer_jumptocut.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19
20 bl_info = {
21     "name": "Jump to Cut",
22     "author": "Carlos Padial",
23     "version": (5, 0, 2),
24     "blender": (2, 63, 0),
25     "api": 44539,
26     "category": "Sequencer",
27     "location": "Sequencer > UI > Jump to Cut",
28     "description": "Tool collection to help speed up editting and grade videos with blender",
29     "warning": "",
30     "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Sequencer/Jump_to_cut",
31     "tracker_url": "https://projects.blender.org/tracker/index.php?func=detail&aid=24279",}
32
33 #
34
35 #
36 #-----------------------------------------------------------------------------------------------------
37 import bpy
38
39 class Jumptocut(bpy.types.Panel):
40     bl_space_type = "SEQUENCE_EDITOR"
41     bl_region_type = "UI"
42     bl_label = "Jump to Cut"  
43
44     def draw_header(self, context):
45         layout = self.layout
46         layout.label(text="", icon="NLA")
47     
48     def draw(self, context):
49         layout = self.layout
50        
51         row=layout.row()
52         split=row.split(percentage=0.5)
53         colL = split.column()
54         colR = split.column()
55         colL.operator("sequencer.jumpprev", icon="PLAY_REVERSE")
56         colR.operator("sequencer.jumpnext", icon='PLAY')
57
58         row=layout.row()
59         split=row.split()
60         colL = split.column()
61         colR = split.column()
62         colL.operator("sequencer.markprev", icon="MARKER_HLT")
63         colR.operator("sequencer.marknext", icon='MARKER_HLT')
64         
65         row=layout.row()
66         split=row.split()
67         colL1 = split.column()
68         colL2 = split.column()
69         colL1.operator("sequencer.sourcein", icon="REW")
70         colL2.operator("sequencer.sourceout", icon='FF')
71  
72         
73         row=layout.row()
74         split=row.split()
75         colR1 = split.column()
76         colR1.operator("sequencer.setinout", icon="ARROW_LEFTRIGHT")
77         row=layout.row()
78         split=row.split(percentage=0.5)
79         colR1 = split.column()
80         colR1.operator("sequencer.triminout", icon="FULLSCREEN_EXIT") 
81         colR2 = split.column()
82         colR2.operator("sequencer.setstartend", icon="SETTINGS")
83
84         row=layout.row()
85         split=row.split()
86         colR1 = split.column()
87         colR2 = split.column()
88         colR1.operator("sequencer.metacopy", icon="COPYDOWN")
89         colR2.operator("sequencer.metapaste", icon='PASTEDOWN')
90         
91 #-----------------------------------------------------------------------------------------------------
92
93 class OBJECT_OT_Setinout(bpy.types.Operator):  
94     bl_label = "Mark in & out to active strip"
95     bl_idname = "sequencer.setinout"
96     bl_description = "set IN and OUT markers to the active strip limits"
97         
98     def invoke(self, context, event):
99         scene=bpy.context.scene
100         markers=scene.timeline_markers
101         seq=scene.sequence_editor
102         if seq:
103             strip= seq.active_strip
104             if strip != None:
105                 sin = strip.frame_start + strip.frame_offset_start
106                 sout = sin + strip.frame_final_duration 
107                 if "IN" not in markers:
108                     mark=markers.new(name="IN")
109                     mark.frame=sin
110                 else:
111                     mark=markers["IN"]
112                     mark.frame=sin
113                 if "OUT" not in markers:
114                     mark= markers.new(name="OUT")
115                     mark.frame=sout
116                 else:
117                     mark=markers["OUT"]
118                     mark.frame=sout 
119         return {'FINISHED'}
120     
121
122 def triminout(strip,sin,sout):
123     start = strip.frame_start+strip.frame_offset_start 
124     end = start+strip.frame_final_duration
125     if end > sin:
126         if start < sin:
127             strip.select_right_handle = False            
128             strip.select_left_handle = True
129             bpy.ops.sequencer.snap(frame=sin)
130             strip.select_left_handle = False
131     if start < sout:
132         if end > sout:
133             strip.select_left_handle = False            
134             strip.select_right_handle = True
135             bpy.ops.sequencer.snap(frame=sout)
136             strip.select_right_handle = False    
137     return {'FINISHED'}
138
139
140 class OBJECT_OT_Triminout(bpy.types.Operator):  
141     bl_label = "Trim to in & out"
142     bl_idname = "sequencer.triminout"
143     bl_description = "trim the selected strip to IN and OUT markers (if exists)"
144         
145     def invoke(self, context, event):
146         scene=bpy.context.scene
147         markers=scene.timeline_markers
148         seq=scene.sequence_editor
149         if seq:
150             strip= seq.active_strip
151             if strip != None:
152                 if "IN" and "OUT" in markers:
153                     sin=markers["IN"].frame
154                     sout=markers["OUT"].frame
155                     triminout(strip,sin,sout)
156                 else:
157                     self.report({'WARNING'}, "there is no IN and OUT")
158             bpy.ops.sequencer.reload()
159         return {'FINISHED'}
160
161 def searchprev(j, list):
162     list.sort()
163     list.reverse()
164     for i in list:
165         if i < j:
166             result = i
167             break 
168     else: result = j
169     return result
170
171 def searchnext(j, list): 
172     list.sort()
173     for i in list:
174         if i > j:
175             result = i
176             break
177     else: result = j
178     return result  
179
180 def geteditpoints(seq):
181     #this create a list of editpoints including strips from
182     # inside metastrips. It reads only 1 level into the metastrip
183     editpoints = []
184     cliplist = []
185     metalist = []
186     if seq:
187         for i in seq.sequences:
188             if i.type == 'META':
189                 metalist.append(i)
190                 start = i.frame_start + i.frame_offset_start
191                 end = start + i.frame_final_duration
192                 editpoints.append(start)
193                 editpoints.append(end)
194             else:
195                 cliplist.append(i)
196         for i in metalist:
197             for j in i.sequences:
198                 cliplist.append(j)  
199         for i in cliplist:
200             start = i.frame_start + i.frame_offset_start
201             end = start + i.frame_final_duration
202             editpoints.append(start)
203             editpoints.append(end)
204             #print(start," ",end)
205     return editpoints
206
207 #JUMP    
208 class OBJECT_OT_Jumpprev(bpy.types.Operator):  #Operator jump previous edit point
209     bl_label = "Cut previous"
210     bl_idname = "sequencer.jumpprev"
211     bl_description = "jump to previous edit point"
212     
213     editpoints = []
214         
215     def invoke(self, context, event):
216         scene=bpy.context.scene
217         seq=scene.sequence_editor
218         editpoints = geteditpoints(seq)
219         bpy.context.scene.frame_current = searchprev(scene.frame_current, editpoints) 
220         return {'FINISHED'}   
221            
222 class OBJECT_OT_Jumpnext(bpy.types.Operator):  #Operator jump next edit point
223     bl_label = "Cut next"
224     bl_idname = "sequencer.jumpnext"
225     bl_description = "jump to next edit point"
226     
227     def invoke(self, context, event):
228         scene=bpy.context.scene
229         seq=scene.sequence_editor
230         editpoints = geteditpoints(seq)
231         bpy.context.scene.frame_current = searchnext(scene.frame_current, editpoints)
232         last = 0
233         for i in editpoints:
234             if i > last: last = i
235         if bpy.context.scene.frame_current == last:
236             bpy.context.scene.frame_current = last-1
237             self.report({'INFO'},'Last Frame')
238         return {'FINISHED'}
239  
240 # MARKER 
241 class OBJECT_OT_Markerprev(bpy.types.Operator): 
242     bl_label = "Marker previous"
243     bl_idname = "sequencer.markprev"
244     bl_description = "jump to previous marker"
245         
246     def invoke(self, context, event):
247         markerlist = []
248         scene= bpy.context.scene
249         markers = scene.timeline_markers
250         for i in markers: markerlist.append(i.frame)
251         bpy.context.scene.frame_current = searchprev(scene.frame_current, markerlist)
252         return {'FINISHED'}
253     
254 class OBJECT_OT_Markernext(bpy.types.Operator):  
255     bl_label = "Marker next"
256     bl_idname = "sequencer.marknext"
257     bl_description = "jump to next marker"
258         
259     def invoke(self, context, event):
260         markerlist = []
261         scene= bpy.context.scene
262         markers = scene.timeline_markers
263         for i in markers: markerlist.append(i.frame)
264         bpy.context.scene.frame_current = searchnext(scene.frame_current, markerlist)
265         return {'FINISHED'}
266
267 # SOURCE IN OUT
268               
269 class OBJECT_OT_Sourcein(bpy.types.Operator):  #Operator source in
270     bl_label = "Source IN"
271     bl_idname = "sequencer.sourcein"
272     bl_description = "add a marker named IN"
273     
274     def invoke(self, context, event):
275         scene=bpy.context.scene
276         seq = scene.sequence_editor
277         markers=scene.timeline_markers
278         if "OUT" in markers:
279             sout=markers["OUT"]
280             if scene.frame_current <= sout.frame:
281                 if "IN" not in markers:
282                     sin=markers.new(name="IN")
283                     sin.frame=scene.frame_current
284                 else:
285                     sin=markers["IN"]
286                     sin.frame=scene.frame_current
287             #trying to set in after out
288             else:  
289                 if "IN" not in markers:
290                     sin=markers.new(name="IN")
291                     sin.frame=sout.frame
292                 else:
293                     sin=markers["IN"]
294                     sin.frame=sout.frame
295                 self.report({'WARNING'},'IN after OUT')
296         else:
297             if "IN" not in markers:
298                 sin=markers.new(name="IN")
299                 sin.frame=scene.frame_current
300             else:
301                 sin=markers["IN"]
302                 sin.frame=scene.frame_current
303         if seq:
304             bpy.ops.sequencer.reload()
305         return {'FINISHED'}
306
307 class OBJECT_OT_Sourceout(bpy.types.Operator):  #Operator source out
308     bl_label = "Source OUT"
309     bl_idname = "sequencer.sourceout"
310     bl_description = "add a marker named OUT"
311     
312     def invoke(self, context, event):
313         scene=bpy.context.scene
314         seq = scene.sequence_editor
315         markers=scene.timeline_markers
316         if "IN" in markers:
317             sin=markers["IN"]
318             if scene.frame_current >= sin.frame:
319                 if "OUT" not in markers:
320                     sout= markers.new(name="OUT")
321                     sout.frame=scene.frame_current
322                 else:
323                     sout=markers["OUT"]
324                     sout.frame=scene.frame_current 
325             #trying to set out before in 
326             else:
327                 if "OUT" not in markers:
328                     sout= markers.new(name="OUT")
329                     sout.frame = sin.frame
330                 else:
331                     sout=markers["OUT"]
332                     sout.frame = sin.frame 
333                 self.report({'WARNING'}, "OUT before IN")
334         else:
335             sout= markers.new(name="OUT")
336             sout.frame=scene.frame_current
337         if seq:
338             bpy.ops.sequencer.reload()
339         return {'FINISHED'}
340
341
342
343 class OBJECT_OT_Setstartend(bpy.types.Operator):  #Operator set start & end
344     bl_label = "set Start & End"
345     bl_idname = "sequencer.setstartend"
346     bl_description = "set Start = In and End = Out"
347     
348     def invoke(self, context, event):
349         scene=bpy.context.scene
350         seq = scene.sequence_editor
351         markers=scene.timeline_markers
352         if seq:
353             if "IN" and "OUT" in markers:
354                 sin=markers["IN"]
355                 sout=markers["OUT"]
356                 scene.frame_start = sin.frame
357                 scene.frame_end = sout.frame
358                 print("change")
359             else:
360                 self.report({'WARNING'}, "there is no IN and OUT")
361             bpy.ops.sequencer.reload()
362         return {'FINISHED'}
363
364     
365 # COPY PASTE
366
367 class OBJECT_OT_Metacopy(bpy.types.Operator):  #Operator copy source in/out
368     bl_label = "Trim & Meta-Copy"
369     bl_idname = "sequencer.metacopy"
370     bl_description = "make meta from selected strips, trim it to in/out (if available) and copy it to clipboard"
371     
372     def invoke(self, context, event):
373         # rehacer
374         scene=bpy.context.scene
375         seq = scene.sequence_editor
376         markers=scene.timeline_markers
377         strip1= seq.active_strip
378         if strip1 != None:
379             if "IN" and "OUT" in markers:
380                 sin=markers["IN"].frame
381                 sout=markers["OUT"].frame
382                 bpy.ops.sequencer.meta_make()
383                 strip2= seq.active_strip
384                 triminout(strip2,sin,sout)
385                 bpy.ops.sequencer.copy()
386                 bpy.ops.sequencer.meta_separate()
387                 self.report({'INFO'}, "META has been trimed and copied")              
388             else:
389                 bpy.ops.sequencer.meta_make()
390                 bpy.ops.sequencer.copy()
391                 bpy.ops.sequencer.meta_separate()
392                 self.report({'WARNING'}, "No In & Out!! META has been copied")
393         else:
394             self.report({'ERROR'}, "No strip selected")
395         return {'FINISHED'}
396         
397 class OBJECT_OT_Metapaste(bpy.types.Operator):  #Operator paste source in/out
398     bl_label = "Paste in current Frame"
399     bl_idname = "sequencer.metapaste"
400     bl_description = "paste source from clipboard to current frame"
401     
402     def invoke(self, context, event):
403         # rehacer
404         scene=bpy.context.scene
405         bpy.ops.sequencer.paste()
406         bpy.ops.sequencer.snap(frame=scene.frame_current)
407         return {'FINISHED'}
408
409 # Registering / Unregister
410  
411 def register():
412     bpy.utils.register_class(Jumptocut)
413     bpy.utils.register_class(OBJECT_OT_Jumpprev)
414     bpy.utils.register_class(OBJECT_OT_Jumpnext)
415     bpy.utils.register_class(OBJECT_OT_Markerprev)
416     bpy.utils.register_class(OBJECT_OT_Markernext)    
417     bpy.utils.register_class(OBJECT_OT_Sourcein)
418     bpy.utils.register_class(OBJECT_OT_Sourceout)
419     bpy.utils.register_class(OBJECT_OT_Metacopy)
420     bpy.utils.register_class(OBJECT_OT_Metapaste)
421     bpy.utils.register_class(OBJECT_OT_Triminout)
422     bpy.utils.register_class(OBJECT_OT_Setinout)
423     bpy.utils.register_class(OBJECT_OT_Setstartend)
424     
425 def unregister():
426     bpy.utils.unregister_class(Jumptocut)
427     bpy.utils.unregister_class(OBJECT_OT_Jumpprev)
428     bpy.utils.unregister_class(OBJECT_OT_Jumpnext)
429     bpy.utils.unregister_class(OBJECT_OT_Markerprev)
430     bpy.utils.unregister_class(OBJECT_OT_Markernext)      
431     bpy.utils.unregister_class(OBJECT_OT_Sourcein)
432     bpy.utils.unregister_class(OBJECT_OT_Sourceout)
433     bpy.utils.unregister_class(OBJECT_OT_Metacopy)
434     bpy.utils.unregister_class(OBJECT_OT_Metapaste)
435     bpy.utils.unregister_class(OBJECT_OT_Triminout)
436     bpy.utils.unregister_class(OBJECT_OT_Setinout)
437     bpy.utils.unregister_class(OBJECT_OT_Setstartend)
438 if __name__ == "__main__":
439     register()