154
153
"() - Return Sound object filename"},
155
154
{"setName", ( PyCFunction ) Sound_setName, METH_VARARGS,
156
155
"(name) - Set Sound object name"},
157
{"setFilename", ( PyCFunction ) Sound_setFilename, METH_VARARGS,
156
{"setFilename", ( PyCFunction ) Sound_oldsetFilename, METH_VARARGS,
158
157
"(filename) - Set Sound object filename"},
159
158
{"setCurrent", ( PyCFunction ) Sound_setCurrent, METH_NOARGS,
160
159
"() - make this the active sound in the sound buttons win (also redraws)"},
181
180
{NULL, NULL, 0, NULL}
184
/*****************************************************************************/
185
/* Python Sound_Type structure definition: */
186
/*****************************************************************************/
187
PyTypeObject Sound_Type = {
188
PyObject_HEAD_INIT( NULL )
190
"Blender Sound", /* tp_name */
191
sizeof( BPy_Sound ), /* tp_basicsize */
194
( destructor ) Sound_dealloc, /* tp_dealloc */
196
( getattrfunc ) Sound_getAttr, /* tp_getattr */
197
( setattrfunc ) Sound_setAttr, /* tp_setattr */
198
( cmpfunc ) Sound_compare, /* tp_compare */
199
( reprfunc ) Sound_repr, /* tp_repr */
200
0, /* tp_as_number */
201
0, /* tp_as_sequence */
202
0, /* tp_as_mapping */
207
BPy_Sound_methods, /* tp_methods */
211
183
/* NOTE: these were copied and modified from image.h. To Be Done TBD:
212
184
* macro-ize them, or C++ templates eventually?
437
static PyObject *Sound_setFilename( BPy_Sound * self, PyObject * args )
400
static int Sound_setFilename( BPy_Sound * self, PyObject * value )
442
/* max len is FILE_MAXDIR = 160 chars like done in DNA_image_types.h */
444
if( !PyArg_ParseTuple( args, "s#", &name, &namelen ) )
445
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
446
"expected a string argument" ) );
448
if( namelen >= FILE_MAXDIR )
449
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
404
/* max len is FILE_MAXDIR = 160 chars like in DNA_image_types.h */
405
name = PyString_AsString(value);
406
if (!name || strlen(name) > FILE_MAXDIR)
407
return ( EXPP_ReturnIntError( PyExc_ValueError,
450
408
"string argument is limited to 160 chars at most" ) );
452
PyOS_snprintf( self->sound->name, FILE_MAXDIR * sizeof( char ), "%s",
410
strcpy( self->sound->name, name );
414
static PyObject *Sound_oldsetFilename( BPy_Sound * self, PyObject * args )
416
return EXPP_setterWrapper( (void *)self, args, (setter)Sound_setFilename );
540
/*****************************************************************************/
541
/* Function: Sound_getAttr */
542
/* Description: This is a callback function for the BPy_Sound type. It is */
543
/* the function that accesses BPy_Sound member variables and */
545
/*****************************************************************************/
546
static PyObject *Sound_getAttr( BPy_Sound * self, char *name )
548
PyObject *attr = Py_None;
550
if( strcmp( name, "name" ) == 0 )
551
attr = PyString_FromString( self->sound->id.name + 2 );
552
else if( strcmp( name, "filename" ) == 0 )
553
attr = PyString_FromString( self->sound->name );
554
else if( strcmp( name, "packed" ) == 0 ) {
555
if (!sound_sample_is_null(self->sound))
557
bSample *sample = sound_find_sample(self->sound);
558
if (sample->packedfile)
559
attr = EXPP_incr_ret_True();
561
attr = EXPP_incr_ret_False();
564
attr = EXPP_incr_ret_False();
565
} else if( strcmp( name, "__members__" ) == 0 )
566
attr = Py_BuildValue( "[s,s]", "name", "filename" );
569
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
570
"couldn't create PyObject" ) );
572
if( attr != Py_None )
573
return attr; /* attribute found, return its value */
575
/* not an attribute, search the methods table */
576
return Py_FindMethod( BPy_Sound_methods, ( PyObject * ) self, name );
579
/*****************************************************************************/
580
/* Function: Sound_setAttr */
581
/* Description: This is a callback function for the BPy_Sound type. It is the*/
582
/* function that changes Sound object members values. If this */
583
/* data is linked to a Blender Sound, it also gets updated. */
584
/*****************************************************************************/
585
static int Sound_setAttr( BPy_Sound * self, char *name, PyObject * value )
587
PyObject *valtuple, *result=NULL;
589
/* Put the value(s) in a tuple. For some variables, we want to */
590
/* pass the values to a function, and these functions only accept */
592
valtuple = Py_BuildValue( "(O)", value );
594
return EXPP_ReturnIntError( PyExc_MemoryError,
595
"Sound_setAttr: couldn't create PyTuple" );
597
if( StringEqual( name, "name" ) )
598
result = Sound_setName( self, valtuple );
599
else if( StringEqual( name, "filename" ) ) {
600
result = Sound_setFilename( self , valtuple );
601
} else { /* if it turns out here, it's not an attribute*/
603
return EXPP_ReturnIntError( PyExc_KeyError, "attribute not found" );
606
/* valtuple won't be returned to the caller, so we need to DECREF it */
609
if( result != Py_None )
610
return -1; /* error return */
612
/* Py_None was incref'ed by the called Scene_set* function. We probably
613
* don't need to decref Py_None (!), but since Python/C API manual tells us
614
* to treat it like any other PyObject regarding ref counting ... */
615
Py_DECREF( Py_None );
616
return 0; /* normal return */
620
503
/*****************************************************************************/
641
524
self->sound->id.name + 2 );
527
/*****************************************************************************/
528
/* Python attributes get/set structure: */
529
/*****************************************************************************/
530
static PyGetSetDef BPy_Sound_getseters[] = {
531
GENERIC_LIB_GETSETATTR,
532
{"filename", (getter)Sound_getFilename, (setter)Sound_setFilename,
533
"text filename", NULL},
534
{"packed", (getter)Sound_getPacked, (setter)NULL,
535
"text filename", NULL},
536
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
541
/*****************************************************************************/
542
/* Python Sound_Type structure definition: */
543
/*****************************************************************************/
544
PyTypeObject Sound_Type = {
545
PyObject_HEAD_INIT( NULL )
547
"Blender Sound", /* tp_name */
548
sizeof( BPy_Sound ), /* tp_basicsize */
551
NULL, /* tp_dealloc */
553
NULL, /* tp_getattr */
554
NULL, /* tp_setattr */
555
( cmpfunc ) Sound_compare, /* tp_compare */
556
( reprfunc ) Sound_repr, /* tp_repr */
558
/* Method suites for standard classes */
560
NULL, /* PyNumberMethods *tp_as_number; */
561
NULL, /* PySequenceMethods *tp_as_sequence; */
562
NULL, /* PyMappingMethods *tp_as_mapping; */
564
/* More standard operations (here for binary compatibility) */
566
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
567
NULL, /* ternaryfunc tp_call; */
568
NULL, /* reprfunc tp_str; */
569
NULL, /* getattrofunc tp_getattro; */
570
NULL, /* setattrofunc tp_setattro; */
572
/* Functions to access object as input/output buffer */
573
NULL, /* PyBufferProcs *tp_as_buffer; */
575
/*** Flags to define presence of optional/expanded features ***/
576
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
578
NULL, /* char *tp_doc; Documentation string */
579
/*** Assigned meaning in release 2.0 ***/
580
/* call function for all accessible objects */
581
NULL, /* traverseproc tp_traverse; */
583
/* delete references to contained objects */
584
NULL, /* inquiry tp_clear; */
586
/*** Assigned meaning in release 2.1 ***/
587
/*** rich comparisons ***/
588
NULL, /* richcmpfunc tp_richcompare; */
590
/*** weak reference enabler ***/
591
0, /* long tp_weaklistoffset; */
593
/*** Added in release 2.2 ***/
595
NULL, /* getiterfunc tp_iter; */
596
NULL, /* iternextfunc tp_iternext; */
598
/*** Attribute descriptor and subclassing stuff ***/
599
BPy_Sound_methods, /* struct PyMethodDef *tp_methods; */
600
NULL, /* struct PyMemberDef *tp_members; */
601
BPy_Sound_getseters, /* struct PyGetSetDef *tp_getset; */
602
NULL, /* struct _typeobject *tp_base; */
603
NULL, /* PyObject *tp_dict; */
604
NULL, /* descrgetfunc tp_descr_get; */
605
NULL, /* descrsetfunc tp_descr_set; */
606
0, /* long tp_dictoffset; */
607
NULL, /* initproc tp_init; */
608
NULL, /* allocfunc tp_alloc; */
609
NULL, /* newfunc tp_new; */
610
/* Low-level free-memory routine */
611
NULL, /* freefunc tp_free; */
612
/* For PyObject_IS_GC */
613
NULL, /* inquiry tp_is_gc; */
614
NULL, /* PyObject *tp_bases; */
615
/* method resolution order */
616
NULL, /* PyObject *tp_mro; */
617
NULL, /* PyObject *tp_cache; */
618
NULL, /* PyObject *tp_subclasses; */
619
NULL, /* PyObject *tp_weaklist; */