Debian Codegraph @

plugins/actor/bumpscope/actor_bumpscope.c

raw
1 /* Libvisual-plugins - Standard plugins for libvisual
2 *
3 * Copyright (C) 2004, 2005, 2006 Dennis Smit <[email protected]>
4 *
5 * Authors: Dennis Smit <[email protected]>
6 *
7 * $Id: actor_bumpscope.c,v 1.29 2006/01/27 20:19:14 synap Exp $
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <config.h>
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30 #include <string.h>
31 #include <gettext.h>
32
33 #include <libvisual/libvisual.h>
34
35 #include "actor_bumpscope.h"
36 #include "bump_scope.h"
37
38 int act_bumpscope_init (VisPluginData *plugin);
39 int act_bumpscope_cleanup (VisPluginData *plugin);
40 int act_bumpscope_requisition (VisPluginData *plugin, int *width, int *height);
41 int act_bumpscope_dimension (VisPluginData *plugin, VisVideo *video, int width, int height);
42 int act_bumpscope_events (VisPluginData *plugin, VisEventQueue *events);
43 VisPalette *act_bumpscope_palette (VisPluginData *plugin);
44 int act_bumpscope_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio);
45
46 VISUAL_PLUGIN_API_VERSION_VALIDATOR
47
48 const VisPluginInfo *get_plugin_info (int *count)
49 {
50 static VisActorPlugin actor[] = {{
51 .requisition = act_bumpscope_requisition,
52 .palette = act_bumpscope_palette,
53 .render = act_bumpscope_render,
54 .vidoptions.depth = VISUAL_VIDEO_DEPTH_8BIT
55 }};
56
57 static VisPluginInfo info[] = {{
58 .type = VISUAL_PLUGIN_TYPE_ACTOR,
59
60 .plugname = "bumpscope",
61 .name = "Bumpscope plugin",
62 .author = N_("Original by: Zinx Verituse <[email protected]>, Port by: Dennis Smit <[email protected]>"),
63 .version = "0.0.1",
64 .about = N_("Bumpscope visual plugin"),
65 .help = N_("This is the libvisual port of the xmms Bumpscope plugin"),
66 .license = VISUAL_PLUGIN_LICENSE_GPL,
67
68 .init = act_bumpscope_init,
69 .cleanup = act_bumpscope_cleanup,
70 .events = act_bumpscope_events,
71
72 .plugin = VISUAL_OBJECT (&actor[0])
73 }};
74
75 *count = sizeof (info) / sizeof (*info);
76
77 return info;
78 }
79
80 int act_bumpscope_init (VisPluginData *plugin)
81 {
82 BumpscopePrivate *priv;
83 VisParamContainer *paramcontainer = visual_plugin_get_params (plugin);
84
85 static VisParamEntry params[] = {
86 VISUAL_PARAM_LIST_ENTRY_COLOR ("color", 122, 204, 255),
87 VISUAL_PARAM_LIST_ENTRY_INTEGER ("light size", 256),
88 VISUAL_PARAM_LIST_ENTRY_INTEGER ("color cycle", TRUE),
89 VISUAL_PARAM_LIST_ENTRY_INTEGER ("moving light", TRUE),
90 VISUAL_PARAM_LIST_ENTRY_INTEGER ("diamond", FALSE),
91 VISUAL_PARAM_LIST_END
92 };
93
94 /* UI vars */
95 VisUIWidget *vbox;
96 VisUIWidget *hbox;
97 VisUIWidget *label1;
98 VisUIWidget *color;
99 VisUIWidget *separator;
100 VisUIWidget *slider;
101 VisUIWidget *numeric;
102 VisUIWidget *check1;
103 VisUIWidget *check2;
104 VisUIWidget *check3;
105
106 #if ENABLE_NLS
107 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
108 #endif
109
110 priv = visual_mem_new0 (BumpscopePrivate, 1);
111 visual_object_set_private (VISUAL_OBJECT (plugin), priv);
112 priv->phongres = 256;
113
114 priv->rcontext = visual_plugin_get_random_context (plugin);
115
116 visual_palette_allocate_colors (&priv->pal, 256);
117
118 visual_param_container_add_many (paramcontainer, params);
119
120 vbox = visual_ui_box_new (VISUAL_ORIENT_TYPE_VERTICAL);
121 hbox = visual_ui_box_new (VISUAL_ORIENT_TYPE_HORIZONTAL);
122
123 label1 = visual_ui_label_new ("Light size:", FALSE);
124
125 color = visual_ui_color_new ();
126 visual_ui_widget_set_tooltip (color, _("The color of the light"));
127 visual_ui_mutator_set_param (VISUAL_UI_MUTATOR (color), visual_param_container_get (paramcontainer, "color"));
128
129 separator = visual_ui_separator_new (VISUAL_ORIENT_TYPE_HORIZONTAL);
130
131 numeric = visual_ui_numeric_new ();
132 visual_ui_widget_set_tooltip (numeric, _("The size of the light"));
133 visual_ui_mutator_set_param (VISUAL_UI_MUTATOR (numeric), visual_param_container_get (paramcontainer, "light size"));
134 visual_ui_range_set_min (VISUAL_UI_RANGE (numeric), 8);
135 visual_ui_range_set_max (VISUAL_UI_RANGE (numeric), 512);
136 visual_ui_range_set_step (VISUAL_UI_RANGE (numeric), 8);
137 visual_ui_range_set_precision (VISUAL_UI_RANGE (numeric), 0);
138
139 slider = visual_ui_slider_new (FALSE);
140 visual_ui_widget_set_tooltip (slider, _("The size of the light"));
141 visual_ui_widget_set_size_request (slider, 200, -1);
142 visual_ui_mutator_set_param (VISUAL_UI_MUTATOR (slider), visual_param_container_get (paramcontainer, "light size"));
143 visual_ui_range_set_min (VISUAL_UI_RANGE (slider), 8);
144 visual_ui_range_set_max (VISUAL_UI_RANGE (slider), 512);
145 visual_ui_range_set_step (VISUAL_UI_RANGE (slider), 8);
146 visual_ui_range_set_precision (VISUAL_UI_RANGE (slider), 0);
147
148 check1 = visual_ui_checkbox_new (_("Cycling colors"), TRUE);
149 visual_ui_widget_set_tooltip (check1, _("Automatic cycling through colors"));
150 visual_ui_mutator_set_param (VISUAL_UI_MUTATOR (check1), visual_param_container_get (paramcontainer, "color cycle"));
151
152 check2 = visual_ui_checkbox_new (_("Moving light"), TRUE);
153 visual_ui_widget_set_tooltip (check2,
154 _("Automatic movement of the light, when disabled it's possible to select it " \
155 "using the mouse cursor"));
156 visual_ui_mutator_set_param (VISUAL_UI_MUTATOR (check2), visual_param_container_get (paramcontainer, "moving light"));
157
158 check3 = visual_ui_checkbox_new (_("Diamond"), TRUE);
159 visual_ui_widget_set_tooltip (check3, _("Diamond shaped light"));
160 visual_ui_mutator_set_param (VISUAL_UI_MUTATOR (check3), visual_param_container_get (paramcontainer, "diamond"));
161
162 visual_ui_box_pack (VISUAL_UI_BOX (hbox), label1);
163 visual_ui_box_pack (VISUAL_UI_BOX (hbox), slider);
164 visual_ui_box_pack (VISUAL_UI_BOX (hbox), numeric);
165
166 visual_ui_box_pack (VISUAL_UI_BOX (vbox), color);
167 visual_ui_box_pack (VISUAL_UI_BOX (vbox), separator);
168 visual_ui_box_pack (VISUAL_UI_BOX (vbox), hbox);
169 visual_ui_box_pack (VISUAL_UI_BOX (vbox), check1);
170 visual_ui_box_pack (VISUAL_UI_BOX (vbox), check2);
171 visual_ui_box_pack (VISUAL_UI_BOX (vbox), check3);
172
173 visual_plugin_set_userinterface (plugin, vbox);
174
175 priv->pcmbuf = visual_buffer_new_allocate (512 * sizeof (float), visual_buffer_destroyer_free);
176
177 return 0;
178 }
179
180 int act_bumpscope_cleanup (VisPluginData *plugin)
181 {
182 BumpscopePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
183 VisUIWidget *ui;
184
185 ui = visual_plugin_get_userinterface (plugin);
186 visual_object_unref (VISUAL_OBJECT (ui));
187
188 __bumpscope_cleanup (priv);
189
190 visual_palette_free_colors (&priv->pal);
191
192 visual_object_unref (VISUAL_OBJECT (priv->pcmbuf));
193
194 visual_mem_free (priv);
195
196 return 0;
197 }
198
199 int act_bumpscope_requisition (VisPluginData *plugin, int *width, int *height)
200 {
201 int reqw, reqh;
202
203 reqw = *width;
204 reqh = *height;
205
206 while (reqw % 4)
207 reqw--;
208
209 while (reqh % 2)
210 reqh--;
211
212 if (reqw < 32)
213 reqw = 32;
214
215 if (reqh < 32)
216 reqh = 32;
217
218 *width = reqw;
219 *height = reqh;
220
221 return 0;
222 }
223
224 int act_bumpscope_dimension (VisPluginData *plugin, VisVideo *video, int width, int height)
225 {
226 BumpscopePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
227
228 visual_video_set_dimension (video, width, height);
229
230 priv->video = video;
231
232 priv->width = width;
233 priv->height = height;
234
235 __bumpscope_cleanup (priv);
236 __bumpscope_init (priv);
237
238 return 0;
239 }
240
241 int act_bumpscope_events (VisPluginData *plugin, VisEventQueue *events)
242 {
243 BumpscopePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
244 VisEvent ev;
245 VisParamEntry *param;
246 VisColor *tmp;
247
248 while (visual_event_queue_poll (events, &ev)) {
249 switch (ev.type) {
250 case VISUAL_EVENT_RESIZE:
251 act_bumpscope_dimension (plugin, ev.event.resize.video,
252 ev.event.resize.width, ev.event.resize.height);
253 break;
254
255 case VISUAL_EVENT_MOUSEMOTION:
256 if (ev.event.mousemotion.state == VISUAL_MOUSE_DOWN) {
257 priv->light_x = ev.event.mousemotion.x;
258 priv->light_y = ev.event.mousemotion.y;
259 }
260
261 break;
262
263 case VISUAL_EVENT_PARAM:
264 param = ev.event.param.param;
265
266 if (visual_param_entry_is (param, "color")) {
267 tmp = visual_param_entry_get_color (param);
268 visual_color_copy (&priv->color, tmp);
269
270 __bumpscope_generate_palette (priv, &priv->color);
271 } else if (visual_param_entry_is (param, "light size")) {
272 priv->phongres = visual_param_entry_get_integer (param);
273
274 __bumpscope_cleanup (priv);
275 __bumpscope_init (priv);
276
277 } else if (visual_param_entry_is (param, "color cycle")) {
278 priv->color_cycle = visual_param_entry_get_integer (param);
279
280 } else if (visual_param_entry_is (param, "moving light")) {
281 priv->moving_light = visual_param_entry_get_integer (param);
282
283 } else if (visual_param_entry_is (param, "diamond")) {
284 priv->diamond = visual_param_entry_get_integer (param);
285
286 __bumpscope_generate_phongdat (priv);
287 }
288
289 break;
290
291 default: /* to avoid warnings */
292 break;
293 }
294 }
295
296 return 0;
297 }
298
299 VisPalette *act_bumpscope_palette (VisPluginData *plugin)
300 {
301 BumpscopePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
302
303 return &priv->pal;
304 }
305
306 int act_bumpscope_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio)
307 {
308 BumpscopePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
309 int i;
310
311 priv->video = video;
312
313 visual_audio_get_sample_mixed (audio, priv->pcmbuf, TRUE, 2,
314 VISUAL_AUDIO_CHANNEL_LEFT,
315 VISUAL_AUDIO_CHANNEL_RIGHT,
316 1.0,
317 1.0);
318
319 __bumpscope_render_pcm (priv, visual_buffer_get_data (priv->pcmbuf));
320
321 visual_mem_copy (visual_video_get_pixels (video), priv->rgb_buf2, visual_video_get_size (video));
322
323 priv->colorupdate++;
324
325 /* Let's not overload the color selector */
326 if (priv->colorupdate > 1)
327 priv->colorupdate = 0;
328
329 if (priv->colorchanged == TRUE && priv->colorupdate == 0) {
330 /* I couldn't hold myself */
331 visual_param_entry_set_color_by_color (
332 visual_param_container_get (
333 visual_plugin_get_params (plugin), "color"), &priv->color);
334 }
335
336 return 0;
337 }
338