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.
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_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 sdl_ok;
width = _width;
height = _height;
scale = _scale;
player = _player;
if (! effects_load_effects(player)) {
return FALSE;
}
if (! sdl_init()) {
sdl_quit();
return FALSE;
}
compute_init(width, height, scale);
sdl_ok = sdl_init();
generate_colors();
effects_load_effects();
vector_field = compute_vector_field_new(width, height);
compute_generate_vector_field(vector_field);
if (!sdl_ok) {
display_quit();
}
initialized = TRUE;
return sdl_ok;
return TRUE;
}
void display_quit(void)
@ -250,12 +259,7 @@ void display_quit(void)
return;
compute_vector_field_destroy(vector_field);
compute_quit();
if (screen != NULL)
SDL_FreeSurface(screen);
screen = NULL;
if (window != NULL)
SDL_DestroyWindow(window);
window = NULL;
sdl_quit();
// do not call SDL_Quit() since there is another plugin that use
// SDL inside Audacious.
// 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)
{
effects_save_effect(effect);
effects_append_effect(effect);
}

View File

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

View File

@ -17,6 +17,7 @@
#define __INFINITY_EFFECTS__
#include <glib.h>
#include "music-player.h"
#include "types.h"
/*
@ -37,18 +38,20 @@ typedef struct {
} t_effect;
/*
* Saves the given effect pointed by \a effect to disk.
*
* The effect are saved to the file
* {prefix}/share/xmms/infinity_states, where {prefix} is
* usually /usr or /usr/local.
* Appends effect to file ~/infinite_states
*
* @param effect Must be a non NULL reference to a ::t_effect
* 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__ */

View File

@ -53,7 +53,7 @@ G_LOCK_DEFINE_STATIC(resizing);
static gboolean initializing = FALSE;
static gboolean visible;
static gboolean quiting;
static gboolean mode_interactif;
static gboolean interactive_mode;
static gboolean first_xevent;
static gchar *current_title;
static GTimer *title_timer;
@ -99,7 +99,7 @@ void infinity_init(InfParameters * _params, Player * _player)
finished = FALSE;
must_resize = FALSE;
resizing = FALSE;
mode_interactif = FALSE;
interactive_mode = FALSE;
visible = TRUE;
quiting = FALSE;
first_xevent = TRUE;
@ -156,6 +156,40 @@ void infinity_render_multi_pcm(const float *data, int 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) {
switch (event->window.event) {
case SDL_WINDOWEVENT_SHOWN:
@ -231,11 +265,9 @@ static void check_events()
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
player->disable_plugin();
break;
player->disable_plugin(); break;
case SDL_WINDOWEVENT:
handle_window_event(&event);
break;
handle_window_event(&event); break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_RIGHT:
@ -247,32 +279,23 @@ static void check_events()
player->seek(-5000);
break;
case SDLK_UP:
player->adjust_volume(5);
break;
player->adjust_volume(5); break;
case SDLK_DOWN:
player->adjust_volume(-5);
break;
player->adjust_volume(-5); break;
case SDLK_TAB:
display_toggle_fullscreen();
break;
display_toggle_fullscreen(); break;
case SDLK_z:
player->previous();
break;
player->previous(); break;
case SDLK_x:
player->play();
break;
player->play(); break;
case SDLK_c:
player->pause();
break;
player->pause(); break;
case SDLK_v:
player->stop();
break;
player->stop(); break;
case SDLK_b:
player->next();
break;
player->next(); break;
case SDLK_F11:
display_save_screen();
break;
display_save_screen(); break;
case SDLK_F12:
if (t_last_color > 32) {
t_last_color = 0;
@ -286,7 +309,8 @@ static void check_events()
break;
#ifdef INFINITY_DEBUG
case SDLK_RETURN:
mode_interactif = !mode_interactif;
interactive_mode = !interactive_mode;
g_message("Infinity %s interactive mode", interactive_mode ? "entered" : "leaved");
break;
#endif
default:
@ -298,38 +322,8 @@ static void check_events()
}
}
#ifdef INFINITY_DEBUG
if (mode_interactif) {
gint32 i;
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;
}
if (interactive_mode)
handle_interactive_mode();
#endif /* INFINITY_DEBUG */
}
@ -392,7 +386,7 @@ static int renderer(void *arg)
next_effect();
if (t_last_effect % t_between_effects == 0) {
#ifdef INFINITY_DEBUG
if (!mode_interactif) {
if (!interactive_mode) {
display_load_random_effect(&current_effect);
t_last_effect = 0;
t_between_effects = params->get_effect_interval();
@ -405,7 +399,7 @@ static int renderer(void *arg)
}
if (t_last_color % t_between_colors == 0) {
#ifdef INFINITY_DEBUG
if (!mode_interactif) {
if (!interactive_mode) {
old_color = color;
color = rand() % NB_PALETTES;
t_last_color = 0;