6283f2dd0c68d9de0314ad0b92a566cb48c86a85
[blender.git] / source / blender / editors / animation / anim_filter.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Joshua Leung
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /* This file contains a system used to provide a layer of abstraction between sources
30  * of animation data and tools in Animation Editors. The method used here involves 
31  * generating a list of edit structures which enable tools to naively perform the actions 
32  * they require without all the boiler-plate associated with loops within loops and checking 
33  * for cases to ignore. 
34  *
35  * While this is primarily used for the Action/Dopesheet Editor (and its accessory modes),
36  * the IPO Editor also uses this for it's channel list and for determining which curves
37  * are being edited.
38  *
39  * Note: much of the original system this was based on was built before the creation of the RNA
40  * system. In future, it would be interesting to replace some parts of this code with RNA queries,
41  * however, RNA does not eliminate some of the boiler-plate reduction benefits presented by this 
42  * system, so if any such work does occur, it should only be used for the internals used here...
43  *
44  * -- Joshua Leung, Dec 2008
45  */
46
47 #include <string.h>
48 #include <stdio.h>
49
50 #include "DNA_listBase.h"
51 #include "DNA_ID.h"
52 #include "DNA_action_types.h"
53 #include "DNA_constraint_types.h"
54 #include "DNA_camera_types.h"
55 #include "DNA_curve_types.h"
56 #include "DNA_gpencil_types.h"
57 #include "DNA_ipo_types.h"
58 #include "DNA_lamp_types.h"
59 #include "DNA_lattice_types.h"
60 #include "DNA_key_types.h"
61 #include "DNA_material_types.h"
62 #include "DNA_mesh_types.h"
63 #include "DNA_object_types.h"
64 #include "DNA_space_types.h"
65 #include "DNA_scene_types.h"
66 #include "DNA_screen_types.h"
67 #include "DNA_windowmanager_types.h"
68
69 #include "MEM_guardedalloc.h"
70
71 #include "BLI_blenlib.h"
72
73 #include "BKE_context.h"
74 #include "BKE_global.h"
75 #include "BKE_key.h"
76 #include "BKE_object.h"
77 #include "BKE_material.h"
78 #include "BKE_screen.h"
79 #include "BKE_utildefines.h"
80
81 #include "ED_anim_api.h"
82 #include "ED_types.h"
83 #include "ED_util.h"
84
85 #include "WM_api.h"
86 #include "WM_types.h"
87
88 #include "BIF_gl.h"
89 #include "BIF_glutil.h"
90
91 #include "UI_interface.h"
92 #include "UI_resources.h"
93 #include "UI_view2d.h"
94
95 /* ************************************************************ */
96 /* Blender Context <-> Animation Context mapping */
97
98 /* ----------- Private Stuff - Action Editor ------------- */
99
100 /* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */
101 /* Note: there's a similar function in key.c (ob_get_key) */
102 Key *actedit_get_shapekeys (const bContext *C, SpaceAction *saction) 
103 {
104     Scene *scene= CTX_data_scene(C);
105     Object *ob;
106     Key *key;
107         
108     ob = OBACT;  // XXX er...
109     if (ob == NULL) 
110                 return NULL;
111         
112         /* XXX pinning is not available in 'ShapeKey' mode... */
113         //if (saction->pin) return NULL;
114         
115         /* shapekey data is stored with geometry data */
116         switch (ob->type) {
117                 case OB_MESH:
118                         key= ((Mesh *)ob->data)->key;
119                         break;
120                         
121                 case OB_LATTICE:
122                         key= ((Lattice *)ob->data)->key;
123                         break;
124                         
125                 case OB_CURVE:
126                 case OB_SURF:
127                         key= ((Curve *)ob->data)->key;
128                         break;
129                         
130                 default:
131                         return NULL;
132         }
133         
134         if (key) {
135                 if (key->type == KEY_RELATIVE)
136                         return key;
137         }
138         
139     return NULL;
140 }
141
142 /* Get data being edited in Action Editor (depending on current 'mode') */
143 static short actedit_get_context (const bContext *C, bAnimContext *ac, SpaceAction *saction)
144 {
145         /* sync settings with current view status, then return appropriate data */
146         switch (saction->mode) {
147                 case SACTCONT_ACTION: /* 'Action Editor' */
148                         /* if not pinned, sync with active object */
149                         if (saction->pin == 0) {
150                                 if (ac->obact)
151                                         saction->action = ac->obact->action;
152                                 else
153                                         saction->action= NULL;
154                         }
155                         
156                         ac->datatype= ANIMCONT_ACTION;
157                         ac->data= saction->action;
158                         
159                         ac->mode= saction->mode;
160                         return 1;
161                         
162                 case SACTCONT_SHAPEKEY: /* 'ShapeKey Editor' */
163                         ac->datatype= ANIMCONT_SHAPEKEY;
164                         ac->data= actedit_get_shapekeys(C, saction);
165                         
166                         ac->mode= saction->mode;
167                         return 1;
168                         
169                 case SACTCONT_GPENCIL: /* Grease Pencil */ // XXX review how this mode is handled...
170                         ac->datatype=ANIMCONT_GPENCIL;
171                         ac->data= CTX_wm_screen(C); // FIXME: add that dopesheet type thing here!
172                         
173                         ac->mode= saction->mode;
174                         return 1;
175                         
176                 case SACTCONT_DOPESHEET: /* DopeSheet */
177                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
178                         saction->ads.source= (ID *)ac->scene;
179                         
180                         ac->datatype= ANIMCONT_DOPESHEET;
181                         ac->data= &saction->ads;
182                         
183                         ac->mode= saction->mode;
184                         return 1;
185                 
186                 default: /* unhandled yet */
187                         ac->datatype= ANIMCONT_NONE;
188                         ac->data= NULL;
189                         
190                         ac->mode= -1;
191                         return 0;
192         }
193 }
194
195 /* ----------- Private Stuff - IPO Editor ------------- */
196
197 /* Get data being edited in IPO Editor (depending on current 'mode') */
198 static short ipoedit_get_context (const bContext *C, bAnimContext *ac, SpaceIpo *sipo)
199 {
200         // XXX FIXME...
201         return 0;
202 }
203
204 /* ----------- Public API --------------- */
205
206 /* Obtain current anim-data context from Blender Context info 
207  *      - AnimContext to write to is provided as pointer to var on stack so that we don't have
208  *        allocation/freeing costs (which are not that avoidable with channels).
209  *      - 
210  */
211 short ANIM_animdata_get_context (const bContext *C, bAnimContext *ac)
212 {
213         ScrArea *sa= CTX_wm_area(C);
214         ARegion *ar= CTX_wm_region(C);
215         Scene *scene= CTX_data_scene(C);
216         short ok= 0;
217         
218         /* clear old context info */
219         if (ac == NULL) return 0;
220         memset(ac, 0, sizeof(bAnimContext));
221         
222         /* set default context settings */
223         ac->scene= scene;
224         ac->obact= (scene && scene->basact)?  scene->basact->object : NULL;
225         ac->sa= sa;
226         ac->ar= ar;
227         ac->spacetype= sa->spacetype;
228         ac->regiontype= ar->regiontype;
229         
230         /* context depends on editor we are currently in */
231         switch (sa->spacetype) {
232                 case SPACE_ACTION:
233                 {
234                         SpaceAction *saction= (SpaceAction *)CTX_wm_space_data(C);
235                         ok= actedit_get_context(C, ac, saction);
236                 }
237                         break;
238                         
239                 case SPACE_IPO:
240                 {
241                         SpaceIpo *sipo= (SpaceIpo *)CTX_wm_space_data(C);
242                         ok= ipoedit_get_context(C, ac, sipo);
243                 }
244                         break;
245         }
246         
247         /* check if there's any valid data */
248         if (ok && ac->data)
249                 return 1;
250         else
251                 return 0;
252 }
253
254 /* ************************************************************ */
255 /* Blender Data <-- Filter --> Channels to be operated on */
256
257 /* ----------- 'Private' Stuff --------------- */
258
259 /* this function allocates memory for a new bAnimListElem struct for the 
260  * provided animation channel-data. 
261  */
262 bAnimListElem *make_new_animlistelem (void *data, short datatype, void *owner, short ownertype)
263 {
264         bAnimListElem *ale= NULL;
265         
266         /* only allocate memory if there is data to convert */
267         if (data) {
268                 /* allocate and set generic data */
269                 ale= MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
270                 
271                 ale->data= data;
272                 ale->type= datatype;
273                 ale->owner= owner;
274                 ale->ownertype= ownertype;
275                 
276                 if ((owner) && (ownertype == ANIMTYPE_ACHAN)) {
277                         bActionChannel *ochan= (bActionChannel *)owner;
278                         ale->grp= ochan->grp;
279                 }
280                 else 
281                         ale->grp= NULL;
282                 
283                 /* do specifics */
284                 switch (datatype) {
285                         case ANIMTYPE_OBJECT:
286                         {
287                                 Base *base= (Base *)data;
288                                 Object *ob= base->object;
289                                 
290                                 ale->flag= ob->flag;
291                                 
292                                 ale->key_data= ob;
293                                 ale->datatype= ALE_OB;
294                         }
295                                 break;
296                         case ANIMTYPE_FILLACTD:
297                         {
298                                 bAction *act= (bAction *)data;
299                                 
300                                 ale->flag= act->flag;
301                                 
302                                 ale->key_data= act;
303                                 ale->datatype= ALE_ACT;
304                         }
305                                 break;
306                         case ANIMTYPE_FILLIPOD:
307                         {
308                                 Object *ob= (Object *)data;
309                                 
310                                 ale->flag= FILTER_IPO_OBJC(ob);
311                                 
312                                 ale->key_data= ob->ipo;
313                                 ale->datatype= ALE_IPO;
314                         }
315                                 break;
316                         case ANIMTYPE_FILLCOND:
317                         {
318                                 Object *ob= (Object *)data;
319                                 
320                                 ale->flag= FILTER_CON_OBJC(ob);
321                                 
322                                 ale->key_data= NULL;
323                                 ale->datatype= ALE_NONE;
324                         }
325                                 break;
326                         case ANIMTYPE_FILLMATD:
327                         {
328                                 Object *ob= (Object *)data;
329                                 
330                                 ale->flag= FILTER_MAT_OBJC(ob);
331                                 
332                                 ale->key_data= NULL;
333                                 ale->datatype= ALE_NONE;
334                         }
335                                 break;
336                         
337                         case ANIMTYPE_DSMAT:
338                         {
339                                 Material *ma= (Material *)data;
340                                 
341                                 ale->flag= FILTER_MAT_OBJD(ma);
342                                 
343                                 ale->key_data= ma->ipo;
344                                 ale->datatype= ALE_IPO;
345                         }
346                                 break;
347                         case ANIMTYPE_DSLAM:
348                         {
349                                 Lamp *la= (Lamp *)data;
350                                 
351                                 ale->flag= FILTER_LAM_OBJD(la);
352                                 
353                                 ale->key_data= la->ipo;
354                                 ale->datatype= ALE_IPO;
355                         }
356                                 break;
357                         case ANIMTYPE_DSCAM:
358                         {
359                                 Camera *ca= (Camera *)data;
360                                 
361                                 ale->flag= FILTER_CAM_OBJD(ca);
362                                 
363                                 ale->key_data= ca->ipo;
364                                 ale->datatype= ALE_IPO;
365                         }
366                                 break;
367                         case ANIMTYPE_DSCUR:
368                         {
369                                 Curve *cu= (Curve *)data;
370                                 
371                                 ale->flag= FILTER_CUR_OBJD(cu);
372                                 
373                                 ale->key_data= cu->ipo;
374                                 ale->datatype= ALE_IPO;
375                         }
376                                 break;
377                         case ANIMTYPE_DSSKEY:
378                         {
379                                 Key *key= (Key *)data;
380                                 
381                                 ale->flag= FILTER_SKE_OBJD(key);
382                                 
383                                 ale->key_data= key->ipo;
384                                 ale->datatype= ALE_IPO;
385                         }
386                                 break;
387                                 
388                         case ANIMTYPE_GROUP:
389                         {
390                                 bActionGroup *agrp= (bActionGroup *)data;
391                                 
392                                 ale->flag= agrp->flag;
393                                 
394                                 ale->key_data= NULL;
395                                 ale->datatype= ALE_GROUP;
396                         }
397                                 break;
398                         case ANIMTYPE_ACHAN:
399                         {
400                                 bActionChannel *achan= (bActionChannel *)data;
401                                 
402                                 ale->flag= achan->flag;
403                                 
404                                 if (achan->ipo) {
405                                         ale->key_data= achan->ipo;
406                                         ale->datatype= ALE_IPO;
407                                 }
408                                 else {
409                                         ale->key_data= NULL;
410                                         ale->datatype= ALE_NONE;
411                                 }
412                         }       
413                                 break;
414                         case ANIMTYPE_CONCHAN:
415                         case ANIMTYPE_CONCHAN2:
416                         {
417                                 bConstraintChannel *conchan= (bConstraintChannel *)data;
418                                 
419                                 ale->flag= conchan->flag;
420                                 
421                                 if (datatype == ANIMTYPE_CONCHAN2) {
422                                         /* CONCHAN2 is a hack so that constraint-channels keyframes can be edited */
423                                         if (conchan->ipo) {
424                                                 ale->key_data= conchan->ipo;
425                                                 ale->datatype= ALE_IPO;
426                                         }
427                                         else {
428                                                 ale->key_data= NULL;
429                                                 ale->datatype= ALE_NONE;
430                                         }
431                                 }
432                                 else {
433                                         if ((conchan->ipo) && (conchan->ipo->curve.first)) {
434                                                 /* we assume that constraint ipo blocks only have 1 curve:
435                                                  * INFLUENCE, so we pretend that a constraint channel is 
436                                                  * really just a Ipo-Curve channel instead.
437                                                  */
438                                                 ale->key_data= conchan->ipo->curve.first;
439                                                 ale->datatype= ALE_ICU;
440                                         }
441                                         else {
442                                                 ale->key_data= NULL;
443                                                 ale->datatype= ALE_NONE;
444                                         }
445                                 }
446                         }
447                                 break;
448                         case ANIMTYPE_ICU:
449                         {
450                                 IpoCurve *icu= (IpoCurve *)data;
451                                 
452                                 ale->flag= icu->flag;
453                                 ale->key_data= icu;
454                                 ale->datatype= ALE_ICU;
455                         }
456                                 break;
457                         case ANIMTYPE_FILLIPO:
458                         case ANIMTYPE_FILLCON:
459                         {
460                                 bActionChannel *achan= (bActionChannel *)data;
461                                 
462                                 if (datatype == ANIMTYPE_FILLIPO)
463                                         ale->flag= FILTER_IPO_ACHAN(achan);
464                                 else
465                                         ale->flag= FILTER_CON_ACHAN(achan);
466                                         
467                                 ale->key_data= NULL;
468                                 ale->datatype= ALE_NONE;
469                         }
470                                 break;
471                         case ANIMTYPE_IPO:
472                         {
473                                 ale->flag= 0;
474                                 ale->key_data= data;
475                                 ale->datatype= ALE_IPO;
476                         }
477                                 break;
478                         
479                         case ANIMTYPE_GPLAYER:
480                         {
481                                 bGPDlayer *gpl= (bGPDlayer *)data;
482                                 
483                                 ale->flag= gpl->flag;
484                                 
485                                 ale->key_data= NULL;
486                                 ale->datatype= ALE_GPFRAME;
487                         }
488                                 break;
489                 }
490         }
491         
492         /* return created datatype */
493         return ale;
494 }
495  
496 /* ----------------------------------------- */
497
498 static int animdata_filter_actionchannel (ListBase *anim_data, bActionChannel *achan, int filter_mode, void *owner, short ownertype)
499 {
500         bAnimListElem *ale = NULL;
501         bConstraintChannel *conchan;
502         IpoCurve *icu;
503         short owned= (owner && ownertype)? 1 : 0;
504         int items = 0;
505         
506         /* only work with this channel and its subchannels if it is visible */
507         if (!(filter_mode & ANIMFILTER_VISIBLE) || VISIBLE_ACHAN(achan)) {
508                 /* only work with this channel and its subchannels if it is editable */
509                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_ACHAN(achan)) {
510                         /* check if this achan should only be included if it is selected */
511                         if (!(filter_mode & ANIMFILTER_SEL) || SEL_ACHAN(achan)) {
512                                 /* are we only interested in the ipo-curves? */
513                                 if ((filter_mode & ANIMFILTER_ONLYICU)==0) {
514                                         ale= make_new_animlistelem(achan, ANIMTYPE_ACHAN, achan, ANIMTYPE_ACHAN);
515                                         
516                                         if (ale) {
517                                                 if (owned) ale->id= owner;
518                                                 BLI_addtail(anim_data, ale);
519                                                 items++;
520                                         }
521                                 }
522                         }
523                         else {
524                                 /* for insert key... this check could be improved */
525                                 //return;  // FIXME...
526                         }
527                         
528                         /* check if expanded - if not, continue on to next animion channel */
529                         if (EXPANDED_ACHAN(achan) == 0 && (filter_mode & ANIMFILTER_ONLYICU)==0) {
530                                 /* only exit if we don't need to include constraint channels for group-channel keyframes */
531                                 if ( !(filter_mode & ANIMFILTER_IPOKEYS) || (achan->grp == NULL) || (EXPANDED_AGRP(achan->grp)==0) )
532                                         return items;
533                         }
534                                 
535                         /* ipo channels */
536                         if ((achan->ipo) && (filter_mode & ANIMFILTER_IPOKEYS)==0) {
537                                 /* include ipo-expand widget? */
538                                 if ((filter_mode & ANIMFILTER_CHANNELS) && (filter_mode & ANIMFILTER_ONLYICU)==0) {
539                                         ale= make_new_animlistelem(achan, ANIMTYPE_FILLIPO, achan, ANIMTYPE_ACHAN);
540                                         
541                                         if (ale) {
542                                                 if (owned) ale->id= owner;
543                                                 BLI_addtail(anim_data, ale);
544                                                 items++;
545                                         }
546                                 }
547                                 
548                                 /* add ipo-curve channels? */
549                                 if (FILTER_IPO_ACHAN(achan) || (filter_mode & ANIMFILTER_ONLYICU)) {
550                                         /* loop through ipo-curve channels, adding them */
551                                         for (icu= achan->ipo->curve.first; icu; icu=icu->next) {
552                                                 ale= make_new_animlistelem(icu, ANIMTYPE_ICU, achan, ANIMTYPE_ACHAN);
553                                                 
554                                                 if (ale) {
555                                                         if (owned) ale->id= owner;
556                                                         BLI_addtail(anim_data, ale); 
557                                                         items++;
558                                                 }
559                                         }
560                                 }
561                         }
562                         
563                         /* constraint channels */
564                         if (achan->constraintChannels.first) {
565                                 /* include constraint-expand widget? */
566                                 if ( (filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_ONLYICU)
567                                          && !(filter_mode & ANIMFILTER_IPOKEYS) ) 
568                                 {
569                                         ale= make_new_animlistelem(achan, ANIMTYPE_FILLCON, achan, ANIMTYPE_ACHAN);
570                                         
571                                         if (ale) {
572                                                 if (owned) ale->id= owner;
573                                                 BLI_addtail(anim_data, ale);
574                                                 items++;
575                                         }
576                                 }
577                                 
578                                 /* add constraint channels? */
579                                 if (FILTER_CON_ACHAN(achan) || (filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYICU)) {
580                                         /* loop through constraint channels, checking and adding them */
581                                         for (conchan=achan->constraintChannels.first; conchan; conchan=conchan->next) {
582                                                 /* only work with this channel and its subchannels if it is editable */
583                                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_CONCHAN(conchan)) {
584                                                         /* check if this conchan should only be included if it is selected */
585                                                         if (!(filter_mode & ANIMFILTER_SEL) || SEL_CONCHAN(conchan)) {
586                                                                 if (filter_mode & ANIMFILTER_IPOKEYS) {
587                                                                         ale= make_new_animlistelem(conchan, ANIMTYPE_CONCHAN2, achan, ANIMTYPE_ACHAN);
588                                                                         
589                                                                         if (ale) {
590                                                                                 if (owned) ale->id= owner;
591                                                                                 BLI_addtail(anim_data, ale);
592                                                                                 items++;
593                                                                         }
594                                                                 }
595                                                                 else {
596                                                                         ale= make_new_animlistelem(conchan, ANIMTYPE_CONCHAN, achan, ANIMTYPE_ACHAN);
597                                                                         
598                                                                         if (ale) {
599                                                                                 if (owned) ale->id= owner;
600                                                                                 BLI_addtail(anim_data, ale);
601                                                                                 items++;
602                                                                         }
603                                                                 }
604                                                         }
605                                                 }
606                                         }
607                                 }
608                         }
609                 }               
610         }
611         
612         /* return the number of items added to the list */
613         return items;
614 }
615
616 static int animdata_filter_action (ListBase *anim_data, bAction *act, int filter_mode, void *owner, short ownertype)
617 {
618         bAnimListElem *ale=NULL;
619         bActionGroup *agrp;
620         bActionChannel *achan, *lastchan=NULL;
621         short owned= (owner && ownertype) ? 1 : 0;
622         int items = 0;
623         
624         /* loop over groups */
625         for (agrp= act->groups.first; agrp; agrp= agrp->next) {
626                 /* add this group as a channel first */
627                 if (!(filter_mode & ANIMFILTER_ONLYICU) && !(filter_mode & ANIMFILTER_IPOKEYS)) {
628                         /* check if filtering by selection */
629                         if ( !(filter_mode & ANIMFILTER_SEL) || SEL_AGRP(agrp) ) {
630                                 ale= make_new_animlistelem(agrp, ANIMTYPE_GROUP, NULL, ANIMTYPE_NONE);
631                                 if (ale) {
632                                         if (owned) ale->id= owner;
633                                         BLI_addtail(anim_data, ale);
634                                         items++;
635                                 }
636                         }
637                 }
638                 
639                 /* store reference to last channel of group */
640                 if (agrp->channels.last) 
641                         lastchan= agrp->channels.last;
642                 
643                 
644                 /* there are some situations, where only the channels of the animive group should get considered */
645                 if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
646                         /* filters here are a bit convoulted...
647                          *      - groups show a "summary" of keyframes beside their name which must accessable for tools which handle keyframes
648                          *      - groups can be collapsed (and those tools which are only interested in channels rely on knowing that group is closed)
649                          *
650                          * cases when we should include animion-channels and so-forth inside group:
651                          *      - we don't care about visibility
652                          *      - group is expanded
653                          *      - we're interested in keyframes, but not if they appear in selected channels
654                          */
655                         if ( (!(filter_mode & ANIMFILTER_VISIBLE) || EXPANDED_AGRP(agrp)) || 
656                                  ( ((filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYICU)) && 
657                                    (!(filter_mode & ANIMFILTER_SEL) || (SEL_AGRP(agrp))) ) ) 
658                         {
659                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {                                       
660                                         for (achan= agrp->channels.first; achan && achan->grp==agrp; achan= achan->next) {
661                                                 items += animdata_filter_actionchannel(anim_data, achan, filter_mode, owner, ownertype);
662                                         }
663                                         
664                                         /* remove group from filtered list if last element is group 
665                                          * (i.e. only if group had channels, which were all hidden)
666                                          */
667                                         // XXX this is really hacky... it should be fixed in a much more elegant way!
668                                         if ( (ale) && (anim_data->last == ale) && 
669                                                  (ale->data == agrp) && (agrp->channels.first) ) 
670                                         {
671                                                 BLI_freelinkN(anim_data, ale);
672                                                 items--;
673                                         }
674                                 }
675                         }
676                 }
677         }
678         
679         /* loop over un-grouped animion channels (only if we're not only considering those channels in the animive group) */
680         if (!(filter_mode & ANIMFILTER_ACTGROUPED))  {
681                 for (achan=(lastchan)?(lastchan->next):(act->chanbase.first); achan; achan=achan->next) {
682                         items += animdata_filter_actionchannel(anim_data, achan, filter_mode, owner, ownertype);
683                 }
684         }
685         
686         /* return the number of items added to the list */
687         return items;
688 }
689
690 static int animdata_filter_shapekey (ListBase *anim_data, Key *key, int filter_mode, void *owner, short ownertype)
691 {
692         bAnimListElem *ale;
693         KeyBlock *kb;
694         IpoCurve *icu;
695         short owned= (owner && ownertype)? 1 : 0;
696         int i, items=0;
697         
698         /* are we filtering for display or editing */
699         if (filter_mode & ANIMFILTER_FORDRAWING) {
700                 /* for display - loop over shapekeys, adding ipo-curve references where needed */
701                 kb= key->block.first;
702                 
703                 /* loop through possible shapekeys, manually creating entries */
704                 for (i= 1; i < key->totkey; i++) {
705                         ale= MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
706                         kb = kb->next; /* do this even on the first try, as the first is 'Basis' (which doesn't get included) */
707                         
708                         ale->data= kb;
709                         ale->type= ANIMTYPE_SHAPEKEY; /* 'abused' usage of this type */
710                         ale->owner= key;
711                         ale->ownertype= ANIMTYPE_SHAPEKEY;
712                         ale->datatype= ALE_NONE;
713                         ale->index = i;
714                         
715                         if (key->ipo) {
716                                 for (icu= key->ipo->curve.first; icu; icu=icu->next) {
717                                         if (icu->adrcode == i) {
718                                                 ale->key_data= icu;
719                                                 ale->datatype= ALE_ICU;
720                                                 break;
721                                         }
722                                 }
723                         }
724                         
725                         if (owned) ale->id= owner;
726                         
727                         BLI_addtail(anim_data, ale);
728                         items++;
729                 }
730         }
731         else {
732                 /* loop over ipo curves if present - for editing */
733                 if (key->ipo) {
734                         if (filter_mode & ANIMFILTER_IPOKEYS) {
735                                 ale= make_new_animlistelem(key->ipo, ANIMTYPE_IPO, key, ANIMTYPE_SHAPEKEY);
736                                 if (ale) {
737                                         if (owned) ale->id= owner;
738                                         BLI_addtail(anim_data, ale);
739                                         items++;
740                                 }
741                         }
742                         else {
743                                 for (icu= key->ipo->curve.first; icu; icu=icu->next) {
744                                         ale= make_new_animlistelem(icu, ANIMTYPE_ICU, key, ANIMTYPE_SHAPEKEY);
745                                         if (ale) {
746                                                 if (owned) ale->id= owner;
747                                                 BLI_addtail(anim_data, ale);
748                                                 items++;
749                                         }
750                                 }
751                         }
752                 }
753         }
754         
755         /* return the number of items added to the list */
756         return items;
757 }
758  
759 #if 0
760 // FIXME: switch this to use the bDopeSheet...
761 static int animdata_filter_gpencil (ListBase *anim_data, bScreen *sc, int filter_mode)
762 {
763         bAnimListElem *ale;
764         ScrArea *sa, *curarea;
765         bGPdata *gpd;
766         bGPDlayer *gpl;
767         int items = 0;
768         
769         /* check if filtering types are appropriate */
770         if ( !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYICU|ANIMFILTER_ACTGROUPED)) ) 
771         {
772                 /* special hack for fullscreen area (which must be this one then):
773                  *      - we use the curarea->full as screen to get spaces from, since the
774                  *        old (pre-fullscreen) screen was stored there...
775                  *      - this is needed as all data would otherwise disappear
776                  */
777                 // XXX need to get new alternative for curarea
778                 if ((curarea->full) && (curarea->spacetype==SPACE_ACTION))
779                         sc= curarea->full;
780                 
781                 /* loop over spaces in current screen, finding gpd blocks (could be slow!) */
782                 for (sa= sc->areabase.first; sa; sa= sa->next) {
783                         /* try to get gp data */
784                         // XXX need to put back grease pencil api...
785                         gpd= gpencil_data_getactive(sa);
786                         if (gpd == NULL) continue;
787                         
788                         /* add gpd as channel too (if for drawing, and it has layers) */
789                         if ((filter_mode & ANIMFILTER_FORDRAWING) && (gpd->layers.first)) {
790                                 /* add to list */
791                                 ale= make_new_animlistelem(gpd, ANIMTYPE_GPDATABLOCK, sa, ANIMTYPE_SPECIALDATA);
792                                 if (ale) {
793                                         BLI_addtail(anim_data, ale);
794                                         items++;
795                                 }
796                         }
797                         
798                         /* only add layers if they will be visible (if drawing channels) */
799                         if ( !(filter_mode & ANIMFILTER_VISIBLE) || (EXPANDED_GPD(gpd)) ) {
800                                 /* loop over layers as the conditions are acceptable */
801                                 for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
802                                         /* only if selected */
803                                         if (!(filter_mode & ANIMFILTER_SEL) || SEL_GPL(gpl)) {
804                                                 /* only if editable */
805                                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) {
806                                                         /* add to list */
807                                                         ale= make_new_animlistelem(gpl, ANIMTYPE_GPLAYER, gpd, ANIMTYPE_GPDATABLOCK);
808                                                         if (ale) {
809                                                                 BLI_addtail(anim_data, ale);
810                                                                 items++;
811                                                         }
812                                                 }
813                                         }
814                                 }
815                         }
816                 }
817         }
818         
819         /* return the number of items added to the list */
820         return items;
821 }
822 #endif 
823
824 static int animdata_filter_dopesheet_mats (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
825 {
826         bAnimListElem *ale=NULL;
827         Object *ob= base->object;
828         IpoCurve *icu;
829         int items = 0;
830         
831         /* include materials-expand widget? */
832         if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYICU))) {
833                 ale= make_new_animlistelem(ob, ANIMTYPE_FILLMATD, base, ANIMTYPE_OBJECT);
834                 if (ale) {
835                         BLI_addtail(anim_data, ale);
836                         items++;
837                 }
838         }
839         
840         /* add materials? */
841         if (FILTER_MAT_OBJC(ob) || (filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYICU)) {
842                 short a;
843                 
844                 /* for each material, either add channels separately, or as ipo-block */
845                 for (a=0; a<ob->totcol; a++) {
846                         Material *ma= give_current_material(ob, a);
847                         
848                         /* for now, if no material returned, skip (this shouldn't confuse the user I hope) */
849                         if (ELEM(NULL, ma, ma->ipo)) continue;
850                         
851                         /* include material-expand widget? */
852                         // hmm... do we need to store the index of this material in the array anywhere?
853                         if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
854                                 ale= make_new_animlistelem(ma, ANIMTYPE_DSMAT, base, ANIMTYPE_OBJECT);
855                                 if (ale) {
856                                         BLI_addtail(anim_data, ale);
857                                         items++;
858                                 }
859                         }
860                         
861                         /* add material's ipo-curve channels? */
862                         if ( (FILTER_MAT_OBJD(ma) || (filter_mode & ANIMFILTER_ONLYICU)) && 
863                                   !(filter_mode & ANIMFILTER_IPOKEYS) ) 
864                         {
865                                 /* loop through ipo-curve channels, adding them */
866                                 for (icu= ma->ipo->curve.first; icu; icu=icu->next) {
867                                         /* only if selected (if checking for selection) */
868                                         if ( !(filter_mode & ANIMFILTER_SEL) || (SEL_ICU(icu)) ) {
869                                                 ale= make_new_animlistelem(icu, ANIMTYPE_ICU, base, ANIMTYPE_OBJECT);
870                                                 if (ale) {
871                                                         /* make owner the material not object, so that indent is not just object level */
872                                                         ale->id= (ID *)ma;
873                                                         BLI_addtail(anim_data, ale);
874                                                         items++;
875                                                 }
876                                         }
877                                 }
878                         }
879                 }
880         }
881         
882         /* return the number of items added to the list */
883         return items;
884 }
885
886 static int animdata_filter_dopesheet_cam (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
887 {
888         bAnimListElem *ale=NULL;
889         Object *ob= base->object;
890         Camera *ca= (Camera *)ob->data;
891         IpoCurve *icu;
892         int items = 0;
893         
894         /* include camera-expand widget? */
895         if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
896                 ale= make_new_animlistelem(ca, ANIMTYPE_DSCAM, base, ANIMTYPE_OBJECT);
897                 if (ale) {
898                         BLI_addtail(anim_data, ale);
899                         items++;
900                 }
901         }
902         
903         /* add camera ipo-curve channels? */
904         if ( (FILTER_CAM_OBJD(ca) || (filter_mode & ANIMFILTER_ONLYICU)) && 
905                   !(filter_mode & ANIMFILTER_IPOKEYS) ) 
906         {
907                 /* loop through ipo-curve channels, adding them */
908                 for (icu= ca->ipo->curve.first; icu; icu=icu->next) {
909                         /* only if selected (if checking for selection) */
910                         if ( !(filter_mode & ANIMFILTER_SEL) || (SEL_ICU(icu)) ) {
911                                 ale= make_new_animlistelem(icu, ANIMTYPE_ICU, base, ANIMTYPE_OBJECT);
912                                 if (ale) {
913                                         /* make owner the material not object, so that indent is not just object level */
914                                         ale->id= (ID *)ca;
915                                         BLI_addtail(anim_data, ale);
916                                         items++;
917                                 }
918                         }
919                 }
920         }
921         
922         /* return the number of items added to the list */
923         return items;
924 }
925
926 static int animdata_filter_dopesheet_lamp (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
927 {
928         bAnimListElem *ale=NULL;
929         Object *ob= base->object;
930         Lamp *la= (Lamp *)ob->data;
931         IpoCurve *icu;
932         int items = 0;
933         
934         /* include lamp-expand widget? */
935         if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
936                 ale= make_new_animlistelem(la, ANIMTYPE_DSLAM, base, ANIMTYPE_OBJECT);
937                 if (ale) {
938                         BLI_addtail(anim_data, ale);
939                         items++;
940                 }
941         }
942         
943         /* add lamp ipo-curve channels? */
944         if ( (FILTER_LAM_OBJD(la) || (filter_mode & ANIMFILTER_ONLYICU)) && 
945                   !(filter_mode & ANIMFILTER_IPOKEYS) ) 
946         {
947                 /* loop through ipo-curve channels, adding them */
948                 for (icu= la->ipo->curve.first; icu; icu=icu->next) {
949                         /* only if selected (if checking for selection) */
950                         if ( !(filter_mode & ANIMFILTER_SEL) || (SEL_ICU(icu)) ) {
951                                 ale= make_new_animlistelem(icu, ANIMTYPE_ICU, base, ANIMTYPE_OBJECT);
952                                 if (ale) {
953                                         /* make owner the material not object, so that indent is not just object level */
954                                         ale->id= (ID *)la;
955                                         BLI_addtail(anim_data, ale);
956                                         items++;
957                                 }
958                         }
959                 }
960         }
961         
962         /* return the number of items added to the list */
963         return items;
964 }
965
966 static int animdata_filter_dopesheet_curve (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
967 {
968         bAnimListElem *ale=NULL;
969         Object *ob= base->object;
970         Curve *cu= (Curve *)ob->data;
971         IpoCurve *icu;
972         int items = 0;
973         
974         /* include curve-expand widget? */
975         if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
976                 ale= make_new_animlistelem(cu, ANIMTYPE_DSCUR, base, ANIMTYPE_OBJECT);
977                 if (ale) {
978                         BLI_addtail(anim_data, ale);
979                         items++;
980                 }
981         }
982         
983         /* add curve ipo-curve channels? */
984         if ( (FILTER_CUR_OBJD(cu) || (filter_mode & ANIMFILTER_ONLYICU)) && 
985                   !(filter_mode & ANIMFILTER_IPOKEYS) ) 
986         {
987                 /* loop through ipo-curve channels, adding them */
988                 for (icu= cu->ipo->curve.first; icu; icu=icu->next) {
989                         /* only if selected (if checking for selection) */
990                         if ( !(filter_mode & ANIMFILTER_SEL) || (SEL_ICU(icu)) ) {
991                                 ale= make_new_animlistelem(icu, ANIMTYPE_ICU, base, ANIMTYPE_OBJECT);
992                                 if (ale) {
993                                         /* make owner the material not object, so that indent is not just object level */
994                                         ale->id= (ID *)cu;
995                                         BLI_addtail(anim_data, ale);
996                                         items++;
997                                 }
998                         }
999                 }
1000         }
1001         
1002         /* return the number of items added to the list */
1003         return items;
1004 }
1005
1006 static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
1007 {
1008         bAnimListElem *ale=NULL;
1009         Scene *sce= (Scene *)ads->source;
1010         Object *ob= base->object;
1011         Key *key= ob_get_key(ob);
1012         IpoCurve *icu;
1013         int items = 0;
1014         
1015         /* add this object as a channel first */
1016         if (!(filter_mode & ANIMFILTER_ONLYICU) && !(filter_mode & ANIMFILTER_IPOKEYS)) {
1017                 /* check if filtering by selection */
1018                 if ( !(filter_mode & ANIMFILTER_SEL) || ((base->flag & SELECT) || (base == sce->basact)) ) {
1019                         ale= make_new_animlistelem(base, ANIMTYPE_OBJECT, NULL, ANIMTYPE_NONE);
1020                         if (ale) {
1021                                 BLI_addtail(anim_data, ale);
1022                                 items++;
1023                         }
1024                 }
1025         }
1026         
1027         /* if collapsed, don't go any further (unless adding keyframes only) */
1028         if ( (EXPANDED_OBJC(ob) == 0) && !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYICU)) )
1029                 return items;
1030         
1031         /* IPO? */
1032         if ((ob->ipo) && !(ads->filterflag & ADS_FILTER_NOIPOS)) {              
1033                 /* include ipo-expand widget? */
1034                 if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
1035                         ale= make_new_animlistelem(ob, ANIMTYPE_FILLIPOD, base, ANIMTYPE_OBJECT);
1036                         if (ale) {
1037                                 BLI_addtail(anim_data, ale);
1038                                 items++;
1039                         }
1040                 }
1041                 
1042                 /* add ipo-curve channels? */
1043                 if ( (FILTER_IPO_OBJC(ob) || (filter_mode & ANIMFILTER_ONLYICU)) && 
1044                           !(filter_mode & ANIMFILTER_IPOKEYS) ) 
1045                 {
1046                         /* loop through ipo-curve channels, adding them */
1047                         for (icu= ob->ipo->curve.first; icu; icu=icu->next) {
1048                                 /* only if selected (if checking for selection) */
1049                                 if ( !(filter_mode & ANIMFILTER_SEL) || (SEL_ICU(icu)) ) {
1050                                         ale= make_new_animlistelem(icu, ANIMTYPE_ICU, base, ANIMTYPE_OBJECT);
1051                                         if (ale) {
1052                                                 BLI_addtail(anim_data, ale); 
1053                                                 items++;
1054                                         }
1055                                 }
1056                         }
1057                 }
1058         }
1059         
1060         /* Action? */
1061         if ((ob->action) && !(ads->filterflag & ADS_FILTER_NOACTS)) {
1062                 /* include animion-expand widget? */
1063                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYICU))) {
1064                         ale= make_new_animlistelem(ob->action, ANIMTYPE_FILLACTD, base, ANIMTYPE_OBJECT);
1065                         if (ale) {
1066                                 ale->id= (ID *)ob; // err.... is this a good idea?
1067                                 BLI_addtail(anim_data, ale);
1068                                 items++;
1069                         }
1070                 }
1071                 
1072                 /* add ipo-curve channels? */
1073                 if (EXPANDED_ACTC(ob->action) || !(filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_FORDRAWING))) {
1074                         // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
1075                         items += animdata_filter_action(anim_data, ob->action, filter_mode, ob, ANIMTYPE_OBJECT); 
1076                 }
1077         }
1078         
1079         /* ShapeKeys? */
1080         if ((key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
1081                 /* include shapekey-expand widget? */
1082                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYICU))) {
1083                         ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT);
1084                         if (ale) {
1085                                 BLI_addtail(anim_data, ale);
1086                                 items++;
1087                         }
1088                 }
1089                 
1090                 /* add channels */
1091                 if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYICU)) {
1092                         items += animdata_filter_shapekey (anim_data, key, filter_mode, ob, ANIMTYPE_OBJECT);
1093                 }
1094         }
1095         
1096         /* Materials? */
1097         if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT))
1098                 items += animdata_filter_dopesheet_mats(anim_data, ads, base, filter_mode);
1099         
1100         /* Object Data */
1101         switch (ob->type) {
1102                 case OB_CAMERA: /* ------- Camera ------------ */
1103                 {
1104                         Camera *ca= (Camera *)ob->data;
1105                         if ((ca->ipo) && !(ads->filterflag & ADS_FILTER_NOCAM))
1106                                 items += animdata_filter_dopesheet_cam(anim_data, ads, base, filter_mode);
1107                 }
1108                         break;
1109                 case OB_LAMP: /* ---------- Lamp ----------- */
1110                 {
1111                         Lamp *la= (Lamp *)ob->data;
1112                         if ((la->ipo) && !(ads->filterflag & ADS_FILTER_NOLAM))
1113                                 items += animdata_filter_dopesheet_lamp(anim_data, ads, base, filter_mode);
1114                 }
1115                         break;
1116                 case OB_CURVE: /* ------- Curve ---------- */
1117                 {
1118                         Curve *cu= (Curve *)ob->data;
1119                         if ((cu->ipo) && !(ads->filterflag & ADS_FILTER_NOCUR))
1120                                 items += animdata_filter_dopesheet_curve(anim_data, ads, base, filter_mode);
1121                 }
1122                         break;
1123         }
1124         
1125         /* Constraint Channels? */
1126         if ((ob->constraintChannels.first) && !(ads->filterflag & ADS_FILTER_NOCONSTRAINTS)) {
1127                 bConstraintChannel *conchan;
1128                 
1129                 /* include constraint-expand widget? */
1130                 if ( (filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_ONLYICU)
1131                          && !(filter_mode & ANIMFILTER_IPOKEYS) ) 
1132                 {
1133                         ale= make_new_animlistelem(ob, ANIMTYPE_FILLCOND, base, ANIMTYPE_OBJECT);
1134                         if (ale) {
1135                                 BLI_addtail(anim_data, ale);
1136                                 items++;
1137                         }
1138                 }
1139                 
1140                 /* add constraint channels? */
1141                 if (FILTER_CON_OBJC(ob) || (filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYICU)) {
1142                         /* loop through constraint channels, checking and adding them */
1143                         for (conchan=ob->constraintChannels.first; conchan; conchan=conchan->next) {
1144                                 /* only work with this channel and its subchannels if it is editable */
1145                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_CONCHAN(conchan)) {
1146                                         /* check if this conchan should only be included if it is selected */
1147                                         if (!(filter_mode & ANIMFILTER_SEL) || SEL_CONCHAN(conchan)) {
1148                                                 if (filter_mode & ANIMFILTER_IPOKEYS) {
1149                                                         ale= make_new_animlistelem(conchan, ANIMTYPE_CONCHAN2, base, ANIMTYPE_OBJECT);
1150                                                         if (ale) {
1151                                                                 ale->id= (ID *)ob;
1152                                                                 BLI_addtail(anim_data, ale);
1153                                                                 items++;
1154                                                         }
1155                                                 }
1156                                                 else {
1157                                                         ale= make_new_animlistelem(conchan, ANIMTYPE_CONCHAN, base, ANIMTYPE_OBJECT);
1158                                                         if (ale) {
1159                                                                 ale->id= (ID *)ob;
1160                                                                 BLI_addtail(anim_data, ale);
1161                                                                 items++;
1162                                                         }
1163                                                 }
1164                                         }
1165                                 }
1166                         }
1167                 }
1168         }
1169         
1170         /* return the number of items added to the list */
1171         return items;
1172 }       
1173
1174 // 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)
1175 static int animdata_filter_dopesheet (ListBase *anim_data, bDopeSheet *ads, int filter_mode)
1176 {
1177         Scene *sce= (Scene *)ads->source;
1178         Base *base;
1179         int items = 0;
1180         
1181         /* check that we do indeed have a scene */
1182         if ((ads->source == NULL) || (GS(ads->source->name)!=ID_SCE)) {
1183                 printf("DopeSheet Error: Not scene! \n");
1184                 return 0;
1185         }
1186         
1187         /* loop over all bases in the scene */
1188         for (base= sce->base.first; base; base= base->next) {
1189                 /* check if there's an object (all the relevant checks are done in the ob-function) */
1190                 if (base->object) {
1191                         Object *ob= base->object;
1192                         Key *key= ob_get_key(ob);
1193                         short ipoOk, actOk, constsOk, keyOk, dataOk;
1194                         
1195                         /* firstly, check if object can be included, by the following fanimors:
1196                          *      - if only visible, must check for layer and also viewport visibility
1197                          *      - if only selected, must check if object is selected 
1198                          *      - there must be animation data to edit
1199                          */
1200                         // TODO: if cache is implemented, just check name here, and then 
1201                         if (filter_mode & ANIMFILTER_VISIBLE) {
1202                                 /* layer visibility */
1203                                 if ((ob->lay & sce->lay)==0) continue;
1204                                 
1205                                 /* outliner restrict-flag */
1206                                 if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
1207                         }
1208                         
1209                         /* additionally, dopesheet filtering also affects what objects to consider */
1210                         if (ads->filterflag) {
1211                                 /* check selection and object type filters */
1212                                 if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & SELECT) || (base == sce->basact)) )  {
1213                                         /* only selected should be shown */
1214                                         continue;
1215                                 }
1216                                 if ((ads->filterflag & ADS_FILTER_NOARM) && (ob->type == OB_ARMATURE)) {
1217                                         /* not showing armatures  */
1218                                         continue;
1219                                 }
1220                                 if ((ads->filterflag & ADS_FILTER_NOOBJ) && (ob->type != OB_ARMATURE)) {
1221                                         /* not showing objects that aren't armatures */
1222                                         continue;
1223                                 }
1224                                 
1225                                 /* check filters for datatypes */
1226                                 ipoOk= ((ob->ipo) && !(ads->filterflag & ADS_FILTER_NOIPOS));
1227                                 actOk= ((ob->action) && !(ads->filterflag & ADS_FILTER_NOACTS));
1228                                 constsOk= ((ob->constraintChannels.first) && !(ads->filterflag & ADS_FILTER_NOCONSTRAINTS));
1229                                 keyOk= ((key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS));
1230                                 
1231                                 switch (ob->type) {
1232                                         case OB_CAMERA: /* ------- Camera ------------ */
1233                                         {
1234                                                 Camera *ca= (Camera *)ob->data;
1235                                                 dataOk= ((ca->ipo) && !(ads->filterflag & ADS_FILTER_NOCAM));                                           
1236                                         }
1237                                                 break;
1238                                         case OB_LAMP: /* ---------- Lamp ----------- */
1239                                         {
1240                                                 Lamp *la= (Lamp *)ob->data;
1241                                                 dataOk= ((la->ipo) && !(ads->filterflag & ADS_FILTER_NOLAM));
1242                                         }
1243                                                 break;
1244                                         case OB_CURVE: /* -------- Curve ---------- */
1245                                         {
1246                                                 Curve *cu= (Curve *)ob->data;
1247                                                 dataOk= ((cu->ipo) && !(ads->filterflag & ADS_FILTER_NOCUR));
1248                                         }
1249                                                 break;
1250                                         default: /* --- other --- */
1251                                                 dataOk= 0;
1252                                                 break;
1253                                 }
1254                                 
1255                                 /* check if all bad (i.e. nothing to show) */
1256                                 if (!ipoOk && !actOk && !constsOk && !keyOk && !dataOk)
1257                                         continue;
1258                         }
1259                         else {
1260                                 /* check data-types */
1261                                 ipoOk= (ob->ipo != NULL);
1262                                 actOk= (ob->action != NULL);
1263                                 constsOk= (ob->constraintChannels.first != NULL);
1264                                 keyOk= (key != NULL);
1265                                 
1266                                 switch (ob->type) {
1267                                         case OB_CAMERA: /* ------- Camera ------------ */
1268                                         {
1269                                                 Camera *ca= (Camera *)ob->data;
1270                                                 dataOk= (ca->ipo != NULL);                                              
1271                                         }
1272                                                 break;
1273                                         case OB_LAMP: /* ---------- Lamp ----------- */
1274                                         {
1275                                                 Lamp *la= (Lamp *)ob->data;
1276                                                 dataOk= (la->ipo != NULL);
1277                                         }
1278                                                 break;
1279                                         case OB_CURVE: /* -------- Curve ---------- */
1280                                         {
1281                                                 Curve *cu= (Curve *)ob->data;
1282                                                 dataOk= (cu->ipo != NULL);
1283                                         }
1284                                                 break;
1285                                         default: /* --- other --- */
1286                                                 dataOk= 0;
1287                                                 break;
1288                                 }
1289                                 
1290                                 /* check if all bad (i.e. nothing to show) */
1291                                 if (!ipoOk && !actOk && !constsOk && !keyOk && !dataOk)
1292                                         continue;
1293                         }
1294                         
1295                         /* since we're still here, this object should be usable */
1296                         items += animdata_filter_dopesheet_ob(anim_data, ads, base, filter_mode);
1297                 }
1298         }
1299         
1300         /* return the number of items in the list */
1301         return items;
1302 }
1303
1304 /* ----------- Public API --------------- */
1305
1306 /* This function filters the active data source to leave only animation channels suitable for
1307  * usage by the caller. It will return the length of the list 
1308  * 
1309  *      *act_data: is a pointer to a ListBase, to which the filtered animation channels
1310  *              will be placed for use.
1311  *      filter_mode: how should the data be filtered - bitmapping accessed flags
1312  */
1313 int ANIM_animdata_filter (ListBase *anim_data, int filter_mode, void *data, short datatype)
1314 {
1315         int items = 0;
1316         
1317         /* only filter data if there's somewhere to put it */
1318         if (data && anim_data) {
1319                 bAnimListElem *ale, *next;
1320                 
1321                 /* firstly filter the data */
1322                 switch (datatype) {
1323                         case ANIMCONT_ACTION:
1324                                 items= animdata_filter_action(anim_data, data, filter_mode, NULL, ANIMTYPE_NONE);
1325                                 break;
1326                         case ANIMCONT_SHAPEKEY:
1327                                 items= animdata_filter_shapekey(anim_data, data, filter_mode, NULL, ANIMTYPE_NONE);
1328                                 break;
1329                         case ANIMCONT_GPENCIL:
1330                                 //items= animdata_filter_gpencil(anim_data, data, filter_mode);
1331                                 break;
1332                         case ANIMCONT_DOPESHEET:
1333                                 items= animdata_filter_dopesheet(anim_data, data, filter_mode);
1334                                 break;
1335                                 
1336                         case ANIMCONT_IPO:
1337                                 // FIXME: this will be used for showing a single IPO-block (not too useful from animator perspective though!)
1338                                 //items= 0;
1339                                 break;
1340                 }
1341                         
1342                 /* remove any weedy entries */
1343                 // XXX this is weedy code!
1344                 for (ale= anim_data->first; ale; ale= next) {
1345                         next= ale->next;
1346                         
1347                         if (ale->type == ANIMTYPE_NONE) {
1348                                 items--;
1349                                 BLI_freelinkN(anim_data, ale);
1350                         }
1351                         
1352                         if (filter_mode & ANIMFILTER_IPOKEYS) {
1353                                 if (ale->datatype != ALE_IPO) {
1354                                         items--;
1355                                         BLI_freelinkN(anim_data, ale);
1356                                 }
1357                                 else if (ale->key_data == NULL) {
1358                                         items--;
1359                                         BLI_freelinkN(anim_data, ale);
1360                                 }
1361                         }
1362                 }
1363         }
1364         
1365         /* return the number of items in the list */
1366         return items;
1367 }
1368
1369 /* ************************************************************ */