1507
|
1 /* Paranormal - A highly customizable audio visualization library
|
|
2 * Copyright (C) 2001 Jamie Gennis <jgennis@mindspring.com>
|
|
3 *
|
|
4 * This library is free software; you can redistribute it and/or
|
|
5 * modify it under the terms of the GNU Library General Public
|
|
6 * License as published by the Free Software Foundation; either
|
|
7 * version 2 of the License, or (at your option) any later version.
|
|
8 *
|
|
9 * This library is distributed in the hope that it will be useful,
|
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12 * Library General Public License for more details.
|
|
13 *
|
|
14 * You should have received a copy of the GNU Library General Public
|
|
15 * License along with this library; if not, write to the Free
|
|
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17 */
|
|
18
|
|
19 #include <glib.h>
|
|
20 #include "pntestactuator.h"
|
|
21 #include "pnbooleanoption.h"
|
|
22 #include "pnintegeroption.h"
|
|
23 #include "pnfloatoption.h"
|
|
24 #include "pnstringoption.h"
|
|
25 #include "pnerror.h"
|
|
26
|
|
27 static void pn_test_actuator_class_init (PnTestActuatorClass *class);
|
|
28 static void pn_test_actuator_init (PnTestActuator *test_actuator,
|
|
29 PnTestActuatorClass *class);
|
|
30 /* PnActuator methods */
|
|
31 static void pn_test_actuator_prepare (PnTestActuator *test_actuator,
|
|
32 PnImage *image);
|
|
33 static void pn_test_actuator_execute (PnTestActuator *test_actuator,
|
|
34 PnImage *image,
|
|
35 PnAudioData *audio_data);
|
|
36
|
|
37 static PnActuatorClass *parent_class = NULL;
|
|
38
|
|
39 GType
|
|
40 pn_test_actuator_get_type (void)
|
|
41 {
|
|
42 static GType test_actuator_type = 0;
|
|
43
|
|
44 if (! test_actuator_type)
|
|
45 {
|
|
46 static const GTypeInfo test_actuator_info =
|
|
47 {
|
|
48 sizeof (PnTestActuatorClass),
|
|
49 NULL, /* base_init */
|
|
50 NULL, /* base_finalize */
|
|
51 (GClassInitFunc) pn_test_actuator_class_init,
|
|
52 NULL, /* class_finalize */
|
|
53 NULL, /* class_data */
|
|
54 sizeof (PnTestActuator),
|
|
55 0, /* n_preallocs */
|
|
56 (GInstanceInitFunc) pn_test_actuator_init
|
|
57 };
|
|
58
|
|
59 /* FIXME: should this be dynamic? */
|
|
60 test_actuator_type = g_type_register_static (PN_TYPE_ACTUATOR,
|
|
61 "PnTestActuator",
|
|
62 &test_actuator_info,
|
|
63 0);
|
|
64 }
|
|
65 return test_actuator_type;
|
|
66 }
|
|
67
|
|
68 static void
|
|
69 pn_test_actuator_class_init (PnTestActuatorClass *class)
|
|
70 {
|
|
71 PnObjectClass *object_class;
|
|
72 PnUserObjectClass *user_object_class;
|
|
73 PnActuatorClass *actuator_class;
|
|
74
|
|
75 parent_class = g_type_class_peek_parent (class);
|
|
76
|
|
77 object_class = (PnObjectClass *) class;
|
|
78 user_object_class = (PnUserObjectClass *) class;
|
|
79 actuator_class = (PnActuatorClass *) class;
|
|
80
|
|
81 /* PnActuator methods */
|
|
82 actuator_class->prepare = (PnActuatorPrepFunc) pn_test_actuator_prepare;
|
|
83 actuator_class->execute = (PnActuatorExecFunc) pn_test_actuator_execute;
|
|
84 }
|
|
85
|
|
86 static void
|
|
87 pn_test_actuator_init (PnTestActuator *test_actuator, PnTestActuatorClass *class)
|
|
88 {
|
|
89 PnBooleanOption *test_bool_opt;
|
|
90 PnIntegerOption *test_int_opt;
|
|
91 PnFloatOption *test_float_opt;
|
|
92 PnStringOption *test_str_opt;
|
|
93
|
|
94 /* Set up the name and description */
|
|
95 pn_user_object_set_name (PN_USER_OBJECT (test_actuator), "Test.Test");
|
|
96 pn_user_object_set_description (PN_USER_OBJECT (test_actuator),
|
|
97 "An actuator to test the functionality of the PnActuator base class");
|
|
98
|
|
99 /* Set up the options */
|
|
100 test_bool_opt = pn_boolean_option_new ("test_boolean_option", "A boolean test option");
|
|
101 pn_boolean_option_set_value (test_bool_opt, TRUE);
|
|
102
|
|
103 test_int_opt = pn_integer_option_new ("test_integer_option", "An integer test option");
|
|
104 pn_integer_option_set_value (test_int_opt, 32);
|
|
105 pn_integer_option_set_min (test_int_opt, 16);
|
|
106 pn_integer_option_set_max (test_int_opt, 64);
|
|
107
|
|
108 test_float_opt = pn_float_option_new ("test_float_option", "A float test option");
|
|
109 pn_float_option_set_value (test_float_opt, 0.7);
|
|
110 pn_float_option_set_min (test_float_opt, 0.0);
|
|
111 pn_float_option_set_max (test_float_opt, 1.0);
|
|
112
|
|
113 test_str_opt = pn_string_option_new ("test_string_option", "A string test option");
|
|
114
|
|
115 pn_actuator_add_option (PN_ACTUATOR (test_actuator), PN_OPTION (test_bool_opt));
|
|
116 pn_actuator_add_option (PN_ACTUATOR (test_actuator), PN_OPTION (test_int_opt));
|
|
117 pn_actuator_add_option (PN_ACTUATOR (test_actuator), PN_OPTION (test_float_opt));
|
|
118 pn_actuator_add_option (PN_ACTUATOR (test_actuator), PN_OPTION (test_str_opt));
|
|
119 }
|
|
120
|
|
121 static void
|
|
122 pn_test_actuator_prepare (PnTestActuator *test_actuator, PnImage *image)
|
|
123 {
|
|
124 g_return_if_fail (test_actuator != NULL);
|
|
125 g_return_if_fail (PN_IS_TEST_ACTUATOR (test_actuator));
|
|
126 g_return_if_fail (image != NULL);
|
|
127 g_return_if_fail (PN_IS_IMAGE (image));
|
|
128
|
|
129 pn_error ("pn_test_actuator_prepare called");
|
|
130 }
|
|
131
|
|
132 static void
|
|
133 pn_test_actuator_execute (PnTestActuator *test_actuator, PnImage *image,
|
|
134 PnAudioData *audio_data)
|
|
135 {
|
|
136 PnOption *test_bool_opt, *test_int_opt, *test_float_opt, *test_str_opt;
|
|
137 PnColor color = { 0, 0, 0, 0 };
|
|
138 guint i;
|
|
139
|
|
140 g_return_if_fail (test_actuator != NULL);
|
|
141 g_return_if_fail (PN_IS_TEST_ACTUATOR (test_actuator));
|
|
142 g_return_if_fail (image != NULL);
|
|
143 g_return_if_fail (PN_IS_IMAGE (image));
|
|
144 g_return_if_fail (audio_data != NULL);
|
|
145 /* g_return_if_fail (PN_IS_AUDIO_DATA (audio_data)); */
|
|
146
|
|
147 test_bool_opt = pn_actuator_get_option_by_index (PN_ACTUATOR (test_actuator),
|
|
148 PN_TEST_ACTUATOR_OPT_TEST_BOOL);
|
|
149 test_int_opt = pn_actuator_get_option_by_index (PN_ACTUATOR (test_actuator),
|
|
150 PN_TEST_ACTUATOR_OPT_TEST_INT);
|
|
151 test_float_opt = pn_actuator_get_option_by_index (PN_ACTUATOR (test_actuator),
|
|
152 PN_TEST_ACTUATOR_OPT_TEST_FLOAT);
|
|
153 test_str_opt = pn_actuator_get_option_by_index (PN_ACTUATOR (test_actuator),
|
|
154 PN_TEST_ACTUATOR_OPT_TEST_STR);
|
|
155
|
|
156 /* printf ("pn_test_actuator_execute: %s = %d\n", */
|
|
157 /* pn_user_object_get_name (PN_USER_OBJECT (test_bool_opt)), */
|
|
158 /* pn_boolean_option_get_value (PN_BOOLEAN_OPTION (test_bool_opt))); */
|
|
159 /* printf ("pn_test_actuator_execute: %s = %d\n", */
|
|
160 /* pn_user_object_get_name (PN_USER_OBJECT (test_int_opt)), */
|
|
161 /* pn_integer_option_get_value (PN_INTEGER_OPTION (test_int_opt))); */
|
|
162 /* printf ("pn_test_actuator_execute: %s = %f\n", */
|
|
163 /* pn_user_object_get_name (PN_USER_OBJECT (test_float_opt)), */
|
|
164 /* pn_float_option_get_value (PN_FLOAT_OPTION (test_float_opt))); */
|
|
165 /* printf ("pn_test_actuator_execute: %s = \"%s\"\n", */
|
|
166 /* pn_user_object_get_name (PN_USER_OBJECT (test_str_opt)), */
|
|
167 /* pn_string_option_get_value (PN_STRING_OPTION (test_str_opt))); */
|
|
168
|
|
169 for (i=0; i<pn_image_get_width (image) * 64; i++)
|
|
170 {
|
|
171 color.red = i % 256;
|
|
172 pn_image_render_pixel_by_offset (image, i, color);
|
|
173 }
|
|
174 }
|
|
175
|
|
176 PnTestActuator*
|
|
177 pn_test_actuator_new (void)
|
|
178 {
|
|
179 return (PnTestActuator *) g_object_new (PN_TYPE_TEST_ACTUATOR, NULL);
|
|
180 }
|