Commit 68fac11b authored by Bruno Coudoin's avatar Bruno Coudoin Committed by Bruno Coudoin

Added Dynamic screen/skin resolution change added way to display credit

2003-06-09  Bruno Coudoin  <bruno.coudoin@free.fr>

	* TODO: Added Dynamic screen/skin resolution change
	* src/gcompris/oggplayer.c: (decode_ogg_file), (erase_credits),
	(display_ogg_file_credits): added way to display credit info from ogg
	* src/gcompris/soundutil.c: (initSound), (scheduler_bgnd),
	(thread_play_ogg): added background music support
parent 7f5bb23c
2003-06-09 Bruno Coudoin <bruno.coudoin@free.fr>
* TODO: Added Dynamic screen/skin resolution change
* src/gcompris/oggplayer.c: (decode_ogg_file), (erase_credits),
(display_ogg_file_credits): added way to display credit info from ogg
* src/gcompris/soundutil.c: (initSound), (scheduler_bgnd),
(thread_play_ogg): added background music support
2003-06-03 Bruno Coudoin <bruno.coudoin@free.fr>
* configure.in : removed gnome-common-init, added gnome-compile-warning
......
......@@ -25,6 +25,10 @@
* change the scale board to be more realistic and flexible.
* Dynamic screen resolution change
* Dynamic skin change
Bug report from Marec Dirson:
- dans le tableau "trains" (et sans doute ailleurs), il lui arrive
......
......@@ -17,6 +17,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "gcompris.h"
#include <stdio.h>
#include <libgen.h>
#include <pthread.h>
......@@ -28,10 +30,12 @@
#include <fcntl.h>
#endif
static GnomeCanvasItem *rootitem = NULL;
int quit = 0;
//int decode_ogg_file(char *infile)
void *decode_ogg_file(void *infile)
//void *decode_ogg_file(void *infile)
int decode_ogg_file(char *infile)
{
char buf[4096];
OggVorbis_File vf;
......@@ -135,3 +139,85 @@ void *decode_ogg_file(void *infile)
return 0;
}
/*
* This does the erase of the credits
*
*/
static gint erase_credits (GtkWidget *widget, gpointer data)
{
gtk_object_destroy (GTK_OBJECT(rootitem));
rootitem = NULL;
return(FALSE);
}
void *display_ogg_file_credits(void *infile)
{
OggVorbis_File vf;
vorbis_comment *vc;
long ov_status;
guint i = 0;
FILE* input;
if(rootitem)
return;
input = fopen((char *)infile, "rb");
if(!input) {
fprintf(stderr, "cannot open %s\n",(char *) infile);
return 0;
}
if((ov_status = ov_open(input, &vf, NULL, 0)) < 0)
{
fclose(input);
fprintf(stderr, "ov_open failed for %s (%d)\n",(char *) infile, ov_status);
return 0;
}
vc = ov_comment(&vf, -1);
rootitem = \
gnome_canvas_item_new (gnome_canvas_root(gcompris_get_canvas()),
gnome_canvas_group_get_type (),
"x", (double)0,
"y", (double)0,
NULL);
gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
gnome_canvas_text_get_type (),
"text", _("Now Playing Music"),
"font", gcompris_skin_font_subtitle,
"x", (double) BOARDWIDTH/2,
"y", (double) BOARDHEIGHT/2-10 + i++*20,
"anchor", GTK_ANCHOR_NORTH,
"fill_color", "white",
"justification", GTK_JUSTIFY_CENTER,
NULL);
{
char **ptr=vc->user_comments;
while(*ptr){
fprintf(stderr,"%s\n",*ptr);
gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
gnome_canvas_text_get_type (),
"text", *ptr,
"font", gcompris_skin_font_board_tiny,
"x", (double) BOARDWIDTH/2,
"y", (double) BOARDHEIGHT/2 + i++*20,
"anchor", GTK_ANCHOR_NORTH,
"fill_color", "white",
"justification", GTK_JUSTIFY_CENTER,
NULL);
++ptr;
}
gtk_timeout_add (20000,
(GtkFunction) erase_credits, NULL);
}
ov_clear(&vf);
}
......@@ -17,6 +17,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef __APPLE__
# include <sys/types.h>
#endif
#include <dirent.h>
#include "gcompris.h"
#include <signal.h>
#include <pthread.h>
......@@ -28,9 +33,11 @@ static gboolean is_playing;
/* Forward function declarations */
pthread_t thread_scheduler, thread_play;
pthread_t thread_scheduler_bgnd, thread_play_bgnd;
static void* thread_play_ogg (void*);
static char* get_next_sound_to_play( );
static void* scheduler ( );
static void* scheduler_bgnd ( );
extern int ogg123(char * sound);
/* mutex */
......@@ -53,6 +60,10 @@ void initSound()
if ( pthread_create ( &thread_scheduler, NULL, scheduler, NULL ) != 0)
perror("create failed for scheduler");
if ( pthread_create ( &thread_scheduler_bgnd, NULL, scheduler_bgnd, NULL ) != 0)
perror("create failed for scheduler background");
}
/* =====================================================================
......@@ -75,6 +86,61 @@ int getSoundPolicy()
{
return sound_policy;
}
/* =====================================================================
* Thread scheduler background :
* - launches a single thread for playing and play any file found
* in the gcompris music directory
======================================================================*/
static void* scheduler_bgnd ()
{
gint i;
gchar *str;
gchar *filename;
struct dirent **namelist = NULL;
int namelistlength = 0;
GList *musiclist = NULL;
if ( !gcompris_get_properties()->music )
return;
/* Sleep to let gcompris intialisation and intro music to complete */
sleep(20);
/* Load the Music directory file names */
filename = g_strdup_printf("%s", PACKAGE_DATA_DIR "/music/background");
namelistlength = scandir(filename,
&namelist, 0, NULL);
if (namelistlength < 0)
g_warning (_("Couldn't open music dir: %s"), filename);
g_free(filename);
/* Fill up the music list */
for(i=2; i<namelistlength; i++)
{
str = g_strdup_printf("%s/%s", PACKAGE_DATA_DIR "/music/background", namelist[i]->d_name);
g_free(namelist[i]);
musiclist = g_list_append (musiclist, str);
}
g_free(namelist);
/* Now loop over all our music files */
while (TRUE)
{
for(i=0; i<g_list_length(musiclist); i++)
{
display_ogg_file_credits((char *)g_list_nth_data(musiclist, i));
decode_ogg_file((char *)g_list_nth_data(musiclist, i));
}
}
return NULL;
}
/* =====================================================================
* Thread scheduler :
* - launches a single thread for playing a file
......@@ -117,7 +183,6 @@ static void* thread_play_ogg (void *s)
{
char* file = NULL;
char locale[3];
pthread_t pid_ogg = 0;
strncpy( locale, gcompris_get_locale(), 2 );
locale[2] = 0; // because strncpy does not put a '\0' at the end of the string
......
......@@ -47,6 +47,6 @@ int getSoundPolicy(void);
void initSound(void);
pid_t exec_play(char *);
int decode_ogg_file(char *infile);
int decode_ogg_file(char *infile);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment