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