Fix for [#32595] N shortcut (view-properties) is not shown in preview mode in sequenc...
[blender.git] / source / blender / editors / space_sequencer / sequencer_ops.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  *
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_sequencer/sequencer_ops.c
28  *  \ingroup spseq
29  */
30
31
32 #include <stdlib.h>
33 #include <math.h>
34
35
36 #include "DNA_space_types.h"
37
38 #include "BLI_math.h"
39 #include "BLI_blenlib.h"
40
41
42
43 #include "WM_api.h"
44 #include "WM_types.h"
45
46 #include "ED_sequencer.h"
47 #include "ED_markers.h"
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_strip_jump);
77         WM_operatortype_append(SEQUENCER_OT_swap);
78         WM_operatortype_append(SEQUENCER_OT_swap_data);
79         WM_operatortype_append(SEQUENCER_OT_rendersize);
80
81         WM_operatortype_append(SEQUENCER_OT_copy);
82         WM_operatortype_append(SEQUENCER_OT_paste);
83
84         WM_operatortype_append(SEQUENCER_OT_view_all);
85         WM_operatortype_append(SEQUENCER_OT_view_selected);
86         WM_operatortype_append(SEQUENCER_OT_view_all_preview);
87         WM_operatortype_append(SEQUENCER_OT_view_toggle);
88         WM_operatortype_append(SEQUENCER_OT_view_zoom_ratio);
89         WM_operatortype_append(SEQUENCER_OT_view_ghost_border);
90
91         WM_operatortype_append(SEQUENCER_OT_rebuild_proxy);
92         WM_operatortype_append(SEQUENCER_OT_change_effect_input);
93         WM_operatortype_append(SEQUENCER_OT_change_effect_type);
94         WM_operatortype_append(SEQUENCER_OT_change_path);
95
96         /* sequencer_select.c */
97         WM_operatortype_append(SEQUENCER_OT_select_all);
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_movieclip_strip_add);
111         WM_operatortype_append(SEQUENCER_OT_mask_strip_add);
112         WM_operatortype_append(SEQUENCER_OT_movie_strip_add);
113         WM_operatortype_append(SEQUENCER_OT_sound_strip_add);
114         WM_operatortype_append(SEQUENCER_OT_image_strip_add);
115         WM_operatortype_append(SEQUENCER_OT_effect_strip_add);
116
117         /* sequencer_buttons.c */
118         WM_operatortype_append(SEQUENCER_OT_properties);
119
120         /* sequencer_modifiers.c */
121         WM_operatortype_append(SEQUENCER_OT_strip_modifier_add);
122         WM_operatortype_append(SEQUENCER_OT_strip_modifier_remove);
123         WM_operatortype_append(SEQUENCER_OT_strip_modifier_move);
124
125         /* sequencer_view.h */
126         WM_operatortype_append(SEQUENCER_OT_sample);
127 }
128
129
130 void sequencer_keymap(wmKeyConfig *keyconf)
131 {
132         wmKeyMap *keymap;
133         wmKeyMapItem *kmi;
134         
135         /* Common items ------------------------------------------------------------------ */
136         keymap = WM_keymap_find(keyconf, "SequencerCommon", SPACE_SEQ, 0);
137
138         WM_keymap_add_item(keymap, "SEQUENCER_OT_properties", NKEY, KM_PRESS, 0, 0);
139
140         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", OKEY, KM_PRESS, KM_SHIFT, 0);
141         RNA_string_set(kmi->ptr, "data_path", "scene.sequence_editor.show_overlay");
142
143         /* operators common to sequence and preview view */
144         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_toggle", TABKEY, KM_PRESS, KM_CTRL, 0);
145
146         /* Strips Region --------------------------------------------------------------- */
147         keymap = WM_keymap_find(keyconf, "Sequencer", SPACE_SEQ, 0);
148
149         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_all", AKEY, KM_PRESS, 0, 0);
150         RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
151         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
152         RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
153
154         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, 0, 0);
155         RNA_enum_set(kmi->ptr, "type", SEQ_CUT_SOFT);
156         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, KM_SHIFT, 0);
157         RNA_enum_set(kmi->ptr, "type", SEQ_CUT_HARD);
158
159         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_mute", HKEY, KM_PRESS, 0, 0);
160         RNA_boolean_set(kmi->ptr, "unselected", FALSE);
161         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_mute", HKEY, KM_PRESS, KM_SHIFT, 0);
162         RNA_boolean_set(kmi->ptr, "unselected", TRUE);
163
164         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_unmute", HKEY, KM_PRESS, KM_ALT, 0);
165         RNA_boolean_set(kmi->ptr, "unselected", FALSE);
166         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_unmute", HKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
167         RNA_boolean_set(kmi->ptr, "unselected", TRUE);
168
169         WM_keymap_add_item(keymap, "SEQUENCER_OT_lock", LKEY, KM_PRESS, KM_SHIFT, 0);
170         WM_keymap_add_item(keymap, "SEQUENCER_OT_unlock", LKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0);
171
172         WM_keymap_add_item(keymap, "SEQUENCER_OT_reassign_inputs", RKEY, KM_PRESS, 0, 0);
173
174         WM_keymap_add_item(keymap, "SEQUENCER_OT_reload", RKEY, KM_PRESS, KM_ALT, 0);
175         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_reload", RKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0);
176         RNA_boolean_set(kmi->ptr, "adjust_length", TRUE);
177
178         WM_keymap_add_item(keymap, "SEQUENCER_OT_offset_clear", OKEY, KM_PRESS, KM_ALT, 0);
179
180         WM_keymap_add_item(keymap, "SEQUENCER_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
181
182         WM_keymap_add_item(keymap, "SEQUENCER_OT_delete", XKEY, KM_PRESS, 0, 0);
183         WM_keymap_add_item(keymap, "SEQUENCER_OT_delete", DELKEY, KM_PRESS, 0, 0);
184
185         WM_keymap_add_item(keymap, "SEQUENCER_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
186         WM_keymap_add_item(keymap, "SEQUENCER_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
187
188         WM_keymap_add_item(keymap, "SEQUENCER_OT_images_separate", YKEY, KM_PRESS, 0, 0);
189
190         WM_keymap_add_item(keymap, "SEQUENCER_OT_meta_toggle", TABKEY, KM_PRESS, 0, 0);
191
192         WM_keymap_add_item(keymap, "SEQUENCER_OT_meta_make", GKEY, KM_PRESS, KM_CTRL, 0);
193         WM_keymap_add_item(keymap, "SEQUENCER_OT_meta_separate", GKEY, KM_PRESS, KM_ALT, 0);
194
195         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
196         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
197
198         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_strip_jump", PAGEUPKEY, KM_PRESS, 0, 0);
199         RNA_boolean_set(kmi->ptr, "next", TRUE);
200         RNA_boolean_set(kmi->ptr, "center", FALSE);
201         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_strip_jump", PAGEDOWNKEY, KM_PRESS, 0, 0);
202         RNA_boolean_set(kmi->ptr, "next", FALSE);
203         RNA_boolean_set(kmi->ptr, "center", FALSE);
204
205         /* alt for center */
206         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_strip_jump", PAGEUPKEY, KM_PRESS, KM_ALT, 0);
207         RNA_boolean_set(kmi->ptr, "next", TRUE);
208         RNA_boolean_set(kmi->ptr, "center", TRUE);
209         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_strip_jump", PAGEDOWNKEY, KM_PRESS, KM_ALT, 0);
210         RNA_boolean_set(kmi->ptr, "next", FALSE);
211         RNA_boolean_set(kmi->ptr, "center", TRUE);
212
213         RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_swap", LEFTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "side", SEQ_SIDE_LEFT);
214         RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_swap", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "side", SEQ_SIDE_RIGHT);
215
216         WM_keymap_add_item(keymap, "SEQUENCER_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
217         WM_keymap_add_item(keymap, "SEQUENCER_OT_swap_inputs", SKEY, KM_PRESS, KM_ALT, 0);
218
219         /* multicam editing keyboard layout, switch to camera 1-10 using
220          * regular number keys */
221         {
222                 int keys[] = { ONEKEY, TWOKEY, THREEKEY, FOURKEY, FIVEKEY,
223                                    SIXKEY, SEVENKEY, EIGHTKEY, NINEKEY, ZEROKEY };
224                 int i;
225
226                 for (i = 1; i <= 10; i++) {
227                         RNA_int_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_cut_multicam", keys[i - 1], KM_PRESS, 0, 0)->ptr, "camera", i);
228                 }
229         }
230
231         /* Mouse selection, a bit verbose :/ */
232         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
233         RNA_boolean_set(kmi->ptr, "extend", FALSE);
234         RNA_boolean_set(kmi->ptr, "linked_handle", FALSE);
235         RNA_boolean_set(kmi->ptr, "left_right", FALSE);
236         RNA_boolean_set(kmi->ptr, "linked_time", FALSE);
237         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
238         RNA_boolean_set(kmi->ptr, "extend", TRUE);
239         RNA_boolean_set(kmi->ptr, "linked_handle", FALSE);
240         RNA_boolean_set(kmi->ptr, "left_right", FALSE);
241         RNA_boolean_set(kmi->ptr, "linked_time", FALSE);
242
243
244         /* 2.4x method, now use Alt for handles and select the side based on which handle was selected */
245 #if 0
246         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
247         RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
248         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
249         RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
250
251         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_ALT, 0);
252         RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
253         RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
254
255         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_CTRL | KM_ALT, 0);
256         RNA_boolean_set(kmi->ptr, "extend", TRUE);
257         RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
258         RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
259
260         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
261         RNA_boolean_set(kmi->ptr, "extend", TRUE);
262         RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
263
264         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_ALT, 0);
265         RNA_boolean_set(kmi->ptr, "extend", TRUE);
266         RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
267 #endif
268
269         /* 2.5 method, Alt and use selected handle */
270         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
271         RNA_boolean_set(kmi->ptr, "extend", FALSE);
272         RNA_boolean_set(kmi->ptr, "linked_handle", TRUE);
273         RNA_boolean_set(kmi->ptr, "left_right", FALSE);
274         RNA_boolean_set(kmi->ptr, "linked_time", FALSE);
275
276         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_ALT, 0);
277         RNA_boolean_set(kmi->ptr, "extend", TRUE);
278         RNA_boolean_set(kmi->ptr, "linked_handle", TRUE);
279         RNA_boolean_set(kmi->ptr, "left_right", FALSE);
280         RNA_boolean_set(kmi->ptr, "linked_time", FALSE);
281
282         /* match action editor */
283         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
284         RNA_boolean_set(kmi->ptr, "extend", FALSE);
285         RNA_boolean_set(kmi->ptr, "linked_handle", FALSE);
286         RNA_boolean_set(kmi->ptr, "left_right", TRUE);     /* grr, these conflict - only use left_right if not over an active seq */
287         RNA_boolean_set(kmi->ptr, "linked_time", TRUE);
288         /* adjusted since 2.4 */
289
290         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
291         RNA_boolean_set(kmi->ptr, "extend", TRUE);
292         RNA_boolean_set(kmi->ptr, "linked_handle", FALSE);
293         RNA_boolean_set(kmi->ptr, "left_right", FALSE);
294         RNA_boolean_set(kmi->ptr, "linked_time", TRUE);
295
296         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
297         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
298
299         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
300         RNA_boolean_set(kmi->ptr, "extend", FALSE);
301         kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0);
302         RNA_boolean_set(kmi->ptr, "extend", TRUE);
303
304         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
305
306         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_border", BKEY, KM_PRESS, 0, 0);
307
308         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
309
310         WM_keymap_add_menu(keymap, "SEQUENCER_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
311
312         WM_keymap_add_menu(keymap, "SEQUENCER_MT_change", CKEY, KM_PRESS, 0, 0);
313
314         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_int", OKEY, KM_PRESS, 0, 0);
315         RNA_string_set(kmi->ptr, "data_path", "scene.sequence_editor.overlay_frame");
316         RNA_int_set(kmi->ptr, "value", 0);
317
318         transform_keymap_for_space(keyconf, keymap, SPACE_SEQ);
319
320         /* special markers hotkeys for anim editors: see note in definition of this function */
321         ED_marker_keymap_animedit_conflictfree(keymap);
322
323
324         /* Preview Region ----------------------------------------------------------- */
325         keymap = WM_keymap_find(keyconf, "SequencerPreview", SPACE_SEQ, 0);
326         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_all_preview", HOMEKEY, KM_PRESS, 0, 0);
327
328         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_ghost_border", OKEY, KM_PRESS, 0, 0);
329
330         /* would prefer to use numpad keys for job */
331         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f);
332
333         /* Setting zoom levels is not that useful, except for back to zoom level 1, removing keymap because of conflicts for now */
334 #if 0
335         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f);
336         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f);
337         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f);
338
339         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f);
340         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f);
341         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f);
342 #endif
343
344         /* sample */
345         WM_keymap_add_item(keymap, "SEQUENCER_OT_sample", ACTIONMOUSE, KM_PRESS, 0, 0);
346 }
347
348 void ED_operatormacros_sequencer(void)
349 {
350         wmOperatorType *ot;
351
352         ot = WM_operatortype_append_macro("SEQUENCER_OT_duplicate_move", "Duplicate Strips",
353                                           "Duplicate selected strips and move them", OPTYPE_UNDO | OPTYPE_REGISTER);
354
355         WM_operatortype_macro_define(ot, "SEQUENCER_OT_duplicate");
356         WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
357 }