~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Sound.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
2
 
 * $Id: Sound.c,v 1.12 2006/12/27 05:04:19 campbellbarton Exp $
 
2
 * $Id: Sound.c,v 1.18 2007/03/26 02:10:22 campbellbarton Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
41
41
#include "BKE_packedFile.h"
42
42
#include "mydevice.h"           /* redraw defines */
43
43
#include "gen_utils.h"
 
44
#include "gen_library.h"
44
45
#include "DNA_space_types.h" /* for FILE_MAXDIR only */
45
46
 
46
47
/*****************************************************************************/
88
89
/*****************************************************************************/
89
90
/* Python Sound_Type callback function prototypes:                      */
90
91
/*****************************************************************************/
91
 
static void Sound_dealloc( BPy_Sound * self );
92
 
static int Sound_setAttr( BPy_Sound * self, char *name, PyObject * v );
93
92
static int Sound_compare( BPy_Sound * a, BPy_Sound * b );
94
 
static PyObject *Sound_getAttr( BPy_Sound * self, char *name );
95
93
static PyObject *Sound_repr( BPy_Sound * self );
96
94
 
97
95
#define SOUND_FLOAT_METHODS(funcname, varname)                  \
126
124
static PyObject *Sound_getName( BPy_Sound * self );
127
125
static PyObject *Sound_getFilename( BPy_Sound * self );
128
126
static PyObject *Sound_setName( BPy_Sound * self, PyObject * args );
129
 
static PyObject *Sound_setFilename( BPy_Sound * self, PyObject * args );
 
127
static int               Sound_setFilename( BPy_Sound * self, PyObject * args );
 
128
static PyObject *Sound_oldsetFilename( BPy_Sound * self, PyObject * args );
130
129
static PyObject *Sound_setCurrent( BPy_Sound * self );
131
130
static PyObject *Sound_play( BPy_Sound * self );
132
131
static PyObject *Sound_unpack( BPy_Sound * self, PyObject * args);
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}
182
181
};
183
182
 
184
 
/*****************************************************************************/
185
 
/* Python Sound_Type structure definition:                              */
186
 
/*****************************************************************************/
187
 
PyTypeObject Sound_Type = {
188
 
        PyObject_HEAD_INIT( NULL )
189
 
        0,              /* ob_size */
190
 
        "Blender Sound",        /* tp_name */
191
 
        sizeof( BPy_Sound ),    /* tp_basicsize */
192
 
        0,                      /* tp_itemsize */
193
 
        /* methods */
194
 
        ( destructor ) Sound_dealloc,   /* tp_dealloc */
195
 
        0,                      /* tp_print */
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 */
203
 
        0,                      /* tp_as_hash */
204
 
        0, 0, 0, 0, 0, 0,
205
 
        0,                      /* tp_doc */
206
 
        0, 0, 0, 0, 0, 0,
207
 
        BPy_Sound_methods,      /* tp_methods */
208
 
        0,                      /* tp_members */
209
 
};
210
 
 
211
183
/* NOTE: these were copied and modified from image.h.  To Be Done TBD:
212
184
 * macro-ize them, or C++ templates eventually?
213
185
 */
332
304
{
333
305
        PyObject *submodule;
334
306
 
335
 
        Sound_Type.ob_type = &PyType_Type;
 
307
        if( PyType_Ready( &Sound_Type ) < 0 )
 
308
                return NULL;
336
309
 
337
310
        submodule =
338
311
                Py_InitModule3( "Blender.Sound", M_Sound_methods,
345
318
/*** The Sound PyType ***/
346
319
/************************/
347
320
 
348
 
/*****************************************************************************/
349
 
/* Function:            Sound_dealloc                            */
350
 
/* Description: This is a callback function for the BPy_Sound type. It is  */
351
 
/*              the destructor function.                                */
352
 
/*****************************************************************************/
353
 
static void Sound_dealloc( BPy_Sound * self )
354
 
{
355
 
        PyObject_DEL( self );
356
 
}
357
321
 
358
322
/*****************************************************************************/
359
323
/* Function:    Sound_CreatePyObject                                    */
376
340
}
377
341
 
378
342
/*****************************************************************************/
379
 
/* Function:    Sound_CheckPyObject                                     */
380
 
/* Description: This function returns true when the given PyObject is of the */
381
 
/*                      type Sound. Otherwise it will return false.     */
382
 
/*****************************************************************************/
383
 
int Sound_CheckPyObject( PyObject * pyobj )
384
 
{
385
 
        return ( pyobj->ob_type == &Sound_Type );
386
 
}
387
 
 
388
 
/*****************************************************************************/
389
343
/* Function:    Sound_FromPyObject                              */
390
344
/* Description: Returns the Blender Sound associated with this object    */
391
345
/*****************************************************************************/
419
373
                                        "couldn't get Sound.filename attribute" ) );
420
374
}
421
375
 
 
376
static PyObject *Sound_getPacked( BPy_Sound * self )
 
377
{
 
378
        if (!sound_sample_is_null(self->sound)) {
 
379
                bSample *sample = sound_find_sample(self->sound);
 
380
                if (sample->packedfile)
 
381
                        Py_RETURN_TRUE;
 
382
        }
 
383
        Py_RETURN_FALSE;
 
384
}
422
385
 
423
386
static PyObject *Sound_setName( BPy_Sound * self, PyObject * args )
424
387
{
434
397
        Py_RETURN_NONE;
435
398
}
436
399
 
437
 
static PyObject *Sound_setFilename( BPy_Sound * self, PyObject * args )
 
400
static int Sound_setFilename( BPy_Sound * self, PyObject * value )
438
401
{
439
402
        char *name;
440
 
        int namelen = 0;
441
 
 
442
 
        /* max len is FILE_MAXDIR = 160 chars like done in DNA_image_types.h */
443
 
 
444
 
        if( !PyArg_ParseTuple( args, "s#", &name, &namelen ) )
445
 
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
446
 
                                                "expected a string argument" ) );
447
 
 
448
 
        if( namelen >= FILE_MAXDIR )
449
 
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
403
 
 
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" ) );
451
409
 
452
 
        PyOS_snprintf( self->sound->name, FILE_MAXDIR * sizeof( char ), "%s",
453
 
                       name );
 
410
        strcpy( self->sound->name, name );
 
411
        return 0;
 
412
}
454
413
 
455
 
        Py_RETURN_NONE;
 
414
static PyObject *Sound_oldsetFilename( BPy_Sound * self, PyObject * args )
 
415
{
 
416
        return EXPP_setterWrapper( (void *)self, args, (setter)Sound_setFilename );
456
417
}
457
418
 
458
419
 
537
498
}
538
499
*/
539
500
 
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  */
544
 
/*              methods.                                                 */
545
 
/*****************************************************************************/
546
 
static PyObject *Sound_getAttr( BPy_Sound * self, char *name )
547
 
{
548
 
        PyObject *attr = Py_None;
549
 
 
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))
556
 
                {
557
 
                        bSample *sample = sound_find_sample(self->sound);
558
 
                        if (sample->packedfile)
559
 
                                attr = EXPP_incr_ret_True();
560
 
                        else
561
 
                                attr = EXPP_incr_ret_False();
562
 
                }
563
 
                else
564
 
                        attr = EXPP_incr_ret_False();
565
 
        } else if( strcmp( name, "__members__" ) == 0 )
566
 
                attr = Py_BuildValue( "[s,s]", "name", "filename" );
567
 
        
568
 
        if( !attr )
569
 
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
570
 
                                                "couldn't create PyObject" ) );
571
 
 
572
 
        if( attr != Py_None )
573
 
                return attr;    /* attribute found, return its value */
574
 
 
575
 
        /* not an attribute, search the methods table */
576
 
        return Py_FindMethod( BPy_Sound_methods, ( PyObject * ) self, name );
577
 
}
578
 
 
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 )
586
 
{
587
 
        PyObject *valtuple, *result=NULL;
588
 
        
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 */
591
 
        /* PyTuples. */
592
 
        valtuple = Py_BuildValue( "(O)", value );
593
 
        if( !valtuple )
594
 
                return EXPP_ReturnIntError( PyExc_MemoryError,
595
 
                                "Sound_setAttr: couldn't create PyTuple" );
596
 
        
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*/
602
 
                Py_DECREF(valtuple);
603
 
                return EXPP_ReturnIntError( PyExc_KeyError, "attribute not found" );
604
 
        }
605
 
 
606
 
/* valtuple won't be returned to the caller, so we need to DECREF it */
607
 
        Py_DECREF(valtuple);
608
 
 
609
 
        if( result != Py_None )
610
 
                return -1;      /* error return */
611
 
 
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 */
617
 
}
618
501
 
619
502
 
620
503
/*****************************************************************************/
641
524
                                    self->sound->id.name + 2 );
642
525
}
643
526
 
 
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 */
 
537
};
 
538
 
 
539
 
 
540
 
 
541
/*****************************************************************************/
 
542
/* Python Sound_Type structure definition:                              */
 
543
/*****************************************************************************/
 
544
PyTypeObject Sound_Type = {
 
545
        PyObject_HEAD_INIT( NULL )
 
546
        0,              /* ob_size */
 
547
        "Blender Sound",        /* tp_name */
 
548
        sizeof( BPy_Sound ),    /* tp_basicsize */
 
549
        0,                      /* tp_itemsize */
 
550
        /* methods */
 
551
        NULL,   /* tp_dealloc */
 
552
        0,              /* tp_print */
 
553
        NULL,   /* tp_getattr */
 
554
        NULL,   /* tp_setattr */
 
555
        ( cmpfunc ) Sound_compare,      /* tp_compare */
 
556
        ( reprfunc ) Sound_repr,        /* tp_repr */
 
557
 
 
558
        /* Method suites for standard classes */
 
559
 
 
560
        NULL,                       /* PyNumberMethods *tp_as_number; */
 
561
        NULL,                       /* PySequenceMethods *tp_as_sequence; */
 
562
        NULL,                       /* PyMappingMethods *tp_as_mapping; */
 
563
 
 
564
        /* More standard operations (here for binary compatibility) */
 
565
 
 
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; */
 
571
 
 
572
        /* Functions to access object as input/output buffer */
 
573
        NULL,                       /* PyBufferProcs *tp_as_buffer; */
 
574
 
 
575
  /*** Flags to define presence of optional/expanded features ***/
 
576
        Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
 
577
 
 
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; */
 
582
 
 
583
        /* delete references to contained objects */
 
584
        NULL,                       /* inquiry tp_clear; */
 
585
 
 
586
  /***  Assigned meaning in release 2.1 ***/
 
587
  /*** rich comparisons ***/
 
588
        NULL,                       /* richcmpfunc tp_richcompare; */
 
589
 
 
590
  /***  weak reference enabler ***/
 
591
        0,                          /* long tp_weaklistoffset; */
 
592
 
 
593
  /*** Added in release 2.2 ***/
 
594
        /*   Iterators */
 
595
        NULL,                       /* getiterfunc tp_iter; */
 
596
        NULL,                       /* iternextfunc tp_iternext; */
 
597
 
 
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; */
 
620
        NULL
 
621
};
 
622
 
644
623