From ef5f78ecc7a6a7aac04207d3733087db8d03f5a6 Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Sun, 5 Jun 2011 22:06:29 +0000 Subject: 3D Audio GSoC: Making it possible to access blenders internal sounds via Python. --- intern/audaspace/Python/AUD_PyAPI.cpp | 6 ++++++ intern/audaspace/Python/AUD_PyAPI.h | 4 ++-- intern/audaspace/intern/AUD_C-API.cpp | 40 ++++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 3 deletions(-) (limited to 'intern') 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* factory = (AUD_Reference*) sound_get_factory((void*) lptr); + + if(factory) + { + Factory* obj = (Factory*) Factory_empty(); + if(obj) + { + obj->factory = new AUD_Reference(*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; -- cgit v1.2.3