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