Interactive mode saves effects file in home dir instead of system dir

This commit is contained in:
Duilio Protti 2016-07-01 16:37:17 -03:00
parent c5d5c04800
commit f86a8bce22
5 changed files with 151 additions and 141 deletions

View File

@ -1,7 +1,7 @@
## Process this file with autoconf to produce a configure script. ## Process this file with autoconf to produce a configure script.
AC_PREREQ(2.65) AC_PREREQ(2.65)
AC_INIT([Infinity plugin],[0.9.0alpha2],[https://github.com/dprotti/infinity-plugin/issues],[infinity-plugin],[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_HOST
AC_CANONICAL_TARGET AC_CANONICAL_TARGET

View File

@ -222,26 +222,35 @@ static void line(gint32 x1, gint32 y1, gint32 x2, gint32 y2, gint32 c)
} }
} }
static void sdl_quit() {
if (screen != NULL)
SDL_FreeSurface(screen);
screen = NULL;
if (window != NULL)
SDL_DestroyWindow(window);
window = NULL;
}
gboolean display_init(gint32 _width, gint32 _height, gint32 _scale, Player *_player) gboolean display_init(gint32 _width, gint32 _height, gint32 _scale, Player *_player)
{ {
gboolean sdl_ok;
width = _width; width = _width;
height = _height; height = _height;
scale = _scale; scale = _scale;
player = _player; player = _player;
if (! effects_load_effects(player)) {
return FALSE;
}
if (! sdl_init()) {
sdl_quit();
return FALSE;
}
compute_init(width, height, scale); compute_init(width, height, scale);
sdl_ok = sdl_init();
generate_colors(); generate_colors();
effects_load_effects();
vector_field = compute_vector_field_new(width, height); vector_field = compute_vector_field_new(width, height);
compute_generate_vector_field(vector_field); compute_generate_vector_field(vector_field);
if (!sdl_ok) {
display_quit();
}
initialized = TRUE; initialized = TRUE;
return sdl_ok; return TRUE;
} }
void display_quit(void) void display_quit(void)
@ -250,12 +259,7 @@ void display_quit(void)
return; return;
compute_vector_field_destroy(vector_field); compute_vector_field_destroy(vector_field);
compute_quit(); compute_quit();
if (screen != NULL) sdl_quit();
SDL_FreeSurface(screen);
screen = NULL;
if (window != NULL)
SDL_DestroyWindow(window);
window = NULL;
// do not call SDL_Quit() since there is another plugin that use // do not call SDL_Quit() since there is another plugin that use
// SDL inside Audacious. // SDL inside Audacious.
// Do not call neither SDL_QuitSubsystem() just in case // Do not call neither SDL_QuitSubsystem() just in case
@ -480,7 +484,7 @@ void display_save_screen(void)
inline void display_save_effect(t_effect *effect) inline void display_save_effect(t_effect *effect)
{ {
effects_save_effect(effect); effects_append_effect(effect);
} }

View File

@ -10,35 +10,43 @@
static t_effect effects[100]; static t_effect effects[100];
static gint32 nb_effects = 0; static gint32 nb_effects = 0;
static gboolean initialized = FALSE; static gboolean initialized = FALSE;
static gchar error_msg[256];
void effects_save_effect(t_effect *effect) void effects_append_effect(t_effect *effect)
{ {
FILE *f; FILE *f;
gint32 i; gint32 i;
gchar *personal_states = g_strconcat(g_get_home_dir(), "/infinite_states", NULL);
g_assert(effect); g_return_if_fail(effect != NULL);
f = fopen (EFFECTS_FILE,"a");
f = fopen (personal_states, "a");
if (f == NULL) { if (f == NULL) {
g_warning ("Cannot open file %s for saving effects\n", g_critical("Cannot open file '%s' for saving effects", personal_states);
EFFECTS_FILE); g_free(personal_states);
return; return;
} }
g_message("Infinity appended effect to '%s'", personal_states);
g_free(personal_states);
for (i = 0; i < sizeof(t_effect); i++) for (i = 0; i < sizeof(t_effect); i++)
fputc(*((byte *)effect + i), f); fputc(*((byte *)effect + i), f);
fclose(f); fclose(f);
} }
void effects_load_effects(void) gboolean effects_load_effects(Player *player)
{ {
FILE *f; FILE *f;
gint32 finished = 0; gint32 finished = 0;
gint32 i, b, c, d, e; gint32 i, b, c, d, e;
f = fopen (EFFECTS_FILE,"r"); g_return_val_if_fail(player != NULL, FALSE);
f = fopen (EFFECTS_FILE, "r");
if (f == NULL) { if (f == NULL) {
g_warning ("Cannot open file %s for loading effects\n", g_snprintf(error_msg, 256, "Cannot open file '%s' for loading effects",
EFFECTS_FILE); EFFECTS_FILE);
return; player->notify_critical_error(error_msg);
return FALSE;
} }
while (!finished) { while (!finished) {
byte *ptr_effect = (byte *)&effects[nb_effects]; byte *ptr_effect = (byte *)&effects[nb_effects];
@ -70,6 +78,7 @@ void effects_load_effects(void)
} }
nb_effects--; nb_effects--;
fclose(f); fclose(f);
return TRUE;
} }
void effects_load_random_effect(t_effect *effect) void effects_load_random_effect(t_effect *effect)

View File

@ -17,6 +17,7 @@
#define __INFINITY_EFFECTS__ #define __INFINITY_EFFECTS__
#include <glib.h> #include <glib.h>
#include "music-player.h"
#include "types.h" #include "types.h"
/* /*
@ -26,29 +27,31 @@
* would be enough for some of them. * would be enough for some of them.
*/ */
typedef struct { typedef struct {
gint32 num_effect; /* The number of the effect */ gint32 num_effect; /* The number of the effect */
gint32 x_curve; gint32 x_curve;
gint32 curve_color; gint32 curve_color;
gint32 curve_amplitude; gint32 curve_amplitude;
gint32 spectral_amplitude; gint32 spectral_amplitude;
gint32 spectral_color; gint32 spectral_color;
gint32 mode_spectre; gint32 mode_spectre;
gint32 spectral_shift; gint32 spectral_shift;
} t_effect; } t_effect;
/* /*
* Saves the given effect pointed by \a effect to disk. * Appends effect to file ~/infinite_states
*
* The effect are saved to the file
* {prefix}/share/xmms/infinity_states, where {prefix} is
* usually /usr or /usr/local.
* *
* @param effect Must be a non NULL reference to a ::t_effect * @param effect Must be a non NULL reference to a ::t_effect
* object. * object.
*/ */
void effects_save_effect(t_effect *effect); void effects_append_effect (t_effect *effect);
void effects_load_effects(void); /*
void effects_load_random_effect(t_effect *effect); * Loads effects from file {DATADIR}/infinite_states
*
* Returns TRUE on success or FALSE otherwise.
*/
gboolean effects_load_effects (Player *player);
void effects_load_random_effect (t_effect *effect);
#endif /* __INFINITY_EFFECTS__ */ #endif /* __INFINITY_EFFECTS__ */

View File

@ -53,7 +53,7 @@ G_LOCK_DEFINE_STATIC(resizing);
static gboolean initializing = FALSE; static gboolean initializing = FALSE;
static gboolean visible; static gboolean visible;
static gboolean quiting; static gboolean quiting;
static gboolean mode_interactif; static gboolean interactive_mode;
static gboolean first_xevent; static gboolean first_xevent;
static gchar *current_title; static gchar *current_title;
static GTimer *title_timer; static GTimer *title_timer;
@ -99,7 +99,7 @@ void infinity_init(InfParameters * _params, Player * _player)
finished = FALSE; finished = FALSE;
must_resize = FALSE; must_resize = FALSE;
resizing = FALSE; resizing = FALSE;
mode_interactif = FALSE; interactive_mode = FALSE;
visible = TRUE; visible = TRUE;
quiting = FALSE; quiting = FALSE;
first_xevent = TRUE; first_xevent = TRUE;
@ -156,56 +156,90 @@ void infinity_render_multi_pcm(const float *data, int channels)
display_set_pcm_data(data, channels); display_set_pcm_data(data, channels);
} }
#ifdef INFINITY_DEBUG
static void handle_interactive_mode() {
gint32 i;
gint32 sx, sy;
const byte *keystate = SDL_GetKeyboardState(NULL);
SDL_GetMouseState(&sx, &sy);
current_effect.spectral_shift = sx;
if (keystate[SDL_SCANCODE_A])
current_effect.curve_color = wrap(current_effect.curve_color - 32);
if (keystate[SDL_SCANCODE_Z])
current_effect.curve_color = wrap(current_effect.curve_color + 32);
if (keystate[SDL_SCANCODE_Q])
current_effect.spectral_color = wrap(current_effect.spectral_color - 32);
if (keystate[SDL_SCANCODE_S])
current_effect.spectral_color = wrap(current_effect.spectral_color + 32);
for (i = 0; i < 10; i++)
if (keystate[SDL_SCANCODE_F1 + i])
current_effect.num_effect = i % NB_FCT;
if (keystate[SDL_SCANCODE_D])
current_effect.spectral_amplitude = (current_effect.spectral_amplitude - 1);
if (keystate[SDL_SCANCODE_F])
current_effect.spectral_amplitude = (current_effect.spectral_amplitude + 1);
if (keystate[SDL_SCANCODE_E])
current_effect.curve_amplitude = (current_effect.curve_amplitude - 1);
if (keystate[SDL_SCANCODE_R])
current_effect.curve_amplitude = (current_effect.curve_amplitude + 1);
if (keystate[SDL_SCANCODE_M])
display_save_effect(&current_effect);
if (keystate[SDL_SCANCODE_W])
current_effect.mode_spectre = (current_effect.mode_spectre + 1) % 5;
}
#endif /* INFINITY_DEBUG */
static void handle_window_event(SDL_Event *event) { static void handle_window_event(SDL_Event *event) {
switch (event->window.event) { switch (event->window.event) {
case SDL_WINDOWEVENT_SHOWN: case SDL_WINDOWEVENT_SHOWN:
//SDL_Log("Window %d shown", event->window.windowID); //SDL_Log("Window %d shown", event->window.windowID);
visible = TRUE; visible = TRUE;
break; break;
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
//SDL_Log("Window %d exposed", event->window.windowID); //SDL_Log("Window %d exposed", event->window.windowID);
visible = TRUE; visible = TRUE;
break; break;
case SDL_WINDOWEVENT_HIDDEN: case SDL_WINDOWEVENT_HIDDEN:
//SDL_Log("Window %d hidden", event->window.windowID); //SDL_Log("Window %d hidden", event->window.windowID);
visible = FALSE; visible = FALSE;
break; break;
/*case SDL_WINDOWEVENT_MOVED: /*case SDL_WINDOWEVENT_MOVED:
SDL_Log("Window %d moved to %d,%d", SDL_Log("Window %d moved to %d,%d",
event->window.windowID, event->window.data1, event->window.windowID, event->window.data1,
event->window.data2); event->window.data2);
break;*/ break;*/
case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_RESIZED:
G_LOCK(resizing); G_LOCK(resizing);
resizing = TRUE; resizing = TRUE;
G_UNLOCK(resizing); G_UNLOCK(resizing);
width = event->window.data1; width = event->window.data1;
height = event->window.data2; height = event->window.data2;
g_message("Infinity: Screen resized to %dx%d pixels^2", width, height); g_message("Infinity: Screen resized to %dx%d pixels^2", width, height);
must_resize = TRUE; must_resize = TRUE;
break; break;
/*case SDL_WINDOWEVENT_SIZE_CHANGED: /*case SDL_WINDOWEVENT_SIZE_CHANGED:
SDL_Log("Window %d size changed to %dx%d", SDL_Log("Window %d size changed to %dx%d",
event->window.windowID, event->window.data1, event->window.windowID, event->window.data1,
event->window.data2); event->window.data2);
break;*/ break;*/
case SDL_WINDOWEVENT_MINIMIZED: case SDL_WINDOWEVENT_MINIMIZED:
//SDL_Log("Window %d minimized", event->window.windowID); //SDL_Log("Window %d minimized", event->window.windowID);
visible = FALSE; visible = FALSE;
break; break;
/*case SDL_WINDOWEVENT_MAXIMIZED: /*case SDL_WINDOWEVENT_MAXIMIZED:
SDL_Log("Window %d maximized", event->window.windowID); SDL_Log("Window %d maximized", event->window.windowID);
break; break;
case SDL_WINDOWEVENT_RESTORED: case SDL_WINDOWEVENT_RESTORED:
SDL_Log("Window %d restored", event->window.windowID); SDL_Log("Window %d restored", event->window.windowID);
break;*/ break;*/
case SDL_WINDOWEVENT_CLOSE: case SDL_WINDOWEVENT_CLOSE:
SDL_Log("Window %d closed", event->window.windowID); SDL_Log("Window %d closed", event->window.windowID);
player->disable_plugin(); player->disable_plugin();
break; break;
default: default:
break; break;
} }
} }
static void check_events() static void check_events()
@ -231,11 +265,9 @@ static void check_events()
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
switch (event.type) { switch (event.type) {
case SDL_QUIT: case SDL_QUIT:
player->disable_plugin(); player->disable_plugin(); break;
break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
handle_window_event(&event); handle_window_event(&event); break;
break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
switch (event.key.keysym.sym) { switch (event.key.keysym.sym) {
case SDLK_RIGHT: case SDLK_RIGHT:
@ -247,32 +279,23 @@ static void check_events()
player->seek(-5000); player->seek(-5000);
break; break;
case SDLK_UP: case SDLK_UP:
player->adjust_volume(5); player->adjust_volume(5); break;
break;
case SDLK_DOWN: case SDLK_DOWN:
player->adjust_volume(-5); player->adjust_volume(-5); break;
break;
case SDLK_TAB: case SDLK_TAB:
display_toggle_fullscreen(); display_toggle_fullscreen(); break;
break;
case SDLK_z: case SDLK_z:
player->previous(); player->previous(); break;
break;
case SDLK_x: case SDLK_x:
player->play(); player->play(); break;
break;
case SDLK_c: case SDLK_c:
player->pause(); player->pause(); break;
break;
case SDLK_v: case SDLK_v:
player->stop(); player->stop(); break;
break;
case SDLK_b: case SDLK_b:
player->next(); player->next(); break;
break;
case SDLK_F11: case SDLK_F11:
display_save_screen(); display_save_screen(); break;
break;
case SDLK_F12: case SDLK_F12:
if (t_last_color > 32) { if (t_last_color > 32) {
t_last_color = 0; t_last_color = 0;
@ -286,7 +309,8 @@ static void check_events()
break; break;
#ifdef INFINITY_DEBUG #ifdef INFINITY_DEBUG
case SDLK_RETURN: case SDLK_RETURN:
mode_interactif = !mode_interactif; interactive_mode = !interactive_mode;
g_message("Infinity %s interactive mode", interactive_mode ? "entered" : "leaved");
break; break;
#endif #endif
default: default:
@ -298,38 +322,8 @@ static void check_events()
} }
} }
#ifdef INFINITY_DEBUG #ifdef INFINITY_DEBUG
if (mode_interactif) { if (interactive_mode)
gint32 i; handle_interactive_mode();
gint32 sx, sy;
byte *keystate;
keystate = SDL_GetKeyState(NULL);
SDL_GetMouseState(&sx, &sy);
current_effect.spectral_shift = sx;
if (keystate[SDLK_a])
current_effect.curve_color = wrap(current_effect.curve_color - 32);
if (keystate[SDLK_z])
current_effect.curve_color = wrap(current_effect.curve_color + 32);
if (keystate[SDLK_q])
current_effect.spectral_color = wrap(current_effect.spectral_color - 32);
if (keystate[SDLK_s])
current_effect.spectral_color = wrap(current_effect.spectral_color + 32);
for (i = 0; i < 10; i++)
if (keystate[SDLK_F1 + i])
current_effect.num_effect = i % NB_FCT;
if (keystate[SDLK_d])
current_effect.spectral_amplitude = (current_effect.spectral_amplitude - 1);
if (keystate[SDLK_f])
current_effect.spectral_amplitude = (current_effect.spectral_amplitude + 1);
if (keystate[SDLK_e])
current_effect.curve_amplitude = (current_effect.curve_amplitude - 1);
if (keystate[SDLK_r])
current_effect.curve_amplitude = (current_effect.curve_amplitude + 1);
if (keystate[SDLK_m])
display_save_effect(&current_effect);
if (keystate[SDLK_w])
current_effect.mode_spectre = (current_effect.mode_spectre + 1) % 5;
}
#endif /* INFINITY_DEBUG */ #endif /* INFINITY_DEBUG */
} }
@ -392,7 +386,7 @@ static int renderer(void *arg)
next_effect(); next_effect();
if (t_last_effect % t_between_effects == 0) { if (t_last_effect % t_between_effects == 0) {
#ifdef INFINITY_DEBUG #ifdef INFINITY_DEBUG
if (!mode_interactif) { if (!interactive_mode) {
display_load_random_effect(&current_effect); display_load_random_effect(&current_effect);
t_last_effect = 0; t_last_effect = 0;
t_between_effects = params->get_effect_interval(); t_between_effects = params->get_effect_interval();
@ -405,7 +399,7 @@ static int renderer(void *arg)
} }
if (t_last_color % t_between_colors == 0) { if (t_last_color % t_between_colors == 0) {
#ifdef INFINITY_DEBUG #ifdef INFINITY_DEBUG
if (!mode_interactif) { if (!interactive_mode) {
old_color = color; old_color = color;
color = rand() % NB_PALETTES; color = rand() % NB_PALETTES;
t_last_color = 0; t_last_color = 0;