annotate Plugins/Visualization/paranormal/pn/pnvis.c @ 1527:e05ee730df6b trunk

[svn] - possible tweak to make loading work?
author nenolod
date Mon, 07 Aug 2006 23:16:21 -0700
parents 98a9c54459f0
children 4319ae8c8f69
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);
1526
98a9c54459f0 [svn] - a minor tweak to the save function
nenolod
parents: 1507
diff changeset
146 actuator_node = xmlNewChild (actuators_node, NULL, user_object->name, NULL);
1507
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;
1527
e05ee730df6b [svn] - possible tweak to make loading work?
nenolod
parents: 1526
diff changeset
158 xmlNodePtr actuators_node, actuator_node, tptr;
e05ee730df6b [svn] - possible tweak to make loading work?
nenolod
parents: 1526
diff changeset
159 PnActuator *root_actuator = NULL;
1507
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
1527
e05ee730df6b [svn] - possible tweak to make loading work?
nenolod
parents: 1526
diff changeset
182 /* Create a new actuator (reworked by nenolod) */
e05ee730df6b [svn] - possible tweak to make loading work?
nenolod
parents: 1526
diff changeset
183 for (tptr = actuator_node; tptr != NULL && root_actuator == NULL; tptr = tptr->next)
e05ee730df6b [svn] - possible tweak to make loading work?
nenolod
parents: 1526
diff changeset
184 {
e05ee730df6b [svn] - possible tweak to make loading work?
nenolod
parents: 1526
diff changeset
185 xmlNodePtr ttptr;
e05ee730df6b [svn] - possible tweak to make loading work?
nenolod
parents: 1526
diff changeset
186
e05ee730df6b [svn] - possible tweak to make loading work?
nenolod
parents: 1526
diff changeset
187 for (ttptr = tptr; ttptr != NULL; ttptr = ttptr->xmlChildrenNode)
e05ee730df6b [svn] - possible tweak to make loading work?
nenolod
parents: 1526
diff changeset
188 root_actuator = pn_actuator_factory_new_actuator_from_xml (ttptr);
e05ee730df6b [svn] - possible tweak to make loading work?
nenolod
parents: 1526
diff changeset
189 }
e05ee730df6b [svn] - possible tweak to make loading work?
nenolod
parents: 1526
diff changeset
190
e05ee730df6b [svn] - possible tweak to make loading work?
nenolod
parents: 1526
diff changeset
191 if (!root_actuator)
1507
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
192 pn_error ("Unknown actuator \"%s\"", actuator_node->name);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
193
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
194 pn_vis_set_root_actuator (vis, root_actuator);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
195
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
196 done:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
197 if (parent_class->load_thyself)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
198 parent_class->load_thyself (user_object, node);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
199 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
200
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
201 PnVis*
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
202 pn_vis_new (guint image_width, guint image_height)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
203 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
204 PnVis *vis;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
205
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
206 g_return_val_if_fail (image_width > 0, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
207 g_return_val_if_fail (image_height > 0, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
208
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
209 vis = (PnVis *) g_object_new (PN_TYPE_VIS, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
210 pn_vis_set_image_size (vis, image_width, image_height);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
211
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
212 return vis;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
213 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
214
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
215 void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
216 pn_vis_set_root_actuator (PnVis *vis, PnActuator *actuator)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
217 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
218 g_return_if_fail (vis != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
219 g_return_if_fail (PN_IS_VIS (vis));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
220 g_return_if_fail (actuator != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
221 g_return_if_fail (PN_IS_ACTUATOR (actuator));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
222
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
223 if (vis->root_actuator)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
224 pn_object_unref (PN_OBJECT (vis->root_actuator));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
225
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
226 vis->root_actuator = actuator;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
227
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
228 pn_object_ref (PN_OBJECT (actuator));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
229 pn_object_sink (PN_OBJECT (actuator));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
230 pn_user_object_set_owner (PN_USER_OBJECT (actuator), PN_USER_OBJECT (vis));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
231
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
232 pn_actuator_prepare (actuator, vis->root_image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
233 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
234
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
235 PnActuator*
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
236 pn_vis_get_root_actuator (PnVis *vis)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
237 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
238 g_return_val_if_fail (vis != NULL, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
239 g_return_val_if_fail (PN_IS_VIS (vis), NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
240
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
241 return vis->root_actuator;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
242 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
243
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
244 void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
245 pn_vis_set_image_size (PnVis *vis, guint width, guint height)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
246 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
247 g_return_if_fail (vis != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
248 g_return_if_fail (PN_IS_VIS (vis));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
249
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
250 pn_image_set_size (vis->root_image, width, height);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
251
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
252 if (vis->root_actuator)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
253 pn_actuator_prepare (vis->root_actuator, vis->root_image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
254 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
255
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
256 gboolean
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
257 pn_vis_save_to_file (PnVis *vis, const gchar *fname)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
258 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
259 xmlDocPtr doc;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
260
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
261 doc = xmlNewDoc ("1.0");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
262
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
263 doc->xmlRootNode = xmlNewDocNode (doc, NULL, "BUG", NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
264
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
265 pn_user_object_save_thyself (PN_USER_OBJECT (vis), doc->xmlRootNode);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
266
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
267 if ( xmlSaveFile (fname, doc) == -1)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
268 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
269 xmlFreeDoc (doc);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
270 return FALSE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
271 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
272
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
273 xmlFreeDoc (doc);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
274 return TRUE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
275 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
276
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
277 gboolean
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
278 pn_vis_load_from_file (PnVis *vis, const gchar *fname)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
279 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
280 xmlDocPtr doc;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
281 xmlNodePtr root_node;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
282 xmlNsPtr ns;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
283
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
284 doc = xmlParseFile (fname);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
285 if (! doc)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
286 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
287 pn_error ("unable to parse 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 root_node = xmlDocGetRootElement (doc);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
292 if (! root_node)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
293 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
294 pn_error ("no root element for file \"%s\"", fname);
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 ns = xmlSearchNsByHref (doc, root_node, PN_XML_NS_HREF);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
299 if (! ns)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
300 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
301 pn_error ("invalid file format: paranormal namespace not found");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
302 return FALSE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
303 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
304
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
305 if (g_strcasecmp (root_node->name, pn_user_object_get_name (PN_USER_OBJECT (vis))))
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
306 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
307 pn_error ("invalid file format: this file does not contain a Paranormal visualization");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
308 return FALSE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
309 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
310
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
311 pn_user_object_load_thyself (PN_USER_OBJECT (vis), root_node);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
312
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
313 return TRUE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
314 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
315
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
316 PnImage*
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
317 pn_vis_render (PnVis *vis, PnAudioData *audio_data)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
318 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
319 g_return_val_if_fail (vis != NULL, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
320 g_return_val_if_fail (PN_IS_VIS (vis), NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
321 g_return_val_if_fail (audio_data != NULL, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
322 /* g_return_val_if_fail (PN_IS_AUDIO_DATA (audio_data), NULL); */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
323
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
324 if (vis->root_actuator)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
325 pn_actuator_execute (vis->root_actuator,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
326 vis->root_image,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
327 audio_data);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
328
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
329 return vis->root_image;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
330 }