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