annotate Plugins/Visualization/paranormal/pn/pnscope.c @ 1507:0c5fdcf3f947 trunk

[svn] - incomplete stuff
author nenolod
date Sun, 06 Aug 2006 01:53:29 -0700
parents
children
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 <math.h>
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
20 #include <glib.h>
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
21 #include "pnscope.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
22 #include "pnlistoption.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
23 #include "pnstringoption.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
24
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
25 enum
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
26 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
27 PN_SCOPE_DRAW_METHOD_DOTS = 0,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
28 PN_SCOPE_DRAW_METHOD_LINES
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
29 };
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
30
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
31 static void pn_scope_class_init (PnScopeClass *class);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
32 static void pn_scope_init (PnScope *scope,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
33 PnScopeClass *class);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
34 /* PnObject signals */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
35 static void pn_scope_destroy (PnObject *object);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
36
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
37 /* PnActuator methods */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
38 static void pn_scope_prepare (PnScope *scope,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
39 PnImage *image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
40 static void pn_scope_execute (PnScope *scope,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
41 PnImage *image,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
42 PnAudioData *audio_data);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
43
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
44 static PnActuatorClass *parent_class = NULL;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
45
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
46 GType
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
47 pn_scope_get_type (void)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
48 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
49 static GType scope_type = 0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
50
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
51 if (! scope_type)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
52 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
53 static const GTypeInfo scope_info =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
54 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
55 sizeof (PnScopeClass),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
56 NULL, /* base_init */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
57 NULL, /* base_finalize */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
58 (GClassInitFunc) pn_scope_class_init,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
59 NULL, /* class_finalize */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
60 NULL, /* class_data */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
61 sizeof (PnScope),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
62 0, /* n_preallocs */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
63 (GInstanceInitFunc) pn_scope_init
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
64 };
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
65
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
66 /* FIXME: should this be dynamic? */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
67 scope_type = g_type_register_static (PN_TYPE_ACTUATOR,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
68 "PnScope",
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
69 &scope_info,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
70 0);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
71 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
72 return scope_type;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
73 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
74
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
75 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
76 pn_scope_class_init (PnScopeClass *class)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
77 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
78 PnObjectClass *object_class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
79 PnUserObjectClass *user_object_class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
80 PnActuatorClass *actuator_class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
81
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
82 parent_class = g_type_class_peek_parent (class);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
83
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
84 object_class = (PnObjectClass *) class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
85 user_object_class = (PnUserObjectClass *) class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
86 actuator_class = (PnActuatorClass *) class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
87
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
88 /* PnObject signals */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
89 object_class->destroy = pn_scope_destroy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
90
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
91 /* PnActuator methods */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
92 actuator_class->prepare = (PnActuatorPrepFunc) pn_scope_prepare;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
93 actuator_class->execute = (PnActuatorExecFunc) pn_scope_execute;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
94 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
95
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
96 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
97 pn_scope_init (PnScope *scope, PnScopeClass *class)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
98 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
99 PnListOption *draw_method_opt;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
100 PnStringOption *init_script_opt;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
101 PnStringOption *frame_script_opt;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
102 PnStringOption *sample_script_opt;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
103
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
104 /* Set up the name and description */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
105 pn_user_object_set_name (PN_USER_OBJECT (scope), "Render.Scope");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
106 pn_user_object_set_description (PN_USER_OBJECT (scope),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
107 "A test scope actuator");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
108
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
109 /* Set up the options */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
110 draw_method_opt = pn_list_option_new ("draw_method", "The way the points will be drawn");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
111 init_script_opt = pn_string_option_new ("init_script", "The initialization script");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
112 frame_script_opt = pn_string_option_new ("frame_script", "The per-frame script");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
113 sample_script_opt = pn_string_option_new ("sample_script", "The per-sample script");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
114
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
115 pn_list_option_add_item (draw_method_opt, "Dots");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
116 pn_list_option_add_item (draw_method_opt, "Lines");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
117
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
118 pn_actuator_add_option (PN_ACTUATOR (scope), PN_OPTION (draw_method_opt));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
119 pn_actuator_add_option (PN_ACTUATOR (scope), PN_OPTION (init_script_opt));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
120 pn_actuator_add_option (PN_ACTUATOR (scope), PN_OPTION (frame_script_opt));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
121 pn_actuator_add_option (PN_ACTUATOR (scope), PN_OPTION (sample_script_opt));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
122
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
123 /* Create the script objects and symbol table */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
124 scope->init_script = pn_script_new ();
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
125 pn_object_ref (PN_OBJECT (scope->init_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
126 pn_object_sink (PN_OBJECT (scope->init_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
127 scope->frame_script = pn_script_new ();
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
128 pn_object_ref (PN_OBJECT (scope->frame_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
129 pn_object_sink (PN_OBJECT (scope->frame_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
130 scope->sample_script = pn_script_new ();
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
131 pn_object_ref (PN_OBJECT (scope->sample_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
132 pn_object_sink (PN_OBJECT (scope->sample_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
133 scope->symbol_table = pn_symbol_table_new ();
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
134 pn_object_ref (PN_OBJECT (scope->symbol_table));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
135 pn_object_sink (PN_OBJECT (scope->symbol_table));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
136
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
137 /* Get the variables from the symbol table */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
138 scope->samples_var = pn_symbol_table_ref_variable_by_name (scope->symbol_table, "samples");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
139 scope->width_var = pn_symbol_table_ref_variable_by_name (scope->symbol_table, "width");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
140 scope->height_var = pn_symbol_table_ref_variable_by_name (scope->symbol_table, "height");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
141 scope->x_var = pn_symbol_table_ref_variable_by_name (scope->symbol_table, "x");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
142 scope->y_var = pn_symbol_table_ref_variable_by_name (scope->symbol_table, "y");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
143 scope->iteration_var = pn_symbol_table_ref_variable_by_name (scope->symbol_table, "iteration");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
144 scope->value_var = pn_symbol_table_ref_variable_by_name (scope->symbol_table, "value");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
145 scope->red_var = pn_symbol_table_ref_variable_by_name (scope->symbol_table, "red");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
146 scope->green_var = pn_symbol_table_ref_variable_by_name (scope->symbol_table, "green");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
147 scope->blue_var = pn_symbol_table_ref_variable_by_name (scope->symbol_table, "blue");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
148 scope->volume_var = pn_symbol_table_ref_variable_by_name (scope->symbol_table, "volume");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
149
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
150 PN_VARIABLE_VALUE (scope->samples_var) = 0.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
151 PN_VARIABLE_VALUE (scope->red_var) = 1.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
152 PN_VARIABLE_VALUE (scope->green_var) = 1.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
153 PN_VARIABLE_VALUE (scope->blue_var) = 1.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
154 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
155
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
156 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
157 pn_scope_destroy (PnObject *object)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
158 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
159 PnScope *scope;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
160
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
161 scope = (PnScope *) object;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
162
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
163 pn_object_unref (PN_OBJECT (scope->init_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
164 pn_object_unref (PN_OBJECT (scope->frame_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
165 pn_object_unref (PN_OBJECT (scope->sample_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
166 pn_object_unref (PN_OBJECT (scope->symbol_table));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
167 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
168
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
169 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
170 pn_scope_prepare (PnScope *scope, PnImage *image)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
171 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
172 PnStringOption *init_script_opt;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
173 PnStringOption *frame_script_opt;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
174 PnStringOption *sample_script_opt;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
175
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
176 g_return_if_fail (scope != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
177 g_return_if_fail (PN_IS_SCOPE (scope));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
178 g_return_if_fail (image != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
179 g_return_if_fail (PN_IS_IMAGE (image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
180
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
181 /* Parse the script strings */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
182 init_script_opt = (PnStringOption *) pn_actuator_get_option_by_index (PN_ACTUATOR (scope),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
183 PN_SCOPE_OPT_INIT_SCRIPT);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
184 frame_script_opt = (PnStringOption *) pn_actuator_get_option_by_index (PN_ACTUATOR (scope),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
185 PN_SCOPE_OPT_FRAME_SCRIPT);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
186 sample_script_opt = (PnStringOption *) pn_actuator_get_option_by_index (PN_ACTUATOR (scope),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
187 PN_SCOPE_OPT_SAMPLE_SCRIPT);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
188
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
189 pn_script_parse_string (scope->init_script,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
190 scope->symbol_table,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
191 pn_string_option_get_value (init_script_opt));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
192 pn_script_parse_string (scope->frame_script,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
193 scope->symbol_table,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
194 pn_string_option_get_value (frame_script_opt));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
195 pn_script_parse_string (scope->sample_script,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
196 scope->symbol_table,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
197 pn_string_option_get_value (sample_script_opt));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
198
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
199 /* Set up the width and height in-script variables */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
200 PN_VARIABLE_VALUE (scope->width_var) = pn_image_get_width (image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
201 PN_VARIABLE_VALUE (scope->height_var) = pn_image_get_height (image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
202
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
203 /* Run the init script */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
204 pn_script_execute (scope->init_script);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
205
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
206 if (parent_class->prepare)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
207 parent_class->prepare (PN_ACTUATOR (scope), image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
208 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
209
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
210 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
211 pn_scope_execute (PnScope *scope, PnImage *image, PnAudioData *audio_data)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
212 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
213 gdouble i, samples;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
214 gdouble half_width, neg_half_height, increment = 0.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
215 PnColor color = { 255, 255, 255 };
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
216 guint last_x = 0, last_y = 0, x, y;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
217 PnListOption *draw_method_opt;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
218 gboolean use_lines;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
219
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
220 g_return_if_fail (scope != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
221 g_return_if_fail (PN_IS_SCOPE (scope));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
222 g_return_if_fail (image != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
223 g_return_if_fail (PN_IS_IMAGE (image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
224 g_return_if_fail (audio_data != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
225 g_return_if_fail (PN_IS_AUDIO_DATA (audio_data));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
226
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
227 half_width = (((gdouble) pn_image_get_width (image)) - 1.0) * 0.5;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
228 neg_half_height = (((gdouble) pn_image_get_height (image)) - 1.0) * -0.5;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
229
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
230 draw_method_opt = (PnListOption *) pn_actuator_get_option_by_index (PN_ACTUATOR (scope),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
231 PN_SCOPE_OPT_DRAW_METHOD);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
232 use_lines = pn_list_option_get_index (draw_method_opt) == PN_SCOPE_DRAW_METHOD_LINES;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
233
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
234 /* Set the volume in-script variable */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
235 PN_VARIABLE_VALUE (scope->volume_var) = pn_audio_data_get_volume (audio_data);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
236
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
237 /* Run the frame script */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
238 pn_script_execute (scope->frame_script);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
239
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
240 /* Go through and draw each sample-point */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
241 samples = PN_VARIABLE_VALUE (scope->samples_var);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
242 if (samples > 1)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
243 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
244 increment = 1 / (samples - 1);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
245 PN_VARIABLE_VALUE (scope->iteration_var) = -increment;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
246 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
247 else if (samples > 0)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
248 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
249 increment = 0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
250 PN_VARIABLE_VALUE (scope->iteration_var) = 0.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
251 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
252 for (i=0; i < samples; i++)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
253 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
254 /* Set up the in-script variables */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
255 PN_VARIABLE_VALUE (scope->x_var) = 2.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
256 PN_VARIABLE_VALUE (scope->y_var) = 2.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
257 PN_VARIABLE_VALUE (scope->iteration_var) += increment;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
258
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
259 /* FIXME: This should be done in PnAudioData */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
260 /* Interpolate the sample value */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
261 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
262 gdouble sample, bias;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
263 guint lsamp, usamp;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
264
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
265 sample = (gdouble)PN_AUDIO_DATA_PCM_SAMPLES(audio_data)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
266 * (gdouble)PN_VARIABLE_VALUE (scope->iteration_var);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
267
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
268 lsamp = (guint) sample;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
269 if (lsamp != sample)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
270 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
271 usamp = lsamp + 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
272
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
273 bias = sample - (gdouble) lsamp;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
274
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
275 PN_VARIABLE_VALUE (scope->value_var) =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
276 (PN_AUDIO_DATA_PCM_DATA(audio_data, PN_CHANNEL_LEFT)[lsamp] * (1 - bias))
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
277 + (PN_AUDIO_DATA_PCM_DATA(audio_data, PN_CHANNEL_LEFT)[lsamp] * bias);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
278 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
279 else
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
280 PN_VARIABLE_VALUE (scope->value_var) =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
281 PN_AUDIO_DATA_PCM_DATA (audio_data, PN_CHANNEL_LEFT)[lsamp];
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 /* Run the sample script */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
285 pn_script_execute (scope->sample_script);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
286
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
287 /* Get the color */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
288 color.red = CLAMP (PN_VARIABLE_VALUE (scope->red_var), 0.0, 1.0) * 255.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
289 color.green = CLAMP (PN_VARIABLE_VALUE (scope->green_var), 0.0, 1.0) * 255.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
290 color.blue = CLAMP (PN_VARIABLE_VALUE (scope->blue_var), 0.0, 1.0) * 255.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
291
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
292 /* Render the point */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
293 x = rint ((PN_VARIABLE_VALUE (scope->x_var) + 1.0) * ((gdouble) half_width ));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
294 y = rint ((PN_VARIABLE_VALUE (scope->y_var) - 1.0) * ((gdouble) neg_half_height));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
295
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
296 if (use_lines)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
297 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
298 if (i > 0)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
299 pn_image_render_line (image, last_x, last_y, x, y, color);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
300
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
301 last_x = x;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
302 last_y = y;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
303 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
304 else
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
305 pn_image_render_pixel (image, x, y, color);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
306 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
307
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
308 if (parent_class->execute)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
309 parent_class->execute (PN_ACTUATOR (scope), image, audio_data);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
310 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
311
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
312 PnScope*
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
313 pn_scope_new (void)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
314 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
315 return (PnScope *) g_object_new (PN_TYPE_SCOPE, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
316 }