Mercurial > audlegacy-plugins
comparison src/paranormal-ng/actuators.c @ 2078:1fa3c8cd366a
paranormal-ng: a GL visualiser. lots to do, most stuff won't work, but hey, this will do cool stuff too soon
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Mon, 15 Oct 2007 06:20:13 -0500 |
parents | |
children | f1b6f1b2cdb3 |
comparison
equal
deleted
inserted
replaced
2077:e5b639ab62b0 | 2078:1fa3c8cd366a |
---|---|
1 /* | |
2 * paranormal: iterated pipeline-driven visualization plugin | |
3 * Copyright (c) 2006, 2007 William Pitcock <nenolod@dereferenced.org> | |
4 * Portions copyright (c) 2001 Jamie Gennis <jgennis@mindspring.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; under version 2 of the License. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 | |
20 #include <config.h> | |
21 | |
22 #include <glib.h> | |
23 | |
24 #include "actuators.h" | |
25 //#include "containers.h" | |
26 | |
27 /* FIXME: container options override containees - fix this? */ | |
28 /* FIXME: add actuator groups (by a group name string) */ | |
29 | |
30 /* FIXME: add support for copying containers' children (optionally) */ | |
31 struct pn_actuator * | |
32 copy_actuator (const struct pn_actuator *a) | |
33 { | |
34 struct pn_actuator *actuator; | |
35 int i; | |
36 | |
37 actuator = g_new (struct pn_actuator, 1); | |
38 | |
39 actuator->desc = a->desc; | |
40 | |
41 /* Make an options table */ | |
42 if (actuator->desc->option_descs) | |
43 { | |
44 /* count the options */ | |
45 for (i=0; actuator->desc->option_descs[i].name; i++); | |
46 | |
47 actuator->options = g_new (struct pn_actuator_option, i + 1); | |
48 for (i=0; actuator->desc->option_descs[i].name; i++) | |
49 { | |
50 actuator->options[i].desc = &actuator->desc->option_descs[i]; | |
51 | |
52 /* copy the default options */ | |
53 switch (actuator->desc->option_descs[i].type) | |
54 { | |
55 case OPT_TYPE_INT: | |
56 case OPT_TYPE_COLOR_INDEX: | |
57 case OPT_TYPE_FLOAT: | |
58 case OPT_TYPE_COLOR: | |
59 case OPT_TYPE_BOOLEAN: | |
60 memcpy (&actuator->options[i].val, | |
61 &a->options[i].val, | |
62 sizeof (union actuator_option_val)); | |
63 break; | |
64 case OPT_TYPE_STRING: | |
65 actuator->options[i].val.sval = g_strdup(a->options[i].val.sval); | |
66 break; | |
67 default: | |
68 break; | |
69 } | |
70 } | |
71 | |
72 /* the NULL option */ | |
73 actuator->options[i].desc = NULL; | |
74 } | |
75 else | |
76 actuator->options = NULL; | |
77 | |
78 if (actuator->desc->init) | |
79 actuator->desc->init (&actuator->data); | |
80 | |
81 return actuator; | |
82 } | |
83 | |
84 struct pn_actuator_desc * | |
85 get_actuator_desc (const char *name) | |
86 { | |
87 int i; | |
88 | |
89 for (i=0; builtin_table[i]; i++) | |
90 if (! g_strcasecmp (name, builtin_table[i]->name) || ! g_strcasecmp(name, builtin_table[i]->dispname)) | |
91 break; | |
92 | |
93 /* actuator not found */ | |
94 if (! builtin_table[i]) | |
95 return NULL; | |
96 | |
97 return builtin_table[i]; | |
98 } | |
99 | |
100 struct pn_actuator * | |
101 create_actuator (const char *name) | |
102 { | |
103 int i; | |
104 struct pn_actuator_desc *desc; | |
105 struct pn_actuator *actuator; | |
106 | |
107 /* find the actuatoreration */ | |
108 desc = get_actuator_desc (name); | |
109 | |
110 if (! desc) | |
111 return NULL; | |
112 | |
113 actuator = g_new (struct pn_actuator, 1); | |
114 actuator->desc = desc; | |
115 | |
116 /* Make an options table */ | |
117 if (actuator->desc->option_descs) | |
118 { | |
119 /* count the options */ | |
120 for (i=0; actuator->desc->option_descs[i].name != NULL; i++); | |
121 | |
122 actuator->options = g_new0 (struct pn_actuator_option, i + 1); | |
123 for (i=0; actuator->desc->option_descs[i].name != NULL; i++) | |
124 { | |
125 actuator->options[i].desc = &actuator->desc->option_descs[i]; | |
126 | |
127 /* copy the default options */ | |
128 switch (actuator->desc->option_descs[i].type) | |
129 { | |
130 case OPT_TYPE_INT: | |
131 case OPT_TYPE_COLOR_INDEX: | |
132 case OPT_TYPE_FLOAT: | |
133 case OPT_TYPE_COLOR: | |
134 case OPT_TYPE_BOOLEAN: | |
135 memcpy (&actuator->options[i].val, | |
136 &actuator->desc->option_descs[i].default_val, | |
137 sizeof (union actuator_option_val)); | |
138 break; | |
139 case OPT_TYPE_STRING: | |
140 /* NOTE: It's not realloc'ed so don't free it */ | |
141 actuator->options[i].val.sval = | |
142 actuator->desc->option_descs[i].default_val.sval; | |
143 break; | |
144 } | |
145 } | |
146 | |
147 /* the NULL option */ | |
148 actuator->options[i].desc = NULL; | |
149 } | |
150 else | |
151 actuator->options = NULL; | |
152 | |
153 if (actuator->desc->init) | |
154 actuator->desc->init (&actuator->data); | |
155 | |
156 return actuator; | |
157 } | |
158 | |
159 void | |
160 destroy_actuator (struct pn_actuator *actuator) | |
161 { | |
162 int i; | |
163 | |
164 if (actuator->desc->cleanup) | |
165 actuator->desc->cleanup (actuator->data); | |
166 | |
167 /* find any option val's that need to be freed */ | |
168 if (actuator->options) | |
169 for (i=0; actuator->options[i].desc; i++) | |
170 switch (actuator->options[i].desc->type) | |
171 { | |
172 case OPT_TYPE_INT: | |
173 case OPT_TYPE_FLOAT: | |
174 case OPT_TYPE_COLOR: | |
175 case OPT_TYPE_COLOR_INDEX: | |
176 case OPT_TYPE_BOOLEAN: | |
177 break; | |
178 case OPT_TYPE_STRING: | |
179 if (actuator->options[i].val.sval | |
180 != actuator->options[i].desc->default_val.sval) | |
181 g_free ((char *)actuator->options[i].val.sval); | |
182 } | |
183 | |
184 g_free (actuator->options); | |
185 g_free (actuator); | |
186 } | |
187 | |
188 void | |
189 exec_actuator (struct pn_actuator *actuator) | |
190 { | |
191 g_assert (actuator); | |
192 g_assert (actuator->desc); | |
193 g_assert (actuator->desc->exec); | |
194 actuator->desc->exec (actuator->options, actuator->data); | |
195 } | |
196 |