| 1 |
/* Libvisual-plugins - Standard plugins for libvisual |
| 2 |
* |
| 3 |
* Copyright (C) 2000, 2001 Richard Ashburn <[email protected]> |
| 4 |
* |
| 5 |
* Authors: Richard Ashburn <[email protected]> |
| 6 |
* Jean-Christophe Hoelt <[email protected]> |
| 7 |
* Dennis Smit <[email protected]> |
| 8 |
* |
| 9 |
* $Id: actor_corona.cpp,v 1.17 2006/01/27 20:19:14 synap Exp $ |
| 10 |
* |
| 11 |
* This program is free software; you can redistribute it and/or modify |
| 12 |
* it under the terms of the GNU General Public License as |
| 13 |
* published by the Free Software Foundation; either version 2 |
| 14 |
* of the License, or (at your option) any later version. |
| 15 |
* |
| 16 |
* This program is distributed in the hope that it will be useful, |
| 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
* GNU General Public License for more details. |
| 20 |
* |
| 21 |
* You should have received a copy of the GNU General Public License |
| 22 |
* along with this program; if not, write to the Free Software |
| 23 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 |
*/ |
| 25 |
|
| 26 |
#include <config.h> |
| 27 |
|
| 28 |
#include <stdio.h> |
| 29 |
#include <stdlib.h> |
| 30 |
#include <unistd.h> |
| 31 |
#include <fcntl.h> |
| 32 |
#include <string.h> |
| 33 |
#include <gettext.h> |
| 34 |
|
| 35 |
#include <time.h> |
| 36 |
#include <sys/time.h> |
| 37 |
|
| 38 |
#include <libvisual/libvisual.h> |
| 39 |
|
| 40 |
#include "corona.h" |
| 41 |
#include "palette.h" |
| 42 |
|
| 43 |
static const int PALETTEDATA[][NB_PALETTES] = { |
| 44 |
{ 4, 85, 0xff0000, 170, 0xffff00, 224, 0xffffff, 240, 0xf8f8e0 }, // 0. fire |
| 45 |
{ 3, 85, 0xff, 170, 0xffff, 256, 0xffffff }, // 1. ice |
| 46 |
{ 1, 256, 0xffffff }, // 2. white |
| 47 |
{ 2, 128, 0xffffff, 256, 0xff }, // 3. white to blue |
| 48 |
{ 2, 128, 0x808080, 256, 0xff }, // 4. gray to blue |
| 49 |
{ 2, 128, 0xffff80, 256, 0xff }, // 5. yellow to blue |
| 50 |
{ 2, 128, 0xffffff, 256, 0xff0000 }, // 6. white to red |
| 51 |
{ 2, 128, 0xff, 256, 0xff0000 }, // 7. blue to red |
| 52 |
{ 2, 128, 0xff0000, 256, 0xff }, // 8. red to blue |
| 53 |
{ 2, 128, 0xff, 256, 0xffffff }, // 9. blue to white |
| 54 |
{ 2, 128, 0xffffff, 256, 0 }, // 10. white to black |
| 55 |
{ 2, 128, 0xff, 256, 0 }, // 11. blue to black |
| 56 |
{ 2, 128, 0xff0000, 256, 0 }, // 12. red to black |
| 57 |
{ 8, 32, 0xff, 64, 0, 96, 0xff, 128, 0, 192, 0xff, 256, 0 }, // 13. blue lines on black |
| 58 |
{ 8, 32, 0xffffff, 64, 0, 96, 0xffffff, 128, 0, 192, 0xffffff, 256, 0 }, // 14. white lines on black |
| 59 |
{ 3, 0, 0x000020, 128, 0x40, 256, 0xffffff }, // 15. night sky |
| 60 |
{ 2, 128, 0xff8080, 256, 0xff }, // 16. pink to blue |
| 61 |
{ 2, 0, 0xffffff, 256, 0 }, // 17. black on white |
| 62 |
{ 3, 0, 0xffffff, 128, 0, 256, 0xffffff }, // 18. black to white on white |
| 63 |
{ 3, 0, 0xffffff, 128, 0, 256, 0xc0c0ff }, // 19. heavenly blue |
| 64 |
{ 4, 120, 0x78, 128, 0xff0000, 136, 0x88, 256, 0xff }, // 20. blue, red line |
| 65 |
{ 2, 0, 0xffe0a0, 256, 0 }, // 21. twilight yellow |
| 66 |
{ 3, 0, 0xc0c0ff, 128, 0xa0a0a0, 256, 0xffffff } // 22. clouds |
| 67 |
}; |
| 68 |
|
| 69 |
typedef struct { |
| 70 |
VisTime oldtime; |
| 71 |
VisPalette pal; |
| 72 |
Corona *corona; /* The corona internal private struct */ |
| 73 |
PaletteCycler *pcyl; |
| 74 |
TimedLevel tl; |
| 75 |
} CoronaPrivate; |
| 76 |
|
| 77 |
extern "C" int lv_corona_init (VisPluginData *plugin); |
| 78 |
extern "C" int lv_corona_cleanup (VisPluginData *plugin); |
| 79 |
extern "C" int lv_corona_requisition (VisPluginData *plugin, int *width, int *height); |
| 80 |
extern "C" int lv_corona_dimension (VisPluginData *plugin, VisVideo *video, int width, int height); |
| 81 |
extern "C" int lv_corona_events (VisPluginData *plugin, VisEventQueue *events); |
| 82 |
extern "C" VisPalette *lv_corona_palette (VisPluginData *plugin); |
| 83 |
extern "C" int lv_corona_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio); |
| 84 |
|
| 85 |
VISUAL_PLUGIN_API_VERSION_VALIDATOR |
| 86 |
|
| 87 |
extern "C" const VisPluginInfo *get_plugin_info (int *count) |
| 88 |
{ |
| 89 |
static VisActorPlugin actor[1]; |
| 90 |
static VisPluginInfo info[1]; |
| 91 |
|
| 92 |
actor[0].requisition = lv_corona_requisition; |
| 93 |
actor[0].palette = lv_corona_palette; |
| 94 |
actor[0].render = lv_corona_render; |
| 95 |
actor[0].vidoptions.depth = VISUAL_VIDEO_DEPTH_8BIT; |
| 96 |
|
| 97 |
info[0].type = VISUAL_PLUGIN_TYPE_ACTOR; |
| 98 |
|
| 99 |
info[0].plugname = "corona"; |
| 100 |
info[0].name = "libvisual corona plugin"; |
| 101 |
info[0].author = "Jean-Christophe Hoelt <[email protected]> and Richard Ashburn <[email protected]>"; |
| 102 |
info[0].version = "0.1"; |
| 103 |
info[0].about = N_("Libvisual corona plugin"); |
| 104 |
info[0].help = N_("This plugin adds support for the neat corona plugin"); |
| 105 |
info[0].license = VISUAL_PLUGIN_LICENSE_GPL, |
| 106 |
|
| 107 |
info[0].init = lv_corona_init; |
| 108 |
info[0].cleanup = lv_corona_cleanup; |
| 109 |
info[0].events = lv_corona_events; |
| 110 |
|
| 111 |
info[0].plugin = VISUAL_OBJECT (&actor[0]); |
| 112 |
|
| 113 |
*count = sizeof (info) / sizeof (*info); |
| 114 |
|
| 115 |
return info; |
| 116 |
} |
| 117 |
|
| 118 |
extern "C" int lv_corona_init (VisPluginData *plugin) |
| 119 |
{ |
| 120 |
CoronaPrivate *priv; |
| 121 |
|
| 122 |
#if ENABLE_NLS |
| 123 |
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); |
| 124 |
#endif |
| 125 |
|
| 126 |
priv = new CoronaPrivate; |
| 127 |
visual_mem_set (priv, 0, sizeof (CoronaPrivate)); |
| 128 |
|
| 129 |
visual_object_set_private (VISUAL_OBJECT (plugin), priv); |
| 130 |
|
| 131 |
priv->corona = new Corona(); |
| 132 |
priv->pcyl = new PaletteCycler(PALETTEDATA, NB_PALETTES); |
| 133 |
priv->tl.timeStamp = 0; |
| 134 |
priv->tl.lastbeat = 0; |
| 135 |
priv->tl.state = normal_state; |
| 136 |
|
| 137 |
visual_time_get (&priv->oldtime); |
| 138 |
|
| 139 |
visual_palette_allocate_colors (&priv->pal, 256); |
| 140 |
|
| 141 |
return 0; |
| 142 |
} |
| 143 |
|
| 144 |
extern "C" int lv_corona_cleanup (VisPluginData *plugin) |
| 145 |
{ |
| 146 |
CoronaPrivate *priv = (CoronaPrivate *) visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 147 |
|
| 148 |
visual_palette_free_colors (&priv->pal); |
| 149 |
|
| 150 |
if (priv->corona != NULL) |
| 151 |
delete priv->corona; |
| 152 |
|
| 153 |
if (priv->pcyl != NULL) |
| 154 |
delete priv->pcyl; |
| 155 |
|
| 156 |
delete priv; |
| 157 |
|
| 158 |
return 0; |
| 159 |
} |
| 160 |
|
| 161 |
extern "C" int lv_corona_requisition (VisPluginData *plugin, int *width, int *height) |
| 162 |
{ |
| 163 |
int reqw, reqh; |
| 164 |
|
| 165 |
reqw = *width; |
| 166 |
reqh = *height; |
| 167 |
|
| 168 |
while (reqw % 4) |
| 169 |
reqw--; |
| 170 |
|
| 171 |
if (reqw < 32) |
| 172 |
reqw = 32; |
| 173 |
|
| 174 |
if (reqh < 32) |
| 175 |
reqh = 32; |
| 176 |
|
| 177 |
*width = reqw; |
| 178 |
*height = reqh; |
| 179 |
|
| 180 |
return 0; |
| 181 |
} |
| 182 |
|
| 183 |
extern "C" int lv_corona_dimension (VisPluginData *plugin, VisVideo *video, int width, int height) |
| 184 |
{ |
| 185 |
CoronaPrivate *priv = (CoronaPrivate *) visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 186 |
|
| 187 |
visual_video_set_dimension (video, width, height); |
| 188 |
|
| 189 |
delete priv->corona; |
| 190 |
delete priv->pcyl; |
| 191 |
|
| 192 |
priv->corona = new Corona(); |
| 193 |
priv->pcyl = new PaletteCycler(PALETTEDATA, NB_PALETTES); |
| 194 |
priv->tl.timeStamp = 0; |
| 195 |
priv->tl.lastbeat = 0; |
| 196 |
priv->tl.state = normal_state; |
| 197 |
|
| 198 |
priv->corona->setUpSurface(width, height); |
| 199 |
|
| 200 |
return 0; |
| 201 |
} |
| 202 |
|
| 203 |
extern "C" int lv_corona_events (VisPluginData *plugin, VisEventQueue *events) |
| 204 |
{ |
| 205 |
VisEvent ev; |
| 206 |
|
| 207 |
while (visual_event_queue_poll (events, &ev)) { |
| 208 |
switch (ev.type) { |
| 209 |
case VISUAL_EVENT_RESIZE: |
| 210 |
lv_corona_dimension (plugin, ev.event.resize.video, |
| 211 |
ev.event.resize.width, ev.event.resize.height); |
| 212 |
|
| 213 |
break; |
| 214 |
|
| 215 |
default: |
| 216 |
break; |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
return 0; |
| 221 |
} |
| 222 |
|
| 223 |
extern "C" VisPalette *lv_corona_palette (VisPluginData *plugin) |
| 224 |
{ |
| 225 |
CoronaPrivate *priv = (CoronaPrivate *) visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 226 |
|
| 227 |
priv->pcyl->updateVisPalette (&priv->pal); |
| 228 |
|
| 229 |
return &priv->pal; |
| 230 |
} |
| 231 |
|
| 232 |
extern "C" int lv_corona_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio) |
| 233 |
{ |
| 234 |
CoronaPrivate *priv = (CoronaPrivate *) visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 235 |
VisBuffer buffer; |
| 236 |
VisBuffer pcmb; |
| 237 |
float freq[2][256]; |
| 238 |
float pcm[256]; |
| 239 |
VisTime curtime; |
| 240 |
VisTime difftime; |
| 241 |
VisVideo vidcorona; |
| 242 |
short freqdata[2][512]; // FIXME Move to floats |
| 243 |
unsigned long timemilli = 0; |
| 244 |
int i; |
| 245 |
|
| 246 |
visual_buffer_set_data_pair (&pcmb, pcm, sizeof (pcm)); |
| 247 |
|
| 248 |
visual_audio_get_sample (audio, &pcmb, VISUAL_AUDIO_CHANNEL_LEFT); |
| 249 |
visual_buffer_set_data_pair (&buffer, freq[0], sizeof (freq[0])); |
| 250 |
visual_audio_get_spectrum_for_sample (&buffer, &pcmb, TRUE); |
| 251 |
|
| 252 |
visual_audio_get_sample (audio, &pcmb, VISUAL_AUDIO_CHANNEL_RIGHT); |
| 253 |
visual_buffer_set_data_pair (&buffer, freq[1], sizeof (freq[1])); |
| 254 |
visual_audio_get_spectrum_for_sample (&buffer, &pcmb, TRUE); |
| 255 |
|
| 256 |
for (i = 0; i < 256; ++i) { |
| 257 |
freqdata[0][i*2] = freq[0][i]; |
| 258 |
freqdata[1][i*2] = freq[1][i]; |
| 259 |
freqdata[0][i*2+1] = freq[0][i]; |
| 260 |
freqdata[1][i*2+1] = freq[1][i]; |
| 261 |
} |
| 262 |
|
| 263 |
visual_time_get (&curtime); |
| 264 |
|
| 265 |
visual_time_difference (&difftime, &priv->oldtime, &curtime); |
| 266 |
|
| 267 |
timemilli = difftime.tv_sec * 1000 + difftime.tv_usec / 1000; |
| 268 |
|
| 269 |
priv->tl.timeStamp += timemilli; |
| 270 |
|
| 271 |
visual_time_copy (&priv->oldtime, &curtime); |
| 272 |
|
| 273 |
for (i = 0; i < 512; ++i) { |
| 274 |
priv->tl.frequency[0][i] = freqdata[0][i] * 32768; |
| 275 |
priv->tl.frequency[1][i] = freqdata[1][i] * 32768; |
| 276 |
} |
| 277 |
|
| 278 |
priv->corona->update(&priv->tl); // Update Corona |
| 279 |
priv->pcyl->update(&priv->tl); // Update Palette Cycler |
| 280 |
|
| 281 |
visual_video_init (&vidcorona); |
| 282 |
visual_video_set_depth (&vidcorona, VISUAL_VIDEO_DEPTH_8BIT); |
| 283 |
visual_video_set_dimension (&vidcorona, video->width, video->height); |
| 284 |
visual_video_set_buffer (&vidcorona, priv->corona->getSurface()); |
| 285 |
|
| 286 |
visual_video_mirror (video, &vidcorona, VISUAL_VIDEO_MIRROR_Y); |
| 287 |
|
| 288 |
return 0; |
| 289 |
} |
| 290 |
|