annotate dmtimelinew.c @ 554:d4b84101e480

Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 23 Nov 2012 15:38:32 +0200
parents 0f290af63fc1
children 2dbe70d40481
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
368
08ea68abb1f8 Work towards re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents: 350
diff changeset
1 #include "dmengine.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
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
5 static BOOL dmSaveFloatValue(DMResource *res, DMFloat val)
327
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);
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
9 return !dmf_write_str(res, tmp, DT_FLOAT_STORE_SIZE);
327
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
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
13 static int dmSaveTimelinePoints(DMResource *res, DMTimelinePoints *points, int type)
327
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) ||
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
31 !dmf_write_le32(res, ptime))
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
32 return DMERR_FWRITE;
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
33
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
34 switch (type)
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
35 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
36 case EFPT_INT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
37 if (!dmf_write_le32(res, pt->vint))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
38 return DMERR_FWRITE;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
39 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
40
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
41 case EFPT_FLOAT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
42 if (!dmSaveFloatValue(res, pt->vfloat))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
43 return DMERR_FWRITE;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
44 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
45
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
46 case EFPT_VECTOR:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
47 if (!dmSaveFloatValue(res, pt->vector.x) ||
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
48 !dmSaveFloatValue(res, pt->vector.y) ||
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
49 !dmSaveFloatValue(res, pt->vector.z) ||
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
50 !dmSaveFloatValue(res, pt->vector.W))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
51 return DMERR_FWRITE;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
52 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
53
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
54 case EFPT_MATRIX:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
55 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
56 int x, y;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
57 for (y = 0; y < DM_MATRIX_SIZE; y++)
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
58 for (x = 0; x < DM_MATRIX_SIZE; x++)
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
59 {
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
60 if (!dmSaveFloatValue(res, pt->matrix.m[y][x]))
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
61 return DMERR_FWRITE;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
62 }
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
63 }
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
64 break;
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
65 }
327
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 return DMERR_OK;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
68 }
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
69
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
70
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
71 static int dmSaveTimelineCurve(DMResource *res, DMTimelineCurve *curve)
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
72 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
73 int err;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
74
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
75 dmfputc(curve->enabled, res);
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
76 if ((err = dmSaveTimelinePoints(res, &(curve->points), EFPT_FLOAT)) != DMERR_OK)
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
77 return err;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
78
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
79 return DMERR_OK;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
80 }
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
81
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
82
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
83 static int dmSaveTimelineEventParam(DMResource *res, DMTimelineEventParam *param)
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
84 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
85 int err;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
86 DMFTimelineEventParam hdr;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
87 Uint16 len;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
88
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
89 strncpy(hdr.name, param->name, sizeof(hdr.name));
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
90 hdr.type = param->type;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
91
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
92 if (!dmf_write_str(res, hdr.name, sizeof(hdr.name)) ||
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
93 !dmf_write_le32(res, hdr.type))
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
94 return DMERR_FWRITE;
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 switch (param->type)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
97 {
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
98 case EFPT_INT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
99 case EFPT_FLOAT:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
100 case EFPT_VECTOR:
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
101 case EFPT_MATRIX:
347
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
102 if ((err = dmSaveTimelinePoints(res, &param->pts, param->type)) != DMERR_OK)
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
103 return err;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
104 break;
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
105
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
106 case EFPT_STRING:
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
107 len = strlen(param->vstr);
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
108 if (!dmf_write_le16(res, len))
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
109 return DMERR_FWRITE;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
110
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
111 if (!dmf_write_str(res, param->vstr, len))
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
112 return DMERR_FWRITE;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
113 break;
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
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
116 return DMERR_OK;
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
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
120 static int dmSaveTimelineEvent(DMResource *res, DMTimelineEvent *event)
327
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 int param, err;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
123 DMFTimelineEvent hdr;
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 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
126 hdr.start = event->start;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
127 hdr.duration = event->duration;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
128 hdr.nparams = event->nparams;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
129
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
130 if (!dmf_write_le32(res, hdr.start) ||
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
131 !dmf_write_le32(res, hdr.duration) ||
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
132 !dmf_write_str(res, hdr.effectName, sizeof(hdr.effectName)) ||
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
133 !dmf_write_le32(res, hdr.nparams))
346
882503ef7ab8 More work on timeline saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
134 return DMERR_FWRITE;
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
135
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
136 for (param = 0; param < event->nparams; param++)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
137 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
138 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
139 return err;
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
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
142 return DMERR_OK;
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
350
834f3b686ad3 More work on timeline stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
146 static int dmSaveTimelineTrack(DMResource *res, DMTimelineTrack *track)
327
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 event, err;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
149 DMFTimelineTrack 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 strncpy(hdr.name, track->name, sizeof(hdr.name));
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
152 hdr.enabled = track->enabled;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
153 hdr.nevents = track->nevents;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
154
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
155 if (!dmf_write_str(res, hdr.name, sizeof(hdr.name)))
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
156 return DMERR_FWRITE;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
157
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
158 dmfputc(hdr.enabled, res);
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
159 if (!dmf_write_le32(res, hdr.nevents))
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 (event = 0; event < track->nevents; event++)
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 = dmSaveTimelineEvent(res, track->events[event])) != 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 if ((err = dmSaveTimelineCurve(res, &(track->composite))) != DMERR_OK)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
169 return err;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
170
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
171 return DMERR_OK;
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
172 }
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
173
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
174
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
175 int dmSaveTimeline(DMResource *res, DMTimeline *tl)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
176 {
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
177 int track, err;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
178 DMFTimeline hdr;
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 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
181 strncpy(hdr.name, tl->name, sizeof(hdr.name));
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
182 hdr.ntracks = tl->ntracks;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
183 hdr.duration = tl->duration;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
184
554
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
185 if (!dmf_write_str(res, hdr.magic, sizeof(hdr.magic)) ||
d4b84101e480 Remove useless (Uint8 *) typecasts now that dmf_{read,write}_str() uses void.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
186 !dmf_write_str(res, hdr.name, sizeof(hdr.name)) ||
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
187 !dmf_write_le32(res, hdr.ntracks) ||
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
188 !dmf_write_le32(res, hdr.duration))
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
189 return DMERR_FWRITE;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
190
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
191 for (track = 0; track < tl->ntracks; track++)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
192 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
193 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
194 return err;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
195 }
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 return DMERR_OK;
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
198 }
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
199
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
200
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
201 int dmTimelineNew(DMTimeline **ptl, const char *name)
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 DMTimeline *tl;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
204 if ((*ptl = tl = dmMalloc0(sizeof(DMTimeline))) == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
205 return DMERR_MALLOC;
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 tl->name = dm_strdup(name);
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 return DMERR_OK;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
210 }
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
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
213 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
214 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
215 DMTimelineTrack *track;
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 if ((*ptrack = track = dmMalloc0(sizeof(DMTimelineTrack))) == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
218 return DMERR_MALLOC;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
219
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
220 track->name = dm_strdup(name);
398
8660c6005032 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 395
diff changeset
221 track->enabled = TRUE;
327
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 if (tl->ntracks + 1 >= tl->nallocated)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
224 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
225 tl->nallocated += 16;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
226 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
227 if (tl->tracks == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
228 return DMERR_MALLOC;
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
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
231 tl->tracks[tl->ntracks] = track;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
232 tl->ntracks++;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
233
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
234 return DMERR_OK;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
235 }
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
236
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 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
239 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
240 DMTimelineEvent *ev;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
241
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
242 if ((*pev = ev = dmMalloc0(sizeof(DMTimelineEvent))) == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
243 return DMERR_MALLOC;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
244
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
245 ev->start = start;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
246 ev->duration = duration;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
247
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
248 if (track->nevents + 1 >= track->nallocated)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
249 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
250 track->nallocated += 16;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
251 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
252 if (track->events == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
253 return DMERR_MALLOC;
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
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
256 track->events[track->nevents] = ev;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
257 track->nevents++;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
258
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
259 return DMERR_OK;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
260 }
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
261
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
262
402
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
263 int dmTimelineEventSetEffect(DMTimelineEvent *event, DMEffect *ef)
327
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 int param;
402
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
266 if (ef == NULL)
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
267 return DMERR_INVALID_DATA;
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 event->effect = ef;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
270 event->nparams = ef->nparams;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
271 event->params = dmCalloc(ef->nparams, sizeof(DMTimelineEventParam));
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
272 if (event->params == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
273 return DMERR_MALLOC;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
274
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
275 for (param = 0; param < ef->nparams; param++)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
276 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
277 DMTimelineEventParam *psrc = &ef->params[param],
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
278 *pdst = &event->params[param];
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 pdst->name = dm_strdup(psrc->name);
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
281 pdst->type = psrc->type;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
282 pdst->vstr = dm_strdup(psrc->vstr);
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
283
347
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
284 if (psrc->pts.points != NULL && psrc->pts.npoints > 0)
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
285 {
347
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
286 pdst->pts.npoints = psrc->pts.npoints;
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
287 pdst->pts.nallocated = psrc->pts.nallocated;
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
288 pdst->pts.points = dmMalloc(psrc->pts.nallocated * sizeof(DMTimelinePoint));
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
289 if (pdst->pts.points == NULL)
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
290 return DMERR_MALLOC;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
291
347
f248defe7484 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 346
diff changeset
292 memcpy(pdst->pts.points, psrc->pts.points, pdst->pts.npoints * sizeof(DMTimelinePoint));
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
293 }
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
294 }
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
295
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
296 return DMERR_OK;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
297 }
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
298
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
299
402
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
300 int dmTimelineEventSetEffectByIndex(DMTimelineEvent *event, const int index)
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
301 {
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
302 if (index < 0 || index >= nengineEffects)
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
303 return DMERR_INVALID_DATA;
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
304
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
305 return dmTimelineEventSetEffect(event, &engineEffects[index]);
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
306 }
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
307
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
308
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
309 int dmTimelineEventSetEffectByName(DMTimelineEvent *event, const char *name)
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
310 {
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
311 return dmTimelineEventSetEffect(event, engineFindEffectByName(name));
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
312 }
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
313
0f290af63fc1 Timeline event drawing prototype works.
Matti Hamalainen <ccr@tnsp.org>
parents: 399
diff changeset
314
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
315 DMTimelineEvent *dmTimelineGetEventAt(DMTimelineTrack *track, const int time)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
316 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
317 int event;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
318 for (event = 0; event < track->nevents; event++)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
319 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
320 DMTimelineEvent *ev = track->events[event];
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
321 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
322 return ev;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
323 }
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
324 return NULL;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
325 }
395
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
326
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
327
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
328 int dmCopyTimelinePoints(const DMTimelinePoints *src, DMTimelinePoints *dst)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
329 {
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
330 if (src->points == NULL || src->npoints <= 0 || src->nallocated <= 0)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
331 return DMERR_OK;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
332
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
333 dst->npoints = src->npoints;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
334 dst->nallocated = src->nallocated;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
335 dst->points = dmCalloc(src->nallocated, sizeof(DMTimelinePoint));
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
336 if (dst->points == NULL)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
337 return DMERR_MALLOC;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
338
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
339 memcpy(dst->points, src->points, sizeof(DMTimelinePoint) * src->npoints);
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
340
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
341 return DMERR_OK;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
342 }
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
343
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
344
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
345 int dmCopyTimelineEventParam(const DMTimelineEventParam *src, DMTimelineEventParam *dst)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
346 {
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
347 dst->name = dm_strdup(src->name);
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
348 dst->type = src->type;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
349 dst->vstr = dm_strdup(src->vstr);
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
350
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
351 return dmCopyTimelinePoints(&src->pts, &dst->pts);
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
352 }
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
353
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
354
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
355 int dmCopyTimelineEvent(const DMTimelineEvent *src, DMTimelineEvent **pdst)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
356 {
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
357 int param;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
358 DMTimelineEvent *dst;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
359 if ((*pdst = dst = dmMalloc0(sizeof(DMTimelineEvent))) == NULL)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
360 return DMERR_MALLOC;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
361
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
362 dst->start = src->start;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
363 dst->duration = src->duration;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
364 dst->nparams = src->nparams;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
365 dst->effect = src->effect;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
366 dst->params = dmCalloc(src->nparams, sizeof(DMTimelineEventParam));
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
367 if (dst->params == NULL)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
368 return DMERR_MALLOC;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
369
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
370 for (param = 0; param < src->nparams; param++)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
371 {
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
372 int err;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
373 if ((err = dmCopyTimelineEventParam(&(src->params[param]), &(dst->params[param]))) != DMERR_OK)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
374 return err;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
375 }
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
376
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
377 return DMERR_OK;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
378 }
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
379
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
380
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
381 int dmCopyTimelineCurve(const DMTimelineCurve *src, DMTimelineCurve *dst)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
382 {
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
383 dst->enabled = src->enabled;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
384 return dmCopyTimelinePoints(&(src->points), &(dst->points));
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
385 }
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
386
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
387
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
388 int dmCopyTimelineTrack(const DMTimelineTrack *src, DMTimelineTrack **pdst)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
389 {
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
390 int event, err;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
391 DMTimelineTrack *dst;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
392 if ((*pdst = dst = dmMalloc0(sizeof(DMTimelineTrack))) == NULL)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
393 return DMERR_MALLOC;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
394
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
395 if ((dst->events = dmCalloc(src->nevents, sizeof(DMTimelineEvent *))) == NULL)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
396 return DMERR_MALLOC;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
397
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
398 dst->name = dm_strdup(src->name);
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
399 dst->enabled = src->enabled;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
400 dst->nevents = src->nevents;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
401
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
402 for (event = 0; event < src->nevents; event++)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
403 {
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
404 if ((err = dmCopyTimelineEvent(src->events[event], &(dst->events[event]))) != DMERR_OK)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
405 return err;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
406 }
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
407
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
408 if ((err = dmCopyTimelineCurve(&(src->composite), &(dst->composite))) != DMERR_OK)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
409 return err;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
410
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
411 return DMERR_OK;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
412 }
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
413
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
414
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
415 int dmCopyTimeline(const DMTimeline *src, DMTimeline **pdst)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
416 {
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
417 int track, err;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
418 DMTimeline *dst;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
419 if ((*pdst = dst = dmMalloc0(sizeof(DMTimeline))) == NULL)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
420 return DMERR_MALLOC;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
421
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
422 dst->tracks = (DMTimelineTrack **) dmCalloc(src->ntracks, sizeof(DMTimelineTrack *));
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
423 if (dst->tracks == NULL)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
424 return DMERR_MALLOC;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
425
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
426 dst->name = dm_strdup(src->name);
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
427 dst->duration = src->duration;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
428 dst->ntracks = src->ntracks;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
429
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
430 for (track = 0; track < src->ntracks; track++)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
431 {
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
432 if ((err = dmCopyTimelineTrack(src->tracks[track], &(dst->tracks[track]))) != DMERR_OK)
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
433 return err;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
434 }
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
435
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
436 return DMERR_OK;
530db8fa4569 Implement functions for copying timelines and timeline components.
Matti Hamalainen <ccr@tnsp.org>
parents: 368
diff changeset
437 }