change python scripts so modules which register with blender have a register() functi...
[blender.git] / release / scripts / op / 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20
21 import bpy
22
23 class SequencerCrossfadeSounds(bpy.types.Operator):
24     '''Do crossfading volume animation of two selected sound strips.'''
25
26     bl_idname = "sequencer.crossfade_sounds"
27     bl_label = "Crossfade sounds"
28     bl_register = True
29     bl_undo = True
30
31     def poll(self, context):
32         if context.scene and context.scene.sequence_editor and context.scene.sequence_editor.active_strip:
33             return context.scene.sequence_editor.active_strip.type == 'SOUND'
34         else:
35             return False
36
37     def execute(self, context):
38         seq1 = None
39         seq2 = None
40         for s in context.scene.sequence_editor.sequences:
41             if s.selected and s.type == 'SOUND':
42                 if seq1 == None:
43                     seq1 = s
44                 elif seq2 == None:
45                     seq2 = s
46                 else:
47                     seq2 = None
48                     break
49         if seq2 == None:
50             self.report({'ERROR'}, "Select 2 sound strips.")
51             return {'CANCELLED'}
52         if seq1.start_frame_final > seq2.start_frame_final:
53             s = seq1
54             seq1 = seq2
55             seq2 = s
56         if seq1.end_frame_final > seq2.start_frame_final:
57             tempcfra = context.scene.current_frame
58             context.scene.current_frame = seq2.start_frame_final
59             seq1.keyframe_insert('volume')
60             context.scene.current_frame = seq1.end_frame_final
61             seq1.volume = 0
62             seq1.keyframe_insert('volume')
63             seq2.keyframe_insert('volume')
64             context.scene.current_frame = seq2.start_frame_final
65             seq2.volume = 0
66             seq2.keyframe_insert('volume')
67             context.scene.current_frame = tempcfra
68             return {'FINISHED'}
69         else:
70             self.report({'ERROR'}, "The selected strips don't overlap.")
71             return {'CANCELLED'}
72
73
74 def register():
75     bpy.types.register(SequencerCrossfadeSounds)
76
77 def unregister():
78     bpy.types.unregister(SequencerCrossfadeSounds)
79
80 if __name__ == "__main__":
81     bpy.ops.sequencer.crossfade_sounds()