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