Sound clip NLA Strips for Nexyon
[blender-staging.git] / source / blender / editors / space_nla / nla_ops.c
1 /*
2  * $Id$
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) 2009 Blender Foundation, Joshua Leung
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Joshua Leung (major recode)
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file blender/editors/space_nla/nla_ops.c
30  *  \ingroup spnla
31  */
32
33
34 #include <string.h>
35 #include <stdio.h>
36
37 #include "DNA_scene_types.h"
38
39
40 #include "BLI_blenlib.h"
41 #include "BLI_math.h"
42 #include "BLI_rand.h"
43
44 #include "BKE_context.h"
45 #include "BKE_screen.h"
46
47 #include "ED_anim_api.h"
48 #include "ED_markers.h"
49 #include "ED_screen.h"
50 #include "ED_transform.h"
51
52 #include "WM_api.h"
53 #include "WM_types.h"
54
55 #include "RNA_access.h"
56
57
58 #include "nla_intern.h" // own include
59
60 /* ************************** poll callbacks for operators **********************************/
61
62 /* tweakmode is NOT enabled */
63 int nlaop_poll_tweakmode_off (bContext *C)
64 {
65         Scene *scene;
66         
67         /* for now, we check 2 things: 
68          *      1) active editor must be NLA
69          *      2) tweakmode is currently set as a 'per-scene' flag 
70          *         so that it will affect entire NLA data-sets,
71          *         but not all AnimData blocks will be in tweakmode for 
72          *         various reasons
73          */
74         if (ED_operator_nla_active(C) == 0)
75                 return 0;
76         
77         scene= CTX_data_scene(C);
78         if ((scene == NULL) || (scene->flag & SCE_NLA_EDIT_ON))
79                 return 0;
80         
81         return 1;
82 }
83
84 /* tweakmode IS enabled */
85 int nlaop_poll_tweakmode_on (bContext *C)
86 {
87         Scene *scene;
88         
89         /* for now, we check 2 things: 
90          *      1) active editor must be NLA
91          *      2) tweakmode is currently set as a 'per-scene' flag 
92          *         so that it will affect entire NLA data-sets,
93          *         but not all AnimData blocks will be in tweakmode for 
94          *         various reasons
95          */
96         if (ED_operator_nla_active(C) == 0)
97                 return 0;
98         
99         scene= CTX_data_scene(C);
100         if ((scene == NULL) || !(scene->flag & SCE_NLA_EDIT_ON))
101                 return 0;
102         
103         return 1;
104 }
105
106 /* is tweakmode enabled - for use in NLA operator code */
107 short nlaedit_is_tweakmode_on (bAnimContext *ac)
108 {
109         if (ac && ac->scene)
110                 return (ac->scene->flag & SCE_NLA_EDIT_ON);
111         return 0;
112 }
113
114 /* ************************** registration - operator types **********************************/
115
116 void nla_operatortypes(void)
117 {
118         /* view */
119         WM_operatortype_append(NLA_OT_properties);
120         
121         /* channels */
122         WM_operatortype_append(NLA_OT_channels_click);
123         
124         WM_operatortype_append(NLA_OT_tracks_add);
125         WM_operatortype_append(NLA_OT_delete_tracks);
126         
127         /* select */
128         WM_operatortype_append(NLA_OT_click_select);
129         WM_operatortype_append(NLA_OT_select_border);
130         WM_operatortype_append(NLA_OT_select_all_toggle);
131         WM_operatortype_append(NLA_OT_select_leftright);
132         
133         /* view */
134         WM_operatortype_append(NLA_OT_view_all);
135         WM_operatortype_append(NLA_OT_view_selected);
136         
137         /* edit */
138         WM_operatortype_append(NLA_OT_tweakmode_enter);
139         WM_operatortype_append(NLA_OT_tweakmode_exit);
140         
141         WM_operatortype_append(NLA_OT_actionclip_add);
142         WM_operatortype_append(NLA_OT_transition_add);
143         WM_operatortype_append(NLA_OT_soundclip_add);
144         
145         WM_operatortype_append(NLA_OT_meta_add);
146         WM_operatortype_append(NLA_OT_meta_remove);
147         
148         WM_operatortype_append(NLA_OT_duplicate);
149         WM_operatortype_append(NLA_OT_delete);
150         WM_operatortype_append(NLA_OT_split);
151         
152         WM_operatortype_append(NLA_OT_mute_toggle);
153         
154         WM_operatortype_append(NLA_OT_swap);
155         WM_operatortype_append(NLA_OT_move_up);
156         WM_operatortype_append(NLA_OT_move_down);
157         
158         WM_operatortype_append(NLA_OT_action_sync_length);
159         
160         WM_operatortype_append(NLA_OT_apply_scale);
161         WM_operatortype_append(NLA_OT_clear_scale);
162         
163         WM_operatortype_append(NLA_OT_snap);
164         
165         WM_operatortype_append(NLA_OT_fmodifier_add);
166         WM_operatortype_append(NLA_OT_fmodifier_copy);
167         WM_operatortype_append(NLA_OT_fmodifier_paste);
168 }
169
170 /* ************************** registration - keymaps **********************************/
171
172 static void nla_keymap_channels(wmKeyMap *keymap)
173 {
174         /* NLA-specific (different to standard channels keymap) -------------------------- */
175         /* selection */
176                 /* click-select */
177                 // XXX for now, only leftmouse.... 
178         WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, 0, 0);
179         RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
180         
181         /* channel operations */
182                 /* add tracks */
183         WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_SHIFT, 0);
184         RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "above_selected", 1);
185         
186                 /* delete tracks */
187         WM_keymap_add_item(keymap, "NLA_OT_delete_tracks", XKEY, KM_PRESS, 0, 0);
188         WM_keymap_add_item(keymap, "NLA_OT_delete_tracks", DELKEY, KM_PRESS, 0, 0);
189 }
190
191 static void nla_keymap_main (wmKeyConfig *keyconf, wmKeyMap *keymap)
192 {
193         wmKeyMapItem *kmi;
194         
195         /* selection */
196                 /* click select */
197         WM_keymap_add_item(keymap, "NLA_OT_click_select", SELECTMOUSE, KM_PRESS, 0, 0);
198         kmi= WM_keymap_add_item(keymap, "NLA_OT_click_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
199                 RNA_boolean_set(kmi->ptr, "extend", 1);
200                 
201                 /* select left/right */
202         WM_keymap_add_item(keymap, "NLA_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
203         kmi= WM_keymap_add_item(keymap, "NLA_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
204                 RNA_boolean_set(kmi->ptr, "extend", 1);
205         
206         kmi= WM_keymap_add_item(keymap, "NLA_OT_select_leftright", LEFTBRACKETKEY, KM_PRESS, 0, 0);
207                 RNA_enum_set(kmi->ptr, "mode", NLAEDIT_LRSEL_LEFT);
208         kmi= WM_keymap_add_item(keymap, "NLA_OT_select_leftright", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
209                 RNA_enum_set(kmi->ptr, "mode", NLAEDIT_LRSEL_RIGHT);
210                 
211         
212                 /* deselect all */
213         WM_keymap_add_item(keymap, "NLA_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
214         RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
215         
216                 /* borderselect */
217         WM_keymap_add_item(keymap, "NLA_OT_select_border", BKEY, KM_PRESS, 0, 0);
218         RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0)->ptr, "axis_range", 1);
219         
220         /* view*/
221                 /* auto-set range */
222         //WM_keymap_add_item(keymap, "NLA_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
223         WM_keymap_add_item(keymap, "NLA_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
224         WM_keymap_add_item(keymap, "NLA_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
225         
226         /* editing */
227                 /* tweakmode 
228                  *      - enter and exit are separate operators with the same hotkey... 
229                  *        This works as they use different poll()'s
230                  */
231         WM_keymap_add_item(keymap, "NLA_OT_tweakmode_enter", TABKEY, KM_PRESS, 0, 0);
232         WM_keymap_add_item(keymap, "NLA_OT_tweakmode_exit", TABKEY, KM_PRESS, 0, 0);
233                 
234                 /* add strips */
235         WM_keymap_add_item(keymap, "NLA_OT_actionclip_add", AKEY, KM_PRESS, KM_SHIFT, 0);
236         WM_keymap_add_item(keymap, "NLA_OT_transition_add", TKEY, KM_PRESS, KM_SHIFT, 0);
237         WM_keymap_add_item(keymap, "NLA_OT_soundclip_add", KKEY, KM_PRESS, KM_SHIFT, 0);
238         
239                 /* meta-strips */
240         WM_keymap_add_item(keymap, "NLA_OT_meta_add", GKEY, KM_PRESS, KM_SHIFT, 0);
241         WM_keymap_add_item(keymap, "NLA_OT_meta_remove", GKEY, KM_PRESS, KM_ALT, 0);
242                 
243                 /* duplicate */
244         WM_keymap_add_item(keymap, "NLA_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);    
245                 
246                 /* delete */
247         WM_keymap_add_item(keymap, "NLA_OT_delete", XKEY, KM_PRESS, 0, 0);
248         WM_keymap_add_item(keymap, "NLA_OT_delete", DELKEY, KM_PRESS, 0, 0);
249
250                 /* split */
251         WM_keymap_add_item(keymap, "NLA_OT_split", YKEY, KM_PRESS, 0, 0);
252         
253                 /* toggles */
254         WM_keymap_add_item(keymap, "NLA_OT_mute_toggle", HKEY, KM_PRESS, 0, 0);
255         
256                 /* swap */
257         WM_keymap_add_item(keymap, "NLA_OT_swap", FKEY, KM_PRESS, KM_ALT, 0);
258                 
259                 /* move up */
260         WM_keymap_add_item(keymap, "NLA_OT_move_up", PAGEUPKEY, KM_PRESS, 0, 0);
261                 /* move down */
262         WM_keymap_add_item(keymap, "NLA_OT_move_down", PAGEDOWNKEY, KM_PRESS, 0, 0);
263         
264                 /* apply scale */
265         WM_keymap_add_item(keymap, "NLA_OT_apply_scale", AKEY, KM_PRESS, KM_CTRL, 0);
266                 /* clear scale */
267         WM_keymap_add_item(keymap, "NLA_OT_clear_scale", SKEY, KM_PRESS, KM_ALT, 0);
268         
269                 /* snap */
270         WM_keymap_add_item(keymap, "NLA_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
271         
272                 /* add f-modifier */
273         WM_keymap_add_item(keymap, "NLA_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
274         
275         /* transform system */
276         transform_keymap_for_space(keyconf, keymap, SPACE_NLA);
277         
278         /* special markers hotkeys for anim editors: see note in definition of this function */
279         ED_marker_keymap_animedit_conflictfree(keymap);
280 }
281
282 /* --------------- */
283
284 void nla_keymap(wmKeyConfig *keyconf)
285 {
286         wmKeyMap *keymap;
287         
288         /* keymap for all regions */
289         keymap= WM_keymap_find(keyconf, "NLA Generic", SPACE_NLA, 0);
290         WM_keymap_add_item(keymap, "NLA_OT_properties", NKEY, KM_PRESS, 0, 0);
291         
292         /* channels */
293         /* Channels are not directly handled by the NLA Editor module, but are inherited from the Animation module. 
294          * Most of the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as there
295          * are many similarities with the other Animation Editors.
296          *
297          * However, those operations which involve clicking on channels and/or the placement of them in the view are implemented here instead
298          */
299         keymap= WM_keymap_find(keyconf, "NLA Channels", SPACE_NLA, 0);
300         nla_keymap_channels(keymap);
301         
302         /* data */
303         keymap= WM_keymap_find(keyconf, "NLA Editor", SPACE_NLA, 0);
304         nla_keymap_main(keyconf, keymap);
305 }
306