Merge branch 'blender2.7'
[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_cachefile_types.h"
57 #include "DNA_lamp_types.h"
58 #include "DNA_lattice_types.h"
59 #include "DNA_linestyle_types.h"
60 #include "DNA_key_types.h"
61 #include "DNA_mask_types.h"
62 #include "DNA_material_types.h"
63 #include "DNA_mesh_types.h"
64 #include "DNA_meta_types.h"
65 #include "DNA_movieclip_types.h"
66 #include "DNA_node_types.h"
67 #include "DNA_particle_types.h"
68 #include "DNA_space_types.h"
69 #include "DNA_sequence_types.h"
70 #include "DNA_scene_types.h"
71 #include "DNA_screen_types.h"
72 #include "DNA_speaker_types.h"
73 #include "DNA_world_types.h"
74 #include "DNA_gpencil_types.h"
75 #include "DNA_brush_types.h"
76 #include "DNA_object_types.h"
77 #include "DNA_userdef_types.h"
78 #include "DNA_layer_types.h"
79
80 #include "MEM_guardedalloc.h"
81
82 #include "BLI_blenlib.h"
83 #include "BLI_utildefines.h"
84 #include "BLI_alloca.h"
85 #include "BLI_ghash.h"
86 #include "BLI_string.h"
87
88 #include "BKE_action.h"
89 #include "BKE_animsys.h"
90 #include "BKE_collection.h"
91 #include "BKE_context.h"
92 #include "BKE_fcurve.h"
93 #include "BKE_global.h"
94 #include "BKE_key.h"
95 #include "BKE_layer.h"
96 #include "BKE_main.h"
97 #include "BKE_material.h"
98 #include "BKE_modifier.h"
99 #include "BKE_node.h"
100 #include "BKE_mask.h"
101 #include "BKE_sequencer.h"
102
103 #include "ED_anim_api.h"
104 #include "ED_markers.h"
105
106 #include "UI_resources.h"  /* for TH_KEYFRAME_SCALE lookup */
107
108 /* ************************************************************ */
109 /* Blender Context <-> Animation Context mapping */
110
111 /* ----------- Private Stuff - General -------------------- */
112
113 /* Get vertical scaling factor (i.e. typically used for keyframe size) */
114 static void animedit_get_yscale_factor(bAnimContext *ac)
115 {
116         bTheme *btheme = UI_GetTheme();
117
118         /* grab scale factor directly from action editor setting
119          * NOTE: This theme setting doesn't have an ID, as it cannot be accessed normally
120          *       since it is a float, and the theme settings methods can only handle chars.
121          */
122         ac->yscale_fac = btheme->tact.keyframe_scale_fac;
123
124         /* clamp to avoid problems with uninitialised values... */
125         if (ac->yscale_fac < 0.1f)
126                 ac->yscale_fac = 1.0f;
127         //printf("yscale_fac = %f\n", ac->yscale_fac);
128 }
129
130 /* ----------- Private Stuff - Action Editor ------------- */
131
132 /* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */
133 /* Note: there's a similar function in key.c (BKE_key_from_object) */
134 static Key *actedit_get_shapekeys(bAnimContext *ac)
135 {
136         ViewLayer *view_layer = ac->view_layer;
137         Object *ob;
138         Key *key;
139
140         ob = OBACT(view_layer);
141         if (ob == NULL)
142                 return NULL;
143
144         /* XXX pinning is not available in 'ShapeKey' mode... */
145         //if (saction->pin) return NULL;
146
147         /* shapekey data is stored with geometry data */
148         key = BKE_key_from_object(ob);
149
150         if (key) {
151                 if (key->type == KEY_RELATIVE)
152                         return key;
153         }
154
155         return NULL;
156 }
157
158 /* Get data being edited in Action Editor (depending on current 'mode') */
159 static bool actedit_get_context(bAnimContext *ac, SpaceAction *saction)
160 {
161         /* get dopesheet */
162         ac->ads = &saction->ads;
163
164         /* sync settings with current view status, then return appropriate data */
165         switch (saction->mode) {
166                 case SACTCONT_ACTION: /* 'Action Editor' */
167                         /* if not pinned, sync with active object */
168                         if (/*saction->pin == 0*/ true) {
169                                 if (ac->obact && ac->obact->adt)
170                                         saction->action = ac->obact->adt->action;
171                                 else
172                                         saction->action = NULL;
173                         }
174
175                         ac->datatype = ANIMCONT_ACTION;
176                         ac->data = saction->action;
177
178                         ac->mode = saction->mode;
179                         return true;
180
181                 case SACTCONT_SHAPEKEY: /* 'ShapeKey Editor' */
182                         ac->datatype = ANIMCONT_SHAPEKEY;
183                         ac->data = actedit_get_shapekeys(ac);
184
185                         /* if not pinned, sync with active object */
186                         if (/*saction->pin == 0*/ true) {
187                                 Key *key = (Key *)ac->data;
188
189                                 if (key && key->adt)
190                                         saction->action = key->adt->action;
191                                 else
192                                         saction->action = NULL;
193                         }
194
195                         ac->mode = saction->mode;
196                         return true;
197
198                 case SACTCONT_GPENCIL: /* Grease Pencil */ /* XXX review how this mode is handled... */
199                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
200                         saction->ads.source = (ID *)ac->scene;
201
202                         ac->datatype = ANIMCONT_GPENCIL;
203                         ac->data = &saction->ads;
204
205                         ac->mode = saction->mode;
206                         return true;
207
208                 case SACTCONT_CACHEFILE: /* Cache File */ /* XXX review how this mode is handled... */
209                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
210                         saction->ads.source = (ID *)ac->scene;
211
212                         ac->datatype = ANIMCONT_CHANNEL;
213                         ac->data = &saction->ads;
214
215                         ac->mode = saction->mode;
216                         return true;
217
218                 case SACTCONT_MASK: /* Mask */ /* XXX review how this mode is handled... */
219                 {
220                         /* TODO, other methods to get the mask */
221                         // Sequence *seq = BKE_sequencer_active_get(ac->scene);
222                         //MovieClip *clip = ac->scene->clip;
223 //                      struct Mask *mask = seq ? seq->mask : NULL;
224
225                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
226                         saction->ads.source = (ID *)ac->scene;
227
228                         ac->datatype = ANIMCONT_MASK;
229                         ac->data = &saction->ads;
230
231                         ac->mode = saction->mode;
232                         return true;
233                 }
234
235                 case SACTCONT_DOPESHEET: /* DopeSheet */
236                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
237                         saction->ads.source = (ID *)ac->scene;
238
239                         ac->datatype = ANIMCONT_DOPESHEET;
240                         ac->data = &saction->ads;
241
242                         ac->mode = saction->mode;
243                         return true;
244
245                 case SACTCONT_TIMELINE: /* Timeline */
246                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
247                         saction->ads.source = (ID *)ac->scene;
248
249                         /* sync scene's "selected keys only" flag with our "only selected" flag
250                          * XXX: This is a workaround for T55525. We shouldn't really be syncing the flags like this,
251                          *      but it's a simpler fix for now than also figuring out how the next/prev keyframe tools
252                          *      should work in the 3D View if we allowed full access to the timeline's dopesheet filters
253                          *      (i.e. we'd have to figure out where to host those settings, to be on a scene level like
254                          *      this flag currently is, along with several other unknowns)
255                          */
256                         if (ac->scene->flag & SCE_KEYS_NO_SELONLY)
257                                 saction->ads.filterflag &= ~ADS_FILTER_ONLYSEL;
258                         else
259                                 saction->ads.filterflag |= ADS_FILTER_ONLYSEL;
260
261                         ac->datatype = ANIMCONT_TIMELINE;
262                         ac->data = &saction->ads;
263
264                         ac->mode = saction->mode;
265                         return true;
266
267                 default: /* unhandled yet */
268                         ac->datatype = ANIMCONT_NONE;
269                         ac->data = NULL;
270
271                         ac->mode = -1;
272                         return false;
273         }
274 }
275
276 /* ----------- Private Stuff - Graph Editor ------------- */
277
278 /* Get data being edited in Graph Editor (depending on current 'mode') */
279 static bool graphedit_get_context(bAnimContext *ac, SpaceIpo *sipo)
280 {
281         /* init dopesheet data if non-existent (i.e. for old files) */
282         if (sipo->ads == NULL) {
283                 sipo->ads = MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
284                 sipo->ads->source = (ID *)ac->scene;
285         }
286         ac->ads = sipo->ads;
287
288         /* set settings for Graph Editor - "Selected = Editable" */
289         if (sipo->flag & SIPO_SELCUVERTSONLY)
290                 sipo->ads->filterflag |= ADS_FILTER_SELEDIT;
291         else
292                 sipo->ads->filterflag &= ~ADS_FILTER_SELEDIT;
293
294         /* sync settings with current view status, then return appropriate data */
295         switch (sipo->mode) {
296                 case SIPO_MODE_ANIMATION:  /* Animation F-Curve Editor */
297                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
298                         sipo->ads->source = (ID *)ac->scene;
299                         sipo->ads->filterflag &= ~ADS_FILTER_ONLYDRIVERS;
300
301                         ac->datatype = ANIMCONT_FCURVES;
302                         ac->data = sipo->ads;
303
304                         ac->mode = sipo->mode;
305                         return true;
306
307                 case SIPO_MODE_DRIVERS:  /* Driver F-Curve Editor */
308                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
309                         sipo->ads->source = (ID *)ac->scene;
310                         sipo->ads->filterflag |= ADS_FILTER_ONLYDRIVERS;
311
312                         ac->datatype = ANIMCONT_DRIVERS;
313                         ac->data = sipo->ads;
314
315                         ac->mode = sipo->mode;
316                         return true;
317
318                 default: /* unhandled yet */
319                         ac->datatype = ANIMCONT_NONE;
320                         ac->data = NULL;
321
322                         ac->mode = -1;
323                         return false;
324         }
325 }
326
327 /* ----------- Private Stuff - NLA Editor ------------- */
328
329 /* Get data being edited in Graph Editor (depending on current 'mode') */
330 static bool nlaedit_get_context(bAnimContext *ac, SpaceNla *snla)
331 {
332         /* init dopesheet data if non-existent (i.e. for old files) */
333         if (snla->ads == NULL)
334                 snla->ads = MEM_callocN(sizeof(bDopeSheet), "NlaEdit DopeSheet");
335         ac->ads = snla->ads;
336
337         /* sync settings with current view status, then return appropriate data */
338         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
339         snla->ads->source = (ID *)ac->scene;
340         snla->ads->filterflag |= ADS_FILTER_ONLYNLA;
341
342         ac->datatype = ANIMCONT_NLA;
343         ac->data = snla->ads;
344
345         return true;
346 }
347
348 /* ----------- Public API --------------- */
349
350 /* Obtain current anim-data context, given that context info from Blender context has already been set
351  * - AnimContext to write to is provided as pointer to var on stack so that we don't have
352  *   allocation/freeing costs (which are not that avoidable with channels).
353  */
354 bool ANIM_animdata_context_getdata(bAnimContext *ac)
355 {
356         SpaceLink *sl = ac->sl;
357         bool ok = false;
358
359         /* context depends on editor we are currently in */
360         if (sl) {
361                 switch (ac->spacetype) {
362                         case SPACE_ACTION:
363                         {
364                                 SpaceAction *saction = (SpaceAction *)sl;
365                                 ok = actedit_get_context(ac, saction);
366                                 break;
367                         }
368                         case SPACE_IPO:
369                         {
370                                 SpaceIpo *sipo = (SpaceIpo *)sl;
371                                 ok = graphedit_get_context(ac, sipo);
372                                 break;
373                         }
374                         case SPACE_NLA:
375                         {
376                                 SpaceNla *snla = (SpaceNla *)sl;
377                                 ok = nlaedit_get_context(ac, snla);
378                                 break;
379                         }
380                 }
381         }
382
383         /* check if there's any valid data */
384         return (ok && ac->data);
385 }
386
387 /* Obtain current anim-data context from Blender Context info
388  * - AnimContext to write to is provided as pointer to var on stack so that we don't have
389  *   allocation/freeing costs (which are not that avoidable with channels).
390  * - Clears data and sets the information from Blender Context which is useful
391  */
392 bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
393 {
394         Main *bmain = CTX_data_main(C);
395         ScrArea *sa = CTX_wm_area(C);
396         ARegion *ar = CTX_wm_region(C);
397         SpaceLink *sl = CTX_wm_space_data(C);
398         Scene *scene = CTX_data_scene(C);
399
400         /* clear old context info */
401         if (ac == NULL) return false;
402         memset(ac, 0, sizeof(bAnimContext));
403
404         /* get useful default context settings from context */
405         ac->bmain = bmain;
406         ac->scene = scene;
407         if (scene) {
408                 ac->markers = ED_context_get_markers(C);
409         }
410         ac->depsgraph = CTX_data_depsgraph(C);
411         ac->view_layer = CTX_data_view_layer(C);
412         ac->obact = (ac->view_layer->basact) ? ac->view_layer->basact->object : NULL;
413         ac->sa = sa;
414         ac->ar = ar;
415         ac->sl = sl;
416         ac->spacetype = (sa) ? sa->spacetype : 0;
417         ac->regiontype = (ar) ? ar->regiontype : 0;
418
419         /* initialise default y-scale factor */
420         animedit_get_yscale_factor(ac);
421
422         /* get data context info */
423         // XXX: if the below fails, try to grab this info from context instead... (to allow for scripting)
424         return ANIM_animdata_context_getdata(ac);
425 }
426
427 /* ************************************************************ */
428 /* Blender Data <-- Filter --> Channels to be operated on */
429
430 /* macros to use before/after getting the sub-channels of some channel,
431  * to abstract away some of the tricky logic involved
432  *
433  * cases:
434  * 1) Graph Edit main area (just data) OR channels visible in Channel List
435  * 2) If not showing channels, we're only interested in the data (Action Editor's editing)
436  * 3) We don't care what data, we just care there is some (so that a collapsed
437  *    channel can be kept around). No need to clear channels-flag in order to
438  *    keep expander channels with no sub-data out, as those cases should get
439  *    dealt with by the recursive detection idiom in place.
440  *
441  * Implementation Note:
442  *  YES the _doSubChannels variable is NOT read anywhere. BUT, this is NOT an excuse
443  *  to go steamrolling the logic into a single-line expression as from experience,
444  *  those are notoriously difficult to read + debug when extending later on. The code
445  *  below is purposefully laid out so that each case noted above corresponds clearly to
446  *  one case below.
447  */
448 #define BEGIN_ANIMFILTER_SUBCHANNELS(expanded_check) \
449         { \
450                 int _filter = filter_mode; \
451                 short _doSubChannels = 0; \
452                 if (!(filter_mode & ANIMFILTER_LIST_VISIBLE) || (expanded_check)) \
453                         _doSubChannels = 1; \
454                 else if (!(filter_mode & ANIMFILTER_LIST_CHANNELS)) \
455                         _doSubChannels = 2; \
456                 else { \
457                         filter_mode |= ANIMFILTER_TMP_PEEK; \
458                 } \
459                  \
460                 { \
461                         (void) _doSubChannels; \
462                 }
463 /* ... standard sub-channel filtering can go on here now ... */
464 #define END_ANIMFILTER_SUBCHANNELS \
465                 filter_mode = _filter; \
466         } (void)0
467
468 /* ............................... */
469
470 /* quick macro to test if AnimData is usable */
471 #define ANIMDATA_HAS_KEYS(id) ((id)->adt && (id)->adt->action)
472
473 /* quick macro to test if AnimData is usable for drivers */
474 #define ANIMDATA_HAS_DRIVERS(id) ((id)->adt && (id)->adt->drivers.first)
475
476 /* quick macro to test if AnimData is usable for NLA */
477 #define ANIMDATA_HAS_NLA(id) ((id)->adt && (id)->adt->nla_tracks.first)
478
479 /* Quick macro to test for all three above usability tests, performing the appropriate provided
480  * action for each when the AnimData context is appropriate.
481  *
482  * Priority order for this goes (most important, to least): AnimData blocks, NLA, Drivers, Keyframes.
483  *
484  * For this to work correctly, a standard set of data needs to be available within the scope that this
485  * gets called in:
486  * - ListBase anim_data;
487  * - bDopeSheet *ads;
488  * - bAnimListElem *ale;
489  * - size_t items;
490  *
491  * - id: ID block which should have an AnimData pointer following it immediately, to use
492  * - adtOk: line or block of code to execute for AnimData-blocks case (usually ANIMDATA_ADD_ANIMDATA)
493  * - nlaOk: line or block of code to execute for NLA tracks+strips case
494  * - driversOk: line or block of code to execute for Drivers case
495  * - nlaKeysOk: line or block of code for NLA Strip Keyframes case
496  * - keysOk: line or block of code for Keyframes case
497  *
498  * The checks for the various cases are as follows:
499  * 0) top level: checks for animdata and also that all the F-Curves for the block will be visible
500  * 1) animdata check: for filtering animdata blocks only
501  * 2A) nla tracks: include animdata block's data as there are NLA tracks+strips there
502  * 2B) actions to convert to nla: include animdata block's data as there is an action that can be
503  *     converted to a new NLA strip, and the filtering options allow this
504  * 2C) allow non-animated datablocks to be included so that datablocks can be added
505  * 3) drivers: include drivers from animdata block (for Drivers mode in Graph Editor)
506  * 4A) nla strip keyframes: these are the per-strip controls for time and influence
507  * 4B) normal keyframes: only when there is an active action
508  */
509 #define ANIMDATA_FILTER_CASES(id, adtOk, nlaOk, driversOk, nlaKeysOk, keysOk) \
510         { \
511                 if ((id)->adt) { \
512                         if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || !((id)->adt->flag & ADT_CURVES_NOT_VISIBLE)) { \
513                                 if (filter_mode & ANIMFILTER_ANIMDATA) { \
514                                         adtOk \
515                                 } \
516                                 else if (ads->filterflag & ADS_FILTER_ONLYNLA) { \
517                                         if (ANIMDATA_HAS_NLA(id)) { \
518                                                 nlaOk \
519                                         } \
520                                         else if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || ANIMDATA_HAS_KEYS(id)) { \
521                                                 nlaOk \
522                                         } \
523                                 } \
524                                 else if (ads->filterflag & ADS_FILTER_ONLYDRIVERS) { \
525                                         if (ANIMDATA_HAS_DRIVERS(id)) { \
526                                                 driversOk \
527                                         } \
528                                 } \
529                                 else { \
530                                         if (ANIMDATA_HAS_NLA(id)) { \
531                                                 nlaKeysOk \
532                                         } \
533                                         if (ANIMDATA_HAS_KEYS(id)) { \
534                                                 keysOk \
535                                         } \
536                                 } \
537                         } \
538                 } \
539         } (void)0
540
541 /* ............................... */
542
543 /* Add a new animation channel, taking into account the "peek" flag, which is used to just check
544  * whether any channels will be added (but without needing them to actually get created).
545  *
546  * ! This causes the calling function to return early if we're only "peeking" for channels
547  */
548 // XXX: ale_statement stuff is really a hack for one special case. It shouldn't really be needed...
549 #define ANIMCHANNEL_NEW_CHANNEL_FULL(channel_data, channel_type, owner_id, fcurve_owner_id, ale_statement) \
550         if (filter_mode & ANIMFILTER_TMP_PEEK) \
551                 return 1; \
552         else { \
553                 bAnimListElem *ale = make_new_animlistelem(channel_data, channel_type, (ID *)owner_id, fcurve_owner_id); \
554                 if (ale) { \
555                         BLI_addtail(anim_data, ale); \
556                         items ++; \
557                         ale_statement \
558                 } \
559         } (void)0
560
561 #define ANIMCHANNEL_NEW_CHANNEL(channel_data, channel_type, owner_id, fcurve_owner_id) \
562         ANIMCHANNEL_NEW_CHANNEL_FULL(channel_data, channel_type, owner_id, fcurve_owner_id, {})
563
564 /* ............................... */
565
566 /* quick macro to test if an anim-channel representing an AnimData block is suitably active */
567 #define ANIMCHANNEL_ACTIVEOK(ale) \
568         (!(filter_mode & ANIMFILTER_ACTIVE) || !(ale->adt) || (ale->adt->flag & ADT_UI_ACTIVE) )
569
570 /* quick macro to test if an anim-channel (F-Curve, Group, etc.) is selected in an acceptable way */
571 #define ANIMCHANNEL_SELOK(test_func) \
572         (!(filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) || \
573          ((filter_mode & ANIMFILTER_SEL) && test_func) || \
574          ((filter_mode & ANIMFILTER_UNSEL) && test_func == 0) )
575
576 /* quick macro to test if an anim-channel (F-Curve) is selected ok for editing purposes
577  * - _SELEDIT means that only selected curves will have visible+editable keyframes
578  *
579  * checks here work as follows:
580  * 1) seledit off - don't need to consider the implications of this option
581  * 2) foredit off - we're not considering editing, so channel is ok still
582  * 3) test_func (i.e. selection test) - only if selected, this test will pass
583  */
584 #define ANIMCHANNEL_SELEDITOK(test_func) \
585         (!(filter_mode & ANIMFILTER_SELEDIT) || \
586          !(filter_mode & ANIMFILTER_FOREDIT) || \
587          (test_func) )
588
589 /* ----------- 'Private' Stuff --------------- */
590
591 /* this function allocates memory for a new bAnimListElem struct for the
592  * provided animation channel-data.
593  */
594 static bAnimListElem *make_new_animlistelem(void *data, short datatype, ID *owner_id, ID *fcurve_owner_id)
595 {
596         bAnimListElem *ale = NULL;
597
598         /* only allocate memory if there is data to convert */
599         if (data) {
600                 /* allocate and set generic data */
601                 ale = MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
602
603                 ale->data = data;
604                 ale->type = datatype;
605
606                 ale->id = owner_id;
607                 ale->adt = BKE_animdata_from_id(owner_id);
608                 ale->fcurve_owner_id = fcurve_owner_id;
609
610                 /* do specifics */
611                 switch (datatype) {
612                         case ANIMTYPE_SUMMARY:
613                         {
614                                 /* nothing to include for now... this is just a dummy wrappy around all the other channels
615                                  * in the DopeSheet, and gets included at the start of the list
616                                  */
617                                 ale->key_data = NULL;
618                                 ale->datatype = ALE_ALL;
619                                 break;
620                         }
621                         case ANIMTYPE_SCENE:
622                         {
623                                 Scene *sce = (Scene *)data;
624
625                                 ale->flag = sce->flag;
626
627                                 ale->key_data = sce;
628                                 ale->datatype = ALE_SCE;
629
630                                 ale->adt = BKE_animdata_from_id(data);
631                                 break;
632                         }
633                         case ANIMTYPE_OBJECT:
634                         {
635                                 Base *base = (Base *)data;
636                                 Object *ob = base->object;
637
638                                 ale->flag = ob->flag;
639
640                                 ale->key_data = ob;
641                                 ale->datatype = ALE_OB;
642
643                                 ale->adt = BKE_animdata_from_id(&ob->id);
644                                 break;
645                         }
646                         case ANIMTYPE_FILLACTD:
647                         {
648                                 bAction *act = (bAction *)data;
649
650                                 ale->flag = act->flag;
651
652                                 ale->key_data = act;
653                                 ale->datatype = ALE_ACT;
654                                 break;
655                         }
656                         case ANIMTYPE_FILLDRIVERS:
657                         {
658                                 AnimData *adt = (AnimData *)data;
659
660                                 ale->flag = adt->flag;
661
662                                 // XXX... drivers don't show summary for now
663                                 ale->key_data = NULL;
664                                 ale->datatype = ALE_NONE;
665                                 break;
666                         }
667                         case ANIMTYPE_DSMAT:
668                         {
669                                 Material *ma = (Material *)data;
670                                 AnimData *adt = ma->adt;
671
672                                 ale->flag = FILTER_MAT_OBJD(ma);
673
674                                 ale->key_data = (adt) ? adt->action : NULL;
675                                 ale->datatype = ALE_ACT;
676
677                                 ale->adt = BKE_animdata_from_id(data);
678                                 break;
679                         }
680                         case ANIMTYPE_DSLAM:
681                         {
682                                 Lamp *la = (Lamp *)data;
683                                 AnimData *adt = la->adt;
684
685                                 ale->flag = FILTER_LAM_OBJD(la);
686
687                                 ale->key_data = (adt) ? adt->action : NULL;
688                                 ale->datatype = ALE_ACT;
689
690                                 ale->adt = BKE_animdata_from_id(data);
691                                 break;
692                         }
693                         case ANIMTYPE_DSCAM:
694                         {
695                                 Camera *ca = (Camera *)data;
696                                 AnimData *adt = ca->adt;
697
698                                 ale->flag = FILTER_CAM_OBJD(ca);
699
700                                 ale->key_data = (adt) ? adt->action : NULL;
701                                 ale->datatype = ALE_ACT;
702
703                                 ale->adt = BKE_animdata_from_id(data);
704                                 break;
705                         }
706                         case ANIMTYPE_DSCACHEFILE:
707                         {
708                                 CacheFile *cache_file = (CacheFile *)data;
709                                 AnimData *adt = cache_file->adt;
710
711                                 ale->flag = FILTER_CACHEFILE_OBJD(cache_file);
712
713                                 ale->key_data = (adt) ? adt->action : NULL;
714                                 ale->datatype = ALE_ACT;
715
716                                 ale->adt = BKE_animdata_from_id(data);
717                                 break;
718                         }
719                         case ANIMTYPE_DSCUR:
720                         {
721                                 Curve *cu = (Curve *)data;
722                                 AnimData *adt = cu->adt;
723
724                                 ale->flag = FILTER_CUR_OBJD(cu);
725
726                                 ale->key_data = (adt) ? adt->action : NULL;
727                                 ale->datatype = ALE_ACT;
728
729                                 ale->adt = BKE_animdata_from_id(data);
730                                 break;
731                         }
732                         case ANIMTYPE_DSARM:
733                         {
734                                 bArmature *arm = (bArmature *)data;
735                                 AnimData *adt = arm->adt;
736
737                                 ale->flag = FILTER_ARM_OBJD(arm);
738
739                                 ale->key_data = (adt) ? adt->action : NULL;
740                                 ale->datatype = ALE_ACT;
741
742                                 ale->adt = BKE_animdata_from_id(data);
743                                 break;
744                         }
745                         case ANIMTYPE_DSMESH:
746                         {
747                                 Mesh *me = (Mesh *)data;
748                                 AnimData *adt = me->adt;
749
750                                 ale->flag = FILTER_MESH_OBJD(me);
751
752                                 ale->key_data = (adt) ? adt->action : NULL;
753                                 ale->datatype = ALE_ACT;
754
755                                 ale->adt = BKE_animdata_from_id(data);
756                                 break;
757                         }
758                         case ANIMTYPE_DSLAT:
759                         {
760                                 Lattice *lt = (Lattice *)data;
761                                 AnimData *adt = lt->adt;
762
763                                 ale->flag = FILTER_LATTICE_OBJD(lt);
764
765                                 ale->key_data = (adt) ? adt->action : NULL;
766                                 ale->datatype = ALE_ACT;
767
768                                 ale->adt = BKE_animdata_from_id(data);
769                                 break;
770                         }
771                         case ANIMTYPE_DSSPK:
772                         {
773                                 Speaker *spk = (Speaker *)data;
774                                 AnimData *adt = spk->adt;
775
776                                 ale->flag = FILTER_SPK_OBJD(spk);
777
778                                 ale->key_data = (adt) ? adt->action : NULL;
779                                 ale->datatype = ALE_ACT;
780
781                                 ale->adt = BKE_animdata_from_id(data);
782                                 break;
783                         }
784                         case ANIMTYPE_DSSKEY:
785                         {
786                                 Key *key = (Key *)data;
787                                 AnimData *adt = key->adt;
788
789                                 ale->flag = FILTER_SKE_OBJD(key);
790
791                                 ale->key_data = (adt) ? adt->action : NULL;
792                                 ale->datatype = ALE_ACT;
793
794                                 ale->adt = BKE_animdata_from_id(data);
795                                 break;
796                         }
797                         case ANIMTYPE_DSWOR:
798                         {
799                                 World *wo = (World *)data;
800                                 AnimData *adt = wo->adt;
801
802                                 ale->flag = FILTER_WOR_SCED(wo);
803
804                                 ale->key_data = (adt) ? adt->action : NULL;
805                                 ale->datatype = ALE_ACT;
806
807                                 ale->adt = BKE_animdata_from_id(data);
808                                 break;
809                         }
810                         case ANIMTYPE_DSNTREE:
811                         {
812                                 bNodeTree *ntree = (bNodeTree *)data;
813                                 AnimData *adt = ntree->adt;
814
815                                 ale->flag = FILTER_NTREE_DATA(ntree);
816
817                                 ale->key_data = (adt) ? adt->action : NULL;
818                                 ale->datatype = ALE_ACT;
819
820                                 ale->adt = BKE_animdata_from_id(data);
821                                 break;
822                         }
823                         case ANIMTYPE_DSLINESTYLE:
824                         {
825                                 FreestyleLineStyle *linestyle = (FreestyleLineStyle *)data;
826                                 AnimData *adt = linestyle->adt;
827
828                                 ale->flag = FILTER_LS_SCED(linestyle);
829
830                                 ale->key_data = (adt) ? adt->action : NULL;
831                                 ale->datatype = ALE_ACT;
832
833                                 ale->adt = BKE_animdata_from_id(data);
834                                 break;
835                         }
836                         case ANIMTYPE_DSPART:
837                         {
838                                 ParticleSettings *part = (ParticleSettings *)ale->data;
839                                 AnimData *adt = part->adt;
840
841                                 ale->flag = FILTER_PART_OBJD(part);
842
843                                 ale->key_data = (adt) ? adt->action : NULL;
844                                 ale->datatype = ALE_ACT;
845
846                                 ale->adt = BKE_animdata_from_id(data);
847                                 break;
848                         }
849                         case ANIMTYPE_DSTEX:
850                         {
851                                 Tex *tex = (Tex *)data;
852                                 AnimData *adt = tex->adt;
853
854                                 ale->flag = FILTER_TEX_DATA(tex);
855
856                                 ale->key_data = (adt) ? adt->action : NULL;
857                                 ale->datatype = ALE_ACT;
858
859                                 ale->adt = BKE_animdata_from_id(data);
860                                 break;
861                         }
862                         case ANIMTYPE_DSGPENCIL:
863                         {
864                                 bGPdata *gpd = (bGPdata *)data;
865                                 AnimData *adt = gpd->adt;
866
867                                 /* NOTE: we just reuse the same expand filter for this case */
868                                 ale->flag = EXPANDED_GPD(gpd);
869
870                                 // XXX: currently, this is only used for access to its animation data
871                                 ale->key_data = (adt) ? adt->action : NULL;
872                                 ale->datatype = ALE_ACT;
873
874                                 ale->adt = BKE_animdata_from_id(data);
875                                 break;
876                         }
877                         case ANIMTYPE_DSMCLIP:
878                         {
879                                 MovieClip *clip = (MovieClip *)data;
880                                 AnimData *adt = clip->adt;
881
882                                 ale->flag = EXPANDED_MCLIP(clip);
883
884                                 ale->key_data = (adt) ? adt->action : NULL;
885                                 ale->datatype = ALE_ACT;
886
887                                 ale->adt = BKE_animdata_from_id(data);
888                                 break;
889                         }
890                         case ANIMTYPE_NLACONTROLS:
891                         {
892                                 AnimData *adt = (AnimData *)data;
893
894                                 ale->flag = adt->flag;
895
896                                 ale->key_data = NULL;
897                                 ale->datatype = ALE_NONE;
898                                 break;
899                         }
900                         case ANIMTYPE_GROUP:
901                         {
902                                 bActionGroup *agrp = (bActionGroup *)data;
903
904                                 ale->flag = agrp->flag;
905
906                                 ale->key_data = NULL;
907                                 ale->datatype = ALE_GROUP;
908                                 break;
909                         }
910                         case ANIMTYPE_FCURVE:
911                         case ANIMTYPE_NLACURVE: /* practically the same as ANIMTYPE_FCURVE.
912                                                  * Differences are applied post-creation */
913                         {
914                                 FCurve *fcu = (FCurve *)data;
915
916                                 ale->flag = fcu->flag;
917
918                                 ale->key_data = fcu;
919                                 ale->datatype = ALE_FCURVE;
920                                 break;
921                         }
922                         case ANIMTYPE_SHAPEKEY:
923                         {
924                                 KeyBlock *kb = (KeyBlock *)data;
925                                 Key *key = (Key *)ale->id;
926
927                                 ale->flag = kb->flag;
928
929                                 /* whether we have keyframes depends on whether there is a Key block to find it from */
930                                 if (key) {
931                                         /* index of shapekey is defined by place in key's list */
932                                         ale->index = BLI_findindex(&key->block, kb);
933
934                                         /* the corresponding keyframes are from the animdata */
935                                         if (ale->adt && ale->adt->action) {
936                                                 bAction *act = ale->adt->action;
937                                                 char *rna_path = BKE_keyblock_curval_rnapath_get(key, kb);
938
939                                                 /* try to find the F-Curve which corresponds to this exactly,
940                                                  * then free the MEM_alloc'd string
941                                                  */
942                                                 if (rna_path) {
943                                                         ale->key_data = (void *)list_find_fcurve(&act->curves, rna_path, 0);
944                                                         MEM_freeN(rna_path);
945                                                 }
946                                         }
947                                         ale->datatype = (ale->key_data) ? ALE_FCURVE : ALE_NONE;
948                                 }
949                                 break;
950                         }
951                         case ANIMTYPE_GPLAYER:
952                         {
953                                 bGPDlayer *gpl = (bGPDlayer *)data;
954
955                                 ale->flag = gpl->flag;
956
957                                 ale->key_data = NULL;
958                                 ale->datatype = ALE_GPFRAME;
959                                 break;
960                         }
961                         case ANIMTYPE_MASKLAYER:
962                         {
963                                 MaskLayer *masklay = (MaskLayer *)data;
964
965                                 ale->flag = masklay->flag;
966
967                                 ale->key_data = NULL;
968                                 ale->datatype = ALE_MASKLAY;
969                                 break;
970                         }
971                         case ANIMTYPE_NLATRACK:
972                         {
973                                 NlaTrack *nlt = (NlaTrack *)data;
974
975                                 ale->flag = nlt->flag;
976
977                                 ale->key_data = &nlt->strips;
978                                 ale->datatype = ALE_NLASTRIP;
979                                 break;
980                         }
981                         case ANIMTYPE_NLAACTION:
982                         {
983                                 /* nothing to include for now... nothing editable from NLA-perspective here */
984                                 ale->key_data = NULL;
985                                 ale->datatype = ALE_NONE;
986                                 break;
987                         }
988                 }
989         }
990
991         /* return created datatype */
992         return ale;
993 }
994
995 /* ----------------------------------------- */
996
997 /* 'Only Selected' selected data and/or 'Include Hidden' filtering
998  * NOTE: when this function returns true, the F-Curve is to be skipped
999  */
1000 static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id, int filter_mode)
1001 {
1002         if (fcu->grp != NULL && fcu->grp->flag & ADT_CURVES_ALWAYS_VISIBLE) {
1003                 return false;
1004         }
1005         /* hidden items should be skipped if we only care about visible data,
1006          * but we aren't interested in hidden stuff */
1007         const bool skip_hidden = (filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN);
1008
1009         if (GS(owner_id->name) == ID_OB) {
1010                 Object *ob = (Object *)owner_id;
1011
1012                 /* only consider if F-Curve involves pose.bones */
1013                 if ((fcu->rna_path) && strstr(fcu->rna_path, "pose.bones")) {
1014                         bPoseChannel *pchan;
1015                         char *bone_name;
1016
1017                         /* get bone-name, and check if this bone is selected */
1018                         bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
1019                         pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
1020                         if (bone_name) MEM_freeN(bone_name);
1021
1022                         /* check whether to continue or skip */
1023                         if ((pchan) && (pchan->bone)) {
1024                                 /* if only visible channels, skip if bone not visible unless user wants channels from hidden data too */
1025                                 if (skip_hidden) {
1026                                         bArmature *arm = (bArmature *)ob->data;
1027
1028                                         /* skipping - not visible on currently visible layers */
1029                                         if ((arm->layer & pchan->bone->layer) == 0)
1030                                                 return true;
1031                                         /* skipping - is currently hidden */
1032                                         if (pchan->bone->flag & BONE_HIDDEN_P)
1033                                                 return true;
1034                                 }
1035
1036                                 /* can only add this F-Curve if it is selected */
1037                                 if (ads->filterflag & ADS_FILTER_ONLYSEL) {
1038                                         if ((pchan->bone->flag & BONE_SELECTED) == 0)
1039                                                 return true;
1040                                 }
1041                         }
1042                 }
1043         }
1044         else if (GS(owner_id->name) == ID_SCE) {
1045                 Scene *scene = (Scene *)owner_id;
1046
1047                 /* only consider if F-Curve involves sequence_editor.sequences */
1048                 if ((fcu->rna_path) && strstr(fcu->rna_path, "sequences_all")) {
1049                         Editing *ed = BKE_sequencer_editing_get(scene, false);
1050                         Sequence *seq = NULL;
1051                         char *seq_name;
1052
1053                         if (ed) {
1054                                 /* get strip name, and check if this strip is selected */
1055                                 seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all[");
1056                                 seq = BKE_sequence_get_by_name(ed->seqbasep, seq_name, false);
1057                                 if (seq_name) MEM_freeN(seq_name);
1058                         }
1059
1060                         /* can only add this F-Curve if it is selected */
1061                         if (ads->filterflag & ADS_FILTER_ONLYSEL) {
1062                                 if ((seq == NULL) || (seq->flag & SELECT) == 0)
1063                                         return true;
1064                         }
1065                 }
1066         }
1067         else if (GS(owner_id->name) == ID_NT) {
1068                 bNodeTree *ntree = (bNodeTree *)owner_id;
1069
1070                 /* check for selected nodes */
1071                 if ((fcu->rna_path) && strstr(fcu->rna_path, "nodes")) {
1072                         bNode *node;
1073                         char *node_name;
1074
1075                         /* get strip name, and check if this strip is selected */
1076                         node_name = BLI_str_quoted_substrN(fcu->rna_path, "nodes[");
1077                         node = nodeFindNodebyName(ntree, node_name);
1078                         if (node_name) MEM_freeN(node_name);
1079
1080                         /* can only add this F-Curve if it is selected */
1081                         if (ads->filterflag & ADS_FILTER_ONLYSEL) {
1082                                 if ((node) && (node->flag & NODE_SELECT) == 0)
1083                                         return true;
1084                         }
1085                 }
1086         }
1087
1088         return false;
1089 }
1090
1091 /* Helper for name-based filtering - Perform "partial/fuzzy matches" (as in 80a7efd) */
1092 static bool name_matches_dopesheet_filter(bDopeSheet *ads, char *name)
1093 {
1094         if (ads->flag & ADS_FLAG_FUZZY_NAMES) {
1095                 /* full fuzzy, multi-word, case insensitive matches */
1096                 const size_t str_len = strlen(ads->searchstr);
1097                 const int words_max = (str_len / 2) + 1;
1098
1099                 int (*words)[2] = BLI_array_alloca(words, words_max);
1100                 const int words_len = BLI_string_find_split_words(ads->searchstr, str_len, ' ', words, words_max);
1101                 bool found = false;
1102
1103                 /* match name against all search words */
1104                 for (int index = 0; index < words_len; index++) {
1105                         if (BLI_strncasestr(name, ads->searchstr + words[index][0], words[index][1])) {
1106                                 found = true;
1107                                 break;
1108                         }
1109                 }
1110
1111                 /* if we have a match somewhere, this returns true */
1112                 return found;
1113         }
1114         else {
1115                 /* fallback/default - just case insensitive, but starts from start of word */
1116                 return BLI_strcasestr(name, ads->searchstr) != NULL;
1117         }
1118 }
1119
1120 /* (Display-)Name-based F-Curve filtering
1121  * NOTE: when this function returns true, the F-Curve is to be skipped
1122  */
1123 static bool skip_fcurve_with_name(bDopeSheet *ads, FCurve *fcu, eAnim_ChannelType channel_type, void *owner, ID *owner_id)
1124 {
1125         bAnimListElem ale_dummy = {NULL};
1126         const bAnimChannelType *acf;
1127
1128         /* create a dummy wrapper for the F-Curve, so we can get typeinfo for it */
1129         ale_dummy.type = channel_type;
1130         ale_dummy.owner = owner;
1131         ale_dummy.id = owner_id;
1132         ale_dummy.data = fcu;
1133
1134         /* get type info for channel */
1135         acf = ANIM_channel_get_typeinfo(&ale_dummy);
1136         if (acf && acf->name) {
1137                 char name[256]; /* hopefully this will be enough! */
1138
1139                 /* get name */
1140                 acf->name(&ale_dummy, name);
1141
1142                 /* check for partial match with the match string, assuming case insensitive filtering
1143                  * if match, this channel shouldn't be ignored!
1144                  */
1145                 return !name_matches_dopesheet_filter(ads, name);
1146         }
1147
1148         /* just let this go... */
1149         return true;
1150 }
1151
1152 /**
1153  * Check if F-Curve has errors and/or is disabled
1154  *
1155  * \return true if F-Curve has errors/is disabled
1156  */
1157 static bool fcurve_has_errors(FCurve *fcu)
1158 {
1159         /* F-Curve disabled - path eval error */
1160         if (fcu->flag & FCURVE_DISABLED) {
1161                 return true;
1162         }
1163
1164         /* driver? */
1165         if (fcu->driver) {
1166                 ChannelDriver *driver = fcu->driver;
1167                 DriverVar *dvar;
1168
1169                 /* error flag on driver usually means that there is an error
1170                  * BUT this may not hold with PyDrivers as this flag gets cleared
1171                  *     if no critical errors prevent the driver from working...
1172                  */
1173                 if (driver->flag & DRIVER_FLAG_INVALID)
1174                         return true;
1175
1176                 /* check variables for other things that need linting... */
1177                 // TODO: maybe it would be more efficient just to have a quick flag for this?
1178                 for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
1179                         DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
1180                         {
1181                                 if (dtar->flag & DTAR_FLAG_INVALID)
1182                                         return true;
1183                         }
1184                         DRIVER_TARGETS_LOOPER_END;
1185                 }
1186         }
1187
1188         /* no errors found */
1189         return false;
1190 }
1191
1192 /* find the next F-Curve that is usable for inclusion */
1193 static FCurve *animfilter_fcurve_next(bDopeSheet *ads, FCurve *first, eAnim_ChannelType channel_type, int filter_mode, void *owner, ID *owner_id)
1194 {
1195         bActionGroup *grp = (channel_type == ANIMTYPE_FCURVE) ? owner : NULL;
1196         FCurve *fcu = NULL;
1197
1198         /* loop over F-Curves - assume that the caller of this has already checked that these should be included
1199          * NOTE: we need to check if the F-Curves belong to the same group, as this gets called for groups too...
1200          */
1201         for (fcu = first; ((fcu) && (fcu->grp == grp)); fcu = fcu->next) {
1202                 /* special exception for Pose-Channel/Sequence-Strip/Node Based F-Curves:
1203                  * - the 'Only Selected' and 'Include Hidden' data filters should be applied to sub-ID data which
1204                  *   can be independently selected/hidden, such as Pose-Channels, Sequence Strips, and Nodes.
1205                  *   Since these checks were traditionally done as first check for objects, we do the same here
1206                  * - we currently use an 'approximate' method for getting these F-Curves that doesn't require
1207                  *   carefully checking the entire path
1208                  * - this will also affect things like Drivers, and also works for Bone Constraints
1209                  */
1210                 if (ads && owner_id) {
1211                         if ((filter_mode & ANIMFILTER_TMP_IGNORE_ONLYSEL) == 0) {
1212                                 if ((ads->filterflag & ADS_FILTER_ONLYSEL) || (ads->filterflag & ADS_FILTER_INCL_HIDDEN) == 0) {
1213                                         if (skip_fcurve_selected_data(ads, fcu, owner_id, filter_mode))
1214                                                 continue;
1215                                 }
1216                         }
1217                 }
1218
1219                 /* only include if visible (Graph Editor check, not channels check) */
1220                 if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || (fcu->flag & FCURVE_VISIBLE)) {
1221                         /* only work with this channel and its subchannels if it is editable */
1222                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_FCU(fcu)) {
1223                                 /* only include this curve if selected in a way consistent with the filtering requirements */
1224                                 if (ANIMCHANNEL_SELOK(SEL_FCU(fcu)) && ANIMCHANNEL_SELEDITOK(SEL_FCU(fcu))) {
1225                                         /* only include if this curve is active */
1226                                         if (!(filter_mode & ANIMFILTER_ACTIVE) || (fcu->flag & FCURVE_ACTIVE)) {
1227                                                 /* name based filtering... */
1228                                                 if ( ((ads) && (ads->searchstr[0] != '\0')) && (owner_id) ) {
1229                                                         if (skip_fcurve_with_name(ads, fcu, channel_type, owner, owner_id))
1230                                                                 continue;
1231                                                 }
1232
1233                                                 /* error-based filtering... */
1234                                                 if ((ads) && (ads->filterflag & ADS_FILTER_ONLY_ERRORS)) {
1235                                                         /* skip if no errors... */
1236                                                         if (fcurve_has_errors(fcu) == false)
1237                                                                 continue;
1238                                                 }
1239
1240                                                 /* this F-Curve can be used, so return it */
1241                                                 return fcu;
1242                                         }
1243                                 }
1244                         }
1245                 }
1246         }
1247
1248         /* no (more) F-Curves from the list are suitable... */
1249         return NULL;
1250 }
1251
1252 static size_t animfilter_fcurves(ListBase *anim_data, bDopeSheet *ads,
1253                                  FCurve *first, eAnim_ChannelType fcurve_type,
1254                                  int filter_mode,
1255                                  void *owner, ID *owner_id, ID *fcurve_owner_id)
1256 {
1257         FCurve *fcu;
1258         size_t items = 0;
1259
1260         /* loop over every F-Curve able to be included
1261          * - this for-loop works like this:
1262          *   1) the starting F-Curve is assigned to the fcu pointer so that we have a starting point to search from
1263          *   2) the first valid F-Curve to start from (which may include the one given as 'first') in the remaining
1264          *      list of F-Curves is found, and verified to be non-null
1265          *   3) the F-Curve referenced by fcu pointer is added to the list
1266          *   4) the fcu pointer is set to the F-Curve after the one we just added, so that we can keep going through
1267          *      the rest of the F-Curve list without an eternal loop. Back to step 2 :)
1268          */
1269         for (fcu = first; ( (fcu = animfilter_fcurve_next(ads, fcu, fcurve_type, filter_mode, owner, owner_id)) ); fcu = fcu->next) {
1270                 if (UNLIKELY(fcurve_type == ANIMTYPE_NLACURVE)) {
1271                         /* NLA Control Curve - Basically the same as normal F-Curves,
1272                          * except we need to set some stuff differently */
1273                         ANIMCHANNEL_NEW_CHANNEL_FULL(fcu, ANIMTYPE_NLACURVE, owner_id, fcurve_owner_id, {
1274                                 ale->owner = owner; /* strip */
1275                                 ale->adt = NULL;    /* to prevent time mapping from causing problems */
1276                         });
1277                 }
1278                 else {
1279                         /* Normal FCurve */
1280                         ANIMCHANNEL_NEW_CHANNEL(fcu, ANIMTYPE_FCURVE, owner_id, fcurve_owner_id);
1281                 }
1282         }
1283
1284         /* return the number of items added to the list */
1285         return items;
1286 }
1287
1288 static size_t animfilter_act_group(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bAction *act, bActionGroup *agrp, int filter_mode, ID *owner_id)
1289 {
1290         ListBase tmp_data = {NULL, NULL};
1291         size_t tmp_items = 0;
1292         size_t items = 0;
1293         //int ofilter = filter_mode;
1294
1295         /* if we care about the selection status of the channels,
1296          * but the group isn't expanded (1)...
1297          * (1) this only matters if we actually care about the hierarchy though.
1298          *     - Hierarchy matters: this hack should be applied
1299          *     - Hierarchy ignored: cases like [#21276] won't work properly, unless we skip this hack
1300          */
1301         if (
1302                 /* care about hierarchy but group isn't expanded */
1303                 ((filter_mode & ANIMFILTER_LIST_VISIBLE) && EXPANDED_AGRP(ac, agrp) == 0) &&
1304                 /* care about selection status */
1305                 (filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) )
1306         {
1307                 /* if the group itself isn't selected appropriately, we shouldn't consider it's children either */
1308                 if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) == 0)
1309                         return 0;
1310
1311                 /* if we're still here, then the selection status of the curves within this group should not matter,
1312                  * since this creates too much overhead for animators (i.e. making a slow workflow)
1313                  *
1314                  * Tools affected by this at time of coding (2010 Feb 09):
1315                  * - inserting keyframes on selected channels only
1316                  * - pasting keyframes
1317                  * - creating ghost curves in Graph Editor
1318                  */
1319                 filter_mode &= ~(ANIMFILTER_SEL | ANIMFILTER_UNSEL | ANIMFILTER_LIST_VISIBLE);
1320         }
1321
1322         /* add grouped F-Curves */
1323         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_AGRP(ac, agrp))
1324         {
1325                 /* special filter so that we can get just the F-Curves within the active group */
1326                 if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
1327                         /* for the Graph Editor, curves may be set to not be visible in the view to lessen
1328                          * clutter, but to do this, we need to check that the group doesn't have it's
1329                          * not-visible flag set preventing all its sub-curves to be shown
1330                          */
1331                         if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || !(agrp->flag & AGRP_NOTVISIBLE)) {
1332                                 /* group must be editable for its children to be editable (if we care about this) */
1333                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {
1334                                         /* get first F-Curve which can be used here */
1335                                         FCurve *first_fcu = animfilter_fcurve_next(ads, agrp->channels.first, ANIMTYPE_FCURVE, filter_mode, agrp, owner_id);
1336
1337                                         /* filter list, starting from this F-Curve */
1338                                         tmp_items += animfilter_fcurves(&tmp_data, ads, first_fcu, ANIMTYPE_FCURVE, filter_mode, agrp, owner_id, &act->id);
1339                                 }
1340                         }
1341                 }
1342         }
1343         END_ANIMFILTER_SUBCHANNELS;
1344
1345         /* did we find anything? */
1346         if (tmp_items) {
1347                 /* add this group as a channel first */
1348                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1349                         /* restore original filter mode so that this next step works ok... */
1350                         //filter_mode = ofilter;
1351
1352                         /* filter selection of channel specially here again,
1353                          * since may be open and not subject to previous test */
1354                         if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) ) {
1355                                 ANIMCHANNEL_NEW_CHANNEL(agrp, ANIMTYPE_GROUP, owner_id, NULL);
1356                         }
1357                 }
1358
1359                 /* now add the list of collected channels */
1360                 BLI_movelisttolist(anim_data, &tmp_data);
1361                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1362                 items += tmp_items;
1363         }
1364
1365         /* return the number of items added to the list */
1366         return items;
1367 }
1368
1369 static size_t animfilter_action(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bAction *act, int filter_mode, ID *owner_id)
1370 {
1371         bActionGroup *agrp;
1372         FCurve *lastchan = NULL;
1373         size_t items = 0;
1374
1375         /* don't include anything from this action if it is linked in from another file,
1376          * and we're getting stuff for editing...
1377          */
1378         if ((filter_mode & ANIMFILTER_FOREDIT) && ID_IS_LINKED(act))
1379                 return 0;
1380
1381         /* do groups */
1382         // TODO: do nested groups?
1383         for (agrp = act->groups.first; agrp; agrp = agrp->next) {
1384                 /* store reference to last channel of group */
1385                 if (agrp->channels.last)
1386                         lastchan = agrp->channels.last;
1387
1388                 /* action group's channels */
1389                 items += animfilter_act_group(ac, anim_data, ads, act, agrp, filter_mode, owner_id);
1390         }
1391
1392         /* un-grouped F-Curves (only if we're not only considering those channels in the active group) */
1393         if (!(filter_mode & ANIMFILTER_ACTGROUPED)) {
1394                 FCurve *firstfcu = (lastchan) ? (lastchan->next) : (act->curves.first);
1395                 items += animfilter_fcurves(anim_data, ads, firstfcu, ANIMTYPE_FCURVE, filter_mode, NULL, owner_id, &act->id);
1396         }
1397
1398         /* return the number of items added to the list */
1399         return items;
1400 }
1401
1402 /* Include NLA-Data for NLA-Editor:
1403  * - when ANIMFILTER_LIST_CHANNELS is used, that means we should be filtering the list for display
1404  *   Although the evaluation order is from the first track to the last and then apply the Action on top,
1405  *   we present this in the UI as the Active Action followed by the last track to the first so that we
1406  *   get the evaluation order presented as per a stack.
1407  * - for normal filtering (i.e. for editing), we only need the NLA-tracks but they can be in 'normal' evaluation
1408  *   order, i.e. first to last. Otherwise, some tools may get screwed up.
1409  */
1410 static size_t animfilter_nla(bAnimContext *UNUSED(ac), ListBase *anim_data, bDopeSheet *ads, AnimData *adt, int filter_mode, ID *owner_id)
1411 {
1412         NlaTrack *nlt;
1413         NlaTrack *first = NULL, *next = NULL;
1414         size_t items = 0;
1415
1416         /* if showing channels, include active action */
1417         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1418                 /* if NLA action-line filtering is off, don't show unless there are keyframes,
1419                  * in order to keep things more compact for doing transforms
1420                  */
1421                 if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || (adt->action)) {
1422                         /* there isn't really anything editable here, so skip if need editable */
1423                         if ((filter_mode & ANIMFILTER_FOREDIT) == 0) {
1424                                 /* just add the action track now (this MUST appear for drawing)
1425                                  * - as AnimData may not have an action, we pass a dummy pointer just to get the list elem created, then
1426                                  *   overwrite this with the real value - REVIEW THIS...
1427                                  */
1428                                 ANIMCHANNEL_NEW_CHANNEL_FULL((void *)(&adt->action), ANIMTYPE_NLAACTION, owner_id, NULL,
1429                                         {
1430                                                 ale->data = adt->action ? adt->action : NULL;
1431                                         });
1432                         }
1433                 }
1434
1435                 /* first track to include will be the last one if we're filtering by channels */
1436                 first = adt->nla_tracks.last;
1437         }
1438         else {
1439                 /* first track to include will the first one (as per normal) */
1440                 first = adt->nla_tracks.first;
1441         }
1442
1443         /* loop over NLA Tracks - assume that the caller of this has already checked that these should be included */
1444         for (nlt = first; nlt; nlt = next) {
1445                 /* 'next' NLA-Track to use depends on whether we're filtering for drawing or not */
1446                 if (filter_mode & ANIMFILTER_LIST_CHANNELS)
1447                         next = nlt->prev;
1448                 else
1449                         next = nlt->next;
1450
1451                 /* if we're in NLA-tweakmode, don't show this track if it was disabled (due to tweaking) for now
1452                  * - active track should still get shown though (even though it has disabled flag set)
1453                  */
1454                 // FIXME: the channels after should still get drawn, just 'differently', and after an active-action channel
1455                 if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED) && (adt->act_track != nlt))
1456                         continue;
1457
1458                 /* only work with this channel and its subchannels if it is editable */
1459                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_NLT(nlt)) {
1460                         /* only include this track if selected in a way consistent with the filtering requirements */
1461                         if (ANIMCHANNEL_SELOK(SEL_NLT(nlt))) {
1462                                 /* only include if this track is active */
1463                                 if (!(filter_mode & ANIMFILTER_ACTIVE) || (nlt->flag & NLATRACK_ACTIVE)) {
1464                                         /* name based filtering... */
1465                                         if (((ads) && (ads->searchstr[0] != '\0')) && (owner_id)) {
1466                                                 bool track_ok = false, strip_ok = false;
1467
1468                                                 /* check if the name of the track, or the strips it has are ok... */
1469                                                 track_ok = name_matches_dopesheet_filter(ads, nlt->name);
1470
1471                                                 if (track_ok == false) {
1472                                                         NlaStrip *strip;
1473                                                         for (strip = nlt->strips.first; strip; strip = strip->next) {
1474                                                                 if (name_matches_dopesheet_filter(ads, strip->name)) {
1475                                                                         strip_ok = true;
1476                                                                         break;
1477                                                                 }
1478                                                         }
1479                                                 }
1480
1481                                                 /* skip if both fail this test... */
1482                                                 if (!track_ok && !strip_ok) {
1483                                                         continue;
1484                                                 }
1485                                         }
1486
1487                                         /* add the track now that it has passed all our tests */
1488                                         ANIMCHANNEL_NEW_CHANNEL(nlt, ANIMTYPE_NLATRACK, owner_id, NULL);
1489                                 }
1490                         }
1491                 }
1492         }
1493
1494         /* return the number of items added to the list */
1495         return items;
1496 }
1497
1498 /* Include the control FCurves per NLA Strip in the channel list
1499  * NOTE: This is includes the expander too...
1500  */
1501 static size_t animfilter_nla_controls(ListBase *anim_data, bDopeSheet *ads, AnimData *adt, int filter_mode, ID *owner_id)
1502 {
1503         ListBase tmp_data = {NULL, NULL};
1504         size_t tmp_items = 0;
1505         size_t items = 0;
1506
1507         /* add control curves from each NLA strip... */
1508         /* NOTE: ANIMTYPE_FCURVES are created here, to avoid duplicating the code needed */
1509         BEGIN_ANIMFILTER_SUBCHANNELS(((adt->flag & ADT_NLA_SKEYS_COLLAPSED) == 0))
1510         {
1511                 NlaTrack *nlt;
1512                 NlaStrip *strip;
1513
1514                 /* for now, we only go one level deep - so controls on grouped FCurves are not handled */
1515                 for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
1516                         for (strip = nlt->strips.first; strip; strip = strip->next) {
1517                                 /* pass strip as the "owner", so that the name lookups (used while filtering) will resolve */
1518                                 /* NLA tracks are coming from AnimData, so owner of f-curves
1519                                  * is the same as owner of animation data. */
1520                                 tmp_items += animfilter_fcurves(&tmp_data, ads, strip->fcurves.first, ANIMTYPE_NLACURVE,
1521                                                                 filter_mode, strip, owner_id, owner_id);
1522                         }
1523                 }
1524         }
1525         END_ANIMFILTER_SUBCHANNELS;
1526
1527         /* did we find anything? */
1528         if (tmp_items) {
1529                 /* add the expander as a channel first */
1530                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1531                         /* currently these channels cannot be selected, so they should be skipped */
1532                         if ((filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) == 0) {
1533                                 ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_NLACONTROLS, owner_id, NULL);
1534                         }
1535                 }
1536
1537                 /* now add the list of collected channels */
1538                 BLI_movelisttolist(anim_data, &tmp_data);
1539                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1540                 items += tmp_items;
1541         }
1542
1543         /* return the number of items added to the list */
1544         return items;
1545 }
1546
1547 /* determine what animation data from AnimData block should get displayed */
1548 static size_t animfilter_block_data(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *id, int filter_mode)
1549 {
1550         AnimData *adt = BKE_animdata_from_id(id);
1551         size_t items = 0;
1552
1553         /* image object datablocks have no anim-data so check for NULL */
1554         if (adt) {
1555                 IdAdtTemplate *iat = (IdAdtTemplate *)id;
1556
1557                 /* NOTE: this macro is used instead of inlining the logic here, since this sort of filtering is still needed
1558                  * in a few places in the rest of the code still - notably for the few cases where special mode-based
1559                  * different types of data expanders are required.
1560                  */
1561                 ANIMDATA_FILTER_CASES(iat,
1562                         { /* AnimData */
1563                                 /* specifically filter animdata block */
1564                                 if (ANIMCHANNEL_SELOK(SEL_ANIMDATA(adt)) ) {
1565                                         ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_ANIMDATA, id, NULL);
1566                                 }
1567                         },
1568                         { /* NLA */
1569                                 items += animfilter_nla(ac, anim_data, ads, adt, filter_mode, id);
1570                         },
1571                         { /* Drivers */
1572                                 items += animfilter_fcurves(anim_data, ads, adt->drivers.first, ANIMTYPE_FCURVE,
1573                                                             filter_mode, NULL, id, id);
1574                         },
1575                         { /* NLA Control Keyframes */
1576                                 items += animfilter_nla_controls(anim_data, ads, adt, filter_mode, id);
1577                         },
1578                         { /* Keyframes */
1579                                 items += animfilter_action(ac, anim_data, ads, adt->action, filter_mode, id);
1580                         }
1581                 );
1582         }
1583
1584         return items;
1585 }
1586
1587
1588
1589 /* Include ShapeKey Data for ShapeKey Editor */
1590 static size_t animdata_filter_shapekey(bAnimContext *ac, ListBase *anim_data, Key *key, int filter_mode)
1591 {
1592         size_t items = 0;
1593
1594         /* check if channels or only F-Curves */
1595         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1596                 KeyBlock *kb;
1597
1598                 /* loop through the channels adding ShapeKeys as appropriate */
1599                 for (kb = key->block.first; kb; kb = kb->next) {
1600                         /* skip the first one, since that's the non-animatable basis */
1601                         if (kb == key->block.first) continue;
1602
1603                         /* only work with this channel and its subchannels if it is editable */
1604                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_SHAPEKEY(kb)) {
1605                                 /* only include this track if selected in a way consistent with the filtering requirements */
1606                                 if (ANIMCHANNEL_SELOK(SEL_SHAPEKEY(kb)) ) {
1607                                         // TODO: consider 'active' too?
1608
1609                                         /* owner-id here must be key so that the F-Curve can be resolved... */
1610                                         ANIMCHANNEL_NEW_CHANNEL(kb, ANIMTYPE_SHAPEKEY, key, NULL);
1611                                 }
1612                         }
1613                 }
1614         }
1615         else {
1616                 /* just use the action associated with the shapekey */
1617                 // TODO: somehow manage to pass dopesheet info down here too?
1618                 if (key->adt) {
1619                         if (filter_mode & ANIMFILTER_ANIMDATA) {
1620                                 if (ANIMCHANNEL_SELOK(SEL_ANIMDATA(key->adt)) ) {
1621                                         ANIMCHANNEL_NEW_CHANNEL(key->adt, ANIMTYPE_ANIMDATA, key, NULL);
1622                                 }
1623                         }
1624                         else if (key->adt->action) {
1625                                 items = animfilter_action(ac, anim_data, NULL, key->adt->action, filter_mode, (ID *)key);
1626                         }
1627                 }
1628         }
1629
1630         /* return the number of items added to the list */
1631         return items;
1632 }
1633
1634 /* Helper for Grease Pencil - layers within a datablock */
1635 static size_t animdata_filter_gpencil_layers_data(ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
1636 {
1637         bGPDlayer *gpl;
1638         size_t items = 0;
1639
1640         /* loop over layers as the conditions are acceptable (top-Down order) */
1641         for (gpl = gpd->layers.last; gpl; gpl = gpl->prev) {
1642                 /* only if selected */
1643                 if (ANIMCHANNEL_SELOK(SEL_GPL(gpl)) ) {
1644                         /* only if editable */
1645                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) {
1646                                 /* active... */
1647                                 if (!(filter_mode & ANIMFILTER_ACTIVE) || (gpl->flag & GP_LAYER_ACTIVE)) {
1648                                         /* skip layer if the name doesn't match the filter string */
1649                                         if ((ads) && (ads->searchstr[0] != '\0')) {
1650                                                 if (name_matches_dopesheet_filter(ads, gpl->info) == false)
1651                                                         continue;
1652                                         }
1653                                         /* add to list */
1654                                         ANIMCHANNEL_NEW_CHANNEL(gpl, ANIMTYPE_GPLAYER, gpd, NULL);
1655                                 }
1656                         }
1657                 }
1658         }
1659
1660         return items;
1661 }
1662
1663 /* Helper for Grease Pencil - Grease Pencil datablock - GP Frames */
1664 static size_t animdata_filter_gpencil_data(ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
1665 {
1666         size_t items = 0;
1667
1668         /* When asked from "AnimData" blocks (i.e. the top-level containers for normal animation),
1669          * for convenience, this will return GP Datablocks instead. This may cause issues down
1670          * the track, but for now, this will do...
1671          */
1672         if (filter_mode & ANIMFILTER_ANIMDATA) {
1673                 /* just add GPD as a channel - this will add everything needed */
1674                 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_GPDATABLOCK, gpd, NULL);
1675         }
1676         else {
1677                 ListBase tmp_data = {NULL, NULL};
1678                 size_t tmp_items = 0;
1679
1680                 /* add gpencil animation channels */
1681                 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_GPD(gpd))
1682                 {
1683                         tmp_items += animdata_filter_gpencil_layers_data(&tmp_data, ads, gpd, filter_mode);
1684                 }
1685                 END_ANIMFILTER_SUBCHANNELS;
1686
1687                 /* did we find anything? */
1688                 if (tmp_items) {
1689                         /* include data-expand widget first */
1690                         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1691                                 /* add gpd as channel too (if for drawing, and it has layers) */
1692                                 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_GPDATABLOCK, NULL, NULL);
1693                         }
1694
1695                         /* now add the list of collected channels */
1696                         BLI_movelisttolist(anim_data, &tmp_data);
1697                         BLI_assert(BLI_listbase_is_empty(&tmp_data));
1698                         items += tmp_items;
1699                 }
1700         }
1701
1702         return items;
1703 }
1704
1705 /* Grab all Grease Pencil datablocks in file */
1706 // TODO: should this be amalgamated with the dopesheet filtering code?
1707 static size_t animdata_filter_gpencil(bAnimContext *ac, ListBase *anim_data, void *UNUSED(data), int filter_mode)
1708 {
1709         bDopeSheet *ads = ac->ads;
1710         size_t items = 0;
1711
1712         if (ads->filterflag & ADS_FILTER_GP_3DONLY) {
1713                 Scene *scene = (Scene *)ads->source;
1714                 ViewLayer *view_layer = (ViewLayer *)ac->view_layer;
1715                 Base *base;
1716
1717                 /* Active scene's GPencil block first - No parent item needed... */
1718                 if (scene->gpd) {
1719                         items += animdata_filter_gpencil_data(anim_data, ads, scene->gpd, filter_mode);
1720                 }
1721
1722                 /* Objects in the scene */
1723                 for (base = view_layer->object_bases.first; base; base = base->next) {
1724                         /* Only consider this object if it has got some GP data (saving on all the other tests) */
1725                         if (base->object && (base->object->type == OB_GPENCIL)) {
1726                                 Object *ob = base->object;
1727
1728                                 /* firstly, check if object can be included, by the following factors:
1729                                  * - if only visible, must check for layer and also viewport visibility
1730                                  *   --> while tools may demand only visible, user setting takes priority
1731                                  *       as user option controls whether sets of channels get included while
1732                                  *       tool-flag takes into account collapsed/open channels too
1733                                  * - if only selected, must check if object is selected
1734                                  * - there must be animation data to edit (this is done recursively as we
1735                                  *   try to add the channels)
1736                                  */
1737                                 if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
1738                                         /* layer visibility - we check both object and base, since these may not be in sync yet */
1739                                         if ((base->flag & BASE_VISIBLE) == 0) continue;
1740
1741                                         /* outliner restrict-flag */
1742                                         if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
1743                                 }
1744
1745                                 /* check selection and object type filters */
1746                                 if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & BASE_SELECTED) /*|| (base == scene->basact)*/) ) {
1747                                         /* only selected should be shown */
1748                                         continue;
1749                                 }
1750
1751                                 /* check if object belongs to the filtering group if option to filter
1752                                  * objects by the grouped status is on
1753                                  * - used to ease the process of doing multiple-character choreographies
1754                                  */
1755                                 if (ads->filter_grp != NULL) {
1756                                         if (BKE_collection_has_object_recursive(ads->filter_grp, ob) == 0)
1757                                                 continue;
1758                                 }
1759
1760                                 /* finally, include this object's grease pencil datablock */
1761                                 /* XXX: Should we store these under expanders per item? */
1762                                 items += animdata_filter_gpencil_data(anim_data, ads, ob->data, filter_mode);
1763                         }
1764                 }
1765         }
1766         else {
1767                 bGPdata *gpd;
1768
1769                 /* Grab all Grease Pencil datablocks directly from main,
1770                  * but only those that seem to be useful somewhere */
1771                 for (gpd = ac->bmain->gpencil.first; gpd; gpd = gpd->id.next) {
1772                         /* only show if gpd is used by something... */
1773                         if (ID_REAL_USERS(gpd) < 1)
1774                                 continue;
1775
1776                         /* add GP frames from this datablock */
1777                         items += animdata_filter_gpencil_data(anim_data, ads, gpd, filter_mode);
1778                 }
1779         }
1780
1781         /* return the number of items added to the list */
1782         return items;
1783 }
1784
1785 /* Helper for Grease Pencil data integrated with main DopeSheet */
1786 static size_t animdata_filter_ds_gpencil(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
1787 {
1788         ListBase tmp_data = {NULL, NULL};
1789         size_t tmp_items = 0;
1790         size_t items = 0;
1791
1792         /* add relevant animation channels for Grease Pencil */
1793         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_GPD(gpd))
1794         {
1795                 /* add animation channels */
1796                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, &gpd->id, filter_mode);
1797
1798                 /* add Grease Pencil layers */
1799                 // TODO: do these need a separate expander?
1800                 // XXX:  what order should these go in?
1801         }
1802         END_ANIMFILTER_SUBCHANNELS;
1803
1804         /* did we find anything? */
1805         if (tmp_items) {
1806                 /* include data-expand widget first */
1807                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1808                         /* check if filtering by active status */
1809                         // XXX: active check here needs checking
1810                         if (ANIMCHANNEL_ACTIVEOK(gpd)) {
1811                                 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_DSGPENCIL, gpd, NULL);
1812                         }
1813                 }
1814
1815                 /* now add the list of collected channels */
1816                 BLI_movelisttolist(anim_data, &tmp_data);
1817                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1818                 items += tmp_items;
1819         }
1820
1821         /* return the number of items added to the list */
1822         return items;
1823 }
1824
1825 /* Helper for Cache File data integrated with main DopeSheet */
1826 static size_t animdata_filter_ds_cachefile(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, CacheFile *cache_file, int filter_mode)
1827 {
1828         ListBase tmp_data = {NULL, NULL};
1829         size_t tmp_items = 0;
1830         size_t items = 0;
1831
1832         /* add relevant animation channels for Cache File */
1833         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_CACHEFILE_OBJD(cache_file))
1834         {
1835                 /* add animation channels */
1836                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, &cache_file->id, filter_mode);
1837         }
1838         END_ANIMFILTER_SUBCHANNELS;
1839
1840         /* did we find anything? */
1841         if (tmp_items) {
1842                 /* include data-expand widget first */
1843                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1844                         /* check if filtering by active status */
1845                         // XXX: active check here needs checking
1846                         if (ANIMCHANNEL_ACTIVEOK(cache_file)) {
1847                                 ANIMCHANNEL_NEW_CHANNEL(cache_file, ANIMTYPE_DSCACHEFILE, cache_file, NULL);
1848                         }
1849                 }
1850
1851                 /* now add the list of collected channels */
1852                 BLI_movelisttolist(anim_data, &tmp_data);
1853                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1854                 items += tmp_items;
1855         }
1856
1857         /* return the number of items added to the list */
1858         return items;
1859 }
1860
1861 /* Helper for Mask Editing - mask layers */
1862 static size_t animdata_filter_mask_data(ListBase *anim_data, Mask *mask, const int filter_mode)
1863 {
1864         MaskLayer *masklay_act = BKE_mask_layer_active(mask);
1865         MaskLayer *masklay;
1866         size_t items = 0;
1867
1868         /* loop over layers as the conditions are acceptable */
1869         for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
1870                 /* only if selected */
1871                 if (ANIMCHANNEL_SELOK(SEL_MASKLAY(masklay)) ) {
1872                         /* only if editable */
1873                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_MASK(masklay)) {
1874                                 /* active... */
1875                                 if (!(filter_mode & ANIMFILTER_ACTIVE) || (masklay_act == masklay)) {
1876                                         /* add to list */
1877                                         ANIMCHANNEL_NEW_CHANNEL(masklay, ANIMTYPE_MASKLAYER, mask, NULL);
1878                                 }
1879                         }
1880                 }
1881         }
1882
1883         return items;
1884 }
1885
1886 /* Grab all mask data */
1887 static size_t animdata_filter_mask(Main *bmain, ListBase *anim_data, void *UNUSED(data), int filter_mode)
1888 {
1889         Mask *mask;
1890         size_t items = 0;
1891
1892         /* for now, grab mask datablocks directly from main */
1893         // XXX: this is not good...
1894         for (mask = bmain->mask.first; mask; mask = mask->id.next) {
1895                 ListBase tmp_data = {NULL, NULL};
1896                 size_t tmp_items = 0;
1897
1898                 /* only show if mask is used by something... */
1899                 if (ID_REAL_USERS(mask) < 1)
1900                         continue;
1901
1902                 /* add mask animation channels */
1903                 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_MASK(mask))
1904                 {
1905                         tmp_items += animdata_filter_mask_data(&tmp_data, mask, filter_mode);
1906                 }
1907                 END_ANIMFILTER_SUBCHANNELS;
1908
1909                 /* did we find anything? */
1910                 if (tmp_items) {
1911                         /* include data-expand widget first */
1912                         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1913                                 /* add gpd as channel too (if for drawing, and it has layers) */
1914                                 ANIMCHANNEL_NEW_CHANNEL(mask, ANIMTYPE_MASKDATABLOCK, NULL, NULL);
1915                         }
1916
1917                         /* now add the list of collected channels */
1918                         BLI_movelisttolist(anim_data, &tmp_data);
1919                         BLI_assert(BLI_listbase_is_empty(&tmp_data));
1920                         items += tmp_items;
1921                 }
1922         }
1923
1924         /* return the number of items added to the list */
1925         return items;
1926 }
1927
1928 /* NOTE: owner_id is scene, material, or texture block, which is the direct owner of the node tree in question */
1929 static size_t animdata_filter_ds_nodetree_group(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, bNodeTree *ntree, int filter_mode)
1930 {
1931         ListBase tmp_data = {NULL, NULL};
1932         size_t tmp_items = 0;
1933         size_t items = 0;
1934
1935         /* add nodetree animation channels */
1936         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_NTREE_DATA(ntree))
1937         {
1938                 /* animation data filtering */
1939                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ntree, filter_mode);
1940         }
1941         END_ANIMFILTER_SUBCHANNELS;
1942
1943         /* did we find anything? */
1944         if (tmp_items) {
1945                 /* include data-expand widget first */
1946                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1947                         /* check if filtering by active status */
1948                         if (ANIMCHANNEL_ACTIVEOK(ntree)) {
1949                                 ANIMCHANNEL_NEW_CHANNEL(ntree, ANIMTYPE_DSNTREE, owner_id, NULL);
1950                         }
1951                 }
1952
1953                 /* now add the list of collected channels */
1954                 BLI_movelisttolist(anim_data, &tmp_data);
1955                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1956                 items += tmp_items;
1957         }
1958
1959         /* return the number of items added to the list */
1960         return items;
1961 }
1962
1963 static size_t animdata_filter_ds_nodetree(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, bNodeTree *ntree, int filter_mode)
1964 {
1965         bNode *node;
1966         size_t items = 0;
1967
1968         items += animdata_filter_ds_nodetree_group(ac, anim_data, ads, owner_id, ntree, filter_mode);
1969
1970         for (node = ntree->nodes.first; node; node = node->next) {
1971                 if (node->type == NODE_GROUP) {
1972                         if (node->id) {
1973                                 if ((ads->filterflag & ADS_FILTER_ONLYSEL) && (node->flag & NODE_SELECT) == 0) {
1974                                         continue;
1975                                 }
1976                                 items += animdata_filter_ds_nodetree_group(ac, anim_data, ads, owner_id, (bNodeTree *) node->id,
1977                                                                            filter_mode | ANIMFILTER_TMP_IGNORE_ONLYSEL);
1978                         }
1979                 }
1980         }
1981
1982         return items;
1983 }
1984
1985 static size_t animdata_filter_ds_linestyle(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
1986 {
1987         ViewLayer *view_layer;
1988         FreestyleLineSet *lineset;
1989         size_t items = 0;
1990
1991         for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
1992                 for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) {
1993                         if (lineset->linestyle) {
1994                                 lineset->linestyle->id.tag |= LIB_TAG_DOIT;
1995                         }
1996                 }
1997         }
1998
1999         for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
2000                 /* skip render layers without Freestyle enabled */
2001                 if ((view_layer->flag & VIEW_LAYER_FREESTYLE) == 0) {
2002                         continue;
2003                 }
2004
2005                 /* loop over linesets defined in the render layer */
2006                 for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) {
2007                         FreestyleLineStyle *linestyle = lineset->linestyle;
2008                         ListBase tmp_data = {NULL, NULL};
2009                         size_t tmp_items = 0;
2010
2011                         if ((linestyle == NULL) ||
2012                             !(linestyle->id.tag & LIB_TAG_DOIT))
2013                         {
2014                                 continue;
2015                         }
2016                         linestyle->id.tag &= ~LIB_TAG_DOIT;
2017
2018                         /* add scene-level animation channels */
2019                         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_LS_SCED(linestyle))
2020                         {
2021                                 /* animation data filtering */
2022                                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)linestyle, filter_mode);
2023                         }
2024                         END_ANIMFILTER_SUBCHANNELS;
2025
2026                         /* did we find anything? */
2027                         if (tmp_items) {
2028                                 /* include anim-expand widget first */
2029                                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2030                                         /* check if filtering by active status */
2031                                         if (ANIMCHANNEL_ACTIVEOK(linestyle)) {
2032                                                 ANIMCHANNEL_NEW_CHANNEL(linestyle, ANIMTYPE_DSLINESTYLE, sce, NULL);
2033                                         }
2034                                 }
2035
2036                                 /* now add the list of collected channels */
2037                                 BLI_movelisttolist(anim_data, &tmp_data);
2038                                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2039                                 items += tmp_items;
2040                         }
2041                 }
2042         }
2043
2044         /* return the number of items added to the list */
2045         return items;
2046 }
2047
2048 static size_t animdata_filter_ds_texture(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads,
2049                                          Tex *tex, ID *owner_id, int filter_mode)
2050 {
2051         ListBase tmp_data = {NULL, NULL};
2052         size_t tmp_items = 0;
2053         size_t items = 0;
2054
2055         /* add texture's animation data to temp collection */
2056         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_TEX_DATA(tex))
2057         {
2058                 /* texture animdata */
2059                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)tex, filter_mode);
2060
2061                 /* nodes */
2062                 if ((tex->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
2063                         /* owner_id as id instead of texture, since it'll otherwise be impossible to track the depth */
2064                         // FIXME: perhaps as a result, textures should NOT be included under materials, but under their own section instead
2065                         // so that free-floating textures can also be animated
2066                         tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)tex, tex->nodetree, filter_mode);
2067                 }
2068         }
2069         END_ANIMFILTER_SUBCHANNELS;
2070
2071         /* did we find anything? */
2072         if (tmp_items) {
2073                 /* include texture-expand widget? */
2074                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2075                         /* check if filtering by active status */
2076                         if (ANIMCHANNEL_ACTIVEOK(tex)) {
2077                                 ANIMCHANNEL_NEW_CHANNEL(tex, ANIMTYPE_DSTEX, owner_id, NULL);
2078                         }
2079                 }
2080
2081                 /* now add the list of collected channels */
2082                 BLI_movelisttolist(anim_data, &tmp_data);
2083                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2084                 items += tmp_items;
2085         }
2086
2087         /* return the number of items added to the list */
2088         return items;
2089 }
2090
2091 /* NOTE: owner_id is the direct owner of the texture stack in question
2092  *       It used to be Material/Lamp/World before the Blender Internal removal for 2.8
2093  */
2094 static size_t animdata_filter_ds_textures(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, int filter_mode)
2095 {
2096         MTex **mtex = NULL;
2097         size_t items = 0;
2098         int a = 0;
2099
2100         /* get datatype specific data first */
2101         if (owner_id == NULL)
2102                 return 0;
2103
2104         switch (GS(owner_id->name)) {
2105                 case ID_PA:
2106                 {
2107                         ParticleSettings *part = (ParticleSettings *)owner_id;
2108                         mtex = (MTex **)(&part->mtex);
2109                         break;
2110                 }
2111                 default:
2112                 {
2113                         /* invalid/unsupported option */
2114                         if (G.debug & G_DEBUG)
2115                                 printf("ERROR: Unsupported owner_id (i.e. texture stack) for filter textures - %s\n", owner_id->name);
2116                         return 0;
2117                 }
2118         }
2119
2120         /* firstly check that we actuallly have some textures, by gathering all textures in a temp list */
2121         for (a = 0; a < MAX_MTEX; a++) {
2122                 Tex *tex = (mtex[a]) ? mtex[a]->tex : NULL;
2123
2124                 /* for now, if no texture returned, skip (this shouldn't confuse the user I hope) */
2125                 if (tex == NULL)
2126                         continue;
2127
2128                 /* add texture's anim channels */
2129                 items += animdata_filter_ds_texture(ac, anim_data, ads, tex, owner_id, filter_mode);
2130         }
2131
2132         /* return the number of items added to the list */
2133         return items;
2134 }
2135
2136
2137 static size_t animdata_filter_ds_material(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Material *ma, int filter_mode)
2138 {
2139         ListBase tmp_data = {NULL, NULL};
2140         size_t tmp_items = 0;
2141         size_t items = 0;
2142
2143         /* add material's animation data to temp collection */
2144         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_MAT_OBJD(ma))
2145         {
2146                 /* material's animation data */
2147                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ma, filter_mode);
2148
2149                 /* nodes */
2150                 if ((ma->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE))
2151                         tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)ma, ma->nodetree, filter_mode);
2152         }
2153         END_ANIMFILTER_SUBCHANNELS;
2154
2155         /* did we find anything? */
2156         if (tmp_items) {
2157                 /* include material-expand widget first */
2158                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2159                         /* check if filtering by active status */
2160                         if (ANIMCHANNEL_ACTIVEOK(ma)) {
2161                                 ANIMCHANNEL_NEW_CHANNEL(ma, ANIMTYPE_DSMAT, ma, NULL);
2162                         }
2163                 }
2164
2165                 /* now add the list of collected channels */
2166                 BLI_movelisttolist(anim_data, &tmp_data);
2167                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2168                 items += tmp_items;
2169         }
2170
2171         return items;
2172 }
2173
2174 static size_t animdata_filter_ds_materials(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2175 {
2176         bool has_nested = false;
2177         size_t items = 0;
2178         int a = 0;
2179
2180         /* first pass: take the materials referenced via the Material slots of the object */
2181         for (a = 1; a <= ob->totcol; a++) {
2182                 Material *ma = give_current_material(ob, a);
2183
2184                 /* if material is valid, try to add relevant contents from here */
2185                 if (ma) {
2186                         /* add channels */
2187                         items += animdata_filter_ds_material(ac, anim_data, ads, ma, filter_mode);
2188
2189                         /* for optimising second pass - check if there's a nested material here to come back for */
2190                         if (has_nested == false) {
2191                                 has_nested = (give_node_material(ma) != NULL);
2192                         }
2193                 }
2194         }
2195
2196         /* second pass: go through a second time looking for "nested" materials (material.material references)
2197          *
2198          * NOTE: here we ignore the expanded status of the parent, as it could be too confusing as to why these are
2199          *       disappearing/not available, since the relationships between these is not that clear
2200          */
2201         if (has_nested) {
2202                 for (a = 1; a <= ob->totcol; a++) {
2203                         Material *base = give_current_material(ob, a);
2204                         Material *ma   = give_node_material(base);
2205
2206                         /* add channels from the nested material if it exists
2207                          *   - skip if the same material is referenced in its node tree
2208                          *     (which is common for BI materials) as that results in
2209                          *     confusing duplicates
2210                          */
2211                         if ((ma) && (ma != base)) {
2212                                 items += animdata_filter_ds_material(ac, anim_data, ads, ma, filter_mode);
2213                         }
2214                 }
2215         }
2216
2217         /* return the number of items added to the list */
2218         return items;
2219 }
2220
2221
2222 /* ............ */
2223
2224 /* Temporary context for modifier linked-data channel extraction */
2225 typedef struct tAnimFilterModifiersContext {
2226         bAnimContext *ac;       /* anim editor context */
2227         bDopeSheet *ads;    /* dopesheet filtering settings */
2228
2229         ListBase tmp_data;  /* list of channels created (but not yet added to the main list) */
2230         size_t items;       /* number of channels created */
2231
2232         int filter_mode;    /* flags for stuff we want to filter */
2233 } tAnimFilterModifiersContext;
2234
2235
2236 /* dependency walker callback for modifier dependencies */
2237 static void animfilter_modifier_idpoin_cb(void *afm_ptr, Object *ob, ID **idpoin, int UNUSED(cb_flag))
2238 {
2239         tAnimFilterModifiersContext *afm = (tAnimFilterModifiersContext *)afm_ptr;
2240         ID *owner_id = &ob->id;
2241         ID *id = *idpoin;
2242
2243         /* NOTE: the walker only guarantees to give us all the ID-ptr *slots*,
2244          * not just the ones which are actually used, so be careful!
2245          */
2246         if (id == NULL)
2247                 return;
2248
2249         /* check if this is something we're interested in... */
2250         switch (GS(id->name)) {
2251                 case ID_TE: /* Textures */
2252                 {
2253                         Tex *tex = (Tex *)id;
2254                         if (!(afm->ads->filterflag & ADS_FILTER_NOTEX)) {
2255                                 afm->items += animdata_filter_ds_texture(afm->ac, &afm->tmp_data, afm->ads, tex, owner_id, afm->filter_mode);
2256                         }
2257                         break;
2258                 }
2259
2260                 /* TODO: images? */
2261                 default:
2262                         break;
2263         }
2264 }
2265
2266 /* animation linked to data used by modifiers
2267  * NOTE: strictly speaking, modifier animation is already included under Object level
2268  *       but for some modifiers (e.g. Displace), there can be linked data that has settings
2269  *       which would be nice to animate (i.e. texture parameters) but which are not actually
2270  *       attached to any other objects/materials/etc. in the scene
2271  */
2272 // TODO: do we want an expander for this?
2273 static size_t animdata_filter_ds_modifiers(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2274 {
2275         tAnimFilterModifiersContext afm = {NULL};
2276         size_t items = 0;
2277
2278         /* 1) create a temporary "context" containing all the info we have here to pass to the callback
2279          *    use to walk through the dependencies of the modifiers
2280          *
2281          * ! Assumes that all other unspecified values (i.e. accumulation buffers) are zero'd out properly
2282          */
2283         afm.ac          = ac;
2284         afm.ads         = ads;
2285         afm.filter_mode = filter_mode;
2286
2287         /* 2) walk over dependencies */
2288         modifiers_foreachIDLink(ob, animfilter_modifier_idpoin_cb, &afm);
2289
2290         /* 3) extract data from the context, merging it back into the standard list */
2291         if (afm.items) {
2292                 /* now add the list of collected channels */
2293                 BLI_movelisttolist(anim_data, &afm.tmp_data);
2294                 BLI_assert(BLI_listbase_is_empty(&afm.tmp_data));
2295                 items += afm.items;
2296         }
2297
2298         return items;
2299 }
2300
2301 /* ............ */
2302
2303
2304 static size_t animdata_filter_ds_particles(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2305 {
2306         ParticleSystem *psys;
2307         size_t items = 0;
2308
2309         for (psys = ob->particlesystem.first; psys; psys = psys->next) {
2310                 ListBase tmp_data = {NULL, NULL};
2311                 size_t tmp_items = 0;
2312
2313                 /* if no material returned, skip - so that we don't get weird blank entries... */
2314                 if (ELEM(NULL, psys->part, psys->part->adt))
2315                         continue;
2316
2317                 /* add particle-system's animation data to temp collection */
2318                 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_PART_OBJD(psys->part))
2319                 {
2320                         /* particle system's animation data */
2321                         tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)psys->part, filter_mode);
2322
2323                         /* textures */
2324                         if (!(ads->filterflag & ADS_FILTER_NOTEX))
2325                                 tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, (ID *)psys->part, filter_mode);
2326                 }
2327                 END_ANIMFILTER_SUBCHANNELS;
2328
2329                 /* did we find anything? */
2330                 if (tmp_items) {
2331                         /* include particle-expand widget first */
2332                         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2333                                 /* check if filtering by active status */
2334                                 if (ANIMCHANNEL_ACTIVEOK(psys->part)) {
2335                                         ANIMCHANNEL_NEW_CHANNEL(psys->part, ANIMTYPE_DSPART, psys->part, NULL);
2336                                 }
2337                         }
2338
2339                         /* now add the list of collected channels */
2340                         BLI_movelisttolist(anim_data, &tmp_data);
2341                         BLI_assert(BLI_listbase_is_empty(&tmp_data));
2342                         items += tmp_items;
2343                 }
2344         }
2345
2346         /* return the number of items added to the list */
2347         return items;
2348 }
2349
2350
2351 static size_t animdata_filter_ds_obdata(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2352 {
2353         ListBase tmp_data = {NULL, NULL};
2354         size_t tmp_items = 0;
2355         size_t items = 0;
2356
2357         IdAdtTemplate *iat = ob->data;
2358         short type = 0, expanded = 0;
2359
2360         /* get settings based on data type */
2361         switch (ob->type) {
2362                 case OB_CAMERA: /* ------- Camera ------------ */
2363                 {
2364                         Camera *ca = (Camera *)ob->data;
2365
2366                         if (ads->filterflag & ADS_FILTER_NOCAM)
2367                                 return 0;
2368
2369                         type = ANIMTYPE_DSCAM;
2370                         expanded = FILTER_CAM_OBJD(ca);
2371                         break;
2372                 }
2373                 case OB_LAMP: /* ---------- Lamp ----------- */
2374                 {
2375                         Lamp *la = (Lamp *)ob->data;
2376
2377                         if (ads->filterflag & ADS_FILTER_NOLAM)
2378                                 return 0;
2379
2380                         type = ANIMTYPE_DSLAM;
2381                         expanded = FILTER_LAM_OBJD(la);
2382                         break;
2383                 }
2384                 case OB_CURVE: /* ------- Curve ---------- */
2385                 case OB_SURF: /* ------- Nurbs Surface ---------- */
2386                 case OB_FONT: /* ------- Text Curve ---------- */
2387                 {
2388                         Curve *cu = (Curve *)ob->data;
2389
2390                         if (ads->filterflag & ADS_FILTER_NOCUR)
2391                                 return 0;
2392
2393                         type = ANIMTYPE_DSCUR;
2394                         expanded = FILTER_CUR_OBJD(cu);
2395                         break;
2396                 }
2397                 case OB_MBALL: /* ------- MetaBall ---------- */
2398                 {
2399                         MetaBall *mb = (MetaBall *)ob->data;
2400
2401                         if (ads->filterflag & ADS_FILTER_NOMBA)
2402                                 return 0;
2403
2404                         type = ANIMTYPE_DSMBALL;
2405                         expanded = FILTER_MBALL_OBJD(mb);
2406                         break;
2407                 }
2408                 case OB_ARMATURE: /* ------- Armature ---------- */
2409                 {
2410                         bArmature *arm = (bArmature *)ob->data;
2411
2412                         if (ads->filterflag & ADS_FILTER_NOARM)
2413                                 return 0;
2414
2415                         type = ANIMTYPE_DSARM;
2416                         expanded = FILTER_ARM_OBJD(arm);
2417                         break;
2418                 }
2419                 case OB_MESH: /* ------- Mesh ---------- */
2420                 {
2421                         Mesh *me = (Mesh *)ob->data;
2422
2423                         if (ads->filterflag & ADS_FILTER_NOMESH)
2424                                 return 0;
2425
2426                         type = ANIMTYPE_DSMESH;
2427                         expanded = FILTER_MESH_OBJD(me);
2428                         break;
2429                 }
2430                 case OB_LATTICE: /* ---- Lattice ---- */
2431                 {
2432                         Lattice *lt = (Lattice *)ob->data;
2433
2434                         if (ads->filterflag & ADS_FILTER_NOLAT)
2435                                 return 0;
2436
2437                         type = ANIMTYPE_DSLAT;
2438                         expanded = FILTER_LATTICE_OBJD(lt);
2439                         break;
2440                 }
2441                 case OB_SPEAKER: /* ---------- Speaker ----------- */
2442                 {
2443                         Speaker *spk = (Speaker *)ob->data;
2444
2445                         type = ANIMTYPE_DSSPK;
2446                         expanded = FILTER_SPK_OBJD(spk);
2447                         break;
2448                 }
2449         }
2450
2451         /* add object data animation channels */
2452         BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
2453         {
2454                 /* animation data filtering */
2455                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)iat, filter_mode);
2456
2457                 /* sub-data filtering... */
2458                 switch (ob->type) {
2459                         case OB_LAMP:  /* lamp - textures + nodetree */
2460                         {
2461                                 Lamp *la = ob->data;
2462                                 bNodeTree *ntree = la->nodetree;
2463
2464                                 /* nodetree */
2465                                 if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE))
2466                                         tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, &la->id, ntree, filter_mode);
2467                                 break;
2468                         }
2469                 }
2470         }
2471         END_ANIMFILTER_SUBCHANNELS;
2472
2473         /* did we find anything? */
2474         if (tmp_items) {
2475                 /* include data-expand widget first */
2476                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2477                         /* check if filtering by active status */
2478                         if (ANIMCHANNEL_ACTIVEOK(iat)) {
2479                                 ANIMCHANNEL_NEW_CHANNEL(iat, type, iat, NULL);
2480                         }
2481                 }
2482
2483                 /* now add the list of collected channels */
2484                 BLI_movelisttolist(anim_data, &tmp_data);
2485                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2486                 items += tmp_items;
2487         }
2488
2489         /* return the number of items added to the list */
2490         return items;
2491 }
2492
2493 /* shapekey-level animation */
2494 static size_t animdata_filter_ds_keyanim(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, Key *key, int filter_mode)
2495 {
2496         ListBase tmp_data = {NULL, NULL};
2497         size_t tmp_items = 0;
2498         size_t items = 0;
2499
2500         /* add shapekey-level animation channels */
2501         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_SKE_OBJD(key))
2502         {
2503                 /* animation data filtering */
2504                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)key, filter_mode);
2505         }
2506         END_ANIMFILTER_SUBCHANNELS;
2507
2508         /* did we find anything? */
2509         if (tmp_items) {
2510                 /* include key-expand widget first */
2511                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2512                         if (ANIMCHANNEL_ACTIVEOK(key)) {
2513                                 ANIMCHANNEL_NEW_CHANNEL(key, ANIMTYPE_DSSKEY, ob, NULL);
2514                         }
2515                 }
2516
2517                 /* now add the list of collected channels */
2518                 BLI_movelisttolist(anim_data, &tmp_data);
2519                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2520                 items += tmp_items;
2521         }
2522
2523         /* return the number of items added to the list */
2524         return items;
2525 }
2526
2527
2528 /* object-level animation */
2529 static size_t animdata_filter_ds_obanim(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2530 {
2531         ListBase tmp_data = {NULL, NULL};
2532         size_t tmp_items = 0;
2533         size_t items = 0;
2534
2535         AnimData *adt = ob->adt;
2536         short type = 0, expanded = 1;
2537         void *cdata = NULL;
2538
2539         /* determine the type of expander channels to use */
2540         /* this is the best way to do this for now... */
2541         ANIMDATA_FILTER_CASES(ob,
2542                 { /* AnimData - no channel, but consider data */ },
2543                 { /* NLA - no channel, but consider data */ },
2544                 { /* Drivers */
2545                         type = ANIMTYPE_FILLDRIVERS;
2546                         cdata = adt;
2547                         expanded = EXPANDED_DRVD(adt);
2548                 },
2549                 { /* NLA Strip Controls - no dedicated channel for now (XXX) */ },
2550                 { /* Keyframes */
2551                         type = ANIMTYPE_FILLACTD;
2552                         cdata = adt->action;
2553                         expanded = EXPANDED_ACTC(adt->action);
2554                 });
2555
2556         /* add object-level animation channels */
2557         BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
2558         {
2559                 /* animation data filtering */
2560                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ob, filter_mode);
2561         }
2562         END_ANIMFILTER_SUBCHANNELS;
2563
2564         /* did we find anything? */
2565         if (tmp_items) {
2566                 /* include anim-expand widget first */
2567                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2568                         if (type != ANIMTYPE_NONE) {
2569                                 /* NOTE: active-status (and the associated checks) don't apply here... */
2570                                 ANIMCHANNEL_NEW_CHANNEL(cdata, type, ob, NULL);
2571                         }
2572                 }
2573
2574                 /* now add the list of collected channels */
2575                 BLI_movelisttolist(anim_data, &tmp_data);
2576                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2577                 items += tmp_items;
2578         }
2579
2580         /* return the number of items added to the list */
2581         return items;
2582 }
2583
2584 /* get animation channels from object2 */
2585 static size_t animdata_filter_dopesheet_ob(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
2586 {
2587         ListBase tmp_data = {NULL, NULL};
2588         Object *ob = base->object;
2589         size_t tmp_items = 0;
2590         size_t items = 0;
2591
2592         /* filter data contained under object first */
2593         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_OBJC(ob))
2594         {
2595                 Key *key = BKE_key_from_object(ob);
2596
2597                 /* object-level animation */
2598                 if ((ob->adt) && !(ads->filterflag & ADS_FILTER_NOOBJ)) {
2599                         tmp_items += animdata_filter_ds_obanim(ac, &tmp_data, ads, ob, filter_mode);
2600                 }
2601
2602                 /* shape-key */
2603                 if ((key && key->adt) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
2604                         tmp_items += animdata_filter_ds_keyanim(ac, &tmp_data, ads, ob, key, filter_mode);
2605                 }
2606
2607                 /* modifiers */
2608                 if ((ob->modifiers.first) && !(ads->filterflag & ADS_FILTER_NOMODIFIERS)) {
2609                         tmp_items += animdata_filter_ds_modifiers(ac, &tmp_data, ads, ob, filter_mode);
2610                 }
2611
2612                 /* materials */
2613                 if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT)) {
2614                         tmp_items += animdata_filter_ds_materials(ac, &tmp_data, ads, ob, filter_mode);
2615                 }
2616
2617                 /* object data */
2618                 if (ob->data) {
2619                         tmp_items += animdata_filter_ds_obdata(ac, &tmp_data, ads, ob, filter_mode);
2620                 }
2621
2622                 /* particles */
2623                 if ((ob->particlesystem.first) && !(ads->filterflag & ADS_FILTER_NOPART)) {
2624                         tmp_items += animdata_filter_ds_particles(ac, &tmp_data, ads, ob, filter_mode);
2625                 }
2626
2627                 /* grease pencil */
2628                 if ((ob->type == OB_GPENCIL) &&
2629                     (ob->data) && !(ads->filterflag & ADS_FILTER_NOGPENCIL))
2630                 {
2631                         tmp_items += animdata_filter_ds_gpencil(ac, &tmp_data, ads, ob->data, filter_mode);
2632                 }
2633         }
2634         END_ANIMFILTER_SUBCHANNELS;
2635
2636
2637         /* if we collected some channels, add these to the new list... */
2638         if (tmp_items) {
2639                 /* firstly add object expander if required */
2640                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2641                         /* check if filtering by selection */
2642                         // XXX: double-check on this - most of the time, a lot of tools need to filter out these channels!
2643                         if (ANIMCHANNEL_SELOK((base->flag & BASE_SELECTED))) {
2644                                 /* check if filtering by active status */
2645                                 if (ANIMCHANNEL_ACTIVEOK(ob)) {
2646                                         ANIMCHANNEL_NEW_CHANNEL(base, ANIMTYPE_OBJECT, ob, NULL);
2647                                 }
2648                         }
2649                 }
2650
2651                 /* now add the list of collected channels */
2652                 BLI_movelisttolist(anim_data, &tmp_data);
2653                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2654                 items += tmp_items;
2655         }
2656
2657         /* return the number of items added */
2658         return items;
2659 }
2660
2661 static size_t animdata_filter_ds_world(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, World *wo, int filter_mode)
2662 {
2663         ListBase tmp_data = {NULL, NULL};
2664         size_t tmp_items = 0;
2665         size_t items = 0;
2666
2667         /* add world animation channels */
2668         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_WOR_SCED(wo))
2669         {
2670                 /* animation data filtering */
2671                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)wo, filter_mode);
2672
2673                 /* nodes */
2674                 if ((wo->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE))
2675                         tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)wo, wo->nodetree, filter_mode);
2676         }
2677         END_ANIMFILTER_SUBCHANNELS;
2678
2679         /* did we find anything? */
2680         if (tmp_items) {
2681                 /* include data-expand widget first */
2682                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2683                         /* check if filtering by active status */
2684                         if (ANIMCHANNEL_ACTIVEOK(wo)) {
2685                                 ANIMCHANNEL_NEW_CHANNEL(wo, ANIMTYPE_DSWOR, sce, NULL);
2686                         }
2687                 }
2688
2689                 /* now add the list of collected channels */
2690                 BLI_movelisttolist(anim_data, &tmp_data);
2691                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2692                 items += tmp_items;
2693         }
2694
2695         /* return the number of items added to the list */
2696         return items;
2697 }
2698
2699 static size_t animdata_filter_ds_scene(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
2700 {
2701         ListBase tmp_data = {NULL, NULL};
2702         size_t tmp_items = 0;
2703         size_t items = 0;
2704
2705         AnimData *adt = sce->adt;
2706         short type = 0, expanded = 1;
2707         void *cdata = NULL;
2708
2709         /* determine the type of expander channels to use */
2710         // this is the best way to do this for now...
2711         ANIMDATA_FILTER_CASES(sce,
2712                 { /* AnimData - no channel, but consider data */},
2713                 { /* NLA - no channel, but consider data */},
2714                 { /* Drivers */
2715                         type = ANIMTYPE_FILLDRIVERS;
2716                         cdata = adt;
2717                         expanded = EXPANDED_DRVD(adt);
2718                 },
2719                 { /* NLA Strip Controls - no dedicated channel for now (XXX) */ },
2720                 { /* Keyframes */
2721                         type = ANIMTYPE_FILLACTD;
2722                         cdata = adt->action;
2723                         expanded = EXPANDED_ACTC(adt->action);
2724                 });
2725
2726         /* add scene-level animation channels */
2727         BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
2728         {
2729                 /* animation data filtering */
2730                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)sce, filter_mode);
2731         }
2732         END_ANIMFILTER_SUBCHANNELS;
2733
2734         /* did we find anything? */
2735         if (tmp_items) {
2736                 /* include anim-expand widget first */
2737                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2738                         if (type != ANIMTYPE_NONE) {
2739                                 /* NOTE: active-status (and the associated checks) don't apply here... */
2740                                 ANIMCHANNEL_NEW_CHANNEL(cdata, type, sce, NULL);
2741                         }
2742                 }
2743
2744                 /* now add the list of collected channels */
2745                 BLI_movelisttolist(anim_data, &tmp_data);
2746                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2747                 items += tmp_items;
2748         }
2749
2750         /* return the number of items added to the list */
2751         return items;
2752 }
2753
2754 static size_t animdata_filter_dopesheet_scene(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
2755 {
2756         ListBase tmp_data = {NULL, NULL};
2757         size_t tmp_items = 0;
2758         size_t items = 0;
2759
2760         /* filter data contained under object first */
2761         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_SCEC(sce))
2762         {
2763                 bNodeTree *ntree = sce->nodetree;
2764                 bGPdata *gpd = sce->gpd;
2765                 World *wo = sce->world;
2766
2767                 /* Action, Drivers, or NLA for Scene */
2768                 if ((ads->filterflag & ADS_FILTER_NOSCE) == 0) {
2769                         tmp_items += animdata_filter_ds_scene(ac, &tmp_data, ads, sce, filter_mode);
2770                 }
2771
2772                 /* world */
2773                 if ((wo) && !(ads->filterflag & ADS_FILTER_NOWOR)) {
2774                         tmp_items += animdata_filter_ds_world(ac, &tmp_data, ads, sce, wo, filter_mode);
2775                 }
2776
2777                 /* nodetree */
2778                 if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
2779                         tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)sce, ntree, filter_mode);
2780                 }
2781
2782                 /* line styles */
2783                 if ((ads->filterflag & ADS_FILTER_NOLINESTYLE) == 0) {
2784                         tmp_items += animdata_filter_ds_linestyle(ac, &tmp_data, ads, sce, filter_mode);
2785                 }
2786
2787                 /* grease pencil */
2788                 if ((gpd) && !(ads->filterflag & ADS_FILTER_NOGPENCIL)) {
2789                         tmp_items += animdata_filter_ds_gpencil(ac, &tmp_data, ads, gpd, filter_mode);
2790                 }
2791
2792                 /* TODO: one day, when sequencer becomes its own datatype, perhaps it should be included here */
2793         }
2794         END_ANIMFILTER_SUBCHANNELS;
2795
2796         /* if we collected some channels, add these to the new list... */
2797         if (tmp_items) {
2798                 /* firstly add object expander if required */
2799                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2800                         /* check if filtering by selection */
2801                         if (ANIMCHANNEL_SELOK((sce->flag & SCE_DS_SELECTED))) {
2802                                 /* NOTE: active-status doesn't matter for this! */
2803                                 ANIMCHANNEL_NEW_CHANNEL(sce, ANIMTYPE_SCENE, sce, NULL);
2804                         }
2805                 }
2806
2807                 /* now add the list of collected channels */
2808                 BLI_movelisttolist(anim_data, &tmp_data);
2809                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2810                 items += tmp_items;
2811         }
2812
2813         /* return the number of items added */
2814         return items;
2815 }
2816
2817 static size_t animdata_filter_ds_movieclip(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, MovieClip *clip, int filter_mode)
2818 {
2819         ListBase tmp_data = {NULL, NULL};
2820         size_t tmp_items = 0;
2821         size_t items = 0;
2822         /* add world animation channels */
2823         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_MCLIP(clip))
2824         {
2825                 /* animation data filtering */
2826                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)clip, filter_mode);
2827         }
2828         END_ANIMFILTER_SUBCHANNELS;
2829         /* did we find anything? */
2830         if (tmp_items) {
2831                 /* include data-expand widget first */
2832                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2833                         /* check if filtering by active status */
2834                         if (ANIMCHANNEL_ACTIVEOK(clip)) {
2835                                 ANIMCHANNEL_NEW_CHANNEL(clip, ANIMTYPE_DSMCLIP, clip, NULL);
2836                         }
2837                 }
2838                 /* now add the list of collected channels */
2839                 BLI_movelisttolist(anim_data, &tmp_data);
2840                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2841                 items += tmp_items;
2842         }
2843         /* return the number of items added to the list */
2844         return items;
2845 }
2846
2847 static size_t animdata_filter_dopesheet_movieclips(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, int filter_mode)
2848 {
2849         size_t items = 0;
2850         MovieClip *clip;
2851         for (clip = ac->bmain->movieclip.first; clip != NULL; clip = clip->id.next) {
2852                 /* only show if gpd is used by something... */
2853                 if (ID_REAL_USERS(clip) < 1) {
2854                         continue;
2855                 }
2856                 items += animdata_filter_ds_movieclip(ac, anim_data, ads, clip, filter_mode);
2857         }
2858         /* return the number of items added to the list */
2859         return items;
2860 }
2861
2862 /* Helper for animdata_filter_dopesheet() - For checking if an object should be included or not */
2863 static bool animdata_filter_base_is_ok(bDopeSheet *ads, Base *base, int filter_mode)
2864 {
2865         Object *ob = base->object;
2866
2867         if (base->object == NULL)
2868                 return false;
2869
2870         /* firstly, check if object can be included, by the following factors:
2871          * - if only visible, must check for layer and also viewport visibility
2872          *   --> while tools may demand only visible, user setting takes priority
2873          *       as user option controls whether sets of channels get included while
2874          *       tool-flag takes into account collapsed/open channels too
2875          * - if only selected, must check if object is selected
2876          * - there must be animation data to edit (this is done recursively as we
2877          *   try to add the channels)
2878          */
2879         if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
2880                 /* layer visibility - we check both object and base, since these may not be in sync yet */
2881                 if ((base->flag & BASE_VISIBLE) == 0)
2882                         return false;
2883
2884                 /* outliner restrict-flag */
2885                 if (ob->restrictflag & OB_RESTRICT_VIEW)
2886                         return false;
2887         }
2888
2889         /* if only F-Curves with visible flags set can be shown, check that
2890          * datablock hasn't been set to invisible
2891          */
2892         if (filter_mode & ANIMFILTER_CURVE_VISIBLE) {
2893                 if ((ob->adt) && (ob->adt->flag & ADT_CURVES_NOT_VISIBLE))
2894                         return false;
2895         }
2896
2897         /* Pinned curves are visible regardless of selection flags. */
2898         if ((ob->adt) && (ob->adt->flag & ADT_CURVES_ALWAYS_VISIBLE)) {
2899                 return true;
2900         }
2901
2902         /* Special case.
2903          * We don't do recursive checks for pin, but we need to deal with tricky
2904          * setup like animated camera lens without animated camera location.
2905          * Without such special handle here we wouldn't be able to bin such
2906          * camera data only animation to the editor.
2907          */
2908         if (ob->adt == NULL && ob->data != NULL) {
2909                 AnimData *data_adt = BKE_animdata_from_id(ob->data);
2910                 if (data_adt != NULL && (data_adt->flag & ADT_CURVES_ALWAYS_VISIBLE)) {
2911                         return true;
2912                 }
2913         }
2914
2915         /* check selection and object type filters */
2916         if ((ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & BASE_SELECTED) /*|| (base == sce->basact)*/)) {
2917                 /* only selected should be shown */
2918                 return false;
2919         }
2920
2921         /* check if object belongs to the filtering group if option to filter
2922          * objects by the grouped status is on
2923          * - used to ease the process of doing multiple-character choreographies
2924          */
2925         if (ads->filter_grp != NULL) {
2926                 if (BKE_collection_has_object_recursive(ads->filter_grp, ob) == 0)
2927                         return false;
2928         }
2929
2930         /* no reason to exclude this object... */
2931         return true;
2932 }
2933