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