diff options
Diffstat (limited to 'source/blender/editors/space_nla/nla_edit.c')
-rw-r--r-- | source/blender/editors/space_nla/nla_edit.c | 277 |
1 files changed, 250 insertions, 27 deletions
diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index af99087b0b8..0f87be0f807 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -1,6 +1,4 @@ /* - * $Id$ - * * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or @@ -36,6 +34,7 @@ #include <math.h> #include "DNA_anim_types.h" +#include "DNA_object_types.h" #include "DNA_scene_types.h" #include "MEM_guardedalloc.h" @@ -68,6 +67,7 @@ #include "UI_interface.h" #include "UI_resources.h" +#include "UI_view2d.h" #include "nla_intern.h" // own include #include "nla_private.h" // FIXME... maybe this shouldn't be included? @@ -80,7 +80,7 @@ void ED_nla_postop_refresh (bAnimContext *ac) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; - short filter= (ANIMFILTER_VISIBLE | ANIMFILTER_ANIMDATA | ANIMFILTER_FOREDIT); + short filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ANIMDATA | ANIMFILTER_FOREDIT); /* get blocks to work on */ ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); @@ -116,7 +116,7 @@ static int nlaedit_enable_tweakmode_exec (bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* get a list of the AnimData blocks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_ANIMDATA); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ANIMDATA); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* if no blocks, popup error? */ @@ -185,7 +185,7 @@ static int nlaedit_disable_tweakmode_exec (bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* get a list of the AnimData blocks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_ANIMDATA); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ANIMDATA); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* if no blocks, popup error? */ @@ -236,6 +236,136 @@ void NLA_OT_tweakmode_exit (wmOperatorType *ot) } /* *********************************************** */ +/* NLA Strips Range Stuff */ + +/* *************************** Calculate Range ************************** */ + +/* Get the min/max strip extents */ +static void get_nlastrip_extents (bAnimContext *ac, float *min, float *max, const short onlySel) +{ + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + + /* get data to filter */ + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_NODUPLIS); + ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); + + /* set large values to try to override */ + *min= 999999999.0f; + *max= -999999999.0f; + + /* check if any channels to set range with */ + if (anim_data.first) { + /* go through channels, finding max extents */ + for (ale= anim_data.first; ale; ale= ale->next) { + NlaTrack *nlt = (NlaTrack *)ale->data; + NlaStrip *strip; + + for (strip = nlt->strips.first; strip; strip = strip->next) { + /* only consider selected strips? */ + if ((onlySel == 0) || (strip->flag & NLASTRIP_FLAG_SELECT)) { + /* extend range if appropriate */ + *min = MIN2(*min, strip->start); + *max = MAX2(*max, strip->end); + } + } + } + + /* free memory */ + BLI_freelistN(&anim_data); + } + else { + /* set default range */ + if (ac->scene) { + *min= (float)ac->scene->r.sfra; + *max= (float)ac->scene->r.efra; + } + else { + *min= -5; + *max= 100; + } + } +} + +/* ****************** View-All Operator ****************** */ + +static int nlaedit_viewall(bContext *C, const short onlySel) +{ + bAnimContext ac; + View2D *v2d; + float extra; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + v2d= &ac.ar->v2d; + + /* set the horizontal range, with an extra offset so that the extreme keys will be in view */ + get_nlastrip_extents(&ac, &v2d->cur.xmin, &v2d->cur.xmax, onlySel); + + extra= 0.1f * (v2d->cur.xmax - v2d->cur.xmin); + v2d->cur.xmin -= extra; + v2d->cur.xmax += extra; + + /* set vertical range */ + v2d->cur.ymax= 0.0f; + v2d->cur.ymin= (float)-(v2d->mask.ymax - v2d->mask.ymin); + + /* do View2D syncing */ + UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); + + /* just redraw this view */ + ED_area_tag_redraw(CTX_wm_area(C)); + + return OPERATOR_FINISHED; +} + +/* ......... */ + +static int nlaedit_viewall_exec(bContext *C, wmOperator *UNUSED(op)) +{ + /* whole range */ + return nlaedit_viewall(C, FALSE); +} + +static int nlaedit_viewsel_exec(bContext *C, wmOperator *UNUSED(op)) +{ + /* only selected */ + return nlaedit_viewall(C, TRUE); +} + +void NLA_OT_view_all (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "View All"; + ot->idname= "NLA_OT_view_all"; + ot->description= "Reset viewable area to show full strips range"; + + /* api callbacks */ + ot->exec= nlaedit_viewall_exec; + ot->poll= ED_operator_nla_active; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +void NLA_OT_view_selected (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "View Selected"; + ot->idname= "NLA_OT_view_selected"; + ot->description= "Reset viewable area to show selected strips range"; + + /* api callbacks */ + ot->exec= nlaedit_viewsel_exec; + ot->poll= ED_operator_nla_active; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/* *********************************************** */ /* NLA Editing Operations (Constructive/Destructive) */ /* ******************** Add Action-Clip Operator ***************************** */ @@ -250,7 +380,8 @@ static int nlaedit_add_actionclip_exec (bContext *C, wmOperator *op) ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; - int filter, items; + size_t items; + int filter; bAction *act; @@ -281,7 +412,7 @@ static int nlaedit_add_actionclip_exec (bContext *C, wmOperator *op) /* get a list of the editable tracks being shown in the NLA * - this is limited to active ones for now, but could be expanded to */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_ACTIVE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ACTIVE | ANIMFILTER_FOREDIT); items= ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); if (items == 0) { @@ -379,7 +510,7 @@ static int nlaedit_add_transition_exec (bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* for each track, find pairs of strips to add transitions to */ @@ -404,12 +535,15 @@ static int nlaedit_add_transition_exec (bContext *C, wmOperator *op) /* check if there's space between the two */ if (IS_EQ(s1->end, s2->start)) continue; - /* make neither one is a transition + /* make sure neither one is a transition * - although this is impossible to create with the standard tools, * the user may have altered the settings */ if (ELEM(NLASTRIP_TYPE_TRANSITION, s1->type, s2->type)) continue; + /* also make sure neither one is a soundclip */ + if (ELEM(NLASTRIP_TYPE_SOUND, s1->type, s2->type)) + continue; /* allocate new strip */ strip= MEM_callocN(sizeof(NlaStrip), "NlaStrip"); @@ -476,6 +610,91 @@ void NLA_OT_transition_add (wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +/* ******************** Add Sound Clip Operator ***************************** */ +/* Add a new sound clip */ + +static int nlaedit_add_sound_exec (bContext *C, wmOperator *op) +{ + bAnimContext ac; + + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + + Scene *scene; + int cfra; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + + scene = ac.scene; + cfra = CFRA; + + /* get a list of the editable tracks being shown in the NLA */ + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_FOREDIT); + ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + + /* for each track, add sound clips if it belongs to a speaker */ + // TODO: what happens if there aren't any tracks... well that's a more general problem for later + for (ale= anim_data.first; ale; ale= ale->next) { + Object *ob = (Object *)ale->id; /* may not be object until we actually check! */ + + AnimData *adt = ale->adt; + NlaTrack *nlt= (NlaTrack *)ale->data; + NlaStrip *strip; + + /* does this belong to speaker - assumed to live on Object level only */ + if ((GS(ale->id->name) != ID_OB) || (ob->type != OB_SPEAKER)) + continue; + + /* create a new strip, and offset it to start on the current frame */ + strip= add_nla_soundstrip(ac.scene, ob->data); + + strip->start += cfra; + strip->end += cfra; + + /* firstly try adding strip to our current track, but if that fails, add to a new track */ + if (BKE_nlatrack_add_strip(nlt, strip) == 0) { + /* trying to add to the current failed (no space), + * so add a new track to the stack, and add to that... + */ + nlt= add_nlatrack(adt, NULL); + BKE_nlatrack_add_strip(nlt, strip); + } + + /* auto-name it */ + BKE_nlastrip_validate_name(adt, strip); + } + + /* free temp data */ + BLI_freelistN(&anim_data); + + /* refresh auto strip properties */ + ED_nla_postop_refresh(&ac); + + /* set notifier that things have changed */ + WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_EDITED, NULL); + + /* done */ + return OPERATOR_FINISHED; +} + +void NLA_OT_soundclip_add (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add Sound Clip"; + ot->idname= "NLA_OT_soundclip_add"; + ot->description= "Add a strip for controlling when speaker plays its sound clip"; + + /* api callbacks */ + ot->exec= nlaedit_add_sound_exec; + ot->poll= nlaop_poll_tweakmode_off; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + /* ******************** Add Meta-Strip Operator ***************************** */ /* Add new meta-strips incorporating the selected strips */ @@ -493,7 +712,7 @@ static int nlaedit_add_meta_exec (bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* for each track, find pairs of strips to add transitions to */ @@ -554,7 +773,7 @@ static int nlaedit_remove_meta_exec (bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* for each track, find pairs of strips to add transitions to */ @@ -610,7 +829,7 @@ static int nlaedit_duplicate_exec (bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; /* get a list of editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* duplicate strips in tracks starting from the last one so that we're @@ -713,7 +932,7 @@ static int nlaedit_delete_exec (bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* for each NLA-Track, delete all selected strips */ @@ -854,7 +1073,7 @@ static int nlaedit_split_exec (bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; /* get a list of editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* for each NLA-Track, split all selected strips into two strips */ @@ -930,7 +1149,7 @@ static int nlaedit_bake_exec (bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_ANIMDATA | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_ANIMDATA | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* for each AnimData block, bake strips to animdata... */ @@ -985,7 +1204,7 @@ static int nlaedit_toggle_mute_exec (bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* go over all selected strips */ @@ -1044,7 +1263,7 @@ static int nlaedit_swap_exec (bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* consider each track in turn */ @@ -1202,7 +1421,7 @@ static int nlaedit_move_up_exec (bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* since we're potentially moving strips from lower tracks to higher tracks, we should @@ -1276,7 +1495,7 @@ static int nlaedit_move_down_exec (bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* loop through the tracks in normal order, since we're pushing strips down, @@ -1351,7 +1570,7 @@ static int nlaedit_sync_actlen_exec (bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); if (active_only) filter |= ANIMFILTER_ACTIVE; ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); @@ -1446,7 +1665,7 @@ static int nlaedit_apply_scale_exec (bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* init the editing data */ @@ -1473,7 +1692,7 @@ static int nlaedit_apply_scale_exec (bContext *C, wmOperator *UNUSED(op)) /* setup iterator, and iterate over all the keyframes in the action, applying this scaling */ ked.data= strip; - ANIM_animchanneldata_keyframes_loop(&ked, strip->act, ALE_ACT, NULL, bezt_apply_nlamapping, calchandles_fcurve, 0); + ANIM_animchanneldata_keyframes_loop(&ked, ac.ads, strip->act, ALE_ACT, NULL, bezt_apply_nlamapping, calchandles_fcurve); /* clear scale of strip now that it has been applied, * and recalculate the extents of the action now that it has been scaled @@ -1526,7 +1745,7 @@ static int nlaedit_clear_scale_exec (bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* for each NLA-Track, reset scale of all selected strips */ @@ -1602,7 +1821,7 @@ static int nlaedit_snap_exec (bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* get some necessary vars */ @@ -1770,7 +1989,7 @@ static int nla_fmodifier_add_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* for each NLA-Track, add the specified modifier to all selected strips */ @@ -1791,6 +2010,10 @@ static int nla_fmodifier_add_exec(bContext *C, wmOperator *op) continue; } + /* sound clips are not affected by FModifiers */ + if (strip->type == NLASTRIP_TYPE_SOUND) + continue; + /* add F-Modifier of specified type to selected, and make it the active one */ fcm= add_fmodifier(&strip->modifiers, type); @@ -1851,7 +2074,7 @@ static int nla_fmodifier_copy_exec(bContext *C, wmOperator *op) free_fmodifiers_copybuf(); /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* for each NLA-Track, add the specified modifier to all selected strips */ @@ -1910,7 +2133,7 @@ static int nla_fmodifier_paste_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* get a list of the editable tracks being shown in the NLA */ - filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_SEL | ANIMFILTER_FOREDIT); + filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* for each NLA-Track, add the specified modifier to all selected strips */ |