diff options
-rw-r--r-- | intern/audaspace/Python/AUD_PyAPI.cpp | 6 | ||||
-rw-r--r-- | intern/audaspace/Python/AUD_PyAPI.h | 4 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_C-API.cpp | 40 | ||||
-rw-r--r-- | release/scripts/modules/bpy_types.py | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_sound.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/sound.c | 5 |
6 files changed, 64 insertions, 3 deletions
diff --git a/intern/audaspace/Python/AUD_PyAPI.cpp b/intern/audaspace/Python/AUD_PyAPI.cpp index 53dfedee5eb..ac25ab34a69 100644 --- a/intern/audaspace/Python/AUD_PyAPI.cpp +++ b/intern/audaspace/Python/AUD_PyAPI.cpp @@ -2875,6 +2875,12 @@ Device_empty() return DeviceType.tp_alloc(&DeviceType, 0); } +PyObject * +Factory_empty() +{ + return FactoryType.tp_alloc(&FactoryType, 0); +} + // ==================================================================== PyDoc_STRVAR(M_aud_doc, diff --git a/intern/audaspace/Python/AUD_PyAPI.h b/intern/audaspace/Python/AUD_PyAPI.h index d1a70ce892d..97e1e63b6eb 100644 --- a/intern/audaspace/Python/AUD_PyAPI.h +++ b/intern/audaspace/Python/AUD_PyAPI.h @@ -66,8 +66,8 @@ typedef struct { PyMODINIT_FUNC PyInit_aud(void); -extern PyObject * -Device_empty(); +extern PyObject* Device_empty(); +extern PyObject* Factory_empty(); #ifdef __cplusplus } diff --git a/intern/audaspace/intern/AUD_C-API.cpp b/intern/audaspace/intern/AUD_C-API.cpp index 3d78a5945df..08fb55f7605 100644 --- a/intern/audaspace/intern/AUD_C-API.cpp +++ b/intern/audaspace/intern/AUD_C-API.cpp @@ -181,10 +181,48 @@ static PyMethodDef meth_getcdevice[] = {{ "device", (PyCFunction)AUD_getCDevice, ":return: The application's :class:`Device`.\n" ":rtype: :class:`Device`"}}; +extern "C" { +extern void* sound_get_factory(void* sound); +} + +static PyObject* AUD_getSoundFromPointer(PyObject* self, PyObject* args) +{ + long int lptr; + + if(PyArg_Parse(args, "l:_sound_from_pointer", &lptr)) + { + if(lptr) + { + AUD_Reference<AUD_IFactory>* factory = (AUD_Reference<AUD_IFactory>*) sound_get_factory((void*) lptr); + + if(factory) + { + Factory* obj = (Factory*) Factory_empty(); + if(obj) + { + obj->factory = new AUD_Reference<AUD_IFactory>(*factory); + return (PyObject*) obj; + } + } + } + } + + Py_RETURN_NONE; +} + +static PyMethodDef meth_sound_from_pointer[] = {{ "_sound_from_pointer", (PyCFunction)AUD_getSoundFromPointer, METH_O, + "_sound_from_pointer(pointer)\n\n" + "Returns the corresponding :class:`Factory` object.\n\n" + ":arg pointer: The pointer to the bSound object as long.\n" + ":type pointer: long\n" + ":return: The corresponding :class:`Factory` object.\n" + ":rtype: :class:`Factory`"}}; + PyObject* AUD_initPython() { PyObject* module = PyInit_aud(); - PyModule_AddObject(module, "device", (PyObject *)PyCFunction_New(meth_getcdevice, NULL)); + PyModule_AddObject(module, "device", (PyObject*)PyCFunction_New(meth_getcdevice, NULL)); + PyModule_AddObject(module, "_sound_from_pointer", (PyObject*)PyCFunction_New(meth_sound_from_pointer, NULL)); PyDict_SetItemString(PyImport_GetModuleDict(), "aud", module); return module; diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index 3c1b454e72e..c30c893c9cc 100644 --- a/release/scripts/modules/bpy_types.py +++ b/release/scripts/modules/bpy_types.py @@ -409,6 +409,16 @@ class Text(bpy_types.ID): TypeMap = {} +class Sound(bpy_types.ID): + __slots__ = () + + @property + def factory(self): + """The aud.Factory object of the sound.""" + import aud + return aud._sound_from_pointer(self.as_pointer()) + + class RNAMeta(type): def __new__(cls, name, bases, classdict, **args): result = type.__new__(cls, name, bases, classdict) diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h index 04597fd666e..7402d501120 100644 --- a/source/blender/blenkernel/BKE_sound.h +++ b/source/blender/blenkernel/BKE_sound.h @@ -104,4 +104,6 @@ int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length, flo int sound_get_channels(struct bSound* sound); +void* sound_get_factory(void* sound); + #endif diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index e0e456a371e..f42492ef713 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -502,3 +502,8 @@ int sound_get_channels(struct bSound* sound) return info.specs.channels; } + +void* sound_get_factory(void* sound) +{ + return ((struct bSound*) sound)->playback_handle; +} |