diff --git a/configure.ac b/configure.ac index 73ffb72..3d50ca2 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ ## Process this file with autoconf to produce a configure script. AC_PREREQ(2.65) -AC_INIT([Infinity plugin],[0.9.0alpha],[https://github.com/dprotti/infinity-plugin/issues],[infinity-plugin-4-audacious],[https://dprotti.github.io/infinity-plugin]) +AC_INIT([Infinity plugin],[0.9.0-dev],[https://github.com/dprotti/infinity-plugin/issues],[infinity-plugin],[https://dprotti.github.io/infinity-plugin]) AC_CANONICAL_HOST AC_CANONICAL_TARGET @@ -189,6 +189,5 @@ Compiler : ${CC} CFLAGS : ${INF_CFLAGS_EXTRA} ${CFLAGS} CXXFLAGS : ${CXXFLAGS} Debug enabled : ${debug} -MMX Extensions support : ${mmx} " diff --git a/src/Makefile.am b/src/Makefile.am index bcc4a96..ec4e020 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,8 +15,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_builddir) libinfinite_la_LDFLAGS = ${CXX} libinfinite_la_LIBADD = @AUDACIOUS_LIBS@ @SDL_LIBS@ @GTK_LIBS@ @GLIB_LIBS@ libinfinite_la_SOURCES = \ - main.cc \ - renderer.cc renderer.h\ + audacious.cc \ + infinity.c infinity.h\ compute.c compute.h \ display.c display.h \ effects.c effects.h\ diff --git a/src/main.cc b/src/audacious.cc similarity index 57% rename from src/main.cc rename to src/audacious.cc index 0819029..c24a2c5 100644 --- a/src/main.cc +++ b/src/audacious.cc @@ -14,17 +14,21 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include +#include +#include #include +#include #include #include -#include extern "C" { #include "config.h" -#include "renderer.h" +#include "infinity.h" #include "types.h" } +#define CFGID "infinity" + static const char about_text[] = "Infinity " PACKAGE_VERSION "\n\n" "Julien Carme, Duilio Protti\n\n" @@ -73,6 +77,113 @@ private: EXPORT InfinityPlugin aud_plugin_instance; +static gint32 get_width() { + return aud_get_int(CFGID, "width"); +} + +static void set_width(gint32 width) { + aud_set_int(CFGID, "width", width); +} + +static gint32 get_height() { + return aud_get_int(CFGID, "height"); +} + +static void set_height(gint32 height) { + aud_set_int(CFGID, "height", height); +} + +static gint32 get_scale() { + return aud_get_int(CFGID, "scale_factor"); +} + +static gint32 get_effect_interval() { + return aud_get_int(CFGID, "effect_time"); +} + +static gint32 get_color_interval() { + return aud_get_int(CFGID, "palette_time"); +} + +static gboolean must_show_title() { + return aud_get_bool(CFGID, "show_title"); +} + +static gint32 get_max_fps() { + return aud_get_int(CFGID, "max_fps"); +} + +static InfParameters params; + +static void init_params() { + params.get_width = get_width; + params.set_width = set_width; + params.get_height = get_height; + params.set_height = set_height; + params.get_scale = get_scale; + params.get_effect_interval = get_effect_interval; + params.get_color_interval = get_color_interval; + params.must_show_title = must_show_title; + params.get_max_fps = get_max_fps; +}; + +static gboolean is_playing() { + return aud_drct_get_playing() && aud_drct_get_ready(); +} + +static gchar* get_title() { + String title = aud_playlist_get_title(aud_playlist_get_playing()); + return (gchar*) title.to_raw(); +} + +static void play() { + aud_drct_play(); +} + +static void pause() { + aud_drct_pause(); +} + +static void stop() { + aud_drct_stop(); +} + +static void previous() { + aud_drct_pl_prev(); +} + +static void next() { + aud_drct_pl_next(); +} + +static void seek(gint32 usecs) { + aud_drct_seek(aud_drct_get_time() + usecs); +} + +static void adjust_volume(gint delta) { + gint volume = aud_drct_get_volume_main(); + g_message("Increasing volume to %d", volume + 5); + aud_drct_set_volume_main(volume + delta); +} + +static void disable_plugin() { + PluginHandle * plugin = aud_plugin_lookup_basename("libinfinite"); + aud_plugin_enable(plugin, false); +} + +static Player player = { + .is_playing = is_playing, + .get_title = get_title, + .play = play, + .pause = pause, + .stop = stop, + .previous = previous, + .next = next, + .seek = seek, + .adjust_volume = adjust_volume, + .disable_plugin = disable_plugin +}; + bool InfinityPlugin::init(void) { g_message("Infinity commands:\n" @@ -89,7 +200,9 @@ bool InfinityPlugin::init(void) "- F11:\t\tscreenshot.\n" "- F12:\t\tchange palette."); load_settings(); - renderer_init(); + init_params(); + infinity_init(¶ms, &player); + return TRUE; } @@ -101,11 +214,11 @@ void InfinityPlugin::clear () void InfinityPlugin::cleanup(void) { g_message("Infinity: cleanup()"); - renderer_finish(); + infinity_finish(); } void InfinityPlugin::render_multi_pcm (const float * pcm, int channels) { - renderer_render_multi_pcm(pcm, channels); + infinity_render_multi_pcm(pcm, channels); } static const char * const defaults[] = { diff --git a/src/compute.c b/src/compute.c index 1598b65..59a48ec 100644 --- a/src/compute.c +++ b/src/compute.c @@ -31,7 +31,7 @@ typedef struct t_complex { gfloat x, y; } t_complex; -static t_screen_parameters scr_par; +static gint32 width, height, scale; static byte *surface1; static byte *surface2; @@ -45,15 +45,15 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p gfloat speed; gfloat co, si; - a.x -= scr_par.width / 2; - a.y -= scr_par.height / 2; + 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 = scr_par.height * 0.25; + circle_size = height * 0.25; speed = (gfloat)2000 + p2 * 500; b.x = (co * a.x - si * a.y); b.y = (si * a.x + co * a.y); @@ -65,7 +65,7 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p an = 0.015 * (p1 - 2) + 0.002; co = cos(an); si = sin(an); - circle_size = scr_par.height * 0.45; + circle_size = height * 0.45; speed = (gfloat)4000 + p2 * 1000; b.x = (co * a.x - si * a.y); b.y = (si * a.x + co * a.y); @@ -77,7 +77,7 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p an = 0.002; co = cos(an); si = sin(an); - circle_size = scr_par.height * 0.25; + circle_size = height * 0.25; speed = (gfloat)400 + p2 * 100; b.x = (co * a.x - si * a.y); b.y = (si * a.x + co * a.y); @@ -89,7 +89,7 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p an = (sin(sqrt(a.x * a.x + a.y * a.y) / 20) / 20) + 0.002; co = cos(an); si = sin(an); - circle_size = scr_par.height * 0.25; + circle_size = height * 0.25; speed = (gfloat)4000; b.x = (co * a.x - si * a.y); b.y = (si * a.x + co * a.y); @@ -101,7 +101,7 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p an = 0.002; co = cos(an); si = sin(an); - circle_size = scr_par.height * 0.25; + 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); @@ -117,7 +117,7 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p an = 0.002; co = cos(an); si = sin(an); - circle_size = scr_par.height * 0.25; + circle_size = height * 0.25; 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); @@ -128,16 +128,16 @@ static inline t_complex fct(t_complex a, guint32 n, gint32 p1, gint32 p2) /* p b.x = (gfloat)0.0; b.y = (gfloat)0.0; } - b.x += scr_par.width / 2; - b.y += scr_par.height / 2; + b.x += width / 2; + b.y += height / 2; if (b.x < 0.0) b.x = 0.0; if (b.y < 0.0) b.y = 0.0; - if (b.x > (gfloat)scr_par.width - 1) - b.x = (gfloat)scr_par.width - 1; - if (b.y > (gfloat)scr_par.height - 1) - b.y = (gfloat)scr_par.height - 1; + if (b.x > (gfloat)width - 1) + b.x = (gfloat)width - 1; + if (b.y > (gfloat)height - 1) + b.y = (gfloat)height - 1; return b; } @@ -184,24 +184,24 @@ static inline void compute_generate_sector(guint32 g, guint32 f, guint32 p1, gui } } -void compute_init(gint32 width, gint32 height, gint32 scale) +void compute_init(gint32 _width, gint32 _height, gint32 _scale) { - scr_par.width = width; - scr_par.height = height; - scr_par.scale = scale; + width = _width; + height = _height; + scale = _scale; - surface1 = (byte *)g_malloc((gulong)(scr_par.width + 1) * (scr_par.height + 1)); - surface2 = (byte *)g_malloc((gulong)(scr_par.width + 1) * (scr_par.height + 1)); + surface1 = (byte *)g_malloc((gulong)(width + 1) * (height + 1)); + surface2 = (byte *)g_malloc((gulong)(width + 1) * (height + 1)); } -void compute_resize(gint32 width, gint32 height) +void compute_resize(gint32 _width, gint32 _height) { - scr_par.width = width; - scr_par.height = height; + width = _width; + height = _height; g_free(surface1); g_free(surface2); - surface1 = (byte *)g_malloc((gulong)(scr_par.width + 1) * (scr_par.height + 1)); - surface2 = (byte *)g_malloc((gulong)(scr_par.width + 1) * (scr_par.height + 1)); + surface1 = (byte *)g_malloc((gulong)(width + 1) * (height + 1)); + surface2 = (byte *)g_malloc((gulong)(width + 1) * (height + 1)); } vector_field_t *compute_vector_field_new(gint32 width, gint32 height) @@ -232,15 +232,15 @@ void compute_quit() void compute_generate_vector_field(vector_field_t *vector_field) { - guint32 f, i, height; + guint32 f, i, _height; g_return_if_fail(vector_field != NULL); g_return_if_fail(vector_field->height >= 0); - height = (guint32)vector_field->height; + _height = (guint32)vector_field->height; for (f = 0; f < NB_FCT; f++) - for (i = 0; i < height; i += 10) + for (i = 0; i < _height; i += 10) compute_generate_sector(f, f, 2, 2, i, 10, vector_field); } diff --git a/src/display.c b/src/display.c index b95327d..75aab85 100644 --- a/src/display.c +++ b/src/display.c @@ -35,7 +35,7 @@ typedef struct sincos { static gint16 pcm_data[2][512]; static SDL_mutex *pcm_data_mutex; -static t_screen_parameters scr_par; +static gint32 width, height, scale; /* Little optimization for cos/sin functions */ static sincos_t cosw = { 0, NULL }; @@ -50,11 +50,11 @@ static gint16 current_colors[256]; static byte *surface1; -static void init_sdl(gint32 width, gint32 height, gint32 scale) +static void init_sdl(gint32 _width, gint32 _height, gint32 _scale) { if (SDL_Init((Uint32)(SDL_INIT_VIDEO | SDL_INIT_TIMER)) < 0) g_error("Infinity: Couldn't initialize SDL: %s\n", SDL_GetError()); - screen = SDL_SetVideoMode(width * scale, height * scale, 16, VIDEO_FLAGS); + screen = SDL_SetVideoMode(_width * _scale, _height * _scale, 16, VIDEO_FLAGS); if (screen == NULL) g_error("Infinity: could not init video mode: %s\n", SDL_GetError()); g_message("Infinity: SDL SetVideoMode() Ok"); @@ -99,12 +99,12 @@ static void display_surface() } else { screen_locked = FALSE; } - if (scr_par.scale > 1) { - for (i = 0; i < scr_par.height; i++) { - pdest = (gint16 *)(screen->pixels + i * screen->pitch * scr_par.scale); - psrc = surface1 + i * scr_par.width; - if (scr_par.scale == 2) { - for (j = 1; j < scr_par.width; j++) { + if (scale > 1) { + for (i = 0; i < height; i++) { + pdest = (gint16 *)(screen->pixels + i * screen->pitch * scale); + psrc = surface1 + i * width; + if (scale == 2) { + for (j = 1; j < width; j++) { *(pdest++) = current_colors[*psrc++]; *(pdest) = *(pdest - 1); pdest++; @@ -112,7 +112,7 @@ static void display_surface() memcpy(screen->pixels + i * screen->pitch * 2 + screen->pitch, screen->pixels + i * screen->pitch * 2, screen->pitch); } /* else { - * for (j=1;jpixels + i * screen->pitch); - for (j = 0; j < scr_par.width; j++) + for (j = 0; j < width; j++) *pdest++ = current_colors[*psrc++]; } } @@ -139,19 +139,19 @@ static void display_surface() #define plot1(x, y, c) \ \ - if ((x) > 0 && (x) < scr_par.width - 3 && (y) > 0 && (y) < scr_par.height - 3) \ - assign_max(&(surface1)[(x) + (y) * scr_par.width], (c)) \ + if ((x) > 0 && (x) < width - 3 && (y) > 0 && (y) < height - 3) \ + assign_max(&(surface1)[(x) + (y) * width], (c)) \ \ #define plot2(x, y, c) \ { \ gint32 ty; \ - if ((x) > 0 && (gint32)(x) < scr_par.width - 3 && (y) > 0 && (gint32)(y) < scr_par.height - 3) { \ - ty = (gint32)(y) * scr_par.width; \ + if ((x) > 0 && (gint32)(x) < width - 3 && (y) > 0 && (gint32)(y) < height - 3) { \ + ty = (gint32)(y) * width; \ assign_max((&(surface1)[(gint32)(x) + ty]), (c)); \ assign_max((&(surface1)[(gint32)(x) + 1 + ty]), (c)); \ - assign_max((&(surface1)[(gint32)(x) + ty + scr_par.width]), (c)); \ - assign_max((&(surface1)[(gint32)(x) + 1 + ty + scr_par.width]), (c)); \ + assign_max((&(surface1)[(gint32)(x) + ty + width]), (c)); \ + assign_max((&(surface1)[(gint32)(x) + 1 + ty + width]), (c)); \ } \ } \ @@ -208,11 +208,11 @@ static void line(gint32 x1, gint32 y1, gint32 x2, gint32 y2, gint32 c) } } -void display_init(gint32 width, gint32 height, gint32 scale) +void display_init(gint32 _width, gint32 _height, gint32 _scale) { - scr_par.width = width; - scr_par.height = height; - scr_par.scale = scale; + width = _width; + height = _height; + scale = _scale; pcm_data_mutex = SDL_CreateMutex(); compute_init(width, height, scale); @@ -234,16 +234,16 @@ void display_quit(void) SDL_Quit(); } -void display_resize(gint32 width, gint32 height) +void display_resize(gint32 _width, gint32 _height) { - scr_par.width = width; - scr_par.height = height; - screen = SDL_SetVideoMode(scr_par.width * scr_par.scale, - scr_par.height * scr_par.scale, + width = _width; + height = _height; + screen = SDL_SetVideoMode(width * scale, + height * scale, 16, VIDEO_FLAGS); if (screen == NULL) g_error("Infinity: Couldn't set %dx%d video mode: %s\n", - scr_par.width * scr_par.scale, scr_par.height * scr_par.scale, + width * scale, height * scale, SDL_GetError()); compute_vector_field_destroy(vector_field); vector_field = compute_vector_field_new(width, height); @@ -301,13 +301,13 @@ void spectral(t_effect *current_effect) gfloat y1, y2; const gint32 density_lines = 5; const gint32 step = 4; - const gint32 shift = (current_effect->spectral_shift * scr_par.height) >> 8; + const gint32 shift = (current_effect->spectral_shift * height) >> 8; /* begin CS */ g_return_if_fail(SDL_mutexP(pcm_data_mutex) >= 0); - y1 = (gfloat)((((pcm_data[0][0] + pcm_data[1][0]) >> 9) * current_effect->spectral_amplitude * scr_par.height) >> 12); - y2 = (gfloat)((((pcm_data[0][0] + pcm_data[1][0]) >> 9) * current_effect->spectral_amplitude * scr_par.height) >> 12); - if (cosw.i != scr_par.width || sinw.i != scr_par.width) { + y1 = (gfloat)((((pcm_data[0][0] + pcm_data[1][0]) >> 9) * current_effect->spectral_amplitude * height) >> 12); + y2 = (gfloat)((((pcm_data[0][0] + pcm_data[1][0]) >> 9) * current_effect->spectral_amplitude * height) >> 12); + if (cosw.i != width || sinw.i != width) { g_free(cosw.f); g_free(sinw.f); sinw.f = cosw.f = NULL; @@ -315,21 +315,21 @@ void spectral(t_effect *current_effect) } if (cosw.i == 0 || cosw.f == NULL) { gfloat halfPI = (gfloat)PI / 2; - cosw.i = scr_par.width; + cosw.i = width; if (cosw.f != NULL) g_free(cosw.f); - cosw.f = g_malloc(sizeof(gfloat) * scr_par.width); - for (i = 0; i < scr_par.width; i += step) - cosw.f[i] = cos((gfloat)i / scr_par.width * PI + halfPI); + cosw.f = g_malloc(sizeof(gfloat) * width); + for (i = 0; i < width; i += step) + cosw.f[i] = cos((gfloat)i / width * PI + halfPI); } if (sinw.i == 0 || sinw.f == NULL) { gfloat halfPI = (gfloat)PI / 2; - sinw.i = scr_par.width; + sinw.i = width; if (sinw.f != NULL) g_free(sinw.f); - sinw.f = g_malloc(sizeof(gfloat) * scr_par.width); - for (i = 0; i < scr_par.width; i += step) - sinw.f[i] = sin((gfloat)i / scr_par.width * PI + halfPI); + sinw.f = g_malloc(sizeof(gfloat) * width); + for (i = 0; i < width; i += step) + sinw.f[i] = sin((gfloat)i / width * PI + halfPI); } if (current_effect->mode_spectre == 3) { if (y1 < 0.0) @@ -337,15 +337,15 @@ void spectral(t_effect *current_effect) if (y2 < 0.0) y2 = 0.0; } - halfheight = scr_par.height >> 1; - halfwidth = scr_par.width >> 1; - for (i = step; i < scr_par.width; i += step) { + halfheight = height >> 1; + halfwidth = width >> 1; + for (i = step; i < width; i += step) { old_y1 = y1; old_y2 = y2; - y1 = (gfloat)(((pcm_data[1][(i << 9) / scr_par.width / density_lines] >> 8) * - current_effect->spectral_amplitude * scr_par.height) >> 12); - y2 = (gfloat)(((pcm_data[0][(i << 9) / scr_par.width / density_lines] >> 8) * - current_effect->spectral_amplitude * scr_par.height) >> 12); + y1 = (gfloat)(((pcm_data[1][(i << 9) / width / density_lines] >> 8) * + current_effect->spectral_amplitude * height) >> 12); + y2 = (gfloat)(((pcm_data[0][(i << 9) / width / density_lines] >> 8) * + current_effect->spectral_amplitude * height) >> 12); /* end CS */ switch (current_effect->mode_spectre) { case 0: @@ -396,10 +396,10 @@ void spectral(t_effect *current_effect) } g_return_if_fail(SDL_mutexV(pcm_data_mutex) >= 0); if (current_effect->mode_spectre == 3 || current_effect->mode_spectre == 4) { - line(halfwidth + cosw.f[scr_par.width - step] * (shift + y1), - halfheight + sinw.f[scr_par.width - step] * (shift + y1), - halfwidth - cosw.f[scr_par.width - step] * (shift + y2), - halfheight + sinw.f[scr_par.width - step] * (shift + y2), + line(halfwidth + cosw.f[width - step] * (shift + y1), + halfheight + sinw.f[width - step] * (shift + y1), + halfwidth - cosw.f[width - step] * (shift + y2), + halfheight + sinw.f[width - step] * (shift + y2), current_effect->spectral_color); } } @@ -420,10 +420,10 @@ void curve(t_effect *current_effect) vr = 0.001; k = current_effect->x_curve; for (i = 0; i < 64; i++) { - x = cos((gfloat)(k) / (v + v * j * 1.34)) * scr_par.height * amplitude; - y = sin((gfloat)(k) / (1.756 * (v + v * j * 0.93))) * scr_par.height * amplitude; - plot2(x * cos((gfloat)k * vr) + y * sin((gfloat)k * vr) + scr_par.width / 2, - x * sin((gfloat)k * vr) - y * cos((gfloat)k * vr) + scr_par.height / 2, + x = cos((gfloat)(k) / (v + v * j * 1.34)) * height * amplitude; + y = sin((gfloat)(k) / (1.756 * (v + v * j * 0.93))) * height * amplitude; + plot2(x * cos((gfloat)k * vr) + y * sin((gfloat)k * vr) + width / 2, + x * sin((gfloat)k * vr) - y * cos((gfloat)k * vr) + height / 2, (byte)current_effect->curve_color); k++; } diff --git a/src/renderer.cc b/src/infinity.c similarity index 79% rename from src/renderer.cc rename to src/infinity.c index c20ce3b..a06c2ad 100644 --- a/src/renderer.cc +++ b/src/infinity.c @@ -19,26 +19,19 @@ #include #include -#include -#include -#include -#include - #include #include /*#include */ -extern "C" { #include "config.h" #include "display.h" #include "effects.h" -#include "renderer.h" +#include "infinity.h" #include "types.h" #if MMX_DETECTION #include "cputest.h" #endif -} #define wrap(a) (a < 0 ? 0 : (a > 255 ? 255 : a)) #define next_effect() (t_last_effect++) @@ -47,8 +40,10 @@ extern "C" { typedef gint32 t_color; typedef gint32 t_num_effect; -static t_screen_parameters scr_par; +static InfParameters * params; +static Player * player; +static gint32 width, height, scale; static t_effect current_effect; static t_color color, old_color, t_last_color; static t_num_effect t_last_effect; @@ -72,7 +67,7 @@ static void check_events(); static int renderer(void *); static void set_title(void); -void renderer_init(void) +void infinity_init(InfParameters * _params, Player * _player) { gint32 _try; @@ -87,9 +82,11 @@ void renderer_init(void) } } initializing = TRUE; - scr_par.width = aud_get_int(CFGID, "width"); - scr_par.height = aud_get_int(CFGID, "height"); - scr_par.scale = aud_get_int(CFGID, "scale_factor"); + params = _params; + player = _player; + width = params->get_width(); + height = params->get_height(); + scale = params->get_scale(); old_color = 0; color = 0; @@ -103,7 +100,7 @@ void renderer_init(void) quiting = FALSE; first_xevent = TRUE; - display_init(scr_par.width, scr_par.height, scr_par.scale); + display_init(width, height, scale); current_title = g_strdup("Infinity"); set_title(); title_timer = g_timer_new(); @@ -121,10 +118,9 @@ void renderer_init(void) thread = SDL_CreateThread(renderer, NULL); } -void renderer_finish(void) +void infinity_finish(void) { gint32 _try; - PluginHandle * plugin; if (finished) return; @@ -142,7 +138,7 @@ void renderer_finish(void) SDL_WaitThread(thread, NULL); SDL_DestroyMutex(resizing_mutex); /* - * Take some time to let it know renderer_render_multi_pcm() + * Take some time to let it know infinity_render_multi_pcm() * that must not call display_set_pcm_data(). * If it do that while calling display_quit(), * we could make Audacious crash, because display_quit @@ -155,13 +151,12 @@ void renderer_finish(void) display_quit(); g_timer_destroy(title_timer); - plugin = aud_plugin_lookup_basename("libinfinite"); - aud_plugin_enable(plugin, false); + player->disable_plugin(); g_message("Infinity: Closing..."); } -void renderer_render_multi_pcm(const float *data, int channels) +void infinity_render_multi_pcm(const float *data, int channels) { if (!initializing && !quiting) display_set_pcm_data(data, channels); @@ -215,27 +210,25 @@ static gint32 event_filter(const SDL_Event *event) static gint disable_func(gpointer data) { - renderer_finish(); + infinity_finish(); return FALSE; } static void check_events() { SDL_Event event; - gint volume; /*XEvent *xevent; * XWindowChanges changes; * XWindowAttributes attr; * XSetWindowAttributes s_attr;*/ - if (aud_get_int(CFGID, "show_title")) { + if (params->must_show_title()) { if (g_timer_elapsed(title_timer, NULL) > 1.0) { - if (aud_drct_get_playing() && aud_drct_get_ready()) { + if (player->is_playing()) { if (current_title) g_free(current_title); - String title = aud_playlist_get_title(aud_playlist_get_playing()); - current_title = g_strdup(title.to_raw()); + current_title = g_strdup(player->get_title()); } else { if (current_title) g_free(current_title); @@ -283,49 +276,44 @@ static void check_events() g_return_if_fail(SDL_LockMutex(resizing_mutex) >= 0); resizing = TRUE; g_return_if_fail(SDL_UnlockMutex(resizing_mutex) >= 0); - scr_par.width = event.resize.w; - scr_par.height = event.resize.h; - g_message("Infinity: Screen resized to %dx%d pixels^2", - scr_par.width, scr_par.height); + width = event.resize.w; + height = event.resize.h; + g_message("Infinity: Screen resized to %dx%d pixels^2", width, height); must_resize = TRUE; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_RIGHT: - if (aud_drct_get_playing() && aud_drct_get_ready()) - aud_drct_seek(aud_drct_get_time() + 5000); + if (player->is_playing()) + player->seek(5000); break; case SDLK_LEFT: - if (aud_drct_get_playing() && aud_drct_get_ready()) - aud_drct_seek(aud_drct_get_time() - 5000); + if (player->is_playing()) + player->seek(-5000); break; case SDLK_UP: - volume = aud_drct_get_volume_main(); - g_message("Increasing volume to %d", volume + 5); - aud_drct_set_volume_main(volume + 5); + player->adjust_volume(5); break; case SDLK_DOWN: - volume = aud_drct_get_volume_main(); - g_message("Decreasing volume to %d", volume - 5); - aud_drct_set_volume_main(volume - 5); + player->adjust_volume(-5); break; case SDLK_TAB: display_toggle_fullscreen(); break; case SDLK_z: - aud_drct_pl_prev(); + player->previous(); break; case SDLK_x: - aud_drct_play(); + player->play(); break; case SDLK_c: - aud_drct_pause(); + player->pause(); break; case SDLK_v: - aud_drct_stop(); + player->stop(); break; case SDLK_b: - aud_drct_pl_next(); + player->next(); break; case SDLK_F11: display_save_screen(); @@ -399,15 +387,16 @@ static gint64 calculate_frame_length_usecs(gint32 fps, int line) { static int renderer(void *arg) { + gint64 now, render_time, t_begin; gint32 frame_length; gint32 fps, new_fps; gint32 t_between_effects, t_between_colors; gint32 has_mmx = 0; - fps = aud_get_int(CFGID, "max_fps"); + fps = params->get_max_fps(); frame_length = calculate_frame_length_usecs(fps, __LINE__); - t_between_effects = aud_get_int(CFGID, "effect_time"); - t_between_colors = aud_get_int(CFGID, "palette_time"); + t_between_effects = params->get_effect_interval(); + t_between_colors = params->get_color_interval(); #if MMX_DETECTION has_mmx = mm_support_check_and_show(); #endif @@ -424,19 +413,19 @@ static int renderer(void *arg) if (finished) break; if (must_resize) { - display_resize(scr_par.width, scr_par.height); - aud_set_int(CFGID, "width", scr_par.width); - aud_set_int(CFGID, "heigth", scr_par.height); + display_resize(width, height); + params->set_width(width); + params->set_height(height); must_resize = FALSE; g_return_val_if_fail(SDL_LockMutex(resizing_mutex) >= 0, -1); resizing = FALSE; g_return_val_if_fail(SDL_UnlockMutex(resizing_mutex) >= 0, -1); } - auto t_begin = g_get_monotonic_time(); + t_begin = g_get_monotonic_time(); if (has_mmx) - display_blur_mmx(scr_par.width * scr_par.height * current_effect.num_effect); + display_blur_mmx(width * height * current_effect.num_effect); else - display_blur(scr_par.width * scr_par.height * current_effect.num_effect); + display_blur(width * height * current_effect.num_effect); spectral(¤t_effect); curve(¤t_effect); if (t_last_color <= 32) @@ -448,12 +437,12 @@ static int renderer(void *arg) if (!mode_interactif) { display_load_random_effect(¤t_effect); t_last_effect = 0; - t_between_effects = aud_get_int(CFGID, "effect_time"); + t_between_effects = params->get_effect_interval(); } #else display_load_random_effect(¤t_effect); t_last_effect = 0; - t_between_effects = aud_get_int(CFGID, "effect_time"); + t_between_effects = params->get_effect_interval(); #endif } if (t_last_color % t_between_colors == 0) { @@ -462,24 +451,24 @@ static int renderer(void *arg) old_color = color; color = rand() % NB_PALETTES; t_last_color = 0; - t_between_colors = aud_get_int(CFGID, "palette_time"); + t_between_colors = params->get_color_interval(); } #else old_color = color; color = rand() % NB_PALETTES; t_last_color = 0; - t_between_colors = aud_get_int(CFGID, "palette_time"); + t_between_colors = params->get_color_interval(); #endif } - new_fps = aud_get_int(CFGID, "max_fps"); + new_fps = params->get_max_fps(); if (new_fps != fps) { fps = new_fps; frame_length = calculate_frame_length_usecs(fps, __LINE__); } - auto now = g_get_monotonic_time(); - auto render_time = now - t_begin; + now = g_get_monotonic_time(); + render_time = now - t_begin; if (render_time < frame_length) { g_usleep(frame_length - render_time); } diff --git a/src/infinity.h b/src/infinity.h new file mode 100644 index 0000000..0f8ac18 --- /dev/null +++ b/src/infinity.h @@ -0,0 +1,71 @@ +/* + * 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. + */ +#ifndef __INFINITY_INFINITY__ +#define __INFINITY_INFINITY__ + +#include + +typedef struct _InfParameters { + gint32 (*get_x_origin) (void); + gint32 (*get_y_origin) (void); + gint32 (*get_width) (void); + void (*set_width) (gint32 width); + gint32 (*get_height) (void); + void (*set_height) (gint32 height); + gint32 (*get_scale) (void); + gint32 (*get_bpp) (void); /* bytes per pixels. */ + gint32 (*get_effect_interval) (void); + gint32 (*get_color_interval) (void); + gint32 (*must_show_title) (void); + gint32 (*get_max_fps) (void); +} InfParameters; + +typedef struct _Player { + + gboolean (*is_playing) (void); + gchar* (*get_title) (void); + + void (*play) (void); + void (*pause) (void); + void (*stop) (void); + void (*previous) (void); + void (*next) (void); + void (*seek) (gint32 usecs); + void (*adjust_volume) (gint delta); + + void (*disable_plugin) (void); /* tell the player that this plugin has stopped */ + +} Player; + +/* + * Initializes rendering process. + * + * Reads configuration parameters and launches a thread where most of the + * plugin job gets done. + */ +void infinity_init(InfParameters * params, Player * player); + +/* + * Closes rendering process. + */ +void infinity_finish(void); + +/* + * Expected to be called periodically by the player to provide actual PCM data. + */ +void infinity_render_multi_pcm(const float *data, int channels); + +#endif /* __INFINITY_INFINITY__ */ diff --git a/src/renderer.h b/src/renderer.h deleted file mode 100644 index 0de008c..0000000 --- a/src/renderer.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - */ -#ifndef __INFINITY_RENDERER__ -#define __INFINITY_RENDERER__ - -#include - -/* - * Initializes rendering process. - * - * Reads configuration parameters and launchs a thread where most of the - * plugin job gets done. - */ -void renderer_init(void); - -/* - * Closes rendering process. - */ -void renderer_finish(void); - -/* - * Copies PCM data from Audacity. - * - * Called periodically by Audacity with actual PCM data. - */ -void renderer_render_multi_pcm(const float *data, int channels); - -#endif /* __INFINITY_RENDERER__ */ diff --git a/src/types.h b/src/types.h index 86e7efa..796e02b 100644 --- a/src/types.h +++ b/src/types.h @@ -18,17 +18,6 @@ #include -#define CFGID "infinity" - -// existence of this header smells as bad design... -typedef struct _t_screen_parameters { - gint32 x, y; - gint32 width; - gint32 height; - gint32 scale; - gint32 bpp; /* bytes per pixels. */ -} t_screen_parameters; - typedef Uint8 byte; #endif /* __INFINITY_TYPES__ */