[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37226] branches/soc-2011-pepper: 3D Audio GSoC:

Joerg Mueller nexyon at gmail.com
Mon Jun 6 00:06:31 CEST 2011


Revision: 37226
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37226
Author:   nexyon
Date:     2011-06-05 22:06:29 +0000 (Sun, 05 Jun 2011)
Log Message:
-----------
3D Audio GSoC:
Making it possible to access blenders internal sounds via Python.

Modified Paths:
--------------
    branches/soc-2011-pepper/intern/audaspace/Python/AUD_PyAPI.cpp
    branches/soc-2011-pepper/intern/audaspace/Python/AUD_PyAPI.h
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp
    branches/soc-2011-pepper/release/scripts/modules/bpy_types.py
    branches/soc-2011-pepper/source/blender/blenkernel/BKE_sound.h
    branches/soc-2011-pepper/source/blender/blenkernel/intern/sound.c

Modified: branches/soc-2011-pepper/intern/audaspace/Python/AUD_PyAPI.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/Python/AUD_PyAPI.cpp	2011-06-05 20:54:04 UTC (rev 37225)
+++ branches/soc-2011-pepper/intern/audaspace/Python/AUD_PyAPI.cpp	2011-06-05 22:06:29 UTC (rev 37226)
@@ -2875,6 +2875,12 @@
 	return DeviceType.tp_alloc(&DeviceType, 0);
 }
 
+PyObject *
+Factory_empty()
+{
+	return FactoryType.tp_alloc(&FactoryType, 0);
+}
+
 // ====================================================================
 
 PyDoc_STRVAR(M_aud_doc,

Modified: branches/soc-2011-pepper/intern/audaspace/Python/AUD_PyAPI.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/Python/AUD_PyAPI.h	2011-06-05 20:54:04 UTC (rev 37225)
+++ branches/soc-2011-pepper/intern/audaspace/Python/AUD_PyAPI.h	2011-06-05 22:06:29 UTC (rev 37226)
@@ -66,8 +66,8 @@
 PyMODINIT_FUNC
 PyInit_aud(void);
 
-extern PyObject *
-Device_empty();
+extern PyObject* Device_empty();
+extern PyObject* Factory_empty();
 
 #ifdef __cplusplus
 }

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp	2011-06-05 20:54:04 UTC (rev 37225)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp	2011-06-05 22:06:29 UTC (rev 37226)
@@ -181,10 +181,48 @@
 										  ":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;

Modified: branches/soc-2011-pepper/release/scripts/modules/bpy_types.py
===================================================================
--- branches/soc-2011-pepper/release/scripts/modules/bpy_types.py	2011-06-05 20:54:04 UTC (rev 37225)
+++ branches/soc-2011-pepper/release/scripts/modules/bpy_types.py	2011-06-05 22:06:29 UTC (rev 37226)
@@ -409,6 +409,16 @@
 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)

Modified: branches/soc-2011-pepper/source/blender/blenkernel/BKE_sound.h
===================================================================
--- branches/soc-2011-pepper/source/blender/blenkernel/BKE_sound.h	2011-06-05 20:54:04 UTC (rev 37225)
+++ branches/soc-2011-pepper/source/blender/blenkernel/BKE_sound.h	2011-06-05 22:06:29 UTC (rev 37226)
@@ -104,4 +104,6 @@
 
 int sound_get_channels(struct bSound* sound);
 
+void* sound_get_factory(void* sound);
+
 #endif

Modified: branches/soc-2011-pepper/source/blender/blenkernel/intern/sound.c
===================================================================
--- branches/soc-2011-pepper/source/blender/blenkernel/intern/sound.c	2011-06-05 20:54:04 UTC (rev 37225)
+++ branches/soc-2011-pepper/source/blender/blenkernel/intern/sound.c	2011-06-05 22:06:29 UTC (rev 37226)
@@ -502,3 +502,8 @@
 
 	return info.specs.channels;
 }
+
+void* sound_get_factory(void* sound)
+{
+	return ((struct bSound*) sound)->playback_handle;
+}




More information about the Bf-blender-cvs mailing list