Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2006-05-06 10:17:46 +0400
committerCampbell Barton <ideasman42@gmail.com>2006-05-06 10:17:46 +0400
commite9718958ee2d0425e9cdc8e403ffc05ecc669872 (patch)
tree2be45d1c7ec9f7d2a2820a4ed158370f04cc1dcb /source/blender/python/api2_2x/Sound.c
parent75f4416e32353af374c08f18f46c4c5f80dd7985 (diff)
Applied pack unpack from Pablo Martin (caedes),
http://projects.blender.org/tracker/?func=detail&atid=127&aid=3246&group_id=9 adds Blender.c: Blender.UnpackModes (dict with the unpack modes) Blender.UnpackAll(mode) Blender.PackAll() Blender.CountPackedFiles() Image.c: image.packed (this was working) image.pack() image.unpack() Sound.c: sound.packed sound.pack() sound.unpack()
Diffstat (limited to 'source/blender/python/api2_2x/Sound.c')
-rw-r--r--source/blender/python/api2_2x/Sound.c76
1 files changed, 74 insertions, 2 deletions
diff --git a/source/blender/python/api2_2x/Sound.c b/source/blender/python/api2_2x/Sound.c
index 21aa8af0691..2b7316b4045 100644
--- a/source/blender/python/api2_2x/Sound.c
+++ b/source/blender/python/api2_2x/Sound.c
@@ -35,7 +35,9 @@
#include "BKE_global.h"
#include "BKE_main.h"
#include "BLI_blenlib.h"
+#include "BKE_sound.h"
#include "BIF_editsound.h"
+#include "BKE_packedFile.h"
#include "mydevice.h" /* redraw defines */
#include "gen_utils.h"
@@ -123,6 +125,8 @@ static PyObject *Sound_getName( BPy_Sound * self );
static PyObject *Sound_getFilename( BPy_Sound * self );
static PyObject *Sound_play( BPy_Sound * self );
static PyObject *Sound_setCurrent( BPy_Sound * self );
+static PyObject *Sound_unpack( BPy_Sound * self, PyObject * args);
+static PyObject *Sound_pack( BPy_Sound * self );
//static PyObject *Sound_reload ( BPy_Sound * self );
SOUND_FLOAT_METHODS( Volume, volume )
SOUND_FLOAT_METHODS( Attenuation, attenuation )
@@ -148,7 +152,10 @@ static PyMethodDef BPy_Sound_methods[] = {
"() - play this sound"},
{"setCurrent", ( PyCFunction ) Sound_setCurrent, METH_NOARGS,
"() - make this the active sound in the sound buttons win (also redraws)"},
-
+ {"unpack", ( PyCFunction ) Sound_unpack, METH_VARARGS,
+ "(int) - Unpack sound. Uses one of the values defined in Blender.UnpackModes."},
+ {"pack", ( PyCFunction ) Sound_pack, METH_NOARGS,
+ "() Pack the sound"},
/*
{"reload", ( PyCFunction ) Sound_setCurrent, METH_NOARGS,
"() - reload this Sound object's sample.\n\
@@ -428,6 +435,57 @@ static PyObject *Sound_setCurrent( BPy_Sound * self )
Py_INCREF( Py_None );
return Py_None;
}
+
+/* unpack sound */
+
+static PyObject *Sound_unpack( BPy_Sound * self, PyObject * args )
+{
+ bSound *sound = self->sound;
+ int mode;
+ if( !PyArg_ParseTuple( args, "i", &mode ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected 1 integer" );
+
+ if (!sound_sample_is_null(sound))
+ {
+ bSample *sample = sound_find_sample(sound);
+ if (sample->packedfile==NULL)
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "sound not packed" );
+ if (unpackSample(sample, mode) == RET_ERROR)
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "error unpacking sound" );
+ }
+ else
+ {
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "sound has no samples" );
+ }
+ Py_RETURN_NONE;
+
+}
+
+/* pack sound */
+
+static PyObject *Sound_pack( BPy_Sound * self )
+{
+ bSound *sound = self->sound;
+ if (!sound_sample_is_null(sound))
+ {
+ bSample *sample = sound_find_sample(sound);
+ if (sample->packedfile )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "sound alredy packed" );
+ sound_set_packedfile(sample, newPackedFile(sample->name));
+ }
+ else
+ {
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "sound has no samples" );
+ }
+ Py_RETURN_NONE;
+}
+
/*
static PyObject *Sound_reload( BPy_Sound * self)
{
@@ -459,7 +517,19 @@ static PyObject *Sound_getAttr( BPy_Sound * self, char *name )
else if( strcmp( name, "__members__" ) == 0 )
attr = Py_BuildValue( "[s,s]", "name", "filename" );
-
+ else if( strcmp( name, "packed" ) == 0 ) {
+ if (!sound_sample_is_null(self->sound))
+ {
+ bSample *sample = sound_find_sample(self->sound);
+ if (sample->packedfile)
+ attr = EXPP_incr_ret_True();
+ else
+ attr = EXPP_incr_ret_False();
+ }
+ else
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "Sound has no sample to unpack!" ) );
+ }
if( !attr )
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create PyObject" ) );
@@ -538,3 +608,5 @@ static PyObject *Sound_repr( BPy_Sound * self )
return PyString_FromFormat( "[Sound \"%s\"]",
self->sound->id.name + 2 );
}
+
+