mixer.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. pygame - Python Game Library
  3. Copyright (C) 2000-2001 Pete Shinners
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this library; if not, write to the Free
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. Pete Shinners
  16. pete@shinners.org
  17. */
  18. #include <Python.h>
  19. #include <SDL_mixer.h>
  20. #include <structmember.h>
  21. /* test mixer initializations */
  22. #define MIXER_INIT_CHECK() \
  23. if(!SDL_WasInit(SDL_INIT_AUDIO)) \
  24. return RAISE(PyExc_SDLError, "mixer system not initialized")
  25. #define PYGAMEAPI_MIXER_NUMSLOTS 7
  26. typedef struct {
  27. PyObject_HEAD
  28. Mix_Chunk* chunk;
  29. PyObject *weakreflist;
  30. } PySoundObject;
  31. typedef struct {
  32. PyObject_HEAD
  33. int chan;
  34. } PyChannelObject;
  35. #define PySound_AsChunk(x) (((PySoundObject*)x)->chunk)
  36. #define PyChannel_AsInt(x) (((PyChannelObject*)x)->chan)
  37. #ifndef PYGAMEAPI_MIXER_INTERNAL
  38. #define PySound_Check(x) ((x)->ob_type == (PyTypeObject*)PyMIXER_C_API[0])
  39. #define PySound_Type (*(PyTypeObject*)PyMIXER_C_API[0])
  40. #define PySound_New (*(PyObject*(*)(Mix_Chunk*))PyMIXER_C_API[1])
  41. #define PySound_Play (*(PyObject*(*)(PyObject*, PyObject*))PyMIXER_C_API[2])
  42. #define PyChannel_Check(x) ((x)->ob_type == (PyTypeObject*)PyMIXER_C_API[3])
  43. #define PyChannel_Type (*(PyTypeObject*)PyMIXER_C_API[3])
  44. #define PyChannel_New (*(PyObject*(*)(int))PyMIXER_C_API[4])
  45. #define PyMixer_AutoInit (*(PyObject*(*)(PyObject*, PyObject*))PyMIXER_C_API[5])
  46. #define PyMixer_AutoQuit (*(void(*)(void))PyMIXER_C_API[6])
  47. #define import_pygame_mixer() { \
  48. PyObject *_module = PyImport_ImportModule(IMPPREFIX "mixer"); \
  49. if (_module != NULL) { \
  50. PyObject *_dict = PyModule_GetDict(_module); \
  51. PyObject *_c_api = PyDict_GetItemString(_dict, PYGAMEAPI_LOCAL_ENTRY); \
  52. if(PyCObject_Check(_c_api)) {\
  53. void** localptr = (void**)PyCObject_AsVoidPtr(_c_api); \
  54. memcpy(PyMIXER_C_API, localptr, sizeof(void*)*PYGAMEAPI_MIXER_NUMSLOTS); \
  55. } Py_DECREF(_module); } }
  56. #endif
  57. static void* PyMIXER_C_API[PYGAMEAPI_MIXER_NUMSLOTS] = {NULL};