annotate Plugins/Visualization/paranormal/pn/pnvis.c @ 1523:aa1e05d66f6d trunk

[svn] - it might help if i actually ran bison on the script parser eh :)
author nenolod
date Mon, 07 Aug 2006 21:47:55 -0700
parents 0c5fdcf3f947
children 98a9c54459f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1507
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
1 /* Paranormal - A highly customizable audio visualization library
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
2 * Copyright (C) 2001 Jamie Gennis <jgennis@mindspring.com>
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
3 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
4 * This library is free software; you can redistribute it and/or
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
5 * modify it under the terms of the GNU Library General Public
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
6 * License as published by the Free Software Foundation; either
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
7 * version 2 of the License, or (at your option) any later version.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
8 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
9 * This library is distributed in the hope that it will be useful,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
12 * Library General Public License for more details.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
13 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
14 * You should have received a copy of the GNU Library General Public
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
15 * License along with this library; if not, write to the Free
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
17 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
18
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
19 #include <config.h>
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
20
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
21 #include <glib.h>
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
22 #include "pnvis.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
23 #include "pnactuatorfactory.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
24 #include "pnerror.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
25
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
26 static void pn_vis_class_init (PnVisClass *class);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
27 static void pn_vis_init (PnVis *vis,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
28 PnVisClass *class);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
29
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
30 /* GObject signals */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
31 static void pn_vis_finalize (GObject *gobject);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
32
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
33 /* PnObject signals */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
34 static void pn_vis_destroy (PnObject *object);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
35
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
36 /* PnUserObject methods */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
37 static void pn_vis_save_thyself (PnUserObject *user_object,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
38 xmlNodePtr node);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
39 static void pn_vis_load_thyself (PnUserObject *user_object,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
40 xmlNodePtr node);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
41
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
42 static PnUserObjectClass *parent_class = NULL;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
43
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
44 GType
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
45 pn_vis_get_type (void)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
46 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
47 static GType vis_type = 0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
48
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
49 if (! vis_type)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
50 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
51 static const GTypeInfo vis_info =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
52 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
53 sizeof (PnVisClass),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
54 NULL, /* base_init */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
55 NULL, /* base_finalize */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
56 (GClassInitFunc) pn_vis_class_init,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
57 NULL, /* class_finalize */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
58 NULL, /* class_data */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
59 sizeof (PnVis),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
60 0, /* n_preallocs */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
61 (GInstanceInitFunc) pn_vis_init
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
62 };
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
63
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
64 /* FIXME: should this be dynamic? */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
65 vis_type = g_type_register_static (PN_TYPE_USER_OBJECT,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
66 "PnVis",
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
67 &vis_info,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
68 0);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
69 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
70 return vis_type;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
71 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
72
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
73 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
74 pn_vis_class_init (PnVisClass *class)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
75 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
76 GObjectClass *gobject_class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
77 PnObjectClass *object_class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
78 PnUserObjectClass *user_object_class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
79
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
80 parent_class = g_type_class_peek_parent (class);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
81
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
82 gobject_class = (GObjectClass *) class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
83 object_class = (PnObjectClass *) class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
84 user_object_class = (PnUserObjectClass *) class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
85
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
86 /* GObject signals */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
87 gobject_class->finalize = pn_vis_finalize;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
88
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
89 /* PnObject signals */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
90 object_class->destroy = pn_vis_destroy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
91
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
92 /* PnUserObject methods */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
93 user_object_class->save_thyself = pn_vis_save_thyself;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
94 user_object_class->load_thyself = pn_vis_load_thyself;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
95 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
96
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
97 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
98 pn_vis_init (PnVis *vis, PnVisClass *class)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
99 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
100 /* Set a name for xml stuffs */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
101 pn_user_object_set_name (PN_USER_OBJECT (vis), "Paranormal_Visualization");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
102
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
103 /* Create a new image context */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
104 vis->root_image = pn_image_new ();
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
105 pn_object_ref (PN_OBJECT (vis->root_image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
106 pn_object_sink (PN_OBJECT (vis->root_image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
107 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
108
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
109 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
110 pn_vis_destroy (PnObject *object)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
111 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
112 PnVis *vis = (PnVis *) object;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
113
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
114 if (vis->root_actuator)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
115 pn_object_unref (PN_OBJECT (vis->root_actuator));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
116
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
117 if (vis->root_image)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
118 pn_object_unref (PN_OBJECT (vis->root_image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
119 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
120
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
121 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
122 pn_vis_finalize (GObject *gobject)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
123 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
124 PnVis *vis;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
125
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
126 vis = (PnVis *) gobject;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
127 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
128
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
129 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
130 pn_vis_save_thyself (PnUserObject *user_object, xmlNodePtr node)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
131 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
132 PnVis *vis;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
133 xmlNsPtr ns;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
134 xmlNodePtr actuators_node, actuator_node;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
135
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
136 g_return_if_fail (user_object != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
137 g_return_if_fail (PN_IS_VIS (user_object));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
138 g_return_if_fail (node != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
139
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
140 vis = (PnVis *) user_object;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
141
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
142 ns = xmlNewNs (node, PN_XML_NS_HREF, "pn");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
143 xmlSetNs (node, ns);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
144
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
145 actuators_node = xmlNewChild (node, NULL, "Actuators", NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
146 actuator_node = xmlNewChild (actuators_node, NULL, "BUG", NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
147 if (vis->root_actuator)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
148 pn_user_object_save_thyself (PN_USER_OBJECT (vis->root_actuator), actuator_node);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
149
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
150 if (parent_class->save_thyself)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
151 parent_class->save_thyself (user_object, node);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
152 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
153
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
154 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
155 pn_vis_load_thyself (PnUserObject *user_object, const xmlNodePtr node)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
156 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
157 PnVis *vis;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
158 xmlNodePtr actuators_node, actuator_node;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
159 PnActuator *root_actuator;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
160
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
161 g_return_if_fail (user_object != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
162 g_return_if_fail (PN_IS_VIS (user_object));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
163 g_return_if_fail (node != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
164
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
165 vis = (PnVis *) user_object;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
166
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
167 /* find the 'Actuators' node */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
168 for (actuators_node = node->xmlChildrenNode; actuators_node; actuators_node = actuators_node->next)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
169 if (g_strcasecmp (actuators_node->name, "Actuators") == 0)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
170 break;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
171 if (! actuators_node)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
172 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
173 pn_error ("unable to load a PnVis from xml node \"%s\"", node->name);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
174 return;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
175 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
176
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
177 /* get the root actuator's node */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
178 actuator_node = actuators_node->xmlChildrenNode;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
179 if (! actuator_node)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
180 goto done;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
181
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
182 /* Create a new actuator */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
183 root_actuator = pn_actuator_factory_new_actuator_from_xml (actuator_node);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
184 if (! root_actuator)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
185 pn_error ("Unknown actuator \"%s\"", actuator_node->name);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
186
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
187 pn_vis_set_root_actuator (vis, root_actuator);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
188
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
189 done:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
190 if (parent_class->load_thyself)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
191 parent_class->load_thyself (user_object, node);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
192 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
193
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
194 PnVis*
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
195 pn_vis_new (guint image_width, guint image_height)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
196 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
197 PnVis *vis;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
198
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
199 g_return_val_if_fail (image_width > 0, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
200 g_return_val_if_fail (image_height > 0, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
201
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
202 vis = (PnVis *) g_object_new (PN_TYPE_VIS, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
203 pn_vis_set_image_size (vis, image_width, image_height);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
204
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
205 return vis;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
206 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
207
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
208 void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
209 pn_vis_set_root_actuator (PnVis *vis, PnActuator *actuator)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
210 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
211 g_return_if_fail (vis != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
212 g_return_if_fail (PN_IS_VIS (vis));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
213 g_return_if_fail (actuator != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
214 g_return_if_fail (PN_IS_ACTUATOR (actuator));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
215
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
216 if (vis->root_actuator)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
217 pn_object_unref (PN_OBJECT (vis->root_actuator));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
218
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
219 vis->root_actuator = actuator;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
220
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
221 pn_object_ref (PN_OBJECT (actuator));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
222 pn_object_sink (PN_OBJECT (actuator));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
223 pn_user_object_set_owner (PN_USER_OBJECT (actuator), PN_USER_OBJECT (vis));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
224
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
225 pn_actuator_prepare (actuator, vis->root_image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
226 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
227
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
228 PnActuator*
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
229 pn_vis_get_root_actuator (PnVis *vis)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
230 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
231 g_return_val_if_fail (vis != NULL, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
232 g_return_val_if_fail (PN_IS_VIS (vis), NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
233
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
234 return vis->root_actuator;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
235 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
236
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
237 void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
238 pn_vis_set_image_size (PnVis *vis, guint width, guint height)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
239 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
240 g_return_if_fail (vis != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
241 g_return_if_fail (PN_IS_VIS (vis));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
242
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
243 pn_image_set_size (vis->root_image, width, height);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
244
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
245 if (vis->root_actuator)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
246 pn_actuator_prepare (vis->root_actuator, vis->root_image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
247 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
248
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
249 gboolean
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
250 pn_vis_save_to_file (PnVis *vis, const gchar *fname)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
251 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
252 xmlDocPtr doc;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
253
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
254 doc = xmlNewDoc ("1.0");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
255
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
256 doc->xmlRootNode = xmlNewDocNode (doc, NULL, "BUG", NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
257
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
258 pn_user_object_save_thyself (PN_USER_OBJECT (vis), doc->xmlRootNode);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
259
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
260 if ( xmlSaveFile (fname, doc) == -1)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
261 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
262 xmlFreeDoc (doc);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
263 return FALSE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
264 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
265
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
266 xmlFreeDoc (doc);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
267 return TRUE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
268 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
269
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
270 gboolean
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
271 pn_vis_load_from_file (PnVis *vis, const gchar *fname)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
272 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
273 xmlDocPtr doc;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
274 xmlNodePtr root_node;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
275 xmlNsPtr ns;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
276
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
277 doc = xmlParseFile (fname);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
278 if (! doc)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
279 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
280 pn_error ("unable to parse file \"%s\"", fname);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
281 return FALSE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
282 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
283
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
284 root_node = xmlDocGetRootElement (doc);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
285 if (! root_node)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
286 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
287 pn_error ("no root element for file \"%s\"", fname);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
288 return FALSE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
289 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
290
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
291 ns = xmlSearchNsByHref (doc, root_node, PN_XML_NS_HREF);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
292 if (! ns)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
293 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
294 pn_error ("invalid file format: paranormal namespace not found");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
295 return FALSE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
296 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
297
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
298 if (g_strcasecmp (root_node->name, pn_user_object_get_name (PN_USER_OBJECT (vis))))
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
299 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
300 pn_error ("invalid file format: this file does not contain a Paranormal visualization");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
301 return FALSE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
302 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
303
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
304 pn_user_object_load_thyself (PN_USER_OBJECT (vis), root_node);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
305
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
306 return TRUE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
307 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
308
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
309 PnImage*
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
310 pn_vis_render (PnVis *vis, PnAudioData *audio_data)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
311 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
312 g_return_val_if_fail (vis != NULL, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
313 g_return_val_if_fail (PN_IS_VIS (vis), NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
314 g_return_val_if_fail (audio_data != NULL, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
315 /* g_return_val_if_fail (PN_IS_AUDIO_DATA (audio_data), NULL); */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
316
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
317 if (vis->root_actuator)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
318 pn_actuator_execute (vis->root_actuator,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
319 vis->root_image,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
320 audio_data);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
321
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
322 return vis->root_image;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
323 }