Mercurial > audlegacy-plugins
annotate src/paranormal/presets.c @ 2284:d19b53359b24
cleaned up the sndfile wav plugin, currently limiting it ONLY TO WAV
PLAYBACK. if somebody is more experienced with it and wants to restore
the other formats, go ahead (maybe change the name of the plugin too?).
author | mf0102 <0102@gmx.at> |
---|---|
date | Wed, 09 Jan 2008 15:41:22 +0100 |
parents | 56bb18dd3fdd |
children | f1b6f1b2cdb3 |
rev | line source |
---|---|
1892
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
1 /* |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
2 * paranormal: iterated pipeline-driven visualization plugin |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
3 * Copyright (c) 2006, 2007 William Pitcock <nenolod@dereferenced.org> |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
4 * Portions copyright (c) 2001 Jamie Gennis <jgennis@mindspring.com> |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
5 * |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
8 * the Free Software Foundation; under version 2 of the License. |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
9 * |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
13 * GNU General Public License for more details. |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
14 * |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
16 * along with this program; if not, write to the Free Software |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
18 */ |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
963
diff
changeset
|
19 |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
20 /* FIXME: add documentation support to preset files */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
21 /* FIXME: add multiple-presets-per-file support (maybe) */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
22 |
1943
56bb18dd3fdd
paranormal: CONFIG_H removal
William Pitcock <nenolod@atheme.org>
parents:
1892
diff
changeset
|
23 #include <config.h> |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
24 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
25 #include <stdlib.h> |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
26 #include <ctype.h> |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
27 #include <string.h> |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
28 #include <errno.h> |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
29 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
30 #include <glib.h> |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
31 #include <libxml/parser.h> |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
32 #include <libxml/xmlmemory.h> |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
33 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
34 #include "paranormal.h" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
35 #include "actuators.h" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
36 #include "containers.h" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
37 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
38 /* cur->name should be the actuator name */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
39 static void |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
40 parse_actuator (xmlNodePtr cur, struct pn_actuator *a) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
41 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
42 int i; |
963 | 43 char *content; |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
44 struct pn_actuator *child; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
45 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
46 for (cur = cur->xmlChildrenNode; cur; cur = cur->next) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
47 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
48 if (xmlIsBlankNode (cur) || cur->type != XML_ELEMENT_NODE) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
49 continue; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
50 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
51 /* see if it's an option */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
52 for (i=0; a->options && a->options[i].desc; i++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
53 if (! xmlStrcmp (cur->name, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
54 (const xmlChar *) a->options[i].desc->name)) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
55 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
56 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
57 if (a->options && a->options[i].desc) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
58 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
59 /* it is an option, so let's set it! */ |
963 | 60 content = (char*)xmlNodeGetContent (cur); |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
61 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
62 /* FIXME: warning? */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
63 if (! content) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
64 continue; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
65 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
66 /* FIXME: perhaps do a little better job of error checking? */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
67 switch (a->options[i].desc->type) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
68 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
69 case OPT_TYPE_INT: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
70 a->options[i].val.ival = (int)strtol (content, NULL, 0); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
71 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
72 case OPT_TYPE_FLOAT: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
73 a->options[i].val.fval = (float)strtod (content, NULL); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
74 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
75 case OPT_TYPE_STRING: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
76 a->options[i].val.sval = g_strdup (content); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
77 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
78 case OPT_TYPE_COLOR: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
79 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
80 guint r,g,b; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
81 char *s = content+1; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
82 r = strtoul (s, &s, 0); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
83 if (r > 255 || ! (s = strchr (s, ','))) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
84 goto bad_color; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
85 g = strtoul (s+1, &s, 0); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
86 if (g > 255 || ! (s = strchr (s, ','))) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
87 goto bad_color; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
88 b = strtoul (s+1, NULL, 0); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
89 if (b > 255) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
90 goto bad_color; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
91 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
92 a->options[i].val.cval.r = (guchar)r; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
93 a->options[i].val.cval.g = (guchar)g; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
94 a->options[i].val.cval.b = (guchar)b; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
95 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
96 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
97 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
98 bad_color: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
99 pn_error ("parse error: invalid color value: option \"%s\" ignored.\n" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
100 " correct syntax: (r,g,b) where r, g, and b are the\n" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
101 " red, green, and blue components of the " |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
102 "color, respectively", cur->name); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
103 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
104 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
105 case OPT_TYPE_COLOR_INDEX: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
106 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
107 int c = (int)strtol (content, NULL, 0); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
108 if (c < 0 || c > 255) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
109 pn_error ("parse error: invalid color index \"%s\" (%d): option ignored.\n" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
110 " the value must be between 0 and 255", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
111 cur->name, c); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
112 else |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
113 a->options[i].val.ival = c; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
114 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
115 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
116 case OPT_TYPE_BOOLEAN: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
117 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
118 char *c, *d; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
119 for (c=content; isspace (*c); c++); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
120 for (d=c; !isspace(*d); d++); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
121 *d = '\0'; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
122 if (g_strcasecmp (c, "true") == 0) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
123 a->options[i].val.bval = TRUE; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
124 else if (g_strcasecmp (c, "false") == 0) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
125 a->options[i].val.bval = FALSE; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
126 else |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
127 pn_error ("parse error: invalid boolean value \"%s\" (%s): option ignored.\n" |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
128 " the value must be either 'true' or 'false'", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
129 cur->name, c); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
130 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
131 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
132 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
133 /* gotta free content */ |
963 | 134 xmlFree ((xmlChar*)content); |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
135 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
136 /* See if we have a child actuator */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
137 else if (a->desc->flags & ACTUATOR_FLAG_CONTAINER |
963 | 138 && (child = create_actuator ((char*)cur->name))) |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
139 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
140 container_add_actuator (a, child); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
141 parse_actuator (cur, child); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
142 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
143 else |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
144 /* We have an error */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
145 pn_error ("parse error: unknown entity \"%s\": ignored.", cur->name); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
146 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
147 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
148 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
149 struct pn_actuator * |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
150 load_preset (const char *filename) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
151 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
152 xmlDocPtr doc; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
153 xmlNodePtr cur; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
154 struct pn_actuator *a = NULL; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
155 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
156 doc = xmlParseFile (filename); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
157 if (! doc) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
158 return NULL; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
159 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
160 cur = xmlDocGetRootElement (doc); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
161 if (! cur) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
162 xmlFreeDoc (doc); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
163 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
164 if (xmlStrcmp (cur->name, (const xmlChar *) "paranormal_preset")) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
165 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
166 xmlFreeDoc (doc); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
167 return NULL; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
168 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
169 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
170 for (cur = cur->children; cur; cur = cur->next) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
171 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
172 if (xmlIsBlankNode (cur) || cur->type != XML_ELEMENT_NODE) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
173 continue; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
174 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
175 /* if (...) { ... } else if (is_documentation [see top of file]) ... else */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
176 { |
963 | 177 a = create_actuator ((char*)cur->name); |
149
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
178 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
179 /* FIXME: warn? */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
180 if (! a) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
181 continue; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
182 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
183 parse_actuator (cur, a); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
184 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
185 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
186 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
187 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
188 /* Don't need this any longer */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
189 xmlFreeDoc (doc); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
190 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
191 return a; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
192 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
193 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
194 /* FIXME: do the file writing w/ error checking */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
195 static gboolean |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
196 save_preset_recursive (FILE *file, const struct pn_actuator *actuator, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
197 int recursion_depth) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
198 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
199 int i; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
200 GSList *child; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
201 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
202 /* open this actuator */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
203 fprintf (file, "%*s<%s>\n", recursion_depth, "", actuator->desc->name); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
204 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
205 /* options */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
206 if (actuator->options) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
207 for (i=0; actuator->options[i].desc; i++) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
208 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
209 fprintf (file, "%*s <%s> ", recursion_depth, "", |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
210 actuator->desc->option_descs[i].name); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
211 switch (actuator->desc->option_descs[i].type) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
212 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
213 case OPT_TYPE_INT: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
214 case OPT_TYPE_COLOR_INDEX: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
215 fprintf (file, "%d", actuator->options[i].val.ival); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
216 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
217 case OPT_TYPE_FLOAT: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
218 fprintf (file, "%.5f", actuator->options[i].val.fval); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
219 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
220 case OPT_TYPE_STRING: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
221 fprintf (file, "%s", actuator->options[i].val.sval); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
222 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
223 case OPT_TYPE_COLOR: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
224 fprintf (file, "%d, %d, %d", actuator->options[i].val.cval.r, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
225 actuator->options[i].val.cval.g, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
226 actuator->options[i].val.cval.b); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
227 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
228 case OPT_TYPE_BOOLEAN: |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
229 if (actuator->options[i].val.bval) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
230 fprintf (file, "TRUE"); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
231 else |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
232 fprintf (file, "FALSE"); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
233 break; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
234 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
235 fprintf (file, " </%s>\n", actuator->desc->option_descs[i].name); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
236 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
237 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
238 /* children */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
239 if (actuator->desc->flags & ACTUATOR_FLAG_CONTAINER) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
240 for (child = *(GSList **)actuator->data; child; child = child->next) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
241 if (! save_preset_recursive (file, (struct pn_actuator*) child->data, |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
242 recursion_depth+1)) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
243 return FALSE; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
244 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
245 /* close the actuator */ |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
246 fprintf (file, "%*s</%s>\n", recursion_depth, "", actuator->desc->name); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
247 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
248 return TRUE; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
249 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
250 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
251 gboolean |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
252 save_preset (const char *filename, const struct pn_actuator *actuator) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
253 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
254 FILE *file; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
255 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
256 file = fopen (filename, "w"); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
257 if (! file) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
258 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
259 pn_error ("fopen: %s", strerror (errno)); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
260 return FALSE; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
261 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
262 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
263 fprintf (file, "<?xml version=\"1.0\"?>\n\n<paranormal_preset>\n"); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
264 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
265 if (actuator) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
266 if (! save_preset_recursive (file, actuator, 1)) |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
267 { |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
268 fclose (file); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
269 return FALSE; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
270 } |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
271 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
272 fprintf (file, "</paranormal_preset>"); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
273 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
274 fclose (file); |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
275 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
276 return TRUE; |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
277 |
fd9c0a5871ac
[svn] - new and IMPROVED paranormal visualization studio
nenolod
parents:
diff
changeset
|
278 } |