Mercurial > hg > dmlib
changeset 395:530db8fa4569
Implement functions for copying timelines and timeline components.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 19 Oct 2012 07:21:39 +0300 |
parents | 412082d5babc |
children | 1712cc35e9a1 |
files | dmengine.h dmtimelinew.c |
diffstat | 2 files changed, 119 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/dmengine.h Fri Oct 19 05:50:44 2012 +0300 +++ b/dmengine.h Fri Oct 19 07:21:39 2012 +0300 @@ -259,6 +259,13 @@ // Editing/saving related functions +int dmCopyTimelinePoints(const DMTimelinePoints *src, DMTimelinePoints *dst); +int dmCopyTimelineEventParam(const DMTimelineEventParam *src, DMTimelineEventParam *dst); +int dmCopyTimelineEvent(const DMTimelineEvent *src, DMTimelineEvent **pdst); +int dmCopyTimelineCurve(const DMTimelineCurve *src, DMTimelineCurve *dst); +int dmCopyTimelineTrack(const DMTimelineTrack *src, DMTimelineTrack **pdst); +int dmCopyTimeline(const DMTimeline *src, DMTimeline **pdst); + int dmSaveTimeline(DMResource *res, DMTimeline *tl); int dmTimelineNew(DMTimeline **tl, const char *name);
--- a/dmtimelinew.c Fri Oct 19 05:50:44 2012 +0300 +++ b/dmtimelinew.c Fri Oct 19 07:21:39 2012 +0300 @@ -309,3 +309,115 @@ } return NULL; } + + +int dmCopyTimelinePoints(const DMTimelinePoints *src, DMTimelinePoints *dst) +{ + if (src->points == NULL || src->npoints <= 0 || src->nallocated <= 0) + return DMERR_OK; + + dst->npoints = src->npoints; + dst->nallocated = src->nallocated; + dst->points = dmCalloc(src->nallocated, sizeof(DMTimelinePoint)); + if (dst->points == NULL) + return DMERR_MALLOC; + + memcpy(dst->points, src->points, sizeof(DMTimelinePoint) * src->npoints); + + return DMERR_OK; +} + + +int dmCopyTimelineEventParam(const DMTimelineEventParam *src, DMTimelineEventParam *dst) +{ + dst->name = dm_strdup(src->name); + dst->type = src->type; + dst->vstr = dm_strdup(src->vstr); + + return dmCopyTimelinePoints(&src->pts, &dst->pts); +} + + +int dmCopyTimelineEvent(const DMTimelineEvent *src, DMTimelineEvent **pdst) +{ + int param; + DMTimelineEvent *dst; + if ((*pdst = dst = dmMalloc0(sizeof(DMTimelineEvent))) == NULL) + return DMERR_MALLOC; + + dst->start = src->start; + dst->duration = src->duration; + dst->nparams = src->nparams; + dst->effect = src->effect; + dst->params = dmCalloc(src->nparams, sizeof(DMTimelineEventParam)); + if (dst->params == NULL) + return DMERR_MALLOC; + + for (param = 0; param < src->nparams; param++) + { + int err; + if ((err = dmCopyTimelineEventParam(&(src->params[param]), &(dst->params[param]))) != DMERR_OK) + return err; + } + + return DMERR_OK; +} + + +int dmCopyTimelineCurve(const DMTimelineCurve *src, DMTimelineCurve *dst) +{ + dst->enabled = src->enabled; + return dmCopyTimelinePoints(&(src->points), &(dst->points)); +} + + +int dmCopyTimelineTrack(const DMTimelineTrack *src, DMTimelineTrack **pdst) +{ + int event, err; + DMTimelineTrack *dst; + if ((*pdst = dst = dmMalloc0(sizeof(DMTimelineTrack))) == NULL) + return DMERR_MALLOC; + + if ((dst->events = dmCalloc(src->nevents, sizeof(DMTimelineEvent *))) == NULL) + return DMERR_MALLOC; + + dst->name = dm_strdup(src->name); + dst->enabled = src->enabled; + dst->nevents = src->nevents; + + for (event = 0; event < src->nevents; event++) + { + if ((err = dmCopyTimelineEvent(src->events[event], &(dst->events[event]))) != DMERR_OK) + return err; + } + + if ((err = dmCopyTimelineCurve(&(src->composite), &(dst->composite))) != DMERR_OK) + return err; + + return DMERR_OK; +} + + +int dmCopyTimeline(const DMTimeline *src, DMTimeline **pdst) +{ + int track, err; + DMTimeline *dst; + if ((*pdst = dst = dmMalloc0(sizeof(DMTimeline))) == NULL) + return DMERR_MALLOC; + + dst->tracks = (DMTimelineTrack **) dmCalloc(src->ntracks, sizeof(DMTimelineTrack *)); + if (dst->tracks == NULL) + return DMERR_MALLOC; + + dst->name = dm_strdup(src->name); + dst->duration = src->duration; + dst->ntracks = src->ntracks; + + for (track = 0; track < src->ntracks; track++) + { + if ((err = dmCopyTimelineTrack(src->tracks[track], &(dst->tracks[track]))) != DMERR_OK) + return err; + } + + return DMERR_OK; +}