Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYves Combe <ycombe@src.gnome.org>2006-12-12 21:29:30 (GMT)
committer Yves Combe <ycombe@src.gnome.org>2006-12-12 21:29:30 (GMT)
commit396f490db037b71397be41fe5099e2506756b4c2 (patch)
tree67a698cac9817783aa00c31235ba81f0f9b3cedc
parent978534039ab03043d9aa11b40ab522d6aed666b3 (diff)
GC_SOUND: - add demo.py little python demo. - add g_object_ref in
GC_SOUND: - add demo.py little python demo. - add g_object_ref in mixer_sdl_new (fix bug in destroy). - get filename returns a copy of the string, not the pointer itself. - reset channel number when a channel is destroyed.
-rw-r--r--ChangeLog20
-rw-r--r--src/gc_sound/ChangeLog18
-rw-r--r--src/gc_sound/python/demo.py26
-rw-r--r--src/gc_sound/python/gc_sound.override98
-rw-r--r--src/gc_sound/src/gc-sound-item.c12
-rw-r--r--src/gc_sound/src/gc-sound-mixer-SDL.c45
-rw-r--r--src/gc_sound/src/gc-sound-object.c2
-rw-r--r--src/gc_sound/src/test_gc_sound.c22
8 files changed, 210 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index cd369f5..ab84474 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2006-12-12 Yves Combe <yves@ycombe.net>
+
+ GC_SOUND:
+ - add demo.py little python demo.
+ - add g_object_ref in mixer_sdl_new (fix bug in destroy).
+ - get filename returns a copy of the string, not the pointer itself.
+ - reset channel number when a channel is destroyed.
+
+ * src/gc_sound/ChangeLog:
+ * src/gc_sound/python/demo.py:
+ * src/gc_sound/python/gc_sound.override:
+ * src/gc_sound/src/gc-sound-item.c: (gc_sound_item_set_filename),
+ (gc_sound_item_get_filename), (gc_sound_item_class_init):
+ * src/gc_sound/src/gc-sound-mixer-SDL.c:
+ (gc_sound_mixer_sdl_open_audio), (reset_channel_number),
+ (channel_destroyed), (gc_sound_mixer_sdl_init),
+ (gc_sound_mixer_sdl_finalize), (gc_sound_mixer_sdl_destroy):
+ * src/gc_sound/src/gc-sound-object.c:
+ * src/gc_sound/src/test_gc_sound.c: (main):
+
2006-12-10 Yves Combe <yves@ycombe.net>
GC_SOUND
diff --git a/src/gc_sound/ChangeLog b/src/gc_sound/ChangeLog
index 138ae0c..f228e8f 100644
--- a/src/gc_sound/ChangeLog
+++ b/src/gc_sound/ChangeLog
@@ -1,3 +1,21 @@
+2006-12-12 Yves Combe <yves@ycombe.net>
+
+ add demo.py little python demo.
+ add g_object_ref in mixer_sdl_new (fix bug in destroy).
+ get filename returns a copy of the string, not the pointer itself.
+ reset channel number when a channel is destroyed.
+
+ * python/demo.py:
+ * python/gc_sound.override:
+ * src/gc-sound-item.c: (gc_sound_item_set_filename),
+ (gc_sound_item_get_filename), (gc_sound_item_class_init):
+ * src/gc-sound-mixer-SDL.c:
+ (gc_sound_mixer_sdl_open_audio), (reset_channel_number),
+ (channel_destroyed), (gc_sound_mixer_sdl_init),
+ (gc_sound_mixer_sdl_finalize), (gc_sound_mixer_sdl_destroy):
+ * src/gc-sound-object.c:
+ * src/test_gc_sound.c: (main):
+
2006-12-10 Yves Combe <yves@ycombe.net>
fix errors in destroy (destroy loop).
diff --git a/src/gc_sound/python/demo.py b/src/gc_sound/python/demo.py
new file mode 100644
index 0000000..cd09d18
--- /dev/null
+++ b/src/gc_sound/python/demo.py
@@ -0,0 +1,26 @@
+import sys
+sys.path.append('.libs')
+
+import gc_sound
+import gtk
+
+def cb_start(item):
+ print item.get_filename(), " started."
+
+def cb_stop(item, stopped):
+ print item.get_filename(), ' stopped ', stopped
+ print "Stopping loop."
+ gtk.main_quit()
+
+if __name__ == "__main__":
+ mix = gc_sound.MixerSdl()
+ chan = mix.new_channel()
+
+ item = chan.get_root().append_child()
+ item.set_filename("/home/ycombe/Win32/gcompris_main/gcompris/boards/sounds/youcannot.wav")
+
+ item.connect("play_start", cb_start)
+ item.connect("play_end", cb_stop)
+ item.play()
+
+ gtk.main()
diff --git a/src/gc_sound/python/gc_sound.override b/src/gc_sound/python/gc_sound.override
index bbc1062..d705eb3 100644
--- a/src/gc_sound/python/gc_sound.override
+++ b/src/gc_sound/python/gc_sound.override
@@ -18,3 +18,101 @@ import gobject.GObject as PyGObject_Type
ignore-glob
*_get_type
%%
+override-slot GcSoundObject
+
+/* ----------- GcSoundObject ----------- */
+
+static PyObject *
+_wrap_gc_sound_object_destroy(PyGObject *self)
+{
+
+ gc_sound_object_destroy(GC_SOUND_OBJECT(self->obj));
+
+ PyObject_Del(self);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static const PyMethodDef _PyGcSoundObject_methods[] = {
+ { "destroy", (PyCFunction)_wrap_gc_sound_object_destroy, METH_NOARGS,
+ NULL },
+ { NULL, NULL, 0, NULL }
+};
+
+static void
+py_gc_sound_object_dealloc(PyGcSoundObject *self)
+{
+ /* object is destroyed when python release it */
+ gc_sound_object_destroy(GC_SOUND_OBJECT(self->obj));
+
+ PyObject_GC_Del((PyObject*) self);
+}
+
+PyTypeObject G_GNUC_INTERNAL PyGcSoundObject_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "gc_sound.Object", /* tp_name */
+ sizeof(PyGObject), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ /* methods */
+ (destructor))py_gc_sound_object_dealloc, /* tp_dealloc */
+ (printfunc)0, /* tp_print */
+ (getattrfunc)0, /* tp_getattr */
+ (setattrfunc)0, /* tp_setattr */
+ (cmpfunc)0, /* tp_compare */
+ (reprfunc)0, /* tp_repr */
+ (PyNumberMethods*)0, /* tp_as_number */
+ (PySequenceMethods*)0, /* tp_as_sequence */
+ (PyMappingMethods*)0, /* tp_as_mapping */
+ (hashfunc)0, /* tp_hash */
+ (ternaryfunc)0, /* tp_call */
+ (reprfunc)0, /* tp_str */
+ (getattrofunc)0, /* tp_getattro */
+ (setattrofunc)0, /* tp_setattro */
+ (PyBufferProcs*)0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ NULL, /* Documentation string */
+ (traverseproc)0, /* tp_traverse */
+ (inquiry)0, /* tp_clear */
+ (richcmpfunc)0, /* tp_richcompare */
+ offsetof(PyGObject, weakreflist), /* tp_weaklistoffset */
+ (getiterfunc)0, /* tp_iter */
+ (iternextfunc)0, /* tp_iternext */
+ (struct PyMethodDef*)_PyGcSoundObject_methods, /* tp_methods */
+ (struct PyMemberDef*)0, /* tp_members */
+ (struct PyGetSetDef*)0, /* tp_getset */
+ NULL, /* tp_base */
+ NULL, /* tp_dict */
+ (descrgetfunc)0, /* tp_descr_get */
+ (descrsetfunc)0, /* tp_descr_set */
+ offsetof(PyGObject, inst_dict), /* tp_dictoffset */
+ (initproc)0, /* tp_init */
+ (allocfunc)0, /* tp_alloc */
+ (newfunc)0, /* tp_new */
+ (freefunc)0, /* tp_free */
+ (inquiry)0 /* tp_is_gc */
+};
+%%
+override gc_sound_mixer_sdl_new
+/* ----------- GcSoundMixerSdl ----------- */
+
+static int
+_wrap_gc_sound_mixer_sdl_new(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char* kwlist[] = { NULL };
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ ":gc_sound.MixerSdl.__init__",
+ kwlist))
+ return -1;
+
+ pygobject_constructv(self, 0, NULL);
+ if (!self->obj) {
+ PyErr_SetString(
+ PyExc_RuntimeError,
+ "could not create gc_sound.MixerSdl object");
+ return -1;
+ }
+ g_object_ref(G_OBJECT(self->obj));
+ return 0;
+}
diff --git a/src/gc_sound/src/gc-sound-item.c b/src/gc_sound/src/gc-sound-item.c
index d6aaebe..275a90f 100644
--- a/src/gc_sound/src/gc-sound-item.c
+++ b/src/gc_sound/src/gc-sound-item.c
@@ -166,6 +166,9 @@ gboolean gc_sound_item_play (GcSoundItem *self)
void gc_sound_item_set_filename (GcSoundItem *self, gchar *filename)
{
+ if (self->filename)
+ g_free (self->filename);
+
if (filename) {
self->filename = g_strdup(filename);
@@ -180,7 +183,7 @@ void gc_sound_item_set_filename (GcSoundItem *self, gchar *filename)
gchar * gc_sound_item_get_filename (GcSoundItem *self)
{
- return self->filename;
+ return g_strdup(self->filename);
}
static void
@@ -319,6 +322,13 @@ gc_sound_item_class_init(GcSoundItemClass* self_class)
"The channel where this channel stand",
GC_TYPE_SOUND_CHANNEL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_object_class_install_property(go_class,
+ PROP_FILENAME,
+ g_param_spec_string ("filename",
+ "File to play",
+ "The sound file to play",
+ NULL,
+ G_PARAM_READWRITE));
/* signals */
/* enum { */
diff --git a/src/gc_sound/src/gc-sound-mixer-SDL.c b/src/gc_sound/src/gc-sound-mixer-SDL.c
index 1edb622..64727da 100644
--- a/src/gc_sound/src/gc-sound-mixer-SDL.c
+++ b/src/gc_sound/src/gc-sound-mixer-SDL.c
@@ -70,7 +70,7 @@ gc_sound_mixer_sdl_open_audio (GcSoundMixer* mixer)
return FALSE;
}
- self->audio_opened = FALSE;
+ self->audio_opened = TRUE;
// print out some info on the audio device and stream
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
@@ -108,6 +108,13 @@ gc_sound_mixer_sdl_close_audio (GcSoundMixer * mixer)
static void reset_channel_number(GcSoundChannel *channel, gboolean stopped, gpointer data)
{
channel->channel_number = GPOINTER_TO_INT(data);
+ GcSoundMixerSdl *self = GC_SOUND_MIXER_SDL(GC_SOUND_OBJECT(channel)->parent);
+
+ /* if this channel is last in list, we can now reset numbers of channel */
+ if (self->channels->len == channel->channel_number + 1){
+ Mix_AllocateChannels(channel->channel_number + 1);
+ g_warning ("Numbers of channels allocated is now %d", Mix_AllocateChannels(-1));
+ }
}
static void channel_destroyed(GcSoundChannel *channel, gpointer data)
@@ -121,9 +128,8 @@ static void channel_destroyed(GcSoundChannel *channel, gpointer data)
// not be finalized before it get this signal.
gc_sound_mixer_halt_channel (GC_SOUND_MIXER(self), channel);
}
-
+
g_ptr_array_remove_index (self->channels, channel->channel_number);
- g_object_unref (channel);
/* channel reorganisation */
for (i = 0; i < self->channels->len; i++) {
@@ -136,6 +142,15 @@ static void channel_destroyed(GcSoundChannel *channel, gpointer data)
reset_channel_number ( i_channel, FALSE, GINT_TO_POINTER(i));
}
}
+
+ /* destroyed channel is last one */
+ if (self->channels->len == channel->channel_number){
+ Mix_AllocateChannels(channel->channel_number + 1);
+ g_warning ("Numbers of channels allocated is now %d", Mix_AllocateChannels(-1));
+ }
+
+ g_object_unref (channel);
+
}
static GcSoundChannel *gc_sound_mixer_sdl_new_channel (GcSoundMixer * mixer)
@@ -351,9 +366,8 @@ gc_sound_mixer_sdl_init (GcSoundMixerSdl* self)
}
/* like GtkWindow */
- g_object_ref_sink (self);
+ g_object_ref_sink (G_OBJECT(self));
self->has_user_ref_count = TRUE;
-
}
enum {
@@ -368,19 +382,10 @@ gc_sound_mixer_sdl_finalize (GObject* object)
{
GcSoundMixerSdl * self = GC_SOUND_MIXER_SDL(object);
- running_mixer = NULL;
-
g_ptr_array_free (self->channels, TRUE);
g_hash_table_destroy (self->samples);
- if (self->audio_opened)
- Mix_CloseAudio();
-
- SDL_Quit();
-
- g_warning("SDL audio closed");
-
G_OBJECT_CLASS(parent_class)->finalize (object);
}
@@ -396,6 +401,18 @@ gc_sound_mixer_sdl_destroy (GcSoundObject *object)
gc_sound_object_destroy (GC_SOUND_OBJECT(g_ptr_array_index(self->channels,i)));
g_object_unref(G_OBJECT(g_ptr_array_index(self->channels,i)));
}
+
+ running_mixer = NULL;
+
+ if (self->audio_opened){
+ Mix_CloseAudio();
+ self->audio_opened = FALSE;
+ g_warning ("SDL audio closed");
+ } else
+ g_warning("mixer destroy: SDL audio was closed !");
+
+ SDL_Quit();
+
if (self->has_user_ref_count)
{
diff --git a/src/gc_sound/src/gc-sound-object.c b/src/gc_sound/src/gc-sound-object.c
index 67fad8f..f313cf6 100644
--- a/src/gc_sound/src/gc-sound-object.c
+++ b/src/gc_sound/src/gc-sound-object.c
@@ -1,4 +1,4 @@
-/* gcompris - gc-sound-object.h
+/* gcompris - gc-sound-object.c
*
* Copyright (C) 2006 Yves Combe
*
diff --git a/src/gc_sound/src/test_gc_sound.c b/src/gc_sound/src/test_gc_sound.c
index 082caf0..afa36dd 100644
--- a/src/gc_sound/src/test_gc_sound.c
+++ b/src/gc_sound/src/test_gc_sound.c
@@ -23,28 +23,16 @@ main (int argc, char *argv)
gcmix = gc_sound_mixer_sdl_new();
GC_SOUND_OBJECT(gcmix)->nick = "gcmix";
- g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count);
-
/* We open two chans to play simultaneously */
gcchan1 = gc_sound_mixer_new_channel(gcmix);
- g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count);
-
gcchan2 = gc_sound_mixer_new_channel(gcmix);
- g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count);
GC_SOUND_OBJECT(gcchan1)->nick = "gcchan1";
GC_SOUND_OBJECT(gcchan2)->nick = "gcchan2";
- //GcSoundMixer *gcmix2;
-
- //g_object_get(G_OBJECT(gcchan2), "parent", &gcmix2, NULL);
-
/* Each chan has a root item, where we group the sounds to play in that channel*/
root1 = GC_SOUND_ITEM(gc_sound_channel_get_root(gcchan1));
- g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count);
-
root2 = GC_SOUND_ITEM(gc_sound_channel_get_root(gcchan2));
- g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count);
GC_SOUND_OBJECT(root1)->nick="root1";
GC_SOUND_OBJECT(root2)->nick="root2";
@@ -57,8 +45,6 @@ main (int argc, char *argv)
item1_2 = gc_sound_item_append_child (item1);
- g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count);
-
GC_SOUND_OBJECT(item1)->nick = "item1";
GC_SOUND_OBJECT(item2)->nick = "item2";
GC_SOUND_OBJECT(item3)->nick = "item3";
@@ -114,16 +100,18 @@ main (int argc, char *argv)
gc_sound_item_play(item3);
//gc_sound_object_destroy(GC_SOUND_OBJECT(gcchan2));
+ g_warning("destroying item1");
gc_sound_object_destroy(GC_SOUND_OBJECT(item1));
- g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count);
+
g_usleep(3000000);
+ g_warning("destroying root2");
gc_sound_object_destroy(GC_SOUND_OBJECT(root2));
- g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count);
g_usleep(3000000);
+ g_warning("destroying gcmix");
gc_sound_object_destroy(GC_SOUND_OBJECT(gcmix));
- g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count);
+
//gc_sound_object_destroy(GC_SOUND_OBJECT(gcmix2));
g_usleep(3000000);