From f98c3ed70b86d12945078c288c2bd3288a297841 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Mon, 6 Jul 2009 12:24:09 +0000 Subject: NLA SoC: Fixes for Meta-Strips and Editing * Split strip (YKEY) now plays nicely with Transitions and Metas. Meta strips get split up into their child strips, while transitions are ignored. * Wrapped Meta_Strip->strips in RNA * Bugfixes in Meta-strip API functions to silence some runtime-errors... --- source/blender/blenkernel/BKE_nla.h | 1 + source/blender/blenkernel/intern/nla.c | 39 ++++++++---- source/blender/editors/space_nla/nla_edit.c | 96 +++++++++++++++++++---------- source/blender/makesrna/intern/rna_nla.c | 7 ++- 4 files changed, 95 insertions(+), 48 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_nla.h b/source/blender/blenkernel/BKE_nla.h index 3fcd799310e..5cb967c9c59 100644 --- a/source/blender/blenkernel/BKE_nla.h +++ b/source/blender/blenkernel/BKE_nla.h @@ -61,6 +61,7 @@ short BKE_nlastrips_add_strip(ListBase *strips, struct NlaStrip *strip); void BKE_nlastrips_make_metas(ListBase *strips, short temp); void BKE_nlastrips_clear_metas(ListBase *strips, short onlySel, short onlyTemp); +void BKE_nlastrips_clear_metastrip(ListBase *strips, struct NlaStrip *strip); short BKE_nlameta_add_strip(struct NlaStrip *mstrip, struct NlaStrip *strip); void BKE_nlameta_flush_transforms(struct NlaStrip *mstrip); diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 715f99c820f..a83fa0abe1e 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -650,6 +650,9 @@ void BKE_nlastrips_make_metas (ListBase *strips, short temp) /* set temp flag if appropriate (i.e. for transform-type editing) */ if (temp) mstrip->flag |= NLASTRIP_FLAG_TEMP_META; + + /* set default repeat/scale values to prevent warnings */ + mstrip->repeat= mstrip->scale= 1.0f; /* make its start frame be set to the start frame of the current strip */ mstrip->start= strip->start; @@ -671,6 +674,28 @@ void BKE_nlastrips_make_metas (ListBase *strips, short temp) } } +/* Split a meta-strip into a set of normal strips */ +void BKE_nlastrips_clear_metastrip (ListBase *strips, NlaStrip *strip) +{ + NlaStrip *cs, *csn; + + /* sanity check */ + if ELEM(NULL, strips, strip) + return; + + /* move each one of the meta-strip's children before the meta-strip + * in the list of strips after unlinking them from the meta-strip + */ + for (cs= strip->strips.first; cs; cs= csn) { + csn= cs->next; + BLI_remlink(&strip->strips, cs); + BLI_insertlinkbefore(strips, strip, cs); + } + + /* free the meta-strip now */ + BLI_freelinkN(strips, strip); +} + /* Remove meta-strips (i.e. flatten the list of strips) from the top-level of the list of strips * sel: only consider selected meta-strips, otherwise all meta-strips are removed * onlyTemp: only remove the 'temporary' meta-strips used for transforms @@ -692,19 +717,7 @@ void BKE_nlastrips_clear_metas (ListBase *strips, short onlySel, short onlyTemp) /* if check if selection and 'temporary-only' considerations are met */ if ((onlySel==0) || (strip->flag & NLASTRIP_FLAG_SELECT)) { if ((!onlyTemp) || (strip->flag & NLASTRIP_FLAG_TEMP_META)) { - NlaStrip *cs, *csn; - - /* move each one of the meta-strip's children before the meta-strip - * in the list of strips after unlinking them from the meta-strip - */ - for (cs= strip->strips.first; cs; cs= csn) { - csn= cs->next; - BLI_remlink(&strip->strips, cs); - BLI_insertlinkbefore(strips, strip, cs); - } - - /* free the meta-strip now */ - BLI_freelinkN(strips, strip); + BKE_nlastrips_clear_metastrip(strips, strip); } } } diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index f7d4db17e2c..676d0aac1b1 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -736,6 +736,55 @@ void NLA_OT_delete (wmOperatorType *ot) // - multiple splits // - variable-length splits? +/* split a given Action-Clip strip */ +static void nlaedit_split_strip_actclip (NlaTrack *nlt, NlaStrip *strip) +{ + NlaStrip *nstrip; + float midframe, midaframe, len; + + /* calculate the frames to do the splitting at */ + /* strip extents */ + len= strip->end - strip->start; + if (IS_EQ(len, 0.0f)) + return; + else + midframe= strip->start + (len / 2.0f); + + /* action range */ + len= strip->actend - strip->actstart; + if (IS_EQ(len, 0.0f)) + midaframe= strip->actend; + else + midaframe= strip->actstart + (len / 2.0f); + + /* make a copy (assume that this is possible) and append + * it immediately after the current strip + */ + nstrip= copy_nlastrip(strip); + BLI_insertlinkafter(&nlt->strips, strip, nstrip); + + /* set the endpoint of the first strip and the start of the new strip + * to the midframe values calculated above + */ + strip->end= midframe; + nstrip->start= midframe; + + strip->actend= midaframe; + nstrip->actstart= midaframe; + + /* clear the active flag from the copy */ + nstrip->flag &= ~NLASTRIP_FLAG_ACTIVE; +} + +/* split a given Meta strip */ +static void nlaedit_split_strip_meta (NlaTrack *nlt, NlaStrip *strip) +{ + /* simply ungroup it for now... */ + BKE_nlastrips_clear_metastrip(&nlt->strips, strip); +} + +/* ----- */ + static int nlaedit_split_exec (bContext *C, wmOperator *op) { bAnimContext ac; @@ -755,47 +804,26 @@ static int nlaedit_split_exec (bContext *C, wmOperator *op) /* for each NLA-Track, split all selected strips into two strips */ for (ale= anim_data.first; ale; ale= ale->next) { NlaTrack *nlt= (NlaTrack *)ale->data; - NlaStrip *strip, *nstrip, *next; + NlaStrip *strip, *next; for (strip= nlt->strips.first; strip; strip= next) { next= strip->next; /* if selected, split the strip at its midpoint */ if (strip->flag & NLASTRIP_FLAG_SELECT) { - float midframe, midaframe, len; - - /* calculate the frames to do the splitting at */ - /* strip extents */ - len= strip->end - strip->start; - if (IS_EQ(len, 0.0f)) - continue; - else - midframe= strip->start + (len / 2.0f); + /* splitting method depends on the type of strip */ + switch (strip->type) { + case NLASTRIP_TYPE_CLIP: /* action-clip */ + nlaedit_split_strip_actclip(nlt, strip); + break; + + case NLASTRIP_TYPE_META: /* meta-strips need special handling */ + nlaedit_split_strip_meta(nlt, strip); + break; - /* action range */ - len= strip->actend - strip->actstart; - if (IS_EQ(len, 0.0f)) - midaframe= strip->actend; - else - midaframe= strip->actstart + (len / 2.0f); - - /* make a copy (assume that this is possible) and append - * it immediately after the current strip - */ - nstrip= copy_nlastrip(strip); - BLI_insertlinkafter(&nlt->strips, strip, nstrip); - - /* set the endpoint of the first strip and the start of the new strip - * to the midframe values calculated above - */ - strip->end= midframe; - nstrip->start= midframe; - - strip->actend= midaframe; - nstrip->actstart= midaframe; - - /* clear the active flag from the copy */ - nstrip->flag &= ~NLASTRIP_FLAG_ACTIVE; + default: /* for things like Transitions, do not split! */ + break; + } } } } diff --git a/source/blender/makesrna/intern/rna_nla.c b/source/blender/makesrna/intern/rna_nla.c index 28a422dd601..dae1a611757 100644 --- a/source/blender/makesrna/intern/rna_nla.c +++ b/source/blender/makesrna/intern/rna_nla.c @@ -207,7 +207,7 @@ void rna_def_nlastrip(BlenderRNA *brna) static EnumPropertyItem prop_type_items[] = { {NLASTRIP_TYPE_CLIP, "CLIP", 0, "Action Clip", "NLA Strip references some Action."}, {NLASTRIP_TYPE_TRANSITION, "TRANSITION", 0, "Transition", "NLA Strip 'transitions' between adjacent strips."}, - {NLASTRIP_TYPE_META, "META", 0, "Strip Container", "NLA Strip acts as a container for adjacent strips."}, + {NLASTRIP_TYPE_META, "META", 0, "Meta", "NLA Strip acts as a container for adjacent strips."}, {0, NULL, 0, NULL, NULL}}; static EnumPropertyItem prop_mode_blend_items[] = { {NLASTRIP_MODE_BLEND, "BLEND", 0, "Blend", "Results of strip and accumulated results are combined in ratio governed by influence."}, @@ -308,6 +308,11 @@ void rna_def_nlastrip(BlenderRNA *brna) RNA_def_property_struct_type(prop, "FModifier"); RNA_def_property_ui_text(prop, "Modifiers", "Modifiers affecting all the F-Curves in the referenced Action."); + /* Strip's Sub-Strips (for Meta-Strips) */ + prop= RNA_def_property(srna, "strips", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "NlaStrip"); + RNA_def_property_ui_text(prop, "NLA Strips", "NLA Strips that this strip acts as a container for (if it is of type Meta)."); + /* Settings - Values necessary for evaluation */ prop= RNA_def_property(srna, "influence", PROP_FLOAT, PROP_NONE); RNA_def_property_range(prop, 0.0f, 1.0f); -- cgit v1.2.3