Merged changes in the trunk up to revision 41368.
[blender.git] / source / blender / editors / animation / anim_filter.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, Joshua Leung
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Joshua Leung (original author)
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/animation/anim_filter.c
28  *  \ingroup edanimation
29  */
30
31
32 /* This file contains a system used to provide a layer of abstraction between sources
33  * of animation data and tools in Animation Editors. The method used here involves 
34  * generating a list of edit structures which enable tools to naively perform the actions 
35  * they require without all the boiler-plate associated with loops within loops and checking 
36  * for cases to ignore. 
37  *
38  * While this is primarily used for the Action/Dopesheet Editor (and its accessory modes),
39  * the Graph Editor also uses this for its channel list and for determining which curves
40  * are being edited. Likewise, the NLA Editor also uses this for its channel list and in
41  * its operators.
42  *
43  * Note: much of the original system this was based on was built before the creation of the RNA
44  * system. In future, it would be interesting to replace some parts of this code with RNA queries,
45  * however, RNA does not eliminate some of the boiler-plate reduction benefits presented by this 
46  * system, so if any such work does occur, it should only be used for the internals used here...
47  *
48  * -- Joshua Leung, Dec 2008 (Last revision July 2009)
49  */
50
51 #include <string.h>
52
53 #include "DNA_anim_types.h"
54 #include "DNA_armature_types.h"
55 #include "DNA_camera_types.h"
56 #include "DNA_lamp_types.h"
57 #include "DNA_lattice_types.h"
58 #include "DNA_linestyle_types.h"
59 #include "DNA_key_types.h"
60 #include "DNA_material_types.h"
61 #include "DNA_mesh_types.h"
62 #include "DNA_meta_types.h"
63 #include "DNA_node_types.h"
64 #include "DNA_particle_types.h"
65 #include "DNA_space_types.h"
66 #include "DNA_sequence_types.h"
67 #include "DNA_scene_types.h"
68 #include "DNA_screen_types.h"
69 #include "DNA_speaker_types.h"
70 #include "DNA_world_types.h"
71 #include "DNA_gpencil_types.h"
72 #include "DNA_object_types.h"
73
74 #include "MEM_guardedalloc.h"
75
76 #include "BLI_blenlib.h"
77 #include "BLI_utildefines.h"
78 #include "BLI_ghash.h"
79
80 #include "BKE_animsys.h"
81 #include "BKE_action.h"
82 #include "BKE_fcurve.h"
83 #include "BKE_context.h"
84 #include "BKE_global.h"
85 #include "BKE_group.h"
86 #include "BKE_key.h"
87 #include "BKE_main.h"
88 #include "BKE_material.h"
89 #include "BKE_node.h"
90 #include "BKE_sequencer.h"
91 #include "BKE_utildefines.h"
92
93 #include "ED_anim_api.h"
94 #include "ED_markers.h"
95
96 /* ************************************************************ */
97 /* Blender Context <-> Animation Context mapping */
98
99 /* ----------- Private Stuff - Action Editor ------------- */
100
101 /* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */
102 /* Note: there's a similar function in key.c (ob_get_key) */
103 static Key *actedit_get_shapekeys (bAnimContext *ac) 
104 {
105         Scene *scene= ac->scene;
106         Object *ob;
107         Key *key;
108         
109         ob = OBACT;
110         if (ob == NULL) 
111                 return NULL;
112         
113         /* XXX pinning is not available in 'ShapeKey' mode... */
114         //if (saction->pin) return NULL;
115         
116         /* shapekey data is stored with geometry data */
117         key= ob_get_key(ob);
118         
119         if (key) {
120                 if (key->type == KEY_RELATIVE)
121                         return key;
122         }
123         
124         return NULL;
125 }
126
127 /* Get data being edited in Action Editor (depending on current 'mode') */
128 static short actedit_get_context (bAnimContext *ac, SpaceAction *saction)
129 {
130         /* get dopesheet */
131         ac->ads = &saction->ads;
132         
133         /* sync settings with current view status, then return appropriate data */
134         switch (saction->mode) {
135                 case SACTCONT_ACTION: /* 'Action Editor' */
136                         /* if not pinned, sync with active object */
137                         if (/*saction->pin == 0*/1) {
138                                 if (ac->obact && ac->obact->adt)
139                                         saction->action = ac->obact->adt->action;
140                                 else
141                                         saction->action= NULL;
142                         }
143                         
144                         ac->datatype= ANIMCONT_ACTION;
145                         ac->data= saction->action;
146                         
147                         ac->mode= saction->mode;
148                         return 1;
149                         
150                 case SACTCONT_SHAPEKEY: /* 'ShapeKey Editor' */
151                         ac->datatype= ANIMCONT_SHAPEKEY;
152                         ac->data= actedit_get_shapekeys(ac);
153                         
154                         ac->mode= saction->mode;
155                         return 1;
156                         
157                 case SACTCONT_GPENCIL: /* Grease Pencil */ // XXX review how this mode is handled...
158                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
159                         saction->ads.source= (ID *)ac->scene;
160                         
161                         ac->datatype= ANIMCONT_GPENCIL;
162                         ac->data= &saction->ads;
163                         
164                         ac->mode= saction->mode;
165                         return 1;
166                         
167                 case SACTCONT_DOPESHEET: /* DopeSheet */
168                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
169                         saction->ads.source= (ID *)ac->scene;
170                         
171                         ac->datatype= ANIMCONT_DOPESHEET;
172                         ac->data= &saction->ads;
173                         
174                         ac->mode= saction->mode;
175                         return 1;
176                 
177                 default: /* unhandled yet */
178                         ac->datatype= ANIMCONT_NONE;
179                         ac->data= NULL;
180                         
181                         ac->mode= -1;
182                         return 0;
183         }
184 }
185
186 /* ----------- Private Stuff - Graph Editor ------------- */
187
188 /* Get data being edited in Graph Editor (depending on current 'mode') */
189 static short graphedit_get_context (bAnimContext *ac, SpaceIpo *sipo)
190 {
191         /* init dopesheet data if non-existant (i.e. for old files) */
192         if (sipo->ads == NULL) {
193                 sipo->ads= MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
194                 sipo->ads->source= (ID *)ac->scene;
195         }
196         ac->ads = sipo->ads;
197         
198         /* set settings for Graph Editor - "Selected = Editable" */
199         if (sipo->flag & SIPO_SELCUVERTSONLY)
200                 sipo->ads->filterflag |= ADS_FILTER_SELEDIT;
201         else
202                 sipo->ads->filterflag &= ~ADS_FILTER_SELEDIT;
203         
204         /* sync settings with current view status, then return appropriate data */
205         switch (sipo->mode) {
206                 case SIPO_MODE_ANIMATION:       /* Animation F-Curve Editor */
207                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
208                         sipo->ads->source= (ID *)ac->scene;
209                         sipo->ads->filterflag &= ~ADS_FILTER_ONLYDRIVERS;
210                         
211                         ac->datatype= ANIMCONT_FCURVES;
212                         ac->data= sipo->ads;
213                         
214                         ac->mode= sipo->mode;
215                         return 1;
216                 
217                 case SIPO_MODE_DRIVERS:         /* Driver F-Curve Editor */
218                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
219                         sipo->ads->source= (ID *)ac->scene;
220                         sipo->ads->filterflag |= ADS_FILTER_ONLYDRIVERS;
221                         
222                         ac->datatype= ANIMCONT_DRIVERS;
223                         ac->data= sipo->ads;
224                         
225                         ac->mode= sipo->mode;
226                         return 1;
227                 
228                 default: /* unhandled yet */
229                         ac->datatype= ANIMCONT_NONE;
230                         ac->data= NULL;
231                         
232                         ac->mode= -1;
233                         return 0;
234         }
235 }
236
237 /* ----------- Private Stuff - NLA Editor ------------- */
238
239 /* Get data being edited in Graph Editor (depending on current 'mode') */
240 static short nlaedit_get_context (bAnimContext *ac, SpaceNla *snla)
241 {
242         /* init dopesheet data if non-existant (i.e. for old files) */
243         if (snla->ads == NULL)
244                 snla->ads= MEM_callocN(sizeof(bDopeSheet), "NlaEdit DopeSheet");
245         ac->ads = snla->ads;
246         
247         /* sync settings with current view status, then return appropriate data */
248         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
249         snla->ads->source= (ID *)ac->scene;
250         snla->ads->filterflag |= ADS_FILTER_ONLYNLA;
251         
252         ac->datatype= ANIMCONT_NLA;
253         ac->data= snla->ads;
254         
255         return 1;
256 }
257
258 /* ----------- Public API --------------- */
259
260 /* Obtain current anim-data context, given that context info from Blender context has already been set 
261  *      - AnimContext to write to is provided as pointer to var on stack so that we don't have
262  *        allocation/freeing costs (which are not that avoidable with channels).
263  */
264 short ANIM_animdata_context_getdata (bAnimContext *ac)
265 {
266         SpaceLink *sl = ac->sl;
267         short ok= 0;
268         
269         /* context depends on editor we are currently in */
270         if (sl) {
271                 switch (ac->spacetype) {
272                         case SPACE_ACTION:
273                         {
274                                 SpaceAction *saction= (SpaceAction *)sl;
275                                 ok= actedit_get_context(ac, saction);
276                         }
277                                 break;
278                                 
279                         case SPACE_IPO:
280                         {
281                                 SpaceIpo *sipo= (SpaceIpo *)sl;
282                                 ok= graphedit_get_context(ac, sipo);
283                         }
284                                 break;
285                                 
286                         case SPACE_NLA:
287                         {
288                                 SpaceNla *snla= (SpaceNla *)sl;
289                                 ok= nlaedit_get_context(ac, snla);
290                         }
291                                 break;
292                 }
293         }
294         
295         /* check if there's any valid data */
296         if (ok && ac->data)
297                 return 1;
298         else
299                 return 0;
300 }
301
302 /* Obtain current anim-data context from Blender Context info 
303  *      - AnimContext to write to is provided as pointer to var on stack so that we don't have
304  *        allocation/freeing costs (which are not that avoidable with channels).
305  *      - Clears data and sets the information from Blender Context which is useful
306  */
307 short ANIM_animdata_get_context (const bContext *C, bAnimContext *ac)
308 {
309         ScrArea *sa= CTX_wm_area(C);
310         ARegion *ar= CTX_wm_region(C);
311         SpaceLink *sl= CTX_wm_space_data(C);
312         Scene *scene= CTX_data_scene(C);
313         
314         /* clear old context info */
315         if (ac == NULL) return 0;
316         memset(ac, 0, sizeof(bAnimContext));
317         
318         /* get useful default context settings from context */
319         ac->scene= scene;
320         if (scene) {
321                 ac->markers= ED_context_get_markers(C);         
322                 ac->obact= (scene->basact)?  scene->basact->object : NULL;
323         }
324         ac->sa= sa;
325         ac->ar= ar;
326         ac->sl= sl;
327         ac->spacetype= (sa) ? sa->spacetype : 0;
328         ac->regiontype= (ar) ? ar->regiontype : 0;
329         
330         /* get data context info */
331         return ANIM_animdata_context_getdata(ac);
332 }
333
334 /* ************************************************************ */
335 /* Blender Data <-- Filter --> Channels to be operated on */
336
337 /* macros to use before/after getting the sub-channels of some channel,
338  * to abstract away some of the tricky logic involved
339  *
340  * cases:
341  *      1) Graph Edit main area (just data) OR channels visible in Channel List
342  *      2) If not showing channels, we're only interested in the data (Action Editor's editing)
343  *      3) We don't care what data, we just care there is some (so that a collapsed 
344  *         channel can be kept around). No need to clear channels-flag in order to 
345  *         keep expander channels with no sub-data out, as those cases should get
346  *         dealt with by the recursive detection idiom in place.
347  *
348  * Implementation Note:
349  *      YES the _doSubChannels variable is NOT read anywhere. BUT, this is NOT an excuse
350  *      to go steamrolling the logic into a single-line expression as from experience,
351  *      those are notoriously difficult to read + debug when extending later on. The code
352  *      below is purposefully laid out so that each case noted above corresponds clearly to
353  *      one case below.
354  */
355 #define BEGIN_ANIMFILTER_SUBCHANNELS(expanded_check) \
356         { \
357                 int _filter = filter_mode; \
358                 short _doSubChannels = 0; \
359                 if (!(filter_mode & ANIMFILTER_LIST_VISIBLE) || (expanded_check)) \
360                         _doSubChannels=1; \
361                 else if (!(filter_mode & ANIMFILTER_LIST_CHANNELS)) \
362                         _doSubChannels=2; \
363                 else {\
364                         filter_mode |= ANIMFILTER_TMP_PEEK; \
365                 } \
366                 (void) _doSubChannels;
367                 /* ... standard sub-channel filtering can go on here now ... */
368 #define END_ANIMFILTER_SUBCHANNELS \
369                 filter_mode = _filter; \
370         }
371
372 /* ............................... */
373
374 /* quick macro to test if AnimData is usable */
375 #define ANIMDATA_HAS_KEYS(id) ((id)->adt && (id)->adt->action)
376
377 /* quick macro to test if AnimData is usable for drivers */
378 #define ANIMDATA_HAS_DRIVERS(id) ((id)->adt && (id)->adt->drivers.first)
379
380 /* quick macro to test if AnimData is usable for NLA */
381 #define ANIMDATA_HAS_NLA(id) ((id)->adt && (id)->adt->nla_tracks.first)
382
383 /* Quick macro to test for all three above usability tests, performing the appropriate provided 
384  * action for each when the AnimData context is appropriate. 
385  *
386  * Priority order for this goes (most important, to least): AnimData blocks, NLA, Drivers, Keyframes.
387  *
388  * For this to work correctly, a standard set of data needs to be available within the scope that this
389  * gets called in: 
390  *      - ListBase anim_data;
391  *      - bDopeSheet *ads;
392  *      - bAnimListElem *ale;
393  *      - size_t items;
394  *
395  *      - id: ID block which should have an AnimData pointer following it immediately, to use
396  *      - adtOk: line or block of code to execute for AnimData-blocks case (usually ANIMDATA_ADD_ANIMDATA)
397  *      - nlaOk: line or block of code to execute for NLA tracks+strips case
398  *      - driversOk: line or block of code to execute for Drivers case
399  *      - keysOk: line or block of code for Keyframes case
400  *
401  * The checks for the various cases are as follows:
402  *      0) top level: checks for animdata and also that all the F-Curves for the block will be visible
403  *      1) animdata check: for filtering animdata blocks only
404  *      2A) nla tracks: include animdata block's data as there are NLA tracks+strips there
405  *      2B) actions to convert to nla: include animdata block's data as there is an action that can be 
406  *              converted to a new NLA strip, and the filtering options allow this
407  *      2C) allow non-animated datablocks to be included so that datablocks can be added
408  *      3) drivers: include drivers from animdata block (for Drivers mode in Graph Editor)
409  *      4) normal keyframes: only when there is an active action
410  */
411 #define ANIMDATA_FILTER_CASES(id, adtOk, nlaOk, driversOk, keysOk) \
412         {\
413                 if ((id)->adt) {\
414                         if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || !((id)->adt->flag & ADT_CURVES_NOT_VISIBLE)) {\
415                                 if (filter_mode & ANIMFILTER_ANIMDATA) {\
416                                         adtOk\
417                                 }\
418                                 else if (ads->filterflag & ADS_FILTER_ONLYNLA) {\
419                                         if (ANIMDATA_HAS_NLA(id)) {\
420                                                 nlaOk\
421                                         }\
422                                         else if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) && ANIMDATA_HAS_KEYS(id)) {\
423                                                 nlaOk\
424                                         }\
425                                 }\
426                                 else if (ads->filterflag & ADS_FILTER_ONLYDRIVERS) {\
427                                         if (ANIMDATA_HAS_DRIVERS(id)) {\
428                                                 driversOk\
429                                         }\
430                                 }\
431                                 else {\
432                                         if (ANIMDATA_HAS_KEYS(id)) {\
433                                                 keysOk\
434                                         }\
435                                 }\
436                         }\
437                 }\
438         }
439
440 /* ............................... */
441
442 /* Add a new animation channel, taking into account the "peek" flag, which is used to just check 
443  * whether any channels will be added (but without needing them to actually get created).
444  *
445  * ! This causes the calling function to return early if we're only "peeking" for channels
446  */
447 // XXX: ale_statement stuff is really a hack for one special case. It shouldn't really be needed...
448 #define ANIMCHANNEL_NEW_CHANNEL_FULL(channel_data, channel_type, owner_id, ale_statement) \
449         if (filter_mode & ANIMFILTER_TMP_PEEK) \
450                 return 1; \
451         else { \
452                 bAnimListElem *ale= make_new_animlistelem(channel_data, channel_type, (ID *)owner_id); \
453                 if (ale) {\
454                         BLI_addtail(anim_data, ale); \
455                         items++; \
456                         ale_statement \
457                 } \
458         }
459         
460 #define ANIMCHANNEL_NEW_CHANNEL(channel_data, channel_type, owner_id) \
461         ANIMCHANNEL_NEW_CHANNEL_FULL(channel_data, channel_type, owner_id, {})
462         
463 /* ............................... */
464         
465 /* quick macro to test if an anim-channel representing an AnimData block is suitably active */
466 #define ANIMCHANNEL_ACTIVEOK(ale) \
467         ( !(filter_mode & ANIMFILTER_ACTIVE) || !(ale->adt) || (ale->adt->flag & ADT_UI_ACTIVE) )
468
469 /* quick macro to test if an anim-channel (F-Curve, Group, etc.) is selected in an acceptable way */
470 #define ANIMCHANNEL_SELOK(test_func) \
471                 ( !(filter_mode & (ANIMFILTER_SEL|ANIMFILTER_UNSEL)) || \
472                   ((filter_mode & ANIMFILTER_SEL) && test_func) || \
473                   ((filter_mode & ANIMFILTER_UNSEL) && test_func==0) ) 
474                   
475 /* quick macro to test if an anim-channel (F-Curve) is selected ok for editing purposes 
476  *      - _SELEDIT means that only selected curves will have visible+editable keyframes
477  *
478  * checks here work as follows:
479  *      1) seledit off - don't need to consider the implications of this option
480  *      2) foredit off - we're not considering editing, so channel is ok still
481  *      3) test_func (i.e. selection test) - only if selected, this test will pass
482  */
483 #define ANIMCHANNEL_SELEDITOK(test_func) \
484                 ( !(filter_mode & ANIMFILTER_SELEDIT) || \
485                   !(filter_mode & ANIMFILTER_FOREDIT) || \
486                   (test_func) )
487
488 /* ----------- 'Private' Stuff --------------- */
489
490 /* this function allocates memory for a new bAnimListElem struct for the 
491  * provided animation channel-data. 
492  */
493 static bAnimListElem *make_new_animlistelem (void *data, short datatype, ID *owner_id)
494 {
495         bAnimListElem *ale= NULL;
496         
497         /* only allocate memory if there is data to convert */
498         if (data) {
499                 /* allocate and set generic data */
500                 ale= MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
501                 
502                 ale->data= data;
503                 ale->type= datatype;
504                 
505                 ale->id= owner_id;
506                 ale->adt= BKE_animdata_from_id(owner_id);
507                 
508                 /* do specifics */
509                 switch (datatype) {
510                         case ANIMTYPE_SUMMARY:
511                         {
512                                 /* nothing to include for now... this is just a dummy wrappy around all the other channels 
513                                  * in the DopeSheet, and gets included at the start of the list
514                                  */
515                                 ale->key_data= NULL;
516                                 ale->datatype= ALE_ALL;
517                         }
518                                 break;
519                         
520                         case ANIMTYPE_SCENE:
521                         {
522                                 Scene *sce= (Scene *)data;
523                                 
524                                 ale->flag= sce->flag;
525                                 
526                                 ale->key_data= sce;
527                                 ale->datatype= ALE_SCE;
528                                 
529                                 ale->adt= BKE_animdata_from_id(data);
530                         }
531                                 break;
532                         case ANIMTYPE_OBJECT:
533                         {
534                                 Base *base= (Base *)data;
535                                 Object *ob= base->object;
536                                 
537                                 ale->flag= ob->flag;
538                                 
539                                 ale->key_data= ob;
540                                 ale->datatype= ALE_OB;
541                                 
542                                 ale->adt= BKE_animdata_from_id(&ob->id);
543                         }
544                                 break;
545                         case ANIMTYPE_FILLACTD:
546                         {
547                                 bAction *act= (bAction *)data;
548                                 
549                                 ale->flag= act->flag;
550                                 
551                                 ale->key_data= act;
552                                 ale->datatype= ALE_ACT;
553                         }
554                                 break;
555                         case ANIMTYPE_FILLDRIVERS:
556                         {
557                                 AnimData *adt= (AnimData *)data;
558                                 
559                                 ale->flag= adt->flag;
560                                 
561                                         // XXX... drivers don't show summary for now
562                                 ale->key_data= NULL;
563                                 ale->datatype= ALE_NONE;
564                         }
565                                 break;
566                         
567                         case ANIMTYPE_DSMAT:
568                         {
569                                 Material *ma= (Material *)data;
570                                 AnimData *adt= ma->adt;
571                                 
572                                 ale->flag= FILTER_MAT_OBJD(ma);
573                                 
574                                 ale->key_data= (adt) ? adt->action : NULL;
575                                 ale->datatype= ALE_ACT;
576                                 
577                                 ale->adt= BKE_animdata_from_id(data);
578                         }
579                                 break;
580                         case ANIMTYPE_DSLAM:
581                         {
582                                 Lamp *la= (Lamp *)data;
583                                 AnimData *adt= la->adt;
584                                 
585                                 ale->flag= FILTER_LAM_OBJD(la);
586                                 
587                                 ale->key_data= (adt) ? adt->action : NULL;
588                                 ale->datatype= ALE_ACT;
589                                 
590                                 ale->adt= BKE_animdata_from_id(data);
591                         }
592                                 break;
593                         case ANIMTYPE_DSCAM:
594                         {
595                                 Camera *ca= (Camera *)data;
596                                 AnimData *adt= ca->adt;
597                                 
598                                 ale->flag= FILTER_CAM_OBJD(ca);
599                                 
600                                 ale->key_data= (adt) ? adt->action : NULL;
601                                 ale->datatype= ALE_ACT;
602                                 
603                                 ale->adt= BKE_animdata_from_id(data);
604                         }
605                                 break;
606                         case ANIMTYPE_DSCUR:
607                         {
608                                 Curve *cu= (Curve *)data;
609                                 AnimData *adt= cu->adt;
610                                 
611                                 ale->flag= FILTER_CUR_OBJD(cu);
612                                 
613                                 ale->key_data= (adt) ? adt->action : NULL;
614                                 ale->datatype= ALE_ACT;
615                                 
616                                 ale->adt= BKE_animdata_from_id(data);
617                         }
618                                 break;
619                         case ANIMTYPE_DSARM:
620                         {
621                                 bArmature *arm= (bArmature *)data;
622                                 AnimData *adt= arm->adt;
623                                 
624                                 ale->flag= FILTER_ARM_OBJD(arm);
625                                 
626                                 ale->key_data= (adt) ? adt->action : NULL;
627                                 ale->datatype= ALE_ACT;
628                                 
629                                 ale->adt= BKE_animdata_from_id(data);
630                         }
631                                 break;
632                         case ANIMTYPE_DSMESH:
633                         {
634                                 Mesh *me= (Mesh *)data;
635                                 AnimData *adt= me->adt;
636                                 
637                                 ale->flag= FILTER_MESH_OBJD(me);
638                                 
639                                 ale->key_data= (adt) ? adt->action : NULL;
640                                 ale->datatype= ALE_ACT;
641                                 
642                                 ale->adt= BKE_animdata_from_id(data);
643                         }
644                                 break;
645                         case ANIMTYPE_DSLAT:
646                         {
647                                 Lattice *lt= (Lattice *)data;
648                                 AnimData *adt= lt->adt;
649                                 
650                                 ale->flag= FILTER_LATTICE_OBJD(lt);
651                                 
652                                 ale->key_data= (adt) ? adt->action : NULL;
653                                 ale->datatype= ALE_ACT;
654                                 
655                                 ale->adt= BKE_animdata_from_id(data);
656                         }       
657                                 break;
658                         case ANIMTYPE_DSSPK:
659                         {
660                                 Speaker *spk= (Speaker *)data;
661                                 AnimData *adt= spk->adt;
662
663                                 ale->flag= FILTER_SPK_OBJD(spk);
664
665                                 ale->key_data= (adt) ? adt->action : NULL;
666                                 ale->datatype= ALE_ACT;
667
668                                 ale->adt= BKE_animdata_from_id(data);
669                         }
670                                 break;
671                         case ANIMTYPE_DSSKEY:
672                         {
673                                 Key *key= (Key *)data;
674                                 AnimData *adt= key->adt;
675                                 
676                                 ale->flag= FILTER_SKE_OBJD(key); 
677                                 
678                                 ale->key_data= (adt) ? adt->action : NULL;
679                                 ale->datatype= ALE_ACT;
680                                 
681                                 ale->adt= BKE_animdata_from_id(data);
682                         }
683                                 break;
684                         case ANIMTYPE_DSWOR:
685                         {
686                                 World *wo= (World *)data;
687                                 AnimData *adt= wo->adt;
688                                 
689                                 ale->flag= FILTER_WOR_SCED(wo); 
690                                 
691                                 ale->key_data= (adt) ? adt->action : NULL;
692                                 ale->datatype= ALE_ACT;
693                                 
694                                 ale->adt= BKE_animdata_from_id(data);
695                         }
696                                 break;
697                         case ANIMTYPE_DSNTREE:
698                         {
699                                 bNodeTree *ntree= (bNodeTree *)data;
700                                 AnimData *adt= ntree->adt;
701                                 
702                                 ale->flag= FILTER_NTREE_DATA(ntree); 
703                                 
704                                 ale->key_data= (adt) ? adt->action : NULL;
705                                 ale->datatype= ALE_ACT;
706                                 
707                                 ale->adt= BKE_animdata_from_id(data);
708                         }
709                                 break;
710                         case ANIMTYPE_DSLINESTYLE:
711                         {
712                                 FreestyleLineStyle *linestyle= (FreestyleLineStyle *)data;
713                                 AnimData *adt= linestyle->adt;
714                                 
715                                 ale->flag= FILTER_LS_SCED(linestyle); 
716                                 
717                                 ale->key_data= (adt) ? adt->action : NULL;
718                                 ale->datatype= ALE_ACT;
719                                 
720                                 ale->adt= BKE_animdata_from_id(data);
721                         }
722                                 break;
723                         case ANIMTYPE_DSPART:
724                         {
725                                 ParticleSettings *part= (ParticleSettings*)ale->data;
726                                 AnimData *adt= part->adt;
727                                 
728                                 ale->flag= FILTER_PART_OBJD(part); 
729                                 
730                                 ale->key_data= (adt) ? adt->action : NULL;
731                                 ale->datatype= ALE_ACT;
732                                 
733                                 ale->adt= BKE_animdata_from_id(data);
734                         }
735                                 break;
736                         case ANIMTYPE_DSTEX:
737                         {
738                                 Tex *tex= (Tex *)data;
739                                 AnimData *adt= tex->adt;
740                                 
741                                 ale->flag= FILTER_TEX_DATA(tex); 
742                                 
743                                 ale->key_data= (adt) ? adt->action : NULL;
744                                 ale->datatype= ALE_ACT;
745                                 
746                                 ale->adt= BKE_animdata_from_id(data);
747                         }
748                                 break;
749                                 
750                         case ANIMTYPE_GROUP:
751                         {
752                                 bActionGroup *agrp= (bActionGroup *)data;
753                                 
754                                 ale->flag= agrp->flag;
755                                 
756                                 ale->key_data= NULL;
757                                 ale->datatype= ALE_GROUP;
758                         }
759                                 break;
760                         case ANIMTYPE_FCURVE:
761                         {
762                                 FCurve *fcu= (FCurve *)data;
763                                 
764                                 ale->flag= fcu->flag;
765                                 
766                                 ale->key_data= fcu;
767                                 ale->datatype= ALE_FCURVE;
768                         }
769                                 break;
770                                 
771                         case ANIMTYPE_SHAPEKEY:
772                         {
773                                 KeyBlock *kb= (KeyBlock *)data;
774                                 Key *key= (Key *)ale->id;
775                                 
776                                 ale->flag= kb->flag;
777                                 
778                                 /* whether we have keyframes depends on whether there is a Key block to find it from */
779                                 if (key) {
780                                         /* index of shapekey is defined by place in key's list */
781                                         ale->index= BLI_findindex(&key->block, kb);
782                                         
783                                         /* the corresponding keyframes are from the animdata */
784                                         if (ale->adt && ale->adt->action) {
785                                                 bAction *act= ale->adt->action;
786                                                 char *rna_path = key_get_curValue_rnaPath(key, kb);
787                                                 
788                                                 /* try to find the F-Curve which corresponds to this exactly,
789                                                  * then free the MEM_alloc'd string
790                                                  */
791                                                 if (rna_path) {
792                                                         ale->key_data= (void *)list_find_fcurve(&act->curves, rna_path, 0);
793                                                         MEM_freeN(rna_path);
794                                                 }
795                                         }
796                                         ale->datatype= (ale->key_data)? ALE_FCURVE : ALE_NONE;
797                                 }
798                         }       
799                                 break;
800                         
801                         case ANIMTYPE_GPLAYER:
802                         {
803                                 bGPDlayer *gpl= (bGPDlayer *)data;
804                                 
805                                 ale->flag= gpl->flag;
806                                 
807                                 ale->key_data= NULL;
808                                 ale->datatype= ALE_GPFRAME;
809                         }
810                                 break;
811                                 
812                         case ANIMTYPE_NLATRACK:
813                         {
814                                 NlaTrack *nlt= (NlaTrack *)data;
815                                 
816                                 ale->flag= nlt->flag;
817                                 
818                                 ale->key_data= &nlt->strips;
819                                 ale->datatype= ALE_NLASTRIP;
820                         }
821                                 break;
822                         case ANIMTYPE_NLAACTION:
823                         {
824                                 /* nothing to include for now... nothing editable from NLA-perspective here */
825                                 ale->key_data= NULL;
826                                 ale->datatype= ALE_NONE;
827                         }
828                                 break;
829                 }
830         }
831         
832         /* return created datatype */
833         return ale;
834 }
835  
836 /* ----------------------------------------- */
837
838 /* 'Only Selected' selected data filtering
839  * NOTE: when this function returns true, the F-Curve is to be skipped 
840  */
841 static size_t skip_fcurve_selected_data (bDopeSheet *ads, FCurve *fcu, ID *owner_id, int filter_mode)
842 {
843         if (GS(owner_id->name) == ID_OB) {
844                 Object *ob= (Object *)owner_id;
845                 
846                 /* only consider if F-Curve involves pose.bones */
847                 if ((fcu->rna_path) && strstr(fcu->rna_path, "pose.bones")) {
848                         bPoseChannel *pchan;
849                         char *bone_name;
850                         
851                         /* get bone-name, and check if this bone is selected */
852                         bone_name= BLI_getQuotedStr(fcu->rna_path, "pose.bones[");
853                         pchan= get_pose_channel(ob->pose, bone_name);
854                         if (bone_name) MEM_freeN(bone_name);
855                         
856                         /* check whether to continue or skip */
857                         if ((pchan) && (pchan->bone)) {
858                                 /* if only visible channels, skip if bone not visible unless user wants channels from hidden data too */
859                                 if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
860                                         bArmature *arm= (bArmature *)ob->data;
861                                         
862                                         if ((arm->layer & pchan->bone->layer) == 0)
863                                                 return 1;
864                                         // TODO: manually hidden using flags
865                                 }
866                                 
867                                 /* can only add this F-Curve if it is selected */
868                                 if ((pchan->bone->flag & BONE_SELECTED) == 0)
869                                         return 1;
870                         }
871                 }
872         }
873         else if (GS(owner_id->name) == ID_SCE) {
874                 Scene *scene = (Scene *)owner_id;
875                 
876                 /* only consider if F-Curve involves sequence_editor.sequences */
877                 if ((fcu->rna_path) && strstr(fcu->rna_path, "sequences_all")) {
878                         Editing *ed= seq_give_editing(scene, FALSE);
879                         Sequence *seq;
880                         char *seq_name;
881                         
882                         /* get strip name, and check if this strip is selected */
883                         seq_name= BLI_getQuotedStr(fcu->rna_path, "sequences_all[");
884                         seq = get_seq_by_name(ed->seqbasep, seq_name, FALSE);
885                         if (seq_name) MEM_freeN(seq_name);
886                         
887                         /* can only add this F-Curve if it is selected */
888                         if (seq==NULL || (seq->flag & SELECT)==0)
889                                 return 1;
890                 }
891         }
892         else if (GS(owner_id->name) == ID_NT) {
893                 bNodeTree *ntree = (bNodeTree *)owner_id;
894                 
895                 /* check for selected  nodes */
896                 if ((fcu->rna_path) && strstr(fcu->rna_path, "nodes")) {
897                         bNode *node;
898                         char *node_name;
899                         
900                         /* get strip name, and check if this strip is selected */
901                         node_name= BLI_getQuotedStr(fcu->rna_path, "nodes[");
902                         node = nodeFindNodebyName(ntree, node_name);
903                         if (node_name) MEM_freeN(node_name);
904                         
905                         /* can only add this F-Curve if it is selected */
906                         if ((node) && (node->flag & NODE_SELECT)==0)
907                                 return 1;
908                 }
909         }
910         return 0;
911 }
912
913 /* (Display-)Name-based F-Curve filtering
914  * NOTE: when this function returns true, the F-Curve is to be skipped 
915  */
916 static short skip_fcurve_with_name (bDopeSheet *ads, FCurve *fcu, ID *owner_id)
917 {
918         bAnimListElem ale_dummy = {NULL};
919         bAnimChannelType *acf;
920         
921         /* create a dummy wrapper for the F-Curve */
922         ale_dummy.type = ANIMTYPE_FCURVE;
923         ale_dummy.id = owner_id;
924         ale_dummy.data = fcu;
925         
926         /* get type info for channel */
927         acf = ANIM_channel_get_typeinfo(&ale_dummy);
928         if (acf && acf->name) {
929                 char name[256]; /* hopefully this will be enough! */
930                 
931                 /* get name */
932                 acf->name(&ale_dummy, name);
933                 
934                 /* check for partial match with the match string, assuming case insensitive filtering 
935                  * if match, this channel shouldn't be ignored!
936                  */
937                 return BLI_strcasestr(name, ads->searchstr) == NULL;
938         }
939         
940         /* just let this go... */
941         return 1;
942 }
943
944 /* find the next F-Curve that is usable for inclusion */
945 static FCurve *animfilter_fcurve_next (bDopeSheet *ads, FCurve *first, bActionGroup *grp, int filter_mode, ID *owner_id)
946 {
947         FCurve *fcu = NULL;
948         
949         /* loop over F-Curves - assume that the caller of this has already checked that these should be included 
950          * NOTE: we need to check if the F-Curves belong to the same group, as this gets called for groups too...
951          */
952         for (fcu= first; ((fcu) && (fcu->grp==grp)); fcu= fcu->next) {
953                 /* special exception for Pose-Channel/Sequence-Strip/Node Based F-Curves:
954                  *      - the 'Only Selected' data filter should be applied to Pose-Channel data too, but those are
955                  *        represented as F-Curves. The way the filter for objects worked was to be the first check
956                  *        after 'normal' visibility, so this is done first here too...
957                  *      - we currently use an 'approximate' method for getting these F-Curves that doesn't require
958                  *        carefully checking the entire path
959                  *      - this will also affect things like Drivers, and also works for Bone Constraints
960                  */
961                 if ( ((ads) && (ads->filterflag & ADS_FILTER_ONLYSEL)) && (owner_id) ) {
962                         if (skip_fcurve_selected_data(ads, fcu, owner_id, filter_mode))
963                                 continue;
964                 }
965                 
966                 /* only include if visible (Graph Editor check, not channels check) */
967                 if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || (fcu->flag & FCURVE_VISIBLE)) {
968                         /* only work with this channel and its subchannels if it is editable */
969                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_FCU(fcu)) {
970                                 /* only include this curve if selected in a way consistent with the filtering requirements */
971                                 if ( ANIMCHANNEL_SELOK(SEL_FCU(fcu)) && ANIMCHANNEL_SELEDITOK(SEL_FCU(fcu)) ) {
972                                         /* only include if this curve is active */
973                                         if (!(filter_mode & ANIMFILTER_ACTIVE) || (fcu->flag & FCURVE_ACTIVE)) {
974                                                 /* name based filtering... */
975                                                 if ( ((ads) && (ads->filterflag & ADS_FILTER_BY_FCU_NAME)) && (owner_id) ) {
976                                                         if (skip_fcurve_with_name(ads, fcu, owner_id))
977                                                                 continue;
978                                                 }
979                                                 
980                                                 /* this F-Curve can be used, so return it */
981                                                 return fcu;
982                                         }
983                                 }
984                         }
985                 }
986         }
987         
988         /* no (more) F-Curves from the list are suitable... */
989         return NULL;
990 }
991
992 static size_t animfilter_fcurves (ListBase *anim_data, bDopeSheet *ads, FCurve *first, bActionGroup *grp, int filter_mode, ID *owner_id)
993 {
994         FCurve *fcu;
995         size_t items = 0;
996         
997         /* loop over every F-Curve able to be included 
998          *      - this for-loop works like this: 
999          *              1) the starting F-Curve is assigned to the fcu pointer so that we have a starting point to search from
1000          *              2) the first valid F-Curve to start from (which may include the one given as 'first') in the remaining 
1001          *                 list of F-Curves is found, and verified to be non-null
1002          *              3) the F-Curve referenced by fcu pointer is added to the list
1003          *              4) the fcu pointer is set to the F-Curve after the one we just added, so that we can keep going through 
1004          *                 the rest of the F-Curve list without an eternal loop. Back to step 2 :)
1005          */
1006         for (fcu=first; ( (fcu = animfilter_fcurve_next(ads, fcu, grp, filter_mode, owner_id)) ); fcu=fcu->next)
1007         {
1008                 ANIMCHANNEL_NEW_CHANNEL(fcu, ANIMTYPE_FCURVE, owner_id);
1009         }
1010         
1011         /* return the number of items added to the list */
1012         return items;
1013 }
1014
1015 static size_t animfilter_act_group (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bAction *UNUSED(act), bActionGroup *agrp, int filter_mode, ID *owner_id)
1016 {
1017         ListBase tmp_data = {NULL, NULL};
1018         size_t tmp_items = 0;
1019         size_t items = 0;
1020         //int ofilter = filter_mode;
1021         
1022         /* if we care about the selection status of the channels, 
1023          * but the group isn't expanded (1)...
1024          *      (1) this only matters if we actually care about the hierarchy though.
1025          *              - Hierarchy matters: this hack should be applied
1026          *              - Hierarchy ignored: cases like [#21276] won't work properly, unless we skip this hack
1027          */
1028         if ( ((filter_mode & ANIMFILTER_LIST_VISIBLE) && EXPANDED_AGRP(ac, agrp)==0) &&         /* care about hierarchy but group isn't expanded */
1029                   (filter_mode & (ANIMFILTER_SEL|ANIMFILTER_UNSEL)) )                                                   /* care about selection status */        
1030         {
1031                 /* if the group itself isn't selected appropriately, we shouldn't consider it's children either */
1032                 if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) == 0)
1033                         return 0;
1034                 
1035                 /* if we're still here, then the selection status of the curves within this group should not matter,
1036                  * since this creates too much overhead for animators (i.e. making a slow workflow)
1037                  *
1038                  * Tools affected by this at time of coding (2010 Feb 09):
1039                  *      - inserting keyframes on selected channels only
1040                  *      - pasting keyframes
1041                  *      - creating ghost curves in Graph Editor
1042                  */
1043                 filter_mode &= ~(ANIMFILTER_SEL|ANIMFILTER_UNSEL|ANIMFILTER_LIST_VISIBLE);
1044         }
1045         
1046         /* add grouped F-Curves */
1047         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_AGRP(ac, agrp))
1048         {
1049                 /* special filter so that we can get just the F-Curves within the active group */
1050                 if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
1051                         /* for the Graph Editor, curves may be set to not be visible in the view to lessen clutter,
1052                          * but to do this, we need to check that the group doesn't have it's not-visible flag set preventing 
1053                          * all its sub-curves to be shown
1054                          */
1055                         if ( !(filter_mode & ANIMFILTER_CURVE_VISIBLE) || !(agrp->flag & AGRP_NOTVISIBLE) )
1056                         {
1057                                 /* group must be editable for its children to be editable (if we care about this) */
1058                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {
1059                                         /* get first F-Curve which can be used here */
1060                                         FCurve *first_fcu = animfilter_fcurve_next(ads, agrp->channels.first, agrp, filter_mode, owner_id);
1061                                         
1062                                         /* filter list, starting from this F-Curve */
1063                                         tmp_items += animfilter_fcurves(&tmp_data, ads, first_fcu, agrp, filter_mode, owner_id);
1064                                 }
1065                         }
1066                 }
1067         }
1068         END_ANIMFILTER_SUBCHANNELS;
1069         
1070         /* did we find anything? */
1071         if (tmp_items) {
1072                 /* add this group as a channel first */
1073                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1074                         /* restore original filter mode so that this next step works ok... */
1075                         //filter_mode = ofilter;
1076                         
1077                         /* filter selection of channel specially here again, since may be open and not subject to previous test */
1078                         if ( ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) ) {
1079                                 ANIMCHANNEL_NEW_CHANNEL(agrp, ANIMTYPE_GROUP, owner_id);
1080                         }
1081                 }
1082                 
1083                 /* now add the list of collected channels */
1084                 BLI_movelisttolist(anim_data, &tmp_data);
1085                 BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1086                 items += tmp_items;
1087         }
1088         
1089         /* return the number of items added to the list */
1090         return items;
1091 }
1092
1093 static size_t animfilter_action (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bAction *act, int filter_mode, ID *owner_id)
1094 {
1095         bActionGroup *agrp;
1096         FCurve *lastchan = NULL;
1097         size_t items = 0;
1098         
1099         /* don't include anything from this action if it is linked in from another file,
1100          * and we're getting stuff for editing...
1101          */
1102         // TODO: need a way of tagging other channels that may also be affected...
1103         if ((filter_mode & ANIMFILTER_FOREDIT) && (act->id.lib))
1104                 return 0;
1105                 
1106         /* do groups */
1107         // TODO: do nested groups?
1108         for (agrp = act->groups.first; agrp; agrp = agrp->next) {
1109                 /* store reference to last channel of group */
1110                 if (agrp->channels.last) 
1111                         lastchan= agrp->channels.last;
1112                         
1113                 /* action group's channels */
1114                 items += animfilter_act_group(ac, anim_data, ads, act, agrp, filter_mode, owner_id);
1115         }
1116         
1117         /* un-grouped F-Curves (only if we're not only considering those channels in the active group) */
1118         if (!(filter_mode & ANIMFILTER_ACTGROUPED))  {
1119                 FCurve *firstfcu = (lastchan)? (lastchan->next) : (act->curves.first);
1120                 items += animfilter_fcurves(anim_data, ads, firstfcu, NULL, filter_mode, owner_id);
1121         }
1122         
1123         /* return the number of items added to the list */
1124         return items;
1125 }
1126
1127 /* Include NLA-Data for NLA-Editor:
1128  *      - when ANIMFILTER_LIST_CHANNELS is used, that means we should be filtering the list for display
1129  *        Although the evaluation order is from the first track to the last and then apply the Action on top,
1130  *        we present this in the UI as the Active Action followed by the last track to the first so that we 
1131  *        get the evaluation order presented as per a stack.
1132  *      - for normal filtering (i.e. for editing), we only need the NLA-tracks but they can be in 'normal' evaluation
1133  *        order, i.e. first to last. Otherwise, some tools may get screwed up.
1134  */
1135 static size_t animfilter_nla (bAnimContext *UNUSED(ac), ListBase *anim_data, bDopeSheet *ads, AnimData *adt, int filter_mode, ID *owner_id)
1136 {
1137         NlaTrack *nlt;
1138         NlaTrack *first=NULL, *next=NULL;
1139         size_t items = 0;
1140         
1141         /* if showing channels, include active action */
1142         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1143                 /* if NLA action-line filtering is off, don't show unless there are keyframes, 
1144                  * in order to keep things more compact for doing transforms
1145                  */
1146                 if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || (adt->action)) {
1147                         /* there isn't really anything editable here, so skip if need editable */
1148                         if ((filter_mode & ANIMFILTER_FOREDIT) == 0) { 
1149                                 /* just add the action track now (this MUST appear for drawing)
1150                                  *      - as AnimData may not have an action, we pass a dummy pointer just to get the list elem created, then
1151                                  *        overwrite this with the real value - REVIEW THIS...
1152                                  */
1153                                 ANIMCHANNEL_NEW_CHANNEL_FULL((void *)(&adt->action), ANIMTYPE_NLAACTION, owner_id, 
1154                                         {
1155                                                 ale->data= adt->action ? adt->action : NULL; 
1156                                         });
1157                         }
1158                 }
1159                 
1160                 /* first track to include will be the last one if we're filtering by channels */
1161                 first= adt->nla_tracks.last;
1162         }
1163         else {
1164                 /* first track to include will the the first one (as per normal) */
1165                 first= adt->nla_tracks.first;
1166         }
1167         
1168         /* loop over NLA Tracks - assume that the caller of this has already checked that these should be included */
1169         for (nlt= first; nlt; nlt= next) {
1170                 /* 'next' NLA-Track to use depends on whether we're filtering for drawing or not */
1171                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) 
1172                         next= nlt->prev;
1173                 else
1174                         next= nlt->next;
1175                 
1176                 /* if we're in NLA-tweakmode, don't show this track if it was disabled (due to tweaking) for now 
1177                  *      - active track should still get shown though (even though it has disabled flag set)
1178                  */
1179                 // FIXME: the channels after should still get drawn, just 'differently', and after an active-action channel
1180                 if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED) && !(nlt->flag & NLATRACK_ACTIVE))
1181                         continue;
1182                 
1183                 /* only work with this channel and its subchannels if it is editable */
1184                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_NLT(nlt)) {
1185                         /* only include this track if selected in a way consistent with the filtering requirements */
1186                         if ( ANIMCHANNEL_SELOK(SEL_NLT(nlt)) ) {
1187                                 /* only include if this track is active */
1188                                 if (!(filter_mode & ANIMFILTER_ACTIVE) || (nlt->flag & NLATRACK_ACTIVE)) {
1189                                         ANIMCHANNEL_NEW_CHANNEL(nlt, ANIMTYPE_NLATRACK, owner_id);
1190                                 }
1191                         }
1192                 }
1193         }
1194         
1195         /* return the number of items added to the list */
1196         return items;
1197 }
1198
1199 /* determine what animation data from AnimData block should get displayed */
1200 static size_t animfilter_block_data (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *id, int filter_mode)
1201 {
1202         AnimData *adt = BKE_animdata_from_id(id);
1203         size_t items = 0;
1204
1205         /* image object datablocks have no anim-data so check for NULL */
1206         if(adt) {
1207                 IdAdtTemplate *iat = (IdAdtTemplate*)id;
1208
1209                 /* NOTE: this macro is used instead of inlining the logic here, since this sort of filtering is still needed
1210                  * in a few places in he rest of the code still - notably for the few cases where special mode-based
1211                  * different types of data expanders are required.
1212                  */
1213                 ANIMDATA_FILTER_CASES(iat,
1214                         { /* AnimData */
1215                                 /* specifically filter animdata block */
1216                                 ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_ANIMDATA, id);
1217                         },
1218                         { /* NLA */
1219                                 items += animfilter_nla(ac, anim_data, ads, adt, filter_mode, id);
1220                         },
1221                         { /* Drivers */
1222                                 items += animfilter_fcurves(anim_data, ads, adt->drivers.first, NULL, filter_mode, id);
1223                         },
1224                         { /* Keyframes */
1225                                 items += animfilter_action(ac, anim_data, ads, adt->action, filter_mode, id);
1226                         }
1227                 );
1228         }
1229
1230         return items;
1231 }
1232
1233
1234
1235 /* Include ShapeKey Data for ShapeKey Editor */
1236 static size_t animdata_filter_shapekey (bAnimContext *ac, ListBase *anim_data, Key *key, int filter_mode)
1237 {
1238         size_t items = 0;
1239         
1240         /* check if channels or only F-Curves */
1241         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1242                 KeyBlock *kb;
1243                 
1244                 /* loop through the channels adding ShapeKeys as appropriate */
1245                 for (kb= key->block.first; kb; kb= kb->next) {
1246                         /* skip the first one, since that's the non-animateable basis */
1247                         // XXX maybe in future this may become handy?
1248                         if (kb == key->block.first) continue;
1249                         
1250                         /* only work with this channel and its subchannels if it is editable */
1251                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_SHAPEKEY(kb)) {
1252                                 /* only include this track if selected in a way consistent with the filtering requirements */
1253                                 if ( ANIMCHANNEL_SELOK(SEL_SHAPEKEY(kb)) ) {
1254                                         // TODO: consider 'active' too?
1255                                         
1256                                         /* owner-id here must be key so that the F-Curve can be resolved... */
1257                                         ANIMCHANNEL_NEW_CHANNEL(kb, ANIMTYPE_SHAPEKEY, key);
1258                                 }
1259                         }
1260                 }
1261         }
1262         else {
1263                 /* just use the action associated with the shapekey */
1264                 // TODO: somehow manage to pass dopesheet info down here too?
1265                 if (key->adt) {
1266                         if (filter_mode & ANIMFILTER_ANIMDATA) {
1267                                 ANIMCHANNEL_NEW_CHANNEL(key->adt, ANIMTYPE_ANIMDATA, key);
1268                         }
1269                         else if (key->adt->action) {
1270                                 items= animfilter_action(ac, anim_data, NULL, key->adt->action, filter_mode, (ID *)key);
1271                         }
1272                 }
1273         }
1274         
1275         /* return the number of items added to the list */
1276         return items;
1277 }
1278
1279 static size_t animdata_filter_gpencil_data (ListBase *anim_data, bGPdata *gpd, int filter_mode)
1280 {
1281         bGPDlayer *gpl;
1282         size_t items = 0;
1283         
1284         /* loop over layers as the conditions are acceptable */
1285         for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
1286                 /* only if selected */
1287                 if ( ANIMCHANNEL_SELOK(SEL_GPL(gpl)) ) {
1288                         /* only if editable */
1289                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) {
1290                                 /* active... */
1291                                 if (!(filter_mode & ANIMFILTER_ACTIVE) || (gpl->flag & GP_LAYER_ACTIVE)) {
1292                                         /* add to list */
1293                                         ANIMCHANNEL_NEW_CHANNEL(gpl, ANIMTYPE_GPLAYER, gpd);
1294                                 }
1295                         }
1296                 }
1297         }
1298         
1299         return items;
1300 }
1301
1302 /* Grab all Grase Pencil datablocks in file */
1303 // TODO: should this be amalgamated with the dopesheet filtering code?
1304 static size_t animdata_filter_gpencil (ListBase *anim_data, void *UNUSED(data), int filter_mode)
1305 {
1306         bGPdata *gpd;
1307         size_t items = 0;
1308         
1309         /* for now, grab grease pencil datablocks directly from main */
1310         // XXX: this is not good...
1311         for (gpd = G.main->gpencil.first; gpd; gpd = gpd->id.next) {
1312                 ListBase tmp_data = {NULL, NULL};
1313                 size_t tmp_items = 0;
1314                 
1315                 /* only show if gpd is used by something... */
1316                 if (ID_REAL_USERS(gpd) < 1)
1317                         continue;
1318                         
1319                 /* add gpencil animation channels */
1320                 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_GPD(gpd))
1321                 {
1322                         tmp_items += animdata_filter_gpencil_data(&tmp_data, gpd, filter_mode);
1323                 }
1324                 END_ANIMFILTER_SUBCHANNELS;
1325                 
1326                 /* did we find anything? */
1327                 if (tmp_items) {
1328                         /* include data-expand widget first */
1329                         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1330                                 /* add gpd as channel too (if for drawing, and it has layers) */
1331                                 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_GPDATABLOCK, NULL);
1332                         }
1333                         
1334                         /* now add the list of collected channels */
1335                         BLI_movelisttolist(anim_data, &tmp_data);
1336                         BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1337                         items += tmp_items;
1338                 }
1339         }
1340         
1341         /* return the number of items added to the list */
1342         return items;
1343 }
1344
1345 /* NOTE: owner_id is scene, material, or texture block, which is the direct owner of the node tree in question */
1346 // TODO: how to handle group nodes is still unclear...
1347 static size_t animdata_filter_ds_nodetree (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, bNodeTree *ntree, int filter_mode)
1348 {
1349         ListBase tmp_data = {NULL, NULL};
1350         size_t tmp_items = 0;
1351         size_t items = 0;
1352         
1353         /* add nodetree animation channels */
1354         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_NTREE_DATA(ntree))
1355         {
1356                 /* animation data filtering */
1357                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ntree, filter_mode);
1358         }
1359         END_ANIMFILTER_SUBCHANNELS;
1360         
1361         /* did we find anything? */
1362         if (tmp_items) {
1363                 /* include data-expand widget first */
1364                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1365                         /* check if filtering by active status */
1366                         if ANIMCHANNEL_ACTIVEOK(ntree) {
1367                                 ANIMCHANNEL_NEW_CHANNEL(ntree, ANIMTYPE_DSNTREE, owner_id);
1368                         }
1369                 }
1370                 
1371                 /* now add the list of collected channels */
1372                 BLI_movelisttolist(anim_data, &tmp_data);
1373                 BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1374                 items += tmp_items;
1375         }
1376         
1377         /* return the number of items added to the list */
1378         return items;
1379 }
1380
1381 static size_t animdata_filter_ds_linestyle (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
1382 {
1383         SceneRenderLayer *srl;
1384         size_t items = 0;
1385
1386         for (srl= sce->r.layers.first; srl; srl= srl->next) {
1387                 FreestyleLineSet *lineset;
1388
1389                 /* skip render layers without Freestyle enabled */
1390                 if (!(srl->layflag & SCE_LAY_FRS))
1391                         continue;
1392
1393                 /* loop over linesets defined in the render layer */
1394                 for (lineset= srl->freestyleConfig.linesets.first; lineset; lineset= lineset->next) {
1395                         FreestyleLineStyle *linestyle = lineset->linestyle;
1396                         ListBase tmp_data = {NULL, NULL};
1397                         size_t tmp_items = 0;
1398
1399                         /* add scene-level animation channels */
1400                         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_LS_SCED(linestyle))
1401                         {
1402                                 /* animation data filtering */
1403                                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)linestyle, filter_mode);
1404                         }
1405                         END_ANIMFILTER_SUBCHANNELS;
1406
1407                         /* did we find anything? */
1408                         if (tmp_items) {
1409                                 /* include anim-expand widget first */
1410                                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1411                                         /* check if filtering by active status */
1412                                         if ANIMCHANNEL_ACTIVEOK(linestyle) {
1413                                                 ANIMCHANNEL_NEW_CHANNEL(linestyle, ANIMTYPE_DSLINESTYLE, sce);
1414                                         }
1415                                 }
1416                                 
1417                                 /* now add the list of collected channels */
1418                                 BLI_movelisttolist(anim_data, &tmp_data);
1419                                 BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1420                                 items += tmp_items;
1421                         }
1422                 }
1423         }
1424         
1425         /* return the number of items added to the list */
1426         return items;
1427 }
1428
1429 /* NOTE: owner_id is either material, lamp, or world block, which is the direct owner of the texture stack in question */
1430 static size_t animdata_filter_ds_textures (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, int filter_mode)
1431 {
1432         MTex **mtex = NULL;
1433         size_t items=0;
1434         int a=0;
1435         
1436         /* get datatype specific data first */
1437         if (owner_id == NULL)
1438                 return 0;
1439         
1440         switch (GS(owner_id->name)) {
1441                 case ID_MA:
1442                 {
1443                         Material *ma= (Material *)owner_id;
1444                         mtex= (MTex**)(&ma->mtex);
1445                 }
1446                         break;
1447                 case ID_LA:
1448                 {
1449                         Lamp *la= (Lamp *)owner_id;
1450                         mtex= (MTex**)(&la->mtex);
1451                 }
1452                         break;
1453                 case ID_WO:
1454                 {
1455                         World *wo= (World *)owner_id;
1456                         mtex= (MTex**)(&wo->mtex);
1457                 }
1458                         break;
1459                 default: 
1460                 {
1461                         /* invalid/unsupported option */
1462                         if (G.f & G_DEBUG)
1463                                 printf("ERROR: unsupported owner_id (i.e. texture stack) for filter textures - %s \n", owner_id->name);
1464                         return 0;
1465                 }
1466         }
1467         
1468         /* firstly check that we actuallly have some textures, by gathering all textures in a temp list */
1469         for (a=0; a < MAX_MTEX; a++) {
1470                 Tex *tex= (mtex[a]) ? mtex[a]->tex : NULL;
1471                 ListBase tmp_data = {NULL, NULL};
1472                 size_t tmp_items = 0;
1473                 
1474                 /* for now, if no texture returned, skip (this shouldn't confuse the user I hope) */
1475                 if (tex == NULL) 
1476                         continue;
1477                 
1478                 /* add texture's animation data to temp collection */
1479                 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_TEX_DATA(tex)) 
1480                 {
1481                         /* texture animdata */
1482                         tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)tex, filter_mode);
1483                         
1484                         /* nodes */
1485                         if ((tex->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
1486                                 /* owner_id as id instead of texture, since it'll otherwise be impossible to track the depth */
1487                                 // FIXME: perhaps as a result, textures should NOT be included under materials, but under their own section instead
1488                                 // so that free-floating textures can also be animated
1489                                 tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)tex, tex->nodetree, filter_mode);
1490                         }
1491                 }
1492                 END_ANIMFILTER_SUBCHANNELS;
1493                 
1494                 /* did we find anything? */
1495                 if (tmp_items) {
1496                         /* include texture-expand widget? */
1497                         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1498                                 /* check if filtering by active status */
1499                                 if ANIMCHANNEL_ACTIVEOK(tex) {
1500                                         ANIMCHANNEL_NEW_CHANNEL(tex, ANIMTYPE_DSTEX, owner_id);
1501                                 }
1502                         }
1503                         
1504                         /* now add the list of collected channels */
1505                         BLI_movelisttolist(anim_data, &tmp_data);
1506                         BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1507                         items += tmp_items;
1508                 }
1509         }
1510         
1511         /* return the number of items added to the list */
1512         return items;
1513 }
1514
1515 static size_t animdata_filter_ds_materials (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
1516 {
1517         size_t items=0;
1518         int a=0;
1519         
1520         /* firstly check that we actuallly have some materials, by gathering all materials in a temp list */
1521         for (a=1; a <= ob->totcol; a++) {
1522                 Material *ma= give_current_material(ob, a);
1523                 ListBase tmp_data = {NULL, NULL};
1524                 size_t tmp_items = 0;
1525                 
1526                 /* if no material returned, skip - so that we don't get weird blank entries... */
1527                 if (ma == NULL) continue;
1528                 
1529                 /* add material's animation data to temp collection */
1530                 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_MAT_OBJD(ma))
1531                 {
1532                         /* material's animation data */
1533                         tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ma, filter_mode);
1534                                 
1535                         /* textures */
1536                         if (!(ads->filterflag & ADS_FILTER_NOTEX))
1537                                 tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, (ID *)ma, filter_mode);
1538                                 
1539                         /* nodes */
1540                         if ((ma->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) 
1541                                 tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)ma, ma->nodetree, filter_mode);
1542                 }
1543                 END_ANIMFILTER_SUBCHANNELS;
1544                 
1545                 /* did we find anything? */
1546                 if (tmp_items) {
1547                         /* include material-expand widget first */
1548                         // hmm... do we need to store the index of this material in the array anywhere?
1549                         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1550                                 /* check if filtering by active status */
1551                                 if ANIMCHANNEL_ACTIVEOK(ma) {
1552                                         ANIMCHANNEL_NEW_CHANNEL(ma, ANIMTYPE_DSMAT, ma);
1553                                 }
1554                         }
1555                         
1556                         /* now add the list of collected channels */
1557                         BLI_movelisttolist(anim_data, &tmp_data);
1558                         BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1559                         items += tmp_items;
1560                 }
1561         }
1562         
1563         /* return the number of items added to the list */
1564         return items;
1565 }
1566
1567 static size_t animdata_filter_ds_particles (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
1568 {
1569         ParticleSystem *psys;
1570         size_t items= 0;
1571
1572         for (psys = ob->particlesystem.first; psys; psys=psys->next) {
1573                 ListBase tmp_data = {NULL, NULL};
1574                 size_t tmp_items = 0;
1575                 
1576                 /* if no material returned, skip - so that we don't get weird blank entries... */
1577                 if (ELEM(NULL, psys->part, psys->part->adt))
1578                         continue;
1579                 
1580                 /* add particle-system's animation data to temp collection */
1581                 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_PART_OBJD(psys->part))
1582                 {
1583                         /* material's animation data */
1584                         tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)psys->part, filter_mode);
1585                 }
1586                 END_ANIMFILTER_SUBCHANNELS;
1587                 
1588                 /* did we find anything? */
1589                 if (tmp_items) {
1590                         /* include particle-expand widget first */
1591                         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1592                                 /* check if filtering by active status */
1593                                 if ANIMCHANNEL_ACTIVEOK(psys->part) {
1594                                         ANIMCHANNEL_NEW_CHANNEL(psys->part, ANIMTYPE_DSPART, psys->part);
1595                                 }
1596                         }
1597                         
1598                         /* now add the list of collected channels */
1599                         BLI_movelisttolist(anim_data, &tmp_data);
1600                         BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1601                         items += tmp_items;
1602                 }
1603         }
1604         
1605         /* return the number of items added to the list */
1606         return items;
1607 }
1608
1609 static size_t animdata_filter_ds_obdata (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
1610 {
1611         ListBase tmp_data = {NULL, NULL};
1612         size_t tmp_items = 0;
1613         size_t items= 0;
1614         
1615         IdAdtTemplate *iat= ob->data;
1616         short type=0, expanded=0;
1617         
1618         /* get settings based on data type */
1619         switch (ob->type) {
1620                 case OB_CAMERA: /* ------- Camera ------------ */
1621                 {
1622                         Camera *ca= (Camera *)ob->data;
1623                         
1624                         if (ads->filterflag & ADS_FILTER_NOCAM)
1625                                 return 0;
1626                         
1627                         type= ANIMTYPE_DSCAM;
1628                         expanded= FILTER_CAM_OBJD(ca);
1629                 }
1630                         break;
1631                 case OB_LAMP: /* ---------- Lamp ----------- */
1632                 {
1633                         Lamp *la= (Lamp *)ob->data;
1634                         
1635                         if (ads->filterflag & ADS_FILTER_NOLAM)
1636                                 return 0;
1637                         
1638                         type= ANIMTYPE_DSLAM;
1639                         expanded= FILTER_LAM_OBJD(la);
1640                 }
1641                         break;
1642                 case OB_CURVE: /* ------- Curve ---------- */
1643                 case OB_SURF: /* ------- Nurbs Surface ---------- */
1644                 case OB_FONT: /* ------- Text Curve ---------- */
1645                 {
1646                         Curve *cu= (Curve *)ob->data;
1647                         
1648                         if (ads->filterflag & ADS_FILTER_NOCUR)
1649                                 return 0;
1650                         
1651                         type= ANIMTYPE_DSCUR;
1652                         expanded= FILTER_CUR_OBJD(cu);
1653                 }
1654                         break;
1655                 case OB_MBALL: /* ------- MetaBall ---------- */
1656                 {
1657                         MetaBall *mb= (MetaBall *)ob->data;
1658                         
1659                         if (ads->filterflag & ADS_FILTER_NOMBA)
1660                                 return 0;
1661                         
1662                         type= ANIMTYPE_DSMBALL;
1663                         expanded= FILTER_MBALL_OBJD(mb);
1664                 }
1665                         break;
1666                 case OB_ARMATURE: /* ------- Armature ---------- */
1667                 {
1668                         bArmature *arm= (bArmature *)ob->data;
1669                         
1670                         if (ads->filterflag & ADS_FILTER_NOARM)
1671                                 return 0;
1672                         
1673                         type= ANIMTYPE_DSARM;
1674                         expanded= FILTER_ARM_OBJD(arm);
1675                 }
1676                         break;
1677                 case OB_MESH: /* ------- Mesh ---------- */
1678                 {
1679                         Mesh *me= (Mesh *)ob->data;
1680                         
1681                         if (ads->filterflag & ADS_FILTER_NOMESH)
1682                                 return 0;
1683                         
1684                         type= ANIMTYPE_DSMESH;
1685                         expanded= FILTER_MESH_OBJD(me);
1686                 }
1687                         break;
1688                 case OB_LATTICE: /* ---- Lattice ---- */
1689                 {
1690                         Lattice *lt = (Lattice *)ob->data;
1691                         
1692                         if (ads->filterflag & ADS_FILTER_NOLAT)
1693                                 return 0;
1694                         
1695                         type= ANIMTYPE_DSLAT;
1696                         expanded= FILTER_LATTICE_OBJD(lt);
1697                 }
1698                         break;
1699                 case OB_SPEAKER: /* ---------- Speaker ----------- */
1700                 {
1701                         Speaker *spk= (Speaker *)ob->data;
1702                         
1703                         type= ANIMTYPE_DSSPK;
1704                         expanded= FILTER_SPK_OBJD(spk);
1705                 }
1706                         break;
1707         }
1708         
1709         /* add object data animation channels */
1710         BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
1711         {
1712                 /* animation data filtering */
1713                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)iat, filter_mode);
1714                 
1715                 /* sub-data filtering... */
1716                 switch (ob->type) {
1717                         case OB_LAMP:   /* lamp - textures */
1718                         {
1719                                 /* textures */
1720                                 if (!(ads->filterflag & ADS_FILTER_NOTEX))
1721                                         tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, ob->data, filter_mode);
1722                         }
1723                                 break;
1724                 }
1725         }
1726         END_ANIMFILTER_SUBCHANNELS;
1727         
1728         /* did we find anything? */
1729         if (tmp_items) {
1730                 /* include data-expand widget first */
1731                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1732                         /* check if filtering by active status */
1733                         if ANIMCHANNEL_ACTIVEOK(iat) {
1734                                 ANIMCHANNEL_NEW_CHANNEL(iat, type, iat);
1735                         }
1736                 }
1737                 
1738                 /* now add the list of collected channels */
1739                 BLI_movelisttolist(anim_data, &tmp_data);
1740                 BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1741                 items += tmp_items;
1742         }
1743         
1744         /* return the number of items added to the list */
1745         return items;
1746 }
1747
1748 /* shapekey-level animation */
1749 static size_t animdata_filter_ds_keyanim (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, Key *key, int filter_mode)
1750 {
1751         ListBase tmp_data = {NULL, NULL};
1752         size_t tmp_items = 0;
1753         size_t items = 0;
1754         
1755         /* add shapekey-level animation channels */
1756         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_SKE_OBJD(key))
1757         {
1758                 /* animation data filtering */
1759                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)key, filter_mode);
1760         }
1761         END_ANIMFILTER_SUBCHANNELS;
1762         
1763         /* did we find anything? */
1764         if (tmp_items) {
1765                 /* include key-expand widget first */
1766                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1767                         if ANIMCHANNEL_ACTIVEOK(key) {
1768                                 ANIMCHANNEL_NEW_CHANNEL(key, ANIMTYPE_DSSKEY, ob);
1769                         }
1770                 }
1771                 
1772                 /* now add the list of collected channels */
1773                 BLI_movelisttolist(anim_data, &tmp_data);
1774                 BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1775                 items += tmp_items;
1776         }
1777         
1778         /* return the number of items added to the list */
1779         return items;
1780 }
1781
1782 /* object-level animation */
1783 static size_t animdata_filter_ds_obanim (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
1784 {
1785         ListBase tmp_data = {NULL, NULL};
1786         size_t tmp_items = 0;
1787         size_t items = 0;
1788         
1789         AnimData *adt = ob->adt;
1790         short type=0, expanded=1;
1791         void *cdata = NULL;
1792         
1793         /* determine the type of expander channels to use */
1794         // this is the best way to do this for now...
1795         ANIMDATA_FILTER_CASES(ob,
1796                 {/* AnimData - no channel, but consider data */},
1797                 {/* NLA - no channel, but consider data */},
1798                 {/* Drivers */
1799                         type = ANIMTYPE_FILLDRIVERS;
1800                         cdata = adt;
1801                         expanded = EXPANDED_DRVD(adt);
1802                 },
1803                 {/* Keyframes */
1804                         type = ANIMTYPE_FILLACTD;
1805                         cdata = adt->action;
1806                         expanded = EXPANDED_ACTC(adt->action);
1807                 });
1808                 
1809         /* add object-level animation channels */
1810         BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
1811         {
1812                 /* animation data filtering */
1813                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ob, filter_mode);
1814         }
1815         END_ANIMFILTER_SUBCHANNELS;
1816         
1817         /* did we find anything? */
1818         if (tmp_items) {
1819                 /* include anim-expand widget first */
1820                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1821                         if (type != ANIMTYPE_NONE) {
1822                                 /* NOTE: active-status (and the associated checks) don't apply here... */
1823                                 ANIMCHANNEL_NEW_CHANNEL(cdata, type, ob);
1824                         }
1825                 }
1826                 
1827                 /* now add the list of collected channels */
1828                 BLI_movelisttolist(anim_data, &tmp_data);
1829                 BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1830                 items += tmp_items;
1831         }
1832         
1833         /* return the number of items added to the list */
1834         return items;
1835 }
1836
1837 /* get animation channels from object2 */
1838 static size_t animdata_filter_dopesheet_ob (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
1839 {
1840         ListBase tmp_data = {NULL, NULL};
1841         Object *ob= base->object;
1842         size_t tmp_items = 0;
1843         size_t items = 0;
1844         
1845         /* filter data contained under object first */
1846         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_OBJC(ob))
1847         {
1848                 Key *key= ob_get_key(ob);
1849                 
1850                 /* object-level animation */
1851                 if ((ob->adt) && !(ads->filterflag & ADS_FILTER_NOOBJ)) {
1852                         tmp_items += animdata_filter_ds_obanim(ac, &tmp_data, ads, ob, filter_mode);
1853                 }
1854                 
1855                 /* shape-key */
1856                 if ((key && key->adt) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
1857                         tmp_items += animdata_filter_ds_keyanim(ac, &tmp_data, ads, ob, key, filter_mode);
1858                 }
1859                 
1860                 /* materials */
1861                 if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT)) {
1862                         tmp_items += animdata_filter_ds_materials(ac, &tmp_data, ads, ob, filter_mode);
1863                 }
1864                 
1865                 /* object data */
1866                 if (ob->data) {
1867                         tmp_items += animdata_filter_ds_obdata(ac, &tmp_data, ads, ob, filter_mode);
1868                 }
1869                 
1870                 /* particles */
1871                 if ((ob->particlesystem.first) && !(ads->filterflag & ADS_FILTER_NOPART)) {
1872                         tmp_items += animdata_filter_ds_particles(ac, &tmp_data, ads, ob, filter_mode);
1873                 }
1874         }
1875         END_ANIMFILTER_SUBCHANNELS;
1876         
1877         
1878         /* if we collected some channels, add these to the new list... */
1879         if (tmp_items) {
1880                 /* firstly add object expander if required */
1881                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1882                         /* check if filtering by selection */
1883                         // XXX: double-check on this - most of the time, a lot of tools need to filter out these channels!
1884                         if ANIMCHANNEL_SELOK((base->flag & SELECT)) {
1885                                 /* check if filtering by active status */
1886                                 if (ANIMCHANNEL_ACTIVEOK(ob)) {
1887                                         ANIMCHANNEL_NEW_CHANNEL(base, ANIMTYPE_OBJECT, ob);
1888                                 }
1889                         }
1890                 }
1891                 
1892                 /* now add the list of collected channels */
1893                 BLI_movelisttolist(anim_data, &tmp_data);
1894                 BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1895                 items += tmp_items;
1896         }
1897         
1898         /* return the number of items added */
1899         return items;
1900 }
1901
1902 static size_t animdata_filter_ds_world (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, World *wo, int filter_mode)
1903 {
1904         ListBase tmp_data = {NULL, NULL};
1905         size_t tmp_items = 0;
1906         size_t items = 0;
1907         
1908         /* add world animation channels */
1909         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_WOR_SCED(wo))
1910         {
1911                 /* animation data filtering */
1912                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)wo, filter_mode);
1913                 
1914                 /* textures for world */
1915                 if (!(ads->filterflag & ADS_FILTER_NOTEX))
1916                         items += animdata_filter_ds_textures(ac, &tmp_data, ads, (ID *)wo, filter_mode);
1917         }
1918         END_ANIMFILTER_SUBCHANNELS;
1919         
1920         /* did we find anything? */
1921         if (tmp_items) {
1922                 /* include data-expand widget first */
1923                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1924                         /* check if filtering by active status */
1925                         if ANIMCHANNEL_ACTIVEOK(wo) {
1926                                 ANIMCHANNEL_NEW_CHANNEL(wo, ANIMTYPE_DSWOR, sce);
1927                         }
1928                 }
1929                 
1930                 /* now add the list of collected channels */
1931                 BLI_movelisttolist(anim_data, &tmp_data);
1932                 BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1933                 items += tmp_items;
1934         }
1935         
1936         /* return the number of items added to the list */
1937         return items;
1938 }
1939
1940 static size_t animdata_filter_ds_scene (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
1941 {
1942         ListBase tmp_data = {NULL, NULL};
1943         size_t tmp_items = 0;
1944         size_t items = 0;
1945         
1946         AnimData *adt = sce->adt;
1947         short type=0, expanded=1;
1948         void *cdata = NULL;
1949         
1950         /* determine the type of expander channels to use */
1951         // this is the best way to do this for now...
1952         ANIMDATA_FILTER_CASES(sce,
1953                 {/* AnimData - no channel, but consider data */},
1954                 {/* NLA - no channel, but consider data */},
1955                 {/* Drivers */
1956                         type = ANIMTYPE_FILLDRIVERS;
1957                         cdata = adt;
1958                         expanded = EXPANDED_DRVD(adt);
1959                 },
1960                 {/* Keyframes */
1961                         type = ANIMTYPE_FILLACTD;
1962                         cdata = adt->action;
1963                         expanded = EXPANDED_ACTC(adt->action);
1964                 });
1965                 
1966         /* add scene-level animation channels */
1967         BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
1968         {
1969                 /* animation data filtering */
1970                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)sce, filter_mode);
1971         }
1972         END_ANIMFILTER_SUBCHANNELS;
1973         
1974         /* did we find anything? */
1975         if (tmp_items) {
1976                 /* include anim-expand widget first */
1977                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1978                         if (type != ANIMTYPE_NONE) {
1979                                 /* NOTE: active-status (and the associated checks) don't apply here... */
1980                                 ANIMCHANNEL_NEW_CHANNEL(cdata, type, sce);
1981                         }
1982                 }
1983                 
1984                 /* now add the list of collected channels */
1985                 BLI_movelisttolist(anim_data, &tmp_data);
1986                 BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
1987                 items += tmp_items;
1988         }
1989         
1990         /* return the number of items added to the list */
1991         return items;
1992 }
1993
1994 static size_t animdata_filter_dopesheet_scene (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
1995 {
1996         ListBase tmp_data = {NULL, NULL};
1997         size_t tmp_items = 0;
1998         size_t items = 0;
1999         
2000         /* filter data contained under object first */
2001         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_SCEC(sce))
2002         {
2003                 bNodeTree *ntree= sce->nodetree;
2004                 World *wo= sce->world;
2005                 
2006                 /* Action, Drivers, or NLA for Scene */
2007                 if ((ads->filterflag & ADS_FILTER_NOSCE) == 0) {
2008                         tmp_items += animdata_filter_ds_scene(ac, &tmp_data, ads, sce, filter_mode);
2009                 }
2010                 
2011                 /* world */
2012                 if ((wo && wo->adt) && !(ads->filterflag & ADS_FILTER_NOWOR)) {
2013                         tmp_items += animdata_filter_ds_world(ac, &tmp_data, ads, sce, wo, filter_mode);
2014                 }
2015                 
2016                 /* nodetree */
2017                 if ((ntree && ntree->adt) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
2018                         tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)sce, ntree, filter_mode);
2019                 }
2020
2021                 /* line styles */
2022                 if ((ads->filterflag & ADS_FILTER_NOLINESTYLE) == 0) {
2023                         tmp_items += animdata_filter_ds_linestyle(ac, &tmp_data, ads, sce, filter_mode);
2024                 }
2025                 
2026                 // TODO: one day, when sequencer becomes its own datatype, perhaps it should be included here
2027         }
2028         END_ANIMFILTER_SUBCHANNELS;
2029         
2030         /* if we collected some channels, add these to the new list... */
2031         if (tmp_items) {
2032                 /* firstly add object expander if required */
2033                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2034                         /* check if filtering by selection */
2035                         if ANIMCHANNEL_SELOK((sce->flag & SCE_DS_SELECTED)) {
2036                                 /* NOTE: active-status doesn't matter for this! */
2037                                 ANIMCHANNEL_NEW_CHANNEL(sce, ANIMTYPE_SCENE, sce);
2038                         }
2039                 }
2040                 
2041                 /* now add the list of collected channels */
2042                 BLI_movelisttolist(anim_data, &tmp_data);
2043                 BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
2044                 items += tmp_items;
2045         }
2046         
2047         /* return the number of items added */
2048         return items;
2049 }
2050
2051 // TODO: implement pinning... (if and when pinning is done, what we need to do is to provide freeing mechanisms - to protect against data that was deleted)
2052 static size_t animdata_filter_dopesheet (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, int filter_mode)
2053 {
2054         Scene *sce= (Scene *)ads->source;
2055         Base *base;
2056         size_t items = 0;
2057         
2058         /* check that we do indeed have a scene */
2059         if ((ads->source == NULL) || (GS(ads->source->name)!=ID_SCE)) {
2060                 printf("DopeSheet Error: Not scene!\n");
2061                 if (G.f & G_DEBUG)
2062                         printf("\tPointer = %p, Name = '%s' \n", (void *)ads->source, (ads->source)?ads->source->name:NULL);
2063                 return 0;
2064         }
2065         
2066         /* augment the filter-flags with settings based on the dopesheet filterflags 
2067          * so that some temp settings can get added automagically...
2068          */
2069         if (ads->filterflag & ADS_FILTER_SELEDIT) {
2070                 /* only selected F-Curves should get their keyframes considered for editability */
2071                 filter_mode |= ANIMFILTER_SELEDIT;
2072         }
2073         
2074         /* scene-linked animation - e.g. world, compositing nodes, scene anim (including sequencer currently) */
2075         items += animdata_filter_dopesheet_scene(ac, anim_data, ads, sce, filter_mode);
2076         
2077         /* loop over all bases (i.e.objects) in the scene */
2078         for (base= sce->base.first; base; base= base->next) {
2079                 /* check if there's an object (all the relevant checks are done in the ob-function) */
2080                 if (base->object) {
2081                         Object *ob= base->object;
2082                         
2083                         /* firstly, check if object can be included, by the following factors:
2084                          *      - if only visible, must check for layer and also viewport visibility
2085                          *              --> while tools may demand only visible, user setting takes priority
2086                          *                      as user option controls whether sets of channels get included while
2087                          *                      tool-flag takes into account collapsed/open channels too
2088                          *      - if only selected, must check if object is selected 
2089                          *      - there must be animation data to edit (this is done recursively as we 
2090                          *        try to add the channels)
2091                          */
2092                         if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
2093                                 /* layer visibility - we check both object and base, since these may not be in sync yet */
2094                                 if ((sce->lay & (ob->lay|base->lay))==0) continue;
2095                                 
2096                                 /* outliner restrict-flag */
2097                                 if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
2098                         }
2099                         
2100                         /* if only F-Curves with visible flags set can be shown, check that 
2101                          * datablock hasn't been set to invisible 
2102                          */
2103                         if (filter_mode & ANIMFILTER_CURVE_VISIBLE) {
2104                                 if ((ob->adt) && (ob->adt->flag & ADT_CURVES_NOT_VISIBLE))
2105                                         continue;
2106                         }
2107                         
2108                         /* check selection and object type filters */
2109                         if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & SELECT) /*|| (base == sce->basact)*/) )  {
2110                                 /* only selected should be shown */
2111                                 continue;
2112                         }
2113                         
2114                         /* check if object belongs to the filtering group if option to filter 
2115                          * objects by the grouped status is on
2116                          *      - used to ease the process of doing multiple-character choreographies
2117                          */
2118                         if (ads->filterflag & ADS_FILTER_ONLYOBGROUP) {
2119                                 if (object_in_group(ob, ads->filter_grp) == 0)
2120                                         continue;
2121                         }
2122                                 
2123                         /* since we're still here, this object should be usable */
2124                         items += animdata_filter_dopesheet_ob(ac, anim_data, ads, base, filter_mode);
2125                 }
2126         }
2127         
2128         /* return the number of items in the list */
2129         return items;
2130 }
2131
2132 /* Summary track for DopeSheet/Action Editor 
2133  *      - return code is whether the summary lets the other channels get drawn
2134  */
2135 static short animdata_filter_dopesheet_summary (bAnimContext *ac, ListBase *anim_data, int filter_mode, size_t *items)
2136 {
2137         bDopeSheet *ads = NULL;
2138         
2139         /* get the DopeSheet information to use 
2140          *      - we should only need to deal with the DopeSheet/Action Editor, 
2141          *        since all the other Animation Editors won't have this concept
2142          *        being applicable.
2143          */
2144         if ((ac && ac->sl) && (ac->spacetype == SPACE_ACTION)) {
2145                 SpaceAction *saction= (SpaceAction *)ac->sl;
2146                 ads= &saction->ads;
2147         }
2148         else {
2149                 /* invalid space type - skip this summary channels */
2150                 return 1;
2151         }
2152         
2153         /* dopesheet summary 
2154          *      - only for drawing and/or selecting keyframes in channels, but not for real editing 
2155          *      - only useful for DopeSheet/Action/etc. editors where it is actually useful
2156          */
2157         if ((filter_mode & ANIMFILTER_LIST_CHANNELS) && (ads->filterflag & ADS_FILTER_SUMMARY)) {
2158                 bAnimListElem *ale= make_new_animlistelem(ac, ANIMTYPE_SUMMARY, NULL);
2159                 if (ale) {
2160                         BLI_addtail(anim_data, ale);
2161                         (*items)++;
2162                 }
2163                 
2164                 /* if summary is collapsed, don't show other channels beneath this 
2165                  *      - this check is put inside the summary check so that it doesn't interfere with normal operation
2166                  */ 
2167                 if (ads->flag & ADS_FLAG_SUMMARY_COLLAPSED)
2168                         return 0;
2169         }
2170         
2171         /* the other channels beneath this can be shown */
2172         return 1;
2173 }  
2174
2175 /* ......................... */
2176
2177 /* filter data associated with a channel - usually for handling summary-channels in DopeSheet */
2178 static size_t animdata_filter_animchan (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bAnimListElem *channel, int filter_mode)
2179 {
2180         size_t items = 0;
2181         
2182         /* data to filter depends on channel type */
2183         // XXX: only common channel-types have been handled for now
2184         switch (channel->type) {
2185                 case ANIMTYPE_SUMMARY:
2186                         items += animdata_filter_dopesheet(ac, anim_data, ads, filter_mode);
2187                         break;
2188                         
2189                 case ANIMTYPE_SCENE:
2190                         items += animdata_filter_dopesheet_scene(ac, anim_data, ads, channel->data, filter_mode);
2191                         break;
2192                 
2193                 case ANIMTYPE_OBJECT:
2194                         items += animdata_filter_dopesheet_ob(ac, anim_data, ads, channel->data, filter_mode);
2195                         break;
2196         }
2197         
2198         return items;
2199 }
2200
2201 /* ----------- Cleanup API --------------- */
2202
2203 /* Remove entries with invalid types in animation channel list */
2204 static size_t animdata_filter_remove_invalid (ListBase *anim_data)
2205 {
2206         bAnimListElem *ale, *next;
2207         size_t items = 0;
2208         
2209         /* only keep entries with valid types */
2210         for (ale= anim_data->first; ale; ale= next) {
2211                 next= ale->next;
2212                 
2213                 if (ale->type == ANIMTYPE_NONE)
2214                         BLI_freelinkN(anim_data, ale);
2215                 else
2216                         items++;
2217         }
2218         
2219         return items;
2220 }
2221
2222 /* Remove duplicate entries in animation channel list */
2223 static size_t animdata_filter_remove_duplis (ListBase *anim_data)
2224 {
2225         bAnimListElem *ale, *next;
2226         GHash *gh;
2227         size_t items = 0;
2228         
2229         /* build new hashtable to efficiently store and retrieve which entries have been 
2230          * encountered already while searching
2231          */
2232         gh= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "animdata_filter_duplis_remove gh");
2233         
2234         /* loop through items, removing them from the list if a similar item occurs already */
2235         for (ale = anim_data->first; ale; ale = next) {
2236                 next = ale->next;
2237                 
2238                 /* check if hash has any record of an entry like this 
2239                  *      - just use ale->data for now, though it would be nicer to involve 
2240                  *        ale->type in combination too to capture corner cases (where same data performs differently)
2241                  */
2242                 if (BLI_ghash_haskey(gh, ale->data) == 0) {
2243                         /* this entry is 'unique' and can be kept */
2244                         BLI_ghash_insert(gh, ale->data, NULL);
2245                         items++;
2246                 }
2247                 else {
2248                         /* this entry isn't needed anymore */
2249                         BLI_freelinkN(anim_data, ale);
2250                 }
2251         }
2252         
2253         /* free the hash... */
2254         BLI_ghash_free(gh, NULL, NULL);
2255         
2256         /* return the number of items still in the list */
2257         return items;
2258 }
2259
2260 /* ----------- Public API --------------- */
2261
2262 /* This function filters the active data source to leave only animation channels suitable for
2263  * usage by the caller. It will return the length of the list 
2264  * 
2265  *      *anim_data: is a pointer to a ListBase, to which the filtered animation channels
2266  *              will be placed for use.
2267  *      filter_mode: how should the data be filtered - bitmapping accessed flags
2268  */
2269 size_t ANIM_animdata_filter (bAnimContext *ac, ListBase *anim_data, int filter_mode, void *data, short datatype)
2270 {
2271         size_t items = 0;
2272         
2273         /* only filter data if there's somewhere to put it */
2274         if (data && anim_data) {
2275                 Object *obact= (ac) ? ac->obact : NULL;
2276                 
2277                 /* firstly filter the data */
2278                 switch (datatype) {
2279                         case ANIMCONT_ACTION:   /* 'Action Editor' */
2280                         {
2281                                 SpaceAction *saction = (SpaceAction *)ac->sl;
2282                                 bDopeSheet *ads = (saction)? &saction->ads : NULL;
2283                                 
2284                                 /* the check for the DopeSheet summary is included here since the summary works here too */
2285                                 if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items))
2286                                         items += animfilter_action(ac, anim_data, ads, data, filter_mode, (ID *)obact);
2287                         }
2288                                 break;
2289                                 
2290                         case ANIMCONT_SHAPEKEY: /* 'ShapeKey Editor' */
2291                         {
2292                                 /* the check for the DopeSheet summary is included here since the summary works here too */
2293                                 if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items))
2294                                         items= animdata_filter_shapekey(ac, anim_data, data, filter_mode);
2295                         }
2296                                 break;
2297                                 
2298                         case ANIMCONT_GPENCIL:
2299                         {
2300                                 items= animdata_filter_gpencil(anim_data, data, filter_mode);
2301                         }
2302                                 break;
2303                                 
2304                         case ANIMCONT_DOPESHEET: /* 'DopeSheet Editor' */
2305                         {
2306                                 /* the DopeSheet editor is the primary place where the DopeSheet summaries are useful */
2307                                 if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items))
2308                                         items += animdata_filter_dopesheet(ac, anim_data, data, filter_mode);
2309                         }
2310                                 break;
2311                                 
2312                         case ANIMCONT_FCURVES: /* Graph Editor -> FCurves/Animation Editing */
2313                         case ANIMCONT_DRIVERS: /* Graph Editor -> Drivers Editing */
2314                         case ANIMCONT_NLA: /* NLA Editor */
2315                         {
2316                                 /* all of these editors use the basic DopeSheet data for filtering options, but don't have all the same features */
2317                                 items = animdata_filter_dopesheet(ac, anim_data, data, filter_mode);
2318                         }
2319                                 break;
2320                         
2321                         case ANIMCONT_CHANNEL: /* animation channel */
2322                         {
2323                                 bDopeSheet *ads = ac->ads;
2324                                 
2325                                 /* based on the channel type, filter relevant data for this */
2326                                 items = animdata_filter_animchan(ac, anim_data, ads, data, filter_mode);
2327                         }
2328                                 break;
2329                 }
2330                         
2331                 /* remove any 'weedy' entries */
2332                 items = animdata_filter_remove_invalid(anim_data);
2333                 
2334                 /* remove duplicates (if required) */
2335                 if (filter_mode & ANIMFILTER_NODUPLIS)
2336                         items = animdata_filter_remove_duplis(anim_data);
2337         }
2338         
2339         /* return the number of items in the list */
2340         return items;
2341 }
2342
2343 /* ************************************************************ */