Mercurial > hg > dmlib
annotate dmtimelinew.c @ 327:2964947674d1
More work on the timeline code.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 14 Oct 2012 23:36:06 +0300 |
parents | fc79b57d4646 |
children | dd7b1356d726 |
rev | line source |
---|---|
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 #include "dmtimeline.h" |
327
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
2 #include "dmresw.h" |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
3 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
4 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
5 BOOL dmSaveFloatValue(DMResource *res, DMFloat val) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
6 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
7 char tmp[DT_FLOAT_STORE_SIZE]; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
8 snprintf(tmp, DT_FLOAT_STORE_SIZE, "%f", val); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
9 return (dmf_write_str(res, (Uint8 *) tmp, DT_FLOAT_STORE_SIZE) == DT_FLOAT_STORE_SIZE); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
10 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
11 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
12 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
13 int dmSaveTimelinePoints(DMResource *res, DMTimelinePoints *points) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
14 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
15 int point; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
16 Uint32 npoints; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
17 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
18 // Save number of points |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
19 npoints = points->npoints; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
20 if (!dmf_write_le32(res, npoints)) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
21 return DMERR_FWRITE; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
22 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
23 // Save points |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
24 for (point = 0; point < points->npoints; point++) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
25 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
26 DMTimelinePoint *pt = &(points->points[point]); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
27 Uint32 ptype, ptime; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
28 ptype = pt->type; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
29 ptime = pt->time; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
30 if (!dmf_write_le32(res, ptype) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
31 !dmf_write_le32(res, ptime) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
32 !dmSaveFloatValue(res, pt->value)) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
33 return DMERR_FWRITE; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
34 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
35 return DMERR_OK; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
36 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
37 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
38 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
39 int dmSaveTimelineCurve(DMResource *res, DMTimelineCurve *curve) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
40 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
41 int err; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
42 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
43 dmfputc(curve->enabled, res); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
44 if ((err = dmSaveTimelinePoints(res, &(curve->points))) != DMERR_OK) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
45 return err; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
46 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
47 return DMERR_OK; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
48 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
49 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
50 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
51 int dmSaveTimelineEventParam(DMResource *res, DMTimelineEventParam *param) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
52 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
53 int err; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
54 DMFTimelineEventParam hdr; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
55 Uint16 len; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
56 Uint32 tmp32; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
57 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
58 strncpy(hdr.name, param->name, sizeof(hdr.name)); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
59 hdr.type = param->type; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
60 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
61 if (dmf_write_str(res, (Uint8 *) hdr.name, sizeof(hdr.name)) != sizeof(hdr.name) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
62 !dmf_write_le32(res, hdr.type)) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
63 return DMERR_FWRITE; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
64 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
65 switch (param->type) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
66 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
67 case EFPT_POINTS: |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
68 if ((err = dmSaveTimelinePoints(res, ¶m->vpts)) != DMERR_OK) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
69 return err; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
70 break; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
71 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
72 case EFPT_INT: |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
73 tmp32 = param->vint; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
74 if (!dmf_write_le32(res, tmp32)) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
75 return DMERR_FWRITE; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
76 break; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
77 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
78 case EFPT_FLOAT: |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
79 if (!dmSaveFloatValue(res, param->vfloat)) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
80 return DMERR_FWRITE; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
81 break; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
82 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
83 case EFPT_STRING: |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
84 len = strlen(param->vstr); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
85 if (!dmf_write_le16(res, len)) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
86 return DMERR_FWRITE; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
87 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
88 if (dmf_write_str(res, (Uint8 *) param->vstr, len) != len) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
89 return DMERR_FWRITE; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
90 break; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
91 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
92 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
93 return DMERR_OK; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
94 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
95 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
96 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
97 int dmSaveTimelineEvent(DMResource *res, DMTimelineEvent *event) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
98 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
99 int param, err; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
100 DMFTimelineEvent hdr; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
101 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
102 strncpy(hdr.effectName, event->effect->name, sizeof(hdr.effectName)); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
103 hdr.start = event->start; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
104 hdr.duration = event->duration; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
105 hdr.nparams = event->nparams; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
106 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
107 if (!dmf_write_le32(res, hdr.start) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
108 !dmf_write_le32(res, hdr.duration) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
109 dmf_write_str(res, (Uint8 *) hdr.effectName, sizeof(hdr.effectName)) != sizeof(hdr.effectName) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
110 !dmf_write_le32(res, hdr.nparams)) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
111 return DMERR_FREAD; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
112 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
113 for (param = 0; param < event->nparams; param++) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
114 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
115 if ((err = dmSaveTimelineEventParam(res, &(event->params[param]))) != DMERR_OK) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
116 return err; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
117 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
118 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
119 return DMERR_OK; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
120 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
121 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
122 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
123 int dmSaveTimelineTrack(DMResource *res, DMTimelineTrack *track) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
124 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
125 int event, err; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
126 DMFTimelineTrack hdr; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
127 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
128 strncpy(hdr.name, track->name, sizeof(hdr.name)); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
129 hdr.enabled = track->enabled; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
130 hdr.nevents = track->nevents; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
131 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
132 if (dmf_write_str(res, (Uint8 *) &hdr.name, sizeof(hdr.name)) != sizeof(hdr.name)) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
133 return DMERR_FWRITE; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
134 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
135 dmfputc(hdr.enabled, res); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
136 if (!dmf_write_le32(res, hdr.nevents)) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
137 return DMERR_FWRITE; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
138 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
139 for (event = 0; event < track->nevents; event++) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
140 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
141 if ((err = dmSaveTimelineEvent(res, track->events[event])) != DMERR_OK) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
142 return err; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
143 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
144 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
145 if ((err = dmSaveTimelineCurve(res, &(track->composite))) != DMERR_OK) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
146 return err; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
147 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
148 int track, err; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
149 DMFTimeline hdr; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
150 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
151 memcpy(&hdr.magic, DT_MAGIC_ID, sizeof(hdr.magic)); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
152 strncpy(hdr.name, tl->name, sizeof(hdr.name)); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
153 hdr.ntracks = tl->ntracks; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
154 hdr.duration = tl->duration; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
155 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
156 if (dmf_write_str(res, (Uint8 *) hdr.magic, sizeof(hdr.magic)) != sizeof(hdr.magic) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
157 dmf_write_str(res, (Uint8 *) hdr.name, sizeof(hdr.name)) != sizeof(hdr.name) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
158 !dmf_write_le32(res, hdr.ntracks) || |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
159 !dmf_write_le32(res, hdr.duration)) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
160 return DMERR_FWRITE; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
161 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
162 for (track = 0; track < tl->ntracks; track++) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
163 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
164 if ((err = dmSaveTimelineTrack(res, tl->tracks[track])) != DMERR_OK) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
165 return err; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
166 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
167 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
168 return DMERR_OK; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
169 int dmTimelineNew(DMTimeline **ptl, const char *name) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
170 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
171 DMTimeline *tl; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
172 if ((*ptl = tl = dmMalloc0(sizeof(DMTimeline))) == NULL) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
173 return DMERR_MALLOC; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
174 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
175 tl->name = dm_strdup(name); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
176 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
177 return DMERR_OK; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
178 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
179 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
180 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
181 int dmTimelineAddTrack(DMTimeline *tl, DMTimelineTrack **ptrack, const char *name) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
182 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
183 DMTimelineTrack *track; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
184 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
185 if ((*ptrack = track = dmMalloc0(sizeof(DMTimelineTrack))) == NULL) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
186 return DMERR_MALLOC; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
187 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
188 track->name = dm_strdup(name); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
189 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
190 if (tl->ntracks + 1 >= tl->nallocated) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
191 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
192 tl->nallocated += 16; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
193 tl->tracks = dmRealloc(tl->tracks, sizeof(DMTimelineTrack *) * tl->nallocated); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
194 if (tl->tracks == NULL) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
195 return DMERR_MALLOC; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
196 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
197 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
198 tl->tracks[tl->ntracks] = track; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
199 tl->ntracks++; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
200 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
201 return DMERR_OK; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
202 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
203 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
204 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
205 int dmTimelineTrackAddEvent(DMTimelineTrack *track, int start, int duration, DMTimelineEvent **pev) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
206 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
207 DMTimelineEvent *ev; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
208 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
209 if ((*pev = ev = dmMalloc0(sizeof(DMTimelineEvent))) == NULL) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
210 return DMERR_MALLOC; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
211 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
212 ev->start = start; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
213 ev->duration = duration; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
214 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
215 if (track->nevents + 1 >= track->nallocated) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
216 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
217 track->nallocated += 16; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
218 track->events = dmRealloc(track->events, sizeof(DMTimelineEvent *) * track->nallocated); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
219 if (track->events == NULL) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
220 return DMERR_MALLOC; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
221 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
222 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
223 track->events[track->nevents] = ev; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
224 track->nevents++; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
225 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
226 return DMERR_OK; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
227 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
228 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
229 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
230 int dmTimelineEventSetEffect(DMTimelineEvent *event, const char *name) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
231 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
232 int param; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
233 DMEffect *ef; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
234 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
235 if ((ef = dmFindEffectByName(name)) == NULL) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
236 return DMERR_INVALID_DATA; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
237 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
238 event->effect = ef; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
239 event->nparams = ef->nparams; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
240 event->params = dmCalloc(ef->nparams, sizeof(DMTimelineEventParam)); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
241 if (event->params == NULL) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
242 return DMERR_MALLOC; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
243 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
244 for (param = 0; param < ef->nparams; param++) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
245 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
246 DMTimelineEventParam *psrc = &ef->params[param], |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
247 *pdst = &event->params[param]; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
248 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
249 pdst->name = dm_strdup(psrc->name); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
250 pdst->type = psrc->type; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
251 pdst->vstr = dm_strdup(psrc->vstr); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
252 pdst->vint = psrc->vint; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
253 pdst->vfloat = psrc->vfloat; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
254 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
255 if (psrc->vpts.points != NULL && psrc->vpts.npoints > 0) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
256 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
257 pdst->vpts.npoints = psrc->vpts.npoints; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
258 pdst->vpts.nallocated = psrc->vpts.nallocated; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
259 pdst->vpts.points = dmMalloc(psrc->vpts.nallocated * sizeof(DMTimelinePoint)); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
260 if (pdst->vpts.points == NULL) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
261 return DMERR_MALLOC; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
262 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
263 memcpy(pdst->vpts.points, psrc->vpts.points, pdst->vpts.npoints * sizeof(DMTimelinePoint)); |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
264 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
265 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
266 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
267 return DMERR_OK; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
268 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
269 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
270 |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
271 DMTimelineEvent *dmTimelineGetEventAt(DMTimelineTrack *track, const int time) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
272 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
273 int event; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
274 for (event = 0; event < track->nevents; event++) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
275 { |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
276 DMTimelineEvent *ev = track->events[event]; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
277 if (time >= ev->start && time <= ev->start + ev->duration) |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
278 return ev; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
279 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
280 return NULL; |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
281 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
282 } |
2964947674d1
More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
283 |
320
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
285 int dmSaveTimeline(DMResource *res, DMTimeline *tl) |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 { |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
287 return DMERR_OK; |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
288 } |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 |
fc79b57d4646
Add in unfinished timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
290 |