2004-08-17 04:26:00 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version. The Blender
|
|
|
|
* Foundation also sells licenses for use in proprietary software under
|
|
|
|
* the Blender License. See http://www.blender.org/BL/ for information
|
|
|
|
* about this.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This is a new part of Blender.
|
|
|
|
*
|
|
|
|
* Contributor(s): Chris Keith
|
|
|
|
*
|
|
|
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2005-07-18 03:50:37 +00:00
|
|
|
#include "Sound.h" /*This must come first*/
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2005-07-18 03:50:37 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BLI_blenlib.h"
|
2006-05-06 06:17:46 +00:00
|
|
|
#include "BKE_sound.h"
|
2005-07-18 03:50:37 +00:00
|
|
|
#include "BIF_editsound.h"
|
2006-05-06 06:17:46 +00:00
|
|
|
#include "BKE_packedFile.h"
|
2004-09-25 20:30:40 +00:00
|
|
|
#include "mydevice.h" /* redraw defines */
|
2004-08-17 04:26:00 +00:00
|
|
|
#include "gen_utils.h"
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python BPy_Sound defaults: */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
#define EXPP_SND_volume_MIN 0.0
|
|
|
|
#define EXPP_SND_volume_MAX 1.0
|
|
|
|
#define EXPP_SND_pitch_MIN -12.0
|
|
|
|
#define EXPP_SND_pitch_MAX 12.0
|
|
|
|
#define EXPP_SND_attenuation_MIN 0.0
|
|
|
|
#define EXPP_SND_attenuation_MAX 5.0
|
|
|
|
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Python API function prototypes for the Sound module. */
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Sound_Get( PyObject * self, PyObject * args );
|
|
|
|
static PyObject *M_Sound_Load( PyObject * self, PyObject * args );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* The following string definitions are used for documentation strings. */
|
|
|
|
/* In Python these will be written to the console when doing a */
|
|
|
|
/* Blender.Sound.__doc__ */
|
|
|
|
/************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static char M_Sound_doc[] = "The Blender Sound module\n\n";
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
static char M_Sound_Get_doc[] =
|
2004-09-25 20:30:40 +00:00
|
|
|
"(name) - return the sound with the name 'name', \
|
2004-08-17 04:26:00 +00:00
|
|
|
returns None if not found.\n If 'name' is not specified, \
|
|
|
|
it returns a list of all sounds in the\ncurrent scene.";
|
|
|
|
|
|
|
|
static char M_Sound_Load_doc[] =
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
"(filename) - return sound from file filename as a Sound Object,\n\
|
2004-08-17 04:26:00 +00:00
|
|
|
returns None if not found.";
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Python method structure definition for Blender.Sound module: */
|
|
|
|
/*****************************************************************************/
|
|
|
|
struct PyMethodDef M_Sound_methods[] = {
|
2004-09-25 20:30:40 +00:00
|
|
|
{"Get", M_Sound_Get, METH_VARARGS, M_Sound_Get_doc},
|
|
|
|
{"Load", M_Sound_Load, METH_VARARGS, M_Sound_Load_doc},
|
2004-08-17 04:26:00 +00:00
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python Sound_Type callback function prototypes: */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static void Sound_dealloc( BPy_Sound * self );
|
|
|
|
static int Sound_setAttr( BPy_Sound * self, char *name, PyObject * v );
|
|
|
|
static int Sound_compare( BPy_Sound * a, BPy_Sound * b );
|
|
|
|
static PyObject *Sound_getAttr( BPy_Sound * self, char *name );
|
|
|
|
static PyObject *Sound_repr( BPy_Sound * self );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
#define SOUND_FLOAT_METHODS(funcname, varname) \
|
|
|
|
static PyObject *Sound_get ## funcname(BPy_Sound *self) { \
|
|
|
|
char e[256]; \
|
|
|
|
PyObject *attr = PyFloat_FromDouble(self->sound->varname); \
|
|
|
|
if (attr) return attr; \
|
|
|
|
sprintf(e, "couldn't get Sound.%s attribute", #varname); \
|
|
|
|
return EXPP_ReturnPyObjError (PyExc_RuntimeError, e); \
|
|
|
|
} \
|
|
|
|
static PyObject *Sound_set ## funcname(BPy_Sound *self, PyObject *args) { \
|
|
|
|
float f = 0; \
|
|
|
|
if (!PyArg_ParseTuple(args, "f", &f)) \
|
|
|
|
return (EXPP_ReturnPyObjError (PyExc_TypeError, \
|
|
|
|
"expected float argument")); \
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
self->sound->varname = EXPP_ClampFloat(f,\
|
|
|
|
EXPP_SND_##varname##_MIN, EXPP_SND_##varname##_MAX);\
|
2004-08-17 04:26:00 +00:00
|
|
|
Py_INCREF(Py_None); \
|
|
|
|
return Py_None; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SOUND_FLOAT_METHOD_FUNCS(varname) \
|
|
|
|
{"get"#varname, (PyCFunction)Sound_get ## varname, METH_NOARGS, \
|
|
|
|
"() - Return Sound object "#varname}, \
|
|
|
|
{"set"#varname, (PyCFunction)Sound_set ## varname, METH_VARARGS, \
|
|
|
|
"(float) - Change Sound object "#varname},
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python BPy_Sound methods declarations: */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Sound_getName( BPy_Sound * self );
|
|
|
|
static PyObject *Sound_getFilename( BPy_Sound * self );
|
|
|
|
static PyObject *Sound_play( BPy_Sound * self );
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
static PyObject *Sound_setCurrent( BPy_Sound * self );
|
2006-05-06 06:17:46 +00:00
|
|
|
static PyObject *Sound_unpack( BPy_Sound * self, PyObject * args);
|
|
|
|
static PyObject *Sound_pack( BPy_Sound * self );
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
//static PyObject *Sound_reload ( BPy_Sound * self );
|
2004-09-25 20:30:40 +00:00
|
|
|
SOUND_FLOAT_METHODS( Volume, volume )
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
SOUND_FLOAT_METHODS( Attenuation, attenuation )
|
|
|
|
SOUND_FLOAT_METHODS( Pitch, pitch )
|
|
|
|
/* these can't be set via interface, removed for now */
|
|
|
|
/*
|
|
|
|
SOUND_FLOAT_METHODS( Panning, panning )
|
|
|
|
SOUND_FLOAT_METHODS( MinGain, min_gain )
|
|
|
|
SOUND_FLOAT_METHODS( MaxGain, max_gain )
|
|
|
|
SOUND_FLOAT_METHODS( Distance, distance )
|
|
|
|
*/
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python BPy_Sound methods table: */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
static PyMethodDef BPy_Sound_methods[] = {
|
2004-09-25 20:30:40 +00:00
|
|
|
/* name, method, flags, doc */
|
|
|
|
{"getName", ( PyCFunction ) Sound_getName, METH_NOARGS,
|
|
|
|
"() - Return Sound object name"},
|
|
|
|
{"getFilename", ( PyCFunction ) Sound_getFilename, METH_NOARGS,
|
|
|
|
"() - Return Sound object filename"},
|
|
|
|
{"play", ( PyCFunction ) Sound_play, METH_NOARGS,
|
|
|
|
"() - play this sound"},
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
{"setCurrent", ( PyCFunction ) Sound_setCurrent, METH_NOARGS,
|
2004-09-25 20:30:40 +00:00
|
|
|
"() - make this the active sound in the sound buttons win (also redraws)"},
|
2006-05-06 06:17:46 +00:00
|
|
|
{"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"},
|
2005-03-09 19:45:59 +00:00
|
|
|
/*
|
|
|
|
{"reload", ( PyCFunction ) Sound_setCurrent, METH_NOARGS,
|
|
|
|
"() - reload this Sound object's sample.\n\
|
|
|
|
This is only useful if the original sound file has changed."},
|
|
|
|
*/
|
2004-09-25 20:30:40 +00:00
|
|
|
SOUND_FLOAT_METHOD_FUNCS( Volume )
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
SOUND_FLOAT_METHOD_FUNCS( Attenuation )
|
|
|
|
SOUND_FLOAT_METHOD_FUNCS( Pitch )
|
|
|
|
/*
|
|
|
|
SOUND_FLOAT_METHOD_FUNCS( Panning )
|
|
|
|
SOUND_FLOAT_METHOD_FUNCS( MinGain )
|
|
|
|
SOUND_FLOAT_METHOD_FUNCS( MaxGain )
|
|
|
|
SOUND_FLOAT_METHOD_FUNCS( Distance )
|
|
|
|
*/
|
|
|
|
{NULL, NULL, 0, NULL}
|
2004-08-17 04:26:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python Sound_Type structure definition: */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyTypeObject Sound_Type = {
|
|
|
|
PyObject_HEAD_INIT( NULL )
|
|
|
|
0, /* ob_size */
|
|
|
|
"Blender Sound", /* tp_name */
|
|
|
|
sizeof( BPy_Sound ), /* tp_basicsize */
|
|
|
|
0, /* tp_itemsize */
|
2004-08-17 04:26:00 +00:00
|
|
|
/* methods */
|
2004-09-25 20:30:40 +00:00
|
|
|
( destructor ) Sound_dealloc, /* tp_dealloc */
|
|
|
|
0, /* tp_print */
|
|
|
|
( getattrfunc ) Sound_getAttr, /* tp_getattr */
|
|
|
|
( setattrfunc ) Sound_setAttr, /* tp_setattr */
|
|
|
|
( cmpfunc ) Sound_compare, /* tp_compare */
|
|
|
|
( reprfunc ) Sound_repr, /* tp_repr */
|
|
|
|
0, /* tp_as_number */
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
0, /* tp_as_hash */
|
|
|
|
0, 0, 0, 0, 0, 0,
|
|
|
|
0, /* tp_doc */
|
|
|
|
0, 0, 0, 0, 0, 0,
|
|
|
|
BPy_Sound_methods, /* tp_methods */
|
|
|
|
0, /* tp_members */
|
2004-08-17 04:26:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* NOTE: these were copied and modified from image.h. To Be Done TBD:
|
|
|
|
* macro-ize them, or C++ templates eventually?
|
|
|
|
*/
|
2004-09-25 20:30:40 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Function: M_Sound_Get */
|
|
|
|
/* Python equivalent: Blender.Sound.Get */
|
|
|
|
/* Description: Receives a string and returns the Sound object */
|
|
|
|
/* whose name matches the string. If no argument is */
|
|
|
|
/* passed in, a list of all Sound names in the */
|
|
|
|
/* current scene is returned. */
|
|
|
|
/****************************************************************************/
|
|
|
|
static PyObject *M_Sound_Get( PyObject * self, PyObject * args )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
char *name = NULL;
|
2004-08-17 04:26:00 +00:00
|
|
|
bSound *snd_iter;
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
"expected string argument (or nothing)" ) );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
snd_iter = G.main->sound.first;
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( name ) { /* (name) - Search Sound by name */
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
BPy_Sound *wanted_Sound = NULL;
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( ( snd_iter ) && ( wanted_Sound == NULL ) ) {
|
|
|
|
if( strcmp( name, snd_iter->id.name + 2 ) == 0 ) {
|
|
|
|
wanted_Sound =
|
|
|
|
( BPy_Sound * )
|
|
|
|
PyObject_NEW( BPy_Sound, &Sound_Type );
|
|
|
|
if( wanted_Sound ) {
|
2004-08-17 04:26:00 +00:00
|
|
|
wanted_Sound->sound = snd_iter;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
snd_iter = snd_iter->id.next;
|
|
|
|
}
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( wanted_Sound == NULL ) { /* Requested Sound doesn't exist */
|
2004-08-17 04:26:00 +00:00
|
|
|
char error_msg[64];
|
2004-09-25 20:30:40 +00:00
|
|
|
PyOS_snprintf( error_msg, sizeof( error_msg ),
|
|
|
|
"Sound \"%s\" not found", name );
|
|
|
|
return ( EXPP_ReturnPyObjError
|
|
|
|
( PyExc_NameError, error_msg ) );
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( PyObject * ) wanted_Sound;
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
else { /* () - return a list of all Sounds in the scene */
|
2004-08-17 04:26:00 +00:00
|
|
|
int index = 0;
|
|
|
|
PyObject *snd_list, *pyobj;
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
snd_list = PyList_New( BLI_countlist( &( G.main->sound ) ) );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( snd_list == NULL )
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
"couldn't create PyList" ) );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( snd_iter ) {
|
|
|
|
pyobj = Sound_CreatePyObject( snd_iter );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !pyobj )
|
|
|
|
return ( EXPP_ReturnPyObjError
|
|
|
|
( PyExc_MemoryError,
|
|
|
|
"couldn't create PyObject" ) );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
PyList_SET_ITEM( snd_list, index, pyobj );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
snd_iter = snd_iter->id.next;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( snd_list );
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: M_Sound_Load */
|
|
|
|
/* Python equivalent: Blender.Sound.Load */
|
|
|
|
/* Description: Receives a string and returns the Sound object */
|
|
|
|
/* whose filename matches the string. */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Sound_Load( PyObject * self, PyObject * args )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
char *fname;
|
|
|
|
bSound *snd_ptr;
|
2004-08-17 04:26:00 +00:00
|
|
|
BPy_Sound *snd;
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "s", &fname ) )
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
"expected string argument" ) );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
snd = ( BPy_Sound * ) PyObject_NEW( BPy_Sound, &Sound_Type );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !snd )
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
"couldn't create PyObject Sound_Type" ) );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
snd_ptr = sound_new_sound( fname );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( snd_ptr ) {
|
|
|
|
if( G.ssound ) {
|
|
|
|
G.ssound->sound = snd_ptr;
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !snd_ptr )
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_IOError,
|
|
|
|
"not a valid sound sample" ) );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
snd->sound = snd_ptr;
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( PyObject * ) snd;
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Sound_Init */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *Sound_Init( void )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *submodule;
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
Sound_Type.ob_type = &PyType_Type;
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
submodule =
|
|
|
|
Py_InitModule3( "Blender.Sound", M_Sound_methods,
|
|
|
|
M_Sound_doc );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( submodule );
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************/
|
|
|
|
/*** The Sound PyType ***/
|
|
|
|
/************************/
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Sound_dealloc */
|
|
|
|
/* Description: This is a callback function for the BPy_Sound type. It is */
|
|
|
|
/* the destructor function. */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static void Sound_dealloc( BPy_Sound * self )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject_DEL( self );
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Sound_CreatePyObject */
|
|
|
|
/* Description: This function will create a new BPy_Sound from an existing */
|
|
|
|
/* Blender Sound structure. */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *Sound_CreatePyObject( bSound * snd )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
|
|
|
BPy_Sound *py_snd;
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
py_snd = ( BPy_Sound * ) PyObject_NEW( BPy_Sound, &Sound_Type );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !py_snd )
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
"couldn't create BPy_Sound object" );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
py_snd->sound = snd;
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( PyObject * ) py_snd;
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Sound_CheckPyObject */
|
2004-08-17 04:26:00 +00:00
|
|
|
/* Description: This function returns true when the given PyObject is of the */
|
2004-09-25 20:30:40 +00:00
|
|
|
/* type Sound. Otherwise it will return false. */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
int Sound_CheckPyObject( PyObject * pyobj )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( pyobj->ob_type == &Sound_Type );
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Sound_FromPyObject */
|
|
|
|
/* Description: Returns the Blender Sound associated with this object */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
bSound *Sound_FromPyObject( PyObject * pyobj )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( ( BPy_Sound * ) pyobj )->sound;
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python BPy_Sound methods: */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Sound_getName( BPy_Sound * self )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyString_FromString( self->sound->id.name + 2 );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
return attr;
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
"couldn't get Sound.name attribute" ) );
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Sound_getFilename( BPy_Sound * self )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyString_FromString( self->sound->name );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
return attr;
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
"couldn't get Sound.filename attribute" ) );
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Sound_play( BPy_Sound * self )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
sound_play_sound( self->sound );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2004-08-17 04:26:00 +00:00
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
static PyObject *Sound_setCurrent( BPy_Sound * self )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
|
|
|
bSound *snd_ptr = self->sound;
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( snd_ptr ) {
|
|
|
|
if( G.ssound ) {
|
2004-08-17 04:26:00 +00:00
|
|
|
G.ssound->sound = snd_ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
EXPP_allqueue( REDRAWSOUND, 0 );
|
|
|
|
EXPP_allqueue( REDRAWBUTSLOGIC, 0 );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
2004-08-17 04:26:00 +00:00
|
|
|
return Py_None;
|
|
|
|
}
|
2006-05-06 06:17:46 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
/*
|
|
|
|
static PyObject *Sound_reload( BPy_Sound * self)
|
|
|
|
{
|
|
|
|
sound_free_sample();
|
|
|
|
|
|
|
|
if (sound->snd_sound) {
|
|
|
|
SND_RemoveSound(ghSoundScene, sound->snd_sound);
|
|
|
|
sound->snd_sound = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXPP_incr_ret( Py_None );
|
|
|
|
}
|
|
|
|
*/
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Sound_getAttr */
|
|
|
|
/* Description: This is a callback function for the BPy_Sound type. It is */
|
|
|
|
/* the function that accesses BPy_Sound member variables and */
|
|
|
|
/* methods. */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Sound_getAttr( BPy_Sound * self, char *name )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
|
|
|
PyObject *attr = Py_None;
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( strcmp( name, "name" ) == 0 )
|
|
|
|
attr = PyString_FromString( self->sound->id.name + 2 );
|
|
|
|
else if( strcmp( name, "filename" ) == 0 )
|
|
|
|
attr = PyString_FromString( self->sound->name );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( strcmp( name, "__members__" ) == 0 )
|
|
|
|
attr = Py_BuildValue( "[s,s]", "name", "filename" );
|
2006-05-06 06:17:46 +00:00
|
|
|
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!" ) );
|
|
|
|
}
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !attr )
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
"couldn't create PyObject" ) );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr != Py_None )
|
|
|
|
return attr; /* attribute found, return its value */
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
/* not an attribute, search the methods table */
|
2004-09-25 20:30:40 +00:00
|
|
|
return Py_FindMethod( BPy_Sound_methods, ( PyObject * ) self, name );
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Sound_setAttr */
|
2004-08-17 04:26:00 +00:00
|
|
|
/* Description: This is a callback function for the BPy_Sound type. It is the*/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* function that changes Sound object members values. If this */
|
|
|
|
/* data is linked to a Blender Sound, it also gets updated. */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static int Sound_setAttr( BPy_Sound * self, char *name, PyObject * value )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *valtuple;
|
2005-07-18 03:50:37 +00:00
|
|
|
// PyObject *error = NULL;
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
/* We're playing a trick on the Python API users here. Even if they use
|
|
|
|
* Sound.member = val instead of Sound.setMember(value), we end up using the
|
|
|
|
* function anyway, since it already has error checking, clamps to the right
|
|
|
|
* interval and updates the Blender Sound structure when necessary. */
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
valtuple = Py_BuildValue( "(O)", value ); /*the set* functions expect a tuple */
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !valtuple )
|
|
|
|
return EXPP_ReturnIntError( PyExc_MemoryError,
|
|
|
|
"SoundSetAttr: couldn't create PyTuple" );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
|
|
|
/* if (strcmp (name, "name") == 0)
|
|
|
|
error = Sound_setName (self, valtuple);
|
2004-09-25 20:30:40 +00:00
|
|
|
else */ {
|
|
|
|
/* Error: no such member in the Sound object structure */
|
|
|
|
Py_DECREF( value );
|
|
|
|
Py_DECREF( valtuple );
|
|
|
|
return ( EXPP_ReturnIntError( PyExc_KeyError,
|
|
|
|
"attribute not found or immutable" ) );
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
2005-07-18 03:50:37 +00:00
|
|
|
/* ===This code is unreachable===
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_DECREF( valtuple );
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( error != Py_None )
|
|
|
|
return -1;
|
2004-08-17 04:26:00 +00:00
|
|
|
|
2005-07-18 03:50:37 +00:00
|
|
|
Py_DECREF( Py_None ); // incref'ed by the called set* function /
|
|
|
|
return 0; // normal exit
|
|
|
|
*/
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Sound_compare */
|
|
|
|
/* Description: This is a callback function for the BPy_Sound type. It */
|
|
|
|
/* compares two Sound_Type objects. Only the "==" and "!=" */
|
|
|
|
/* comparisons are meaninful. Returns 0 for equality and -1 if */
|
|
|
|
/* they don't point to the same Blender Sound struct. */
|
|
|
|
/* In Python it becomes 1 if they are equal, 0 otherwise. */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static int Sound_compare( BPy_Sound * a, BPy_Sound * b )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
|
|
|
bSound *pa = a->sound, *pb = b->sound;
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( pa == pb ) ? 0 : -1;
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Sound_repr */
|
|
|
|
/* Description: This is a callback function for the BPy_Sound type. It */
|
|
|
|
/* builds a meaninful string to represent Sound objects. */
|
2004-08-17 04:26:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Sound_repr( BPy_Sound * self )
|
2004-08-17 04:26:00 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
return PyString_FromFormat( "[Sound \"%s\"]",
|
|
|
|
self->sound->id.name + 2 );
|
2004-08-17 04:26:00 +00:00
|
|
|
}
|
2006-05-06 06:17:46 +00:00
|
|
|
|
|
|
|
|