Blender  V3.3
AUD_PyInit.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2009-2011 Jörg Hermann Müller. */
3 
8 #include "AUD_PyInit.h"
9 
10 #include <AUD_Sound.h>
11 #include <python/PyAPI.h>
12 #include <python/PySound.h>
13 
14 extern "C" {
15 extern void *BKE_sound_get_factory(void *sound);
16 }
17 
18 static PyObject *AUD_getSoundFromPointer(PyObject *self, PyObject *args)
19 {
20  PyObject *lptr = NULL;
21 
22  if (PyArg_Parse(args, "O:_sound_from_pointer", &lptr)) {
23  if (lptr) {
24  AUD_Sound *sound = BKE_sound_get_factory(PyLong_AsVoidPtr(lptr));
25 
26  if (sound) {
27  Sound *obj = (Sound *)Sound_empty();
28  if (obj) {
29  obj->sound = AUD_Sound_copy(sound);
30  return (PyObject *)obj;
31  }
32  }
33  }
34  }
35 
36  Py_RETURN_NONE;
37 }
38 
39 static PyMethodDef meth_sound_from_pointer[] = {
40  {"_sound_from_pointer",
41  (PyCFunction)AUD_getSoundFromPointer,
42  METH_O,
43  "_sound_from_pointer(pointer)\n\n"
44  "Returns the corresponding :class:`Factory` object.\n\n"
45  ":arg pointer: The pointer to the bSound object as long.\n"
46  ":type pointer: long\n"
47  ":return: The corresponding :class:`Factory` object.\n"
48  ":rtype: :class:`Factory`"}};
49 
50 PyObject *AUD_initPython(void)
51 {
52  PyObject *module = PyInit_aud();
53  if (module == NULL) {
54  printf("Unable to initialise audio\n");
55  return NULL;
56  }
57 
58  PyModule_AddObject(
59  module, "_sound_from_pointer", (PyObject *)PyCFunction_New(meth_sound_from_pointer, NULL));
60  PyDict_SetItemString(PyImport_GetModuleDict(), "aud", module);
61 
62  return module;
63 }
static PyObject * AUD_getSoundFromPointer(PyObject *self, PyObject *args)
Definition: AUD_PyInit.cpp:18
static PyMethodDef meth_sound_from_pointer[]
Definition: AUD_PyInit.cpp:39
void * BKE_sound_get_factory(void *sound)
PyObject * AUD_initPython(void)
Definition: AUD_PyInit.cpp:50
static struct PyModuleDef module
Definition: python.cpp:972