Merged changes in the trunk up to revision 41368.
[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_toggle);
96         WM_operatortype_append(SEQUENCER_OT_select_inverse);
97         WM_operatortype_append(SEQUENCER_OT_select);
98         WM_operatortype_append(SEQUENCER_OT_select_more);
99         WM_operatortype_append(SEQUENCER_OT_select_less);
100         WM_operatortype_append(SEQUENCER_OT_select_linked_pick);
101         WM_operatortype_append(SEQUENCER_OT_select_linked);
102         WM_operatortype_append(SEQUENCER_OT_select_handles);
103         WM_operatortype_append(SEQUENCER_OT_select_active_side);
104         WM_operatortype_append(SEQUENCER_OT_select_border);
105         WM_operatortype_append(SEQUENCER_OT_select_grouped);
106
107         /* sequencer_add.c */
108         WM_operatortype_append(SEQUENCER_OT_scene_strip_add);
109         WM_operatortype_append(SEQUENCER_OT_movie_strip_add);
110         WM_operatortype_append(SEQUENCER_OT_sound_strip_add);
111         WM_operatortype_append(SEQUENCER_OT_image_strip_add);
112         WM_operatortype_append(SEQUENCER_OT_effect_strip_add);
113         WM_operatortype_append(SEQUENCER_OT_properties);
114
115         WM_operatortype_append(SEQUENCER_OT_copy);
116         WM_operatortype_append(SEQUENCER_OT_paste);
117 }
118
119
120 void sequencer_keymap(wmKeyConfig *keyconf)
121 {
122         wmKeyMap *keymap= WM_keymap_find(keyconf, "SequencerCommon", SPACE_SEQ, 0);
123         wmKeyMapItem *kmi;
124
125         kmi= WM_keymap_add_item(keymap, "WM_OT_context_toggle", OKEY, KM_PRESS, KM_SHIFT, 0);
126         RNA_string_set(kmi->ptr, "data_path", "scene.sequence_editor.show_overlay");
127
128         /* operators common to sequence and preview view */
129         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_toggle", TABKEY, KM_PRESS, KM_CTRL, 0);
130
131         /* operators for sequence */
132         keymap= WM_keymap_find(keyconf, "Sequencer", SPACE_SEQ, 0);
133         
134         WM_keymap_add_item(keymap, "SEQUENCER_OT_properties", NKEY, KM_PRESS, 0, 0);
135         
136         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
137         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
138         
139         RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, 0, 0)->ptr, "type", SEQ_CUT_SOFT);
140         RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", SEQ_CUT_HARD);
141         
142         WM_keymap_add_item(keymap, "SEQUENCER_OT_mute", HKEY, KM_PRESS, 0, 0);
143         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_mute", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
144         
145         WM_keymap_add_item(keymap, "SEQUENCER_OT_unmute", HKEY, KM_PRESS, KM_ALT, 0);
146         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_unmute", HKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "unselected", 1);
147
148         WM_keymap_add_item(keymap, "SEQUENCER_OT_lock", LKEY, KM_PRESS, KM_SHIFT, 0);
149         WM_keymap_add_item(keymap, "SEQUENCER_OT_unlock", LKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
150
151         WM_keymap_add_item(keymap, "SEQUENCER_OT_reassign_inputs", RKEY, KM_PRESS, 0, 0);
152         WM_keymap_add_item(keymap, "SEQUENCER_OT_reload", RKEY, KM_PRESS, KM_ALT, 0);
153
154         WM_keymap_add_item(keymap, "SEQUENCER_OT_offset_clear", OKEY, KM_PRESS, KM_ALT, 0);
155
156         WM_keymap_add_item(keymap, "SEQUENCER_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
157
158         WM_keymap_add_item(keymap, "SEQUENCER_OT_delete", XKEY, KM_PRESS, 0, 0);
159         WM_keymap_add_item(keymap, "SEQUENCER_OT_delete", DELKEY, KM_PRESS, 0, 0);
160         
161         WM_keymap_add_item(keymap, "SEQUENCER_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
162         WM_keymap_add_item(keymap, "SEQUENCER_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
163
164         WM_keymap_add_item(keymap, "SEQUENCER_OT_images_separate", YKEY, KM_PRESS, 0, 0);
165
166         WM_keymap_add_item(keymap, "SEQUENCER_OT_meta_toggle", TABKEY, KM_PRESS, 0, 0);
167
168         WM_keymap_add_item(keymap, "SEQUENCER_OT_meta_make", GKEY, KM_PRESS, KM_CTRL, 0);
169         WM_keymap_add_item(keymap, "SEQUENCER_OT_meta_separate", GKEY, KM_PRESS, KM_ALT, 0);
170
171         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
172         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
173
174         WM_keymap_add_item(keymap, "SEQUENCER_OT_next_edit", PAGEUPKEY, KM_PRESS, 0, 0);
175         WM_keymap_add_item(keymap, "SEQUENCER_OT_previous_edit", PAGEDOWNKEY, KM_PRESS, 0, 0);
176
177         RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_swap", LEFTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "side", SEQ_SIDE_LEFT);
178         RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_swap", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "side", SEQ_SIDE_RIGHT);
179         
180         WM_keymap_add_item(keymap, "SEQUENCER_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
181         WM_keymap_add_item(keymap, "SEQUENCER_OT_swap_inputs", SKEY, KM_PRESS, KM_ALT, 0);
182
183         /* multicam editing keyboard layout, switch to camera 1-10 using
184            regular number keys */
185         {
186                 int keys[] = { ONEKEY, TWOKEY, THREEKEY, FOURKEY, FIVEKEY,
187                                SIXKEY, SEVENKEY, EIGHTKEY, NINEKEY, ZEROKEY };
188                 int i;
189
190                 for (i = 1; i <= 10; i++) {
191                         RNA_int_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_cut_multicam", keys[i-1], KM_PRESS, 0, 0)->ptr, "camera", i);
192                 }
193         }
194
195         /* Mouse selection, a bit verbose :/ */
196         WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
197         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
198
199
200         /* 2.4x method, now use Alt for handles and select the side based on which handle was selected */
201         /*
202         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "linked_left", 1);
203         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "linked_right", 1);
204         
205         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_ALT, 0);
206         RNA_boolean_set(kmi->ptr, "linked_left", 1);
207         RNA_boolean_set(kmi->ptr, "linked_right", 1);
208
209         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL|KM_ALT, 0);
210         RNA_boolean_set(kmi->ptr, "extend", 1);
211         RNA_boolean_set(kmi->ptr, "linked_left", 1);
212         RNA_boolean_set(kmi->ptr, "linked_right", 1);
213
214         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
215         RNA_boolean_set(kmi->ptr, "extend", 1);
216         RNA_boolean_set(kmi->ptr, "linked_left", 1);
217
218         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0);
219         RNA_boolean_set(kmi->ptr, "extend", 1);
220         RNA_boolean_set(kmi->ptr, "linked_right", 1);
221          */
222
223         /* 2.5 method, Alt and use selected handle */
224         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "linked_handle", 1);
225
226         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0);
227         RNA_boolean_set(kmi->ptr, "extend", 1);
228         RNA_boolean_set(kmi->ptr, "linked_handle", 1);
229
230         /* match action editor */
231         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
232         RNA_boolean_set(kmi->ptr, "left_right", 1); /* grr, these conflict - only use left_right if not over an active seq */
233         RNA_boolean_set(kmi->ptr, "linked_time", 1);
234         /* adjusted since 2.4 */
235
236         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
237         RNA_boolean_set(kmi->ptr, "extend", 1);
238         RNA_boolean_set(kmi->ptr, "linked_time", 1);
239
240         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
241         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
242         
243         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
244         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
245         
246         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
247         
248         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_border", BKEY, KM_PRESS, 0, 0);
249
250         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
251
252         WM_keymap_add_menu(keymap, "SEQUENCER_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
253
254         WM_keymap_add_menu(keymap, "SEQUENCER_MT_change", CKEY, KM_PRESS, 0, 0);
255         
256         kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", OKEY, KM_PRESS, 0, 0);
257         RNA_string_set(kmi->ptr, "data_path", "scene.sequence_editor.overlay_frame");
258         RNA_int_set(kmi->ptr, "value", 0);
259
260         transform_keymap_for_space(keyconf, keymap, SPACE_SEQ);
261
262         keymap= WM_keymap_find(keyconf, "SequencerPreview", SPACE_SEQ, 0);
263         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_all_preview", HOMEKEY, KM_PRESS, 0, 0);
264         WM_keymap_add_item(keymap, "SEQUENCER_OT_properties", NKEY, KM_PRESS, 0, 0);
265
266         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_ghost_border", OKEY, KM_PRESS, 0, 0);
267
268         /* would prefer to use numpad keys for job */
269         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f);
270         
271         /* Setting zoom levels is not that useful, except for back to zoom level 1, removing keymap because of conflicts for now */
272 #if 0
273         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f);
274         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f);
275         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f);
276         
277         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f);
278         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f);
279         RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f);
280 #endif
281
282 }
283