Blender  V2.93
AUD_PyInit.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2009-2011 Jörg Hermann Müller
3  *
4  * This file is part of AudaSpace.
5  *
6  * Audaspace is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AudaSpace is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Audaspace; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
25 #include "AUD_PyInit.h"
26 
27 #include <AUD_Sound.h>
28 #include <python/PyAPI.h>
29 #include <python/PySound.h>
30 
31 extern "C" {
32 extern void *BKE_sound_get_factory(void *sound);
33 }
34 
35 static PyObject *AUD_getSoundFromPointer(PyObject *self, PyObject *args)
36 {
37  PyObject *lptr = NULL;
38 
39  if (PyArg_Parse(args, "O:_sound_from_pointer", &lptr)) {
40  if (lptr) {
41  AUD_Sound *sound = BKE_sound_get_factory(PyLong_AsVoidPtr(lptr));
42 
43  if (sound) {
44  Sound *obj = (Sound *)Sound_empty();
45  if (obj) {
46  obj->sound = AUD_Sound_copy(sound);
47  return (PyObject *)obj;
48  }
49  }
50  }
51  }
52 
53  Py_RETURN_NONE;
54 }
55 
56 static PyMethodDef meth_sound_from_pointer[] = {
57  {"_sound_from_pointer",
58  (PyCFunction)AUD_getSoundFromPointer,
59  METH_O,
60  "_sound_from_pointer(pointer)\n\n"
61  "Returns the corresponding :class:`Factory` object.\n\n"
62  ":arg pointer: The pointer to the bSound object as long.\n"
63  ":type pointer: long\n"
64  ":return: The corresponding :class:`Factory` object.\n"
65  ":rtype: :class:`Factory`"}};
66 
67 PyObject *AUD_initPython(void)
68 {
69  PyObject *module = PyInit_aud();
70  if (module == NULL) {
71  printf("Unable to initialise audio\n");
72  return NULL;
73  }
74 
75  PyModule_AddObject(
76  module, "_sound_from_pointer", (PyObject *)PyCFunction_New(meth_sound_from_pointer, NULL));
77  PyDict_SetItemString(PyImport_GetModuleDict(), "aud", module);
78 
79  return module;
80 }
static PyObject * AUD_getSoundFromPointer(PyObject *self, PyObject *args)
Definition: AUD_PyInit.cpp:35
static PyMethodDef meth_sound_from_pointer[]
Definition: AUD_PyInit.cpp:56
void * BKE_sound_get_factory(void *sound)
PyObject * AUD_initPython(void)
Definition: AUD_PyInit.cpp:67
static struct PyModuleDef module