3D Audio GSoC:

Making it possible to access blenders internal sounds via Python.
This commit is contained in:
Joerg Mueller
2011-06-05 22:06:29 +00:00
parent f2daf2ca6b
commit ef5f78ecc7
6 changed files with 64 additions and 3 deletions

View File

@@ -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,

View File

@@ -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
}

View File

@@ -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;

View File

@@ -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)

View File

@@ -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

View File

@@ -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;
}