Merging r43130 through r43500 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / space_sequencer / sequencer_ops.c
1
2 /*
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  *
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file blender/editors/space_sequencer/sequencer_ops.c
30  *  \ingroup spseq
31  */
32
33
34 #include <stdlib.h>
35 #include <math.h>
36
37
38 #include "DNA_space_types.h"
39
40 #include "BLI_math.h"
41 #include "BLI_blenlib.h"
42
43
44
45 #include "WM_api.h"
46 #include "WM_types.h"
47
48 #include "ED_transform.h" /* transform keymap */
49
50 #include "sequencer_intern.h"
51
52
53 /* ************************** registration **********************************/
54
55
56 void sequencer_operatortypes(void)
57 {
58         /* sequencer_edit.c */
59         WM_operatortype_append(SEQUENCER_OT_cut);
60         WM_operatortype_append(SEQUENCER_OT_mute);
61         WM_operatortype_append(SEQUENCER_OT_unmute);
62         WM_operatortype_append(SEQUENCER_OT_lock);
63         WM_operatortype_append(SEQUENCER_OT_unlock);
64         WM_operatortype_append(SEQUENCER_OT_reload);
65         WM_operatortype_append(SEQUENCER_OT_refresh_all);
66         WM_operatortype_append(SEQUENCER_OT_reassign_inputs);
67         WM_operatortype_append(SEQUENCER_OT_swap_inputs);
68         WM_operatortype_append(SEQUENCER_OT_duplicate);
69         WM_operatortype_append(SEQUENCER_OT_delete);
70         WM_operatortype_append(SEQUENCER_OT_offset_clear);
71         WM_operatortype_append(SEQUENCER_OT_images_separate);
72         WM_operatortype_append(SEQUENCER_OT_meta_toggle);
73         WM_operatortype_append(SEQUENCER_OT_meta_make);
74         WM_operatortype_append(SEQUENCER_OT_meta_separate);
75         WM_operatortype_append(SEQUENCER_OT_snap);
76         WM_operatortype_append(SEQUENCER_OT_next_edit);
77         WM_operatortype_append(SEQUENCER_OT_previous_edit);
78         WM_operatortype_append(SEQUENCER_OT_swap);
79         WM_operatortype_append(SEQUENCER_OT_swap_data);
80         WM_operatortype_append(SEQUENCER_OT_rendersize);
81
82         WM_operatortype_append(SEQUENCER_OT_view_all);
83         WM_operatortype_append(SEQUENCER_OT_view_selected);
84         WM_operatortype_append(SEQUENCER_OT_view_all_preview);
85         WM_operatortype_append(SEQUENCER_OT_view_toggle);
86         WM_operatortype_append(SEQUENCER_OT_view_zoom_ratio);
87         WM_operatortype_append(SEQUENCER_OT_view_ghost_border);
88
89         WM_operatortype_append(SEQUENCER_OT_rebuild_proxy);
90         WM_operatortype_append(SEQUENCER_OT_change_effect_input);
91         WM_operatortype_append(SEQUENCER_OT_change_effect_type);
92         WM_operatortype_append(SEQUENCER_OT_change_path);
93
94         /* sequencer_select.c */
95         WM_operatortype_append(SEQUENCER_OT_select_all);
96         WM_operatortype_append(SEQUENCER_OT_select);
97         WM_operatortype_append(SEQUENCER_OT_select_more);
98         WM_operatortype_append(SEQUENCER_OT_select_less);
99         WM_operatortype_append(SEQUENCER_OT_select_linked_pick);
100         WM_operatortype_append(SEQUENCER_OT_select_linked);
101         WM_operatortype_append(SEQUENCER_OT_select_handles);
102         WM_operatortype_append(SEQUENCER_OT_select_active_side);
103         WM_operatortype_append(SEQUENCER_OT_select_border);
104         WM_operatortype_append(SEQUENCER_OT_select_grouped);
105
106         /* sequencer_add.c */
107         WM_operatortype_append(SEQUENCER_OT_scene_strip_add);
108         WM_operatortype_append(SEQUENCER_OT_movie_strip_add);
109         WM_operatortype_append(SEQUENCER_OT_sound_strip_add);
110         WM_operatortype_append(SEQUENCER_OT_image_strip_add);
111         WM_operatortype_append(SEQUENCER_OT_effect_strip_add);
112         WM_operatortype_append(SEQUENCER_OT_properties);
113
114         WM_operatortype_append(SEQUENCER_OT_copy);
115         WM_operatortype_append(SEQUENCER_OT_paste);
116 }
117
118
119 void sequencer_keymap(wmKeyConfig *keyconf)
120 {
121         wmKeyMap *keymap= WM_keymap_find(keyconf, "SequencerCommon", SPACE_SEQ, 0);
122         wmKeyMapItem *kmi;
123
124         kmi= WM_keymap_add_item(keymap, "WM_OT_context_toggle", OKEY, KM_PRESS, KM_SHIFT, 0);
125         RNA_string_set(kmi->ptr, "data_path", "scene.sequence_editor.show_overlay");
126
127         /* operators common to sequence and preview view */
128         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_toggle", TABKEY, KM_PRESS, KM_CTRL, 0);
129
130         /* operators for sequence */
131         keymap= WM_keymap_find(keyconf, "Sequencer", SPACE_SEQ, 0);
132         
133         WM_keymap_add_item(keymap, "SEQUENCER_OT_properties", NKEY, KM_PRESS, 0, 0);
134         
135         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_all", AKEY, KM_PRESS, 0, 0);
136                 RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
137         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
138                 RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
139
140         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, 0, 0);
141                 RNA_enum_set(kmi->ptr, "type", SEQ_CUT_SOFT);
142         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, KM_SHIFT, 0);
143                 RNA_enum_set(kmi->ptr, "type", SEQ_CUT_HARD);
144         
145         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_mute", HKEY, KM_PRESS, 0, 0);
146                 RNA_boolean_set(kmi->ptr, "unselected", FALSE);
147         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_mute", HKEY, KM_PRESS, KM_SHIFT, 0);
148                 RNA_boolean_set(kmi->ptr, "unselected", TRUE);
149         
150         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_unmute", HKEY, KM_PRESS, KM_ALT, 0);
151                 RNA_boolean_set(kmi->ptr, "unselected", FALSE);
152         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_unmute", HKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0);
153                 RNA_boolean_set(kmi->ptr, "unselected", TRUE);
154
155         WM_keymap_add_item(keymap, "SEQUENCER_OT_lock", LKEY, KM_PRESS, KM_SHIFT, 0);
156         WM_keymap_add_item(keymap, "SEQUENCER_OT_unlock", LKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
157
158         WM_keymap_add_item(keymap, "SEQUENCER_OT_reassign_inputs", RKEY, KM_PRESS, 0, 0);
159         WM_keymap_add_item(keymap, "SEQUENCER_OT_reload", RKEY, KM_PRESS, KM_ALT, 0);
160
161         WM_keymap_add_item(keymap, "SEQUENCER_OT_offset_clear", OKEY, KM_PRESS, KM_ALT, 0);
162
163         WM_keymap_add_item(keymap, "SEQUENCER_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
164
165         WM_keymap_add_item(keymap, "SEQUENCER_OT_delete", XKEY, KM_PRESS, 0, 0);
166         WM_keymap_add_item(keymap, "SEQUENCER_OT_delete", DELKEY, KM_PRESS, 0, 0);
167         
168         WM_keymap_add_item(keymap, "SEQUENCER_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
169         WM_keymap_add_item(keymap, "SEQUENCER_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
170
171         WM_keymap_add_item(keymap, "SEQUENCER_OT_images_separate", YKEY, KM_PRESS, 0, 0);
172
173         WM_keymap_add_item(keymap, "SEQUENCER_OT_meta_toggle", TABKEY, KM_PRESS, 0, 0);
174
175         WM_keymap_add_item(keymap, "SEQUENCER_OT_meta_make", GKEY, KM_PRESS, KM_CTRL, 0);
176         WM_keymap_add_item(keymap, "SEQUENCER_OT_meta_separate", GKEY, KM_PRESS, KM_ALT, 0);
177
178         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
179         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
180
181         WM_keymap_add_item(keymap, "SEQUENCER_OT_next_edit", PAGEUPKEY, KM_PRESS, 0, 0);
182         WM_keymap_add_item(keymap, "SEQUENCER_OT_previous_edit", PAGEDOWNKEY, KM_PRESS, 0, 0);
183
184         RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_swap", LEFTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "side", SEQ_SIDE_LEFT);
185         RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_swap", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "side", SEQ_SIDE_RIGHT);
186         
187         WM_keymap_add_item(keymap, "SEQUENCER_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
188         WM_keymap_add_item(keymap, "SEQUENCER_OT_swap_inputs", SKEY, KM_PRESS, KM_ALT, 0);
189
190         /* multicam editing keyboard layout, switch to camera 1-10 using
191            regular number keys */
192         {
193                 int keys[] = { ONEKEY, TWOKEY, THREEKEY, FOURKEY, FIVEKEY,
194                                SIXKEY, SEVENKEY, EIGHTKEY, NINEKEY, ZEROKEY };
195                 int i;
196
197                 for (i = 1; i <= 10; i++) {
198                         RNA_int_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_cut_multicam", keys[i-1], KM_PRESS, 0, 0)->ptr, "camera", i);
199                 }
200         }
201
202         /* Mouse selection, a bit verbose :/ */
203         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
204                 RNA_boolean_set(kmi->ptr, "extend", FALSE);
205                 RNA_boolean_set(kmi->ptr, "linked_handle", FALSE);
206                 RNA_boolean_set(kmi->ptr, "left_right", FALSE);
207                 RNA_boolean_set(kmi->ptr, "linked_time", FALSE);
208         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
209                 RNA_boolean_set(kmi->ptr, "extend", TRUE);
210                 RNA_boolean_set(kmi->ptr, "linked_handle", FALSE);
211                 RNA_boolean_set(kmi->ptr, "left_right", FALSE);
212                 RNA_boolean_set(kmi->ptr, "linked_time", FALSE);
213
214
215         /* 2.4x method, now use Alt for handles and select the side based on which handle was selected */
216         /*
217         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
218         RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
219         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
220         RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
221         
222         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_ALT, 0);
223         RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
224         RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
225
226         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL|KM_ALT, 0);
227         RNA_boolean_set(kmi->ptr, "extend", TRUE);
228         RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
229         RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
230
231         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
232         RNA_boolean_set(kmi->ptr, "extend", TRUE);
233         RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
234
235         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0);
236         RNA_boolean_set(kmi->ptr, "extend", TRUE);
237         RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
238          */
239
240         /* 2.5 method, Alt and use selected handle */
241         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
242                 RNA_boolean_set(kmi->ptr, "extend", FALSE);
243                 RNA_boolean_set(kmi->ptr, "linked_handle", TRUE);
244                 RNA_boolean_set(kmi->ptr, "left_right", FALSE);
245                 RNA_boolean_set(kmi->ptr, "linked_time", FALSE);
246
247         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0);
248                 RNA_boolean_set(kmi->ptr, "extend", TRUE);
249                 RNA_boolean_set(kmi->ptr, "linked_handle", TRUE);
250                 RNA_boolean_set(kmi->ptr, "left_right", FALSE);
251                 RNA_boolean_set(kmi->ptr, "linked_time", FALSE);
252
253         /* match action editor */
254         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
255                 RNA_boolean_set(kmi->ptr, "extend", FALSE);
256                 RNA_boolean_set(kmi->ptr, "linked_handle", FALSE);
257                 RNA_boolean_set(kmi->ptr, "left_right", TRUE); /* grr, these conflict - only use left_right if not over an active seq */
258                 RNA_boolean_set(kmi->ptr, "linked_time", TRUE);
259         /* adjusted since 2.4 */
260
261         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
262                 RNA_boolean_set(kmi->ptr, "extend", TRUE);
263                 RNA_boolean_set(kmi->ptr, "linked_handle", FALSE);
264                 RNA_boolean_set(kmi->ptr, "left_right", FALSE);
265                 RNA_boolean_set(kmi->ptr, "linked_time", TRUE);
266
267         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
268         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
269         
270         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
271         RNA_boolean_set(kmi->ptr, "extend", FALSE);
272         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0);
273         RNA_boolean_set(kmi->ptr, "extend", TRUE);
274         
275         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
276         
277         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_border", BKEY, KM_PRESS, 0, 0);
278
279         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
280
281         WM_keymap_add_menu(keymap, "SEQUENCER_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
282
283         WM_keymap_add_menu(keymap, "SEQUENCER_MT_change", CKEY, KM_PRESS, 0, 0);
284         
285         kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", OKEY, KM_PRESS, 0, 0);
286         RNA_string_set(kmi->ptr, "data_path", "scene.sequence_editor.overlay_frame");
287         RNA_int_set(kmi->ptr, "value", 0);
288
289         transform_keymap_for_space(keyconf, keymap, SPACE_SEQ);
290
291         keymap= WM_keymap_find(keyconf, "SequencerPreview", SPACE_SEQ, 0);
292         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_all_preview", HOMEKEY, KM_PRESS, 0, 0);
293         WM_keymap_add_item(keymap, "SEQUENCER_OT_properties", NKEY, KM_PRESS, 0, 0);
294
295         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_ghost_border", OKEY, KM_PRESS, 0, 0);
296
297         /* would prefer to use numpad keys for job */
298         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f);
299         
300         /* Setting zoom levels is not that useful, except for back to zoom level 1, removing keymap because of conflicts for now */
301 #if 0
302         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f);
303         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f);
304         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f);
305         
306         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f);
307         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f);
308         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f);
309 #endif
310
311 }
312