Python synthesizer stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2KB

  1. #include <python2.7/Python.h>
  2. #include <numpy/arrayobject.h>
  3. PyDoc_STRVAR(hello_doc, "Print hello message from Python module");
  4. /* Output hello message */
  5. static PyObject *pymod_hello(PyObject *self, PyObject *args)
  6. {
  7. PyObject *r = NULL;
  8. npy_int dims[2] = {940, 2};
  9. if (PyArg_ParseTuple(args, "")) {
  10. printf("Hello from Python module\n");
  11. r = PyArray_New(&PyArray_Type, 2, dims, NPY_INT16, NULL, NULL, 2, 0, NULL);
  12. }
  13. return r;
  14. }
  15. /* Exported methods */
  16. static PyMethodDef pymod_methods[] = {
  17. {"hello", (PyCFunction)pymod_hello,
  18. METH_VARARGS, hello_doc},
  19. {NULL, NULL} /* sentinel */
  20. };
  21. PyDoc_STRVAR(module_doc, "Simple test module");
  22. /* Module initialisation, called by Python on import */
  23. PyMODINIT_FUNC
  24. initpymod2(void)
  25. {
  26. PyObject *m;
  27. puts("Hoi, module pymod2 loaded.");
  28. m = Py_InitModule3("pymod2", pymod_methods, module_doc);
  29. if (m == NULL)
  30. return;
  31. /* Our module requires the GIL to be available */
  32. if (!PyEval_ThreadsInitialized()) {
  33. puts("Initialising multithreading for Python");
  34. PyEval_InitThreads();
  35. }
  36. /* Initialise NumPy */
  37. import_array();
  38. return;
  39. }