From 7a27ebbd7927004c5413b1dc80eff40e5e933203 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Wed, 17 Jan 2007 11:22:04 +0000 Subject: [PATCH] wrap mixer set_volume, use tuple to match get_volume Original commit message from CVS: * examples/mixer.py: * gst/interfaces.override: wrap mixer set_volume, use tuple to match get_volume --- ChangeLog | 6 ++++++ examples/mixer.py | 17 ++++++++++++++--- gst/interfaces.override | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1570b48..759cd19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-01-17 Thomas Vander Stichele + * examples/mixer.py: + * gst/interfaces.override: + wrap mixer set_volume, use tuple to match get_volume + +2007-01-17 Thomas Vander Stichele + * gst/pygstexception.c: (element_not_found_error_init), (pygst_exceptions_register_classes): * gst/pygstexception.h: diff --git a/examples/mixer.py b/examples/mixer.py index 73a3d80..e9cb432 100644 --- a/examples/mixer.py +++ b/examples/mixer.py @@ -6,15 +6,26 @@ import sys import gst import gst.interfaces -a = gst.element_factory_make('alsasrc') -print a.set_state(gst.STATE_PLAYING) +pipeline = "alsasrc" +if sys.argv[1:]: + pipeline = " ".join(sys.argv[1:]) +a = gst.element_factory_make(pipeline) +print dir(a) + +res = a.set_state(gst.STATE_PAUSED) +if res != gst.STATE_CHANGE_SUCCESS: + print "Could not set pipeline %s to PAUSED" % pipeline print "Inputs:" for t in a.list_tracks(): if t.flags & gst.interfaces.MIXER_TRACK_INPUT: sys.stdout.write(t.label) sys.stdout.write(': %d - %d' % (t.min_volume, t.max_volume)) - sys.stdout.write(': %r' % (a.get_volume(t), )) + volumes = a.get_volume(t) + sys.stdout.write(': %r' % (volumes, )) + if t.props.num_channels > 0: + a.set_volume(t, volumes=volumes) if t.flags & gst.interfaces.MIXER_TRACK_RECORD: sys.stdout.write(' (selected)') sys.stdout.write('\n') + diff --git a/gst/interfaces.override b/gst/interfaces.override index 89d15e5..7775d1e 100644 --- a/gst/interfaces.override +++ b/gst/interfaces.override @@ -163,6 +163,51 @@ _wrap_gst_mixer_options_get_values (PyGObject *self) } %% +override gst_mixer_set_volume kwargs +static PyObject * +_wrap_gst_mixer_set_volume (PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "track", "volumes", NULL }; + PyGObject *track; + PyObject *py_tuple; + gint *volumes = NULL; + gint channels; + int i; + PyObject *ret; + + if (!PyArg_ParseTupleAndKeywords (args, kwargs, "O!O:GstMixer.set_volume", + kwlist, &PyGstMixerTrack_Type, &track, &py_tuple)) + return NULL; + + g_object_get (GST_MIXER_TRACK (track->obj), "num-channels", &channels, + NULL); + + if (channels != PyTuple_Size (py_tuple)) { + PyErr_Format (PyExc_TypeError, + "Track channel count %d != volume tuple size %d", + channels, PyTuple_Size (py_tuple)); + return NULL; + } + + Py_INCREF(Py_None); + ret = Py_None; + + if (channels == 0) + return ret; + + volumes = g_malloc (channels * sizeof (gint)); + for (i = 0; i < channels; ++i) { + volumes[i] = PyInt_AsLong (PyTuple_GET_ITEM (py_tuple, i)); + } + gst_mixer_set_volume (GST_MIXER (self->obj), GST_MIXER_TRACK (track->obj), + volumes); + + g_free (volumes); + + return ret; +} + +%% override gst_mixer_get_volume kwargs static PyObject * _wrap_gst_mixer_get_volume (PyGObject *self, PyObject *args, PyObject *kwargs) -- 2.7.4