| 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_jakdaw.c,v 1.26 2006/01/27 20:19:16 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 "feedback.h" |
| 34 |
#include "plotter.h" |
| 35 |
|
| 36 |
#include <libvisual/libvisual.h> |
| 37 |
|
| 38 |
int act_jakdaw_init (VisPluginData *plugin); |
| 39 |
int act_jakdaw_cleanup (VisPluginData *plugin); |
| 40 |
int act_jakdaw_requisition (VisPluginData *plugin, int *width, int *height); |
| 41 |
int act_jakdaw_dimension (VisPluginData *plugin, VisVideo *video, int width, int height); |
| 42 |
int act_jakdaw_events (VisPluginData *plugin, VisEventQueue *events); |
| 43 |
VisPalette *act_jakdaw_palette (VisPluginData *plugin); |
| 44 |
int act_jakdaw_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_jakdaw_requisition, |
| 52 |
.palette = act_jakdaw_palette, |
| 53 |
.render = act_jakdaw_render, |
| 54 |
.vidoptions.depth = VISUAL_VIDEO_DEPTH_32BIT |
| 55 |
}}; |
| 56 |
|
| 57 |
static VisPluginInfo info[] = {{ |
| 58 |
.type = VISUAL_PLUGIN_TYPE_ACTOR, |
| 59 |
|
| 60 |
.plugname = "jakdaw", |
| 61 |
.name = "Jakdaw plugin", |
| 62 |
.author = N_("Original by: Christopher Wilson <[email protected]>, Port by: Dennis Smit <[email protected]>"), |
| 63 |
.version = "0.0.1", |
| 64 |
.about = N_("jakdaw visual plugin"), |
| 65 |
.help = N_("This is the libvisual port of the xmms Jakdaw plugin"), |
| 66 |
.license = VISUAL_PLUGIN_LICENSE_GPL, |
| 67 |
|
| 68 |
.init = act_jakdaw_init, |
| 69 |
.cleanup = act_jakdaw_cleanup, |
| 70 |
.events = act_jakdaw_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_jakdaw_init (VisPluginData *plugin) |
| 81 |
{ |
| 82 |
JakdawPrivate *priv; |
| 83 |
VisParamContainer *paramcontainer = visual_plugin_get_params (plugin); |
| 84 |
|
| 85 |
static VisParamEntry params[] = { |
| 86 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("zoom mode", FEEDBACK_ZOOMRIPPLE), |
| 87 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("plotter trigger", PLOTTER_COLOUR_MUSICTRIG), |
| 88 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("plotter type", PLOTTER_SCOPE_LINES), |
| 89 |
VISUAL_PARAM_LIST_END |
| 90 |
}; |
| 91 |
|
| 92 |
static VisParamEntry zoomparamchoices[] = { |
| 93 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("Zoom ripple", FEEDBACK_ZOOMRIPPLE), |
| 94 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("Blur only", FEEDBACK_BLURONLY), |
| 95 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("Zoom rotate", FEEDBACK_ZOOMROTATE), |
| 96 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("Scroll", FEEDBACK_SCROLL), |
| 97 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("Into screen", FEEDBACK_INTOSCREEN), |
| 98 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("Ripple", FEEDBACK_NEWRIPPLE), |
| 99 |
VISUAL_PARAM_LIST_END |
| 100 |
}; |
| 101 |
|
| 102 |
static VisParamEntry colorparamchoices[] = { |
| 103 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("Solid", PLOTTER_COLOUR_SOLID), |
| 104 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("Random", PLOTTER_COLOUR_RANDOM), |
| 105 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("On music", PLOTTER_COLOUR_MUSICTRIG), |
| 106 |
VISUAL_PARAM_LIST_END |
| 107 |
}; |
| 108 |
|
| 109 |
|
| 110 |
static VisParamEntry scopeparamchoices[] = { |
| 111 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("Lines", PLOTTER_SCOPE_LINES), |
| 112 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("Dots", PLOTTER_SCOPE_DOTS), |
| 113 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("Solid", PLOTTER_SCOPE_SOLID), |
| 114 |
VISUAL_PARAM_LIST_ENTRY_INTEGER ("Nothing", PLOTTER_SCOPE_NOTHING), |
| 115 |
VISUAL_PARAM_LIST_END |
| 116 |
}; |
| 117 |
|
| 118 |
/* UI vars */ |
| 119 |
VisUIWidget *table; |
| 120 |
VisUIWidget *label1; |
| 121 |
VisUIWidget *label2; |
| 122 |
VisUIWidget *label3; |
| 123 |
VisUIWidget *popup1; |
| 124 |
VisUIWidget *popup2; |
| 125 |
VisUIWidget *popup3; |
| 126 |
|
| 127 |
#if ENABLE_NLS |
| 128 |
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); |
| 129 |
#endif |
| 130 |
|
| 131 |
priv = visual_mem_new0 (JakdawPrivate, 1); |
| 132 |
visual_object_set_private (VISUAL_OBJECT (plugin), priv); |
| 133 |
|
| 134 |
priv->rcontext = visual_plugin_get_random_context (plugin); |
| 135 |
|
| 136 |
priv->decay_rate = 1; |
| 137 |
|
| 138 |
priv->zoom_ripplesize = 32; |
| 139 |
priv->zoom_ripplefact = 0.1; |
| 140 |
priv->zoom_zoomfact = 0.9; |
| 141 |
|
| 142 |
priv->plotter_amplitude = 0.5; |
| 143 |
|
| 144 |
/* FIXME make param of this one as well */ |
| 145 |
priv->plotter_scopecolor = 0xff00ff; |
| 146 |
|
| 147 |
visual_param_container_add_many (paramcontainer, params); |
| 148 |
|
| 149 |
table = visual_ui_table_new (3, 2); |
| 150 |
|
| 151 |
label1 = visual_ui_label_new (_("Blur mode:"), FALSE); |
| 152 |
label2 = visual_ui_label_new (_("Plotter color:"), FALSE); |
| 153 |
label3 = visual_ui_label_new (_("Plotter type:"), FALSE); |
| 154 |
|
| 155 |
popup1 = visual_ui_popup_new (); |
| 156 |
visual_ui_widget_set_tooltip (popup1, _("The method of blurring")); |
| 157 |
visual_ui_mutator_set_param (VISUAL_UI_MUTATOR (popup1), visual_param_container_get (paramcontainer, "zoom mode")); |
| 158 |
visual_ui_choice_add_many (VISUAL_UI_CHOICE (popup1), zoomparamchoices); |
| 159 |
|
| 160 |
popup2 = visual_ui_popup_new (); |
| 161 |
visual_ui_widget_set_tooltip (popup2, _("The color of the plotter")); |
| 162 |
visual_ui_mutator_set_param (VISUAL_UI_MUTATOR (popup2), visual_param_container_get (paramcontainer, "plotter trigger")); |
| 163 |
visual_ui_choice_add_many (VISUAL_UI_CHOICE (popup2), colorparamchoices); |
| 164 |
|
| 165 |
popup3 = visual_ui_popup_new (); |
| 166 |
visual_ui_widget_set_tooltip (popup3, _("The plotter's shape")); |
| 167 |
visual_ui_mutator_set_param (VISUAL_UI_MUTATOR (popup3), visual_param_container_get (paramcontainer, "plotter type")); |
| 168 |
visual_ui_choice_add_many (VISUAL_UI_CHOICE (popup3), scopeparamchoices); |
| 169 |
|
| 170 |
visual_ui_table_attach (VISUAL_UI_TABLE (table), label1, 0, 0); |
| 171 |
visual_ui_table_attach (VISUAL_UI_TABLE (table), popup1, 0, 1); |
| 172 |
|
| 173 |
visual_ui_table_attach (VISUAL_UI_TABLE (table), label2, 1, 0); |
| 174 |
visual_ui_table_attach (VISUAL_UI_TABLE (table), popup2, 1, 1); |
| 175 |
|
| 176 |
visual_ui_table_attach (VISUAL_UI_TABLE (table), label3, 2, 0); |
| 177 |
visual_ui_table_attach (VISUAL_UI_TABLE (table), popup3, 2, 1); |
| 178 |
|
| 179 |
visual_plugin_set_userinterface (plugin, table); |
| 180 |
|
| 181 |
priv->pcmbuf = visual_buffer_new_allocate (512 * sizeof (float), visual_buffer_destroyer_free); |
| 182 |
priv->freqbuf = visual_buffer_new_allocate (256 * sizeof (float), visual_buffer_destroyer_free); |
| 183 |
|
| 184 |
return 0; |
| 185 |
} |
| 186 |
|
| 187 |
int act_jakdaw_cleanup (VisPluginData *plugin) |
| 188 |
{ |
| 189 |
JakdawPrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 190 |
VisUIWidget *ui; |
| 191 |
|
| 192 |
ui = visual_plugin_get_userinterface (plugin); |
| 193 |
visual_object_unref (VISUAL_OBJECT (ui)); |
| 194 |
|
| 195 |
_jakdaw_feedback_close (priv); |
| 196 |
|
| 197 |
visual_object_unref (VISUAL_OBJECT (priv->pcmbuf)); |
| 198 |
visual_object_unref (VISUAL_OBJECT (priv->freqbuf)); |
| 199 |
|
| 200 |
visual_mem_free (priv); |
| 201 |
|
| 202 |
return 0; |
| 203 |
} |
| 204 |
|
| 205 |
int act_jakdaw_requisition (VisPluginData *plugin, int *width, int *height) |
| 206 |
{ |
| 207 |
int reqw, reqh; |
| 208 |
|
| 209 |
reqw = *width; |
| 210 |
reqh = *height; |
| 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_jakdaw_dimension (VisPluginData *plugin, VisVideo *video, int width, int height) |
| 225 |
{ |
| 226 |
JakdawPrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 227 |
|
| 228 |
visual_video_set_dimension (video, width, height); |
| 229 |
|
| 230 |
priv->xres = width; |
| 231 |
priv->yres = height; |
| 232 |
|
| 233 |
_jakdaw_feedback_reset (priv, width, height); |
| 234 |
|
| 235 |
return 0; |
| 236 |
} |
| 237 |
|
| 238 |
int act_jakdaw_events (VisPluginData *plugin, VisEventQueue *events) |
| 239 |
{ |
| 240 |
JakdawPrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 241 |
VisEvent ev; |
| 242 |
VisParamEntry *param; |
| 243 |
|
| 244 |
while (visual_event_queue_poll (events, &ev)) { |
| 245 |
switch (ev.type) { |
| 246 |
case VISUAL_EVENT_RESIZE: |
| 247 |
act_jakdaw_dimension (plugin, ev.event.resize.video, |
| 248 |
ev.event.resize.width, ev.event.resize.height); |
| 249 |
break; |
| 250 |
|
| 251 |
case VISUAL_EVENT_PARAM: |
| 252 |
param = ev.event.param.param; |
| 253 |
|
| 254 |
visual_log (VISUAL_LOG_DEBUG, "Param changed: %s\n", param->name); |
| 255 |
|
| 256 |
if (visual_param_entry_is (param, "zoom mode")) { |
| 257 |
visual_log (VISUAL_LOG_DEBUG, "New value for the zoom mode param: %d\n", |
| 258 |
param->numeric.integer); |
| 259 |
|
| 260 |
priv->zoom_mode = visual_param_entry_get_integer (param); |
| 261 |
|
| 262 |
_jakdaw_feedback_reset (priv, priv->xres, priv->yres); |
| 263 |
} |
| 264 |
else if (visual_param_entry_is (param, "plotter trigger")) { |
| 265 |
visual_log (VISUAL_LOG_DEBUG, "New value for the plotter trigger param: %d\n", |
| 266 |
param->numeric.integer); |
| 267 |
|
| 268 |
priv->plotter_colortype = visual_param_entry_get_integer (param); |
| 269 |
|
| 270 |
} |
| 271 |
else if (visual_param_entry_is (param, "plotter type")) { |
| 272 |
visual_log (VISUAL_LOG_DEBUG, "New value for the plotter type param: %d\n", |
| 273 |
param->numeric.integer); |
| 274 |
|
| 275 |
priv->plotter_scopetype = visual_param_entry_get_integer (param); |
| 276 |
|
| 277 |
_jakdaw_feedback_reset (priv, priv->xres, priv->yres); |
| 278 |
} |
| 279 |
|
| 280 |
break; |
| 281 |
|
| 282 |
default: /* to avoid warnings */ |
| 283 |
break; |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
return 0; |
| 288 |
} |
| 289 |
|
| 290 |
VisPalette *act_jakdaw_palette (VisPluginData *plugin) |
| 291 |
{ |
| 292 |
return NULL; |
| 293 |
} |
| 294 |
|
| 295 |
int act_jakdaw_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio) |
| 296 |
{ |
| 297 |
JakdawPrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 298 |
uint32_t *vscr = visual_video_get_pixels (video); |
| 299 |
|
| 300 |
visual_audio_get_sample_mixed_simple (audio, priv->pcmbuf, 2, |
| 301 |
VISUAL_AUDIO_CHANNEL_LEFT, |
| 302 |
VISUAL_AUDIO_CHANNEL_RIGHT); |
| 303 |
|
| 304 |
visual_audio_get_spectrum_for_sample (priv->freqbuf, priv->pcmbuf, TRUE); |
| 305 |
|
| 306 |
_jakdaw_feedback_render (priv, vscr); |
| 307 |
_jakdaw_plotter_draw (priv, |
| 308 |
visual_buffer_get_data (priv->pcmbuf), |
| 309 |
visual_buffer_get_data (priv->freqbuf), vscr); |
| 310 |
|
| 311 |
return 0; |
| 312 |
} |
| 313 |
|