annotate dmtimelinew.c @ 328:dd7b1356d726

More work.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 14 Oct 2012 23:47:33 +0300
parents 2964947674d1
children 882503ef7ab8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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, &param->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
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
148 return DMERR_OK;
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
149 }
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
150
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
151
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
152 int dmSaveTimeline(DMResource *res, DMTimeline *tl)
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
153 {
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
154 int track, err;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
155 DMFTimeline hdr;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
156
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
157 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
158 strncpy(hdr.name, tl->name, sizeof(hdr.name));
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
159 hdr.ntracks = tl->ntracks;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
160 hdr.duration = tl->duration;
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 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
163 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
164 !dmf_write_le32(res, hdr.ntracks) ||
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
165 !dmf_write_le32(res, hdr.duration))
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
166 return DMERR_FWRITE;
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 for (track = 0; track < tl->ntracks; track++)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
169 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
170 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
171 return err;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
172 }
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
173
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
174 return DMERR_OK;
328
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
175 }
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
176
dd7b1356d726 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
177
327
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
178 int dmTimelineNew(DMTimeline **ptl, const char *name)
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 DMTimeline *tl;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
181 if ((*ptl = tl = dmMalloc0(sizeof(DMTimeline))) == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
182 return DMERR_MALLOC;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
183
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
184 tl->name = dm_strdup(name);
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
185
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
186 return DMERR_OK;
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
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 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
191 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
192 DMTimelineTrack *track;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
193
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
194 if ((*ptrack = track = dmMalloc0(sizeof(DMTimelineTrack))) == 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 track->name = dm_strdup(name);
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
198
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
199 if (tl->ntracks + 1 >= tl->nallocated)
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 tl->nallocated += 16;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
202 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
203 if (tl->tracks == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
204 return DMERR_MALLOC;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
205 }
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->tracks[tl->ntracks] = track;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
208 tl->ntracks++;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
209
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
210 return DMERR_OK;
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
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
214 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
215 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
216 DMTimelineEvent *ev;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
217
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
218 if ((*pev = ev = dmMalloc0(sizeof(DMTimelineEvent))) == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
219 return DMERR_MALLOC;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
220
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
221 ev->start = start;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
222 ev->duration = duration;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
223
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
224 if (track->nevents + 1 >= track->nallocated)
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 track->nallocated += 16;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
227 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
228 if (track->events == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
229 return DMERR_MALLOC;
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
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
232 track->events[track->nevents] = ev;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
233 track->nevents++;
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 return DMERR_OK;
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
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
239 int dmTimelineEventSetEffect(DMTimelineEvent *event, const char *name)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
240 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
241 int param;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
242 DMEffect *ef;
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 if ((ef = dmFindEffectByName(name)) == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
245 return DMERR_INVALID_DATA;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
246
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
247 event->effect = ef;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
248 event->nparams = ef->nparams;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
249 event->params = dmCalloc(ef->nparams, sizeof(DMTimelineEventParam));
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
250 if (event->params == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
251 return DMERR_MALLOC;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
252
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
253 for (param = 0; param < ef->nparams; param++)
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 DMTimelineEventParam *psrc = &ef->params[param],
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
256 *pdst = &event->params[param];
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
257
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
258 pdst->name = dm_strdup(psrc->name);
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
259 pdst->type = psrc->type;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
260 pdst->vstr = dm_strdup(psrc->vstr);
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
261 pdst->vint = psrc->vint;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
262 pdst->vfloat = psrc->vfloat;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
263
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
264 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
265 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
266 pdst->vpts.npoints = psrc->vpts.npoints;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
267 pdst->vpts.nallocated = psrc->vpts.nallocated;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
268 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
269 if (pdst->vpts.points == NULL)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
270 return DMERR_MALLOC;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
271
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
272 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
273 }
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
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
276 return DMERR_OK;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
277 }
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
278
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 DMTimelineEvent *dmTimelineGetEventAt(DMTimelineTrack *track, const int time)
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 int event;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
283 for (event = 0; event < track->nevents; event++)
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
284 {
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
285 DMTimelineEvent *ev = track->events[event];
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
286 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
287 return ev;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
288 }
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
289 return NULL;
2964947674d1 More work on the timeline code.
Matti Hamalainen <ccr@tnsp.org>
parents: 320
diff changeset
290 }