Mercurial > audlegacy-plugins
comparison src/rovascope/actuators.c @ 408:290588854a9d trunk
[svn] - rovascope -- a variant of the paranormal visualization engine that is
uses random data instead of presets.
author | nenolod |
---|---|
date | Sat, 06 Jan 2007 01:57:34 -0800 |
parents | src/paranormal/actuators.c@0f3ed1b6b273 |
children |
comparison
equal
deleted
inserted
replaced
407:3c0cb7e84e0d | 408:290588854a9d |
---|---|
1 #ifdef HAVE_CONFIG_H | |
2 # include <config.h> | |
3 #endif | |
4 | |
5 #include <glib.h> | |
6 | |
7 #include "actuators.h" | |
8 //#include "containers.h" | |
9 | |
10 /* FIXME: container options override containees - fix this? */ | |
11 /* FIXME: add actuator groups (by a group name string) */ | |
12 | |
13 /* FIXME: add support for copying containers' children (optionally) */ | |
14 struct pn_actuator * | |
15 copy_actuator (const struct pn_actuator *a) | |
16 { | |
17 struct pn_actuator *actuator; | |
18 int i; | |
19 | |
20 actuator = g_new (struct pn_actuator, 1); | |
21 | |
22 actuator->desc = a->desc; | |
23 | |
24 /* Make an options table */ | |
25 if (actuator->desc->option_descs) | |
26 { | |
27 /* count the options */ | |
28 for (i=0; actuator->desc->option_descs[i].name; i++); | |
29 | |
30 actuator->options = g_new (struct pn_actuator_option, i); | |
31 for (i=0; actuator->desc->option_descs[i].name; i++) | |
32 { | |
33 actuator->options[i].desc = &actuator->desc->option_descs[i]; | |
34 | |
35 /* copy the default options */ | |
36 switch (actuator->desc->option_descs[i].type) | |
37 { | |
38 case OPT_TYPE_INT: | |
39 case OPT_TYPE_COLOR_INDEX: | |
40 case OPT_TYPE_FLOAT: | |
41 case OPT_TYPE_COLOR: | |
42 case OPT_TYPE_BOOLEAN: | |
43 memcpy (&actuator->options[i].val, | |
44 &a->options[i].val, | |
45 sizeof (union actuator_option_val)); | |
46 break; | |
47 case OPT_TYPE_STRING: | |
48 actuator->options[i].val.sval = g_strdup(a->options[i].val.sval); | |
49 break; | |
50 default: | |
51 break; | |
52 } | |
53 } | |
54 | |
55 /* the NULL option */ | |
56 actuator->options[i].desc = NULL; | |
57 } | |
58 else | |
59 actuator->options = NULL; | |
60 | |
61 if (actuator->desc->init) | |
62 actuator->desc->init (&actuator->data); | |
63 | |
64 return actuator; | |
65 } | |
66 | |
67 struct pn_actuator_desc * | |
68 get_actuator_desc (const char *name) | |
69 { | |
70 int i; | |
71 | |
72 for (i=0; builtin_table[i]; i++) | |
73 if (! g_strcasecmp (name, builtin_table[i]->name) || ! g_strcasecmp(name, builtin_table[i]->dispname)) | |
74 break; | |
75 | |
76 /* actuator not found */ | |
77 if (! builtin_table[i]) | |
78 return NULL; | |
79 | |
80 return builtin_table[i]; | |
81 } | |
82 | |
83 struct pn_actuator * | |
84 create_actuator (const char *name) | |
85 { | |
86 int i; | |
87 struct pn_actuator_desc *desc; | |
88 struct pn_actuator *actuator; | |
89 | |
90 /* find the actuatoreration */ | |
91 desc = get_actuator_desc (name); | |
92 | |
93 if (! desc) | |
94 return NULL; | |
95 | |
96 actuator = g_new (struct pn_actuator, 1); | |
97 actuator->desc = desc; | |
98 | |
99 /* Make an options table */ | |
100 if (actuator->desc->option_descs) | |
101 { | |
102 /* count the options */ | |
103 for (i=0; actuator->desc->option_descs[i].name != NULL; i++); | |
104 | |
105 actuator->options = g_new0 (struct pn_actuator_option, i + 1); | |
106 for (i=0; actuator->desc->option_descs[i].name != NULL; i++) | |
107 { | |
108 actuator->options[i].desc = &actuator->desc->option_descs[i]; | |
109 | |
110 /* copy the default options */ | |
111 switch (actuator->desc->option_descs[i].type) | |
112 { | |
113 case OPT_TYPE_INT: | |
114 case OPT_TYPE_COLOR_INDEX: | |
115 case OPT_TYPE_FLOAT: | |
116 case OPT_TYPE_COLOR: | |
117 case OPT_TYPE_BOOLEAN: | |
118 memcpy (&actuator->options[i].val, | |
119 &actuator->desc->option_descs[i].default_val, | |
120 sizeof (union actuator_option_val)); | |
121 break; | |
122 case OPT_TYPE_STRING: | |
123 /* NOTE: It's not realloc'ed so don't free it */ | |
124 actuator->options[i].val.sval = | |
125 actuator->desc->option_descs[i].default_val.sval; | |
126 break; | |
127 } | |
128 } | |
129 | |
130 /* the NULL option */ | |
131 actuator->options[i].desc = NULL; | |
132 } | |
133 else | |
134 actuator->options = NULL; | |
135 | |
136 if (actuator->desc->init) | |
137 actuator->desc->init (&actuator->data); | |
138 | |
139 return actuator; | |
140 } | |
141 | |
142 void | |
143 destroy_actuator (struct pn_actuator *actuator) | |
144 { | |
145 int i; | |
146 | |
147 if (actuator->desc->cleanup) | |
148 actuator->desc->cleanup (actuator->data); | |
149 | |
150 /* find any option val's that need to be freed */ | |
151 if (actuator->options) | |
152 for (i=0; actuator->options[i].desc; i++) | |
153 switch (actuator->options[i].desc->type) | |
154 { | |
155 case OPT_TYPE_INT: | |
156 case OPT_TYPE_FLOAT: | |
157 case OPT_TYPE_COLOR: | |
158 case OPT_TYPE_COLOR_INDEX: | |
159 case OPT_TYPE_BOOLEAN: | |
160 break; | |
161 case OPT_TYPE_STRING: | |
162 if (actuator->options[i].val.sval | |
163 != actuator->options[i].desc->default_val.sval) | |
164 g_free ((char *)actuator->options[i].val.sval); | |
165 } | |
166 | |
167 g_free (actuator->options); | |
168 g_free (actuator); | |
169 } | |
170 | |
171 void | |
172 exec_actuator (struct pn_actuator *actuator) | |
173 { | |
174 g_assert (actuator); | |
175 g_assert (actuator->desc); | |
176 g_assert (actuator->desc->exec); | |
177 actuator->desc->exec (actuator->options, actuator->data); | |
178 } | |
179 |