diff --git a/src/compute.c b/src/compute.c index 730dd20..d370e17 100644 --- a/src/compute.c +++ b/src/compute.c @@ -58,8 +58,8 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p b.x = (co * a.x - si * a.y); b.y = (si * a.x + co * a.y); fact = -(sqrt(b.x * b.x + b.y * b.y) - circle_size) / speed + 1; - b.x = (b.x * fact); - b.y = (b.y * fact); + b.x *= fact; + b.y *= fact; break; case 1: an = 0.015 * (p1 - 2) + 0.002; @@ -70,8 +70,8 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p b.x = (co * a.x - si * a.y); b.y = (si * a.x + co * a.y); fact = (sqrt(b.x * b.x + b.y * b.y) - circle_size) / speed + 1; - b.x = (b.x * fact); - b.y = (b.y * fact); + b.x *= fact; + b.y *= fact; break; case 2: an = 0.002; @@ -82,8 +82,8 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p b.x = (co * a.x - si * a.y); b.y = (si * a.x + co * a.y); fact = -(sqrt(b.x * b.x + b.y * b.y) - circle_size) / speed + 1; - b.x = (b.x * fact); - b.y = (b.y * fact); + b.x *= fact; + b.y *= fact; break; case 3: an = (sin(sqrt(a.x * a.x + a.y * a.y) / 20) / 20) + 0.002; @@ -94,8 +94,8 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p b.x = (co * a.x - si * a.y); b.y = (si * a.x + co * a.y); fact = -(sqrt(b.x * b.x + b.y * b.y) - circle_size) / speed + 1; - b.x = (b.x * fact); - b.y = (b.y * fact); + b.x *= fact; + b.y *= fact; break; case 4: an = 0.002; @@ -106,8 +106,8 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p b.x = (co * a.x - si * a.y); b.y = (si * a.x + co * a.y); fact = -(sqrt(b.x * b.x + b.y * b.y) - circle_size) / speed + 1; - b.x = (b.x * fact); - b.y = (b.y * fact); + b.x *= fact; + b.y *= fact; break; case 5: b.x = a.x * 1.02; @@ -121,8 +121,8 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p fact = 1 + cos(atan(a.x / (a.y + 0.00001)) * 6) * 0.02; b.x = (co * a.x - si * a.y); b.y = (si * a.x + co * a.y); - b.x = (b.x * fact); - b.y = (b.y * fact); + b.x *= fact; + b.y *= fact; break; default: b.x = (gfloat)0.0; diff --git a/src/display.c b/src/display.c index 9ff8e4f..6b46a32 100644 --- a/src/display.c +++ b/src/display.c @@ -83,8 +83,6 @@ static void generate_colors() color_table[k][i].r = (Uint8)(colors[k][0][0] * i); color_table[k][i].g = (Uint8)(colors[k][0][1] * i); color_table[k][i].b = (Uint8)(colors[k][0][2] * i); - } - for (i = 0; i < 128; i++) { color_table[k][i + 128].r = (Uint8)(colors[k][0][0] * 127 + colors[k][1][0] * i); color_table[k][i + 128].g = (Uint8)(colors[k][0][1] * 127 + colors[k][1][1] * i); color_table[k][i + 128].b = (Uint8)(colors[k][0][2] * 127 + colors[k][1][2] * i); diff --git a/src/effects.c b/src/effects.c index d44649b..6a7fbeb 100644 --- a/src/effects.c +++ b/src/effects.c @@ -70,9 +70,9 @@ void effects_load_effects(void) finished = 1; } } - nb_effects += 1; + nb_effects++; } - nb_effects -= 1; + nb_effects--; fclose(f); } diff --git a/src/main.c.orig b/src/main.c.orig deleted file mode 100644 index 0ce1e5c..0000000 --- a/src/main.c.orig +++ /dev/null @@ -1,168 +0,0 @@ -/** - * \file main.c - * - * \brief The main module of Infinity plugin. - * - * The only thing that a XMMS visualization plugin has to do - * (from the point of view of XMMS) is to export a function called - * get_vplugin_info() wich returns a pointer to a VisPlugin structure. - * This struct is defined in xmms/plugin.h. It contains pointers to - * functions which will be called on the ocurrence of certain events. - */ - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include -#include -#include -#include -#include - -#include "config.h" -#include "infconfig.h" -#include "renderer.h" -#include "gettext.h" - - -VisPlugin *get_vplugin_info(void); - - -static void plugin_init (void); -static void plugin_close (void); -static void plugin_about (void); - -/** - * Structure shared with XMMS in order to register and get information - * about the plugin. - * - * The \a VisPlugin type is defined on . XMMS will - * obtain a reference to this structure calling ::get_vplugin_info() - * when started. - */ -static VisPlugin sdlblur_vp = { - NULL, /**< Handle, filled in by xmms */ - NULL, /**< Filename, filled in by xmms */ - 0, /**< XMMS Session ID, filled in by XMMS */ - "Infinity " PACKAGE_VERSION, /**< description */ - 2, /**< Number of PCM channels wanted */ - 0, /**< Number of freq channels wanted */ - plugin_init, /**< Called when plugin is enabled */ - plugin_close, /**< Called when plugin is disabled */ - plugin_about, /**< Show the about box */ - config_plugin_config_window, /**< Show the configure box */ - NULL, /**< - void (*disable_plugin)(struct _VisPlugin *) - - Called to disable plugin, filled in by XMMS. - Must be called with a pointer to our plugin - struct to disable the plugin */ - NULL, /**< Called when playback starts */ - NULL, /**< Called when playback stops */ - renderer_set_pcm_data, /**< Render the PCM data */ - NULL, /**< Render the freq data */ -}; - - -static void plugin_init(void) -{ -#if ENABLE_NLS - (void) setlocale (LC_MESSAGES, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); -#endif - - g_message (_("Infinity commands:\n" - "- Space:\tchange effect.\n" - "- Tab:\t\ttoggle full-screen.\n" - "- Up/Down:\tup/down xmms main volume.\n" - "- Left/Right:\treward/forward actual played song, if any.\n" - "- z:\t\tprevious song.\n" - "- x:\t\tplay.\n" - "- c:\t\tpause.\n" - "- v:\t\tstop.\n" - "- b:\t\tnext song.\n" - "- Enter:\tswitch to interactive mode.\n\t\t(works only if infinity was configured with --enable-debug option)\n" - "- F11:\t\tscreenshot.\n" - "- F12:\t\tchange palette.")); - config_plugin_load_prefs (); - renderer_set_plugin_info (&sdlblur_vp); - renderer_init (); -} - - -static void plugin_close (void) -{ - config_plugin_save_prefs (); - renderer_finish (); -} - -static void dummy (GtkWidget *widget, gpointer data) -{ -} - -static void plugin_about (void) -{ - GtkWidget *window_about; - -#if ENABLE_NLS - (void) setlocale (LC_MESSAGES, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); -#endif - - window_about = xmms_show_message (_("About Infinity"), - _("\n" PACKAGE_STRING "\n" - "\n\n" - "\nCopyright (C) 2000, Julien Carme.\n" - "Email: \n" - "\n" - "Duilio J. Protti \n" - "Actual maintainer\n" - "\n" - "This program is free software; you can redistribute it and/or modify\n" - "it under the terms of the GNU General Public License as published by\n" - "the Free Software Foundation; either version 2 of the License, or\n" - "(at your option) any later version.\n" - "\n" - "This program is distributed in the hope that it will be useful,\n" - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - "GNU General Public License for more details.\n" - "\n" - "You should have received a copy of the GNU General Public License\n" - "along with this program; if not, write to the Free Software\n" - "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n" - "USA"), - _("Ok"), FALSE, dummy, NULL); - - gtk_widget_show (window_about); -} - - -/* - * - * Public functions - * - */ - - -/** - * Function to be exported to XMMS in order to register the plugin. - */ -VisPlugin *get_vplugin_info(void) -{ - return &sdlblur_vp; -} diff --git a/src/renderer.c b/src/renderer.c index b145fa9..2be7f3d 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -43,8 +43,8 @@ #endif #define wrap(a) (a < 0 ? 0 : (a > 255 ? 255 : a)) -#define next_effect() (t_last_effect += 1) -#define next_color() (t_last_color += 1) +#define next_effect() (t_last_effect++) +#define next_color() (t_last_color++) typedef struct t_general_parameters { gint32 t_between_effects; @@ -359,7 +359,7 @@ static void check_events() if (t_last_color > 32) { t_last_color = 0; old_color = color; - color = (color + 1) % NB_PALETTES; + color = ++color % NB_PALETTES; } break; case SDLK_SPACE: diff --git a/src/spectrum.c b/src/spectrum.c deleted file mode 100644 index 70e0da2..0000000 --- a/src/spectrum.c +++ /dev/null @@ -1,390 +0,0 @@ -#include -#include -/*#include "libxmms/util.h"*/ -#include - -#define wrap(a) (a < 0 ? 0 : (a > 255 ? 255 : a)) -#define PI 3.14159 - -#define WIDTH 400 -#define HEIGHT 300 - - -#define INTERPOLATION 0 //0 or 1 to double resolution. -#define NB_FCT 6 -#define NB_PALETTES 5 - -#include "affiche.h" - -#define PERIODE_COLORS 64 -#define PERIODE_EFFECTS 128 - -#define VIDEO_FLAGS (SDL_HWSURFACE | SDL_HWPALETTE) - -#define BASS_EXT_MEMORY 100 - -typedef guchar byte; - -static void sanalyzer_init(void); - -static void sanalyzer_cleanup(void); -static void sanalyzer_playback_start(void); -static void sanalyzer_playback_stop(void); -static void sanalyzer_render_pcm(gint16 data[2][512]); -static void sanalyzer_render_freq(gint16 data[2][256]); - -/* - * typedef struct coord { - * int x,y; - * } coord; - * - * typedef struct complex { - * float x,y; - * } complex; - * - * typedef struct interpol { - * coord c; //coordinates of the top left pixel. - * int w1,w2,w3,w4; - * } interpol; - * - * typedef struct effect { - * int addr_effect; - * int f1,f2,f3; - * int x_curve; - * int p_speed,p_rotation; - * int color,old_color; - * int curve_color; - * int spectral_color; - * int mode_spectre; - * int spectral_shift; - * int flash; - * } effect; - */ -struct bass_info { - //int mem[SIZE_BASS_MEM]; - gint32 max_recent; - gint32 max_old; - gint32 time_last_max; - gint32 min_recent; - gint32 min_old; - gint32 time_last_min; - gint32 activated; -} bass_info; - - - -interpol vector_field[NB_FCT][WIDTH * HEIGHT]; - -effect current_effect; - -gint32 t = 0; - -VisPlugin sanalyzer_vp = -{ - NULL, - NULL, - - 0, - "Simple spectrum analyzer", - 1, - 1, - sanalyzer_init, - sanalyzer_cleanup, - NULL, - NULL, - NULL, - sanalyzer_playback_start, - sanalyzer_playback_stop, - sanalyzer_render_pcm, - sanalyzer_render_freq -}; - -VisPlugin *get_vplugin_info(void) -{ - return &sanalyzer_vp; -} - -complex fct(complex a, gint32 n, gint32 p1, gint32 p2) //p1 et p2:0-4 -{ - complex b, b1, b2; - gfloat fact; - gfloat an; - gfloat circle_size; - gfloat speed; - gfloat co, si; - - a.x -= WIDTH / 2; - a.y -= HEIGHT / 2; - - switch (n) { - case 0: - an = 0.025 * (p1 - 2) + 0.002; - co = cos(an); - si = sin(an); - circle_size = HEIGHT * 0.25; - speed = 2000 + p2 * 500; - b.x = (co * a.x - si * a.y); - b.y = (si * a.x + co * a.y); - fact = -(sqrt(b.x * b.x + b.y * b.y) - circle_size) / speed + 1; - b.x = (b.x * fact); - b.y = (b.y * fact); - break; - - case 1: - an = 0.015 * (p1 - 2) + 0.002; - co = cos(an); - si = sin(an); - circle_size = HEIGHT * 0.45; - speed = 4000 + p2 * 1000; - b.x = (co * a.x - si * a.y); - b.y = (si * a.x + co * a.y); - fact = (sqrt(b.x * b.x + b.y * b.y) - circle_size) / speed + 1; - b.x = (b.x * fact); - b.y = (b.y * fact); - break; - - case 2: - an = 0.002; - co = cos(an); - si = sin(an); - circle_size = HEIGHT * 0.25; - speed = 400 + p2 * 100; - b.x = (co * a.x - si * a.y); - b.y = (si * a.x + co * a.y); - fact = -(sqrt(b.x * b.x + b.y * b.y) - circle_size) / speed + 1; - b.x = (b.x * fact); - b.y = (b.y * fact); - break; - - case 3: - an = (sin(sqrt(a.x * a.x + a.y * a.y) / 20) / 20) + 0.002; - co = cos(an); - si = sin(an); - circle_size = HEIGHT * 0.25; - speed = 4000; - b.x = (co * a.x - si * a.y); - b.y = (si * a.x + co * a.y); - fact = -(sqrt(b.x * b.x + b.y * b.y) - circle_size) / speed + 1; - b.x = (b.x * fact); - b.y = (b.y * fact); - break; - - case 4: - an = 0.002; - co = cos(an); - si = sin(an); - circle_size = HEIGHT * 0.25; - speed = sin(sqrt(a.x * a.x + a.y * a.y) / 5) * 3000 + 4000; - b.x = (co * a.x - si * a.y); - b.y = (si * a.x + co * a.y); - fact = -(sqrt(b.x * b.x + b.y * b.y) - circle_size) / speed + 1; - b.x = (b.x * fact); - b.y = (b.y * fact); - break; - - case 5: - b.x = a.x * 1.0; - b.y = a.y * 1.0; - } - - b.x += WIDTH / 2; - b.y += HEIGHT / 2; - if (b.x < 0) - b.x = 0; - if (b.y < 0) - b.y = 0; - if (b.x > WIDTH - 1) - b.x = WIDTH - 1; - if (b.y > HEIGHT - 1) - b.y = HEIGHT - 1; - - return b; -} - - -void generate_sector(gint32 g, gint32 f, gint32 p1, gint32 p2, gint32 debut, gint32 step) -{ - coord c; - complex a; - gfloat fpy; - gint32 rw, lw, add; - gint32 fin = debut + step; - gint32 prop_transmitted = 249; - gint32 i, j; - - if (fin > HEIGHT) - fin = HEIGHT; - for (c.y = debut; c.y < fin; c.y++) - for (c.x = 0; c.x < WIDTH; c.x++) { - a.x = (gfloat)c.x; - a.y = (gfloat)c.y; - a = fct(a, f, p1, p2); - add = c.x + c.y * WIDTH; - vector_field[g][add].c.x = (gint32)(a.x); - vector_field[g][add].c.y = (gint32)(a.y); - fpy = a.y - floor(a.y); - rw = (gint32)((a.x - floor(a.x)) * prop_transmitted); - lw = prop_transmitted - rw; - vector_field[g][add].w4 = (gint32)(fpy * rw); - vector_field[g][add].w2 = rw - vector_field[g][add].w4; - vector_field[g][add].w3 = (gint32)(fpy * lw); - vector_field[g][add].w1 = lw - vector_field[g][add].w3; - } -} - -void generate_vector_field() -{ - gint32 f; - gint32 i, p1, p2; - - for (f = 0; f < NB_FCT; f++) { - p1 = 2; - p2 = 2; - for (i = 0; i < HEIGHT; i += 10) - generate_sector(f, f, p1, p2, i, 10); - } -} - -static void sanalyzer_init(void) -{ - generate_vector_field(); - generate_colors(); -} - - -static void sanalyzer_cleanup(void) -{ - SDL_Quit(); -} - - -static void sanalyzer_playback_start(void) -{ - init_sdl(); - generate_vector_field(); -} - - -static void sanalyzer_playback_stop(void) -{ - SDL_Quit(); -} - - - -void sanalyzer_render_freq(gint16 data[2][256]) -{ - gint32 bass = 0; - gint32 i; - gint32 step = 10; - - for (i = 0; i < step; i++) - bass += (data[0][i] >> 4) + (data[1][i] >> 4); - - bass = bass / step / 2; - - if (bass > bass_info.max_recent) - bass_info.max_recent = bass; - - if (bass < bass_info.min_recent) - bass_info.min_recent = bass; - - if (t - bass_info.time_last_max > BASS_EXT_MEMORY) { - bass_info.max_old = bass_info.max_recent; - bass_info.max_recent = 0; - bass_info.time_last_max = t; - } - - if (t - bass_info.time_last_min > BASS_EXT_MEMORY) { - bass_info.min_old = bass_info.min_recent; - bass_info.min_recent = 0; - bass_info.time_last_min = t; - } - - if (bass > (bass_info.max_old * 6 + bass_info.min_old * 4) / 10 && bass_info.activated == 0) { - if (current_effect.flash) - flash(255, t); - bass_info.activated = 1; - } - - if (bass < (bass_info.max_old * 4 + bass_info.min_old * 6) / 10 && bass_info.activated == 1) - bass_info.activated = 0; -} - -void sanalyzer_render_pcm(gint16 data[2][512]) -{ - SDL_Event event; - Uint8 *keystate; - gint32 son = 0; - gint32 trace = 0; - gfloat x, y, v, vr; - gint32 i; - gint32 t_last_palette = 0; - - while (SDL_PollEvent(&event)) { - if (event.type == SDL_QUIT) - SDL_Quit(); - if (event.type == SDL_KEYDOWN) { - gchar *st; - st = SDL_GetKeyName(event.key.keysym.sym); - if (!strcmp(st, "a")) - current_effect.curve_color = wrap(current_effect.curve_color - 32); - if (!strcmp(st, "z")) - current_effect.curve_color = wrap(current_effect.curve_color + 32); - if (!strcmp(st, "q")) - current_effect.spectral_color = wrap(current_effect.spectral_color - 32); - if (!strcmp(st, "s")) - current_effect.spectral_color = wrap(current_effect.spectral_color + 32); - if (!strcmp(st, "w")) - current_effect.mode_spectre = (current_effect.mode_spectre + 1) % 5; - if (!strcmp(st, "x")) - current_effect.flash = (current_effect.flash + 1) % 2; - } - } - - keystate = SDL_GetKeyState(NULL); - if (keystate[SDLK_ESCAPE]) - ToggleFullScreen(); - for (i = 0; i < 10; i++) - if (keystate[SDLK_F1 + i]) - current_effect.addr_effect = i % NB_FCT; - if (keystate[SDLK_F11]) { - current_effect.color = (current_effect.color - 1) % NB_PALETTES; - t_last_palette = 0; - } - if (keystate[SDLK_F12]) { - current_effect.color = (current_effect.color + 1) % NB_PALETTES; - t_last_palette = 0; - } - if (keystate[SDLK_e]) - current_effect.spectral_shift = (current_effect.spectral_shift - 10) % HEIGHT; - if (keystate[SDLK_r]) - current_effect.spectral_shift = (current_effect.spectral_shift + 10) % HEIGHT; - - if (t_last_palette < 8) - change_color(current_effect.color, (current_effect.color + 1) % NB_PALETTES, (t_last_palette + 1) * 32); - /* - * if (t%PERIODE_EFFECTS==0) { - * // while (current_effect.f1==current_effect.f2) { - * // current_effect.f2=current_effect.f1; - * //current_effect.f1=rand()%NB_TYPE_FCT; - * //} - * //current_effect.p_rotation=2; - * //current_effect.p_speed=rand()%5; - * current_effect.addr_effect=(current_effect.addr_effect+1)%NB_FCT; - * }*/ - /* - * generate_sector(1-current_effect.addr_effect,current_effect.f1, - * current_effect.p_rotation,current_effect.p_speed, - * (t%PERIODE_EFFECTS)*(HEIGHT/PERIODE_EFFECTS+1), - * (HEIGHT/PERIODE_EFFECTS+1)); - */ - affiche(current_effect.addr_effect, vector_field); - - spectral(data, current_effect); - - curve(¤t_effect); - - t += 1; - t_last_palette += 1; -}