home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / Python2 / Python20_source / Modules / almodule.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-25  |  79.0 KB  |  3,239 lines

  1.  
  2. #define OLD_INTERFACE        /* define for pre-Irix 6 interface */
  3.  
  4. #include "Python.h"
  5. #include "stringobject.h"
  6. #include <audio.h>
  7. #include <stdarg.h>
  8.  
  9. #ifndef AL_NO_ELEM
  10. #ifndef OLD_INTERFACE
  11. #define OLD_INTERFACE
  12. #endif /* OLD_INTERFACE */
  13. #endif /* AL_NO_ELEM */
  14.  
  15. static PyObject *ErrorObject;
  16.  
  17. /* ----------------------------------------------------- */
  18.  
  19. /* Declarations for objects of type port */
  20.  
  21. typedef struct {
  22.     PyObject_HEAD
  23.     /* XXXX Add your own stuff here */
  24.     ALport port;
  25. } alpobject;
  26.  
  27. staticforward PyTypeObject Alptype;
  28.  
  29.  
  30.  
  31. /* ---------------------------------------------------------------- */
  32.  
  33. /* Declarations for objects of type config */
  34.  
  35. typedef struct {
  36.     PyObject_HEAD
  37.     /* XXXX Add your own stuff here */
  38.     ALconfig config;
  39. } alcobject;
  40.  
  41. staticforward PyTypeObject Alctype;
  42.  
  43.  
  44. static void
  45. ErrorHandler(long code, const char *fmt, ...)
  46. {
  47.     va_list args;
  48.     char buf[128];
  49.  
  50.     va_start(args, fmt);
  51.     vsprintf(buf, fmt, args);
  52.     va_end(args);
  53.     PyErr_SetString(ErrorObject, buf);
  54. }
  55.  
  56. #ifdef AL_NO_ELEM        /* IRIX 6 */
  57.  
  58. static PyObject *
  59. param2python(int resource, int param, ALvalue value, ALparamInfo *pinfo)
  60. {
  61.     ALparamInfo info;
  62.     PyObject *v;
  63.  
  64.     if (pinfo == NULL) {
  65.         pinfo = &info;
  66.         if (alGetParamInfo(resource, param, &info) < 0)
  67.             return NULL;
  68.     }
  69.     switch (pinfo->elementType) {
  70.     case AL_PTR_ELEM:
  71.         /* XXXX don't know how to handle this */
  72.     case AL_NO_ELEM:
  73.         Py_INCREF(Py_None);
  74.         return Py_None;
  75.     case AL_INT32_ELEM:
  76.     case AL_RESOURCE_ELEM:
  77.     case AL_ENUM_ELEM:
  78.         return PyInt_FromLong((long) value.i);
  79.     case AL_INT64_ELEM:
  80.         return PyLong_FromLongLong(value.ll);
  81.     case AL_FIXED_ELEM:
  82.         return PyFloat_FromDouble(alFixedToDouble(value.ll));
  83.     case AL_CHAR_ELEM:
  84.         if (value.ptr == NULL) {
  85.             Py_INCREF(Py_None);
  86.             return Py_None;
  87.         }
  88.         return PyString_FromString((char *) value.ptr);
  89.     default:
  90.         PyErr_SetString(ErrorObject, "unknown element type");
  91.         return NULL;
  92.     }
  93. }
  94.  
  95. static int
  96. python2elem(PyObject *item, void *ptr, int elementType)
  97. {
  98.     switch (elementType) {
  99.     case AL_INT32_ELEM:
  100.     case AL_RESOURCE_ELEM:
  101.     case AL_ENUM_ELEM:
  102.         if (!PyInt_Check(item)) {
  103.             PyErr_BadArgument();
  104.             return -1;
  105.         }
  106.         *((int *) ptr) = PyInt_AsLong(item);
  107.         break;
  108.     case AL_INT64_ELEM:
  109.         if (PyInt_Check(item))
  110.             *((long long *) ptr) = PyInt_AsLong(item);
  111.         else if (PyLong_Check(item))
  112.             *((long long *) ptr) = PyLong_AsLongLong(item);
  113.         else {
  114.             PyErr_BadArgument();
  115.             return -1;
  116.         }
  117.         break;
  118.     case AL_FIXED_ELEM:
  119.         if (PyInt_Check(item))
  120.             *((long long *) ptr) = alDoubleToFixed((double) PyInt_AsLong(item));
  121.         else if (PyFloat_Check(item))
  122.             *((long long *) ptr) = alDoubleToFixed(PyFloat_AsDouble(item));
  123.         else {
  124.             PyErr_BadArgument();
  125.             return -1;
  126.         }
  127.         break;
  128.     default:
  129.         PyErr_SetString(ErrorObject, "unknown element type");
  130.         return -1;
  131.     }
  132.     return 0;
  133. }
  134.  
  135. static int
  136. python2param(int resource, ALpv *param, PyObject *value, ALparamInfo *pinfo)
  137. {
  138.     ALparamInfo info;
  139.     int i, stepsize;
  140.     PyObject *item;
  141.  
  142.     if (pinfo == NULL) {
  143.         pinfo = &info;
  144.         if (alGetParamInfo(resource, param->param, &info) < 0)
  145.             return -1;
  146.     }
  147.     switch (pinfo->valueType) {
  148.     case AL_STRING_VAL:
  149.         if (pinfo->elementType != AL_CHAR_ELEM) {
  150.             PyErr_SetString(ErrorObject, "unknown element type");
  151.             return -1;
  152.         }
  153.         if (!PyString_Check(value)) {
  154.             PyErr_BadArgument();
  155.             return -1;
  156.         }
  157.         param->value.ptr = PyString_AS_STRING(value);
  158.         param->sizeIn = PyString_GET_SIZE(value)+1; /*account for NUL*/
  159.         break;
  160.     case AL_SET_VAL:
  161.     case AL_VECTOR_VAL:
  162.         if (!PyList_Check(value) && !PyTuple_Check(value)) {
  163.             PyErr_BadArgument();
  164.             return -1;
  165.         }
  166.         switch (pinfo->elementType) {
  167.         case AL_INT32_ELEM:
  168.         case AL_RESOURCE_ELEM:
  169.         case AL_ENUM_ELEM:
  170.             param->sizeIn = PySequence_Size(value);
  171.             param->value.ptr = PyMem_NEW(int, param->sizeIn);
  172.             stepsize = sizeof(int);
  173.             break;
  174.         case AL_INT64_ELEM:
  175.         case AL_FIXED_ELEM:
  176.             param->sizeIn = PySequence_Size(value);
  177.             param->value.ptr = PyMem_NEW(long long, param->sizeIn);
  178.             stepsize = sizeof(long long);
  179.             break;
  180.         }
  181.         for (i = 0; i < param->sizeIn; i++) {
  182.             item = PySequence_GetItem(value, i);
  183.             if (python2elem(item, (void *) ((char *) param->value.ptr + i*stepsize), pinfo->elementType) < 0) {
  184.                 PyMem_DEL(param->value.ptr);
  185.                 return -1;
  186.             }
  187.         }
  188.         break;
  189.     case AL_SCALAR_VAL:
  190.         switch (pinfo->elementType) {
  191.         case AL_INT32_ELEM:
  192.         case AL_RESOURCE_ELEM:
  193.         case AL_ENUM_ELEM:
  194.             return python2elem(value, (void *) ¶m->value.i,
  195.                        pinfo->elementType);
  196.         case AL_INT64_ELEM:
  197.         case AL_FIXED_ELEM:
  198.             return python2elem(value, (void *) ¶m->value.ll,
  199.                        pinfo->elementType);
  200.         default:
  201.             PyErr_SetString(ErrorObject, "unknown element type");
  202.             return -1;
  203.         }
  204.     }
  205.     return 0;
  206. }
  207.  
  208. static int
  209. python2params(int resource1, int resource2, PyObject *list, ALpv **pvsp, ALparamInfo **pinfop)
  210. {
  211.     PyObject *item;
  212.     ALpv *pvs;
  213.     ALparamInfo *pinfo;
  214.     int npvs, i;
  215.  
  216.     npvs = PyList_Size(list);
  217.     pvs = PyMem_NEW(ALpv, npvs);
  218.     pinfo = PyMem_NEW(ALparamInfo, npvs);
  219.     for (i = 0; i < npvs; i++) {
  220.         item = PyList_GetItem(list, i);
  221.         if (!PyArg_ParseTuple(item, "iO", &pvs[i].param, &item))
  222.             goto error;
  223.         if (alGetParamInfo(resource1, pvs[i].param, &pinfo[i]) < 0 &&
  224.             alGetParamInfo(resource2, pvs[i].param, &pinfo[i]) < 0)
  225.             goto error;
  226.         if (python2param(resource1, &pvs[i], item, &pinfo[i]) < 0)
  227.             goto error;
  228.     }
  229.  
  230.     *pvsp = pvs;
  231.     *pinfop = pinfo;
  232.     return npvs;
  233.  
  234.   error:
  235.     /* XXXX we should clean up everything */
  236.     if (pvs)
  237.         PyMem_DEL(pvs);
  238.     if (pinfo)
  239.         PyMem_DEL(pinfo);
  240.     return -1;
  241. }
  242.  
  243. /* -------------------------------------------------------- */
  244.  
  245.  
  246. static PyObject *
  247. SetConfig(alcobject *self, PyObject *args, int (*func)(ALconfig, int))
  248. {
  249.     int par;
  250.  
  251.     if (!PyArg_ParseTuple(args, "i:SetConfig", &par))
  252.         return NULL;
  253.  
  254.     if ((*func)(self->config, par) == -1)
  255.         return NULL;
  256.  
  257.     Py_INCREF(Py_None);
  258.     return Py_None;
  259. }
  260.  
  261. static PyObject *
  262. GetConfig(alcobject *self, PyObject *args, int (*func)(ALconfig))
  263. {    
  264.     int par;
  265.  
  266.     if (!PyArg_ParseTuple(args, ":GetConfig"))
  267.         return NULL;
  268.     
  269.     if ((par = (*func)(self->config)) == -1)
  270.         return NULL;
  271.  
  272.     return PyInt_FromLong((long) par);
  273. }
  274.  
  275. static char alc_SetWidth__doc__[] = 
  276. "alSetWidth: set the wordsize for integer audio data."
  277. ;
  278.  
  279. static PyObject *
  280. alc_SetWidth(alcobject *self, PyObject *args)
  281. {
  282.     return SetConfig(self, args, alSetWidth);
  283. }
  284.  
  285.  
  286. static char alc_GetWidth__doc__[] = 
  287. "alGetWidth: get the wordsize for integer audio data."
  288. ;
  289.  
  290. static PyObject *
  291. alc_GetWidth(alcobject *self, PyObject *args)
  292. {
  293.     return GetConfig(self, args, alGetWidth);
  294. }
  295.  
  296.  
  297. static char alc_SetSampFmt__doc__[] = 
  298. "alSetSampFmt: set the sample format setting in an audio ALconfig structure."
  299. ;
  300.  
  301. static PyObject *
  302. alc_SetSampFmt(alcobject *self, PyObject *args)
  303. {
  304.     return SetConfig(self, args, alSetSampFmt);
  305. }
  306.  
  307.  
  308. static char alc_GetSampFmt__doc__[] = 
  309. "alGetSampFmt: get the sample format setting in an audio ALconfig structure."
  310. ;
  311.  
  312. static PyObject *
  313. alc_GetSampFmt(alcobject *self, PyObject *args)
  314. {
  315.     return GetConfig(self, args, alGetSampFmt);
  316. }
  317.  
  318.  
  319. static char alc_SetChannels__doc__[] = 
  320. "alSetChannels: set the channel settings in an audio ALconfig."
  321. ;
  322.  
  323. static PyObject *
  324. alc_SetChannels(alcobject *self, PyObject *args)
  325. {
  326.     return SetConfig(self, args, alSetChannels);
  327. }
  328.  
  329.  
  330. static char alc_GetChannels__doc__[] = 
  331. "alGetChannels: get the channel settings in an audio ALconfig."
  332. ;
  333.  
  334. static PyObject *
  335. alc_GetChannels(alcobject *self, PyObject *args)
  336. {
  337.     return GetConfig(self, args, alGetChannels);
  338. }
  339.  
  340.  
  341. static char alc_SetFloatMax__doc__[] = 
  342. "alSetFloatMax: set the maximum value of floating point sample data."
  343. ;
  344.  
  345. static PyObject *
  346. alc_SetFloatMax(alcobject *self, PyObject *args)
  347. {
  348.     double maximum_value;
  349.  
  350.     if (!PyArg_ParseTuple(args, "d:SetFloatMax", &maximum_value))
  351.         return NULL;
  352.     if (alSetFloatMax(self->config, maximum_value) < 0)
  353.         return NULL;
  354.     Py_INCREF(Py_None);
  355.     return Py_None;
  356. }
  357.  
  358.  
  359. static char alc_GetFloatMax__doc__[] = 
  360. "alGetFloatMax: get the maximum value of floating point sample data."
  361. ;
  362.  
  363. static PyObject *
  364. alc_GetFloatMax(alcobject *self, PyObject *args)
  365. {
  366.     double maximum_value;
  367.  
  368.     if (!PyArg_ParseTuple(args, ":GetFloatMax"))
  369.         return NULL;
  370.     if ((maximum_value = alGetFloatMax(self->config)) == 0)
  371.         return NULL;
  372.     return PyFloat_FromDouble(maximum_value);
  373. }
  374.  
  375.  
  376. static char alc_SetDevice__doc__[] = 
  377. "alSetDevice: set the device setting in an audio ALconfig structure."
  378. ;
  379.  
  380. static PyObject *
  381. alc_SetDevice(alcobject *self, PyObject *args)
  382. {
  383.     return SetConfig(self, args, alSetDevice);
  384. }
  385.  
  386.  
  387. static char alc_GetDevice__doc__[] = 
  388. "alGetDevice: get the device setting in an audio ALconfig structure."
  389. ;
  390.  
  391. static PyObject *
  392. alc_GetDevice(alcobject *self, PyObject *args)
  393. {
  394.     return GetConfig(self, args, alGetDevice);
  395. }
  396.  
  397.  
  398. static char alc_SetQueueSize__doc__[] = 
  399. "alSetQueueSize: set audio port buffer size."
  400. ;
  401.  
  402. static PyObject *
  403. alc_SetQueueSize(alcobject *self, PyObject *args)
  404. {
  405.     return SetConfig(self, args, alSetQueueSize);
  406. }
  407.  
  408.  
  409. static char alc_GetQueueSize__doc__[] = 
  410. "alGetQueueSize: get audio port buffer size."
  411. ;
  412.  
  413. static PyObject *
  414. alc_GetQueueSize(alcobject *self, PyObject *args)
  415. {
  416.     return GetConfig(self, args, alGetQueueSize);
  417. }
  418.  
  419. #endif /* AL_NO_ELEM */
  420.  
  421. static PyObject *
  422. setconfig(alcobject *self, PyObject *args, int (*func)(ALconfig, long))
  423. {
  424.     long par;
  425.  
  426.     if (!PyArg_ParseTuple(args, "l:SetConfig", &par))
  427.         return NULL;
  428.  
  429.     if ((*func)(self->config, par) == -1)
  430.         return NULL;
  431.  
  432.     Py_INCREF(Py_None);
  433.     return Py_None;
  434. }
  435.  
  436. static PyObject *
  437. getconfig(alcobject *self, PyObject *args, long (*func)(ALconfig))
  438. {    
  439.     long par;
  440.  
  441.     if (!PyArg_ParseTuple(args, ":GetConfig"))
  442.         return NULL;
  443.     
  444.     if ((par = (*func)(self->config)) == -1)
  445.         return NULL;
  446.  
  447.     return PyInt_FromLong((long) par);
  448. }
  449.  
  450. static PyObject *
  451. alc_setqueuesize (alcobject *self, PyObject *args)
  452. {
  453.     return setconfig(self, args, ALsetqueuesize);
  454. }
  455.  
  456. static PyObject *
  457. alc_getqueuesize (alcobject *self, PyObject *args)
  458. {
  459.     return getconfig(self, args, ALgetqueuesize);
  460. }
  461.  
  462. static PyObject *
  463. alc_setwidth (alcobject *self, PyObject *args)
  464. {
  465.     return setconfig(self, args, ALsetwidth);
  466. }
  467.  
  468. static PyObject *
  469. alc_getwidth (alcobject *self, PyObject *args)
  470. {
  471.     return getconfig(self, args, ALgetwidth);    
  472. }
  473.  
  474. static PyObject *
  475. alc_getchannels (alcobject *self, PyObject *args)
  476. {
  477.     return getconfig(self, args, ALgetchannels);    
  478. }
  479.  
  480. static PyObject *
  481. alc_setchannels (alcobject *self, PyObject *args)
  482. {
  483.     return setconfig(self, args, ALsetchannels);
  484. }
  485.  
  486. #ifdef AL_405
  487.  
  488. static PyObject *
  489. alc_getsampfmt (alcobject *self, PyObject *args)
  490. {
  491.     return getconfig(self, args, ALgetsampfmt);    
  492. }
  493.  
  494. static PyObject *
  495. alc_setsampfmt (alcobject *self, PyObject *args)
  496. {
  497.     return setconfig(self, args, ALsetsampfmt);
  498. }
  499.  
  500. static PyObject *
  501. alc_getfloatmax(alcobject *self, PyObject *args)
  502. {
  503.     double arg;
  504.  
  505.     if (!PyArg_ParseTuple(args, ":GetFloatMax"))
  506.         return 0;
  507.     if ((arg = ALgetfloatmax(self->config)) == 0)
  508.         return NULL;
  509.     return PyFloat_FromDouble(arg);
  510. }
  511.  
  512. static PyObject *
  513. alc_setfloatmax(alcobject *self, PyObject *args)
  514. {
  515.     double arg;
  516.  
  517.     if (!PyArg_ParseTuple(args, "d:SetFloatMax", &arg))
  518.         return 0;
  519.     if (ALsetfloatmax(self->config, arg) == -1)
  520.         return NULL;
  521.     Py_INCREF(Py_None);
  522.     return Py_None;
  523. }
  524. #endif /* AL_405 */
  525.     
  526. static struct PyMethodDef alc_methods[] = {
  527. #ifdef AL_NO_ELEM        /* IRIX 6 */
  528.     {"SetWidth",    (PyCFunction)alc_SetWidth,    METH_VARARGS,    alc_SetWidth__doc__},
  529.     {"GetWidth",    (PyCFunction)alc_GetWidth,    METH_VARARGS,    alc_GetWidth__doc__},
  530.     {"SetSampFmt",    (PyCFunction)alc_SetSampFmt,    METH_VARARGS,    alc_SetSampFmt__doc__},
  531.     {"GetSampFmt",    (PyCFunction)alc_GetSampFmt,    METH_VARARGS,    alc_GetSampFmt__doc__},
  532.     {"SetChannels",    (PyCFunction)alc_SetChannels,    METH_VARARGS,    alc_SetChannels__doc__},
  533.     {"GetChannels",    (PyCFunction)alc_GetChannels,    METH_VARARGS,    alc_GetChannels__doc__},
  534.     {"SetFloatMax",    (PyCFunction)alc_SetFloatMax,    METH_VARARGS,    alc_SetFloatMax__doc__},
  535.     {"GetFloatMax",    (PyCFunction)alc_GetFloatMax,    METH_VARARGS,    alc_GetFloatMax__doc__},
  536.     {"SetDevice",    (PyCFunction)alc_SetDevice,    METH_VARARGS,    alc_SetDevice__doc__},
  537.     {"GetDevice",    (PyCFunction)alc_GetDevice,    METH_VARARGS,    alc_GetDevice__doc__},
  538.     {"SetQueueSize",    (PyCFunction)alc_SetQueueSize,    METH_VARARGS,    alc_SetQueueSize__doc__},
  539.     {"GetQueueSize",    (PyCFunction)alc_GetQueueSize,    METH_VARARGS,    alc_GetQueueSize__doc__},
  540. #endif /* AL_NO_ELEM */
  541.     {"getqueuesize",    (PyCFunction)alc_getqueuesize,    METH_VARARGS},
  542.     {"setqueuesize",    (PyCFunction)alc_setqueuesize,    METH_VARARGS},
  543.     {"getwidth",        (PyCFunction)alc_getwidth,    METH_VARARGS},
  544.     {"setwidth",        (PyCFunction)alc_setwidth,    METH_VARARGS},
  545.     {"getchannels",        (PyCFunction)alc_getchannels,    METH_VARARGS},
  546.     {"setchannels",        (PyCFunction)alc_setchannels,    METH_VARARGS},
  547. #ifdef AL_405
  548.     {"getsampfmt",        (PyCFunction)alc_getsampfmt,    METH_VARARGS},
  549.     {"setsampfmt",        (PyCFunction)alc_setsampfmt,    METH_VARARGS},
  550.     {"getfloatmax",        (PyCFunction)alc_getfloatmax,    METH_VARARGS},
  551.     {"setfloatmax",        (PyCFunction)alc_setfloatmax,    METH_VARARGS},
  552. #endif /* AL_405 */
  553.  
  554.     {NULL,        NULL}        /* sentinel */
  555. };
  556.  
  557. /* ---------- */
  558.  
  559.  
  560. static PyObject *
  561. newalcobject(ALconfig config)
  562. {
  563.     alcobject *self;
  564.     
  565.     self = PyObject_New(alcobject, &Alctype);
  566.     if (self == NULL)
  567.         return NULL;
  568.     /* XXXX Add your own initializers here */
  569.     self->config = config;
  570.     return (PyObject *) self;
  571. }
  572.  
  573.  
  574. static void
  575. alc_dealloc(alcobject *self)
  576. {
  577.     /* XXXX Add your own cleanup code here */
  578. #ifdef AL_NO_ELEM        /* IRIX 6 */
  579.     (void) alFreeConfig(self->config);    /* ignore errors */
  580. #else
  581.     (void) ALfreeconfig(self->config);    /* ignore errors */
  582. #endif
  583.     PyObject_Del(self);
  584. }
  585.  
  586. static PyObject *
  587. alc_getattr(alcobject *self, char *name)
  588. {
  589.     /* XXXX Add your own getattr code here */
  590.     return Py_FindMethod(alc_methods, (PyObject *)self, name);
  591. }
  592.  
  593. static char Alctype__doc__[] = 
  594. ""
  595. ;
  596.  
  597. static PyTypeObject Alctype = {
  598.     PyObject_HEAD_INIT(&PyType_Type)
  599.     0,                /*ob_size*/
  600.     "config",            /*tp_name*/
  601.     sizeof(alcobject),        /*tp_basicsize*/
  602.     0,                /*tp_itemsize*/
  603.     /* methods */
  604.     (destructor)alc_dealloc,    /*tp_dealloc*/
  605.     (printfunc)0,        /*tp_print*/
  606.     (getattrfunc)alc_getattr,    /*tp_getattr*/
  607.     (setattrfunc)0,    /*tp_setattr*/
  608.     (cmpfunc)0,        /*tp_compare*/
  609.     (reprfunc)0,        /*tp_repr*/
  610.     0,            /*tp_as_number*/
  611.     0,        /*tp_as_sequence*/
  612.     0,        /*tp_as_mapping*/
  613.     (hashfunc)0,        /*tp_hash*/
  614.     (ternaryfunc)0,        /*tp_call*/
  615.     (reprfunc)0,        /*tp_str*/
  616.  
  617.     /* Space for future expansion */
  618.     0L,0L,0L,0L,
  619.     Alctype__doc__ /* Documentation string */
  620. };
  621.  
  622. /* End of code for config objects */
  623. /* ---------------------------------------------------------------- */
  624.  
  625. #ifdef AL_NO_ELEM        /* IRIX 6 */
  626.  
  627. static char alp_SetConfig__doc__[] = 
  628. "alSetConfig: set the ALconfig of an audio ALport."
  629. ;
  630.  
  631. static PyObject *
  632. alp_SetConfig(alpobject *self, PyObject *args)
  633. {
  634.     alcobject *config;
  635.     if (!PyArg_ParseTuple(args, "O!:SetConfig", &Alctype, &config))
  636.         return NULL;
  637.     if (alSetConfig(self->port, config->config) < 0)
  638.         return NULL;
  639.     Py_INCREF(Py_None);
  640.     return Py_None;
  641. }
  642.  
  643.  
  644. static char alp_GetConfig__doc__[] = 
  645. "alGetConfig: get the ALconfig of an audio ALport."
  646. ;
  647.  
  648. static PyObject *
  649. alp_GetConfig(alpobject *self, PyObject *args)
  650. {
  651.     ALconfig config;
  652.     if (!PyArg_ParseTuple(args, ":GetConfig"))
  653.         return NULL;
  654.     if ((config = alGetConfig(self->port)) == NULL)
  655.         return NULL;
  656.     return newalcobject(config);
  657. }
  658.  
  659.  
  660. static char alp_GetResource__doc__[] = 
  661. "alGetResource: get the resource associated with an audio port."
  662. ;
  663.  
  664. static PyObject *
  665. alp_GetResource(alpobject *self, PyObject *args)
  666. {
  667.     int resource;
  668.  
  669.     if (!PyArg_ParseTuple(args, ":GetResource"))
  670.         return NULL;
  671.     if ((resource = alGetResource(self->port)) == 0)
  672.         return NULL;
  673.     return PyInt_FromLong((long) resource);
  674. }
  675.  
  676.  
  677. static char alp_GetFD__doc__[] = 
  678. "alGetFD: get the file descriptor for an audio port."
  679. ;
  680.  
  681. static PyObject *
  682. alp_GetFD(alpobject *self, PyObject *args)
  683. {
  684.     int fd;
  685.  
  686.     if (!PyArg_ParseTuple(args, ":GetFD"))
  687.         return NULL;
  688.  
  689.     if ((fd = alGetFD(self->port)) < 0)
  690.         return NULL;
  691.  
  692.     return PyInt_FromLong((long) fd);
  693. }
  694.  
  695.  
  696. static char alp_GetFilled__doc__[] = 
  697. "alGetFilled: return the number of filled sample frames in an audio port."
  698. ;
  699.  
  700. static PyObject *
  701. alp_GetFilled(alpobject *self, PyObject *args)
  702. {
  703.     int filled;
  704.  
  705.     if (!PyArg_ParseTuple(args, ":GetFilled"))
  706.         return NULL;
  707.     if ((filled = alGetFilled(self->port)) < 0)
  708.         return NULL;
  709.     return PyInt_FromLong((long) filled);
  710. }
  711.  
  712.  
  713. static char alp_GetFillable__doc__[] = 
  714. "alGetFillable: report the number of unfilled sample frames in an audio port."
  715. ;
  716.  
  717. static PyObject *
  718. alp_GetFillable(alpobject *self, PyObject *args)
  719. {
  720.     int fillable;
  721.  
  722.     if (!PyArg_ParseTuple(args, ":GetFillable"))
  723.         return NULL;
  724.     if ((fillable = alGetFillable(self->port)) < 0)
  725.         return NULL;
  726.     return PyInt_FromLong((long) fillable);
  727. }
  728.  
  729.  
  730. static char alp_ReadFrames__doc__[] = 
  731. "alReadFrames: read sample frames from an audio port."
  732. ;
  733.  
  734. static PyObject *
  735. alp_ReadFrames(alpobject *self, PyObject *args)
  736. {
  737.     void *samples;
  738.     int framecount;
  739.     PyObject *v;
  740.     int size;
  741.     int ch;
  742.     ALconfig c;
  743.  
  744.     if (!PyArg_ParseTuple(args, "i:ReadFrames", &framecount))
  745.         return NULL;
  746.     if (framecount < 0) {
  747.         PyErr_SetString(ErrorObject, "negative framecount");
  748.         return NULL;
  749.     }
  750.     c = alGetConfig(self->port);
  751.     switch (alGetSampFmt(c)) {
  752.     case AL_SAMPFMT_TWOSCOMP:
  753.         switch (alGetWidth(c)) {
  754.         case AL_SAMPLE_8:
  755.             size = 1;
  756.             break;
  757.         case AL_SAMPLE_16:
  758.             size = 2;
  759.             break;
  760.         case AL_SAMPLE_24:
  761.             size = 4;
  762.             break;
  763.         default:
  764.             PyErr_SetString(ErrorObject, "can't determine width");
  765.             alFreeConfig(c);
  766.             return NULL;
  767.         }
  768.         break;
  769.     case AL_SAMPFMT_FLOAT:
  770.         size = 4;
  771.         break;
  772.     case AL_SAMPFMT_DOUBLE:
  773.         size = 8;
  774.         break;
  775.     default:
  776.         PyErr_SetString(ErrorObject, "can't determine format");
  777.         alFreeConfig(c);
  778.         return NULL;
  779.     }
  780.     ch = alGetChannels(c);
  781.     alFreeConfig(c);
  782.     if (ch < 0) {
  783.         PyErr_SetString(ErrorObject, "can't determine # of channels");
  784.         return NULL;
  785.     }
  786.     size *= ch;
  787.     v = PyString_FromStringAndSize((char *) NULL, size * framecount);
  788.     if (v == NULL)
  789.         return NULL;
  790.  
  791.     Py_BEGIN_ALLOW_THREADS
  792.     alReadFrames(self->port, (void *) PyString_AS_STRING(v), framecount);
  793.     Py_END_ALLOW_THREADS
  794.  
  795.     return v;
  796. }
  797.  
  798.  
  799. static char alp_DiscardFrames__doc__[] = 
  800. "alDiscardFrames: discard audio from an audio port."
  801. ;
  802.  
  803. static PyObject *
  804. alp_DiscardFrames(alpobject *self, PyObject *args)
  805. {
  806.     int framecount;
  807.  
  808.     if (!PyArg_ParseTuple(args, "i:DiscardFrames", &framecount))
  809.         return NULL;
  810.  
  811.     Py_BEGIN_ALLOW_THREADS
  812.     framecount = alDiscardFrames(self->port, framecount);
  813.     Py_END_ALLOW_THREADS
  814.  
  815.     if (framecount < 0)
  816.         return NULL;
  817.  
  818.     return PyInt_FromLong((long) framecount);
  819. }
  820.  
  821.  
  822. static char alp_ZeroFrames__doc__[] = 
  823. "alZeroFrames: write zero-valued sample frames to an audio port."
  824. ;
  825.  
  826. static PyObject *
  827. alp_ZeroFrames(alpobject *self, PyObject *args)
  828. {
  829.     int framecount;
  830.  
  831.     if (!PyArg_ParseTuple(args, "i:ZeroFrames", &framecount))
  832.         return NULL;
  833.  
  834.     if (framecount < 0) {
  835.         PyErr_SetString(ErrorObject, "negative framecount");
  836.         return NULL;
  837.     }
  838.  
  839.     Py_BEGIN_ALLOW_THREADS
  840.     alZeroFrames(self->port, framecount);
  841.     Py_END_ALLOW_THREADS
  842.  
  843.     Py_INCREF(Py_None);
  844.     return Py_None;
  845. }
  846.  
  847.  
  848. static char alp_SetFillPoint__doc__[] = 
  849. "alSetFillPoint: set low- or high-water mark for an audio port."
  850. ;
  851.  
  852. static PyObject *
  853. alp_SetFillPoint(alpobject *self, PyObject *args)
  854. {
  855.     int fillpoint;
  856.  
  857.     if (!PyArg_ParseTuple(args, "i:SetFillPoint", &fillpoint))
  858.         return NULL;
  859.  
  860.     if (alSetFillPoint(self->port, fillpoint) < 0)
  861.         return NULL;
  862.  
  863.     Py_INCREF(Py_None);
  864.     return Py_None;
  865. }
  866.  
  867.  
  868. static char alp_GetFillPoint__doc__[] = 
  869. "alGetFillPoint: get low- or high-water mark for an audio port."
  870. ;
  871.  
  872. static PyObject *
  873. alp_GetFillPoint(alpobject *self, PyObject *args)
  874. {
  875.     int fillpoint;
  876.  
  877.     if (!PyArg_ParseTuple(args, ":GetFillPoint"))
  878.         return NULL;
  879.  
  880.     if ((fillpoint = alGetFillPoint(self->port)) < 0)
  881.         return NULL;
  882.  
  883.     return PyInt_FromLong((long) fillpoint);
  884. }
  885.  
  886.  
  887. static char alp_GetFrameNumber__doc__[] = 
  888. "alGetFrameNumber: get the absolute sample frame number associated with a port."
  889. ;
  890.  
  891. static PyObject *
  892. alp_GetFrameNumber(alpobject *self, PyObject *args)
  893. {
  894.     stamp_t fnum;
  895.  
  896.     if (!PyArg_ParseTuple(args, ":GetFrameNumber"))
  897.         return NULL;
  898.  
  899.     if (alGetFrameNumber(self->port, &fnum) < 0)
  900.         return NULL;
  901.  
  902.     return PyLong_FromLongLong((long long) fnum);
  903. }
  904.  
  905.  
  906. static char alp_GetFrameTime__doc__[] = 
  907. "alGetFrameTime: get the time at which a sample frame came in or will go out."
  908. ;
  909.  
  910. static PyObject *
  911. alp_GetFrameTime(alpobject *self, PyObject *args)
  912. {
  913.     stamp_t fnum, time;
  914.     PyObject *ret, *v0, *v1;
  915.  
  916.     if (!PyArg_ParseTuple(args, ":GetFrameTime"))
  917.         return NULL;
  918.     if (alGetFrameTime(self->port, &fnum, &time) < 0)
  919.         return NULL;
  920.     v0 = PyLong_FromLongLong((long long) fnum);
  921.     v1 = PyLong_FromLongLong((long long) time);
  922.     if (PyErr_Occurred()) {
  923.         Py_XDECREF(v0);
  924.         Py_XDECREF(v1);
  925.         return NULL;
  926.     }
  927.     ret = Py_BuildValue("(OO)", v0, v1);
  928.     Py_DECREF(v0);
  929.     Py_DECREF(v1);
  930.     return ret;
  931. }
  932.  
  933.  
  934. static char alp_WriteFrames__doc__[] = 
  935. "alWriteFrames: write sample frames to an audio port."
  936. ;
  937.  
  938. static PyObject *
  939. alp_WriteFrames(alpobject *self, PyObject *args)
  940. {
  941.     char *samples;
  942.     int length;
  943.     int size, ch;
  944.     ALconfig c;
  945.  
  946.     if (!PyArg_ParseTuple(args, "s#:WriteFrames", &samples, &length))
  947.         return NULL;
  948.     c = alGetConfig(self->port);
  949.     switch (alGetSampFmt(c)) {
  950.     case AL_SAMPFMT_TWOSCOMP:
  951.         switch (alGetWidth(c)) {
  952.         case AL_SAMPLE_8:
  953.             size = 1;
  954.             break;
  955.         case AL_SAMPLE_16:
  956.             size = 2;
  957.             break;
  958.         case AL_SAMPLE_24:
  959.             size = 4;
  960.             break;
  961.         default:
  962.             PyErr_SetString(ErrorObject, "can't determine width");
  963.             alFreeConfig(c);
  964.             return NULL;
  965.         }
  966.         break;
  967.     case AL_SAMPFMT_FLOAT:
  968.         size = 4;
  969.         break;
  970.     case AL_SAMPFMT_DOUBLE:
  971.         size = 8;
  972.         break;
  973.     default:
  974.         PyErr_SetString(ErrorObject, "can't determine format");
  975.         alFreeConfig(c);
  976.         return NULL;
  977.     }
  978.     ch = alGetChannels(c);
  979.     alFreeConfig(c);
  980.     if (ch < 0) {
  981.         PyErr_SetString(ErrorObject, "can't determine # of channels");
  982.         return NULL;
  983.     }
  984.     size *= ch;
  985.     if (length % size != 0) {
  986.         PyErr_SetString(ErrorObject,
  987.                 "buffer length not whole number of frames");
  988.         return NULL;
  989.     }
  990.  
  991.     Py_BEGIN_ALLOW_THREADS
  992.     alWriteFrames(self->port, (void *) samples, length / size);
  993.     Py_END_ALLOW_THREADS
  994.  
  995.     Py_INCREF(Py_None);
  996.     return Py_None;
  997. }
  998.  
  999.  
  1000. static char alp_ClosePort__doc__[] = 
  1001. "alClosePort: close an audio port."
  1002. ;
  1003.  
  1004. static PyObject *
  1005. alp_ClosePort(alpobject *self, PyObject *args)
  1006. {
  1007.     if (!PyArg_ParseTuple(args, ":ClosePort"))
  1008.         return NULL;
  1009.     if (alClosePort(self->port) < 0)
  1010.         return NULL;
  1011.     self->port = NULL;
  1012.     Py_INCREF(Py_None);
  1013.     return Py_None;
  1014. }
  1015.  
  1016. #endif /* AL_NO_ELEM */
  1017.  
  1018. #ifdef OLD_INTERFACE
  1019. static PyObject *
  1020. alp_closeport(alpobject *self, PyObject *args)
  1021. {
  1022.     if (!PyArg_ParseTuple(args, ":ClosePort"))
  1023.         return NULL;
  1024.     if (ALcloseport(self->port) < 0)
  1025.         return NULL;
  1026.     self->port = NULL;
  1027.     Py_INCREF(Py_None);
  1028.     return Py_None;
  1029. }
  1030.  
  1031. static PyObject *
  1032. alp_getfd(alpobject *self, PyObject *args)
  1033. {
  1034.     int fd;
  1035.  
  1036.     if (!PyArg_ParseTuple(args, ":GetFD"))
  1037.         return NULL;
  1038.     if ((fd = ALgetfd(self-> port)) == -1)
  1039.         return NULL;
  1040.     return PyInt_FromLong(fd);
  1041. }
  1042.  
  1043. static PyObject *
  1044. alp_getfilled(alpobject *self, PyObject *args)
  1045. {
  1046.     long count;
  1047.  
  1048.     if (!PyArg_ParseTuple(args, ":GetFilled"))
  1049.         return NULL;
  1050.     if ((count = ALgetfilled(self-> port)) == -1)
  1051.         return NULL;
  1052.     return PyInt_FromLong(count);
  1053. }
  1054.  
  1055. static PyObject *
  1056. alp_getfillable(alpobject *self, PyObject *args)
  1057. {
  1058.     long count;
  1059.  
  1060.     if (!PyArg_ParseTuple(args, ":GetFillable"))
  1061.         return NULL;
  1062.     if ((count = ALgetfillable(self-> port)) == -1)
  1063.         return NULL;
  1064.     return PyInt_FromLong (count);
  1065. }
  1066.  
  1067. static PyObject *
  1068. alp_readsamps(alpobject *self, PyObject *args)
  1069. {
  1070.     long count;
  1071.     PyObject *v;
  1072.     ALconfig c;
  1073.     int width;
  1074.     int ret;
  1075.  
  1076.     if (!PyArg_ParseTuple(args, "l:readsamps", &count))
  1077.         return NULL;
  1078.  
  1079.     if (count <= 0) {
  1080.         PyErr_SetString(ErrorObject, "al.readsamps : arg <= 0");
  1081.         return NULL;
  1082.     }
  1083.  
  1084.     c = ALgetconfig(self->port);
  1085. #ifdef AL_405
  1086.     width = ALgetsampfmt(c);
  1087.     if (width == AL_SAMPFMT_FLOAT)
  1088.         width = sizeof(float);
  1089.     else if (width == AL_SAMPFMT_DOUBLE)
  1090.         width = sizeof(double);
  1091.     else
  1092.         width = ALgetwidth(c);
  1093. #else
  1094.     width = ALgetwidth(c);
  1095. #endif /* AL_405 */
  1096.     ALfreeconfig(c);
  1097.     v = PyString_FromStringAndSize((char *)NULL, width * count);
  1098.     if (v == NULL)
  1099.         return NULL;
  1100.  
  1101.     Py_BEGIN_ALLOW_THREADS
  1102.     ret = ALreadsamps(self->port, (void *) PyString_AsString(v), count);
  1103.     Py_END_ALLOW_THREADS
  1104.     if (ret == -1) {
  1105.         Py_DECREF(v);
  1106.         return NULL;
  1107.     }
  1108.  
  1109.     return (v);
  1110. }
  1111.  
  1112. static PyObject *
  1113. alp_writesamps(alpobject *self, PyObject *args)
  1114. {
  1115.     char *buf;
  1116.     int size, width;
  1117.     ALconfig c;
  1118.     int ret;
  1119.  
  1120.     if (!PyArg_ParseTuple(args, "s#:writesamps", &buf, &size))
  1121.         return NULL;
  1122.  
  1123.     c = ALgetconfig(self->port);
  1124. #ifdef AL_405
  1125.     width = ALgetsampfmt(c);
  1126.     if (width == AL_SAMPFMT_FLOAT)
  1127.         width = sizeof(float);
  1128.     else if (width == AL_SAMPFMT_DOUBLE)
  1129.         width = sizeof(double);
  1130.     else
  1131.         width = ALgetwidth(c);
  1132. #else
  1133.     width = ALgetwidth(c);
  1134. #endif /* AL_405 */
  1135.     ALfreeconfig(c);
  1136.     Py_BEGIN_ALLOW_THREADS
  1137.     ret = ALwritesamps (self->port, (void *) buf, (long) size / width);
  1138.     Py_END_ALLOW_THREADS
  1139.     if (ret == -1)
  1140.         return NULL;
  1141.  
  1142.     Py_INCREF(Py_None);
  1143.     return Py_None;
  1144. }
  1145.  
  1146. static PyObject *
  1147. alp_getfillpoint(alpobject *self, PyObject *args)
  1148. {
  1149.     long count;
  1150.  
  1151.     if (!PyArg_ParseTuple(args, ":GetFillPoint"))
  1152.         return NULL;
  1153.     if ((count = ALgetfillpoint(self->port)) == -1)
  1154.         return NULL;
  1155.     return PyInt_FromLong(count);
  1156. }
  1157.  
  1158. static PyObject *
  1159. alp_setfillpoint(alpobject *self, PyObject *args)
  1160. {
  1161.     long count;
  1162.  
  1163.     if (!PyArg_ParseTuple(args, "l:SetFillPoint", &count))
  1164.         return NULL;
  1165.     if (ALsetfillpoint(self->port, count) == -1)
  1166.         return NULL;
  1167.     Py_INCREF(Py_None);
  1168.     return Py_None;
  1169. }
  1170.  
  1171. static PyObject *
  1172. alp_setconfig(alpobject *self, PyObject *args)
  1173. {
  1174.     alcobject *config;
  1175.  
  1176.     if (!PyArg_ParseTuple(args, "O!:SetConfig", &Alctype, &config))
  1177.         return NULL;
  1178.     if (ALsetconfig(self->port, config->config) == -1)
  1179.         return NULL;
  1180.     Py_INCREF(Py_None);
  1181.     return Py_None;
  1182. }
  1183.  
  1184. static PyObject *
  1185. alp_getconfig(alpobject *self, PyObject *args)
  1186. {
  1187.     ALconfig config;
  1188.  
  1189.     if (!PyArg_ParseTuple(args, ":GetConfig"))
  1190.         return NULL;
  1191.     config = ALgetconfig(self->port);
  1192.     if (config == NULL)
  1193.         return NULL;
  1194.     return newalcobject(config);
  1195. }
  1196.  
  1197. #ifdef AL_405
  1198. static PyObject *
  1199. alp_getstatus(alpobject *self, PyObject *args)
  1200. {
  1201.     PyObject *list, *v;
  1202.     long *PVbuffer;
  1203.     long length;
  1204.     int i;
  1205.     
  1206.     if (!PyArg_Parse(args, "O!", &PyList_Type, &list))
  1207.         return NULL;
  1208.     length = PyList_Size(list);
  1209.     PVbuffer = PyMem_NEW(long, length);
  1210.     if (PVbuffer == NULL)
  1211.         return PyErr_NoMemory();
  1212.     for (i = 0; i < length; i++) {
  1213.         v = PyList_GetItem(list, i);
  1214.         if (!PyInt_Check(v)) {
  1215.             PyMem_DEL(PVbuffer);
  1216.             PyErr_BadArgument();
  1217.             return NULL;
  1218.         }
  1219.         PVbuffer[i] = PyInt_AsLong(v);
  1220.     }
  1221.  
  1222.     if (ALgetstatus(self->port, PVbuffer, length) == -1)
  1223.         return NULL;
  1224.  
  1225.     for (i = 0; i < length; i++)
  1226.         PyList_SetItem(list, i, PyInt_FromLong(PVbuffer[i]));
  1227.  
  1228.     PyMem_DEL(PVbuffer);
  1229.  
  1230.     Py_INCREF(Py_None);
  1231.     return Py_None;
  1232. }
  1233. #endif /* AL_405 */
  1234.  
  1235. #endif /* OLD_INTERFACE */
  1236.  
  1237. static struct PyMethodDef alp_methods[] = {
  1238. #ifdef AL_NO_ELEM        /* IRIX 6 */
  1239.     {"SetConfig",    (PyCFunction)alp_SetConfig,    METH_VARARGS,    alp_SetConfig__doc__},
  1240.     {"GetConfig",    (PyCFunction)alp_GetConfig,    METH_VARARGS,    alp_GetConfig__doc__},
  1241.     {"GetResource",    (PyCFunction)alp_GetResource,    METH_VARARGS,    alp_GetResource__doc__},
  1242.     {"GetFD",    (PyCFunction)alp_GetFD,    METH_VARARGS,    alp_GetFD__doc__},
  1243.     {"GetFilled",    (PyCFunction)alp_GetFilled,    METH_VARARGS,    alp_GetFilled__doc__},
  1244.     {"GetFillable",    (PyCFunction)alp_GetFillable,    METH_VARARGS,    alp_GetFillable__doc__},
  1245.     {"ReadFrames",    (PyCFunction)alp_ReadFrames,    METH_VARARGS,    alp_ReadFrames__doc__},
  1246.     {"DiscardFrames",    (PyCFunction)alp_DiscardFrames,    METH_VARARGS,    alp_DiscardFrames__doc__},
  1247.     {"ZeroFrames",    (PyCFunction)alp_ZeroFrames,    METH_VARARGS,    alp_ZeroFrames__doc__},
  1248.     {"SetFillPoint",    (PyCFunction)alp_SetFillPoint,    METH_VARARGS,    alp_SetFillPoint__doc__},
  1249.     {"GetFillPoint",    (PyCFunction)alp_GetFillPoint,    METH_VARARGS,    alp_GetFillPoint__doc__},
  1250.     {"GetFrameNumber",    (PyCFunction)alp_GetFrameNumber,    METH_VARARGS,    alp_GetFrameNumber__doc__},
  1251.     {"GetFrameTime",    (PyCFunction)alp_GetFrameTime,    METH_VARARGS,    alp_GetFrameTime__doc__},
  1252.     {"WriteFrames",    (PyCFunction)alp_WriteFrames,    METH_VARARGS,    alp_WriteFrames__doc__},
  1253.     {"ClosePort",    (PyCFunction)alp_ClosePort,    METH_VARARGS,    alp_ClosePort__doc__},
  1254. #endif /* AL_NO_ELEM */
  1255. #ifdef OLD_INTERFACE
  1256.     {"closeport",        (PyCFunction)alp_closeport,    METH_VARARGS},
  1257.     {"getfd",        (PyCFunction)alp_getfd,    METH_VARARGS},
  1258.         {"fileno",        (PyCFunction)alp_getfd,    METH_VARARGS},
  1259.     {"getfilled",        (PyCFunction)alp_getfilled,    METH_VARARGS},
  1260.     {"getfillable",        (PyCFunction)alp_getfillable,    METH_VARARGS},
  1261.     {"readsamps",        (PyCFunction)alp_readsamps,    METH_VARARGS},
  1262.     {"writesamps",        (PyCFunction)alp_writesamps,    METH_VARARGS},
  1263.     {"setfillpoint",    (PyCFunction)alp_setfillpoint,    METH_VARARGS},
  1264.     {"getfillpoint",    (PyCFunction)alp_getfillpoint,    METH_VARARGS},
  1265.     {"setconfig",        (PyCFunction)alp_setconfig,    METH_VARARGS},
  1266.     {"getconfig",        (PyCFunction)alp_getconfig,    METH_VARARGS},
  1267. #ifdef AL_405
  1268.     {"getstatus",        (PyCFunction)alp_getstatus,    METH_VARARGS},
  1269. #endif /* AL_405 */        
  1270. #endif /* OLD_INTERFACE */
  1271.  
  1272.     {NULL,        NULL}        /* sentinel */
  1273. };
  1274.  
  1275. /* ---------- */
  1276.  
  1277.  
  1278. static PyObject *
  1279. newalpobject(ALport port)
  1280. {
  1281.     alpobject *self;
  1282.     
  1283.     self = PyObject_New(alpobject, &Alptype);
  1284.     if (self == NULL)
  1285.         return NULL;
  1286.     /* XXXX Add your own initializers here */
  1287.     self->port = port;
  1288.     return (PyObject *) self;
  1289. }
  1290.  
  1291.  
  1292. static void
  1293. alp_dealloc(alpobject *self)
  1294. {
  1295.     /* XXXX Add your own cleanup code here */
  1296.     if (self->port) {
  1297. #ifdef AL_NO_ELEM        /* IRIX 6 */
  1298.         alClosePort(self->port);
  1299. #else
  1300.         ALcloseport(self->port);
  1301. #endif
  1302.     }
  1303.     PyObject_Del(self);
  1304. }
  1305.  
  1306. static PyObject *
  1307. alp_getattr(alpobject *self, char *name)
  1308. {
  1309.     /* XXXX Add your own getattr code here */
  1310.     if (self->port == NULL) {
  1311.         PyErr_SetString(ErrorObject, "port already closed");
  1312.         return NULL;
  1313.     }
  1314.     return Py_FindMethod(alp_methods, (PyObject *)self, name);
  1315. }
  1316.  
  1317. static char Alptype__doc__[] = 
  1318. ""
  1319. ;
  1320.  
  1321. static PyTypeObject Alptype = {
  1322.     PyObject_HEAD_INIT(&PyType_Type)
  1323.     0,                /*ob_size*/
  1324.     "port",            /*tp_name*/
  1325.     sizeof(alpobject),        /*tp_basicsize*/
  1326.     0,                /*tp_itemsize*/
  1327.     /* methods */
  1328.     (destructor)alp_dealloc,    /*tp_dealloc*/
  1329.     (printfunc)0,        /*tp_print*/
  1330.     (getattrfunc)alp_getattr,    /*tp_getattr*/
  1331.     (setattrfunc)0,    /*tp_setattr*/
  1332.     (cmpfunc)0,        /*tp_compare*/
  1333.     (reprfunc)0,        /*tp_repr*/
  1334.     0,            /*tp_as_number*/
  1335.     0,        /*tp_as_sequence*/
  1336.     0,        /*tp_as_mapping*/
  1337.     (hashfunc)0,        /*tp_hash*/
  1338.     (ternaryfunc)0,        /*tp_call*/
  1339.     (reprfunc)0,        /*tp_str*/
  1340.  
  1341.     /* Space for future expansion */
  1342.     0L,0L,0L,0L,
  1343.     Alptype__doc__ /* Documentation string */
  1344. };
  1345.  
  1346. /* End of code for port objects */
  1347. /* -------------------------------------------------------- */
  1348.  
  1349.  
  1350. #ifdef AL_NO_ELEM        /* IRIX 6 */
  1351.  
  1352. static char al_NewConfig__doc__[] =
  1353. "alNewConfig: create and initialize an audio ALconfig structure."
  1354. ;
  1355.  
  1356. static PyObject *
  1357. al_NewConfig(PyObject *self, PyObject *args)
  1358. {
  1359.     ALconfig config;
  1360.  
  1361.     if (!PyArg_ParseTuple(args, ":NewConfig"))
  1362.         return NULL;
  1363.     if ((config = alNewConfig()) == NULL)
  1364.         return NULL;
  1365.     return newalcobject(config);
  1366. }
  1367.  
  1368. static char al_OpenPort__doc__[] =
  1369. "alOpenPort: open an audio port."
  1370. ;
  1371.  
  1372. static PyObject *
  1373. al_OpenPort(PyObject *self, PyObject *args)
  1374. {
  1375.     ALport port;
  1376.     char *name, *dir;
  1377.     alcobject *config = NULL;
  1378.  
  1379.     if (!PyArg_ParseTuple(args, "ss|O!:OpenPort", &name, &dir, &Alctype, &config))
  1380.         return NULL;
  1381.     if ((port = alOpenPort(name, dir, config ? config->config : NULL)) == NULL)
  1382.         return NULL;
  1383.     return newalpobject(port);
  1384. }
  1385.  
  1386. static char al_Connect__doc__[] =
  1387. "alConnect: connect two audio I/O resources."
  1388. ;
  1389.  
  1390. static PyObject *
  1391. al_Connect(PyObject *self, PyObject *args)
  1392. {
  1393.     int source, dest, nprops = 0, id, i;
  1394.     ALpv *props = NULL;
  1395.     ALparamInfo *propinfo = NULL;
  1396.     PyObject *propobj = NULL;
  1397.  
  1398.     if (!PyArg_ParseTuple(args, "ii|O!:Connect", &source, &dest, &PyList_Type, &propobj))
  1399.         return NULL;
  1400.     if (propobj != NULL) {
  1401.         nprops = python2params(source, dest, propobj, &props, &propinfo);
  1402.         if (nprops < 0)
  1403.             return NULL;
  1404.     }
  1405.  
  1406.     id = alConnect(source, dest, props, nprops);
  1407.  
  1408.     if (props) {
  1409.         for (i = 0; i < nprops; i++) {
  1410.             switch (propinfo[i].valueType) {
  1411.             case AL_SET_VAL:
  1412.             case AL_VECTOR_VAL:
  1413.                 PyMem_DEL(props[i].value.ptr);
  1414.                 break;
  1415.             }
  1416.         }
  1417.         PyMem_DEL(props);
  1418.         PyMem_DEL(propinfo);
  1419.     }
  1420.  
  1421.     if (id < 0)
  1422.         return NULL;
  1423.     return PyInt_FromLong((long) id);
  1424. }
  1425.  
  1426. static char al_Disconnect__doc__[] =
  1427. "alDisconnect: delete a connection between two audio I/O resources."
  1428. ;
  1429.  
  1430. static PyObject *
  1431. al_Disconnect(PyObject *self, PyObject *args)
  1432. {
  1433.     int res;
  1434.  
  1435.     if (!PyArg_ParseTuple(args, "i:Disconnect", &res))
  1436.         return NULL;
  1437.     if (alDisconnect(res) < 0)
  1438.         return NULL;
  1439.     Py_INCREF(Py_None);
  1440.     return Py_None;
  1441. }
  1442.  
  1443. static char al_GetParams__doc__[] =
  1444. "alGetParams: get the values of audio resource parameters."
  1445. ;
  1446.  
  1447. static PyObject *
  1448. al_GetParams(PyObject *self, PyObject *args)
  1449. {
  1450.     int resource;
  1451.     PyObject *pvslist, *item = NULL, *v = NULL;
  1452.     ALpv *pvs;
  1453.     int i, j, npvs;
  1454.     ALparamInfo *pinfo;
  1455.  
  1456.     if (!PyArg_ParseTuple(args, "iO!:GetParams", &resource, &PyList_Type, &pvslist))
  1457.         return NULL;
  1458.     npvs = PyList_Size(pvslist);
  1459.     pvs = PyMem_NEW(ALpv, npvs);
  1460.     pinfo = PyMem_NEW(ALparamInfo, npvs);
  1461.     for (i = 0; i < npvs; i++) {
  1462.         item = PyList_GetItem(pvslist, i);
  1463.         if (!PyInt_Check(item)) {
  1464.             item = NULL;
  1465.             PyErr_SetString(ErrorObject, "list of integers expected");
  1466.             goto error;
  1467.         }
  1468.         pvs[i].param = (int) PyInt_AsLong(item);
  1469.         item = NULL;    /* not needed anymore */
  1470.         if (alGetParamInfo(resource, pvs[i].param, &pinfo[i]) < 0)
  1471.             goto error;
  1472.         switch (pinfo[i].valueType) {
  1473.         case AL_NO_VAL:
  1474.             break;
  1475.         case AL_MATRIX_VAL:
  1476.             pinfo[i].maxElems *= pinfo[i].maxElems2;
  1477.             /* fall through */
  1478.         case AL_STRING_VAL:
  1479.         case AL_SET_VAL:
  1480.         case AL_VECTOR_VAL:
  1481.             switch (pinfo[i].elementType) {
  1482.             case AL_INT32_ELEM:
  1483.             case AL_RESOURCE_ELEM:
  1484.             case AL_ENUM_ELEM:
  1485.                 pvs[i].value.ptr = PyMem_NEW(int, pinfo[i].maxElems);
  1486.                 pvs[i].sizeIn = pinfo[i].maxElems;
  1487.                 break;
  1488.             case AL_INT64_ELEM:
  1489.             case AL_FIXED_ELEM:
  1490.                 pvs[i].value.ptr = PyMem_NEW(long long, pinfo[i].maxElems);
  1491.                 pvs[i].sizeIn = pinfo[i].maxElems;
  1492.                 break;
  1493.             case AL_CHAR_ELEM:
  1494.                 pvs[i].value.ptr = PyMem_NEW(char, 32);
  1495.                 pvs[i].sizeIn = 32;
  1496.                 break;
  1497.             case AL_NO_ELEM:
  1498.             case AL_PTR_ELEM:
  1499.             default:
  1500.                 PyErr_SetString(ErrorObject, "internal error");
  1501.                 goto error;
  1502.             }
  1503.             break;
  1504.         case AL_SCALAR_VAL:
  1505.             break;
  1506.         default:
  1507.             PyErr_SetString(ErrorObject, "internal error");
  1508.             goto error;
  1509.         }
  1510.         if (pinfo[i].valueType == AL_MATRIX_VAL) {
  1511.             pinfo[i].maxElems /= pinfo[i].maxElems2;
  1512.             pvs[i].sizeIn /= pinfo[i].maxElems2;
  1513.             pvs[i].size2In = pinfo[i].maxElems2;
  1514.         }
  1515.     }
  1516.     if (alGetParams(resource, pvs, npvs) < 0)
  1517.         goto error;
  1518.     v = PyList_New(npvs);
  1519.     for (i = 0; i < npvs; i++) {
  1520.         if (pvs[i].sizeOut < 0) {
  1521.             char buf[32];
  1522.             sprintf(buf, "problem with param %d", i);
  1523.             PyErr_SetString(ErrorObject, buf);
  1524.             goto error;
  1525.         }
  1526.         switch (pinfo[i].valueType) {
  1527.         case AL_NO_VAL:
  1528.             item = Py_None;
  1529.             Py_INCREF(item);
  1530.             break;
  1531.         case AL_STRING_VAL:
  1532.             item = PyString_FromString(pvs[i].value.ptr);
  1533.             PyMem_DEL(pvs[i].value.ptr);
  1534.             break;
  1535.         case AL_MATRIX_VAL:
  1536.             /* XXXX this is not right */
  1537.             pvs[i].sizeOut *= pvs[i].size2Out;
  1538.             /* fall through */
  1539.         case AL_SET_VAL:
  1540.         case AL_VECTOR_VAL:
  1541.             item = PyList_New(pvs[i].sizeOut);
  1542.             for (j = 0; j < pvs[i].sizeOut; j++) {
  1543.                 switch (pinfo[i].elementType) {
  1544.                 case AL_INT32_ELEM:
  1545.                 case AL_RESOURCE_ELEM:
  1546.                 case AL_ENUM_ELEM:
  1547.                     PyList_SetItem(item, j, PyInt_FromLong((long) ((int *) pvs[i].value.ptr)[j]));
  1548.                     break;
  1549.                 case AL_INT64_ELEM:
  1550.                     PyList_SetItem(item, j, PyLong_FromLongLong(((long long *) pvs[i].value.ptr)[j]));
  1551.                     break;
  1552.                 case AL_FIXED_ELEM:
  1553.                     PyList_SetItem(item, j, PyFloat_FromDouble(alFixedToDouble(((long long *) pvs[i].value.ptr)[j])));
  1554.                     break;
  1555.                 default:
  1556.                     PyErr_SetString(ErrorObject, "internal error");
  1557.                     goto error;
  1558.                 }
  1559.             }
  1560.             PyMem_DEL(pvs[i].value.ptr);
  1561.             break;
  1562.         case AL_SCALAR_VAL:
  1563.             item = param2python(resource, pvs[i].param, pvs[i].value, &pinfo[i]);
  1564.             break;
  1565.         }
  1566.         if (PyErr_Occurred() ||
  1567.             PyList_SetItem(v, i, Py_BuildValue("(iO)", pvs[i].param,
  1568.                                item)) < 0 ||
  1569.             PyErr_Occurred())
  1570.             goto error;
  1571.         Py_DECREF(item);
  1572.     }
  1573.     PyMem_DEL(pvs);
  1574.     PyMem_DEL(pinfo);
  1575.     return v;
  1576.  
  1577.   error:
  1578.     Py_XDECREF(v);
  1579.     Py_XDECREF(item);
  1580.     if (pvs)
  1581.         PyMem_DEL(pvs);
  1582.     if (pinfo)
  1583.         PyMem_DEL(pinfo);
  1584.     return NULL;
  1585. }
  1586.  
  1587. static char al_SetParams__doc__[] =
  1588. "alSetParams: set the values of audio resource parameters."
  1589. ;
  1590.  
  1591. static PyObject *
  1592. al_SetParams(PyObject *self, PyObject *args)
  1593. {
  1594.     int resource;
  1595.     PyObject *pvslist, *item;
  1596.     ALpv *pvs;
  1597.     ALparamInfo *pinfo;
  1598.     int npvs, i;
  1599.  
  1600.     if (!PyArg_ParseTuple(args, "iO!:SetParams", &resource, &PyList_Type, &pvslist))
  1601.         return NULL;
  1602.     npvs = python2params(resource, -1, pvslist, &pvs, &pinfo);
  1603.     if (npvs < 0)
  1604.         return NULL;
  1605.  
  1606.     if (alSetParams(resource, pvs, npvs) < 0)
  1607.         goto error;
  1608.  
  1609.     /* cleanup */
  1610.     for (i = 0; i < npvs; i++) {
  1611.         switch (pinfo[i].valueType) {
  1612.         case AL_SET_VAL:
  1613.         case AL_VECTOR_VAL:
  1614.             PyMem_DEL(pvs[i].value.ptr);
  1615.             break;
  1616.         }
  1617.     }
  1618.     PyMem_DEL(pvs);
  1619.     PyMem_DEL(pinfo);
  1620.  
  1621.     Py_INCREF(Py_None);
  1622.     return Py_None;
  1623.  
  1624.   error:
  1625.     /* XXXX we should clean up everything */
  1626.     if (pvs)
  1627.         PyMem_DEL(pvs);
  1628.     if (pinfo)
  1629.         PyMem_DEL(pinfo);
  1630.     return NULL;
  1631. }
  1632.  
  1633. static char al_QueryValues__doc__[] =
  1634. "alQueryValues: get the set of possible values for a parameter."
  1635. ;
  1636.  
  1637. static PyObject *
  1638. al_QueryValues(PyObject *self, PyObject *args)
  1639. {
  1640.     int resource, param;
  1641.     ALvalue *return_set = NULL;
  1642.     int setsize = 32, qualsize = 0, nvals, i;
  1643.     ALpv *quals = NULL;
  1644.     ALparamInfo pinfo;
  1645.     ALparamInfo *qualinfo = NULL;
  1646.     PyObject *qualobj = NULL;
  1647.     PyObject *res = NULL, *item;
  1648.  
  1649.     if (!PyArg_ParseTuple(args, "ii|O!:QueryValues", &resource, ¶m,
  1650.                   &PyList_Type, &qualobj))
  1651.         return NULL;
  1652.     if (qualobj != NULL) {
  1653.         qualsize = python2params(resource, param, qualobj, &quals, &qualinfo);
  1654.         if (qualsize < 0)
  1655.             return NULL;
  1656.     }
  1657.     setsize = 32;
  1658.     return_set = PyMem_NEW(ALvalue, setsize);
  1659.     if (return_set == NULL) {
  1660.         PyErr_NoMemory();
  1661.         goto cleanup;
  1662.     }
  1663.  
  1664.   retry:
  1665.     nvals = alQueryValues(resource, param, return_set, setsize, quals, qualsize);
  1666.     if (nvals < 0)
  1667.         goto cleanup;
  1668.     if (nvals > setsize) {
  1669.         setsize = nvals;
  1670.         PyMem_RESIZE(return_set, ALvalue, setsize);
  1671.         if (return_set == NULL) {
  1672.             PyErr_NoMemory();
  1673.             goto cleanup;
  1674.         }
  1675.         goto retry;
  1676.     }
  1677.  
  1678.     if (alGetParamInfo(resource, param, &pinfo) < 0)
  1679.         goto cleanup;
  1680.  
  1681.     res = PyList_New(nvals);
  1682.     if (res == NULL)
  1683.         goto cleanup;
  1684.     for (i = 0; i < nvals; i++) {
  1685.         item = param2python(resource, param, return_set[i], &pinfo);
  1686.         if (item == NULL ||
  1687.             PyList_SetItem(res, i, item) < 0) {
  1688.             Py_DECREF(res);
  1689.             res = NULL;
  1690.             goto cleanup;
  1691.         }
  1692.     }
  1693.  
  1694.   cleanup:
  1695.     if (return_set)
  1696.         PyMem_DEL(return_set);
  1697.     if (quals) {
  1698.         for (i = 0; i < qualsize; i++) {
  1699.             switch (qualinfo[i].valueType) {
  1700.             case AL_SET_VAL:
  1701.             case AL_VECTOR_VAL:
  1702.                 PyMem_DEL(quals[i].value.ptr);
  1703.                 break;
  1704.             }
  1705.         }
  1706.         PyMem_DEL(quals);
  1707.         PyMem_DEL(qualinfo);
  1708.     }
  1709.  
  1710.     return res;
  1711. }
  1712.  
  1713. static char al_GetParamInfo__doc__[] =
  1714. "alGetParamInfo: get information about a parameter on a particular audio resource."
  1715. ;
  1716.  
  1717. static PyObject *
  1718. al_GetParamInfo(PyObject *self, PyObject *args)
  1719. {
  1720.     int res, param;
  1721.     ALparamInfo pinfo;
  1722.     PyObject *v, *item;;
  1723.  
  1724.     if (!PyArg_ParseTuple(args, "ii:GetParamInfo", &res, ¶m))
  1725.         return NULL;
  1726.     if (alGetParamInfo(res, param, &pinfo) < 0)
  1727.         return NULL;
  1728.     v = PyDict_New();
  1729.  
  1730.     item = PyInt_FromLong((long) pinfo.resource);
  1731.     PyDict_SetItemString(v, "resource", item);
  1732.     Py_DECREF(item);
  1733.  
  1734.     item = PyInt_FromLong((long) pinfo.param);
  1735.     PyDict_SetItemString(v, "param", item);
  1736.     Py_DECREF(item);
  1737.  
  1738.     item = PyInt_FromLong((long) pinfo.valueType);
  1739.     PyDict_SetItemString(v, "valueType", item);
  1740.     Py_DECREF(item);
  1741.  
  1742.     if (pinfo.valueType != AL_NO_VAL && pinfo.valueType != AL_SCALAR_VAL) {
  1743.         /* multiple values */
  1744.         item = PyInt_FromLong((long) pinfo.maxElems);
  1745.         PyDict_SetItemString(v, "maxElems", item);
  1746.         Py_DECREF(item);
  1747.  
  1748.         if (pinfo.valueType == AL_MATRIX_VAL) {
  1749.             /* 2 dimensional */
  1750.             item = PyInt_FromLong((long) pinfo.maxElems2);
  1751.             PyDict_SetItemString(v, "maxElems2", item);
  1752.             Py_DECREF(item);
  1753.         }
  1754.     }
  1755.  
  1756.     item = PyInt_FromLong((long) pinfo.elementType);
  1757.     PyDict_SetItemString(v, "elementType", item);
  1758.     Py_DECREF(item);
  1759.  
  1760.     item = PyString_FromString(pinfo.name);
  1761.     PyDict_SetItemString(v, "name", item);
  1762.     Py_DECREF(item);
  1763.  
  1764.     item = param2python(res, param, pinfo.initial, &pinfo);
  1765.     PyDict_SetItemString(v, "initial", item);
  1766.     Py_DECREF(item);
  1767.  
  1768.     if (pinfo.elementType != AL_ENUM_ELEM &&
  1769.         pinfo.elementType != AL_RESOURCE_ELEM &&
  1770.         pinfo.elementType != AL_CHAR_ELEM) {
  1771.         /* range param */
  1772.         item = param2python(res, param, pinfo.min, &pinfo);
  1773.         PyDict_SetItemString(v, "min", item);
  1774.         Py_DECREF(item);
  1775.  
  1776.         item = param2python(res, param, pinfo.max, &pinfo);
  1777.         PyDict_SetItemString(v, "max", item);
  1778.         Py_DECREF(item);
  1779.  
  1780.         item = param2python(res, param, pinfo.minDelta, &pinfo);
  1781.         PyDict_SetItemString(v, "minDelta", item);
  1782.         Py_DECREF(item);
  1783.  
  1784.         item = param2python(res, param, pinfo.maxDelta, &pinfo);
  1785.         PyDict_SetItemString(v, "maxDelta", item);
  1786.         Py_DECREF(item);
  1787.  
  1788.         item = PyInt_FromLong((long) pinfo.specialVals);
  1789.         PyDict_SetItemString(v, "specialVals", item);
  1790.         Py_DECREF(item);
  1791.     }
  1792.  
  1793.     return v;
  1794. }
  1795.  
  1796. static char al_GetResourceByName__doc__[] =
  1797. "alGetResourceByName: find an audio resource by name."
  1798. ;
  1799.  
  1800. static PyObject *
  1801. al_GetResourceByName(PyObject *self, PyObject *args)
  1802. {
  1803.     int res, start_res, type;
  1804.     char *name;
  1805.  
  1806.     if (!PyArg_ParseTuple(args, "isi:GetResourceByName", &start_res, &name, &type))
  1807.         return NULL;
  1808.     if ((res = alGetResourceByName(start_res, name, type)) == 0)
  1809.         return NULL;
  1810.     return PyInt_FromLong((long) res);
  1811. }
  1812.  
  1813. static char al_IsSubtype__doc__[] =
  1814. "alIsSubtype: indicate if one resource type is a subtype of another."
  1815. ;
  1816.  
  1817. static PyObject *
  1818. al_IsSubtype(PyObject *self, PyObject *args)
  1819. {
  1820.     int type, subtype;
  1821.  
  1822.     if (!PyArg_ParseTuple(args, "ii:IsSubtype", &type, &subtype))
  1823.         return NULL;
  1824.     return PyInt_FromLong((long) alIsSubtype(type, subtype));
  1825. }
  1826.  
  1827. static char al_SetErrorHandler__doc__[] =
  1828. ""
  1829. ;
  1830.  
  1831. static PyObject *
  1832. al_SetErrorHandler(PyObject *self, PyObject *args)
  1833. {
  1834.  
  1835.     if (!PyArg_ParseTuple(args, ":SetErrorHandler"))
  1836.         return NULL;
  1837.     Py_INCREF(Py_None);
  1838.     return Py_None;
  1839. }
  1840.  
  1841. #endif /* AL_NO_ELEM */
  1842.  
  1843. #ifdef OLD_INTERFACE
  1844.  
  1845. static PyObject *
  1846. al_openport(PyObject *self, PyObject *args)
  1847. {
  1848.     char *name, *dir;
  1849.     ALport port;
  1850.     alcobject *config = NULL;
  1851.  
  1852.     if (!PyArg_ParseTuple(args, "ss|O!:OpenPort", &name, &dir, &Alctype, &config))
  1853.         return NULL;
  1854.     if ((port = ALopenport(name, dir, config ? config->config : NULL)) == NULL)
  1855.         return NULL;
  1856.     return newalpobject(port);
  1857. }
  1858.  
  1859. static PyObject *
  1860. al_newconfig(PyObject *self, PyObject *args)
  1861. {
  1862.     ALconfig config;
  1863.  
  1864.     if (!PyArg_ParseTuple(args, ":NewConfig"))
  1865.         return NULL;
  1866.     if ((config = ALnewconfig ()) == NULL)
  1867.         return NULL;
  1868.     return newalcobject(config);
  1869. }
  1870.  
  1871. static PyObject *
  1872. al_queryparams(PyObject *self, PyObject *args)
  1873. {
  1874.     long device;
  1875.     long length;
  1876.     long *PVbuffer;
  1877.     long PVdummy[2];
  1878.     PyObject *v = NULL;
  1879.     int i;
  1880.  
  1881.     if (!PyArg_ParseTuple(args, "l:queryparams", &device))
  1882.         return NULL;
  1883.     if ((length = ALqueryparams(device, PVdummy, 2L)) == -1)
  1884.         return NULL;
  1885.     if ((PVbuffer = PyMem_NEW(long, length)) == NULL)
  1886.         return PyErr_NoMemory();
  1887.     if (ALqueryparams(device, PVbuffer, length) >= 0 &&
  1888.         (v = PyList_New((int)length)) != NULL) {
  1889.         for (i = 0; i < length; i++)
  1890.             PyList_SetItem(v, i, PyInt_FromLong(PVbuffer[i]));
  1891.     }
  1892.     PyMem_DEL(PVbuffer);
  1893.     return v;
  1894. }
  1895.  
  1896. static PyObject *
  1897. doParams(PyObject *args, int (*func)(long, long *, long), int modified)
  1898. {
  1899.     long device;
  1900.     PyObject *list, *v;
  1901.     long *PVbuffer;
  1902.     long length;
  1903.     int i;
  1904.     
  1905.     if (!PyArg_ParseTuple(args, "lO!", &device, &PyList_Type, &list))
  1906.         return NULL;
  1907.     length = PyList_Size(list);
  1908.     PVbuffer = PyMem_NEW(long, length);
  1909.     if (PVbuffer == NULL)
  1910.         return PyErr_NoMemory();
  1911.     for (i = 0; i < length; i++) {
  1912.         v = PyList_GetItem(list, i);
  1913.         if (!PyInt_Check(v)) {
  1914.             PyMem_DEL(PVbuffer);
  1915.             PyErr_BadArgument();
  1916.             return NULL;
  1917.         }
  1918.         PVbuffer[i] = PyInt_AsLong(v);
  1919.     }
  1920.  
  1921.     if ((*func)(device, PVbuffer, length) == -1) {
  1922.         PyMem_DEL(PVbuffer);
  1923.         return NULL;
  1924.     }
  1925.  
  1926.     if (modified) {
  1927.         for (i = 0; i < length; i++)
  1928.             PyList_SetItem(list, i, PyInt_FromLong(PVbuffer[i]));
  1929.     }
  1930.  
  1931.     PyMem_DEL(PVbuffer);
  1932.  
  1933.     Py_INCREF(Py_None);
  1934.     return Py_None;
  1935. }
  1936.  
  1937. static PyObject *
  1938. al_getparams(PyObject *self, PyObject *args)
  1939. {
  1940.     return doParams(args, ALgetparams, 1);
  1941. }
  1942.  
  1943. static PyObject *
  1944. al_setparams(PyObject *self, PyObject *args)
  1945. {
  1946.     return doParams(args, ALsetparams, 0);
  1947. }
  1948.  
  1949. static PyObject *
  1950. al_getname(PyObject *self, PyObject *args)
  1951. {
  1952.     long device, descriptor;
  1953.     char *name;
  1954.  
  1955.     if (!PyArg_ParseTuple(args, "ll:getname", &device, &descriptor))
  1956.         return NULL;
  1957.     if ((name = ALgetname(device, descriptor)) == NULL)
  1958.         return NULL;
  1959.     return PyString_FromString(name);
  1960. }
  1961.  
  1962. static PyObject *
  1963. al_getdefault(PyObject *self, PyObject *args)
  1964. {
  1965.     long device, descriptor, value;
  1966.  
  1967.     if (!PyArg_ParseTuple(args, "ll:getdefault", &device, &descriptor))
  1968.         return NULL;
  1969.     if ((value = ALgetdefault(device, descriptor)) == -1)
  1970.         return NULL;
  1971.     return PyLong_FromLong(value);
  1972. }
  1973.  
  1974. static PyObject *
  1975. al_getminmax(PyObject *self, PyObject *args)
  1976. {
  1977.     long device, descriptor, min, max;
  1978.  
  1979.     if (!PyArg_ParseTuple(args, "ll:getminmax", &device, &descriptor))
  1980.         return NULL;
  1981.     min = -1;
  1982.     max = -1;
  1983.     if (ALgetminmax(device, descriptor, &min, &max) == -1)
  1984.         return NULL;
  1985.     return Py_BuildValue("ll", min, max);
  1986. }
  1987.  
  1988. #endif /* OLD_INTERFACE */
  1989.  
  1990. /* List of methods defined in the module */
  1991.  
  1992. static struct PyMethodDef al_methods[] = {
  1993. #ifdef AL_NO_ELEM        /* IRIX 6 */
  1994.     {"NewConfig",    (PyCFunction)al_NewConfig,    METH_VARARGS,    al_NewConfig__doc__},
  1995.     {"OpenPort",    (PyCFunction)al_OpenPort,    METH_VARARGS,    al_OpenPort__doc__},
  1996.     {"Connect",    (PyCFunction)al_Connect,    METH_VARARGS,    al_Connect__doc__},
  1997.     {"Disconnect",    (PyCFunction)al_Disconnect,    METH_VARARGS,    al_Disconnect__doc__},
  1998.     {"GetParams",    (PyCFunction)al_GetParams,    METH_VARARGS,    al_GetParams__doc__},
  1999.     {"SetParams",    (PyCFunction)al_SetParams,    METH_VARARGS,    al_SetParams__doc__},
  2000.     {"QueryValues",    (PyCFunction)al_QueryValues,    METH_VARARGS,    al_QueryValues__doc__},
  2001.     {"GetParamInfo",    (PyCFunction)al_GetParamInfo,    METH_VARARGS,    al_GetParamInfo__doc__},
  2002.     {"GetResourceByName",    (PyCFunction)al_GetResourceByName,    METH_VARARGS,    al_GetResourceByName__doc__},
  2003.     {"IsSubtype",    (PyCFunction)al_IsSubtype,    METH_VARARGS,    al_IsSubtype__doc__},
  2004. #if 0
  2005.     /* this one not supported */
  2006.     {"SetErrorHandler",    (PyCFunction)al_SetErrorHandler,    METH_VARARGS,    al_SetErrorHandler__doc__},
  2007. #endif
  2008. #endif /* AL_NO_ELEM */
  2009. #ifdef OLD_INTERFACE
  2010.     {"openport",        (PyCFunction)al_openport,    METH_VARARGS},
  2011.     {"newconfig",        (PyCFunction)al_newconfig,    METH_VARARGS},
  2012.     {"queryparams",        (PyCFunction)al_queryparams,    METH_VARARGS},
  2013.     {"getparams",        (PyCFunction)al_getparams,    METH_VARARGS},
  2014.     {"setparams",        (PyCFunction)al_setparams,    METH_VARARGS},
  2015.     {"getname",        (PyCFunction)al_getname,    METH_VARARGS},
  2016.     {"getdefault",        (PyCFunction)al_getdefault,    METH_VARARGS},
  2017.     {"getminmax",        (PyCFunction)al_getminmax,    METH_VARARGS},
  2018. #endif /* OLD_INTERFACE */
  2019.  
  2020.     {NULL,     (PyCFunction)NULL, 0, NULL}        /* sentinel */
  2021. };
  2022.  
  2023.  
  2024. /* Initialization function for the module (*must* be called inital) */
  2025.  
  2026. static char al_module_documentation[] = 
  2027. ""
  2028. ;
  2029.  
  2030. void
  2031. inital(void)
  2032. {
  2033.     PyObject *m, *d, *x;
  2034.  
  2035.     /* Create the module and add the functions */
  2036.     m = Py_InitModule4("al", al_methods,
  2037.         al_module_documentation,
  2038.         (PyObject*)NULL,PYTHON_API_VERSION);
  2039.  
  2040.     /* Add some symbolic constants to the module */
  2041.     d = PyModule_GetDict(m);
  2042.     ErrorObject = PyErr_NewException("al.error", NULL, NULL);
  2043.     PyDict_SetItemString(d, "error", ErrorObject);
  2044.  
  2045.     /* XXXX Add constants here */
  2046. #ifdef AL_4CHANNEL
  2047.     x =  PyInt_FromLong((long) AL_4CHANNEL);
  2048.     if (x == NULL || PyDict_SetItemString(d, "FOURCHANNEL", x) < 0)
  2049.         goto error;
  2050.     Py_DECREF(x);
  2051. #endif
  2052. #ifdef AL_ADAT_IF_TYPE
  2053.     x =  PyInt_FromLong((long) AL_ADAT_IF_TYPE);
  2054.     if (x == NULL || PyDict_SetItemString(d, "ADAT_IF_TYPE", x) < 0)
  2055.         goto error;
  2056.     Py_DECREF(x);
  2057. #endif
  2058. #ifdef AL_ADAT_MCLK_TYPE
  2059.     x =  PyInt_FromLong((long) AL_ADAT_MCLK_TYPE);
  2060.     if (x == NULL || PyDict_SetItemString(d, "ADAT_MCLK_TYPE", x) < 0)
  2061.         goto error;
  2062.     Py_DECREF(x);
  2063. #endif
  2064. #ifdef AL_AES_IF_TYPE
  2065.     x =  PyInt_FromLong((long) AL_AES_IF_TYPE);
  2066.     if (x == NULL || PyDict_SetItemString(d, "AES_IF_TYPE", x) < 0)
  2067.         goto error;
  2068.     Py_DECREF(x);
  2069. #endif
  2070. #ifdef AL_AES_MCLK_TYPE
  2071.     x =  PyInt_FromLong((long) AL_AES_MCLK_TYPE);
  2072.     if (x == NULL || PyDict_SetItemString(d, "AES_MCLK_TYPE", x) < 0)
  2073.         goto error;
  2074.     Py_DECREF(x);
  2075. #endif
  2076. #ifdef AL_ANALOG_IF_TYPE
  2077.     x =  PyInt_FromLong((long) AL_ANALOG_IF_TYPE);
  2078.     if (x == NULL || PyDict_SetItemString(d, "ANALOG_IF_TYPE", x) < 0)
  2079.         goto error;
  2080.     Py_DECREF(x);
  2081. #endif
  2082. #ifdef AL_ASSOCIATE
  2083.     x =  PyInt_FromLong((long) AL_ASSOCIATE);
  2084.     if (x == NULL || PyDict_SetItemString(d, "ASSOCIATE", x) < 0)
  2085.         goto error;
  2086.     Py_DECREF(x);
  2087. #endif
  2088. #ifdef AL_BAD_BUFFER_NULL
  2089.     x =  PyInt_FromLong((long) AL_BAD_BUFFER_NULL);
  2090.     if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFER_NULL", x) < 0)
  2091.         goto error;
  2092.     Py_DECREF(x);
  2093. #endif
  2094. #ifdef AL_BAD_BUFFERLENGTH
  2095.     x =  PyInt_FromLong((long) AL_BAD_BUFFERLENGTH);
  2096.     if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFERLENGTH", x) < 0)
  2097.         goto error;
  2098.     Py_DECREF(x);
  2099. #endif
  2100. #ifdef AL_BAD_BUFFERLENGTH_NEG
  2101.     x =  PyInt_FromLong((long) AL_BAD_BUFFERLENGTH_NEG);
  2102.     if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFERLENGTH_NEG", x) < 0)
  2103.         goto error;
  2104.     Py_DECREF(x);
  2105. #endif
  2106. #ifdef AL_BAD_BUFFERLENGTH_ODD
  2107.     x =  PyInt_FromLong((long) AL_BAD_BUFFERLENGTH_ODD);
  2108.     if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFERLENGTH_ODD", x) < 0)
  2109.         goto error;
  2110.     Py_DECREF(x);
  2111. #endif
  2112. #ifdef AL_BAD_CHANNELS
  2113.     x =  PyInt_FromLong((long) AL_BAD_CHANNELS);
  2114.     if (x == NULL || PyDict_SetItemString(d, "BAD_CHANNELS", x) < 0)
  2115.         goto error;
  2116.     Py_DECREF(x);
  2117. #endif
  2118. #ifdef AL_BAD_CONFIG
  2119.     x =  PyInt_FromLong((long) AL_BAD_CONFIG);
  2120.     if (x == NULL || PyDict_SetItemString(d, "BAD_CONFIG", x) < 0)
  2121.         goto error;
  2122.     Py_DECREF(x);
  2123. #endif
  2124. #ifdef AL_BAD_COUNT_NEG
  2125.     x =  PyInt_FromLong((long) AL_BAD_COUNT_NEG);
  2126.     if (x == NULL || PyDict_SetItemString(d, "BAD_COUNT_NEG", x) < 0)
  2127.         goto error;
  2128.     Py_DECREF(x);
  2129. #endif
  2130. #ifdef AL_BAD_DEVICE
  2131.     x =  PyInt_FromLong((long) AL_BAD_DEVICE);
  2132.     if (x == NULL || PyDict_SetItemString(d, "BAD_DEVICE", x) < 0)
  2133.         goto error;
  2134.     Py_DECREF(x);
  2135. #endif
  2136. #ifdef AL_BAD_DEVICE_ACCESS
  2137.     x =  PyInt_FromLong((long) AL_BAD_DEVICE_ACCESS);
  2138.     if (x == NULL || PyDict_SetItemString(d, "BAD_DEVICE_ACCESS", x) < 0)
  2139.         goto error;
  2140.     Py_DECREF(x);
  2141. #endif
  2142. #ifdef AL_BAD_DIRECTION
  2143.     x =  PyInt_FromLong((long) AL_BAD_DIRECTION);
  2144.     if (x == NULL || PyDict_SetItemString(d, "BAD_DIRECTION", x) < 0)
  2145.         goto error;
  2146.     Py_DECREF(x);
  2147. #endif
  2148. #ifdef AL_BAD_FILLPOINT
  2149.     x =  PyInt_FromLong((long) AL_BAD_FILLPOINT);
  2150.     if (x == NULL || PyDict_SetItemString(d, "BAD_FILLPOINT", x) < 0)
  2151.         goto error;
  2152.     Py_DECREF(x);
  2153. #endif
  2154. #ifdef AL_BAD_FLOATMAX
  2155.     x =  PyInt_FromLong((long) AL_BAD_FLOATMAX);
  2156.     if (x == NULL || PyDict_SetItemString(d, "BAD_FLOATMAX", x) < 0)
  2157.         goto error;
  2158.     Py_DECREF(x);
  2159. #endif
  2160. #ifdef AL_BAD_ILLEGAL_STATE
  2161.     x =  PyInt_FromLong((long) AL_BAD_ILLEGAL_STATE);
  2162.     if (x == NULL || PyDict_SetItemString(d, "BAD_ILLEGAL_STATE", x) < 0)
  2163.         goto error;
  2164.     Py_DECREF(x);
  2165. #endif
  2166. #ifdef AL_BAD_NO_PORTS
  2167.     x =  PyInt_FromLong((long) AL_BAD_NO_PORTS);
  2168.     if (x == NULL || PyDict_SetItemString(d, "BAD_NO_PORTS", x) < 0)
  2169.         goto error;
  2170.     Py_DECREF(x);
  2171. #endif
  2172. #ifdef AL_BAD_NOT_FOUND
  2173.     x =  PyInt_FromLong((long) AL_BAD_NOT_FOUND);
  2174.     if (x == NULL || PyDict_SetItemString(d, "BAD_NOT_FOUND", x) < 0)
  2175.         goto error;
  2176.     Py_DECREF(x);
  2177. #endif
  2178. #ifdef AL_BAD_NOT_IMPLEMENTED
  2179.     x =  PyInt_FromLong((long) AL_BAD_NOT_IMPLEMENTED);
  2180.     if (x == NULL || PyDict_SetItemString(d, "BAD_NOT_IMPLEMENTED", x) < 0)
  2181.         goto error;
  2182.     Py_DECREF(x);
  2183. #endif
  2184. #ifdef AL_BAD_OUT_OF_MEM
  2185.     x =  PyInt_FromLong((long) AL_BAD_OUT_OF_MEM);
  2186.     if (x == NULL || PyDict_SetItemString(d, "BAD_OUT_OF_MEM", x) < 0)
  2187.         goto error;
  2188.     Py_DECREF(x);
  2189. #endif
  2190. #ifdef AL_BAD_PARAM
  2191.     x =  PyInt_FromLong((long) AL_BAD_PARAM);
  2192.     if (x == NULL || PyDict_SetItemString(d, "BAD_PARAM", x) < 0)
  2193.         goto error;
  2194.     Py_DECREF(x);
  2195. #endif
  2196. #ifdef AL_BAD_PERMISSIONS
  2197.     x =  PyInt_FromLong((long) AL_BAD_PERMISSIONS);
  2198.     if (x == NULL || PyDict_SetItemString(d, "BAD_PERMISSIONS", x) < 0)
  2199.         goto error;
  2200.     Py_DECREF(x);
  2201. #endif
  2202. #ifdef AL_BAD_PORT
  2203.     x =  PyInt_FromLong((long) AL_BAD_PORT);
  2204.     if (x == NULL || PyDict_SetItemString(d, "BAD_PORT", x) < 0)
  2205.         goto error;
  2206.     Py_DECREF(x);
  2207. #endif
  2208. #ifdef AL_BAD_PORTSTYLE
  2209.     x =  PyInt_FromLong((long) AL_BAD_PORTSTYLE);
  2210.     if (x == NULL || PyDict_SetItemString(d, "BAD_PORTSTYLE", x) < 0)
  2211.         goto error;
  2212.     Py_DECREF(x);
  2213. #endif
  2214. #ifdef AL_BAD_PVBUFFER
  2215.     x =  PyInt_FromLong((long) AL_BAD_PVBUFFER);
  2216.     if (x == NULL || PyDict_SetItemString(d, "BAD_PVBUFFER", x) < 0)
  2217.         goto error;
  2218.     Py_DECREF(x);
  2219. #endif
  2220. #ifdef AL_BAD_QSIZE
  2221.     x =  PyInt_FromLong((long) AL_BAD_QSIZE);
  2222.     if (x == NULL || PyDict_SetItemString(d, "BAD_QSIZE", x) < 0)
  2223.         goto error;
  2224.     Py_DECREF(x);
  2225. #endif
  2226. #ifdef AL_BAD_RATE
  2227.     x =  PyInt_FromLong((long) AL_BAD_RATE);
  2228.     if (x == NULL || PyDict_SetItemString(d, "BAD_RATE", x) < 0)
  2229.         goto error;
  2230.     Py_DECREF(x);
  2231. #endif
  2232. #ifdef AL_BAD_RESOURCE
  2233.     x =  PyInt_FromLong((long) AL_BAD_RESOURCE);
  2234.     if (x == NULL || PyDict_SetItemString(d, "BAD_RESOURCE", x) < 0)
  2235.         goto error;
  2236.     Py_DECREF(x);
  2237. #endif
  2238. #ifdef AL_BAD_SAMPFMT
  2239.     x =  PyInt_FromLong((long) AL_BAD_SAMPFMT);
  2240.     if (x == NULL || PyDict_SetItemString(d, "BAD_SAMPFMT", x) < 0)
  2241.         goto error;
  2242.     Py_DECREF(x);
  2243. #endif
  2244. #ifdef AL_BAD_TRANSFER_SIZE
  2245.     x =  PyInt_FromLong((long) AL_BAD_TRANSFER_SIZE);
  2246.     if (x == NULL || PyDict_SetItemString(d, "BAD_TRANSFER_SIZE", x) < 0)
  2247.         goto error;
  2248.     Py_DECREF(x);
  2249. #endif
  2250. #ifdef AL_BAD_WIDTH
  2251.     x =  PyInt_FromLong((long) AL_BAD_WIDTH);
  2252.     if (x == NULL || PyDict_SetItemString(d, "BAD_WIDTH", x) < 0)
  2253.         goto error;
  2254.     Py_DECREF(x);
  2255. #endif
  2256. #ifdef AL_CHANNEL_MODE
  2257.     x =  PyInt_FromLong((long) AL_CHANNEL_MODE);
  2258.     if (x == NULL || PyDict_SetItemString(d, "CHANNEL_MODE", x) < 0)
  2259.         goto error;
  2260.     Py_DECREF(x);
  2261. #endif
  2262. #ifdef AL_CHANNELS
  2263.     x =  PyInt_FromLong((long) AL_CHANNELS);
  2264.     if (x == NULL || PyDict_SetItemString(d, "CHANNELS", x) < 0)
  2265.         goto error;
  2266.     Py_DECREF(x);
  2267. #endif
  2268. #ifdef AL_CHAR_ELEM
  2269.     x =  PyInt_FromLong((long) AL_CHAR_ELEM);
  2270.     if (x == NULL || PyDict_SetItemString(d, "CHAR_ELEM", x) < 0)
  2271.         goto error;
  2272.     Py_DECREF(x);
  2273. #endif
  2274. #ifdef AL_CLOCK_GEN
  2275.     x =  PyInt_FromLong((long) AL_CLOCK_GEN);
  2276.     if (x == NULL || PyDict_SetItemString(d, "CLOCK_GEN", x) < 0)
  2277.         goto error;
  2278.     Py_DECREF(x);
  2279. #endif
  2280. #ifdef AL_CLOCKGEN_TYPE
  2281.     x =  PyInt_FromLong((long) AL_CLOCKGEN_TYPE);
  2282.     if (x == NULL || PyDict_SetItemString(d, "CLOCKGEN_TYPE", x) < 0)
  2283.         goto error;
  2284.     Py_DECREF(x);
  2285. #endif
  2286. #ifdef AL_CONNECT
  2287.     x =  PyInt_FromLong((long) AL_CONNECT);
  2288.     if (x == NULL || PyDict_SetItemString(d, "CONNECT", x) < 0)
  2289.         goto error;
  2290.     Py_DECREF(x);
  2291. #endif
  2292. #ifdef AL_CONNECTION_TYPE
  2293.     x =  PyInt_FromLong((long) AL_CONNECTION_TYPE);
  2294.     if (x == NULL || PyDict_SetItemString(d, "CONNECTION_TYPE", x) < 0)
  2295.         goto error;
  2296.     Py_DECREF(x);
  2297. #endif
  2298. #ifdef AL_CONNECTIONS
  2299.     x =  PyInt_FromLong((long) AL_CONNECTIONS);
  2300.     if (x == NULL || PyDict_SetItemString(d, "CONNECTIONS", x) < 0)
  2301.         goto error;
  2302.     Py_DECREF(x);
  2303. #endif
  2304. #ifdef AL_CRYSTAL_MCLK_TYPE
  2305.     x =  PyInt_FromLong((long) AL_CRYSTAL_MCLK_TYPE);
  2306.     if (x == NULL || PyDict_SetItemString(d, "CRYSTAL_MCLK_TYPE", x) < 0)
  2307.         goto error;
  2308.     Py_DECREF(x);
  2309. #endif
  2310. #ifdef AL_DEFAULT_DEVICE
  2311.     x =  PyInt_FromLong((long) AL_DEFAULT_DEVICE);
  2312.     if (x == NULL || PyDict_SetItemString(d, "DEFAULT_DEVICE", x) < 0)
  2313.         goto error;
  2314.     Py_DECREF(x);
  2315. #endif
  2316. #ifdef AL_DEFAULT_INPUT
  2317.     x =  PyInt_FromLong((long) AL_DEFAULT_INPUT);
  2318.     if (x == NULL || PyDict_SetItemString(d, "DEFAULT_INPUT", x) < 0)
  2319.         goto error;
  2320.     Py_DECREF(x);
  2321. #endif
  2322. #ifdef AL_DEFAULT_OUTPUT
  2323.     x =  PyInt_FromLong((long) AL_DEFAULT_OUTPUT);
  2324.     if (x == NULL || PyDict_SetItemString(d, "DEFAULT_OUTPUT", x) < 0)
  2325.         goto error;
  2326.     Py_DECREF(x);
  2327. #endif
  2328. #ifdef AL_DEST
  2329.     x =  PyInt_FromLong((long) AL_DEST);
  2330.     if (x == NULL || PyDict_SetItemString(d, "DEST", x) < 0)
  2331.         goto error;
  2332.     Py_DECREF(x);
  2333. #endif
  2334. #ifdef AL_DEVICE_TYPE
  2335.     x =  PyInt_FromLong((long) AL_DEVICE_TYPE);
  2336.     if (x == NULL || PyDict_SetItemString(d, "DEVICE_TYPE", x) < 0)
  2337.         goto error;
  2338.     Py_DECREF(x);
  2339. #endif
  2340. #ifdef AL_DEVICES
  2341.     x =  PyInt_FromLong((long) AL_DEVICES);
  2342.     if (x == NULL || PyDict_SetItemString(d, "DEVICES", x) < 0)
  2343.         goto error;
  2344.     Py_DECREF(x);
  2345. #endif
  2346. #ifdef AL_DIGITAL_IF_TYPE
  2347.     x =  PyInt_FromLong((long) AL_DIGITAL_IF_TYPE);
  2348.     if (x == NULL || PyDict_SetItemString(d, "DIGITAL_IF_TYPE", x) < 0)
  2349.         goto error;
  2350.     Py_DECREF(x);
  2351. #endif
  2352. #ifdef AL_DIGITAL_INPUT_RATE
  2353.     x =  PyInt_FromLong((long) AL_DIGITAL_INPUT_RATE);
  2354.     if (x == NULL || PyDict_SetItemString(d, "DIGITAL_INPUT_RATE", x) < 0)
  2355.         goto error;
  2356.     Py_DECREF(x);
  2357. #endif
  2358. #ifdef AL_DISCONNECT
  2359.     x =  PyInt_FromLong((long) AL_DISCONNECT);
  2360.     if (x == NULL || PyDict_SetItemString(d, "DISCONNECT", x) < 0)
  2361.         goto error;
  2362.     Py_DECREF(x);
  2363. #endif
  2364. #ifdef AL_ENUM_ELEM
  2365.     x =  PyInt_FromLong((long) AL_ENUM_ELEM);
  2366.     if (x == NULL || PyDict_SetItemString(d, "ENUM_ELEM", x) < 0)
  2367.         goto error;
  2368.     Py_DECREF(x);
  2369. #endif
  2370. #ifdef AL_ENUM_VALUE
  2371.     x =  PyInt_FromLong((long) AL_ENUM_VALUE);
  2372.     if (x == NULL || PyDict_SetItemString(d, "ENUM_VALUE", x) < 0)
  2373.         goto error;
  2374.     Py_DECREF(x);
  2375. #endif
  2376. #ifdef AL_ERROR_INPUT_OVERFLOW
  2377.     x =  PyInt_FromLong((long) AL_ERROR_INPUT_OVERFLOW);
  2378.     if (x == NULL || PyDict_SetItemString(d, "ERROR_INPUT_OVERFLOW", x) < 0)
  2379.         goto error;
  2380.     Py_DECREF(x);
  2381. #endif
  2382. #ifdef AL_ERROR_LENGTH
  2383.     x =  PyInt_FromLong((long) AL_ERROR_LENGTH);
  2384.     if (x == NULL || PyDict_SetItemString(d, "ERROR_LENGTH", x) < 0)
  2385.         goto error;
  2386.     Py_DECREF(x);
  2387. #endif
  2388. #ifdef AL_ERROR_LOCATION_LSP
  2389.     x =  PyInt_FromLong((long) AL_ERROR_LOCATION_LSP);
  2390.     if (x == NULL || PyDict_SetItemString(d, "ERROR_LOCATION_LSP", x) < 0)
  2391.         goto error;
  2392.     Py_DECREF(x);
  2393. #endif
  2394. #ifdef AL_ERROR_LOCATION_MSP
  2395.     x =  PyInt_FromLong((long) AL_ERROR_LOCATION_MSP);
  2396.     if (x == NULL || PyDict_SetItemString(d, "ERROR_LOCATION_MSP", x) < 0)
  2397.         goto error;
  2398.     Py_DECREF(x);
  2399. #endif
  2400. #ifdef AL_ERROR_NUMBER
  2401.     x =  PyInt_FromLong((long) AL_ERROR_NUMBER);
  2402.     if (x == NULL || PyDict_SetItemString(d, "ERROR_NUMBER", x) < 0)
  2403.         goto error;
  2404.     Py_DECREF(x);
  2405. #endif
  2406. #ifdef AL_ERROR_OUTPUT_UNDERFLOW
  2407.     x =  PyInt_FromLong((long) AL_ERROR_OUTPUT_UNDERFLOW);
  2408.     if (x == NULL || PyDict_SetItemString(d, "ERROR_OUTPUT_UNDERFLOW", x) < 0)
  2409.         goto error;
  2410.     Py_DECREF(x);
  2411. #endif
  2412. #ifdef AL_ERROR_TYPE
  2413.     x =  PyInt_FromLong((long) AL_ERROR_TYPE);
  2414.     if (x == NULL || PyDict_SetItemString(d, "ERROR_TYPE", x) < 0)
  2415.         goto error;
  2416.     Py_DECREF(x);
  2417. #endif
  2418. #ifdef AL_FIXED_ELEM
  2419.     x =  PyInt_FromLong((long) AL_FIXED_ELEM);
  2420.     if (x == NULL || PyDict_SetItemString(d, "FIXED_ELEM", x) < 0)
  2421.         goto error;
  2422.     Py_DECREF(x);
  2423. #endif
  2424. #ifdef AL_FIXED_MCLK_TYPE
  2425.     x =  PyInt_FromLong((long) AL_FIXED_MCLK_TYPE);
  2426.     if (x == NULL || PyDict_SetItemString(d, "FIXED_MCLK_TYPE", x) < 0)
  2427.         goto error;
  2428.     Py_DECREF(x);
  2429. #endif
  2430. #ifdef AL_GAIN
  2431.     x =  PyInt_FromLong((long) AL_GAIN);
  2432.     if (x == NULL || PyDict_SetItemString(d, "GAIN", x) < 0)
  2433.         goto error;
  2434.     Py_DECREF(x);
  2435. #endif
  2436. #ifdef AL_GAIN_REF
  2437.     x =  PyInt_FromLong((long) AL_GAIN_REF);
  2438.     if (x == NULL || PyDict_SetItemString(d, "GAIN_REF", x) < 0)
  2439.         goto error;
  2440.     Py_DECREF(x);
  2441. #endif
  2442. #ifdef AL_HRB_TYPE
  2443.     x =  PyInt_FromLong((long) AL_HRB_TYPE);
  2444.     if (x == NULL || PyDict_SetItemString(d, "HRB_TYPE", x) < 0)
  2445.         goto error;
  2446.     Py_DECREF(x);
  2447. #endif
  2448. #ifdef AL_INPUT_COUNT
  2449.     x =  PyInt_FromLong((long) AL_INPUT_COUNT);
  2450.     if (x == NULL || PyDict_SetItemString(d, "INPUT_COUNT", x) < 0)
  2451.         goto error;
  2452.     Py_DECREF(x);
  2453. #endif
  2454. #ifdef AL_INPUT_DEVICE_TYPE
  2455.     x =  PyInt_FromLong((long) AL_INPUT_DEVICE_TYPE);
  2456.     if (x == NULL || PyDict_SetItemString(d, "INPUT_DEVICE_TYPE", x) < 0)
  2457.         goto error;
  2458.     Py_DECREF(x);
  2459. #endif
  2460. #ifdef AL_INPUT_DIGITAL
  2461.     x =  PyInt_FromLong((long) AL_INPUT_DIGITAL);
  2462.     if (x == NULL || PyDict_SetItemString(d, "INPUT_DIGITAL", x) < 0)
  2463.         goto error;
  2464.     Py_DECREF(x);
  2465. #endif
  2466. #ifdef AL_INPUT_HRB_TYPE
  2467.     x =  PyInt_FromLong((long) AL_INPUT_HRB_TYPE);
  2468.     if (x == NULL || PyDict_SetItemString(d, "INPUT_HRB_TYPE", x) < 0)
  2469.         goto error;
  2470.     Py_DECREF(x);
  2471. #endif
  2472. #ifdef AL_INPUT_LINE
  2473.     x =  PyInt_FromLong((long) AL_INPUT_LINE);
  2474.     if (x == NULL || PyDict_SetItemString(d, "INPUT_LINE", x) < 0)
  2475.         goto error;
  2476.     Py_DECREF(x);
  2477. #endif
  2478. #ifdef AL_INPUT_MIC
  2479.     x =  PyInt_FromLong((long) AL_INPUT_MIC);
  2480.     if (x == NULL || PyDict_SetItemString(d, "INPUT_MIC", x) < 0)
  2481.         goto error;
  2482.     Py_DECREF(x);
  2483. #endif
  2484. #ifdef AL_INPUT_PORT_TYPE
  2485.     x =  PyInt_FromLong((long) AL_INPUT_PORT_TYPE);
  2486.     if (x == NULL || PyDict_SetItemString(d, "INPUT_PORT_TYPE", x) < 0)
  2487.         goto error;
  2488.     Py_DECREF(x);
  2489. #endif
  2490. #ifdef AL_INPUT_RATE
  2491.     x =  PyInt_FromLong((long) AL_INPUT_RATE);
  2492.     if (x == NULL || PyDict_SetItemString(d, "INPUT_RATE", x) < 0)
  2493.         goto error;
  2494.     Py_DECREF(x);
  2495. #endif
  2496. #ifdef AL_INPUT_SOURCE
  2497.     x =  PyInt_FromLong((long) AL_INPUT_SOURCE);
  2498.     if (x == NULL || PyDict_SetItemString(d, "INPUT_SOURCE", x) < 0)
  2499.         goto error;
  2500.     Py_DECREF(x);
  2501. #endif
  2502. #ifdef AL_INT32_ELEM
  2503.     x =  PyInt_FromLong((long) AL_INT32_ELEM);
  2504.     if (x == NULL || PyDict_SetItemString(d, "INT32_ELEM", x) < 0)
  2505.         goto error;
  2506.     Py_DECREF(x);
  2507. #endif
  2508. #ifdef AL_INT64_ELEM
  2509.     x =  PyInt_FromLong((long) AL_INT64_ELEM);
  2510.     if (x == NULL || PyDict_SetItemString(d, "INT64_ELEM", x) < 0)
  2511.         goto error;
  2512.     Py_DECREF(x);
  2513. #endif
  2514. #ifdef AL_INTERFACE
  2515.     x =  PyInt_FromLong((long) AL_INTERFACE);
  2516.     if (x == NULL || PyDict_SetItemString(d, "INTERFACE", x) < 0)
  2517.         goto error;
  2518.     Py_DECREF(x);
  2519. #endif
  2520. #ifdef AL_INTERFACE_TYPE
  2521.     x =  PyInt_FromLong((long) AL_INTERFACE_TYPE);
  2522.     if (x == NULL || PyDict_SetItemString(d, "INTERFACE_TYPE", x) < 0)
  2523.         goto error;
  2524.     Py_DECREF(x);
  2525. #endif
  2526. #ifdef AL_INVALID_PARAM
  2527.     x =  PyInt_FromLong((long) AL_INVALID_PARAM);
  2528.     if (x == NULL || PyDict_SetItemString(d, "INVALID_PARAM", x) < 0)
  2529.         goto error;
  2530.     Py_DECREF(x);
  2531. #endif
  2532. #ifdef AL_INVALID_VALUE
  2533.     x =  PyInt_FromLong((long) AL_INVALID_VALUE);
  2534.     if (x == NULL || PyDict_SetItemString(d, "INVALID_VALUE", x) < 0)
  2535.         goto error;
  2536.     Py_DECREF(x);
  2537. #endif
  2538. #ifdef AL_JITTER
  2539.     x =  PyInt_FromLong((long) AL_JITTER);
  2540.     if (x == NULL || PyDict_SetItemString(d, "JITTER", x) < 0)
  2541.         goto error;
  2542.     Py_DECREF(x);
  2543. #endif
  2544. #ifdef AL_LABEL
  2545.     x =  PyInt_FromLong((long) AL_LABEL);
  2546.     if (x == NULL || PyDict_SetItemString(d, "LABEL", x) < 0)
  2547.         goto error;
  2548.     Py_DECREF(x);
  2549. #endif
  2550. #ifdef AL_LEFT_INPUT_ATTEN
  2551.     x =  PyInt_FromLong((long) AL_LEFT_INPUT_ATTEN);
  2552.     if (x == NULL || PyDict_SetItemString(d, "LEFT_INPUT_ATTEN", x) < 0)
  2553.         goto error;
  2554.     Py_DECREF(x);
  2555. #endif
  2556. #ifdef AL_LEFT_MONITOR_ATTEN
  2557.     x =  PyInt_FromLong((long) AL_LEFT_MONITOR_ATTEN);
  2558.     if (x == NULL || PyDict_SetItemString(d, "LEFT_MONITOR_ATTEN", x) < 0)
  2559.         goto error;
  2560.     Py_DECREF(x);
  2561. #endif
  2562. #ifdef AL_LEFT_SPEAKER_GAIN
  2563.     x =  PyInt_FromLong((long) AL_LEFT_SPEAKER_GAIN);
  2564.     if (x == NULL || PyDict_SetItemString(d, "LEFT_SPEAKER_GAIN", x) < 0)
  2565.         goto error;
  2566.     Py_DECREF(x);
  2567. #endif
  2568. #ifdef AL_LEFT1_INPUT_ATTEN
  2569.     x =  PyInt_FromLong((long) AL_LEFT1_INPUT_ATTEN);
  2570.     if (x == NULL || PyDict_SetItemString(d, "LEFT1_INPUT_ATTEN", x) < 0)
  2571.         goto error;
  2572.     Py_DECREF(x);
  2573. #endif
  2574. #ifdef AL_LEFT2_INPUT_ATTEN
  2575.     x =  PyInt_FromLong((long) AL_LEFT2_INPUT_ATTEN);
  2576.     if (x == NULL || PyDict_SetItemString(d, "LEFT2_INPUT_ATTEN", x) < 0)
  2577.         goto error;
  2578.     Py_DECREF(x);
  2579. #endif
  2580. #ifdef AL_LINE_IF_TYPE
  2581.     x =  PyInt_FromLong((long) AL_LINE_IF_TYPE);
  2582.     if (x == NULL || PyDict_SetItemString(d, "LINE_IF_TYPE", x) < 0)
  2583.         goto error;
  2584.     Py_DECREF(x);
  2585. #endif
  2586. #ifdef AL_MASTER_CLOCK
  2587.     x =  PyInt_FromLong((long) AL_MASTER_CLOCK);
  2588.     if (x == NULL || PyDict_SetItemString(d, "MASTER_CLOCK", x) < 0)
  2589.         goto error;
  2590.     Py_DECREF(x);
  2591. #endif
  2592. #ifdef AL_MATRIX_VAL
  2593.     x =  PyInt_FromLong((long) AL_MATRIX_VAL);
  2594.     if (x == NULL || PyDict_SetItemString(d, "MATRIX_VAL", x) < 0)
  2595.         goto error;
  2596.     Py_DECREF(x);
  2597. #endif
  2598. #ifdef AL_MAX_ERROR
  2599.     x =  PyInt_FromLong((long) AL_MAX_ERROR);
  2600.     if (x == NULL || PyDict_SetItemString(d, "MAX_ERROR", x) < 0)
  2601.         goto error;
  2602.     Py_DECREF(x);
  2603. #endif
  2604. #ifdef AL_MAX_EVENT_PARAM
  2605.     x =  PyInt_FromLong((long) AL_MAX_EVENT_PARAM);
  2606.     if (x == NULL || PyDict_SetItemString(d, "MAX_EVENT_PARAM", x) < 0)
  2607.         goto error;
  2608.     Py_DECREF(x);
  2609. #endif
  2610. #ifdef AL_MAX_PBUFSIZE
  2611.     x =  PyInt_FromLong((long) AL_MAX_PBUFSIZE);
  2612.     if (x == NULL || PyDict_SetItemString(d, "MAX_PBUFSIZE", x) < 0)
  2613.         goto error;
  2614.     Py_DECREF(x);
  2615. #endif
  2616. #ifdef AL_MAX_PORTS
  2617.     x =  PyInt_FromLong((long) AL_MAX_PORTS);
  2618.     if (x == NULL || PyDict_SetItemString(d, "MAX_PORTS", x) < 0)
  2619.         goto error;
  2620.     Py_DECREF(x);
  2621. #endif
  2622. #ifdef AL_MAX_RESOURCE_ID
  2623.     x =  PyInt_FromLong((long) AL_MAX_RESOURCE_ID);
  2624.     if (x == NULL || PyDict_SetItemString(d, "MAX_RESOURCE_ID", x) < 0)
  2625.         goto error;
  2626.     Py_DECREF(x);
  2627. #endif
  2628. #ifdef AL_MAX_SETSIZE
  2629.     x =  PyInt_FromLong((long) AL_MAX_SETSIZE);
  2630.     if (x == NULL || PyDict_SetItemString(d, "MAX_SETSIZE", x) < 0)
  2631.         goto error;
  2632.     Py_DECREF(x);
  2633. #endif
  2634. #ifdef AL_MAX_STRLEN
  2635.     x =  PyInt_FromLong((long) AL_MAX_STRLEN);
  2636.     if (x == NULL || PyDict_SetItemString(d, "MAX_STRLEN", x) < 0)
  2637.         goto error;
  2638.     Py_DECREF(x);
  2639. #endif
  2640. #ifdef AL_MCLK_TYPE
  2641.     x =  PyInt_FromLong((long) AL_MCLK_TYPE);
  2642.     if (x == NULL || PyDict_SetItemString(d, "MCLK_TYPE", x) < 0)
  2643.         goto error;
  2644.     Py_DECREF(x);
  2645. #endif
  2646. #ifdef AL_MIC_IF_TYPE
  2647.     x =  PyInt_FromLong((long) AL_MIC_IF_TYPE);
  2648.     if (x == NULL || PyDict_SetItemString(d, "MIC_IF_TYPE", x) < 0)
  2649.         goto error;
  2650.     Py_DECREF(x);
  2651. #endif
  2652. #ifdef AL_MONITOR_CTL
  2653.     x =  PyInt_FromLong((long) AL_MONITOR_CTL);
  2654.     if (x == NULL || PyDict_SetItemString(d, "MONITOR_CTL", x) < 0)
  2655.         goto error;
  2656.     Py_DECREF(x);
  2657. #endif
  2658. #ifdef AL_MONITOR_OFF
  2659.     x =  PyInt_FromLong((long) AL_MONITOR_OFF);
  2660.     if (x == NULL || PyDict_SetItemString(d, "MONITOR_OFF", x) < 0)
  2661.         goto error;
  2662.     Py_DECREF(x);
  2663. #endif
  2664. #ifdef AL_MONITOR_ON
  2665.     x =  PyInt_FromLong((long) AL_MONITOR_ON);
  2666.     if (x == NULL || PyDict_SetItemString(d, "MONITOR_ON", x) < 0)
  2667.         goto error;
  2668.     Py_DECREF(x);
  2669. #endif
  2670. #ifdef AL_MONO
  2671.     x =  PyInt_FromLong((long) AL_MONO);
  2672.     if (x == NULL || PyDict_SetItemString(d, "MONO", x) < 0)
  2673.         goto error;
  2674.     Py_DECREF(x);
  2675. #endif
  2676. #ifdef AL_MUTE
  2677.     x =  PyInt_FromLong((long) AL_MUTE);
  2678.     if (x == NULL || PyDict_SetItemString(d, "MUTE", x) < 0)
  2679.         goto error;
  2680.     Py_DECREF(x);
  2681. #endif
  2682. #ifdef AL_NAME
  2683.     x =  PyInt_FromLong((long) AL_NAME);
  2684.     if (x == NULL || PyDict_SetItemString(d, "NAME", x) < 0)
  2685.         goto error;
  2686.     Py_DECREF(x);
  2687. #endif
  2688. #ifdef AL_NEG_INFINITY
  2689.     x =  PyInt_FromLong((long) AL_NEG_INFINITY);
  2690.     if (x == NULL || PyDict_SetItemString(d, "NEG_INFINITY", x) < 0)
  2691.         goto error;
  2692.     Py_DECREF(x);
  2693. #endif
  2694. #ifdef AL_NEG_INFINITY_BIT
  2695.     x =  PyInt_FromLong((long) AL_NEG_INFINITY_BIT);
  2696.     if (x == NULL || PyDict_SetItemString(d, "NEG_INFINITY_BIT", x) < 0)
  2697.         goto error;
  2698.     Py_DECREF(x);
  2699. #endif
  2700. #ifdef AL_NO_CHANGE
  2701.     x =  PyInt_FromLong((long) AL_NO_CHANGE);
  2702.     if (x == NULL || PyDict_SetItemString(d, "NO_CHANGE", x) < 0)
  2703.         goto error;
  2704.     Py_DECREF(x);
  2705. #endif
  2706. #ifdef AL_NO_CHANGE_BIT
  2707.     x =  PyInt_FromLong((long) AL_NO_CHANGE_BIT);
  2708.     if (x == NULL || PyDict_SetItemString(d, "NO_CHANGE_BIT", x) < 0)
  2709.         goto error;
  2710.     Py_DECREF(x);
  2711. #endif
  2712. #ifdef AL_NO_ELEM
  2713.     x =  PyInt_FromLong((long) AL_NO_ELEM);
  2714.     if (x == NULL || PyDict_SetItemString(d, "NO_ELEM", x) < 0)
  2715.         goto error;
  2716.     Py_DECREF(x);
  2717. #endif
  2718. #ifdef AL_NO_ERRORS
  2719.     x =  PyInt_FromLong((long) AL_NO_ERRORS);
  2720.     if (x == NULL || PyDict_SetItemString(d, "NO_ERRORS", x) < 0)
  2721.         goto error;
  2722.     Py_DECREF(x);
  2723. #endif
  2724. #ifdef AL_NO_OP
  2725.     x =  PyInt_FromLong((long) AL_NO_OP);
  2726.     if (x == NULL || PyDict_SetItemString(d, "NO_OP", x) < 0)
  2727.         goto error;
  2728.     Py_DECREF(x);
  2729. #endif
  2730. #ifdef AL_NO_VAL
  2731.     x =  PyInt_FromLong((long) AL_NO_VAL);
  2732.     if (x == NULL || PyDict_SetItemString(d, "NO_VAL", x) < 0)
  2733.         goto error;
  2734.     Py_DECREF(x);
  2735. #endif
  2736. #ifdef AL_NULL_RESOURCE
  2737.     x =  PyInt_FromLong((long) AL_NULL_RESOURCE);
  2738.     if (x == NULL || PyDict_SetItemString(d, "NULL_RESOURCE", x) < 0)
  2739.         goto error;
  2740.     Py_DECREF(x);
  2741. #endif
  2742. #ifdef AL_OUTPUT_COUNT
  2743.     x =  PyInt_FromLong((long) AL_OUTPUT_COUNT);
  2744.     if (x == NULL || PyDict_SetItemString(d, "OUTPUT_COUNT", x) < 0)
  2745.         goto error;
  2746.     Py_DECREF(x);
  2747. #endif
  2748. #ifdef AL_OUTPUT_DEVICE_TYPE
  2749.     x =  PyInt_FromLong((long) AL_OUTPUT_DEVICE_TYPE);
  2750.     if (x == NULL || PyDict_SetItemString(d, "OUTPUT_DEVICE_TYPE", x) < 0)
  2751.         goto error;
  2752.     Py_DECREF(x);
  2753. #endif
  2754. #ifdef AL_OUTPUT_HRB_TYPE
  2755.     x =  PyInt_FromLong((long) AL_OUTPUT_HRB_TYPE);
  2756.     if (x == NULL || PyDict_SetItemString(d, "OUTPUT_HRB_TYPE", x) < 0)
  2757.         goto error;
  2758.     Py_DECREF(x);
  2759. #endif
  2760. #ifdef AL_OUTPUT_PORT_TYPE
  2761.     x =  PyInt_FromLong((long) AL_OUTPUT_PORT_TYPE);
  2762.     if (x == NULL || PyDict_SetItemString(d, "OUTPUT_PORT_TYPE", x) < 0)
  2763.         goto error;
  2764.     Py_DECREF(x);
  2765. #endif
  2766. #ifdef AL_OUTPUT_RATE
  2767.     x =  PyInt_FromLong((long) AL_OUTPUT_RATE);
  2768.     if (x == NULL || PyDict_SetItemString(d, "OUTPUT_RATE", x) < 0)
  2769.         goto error;
  2770.     Py_DECREF(x);
  2771. #endif
  2772. #ifdef AL_PARAM_BIT
  2773.     x =  PyInt_FromLong((long) AL_PARAM_BIT);
  2774.     if (x == NULL || PyDict_SetItemString(d, "PARAM_BIT", x) < 0)
  2775.         goto error;
  2776.     Py_DECREF(x);
  2777. #endif
  2778. #ifdef AL_PARAMS
  2779.     x =  PyInt_FromLong((long) AL_PARAMS);
  2780.     if (x == NULL || PyDict_SetItemString(d, "PARAMS", x) < 0)
  2781.         goto error;
  2782.     Py_DECREF(x);
  2783. #endif
  2784. #ifdef AL_PORT_COUNT
  2785.     x =  PyInt_FromLong((long) AL_PORT_COUNT);
  2786.     if (x == NULL || PyDict_SetItemString(d, "PORT_COUNT", x) < 0)
  2787.         goto error;
  2788.     Py_DECREF(x);
  2789. #endif
  2790. #ifdef AL_PORT_TYPE
  2791.     x =  PyInt_FromLong((long) AL_PORT_TYPE);
  2792.     if (x == NULL || PyDict_SetItemString(d, "PORT_TYPE", x) < 0)
  2793.         goto error;
  2794.     Py_DECREF(x);
  2795. #endif
  2796. #ifdef AL_PORTS
  2797.     x =  PyInt_FromLong((long) AL_PORTS);
  2798.     if (x == NULL || PyDict_SetItemString(d, "PORTS", x) < 0)
  2799.         goto error;
  2800.     Py_DECREF(x);
  2801. #endif
  2802. #ifdef AL_PORTSTYLE_DIRECT
  2803.     x =  PyInt_FromLong((long) AL_PORTSTYLE_DIRECT);
  2804.     if (x == NULL || PyDict_SetItemString(d, "PORTSTYLE_DIRECT", x) < 0)
  2805.         goto error;
  2806.     Py_DECREF(x);
  2807. #endif
  2808. #ifdef AL_PORTSTYLE_SERIAL
  2809.     x =  PyInt_FromLong((long) AL_PORTSTYLE_SERIAL);
  2810.     if (x == NULL || PyDict_SetItemString(d, "PORTSTYLE_SERIAL", x) < 0)
  2811.         goto error;
  2812.     Py_DECREF(x);
  2813. #endif
  2814. #ifdef AL_PRINT_ERRORS
  2815.     x =  PyInt_FromLong((long) AL_PRINT_ERRORS);
  2816.     if (x == NULL || PyDict_SetItemString(d, "PRINT_ERRORS", x) < 0)
  2817.         goto error;
  2818.     Py_DECREF(x);
  2819. #endif
  2820. #ifdef AL_PTR_ELEM
  2821.     x =  PyInt_FromLong((long) AL_PTR_ELEM);
  2822.     if (x == NULL || PyDict_SetItemString(d, "PTR_ELEM", x) < 0)
  2823.         goto error;
  2824.     Py_DECREF(x);
  2825. #endif
  2826. #ifdef AL_RANGE_VALUE
  2827.     x =  PyInt_FromLong((long) AL_RANGE_VALUE);
  2828.     if (x == NULL || PyDict_SetItemString(d, "RANGE_VALUE", x) < 0)
  2829.         goto error;
  2830.     Py_DECREF(x);
  2831. #endif
  2832. #ifdef AL_RATE
  2833.     x =  PyInt_FromLong((long) AL_RATE);
  2834.     if (x == NULL || PyDict_SetItemString(d, "RATE", x) < 0)
  2835.         goto error;
  2836.     Py_DECREF(x);
  2837. #endif
  2838. #ifdef AL_RATE_11025
  2839.     x =  PyInt_FromLong((long) AL_RATE_11025);
  2840.     if (x == NULL || PyDict_SetItemString(d, "RATE_11025", x) < 0)
  2841.         goto error;
  2842.     Py_DECREF(x);
  2843. #endif
  2844. #ifdef AL_RATE_16000
  2845.     x =  PyInt_FromLong((long) AL_RATE_16000);
  2846.     if (x == NULL || PyDict_SetItemString(d, "RATE_16000", x) < 0)
  2847.         goto error;
  2848.     Py_DECREF(x);
  2849. #endif
  2850. #ifdef AL_RATE_22050
  2851.     x =  PyInt_FromLong((long) AL_RATE_22050);
  2852.     if (x == NULL || PyDict_SetItemString(d, "RATE_22050", x) < 0)
  2853.         goto error;
  2854.     Py_DECREF(x);
  2855. #endif
  2856. #ifdef AL_RATE_32000
  2857.     x =  PyInt_FromLong((long) AL_RATE_32000);
  2858.     if (x == NULL || PyDict_SetItemString(d, "RATE_32000", x) < 0)
  2859.         goto error;
  2860.     Py_DECREF(x);
  2861. #endif
  2862. #ifdef AL_RATE_44100
  2863.     x =  PyInt_FromLong((long) AL_RATE_44100);
  2864.     if (x == NULL || PyDict_SetItemString(d, "RATE_44100", x) < 0)
  2865.         goto error;
  2866.     Py_DECREF(x);
  2867. #endif
  2868. #ifdef AL_RATE_48000
  2869.     x =  PyInt_FromLong((long) AL_RATE_48000);
  2870.     if (x == NULL || PyDict_SetItemString(d, "RATE_48000", x) < 0)
  2871.         goto error;
  2872.     Py_DECREF(x);
  2873. #endif
  2874. #ifdef AL_RATE_8000
  2875.     x =  PyInt_FromLong((long) AL_RATE_8000);
  2876.     if (x == NULL || PyDict_SetItemString(d, "RATE_8000", x) < 0)
  2877.         goto error;
  2878.     Py_DECREF(x);
  2879. #endif
  2880. #ifdef AL_RATE_AES_1
  2881.     x =  PyInt_FromLong((long) AL_RATE_AES_1);
  2882.     if (x == NULL || PyDict_SetItemString(d, "RATE_AES_1", x) < 0)
  2883.         goto error;
  2884.     Py_DECREF(x);
  2885. #endif
  2886. #ifdef AL_RATE_AES_1s
  2887.     x =  PyInt_FromLong((long) AL_RATE_AES_1s);
  2888.     if (x == NULL || PyDict_SetItemString(d, "RATE_AES_1s", x) < 0)
  2889.         goto error;
  2890.     Py_DECREF(x);
  2891. #endif
  2892. #ifdef AL_RATE_AES_2
  2893.     x =  PyInt_FromLong((long) AL_RATE_AES_2);
  2894.     if (x == NULL || PyDict_SetItemString(d, "RATE_AES_2", x) < 0)
  2895.         goto error;
  2896.     Py_DECREF(x);
  2897. #endif
  2898. #ifdef AL_RATE_AES_3
  2899.     x =  PyInt_FromLong((long) AL_RATE_AES_3);
  2900.     if (x == NULL || PyDict_SetItemString(d, "RATE_AES_3", x) < 0)
  2901.         goto error;
  2902.     Py_DECREF(x);
  2903. #endif
  2904. #ifdef AL_RATE_AES_4
  2905.     x =  PyInt_FromLong((long) AL_RATE_AES_4);
  2906.     if (x == NULL || PyDict_SetItemString(d, "RATE_AES_4", x) < 0)
  2907.         goto error;
  2908.     Py_DECREF(x);
  2909. #endif
  2910. #ifdef AL_RATE_AES_6
  2911.     x =  PyInt_FromLong((long) AL_RATE_AES_6);
  2912.     if (x == NULL || PyDict_SetItemString(d, "RATE_AES_6", x) < 0)
  2913.         goto error;
  2914.     Py_DECREF(x);
  2915. #endif
  2916. #ifdef AL_RATE_FRACTION_D
  2917.     x =  PyInt_FromLong((long) AL_RATE_FRACTION_D);
  2918.     if (x == NULL || PyDict_SetItemString(d, "RATE_FRACTION_D", x) < 0)
  2919.         goto error;
  2920.     Py_DECREF(x);
  2921. #endif
  2922. #ifdef AL_RATE_FRACTION_N
  2923.     x =  PyInt_FromLong((long) AL_RATE_FRACTION_N);
  2924.     if (x == NULL || PyDict_SetItemString(d, "RATE_FRACTION_N", x) < 0)
  2925.         goto error;
  2926.     Py_DECREF(x);
  2927. #endif
  2928. #ifdef AL_RATE_INPUTRATE
  2929.     x =  PyInt_FromLong((long) AL_RATE_INPUTRATE);
  2930.     if (x == NULL || PyDict_SetItemString(d, "RATE_INPUTRATE", x) < 0)
  2931.         goto error;
  2932.     Py_DECREF(x);
  2933. #endif
  2934. #ifdef AL_RATE_NO_DIGITAL_INPUT
  2935.     x =  PyInt_FromLong((long) AL_RATE_NO_DIGITAL_INPUT);
  2936.     if (x == NULL || PyDict_SetItemString(d, "RATE_NO_DIGITAL_INPUT", x) < 0)
  2937.         goto error;
  2938.     Py_DECREF(x);
  2939. #endif
  2940. #ifdef AL_RATE_UNACQUIRED
  2941.     x =  PyInt_FromLong((long) AL_RATE_UNACQUIRED);
  2942.     if (x == NULL || PyDict_SetItemString(d, "RATE_UNACQUIRED", x) < 0)
  2943.         goto error;
  2944.     Py_DECREF(x);
  2945. #endif
  2946. #ifdef AL_RATE_UNDEFINED
  2947.     x =  PyInt_FromLong((long) AL_RATE_UNDEFINED);
  2948.     if (x == NULL || PyDict_SetItemString(d, "RATE_UNDEFINED", x) < 0)
  2949.         goto error;
  2950.     Py_DECREF(x);
  2951. #endif
  2952. #ifdef AL_REF_0DBV
  2953.     x =  PyInt_FromLong((long) AL_REF_0DBV);
  2954.     if (x == NULL || PyDict_SetItemString(d, "REF_0DBV", x) < 0)
  2955.         goto error;
  2956.     Py_DECREF(x);
  2957. #endif
  2958. #ifdef AL_REF_NONE
  2959.     x =  PyInt_FromLong((long) AL_REF_NONE);
  2960.     if (x == NULL || PyDict_SetItemString(d, "REF_NONE", x) < 0)
  2961.         goto error;
  2962.     Py_DECREF(x);
  2963. #endif
  2964. #ifdef AL_RESERVED1_TYPE
  2965.     x =  PyInt_FromLong((long) AL_RESERVED1_TYPE);
  2966.     if (x == NULL || PyDict_SetItemString(d, "RESERVED1_TYPE", x) < 0)
  2967.         goto error;
  2968.     Py_DECREF(x);
  2969. #endif
  2970. #ifdef AL_RESERVED2_TYPE
  2971.     x =  PyInt_FromLong((long) AL_RESERVED2_TYPE);
  2972.     if (x == NULL || PyDict_SetItemString(d, "RESERVED2_TYPE", x) < 0)
  2973.         goto error;
  2974.     Py_DECREF(x);
  2975. #endif
  2976. #ifdef AL_RESERVED3_TYPE
  2977.     x =  PyInt_FromLong((long) AL_RESERVED3_TYPE);
  2978.     if (x == NULL || PyDict_SetItemString(d, "RESERVED3_TYPE", x) < 0)
  2979.         goto error;
  2980.     Py_DECREF(x);
  2981. #endif
  2982. #ifdef AL_RESERVED4_TYPE
  2983.     x =  PyInt_FromLong((long) AL_RESERVED4_TYPE);
  2984.     if (x == NULL || PyDict_SetItemString(d, "RESERVED4_TYPE", x) < 0)
  2985.         goto error;
  2986.     Py_DECREF(x);
  2987. #endif
  2988. #ifdef AL_RESOURCE
  2989.     x =  PyInt_FromLong((long) AL_RESOURCE);
  2990.     if (x == NULL || PyDict_SetItemString(d, "RESOURCE", x) < 0)
  2991.         goto error;
  2992.     Py_DECREF(x);
  2993. #endif
  2994. #ifdef AL_RESOURCE_ELEM
  2995.     x =  PyInt_FromLong((long) AL_RESOURCE_ELEM);
  2996.     if (x == NULL || PyDict_SetItemString(d, "RESOURCE_ELEM", x) < 0)
  2997.         goto error;
  2998.     Py_DECREF(x);
  2999. #endif
  3000. #ifdef AL_RESOURCE_TYPE
  3001.     x =  PyInt_FromLong((long) AL_RESOURCE_TYPE);
  3002.     if (x == NULL || PyDict_SetItemString(d, "RESOURCE_TYPE", x) < 0)
  3003.         goto error;
  3004.     Py_DECREF(x);
  3005. #endif
  3006. #ifdef AL_RIGHT_INPUT_ATTEN
  3007.     x =  PyInt_FromLong((long) AL_RIGHT_INPUT_ATTEN);
  3008.     if (x == NULL || PyDict_SetItemString(d, "RIGHT_INPUT_ATTEN", x) < 0)
  3009.         goto error;
  3010.     Py_DECREF(x);
  3011. #endif
  3012. #ifdef AL_RIGHT_MONITOR_ATTEN
  3013.     x =  PyInt_FromLong((long) AL_RIGHT_MONITOR_ATTEN);
  3014.     if (x == NULL || PyDict_SetItemString(d, "RIGHT_MONITOR_ATTEN", x) < 0)
  3015.         goto error;
  3016.     Py_DECREF(x);
  3017. #endif
  3018. #ifdef AL_RIGHT_SPEAKER_GAIN
  3019.     x =  PyInt_FromLong((long) AL_RIGHT_SPEAKER_GAIN);
  3020.     if (x == NULL || PyDict_SetItemString(d, "RIGHT_SPEAKER_GAIN", x) < 0)
  3021.         goto error;
  3022.     Py_DECREF(x);
  3023. #endif
  3024. #ifdef AL_RIGHT1_INPUT_ATTEN
  3025.     x =  PyInt_FromLong((long) AL_RIGHT1_INPUT_ATTEN);
  3026.     if (x == NULL || PyDict_SetItemString(d, "RIGHT1_INPUT_ATTEN", x) < 0)
  3027.         goto error;
  3028.     Py_DECREF(x);
  3029. #endif
  3030. #ifdef AL_RIGHT2_INPUT_ATTEN
  3031.     x =  PyInt_FromLong((long) AL_RIGHT2_INPUT_ATTEN);
  3032.     if (x == NULL || PyDict_SetItemString(d, "RIGHT2_INPUT_ATTEN", x) < 0)
  3033.         goto error;
  3034.     Py_DECREF(x);
  3035. #endif
  3036. #ifdef AL_SAMPFMT_DOUBLE
  3037.     x =  PyInt_FromLong((long) AL_SAMPFMT_DOUBLE);
  3038.     if (x == NULL || PyDict_SetItemString(d, "SAMPFMT_DOUBLE", x) < 0)
  3039.         goto error;
  3040.     Py_DECREF(x);
  3041. #endif
  3042. #ifdef AL_SAMPFMT_FLOAT
  3043.     x =  PyInt_FromLong((long) AL_SAMPFMT_FLOAT);
  3044.     if (x == NULL || PyDict_SetItemString(d, "SAMPFMT_FLOAT", x) < 0)
  3045.         goto error;
  3046.     Py_DECREF(x);
  3047. #endif
  3048. #ifdef AL_SAMPFMT_TWOSCOMP
  3049.     x =  PyInt_FromLong((long) AL_SAMPFMT_TWOSCOMP);
  3050.     if (x == NULL || PyDict_SetItemString(d, "SAMPFMT_TWOSCOMP", x) < 0)
  3051.         goto error;
  3052.     Py_DECREF(x);
  3053. #endif
  3054. #ifdef AL_SAMPLE_16
  3055.     x =  PyInt_FromLong((long) AL_SAMPLE_16);
  3056.     if (x == NULL || PyDict_SetItemString(d, "SAMPLE_16", x) < 0)
  3057.         goto error;
  3058.     Py_DECREF(x);
  3059. #endif
  3060. #ifdef AL_SAMPLE_24
  3061.     x =  PyInt_FromLong((long) AL_SAMPLE_24);
  3062.     if (x == NULL || PyDict_SetItemString(d, "SAMPLE_24", x) < 0)
  3063.         goto error;
  3064.     Py_DECREF(x);
  3065. #endif
  3066. #ifdef AL_SAMPLE_8
  3067.     x =  PyInt_FromLong((long) AL_SAMPLE_8);
  3068.     if (x == NULL || PyDict_SetItemString(d, "SAMPLE_8", x) < 0)
  3069.         goto error;
  3070.     Py_DECREF(x);
  3071. #endif
  3072. #ifdef AL_SCALAR_VAL
  3073.     x =  PyInt_FromLong((long) AL_SCALAR_VAL);
  3074.     if (x == NULL || PyDict_SetItemString(d, "SCALAR_VAL", x) < 0)
  3075.         goto error;
  3076.     Py_DECREF(x);
  3077. #endif
  3078. #ifdef AL_SET_VAL
  3079.     x =  PyInt_FromLong((long) AL_SET_VAL);
  3080.     if (x == NULL || PyDict_SetItemString(d, "SET_VAL", x) < 0)
  3081.         goto error;
  3082.     Py_DECREF(x);
  3083. #endif
  3084. #ifdef AL_SHORT_NAME
  3085.     x =  PyInt_FromLong((long) AL_SHORT_NAME);
  3086.     if (x == NULL || PyDict_SetItemString(d, "SHORT_NAME", x) < 0)
  3087.         goto error;
  3088.     Py_DECREF(x);
  3089. #endif
  3090. #ifdef AL_SOURCE
  3091.     x =  PyInt_FromLong((long) AL_SOURCE);
  3092.     if (x == NULL || PyDict_SetItemString(d, "SOURCE", x) < 0)
  3093.         goto error;
  3094.     Py_DECREF(x);
  3095. #endif
  3096. #ifdef AL_SPEAKER_IF_TYPE
  3097.     x =  PyInt_FromLong((long) AL_SPEAKER_IF_TYPE);
  3098.     if (x == NULL || PyDict_SetItemString(d, "SPEAKER_IF_TYPE", x) < 0)
  3099.         goto error;
  3100.     Py_DECREF(x);
  3101. #endif
  3102. #ifdef AL_SPEAKER_MUTE_CTL
  3103.     x =  PyInt_FromLong((long) AL_SPEAKER_MUTE_CTL);
  3104.     if (x == NULL || PyDict_SetItemString(d, "SPEAKER_MUTE_CTL", x) < 0)
  3105.         goto error;
  3106.     Py_DECREF(x);
  3107. #endif
  3108. #ifdef AL_SPEAKER_MUTE_OFF
  3109.     x =  PyInt_FromLong((long) AL_SPEAKER_MUTE_OFF);
  3110.     if (x == NULL || PyDict_SetItemString(d, "SPEAKER_MUTE_OFF", x) < 0)
  3111.         goto error;
  3112.     Py_DECREF(x);
  3113. #endif
  3114. #ifdef AL_SPEAKER_MUTE_ON
  3115.     x =  PyInt_FromLong((long) AL_SPEAKER_MUTE_ON);
  3116.     if (x == NULL || PyDict_SetItemString(d, "SPEAKER_MUTE_ON", x) < 0)
  3117.         goto error;
  3118.     Py_DECREF(x);
  3119. #endif
  3120. #ifdef AL_SPEAKER_PLUS_LINE_IF_TYPE
  3121.     x =  PyInt_FromLong((long) AL_SPEAKER_PLUS_LINE_IF_TYPE);
  3122.     if (x == NULL || PyDict_SetItemString(d, "SPEAKER_PLUS_LINE_IF_TYPE", x) < 0)
  3123.         goto error;
  3124.     Py_DECREF(x);
  3125. #endif
  3126. #ifdef AL_STEREO
  3127.     x =  PyInt_FromLong((long) AL_STEREO);
  3128.     if (x == NULL || PyDict_SetItemString(d, "STEREO", x) < 0)
  3129.         goto error;
  3130.     Py_DECREF(x);
  3131. #endif
  3132. #ifdef AL_STRING_VAL
  3133.     x =  PyInt_FromLong((long) AL_STRING_VAL);
  3134.     if (x == NULL || PyDict_SetItemString(d, "STRING_VAL", x) < 0)
  3135.         goto error;
  3136.     Py_DECREF(x);
  3137. #endif
  3138. #ifdef AL_SUBSYSTEM
  3139.     x =  PyInt_FromLong((long) AL_SUBSYSTEM);
  3140.     if (x == NULL || PyDict_SetItemString(d, "SUBSYSTEM", x) < 0)
  3141.         goto error;
  3142.     Py_DECREF(x);
  3143. #endif
  3144. #ifdef AL_SUBSYSTEM_TYPE
  3145.     x =  PyInt_FromLong((long) AL_SUBSYSTEM_TYPE);
  3146.     if (x == NULL || PyDict_SetItemString(d, "SUBSYSTEM_TYPE", x) < 0)
  3147.         goto error;
  3148.     Py_DECREF(x);
  3149. #endif
  3150. #ifdef AL_SYNC_INPUT_TO_AES
  3151.     x =  PyInt_FromLong((long) AL_SYNC_INPUT_TO_AES);
  3152.     if (x == NULL || PyDict_SetItemString(d, "SYNC_INPUT_TO_AES", x) < 0)
  3153.         goto error;
  3154.     Py_DECREF(x);
  3155. #endif
  3156. #ifdef AL_SYNC_OUTPUT_TO_AES
  3157.     x =  PyInt_FromLong((long) AL_SYNC_OUTPUT_TO_AES);
  3158.     if (x == NULL || PyDict_SetItemString(d, "SYNC_OUTPUT_TO_AES", x) < 0)
  3159.         goto error;
  3160.     Py_DECREF(x);
  3161. #endif
  3162. #ifdef AL_SYSTEM
  3163.     x =  PyInt_FromLong((long) AL_SYSTEM);
  3164.     if (x == NULL || PyDict_SetItemString(d, "SYSTEM", x) < 0)
  3165.         goto error;
  3166.     Py_DECREF(x);
  3167. #endif
  3168. #ifdef AL_SYSTEM_TYPE
  3169.     x =  PyInt_FromLong((long) AL_SYSTEM_TYPE);
  3170.     if (x == NULL || PyDict_SetItemString(d, "SYSTEM_TYPE", x) < 0)
  3171.         goto error;
  3172.     Py_DECREF(x);
  3173. #endif
  3174. #ifdef AL_TEST_IF_TYPE
  3175.     x =  PyInt_FromLong((long) AL_TEST_IF_TYPE);
  3176.     if (x == NULL || PyDict_SetItemString(d, "TEST_IF_TYPE", x) < 0)
  3177.         goto error;
  3178.     Py_DECREF(x);
  3179. #endif
  3180. #ifdef AL_TYPE
  3181.     x =  PyInt_FromLong((long) AL_TYPE);
  3182.     if (x == NULL || PyDict_SetItemString(d, "TYPE", x) < 0)
  3183.         goto error;
  3184.     Py_DECREF(x);
  3185. #endif
  3186. #ifdef AL_TYPE_BIT
  3187.     x =  PyInt_FromLong((long) AL_TYPE_BIT);
  3188.     if (x == NULL || PyDict_SetItemString(d, "TYPE_BIT", x) < 0)
  3189.         goto error;
  3190.     Py_DECREF(x);
  3191. #endif
  3192. #ifdef AL_UNUSED_COUNT
  3193.     x =  PyInt_FromLong((long) AL_UNUSED_COUNT);
  3194.     if (x == NULL || PyDict_SetItemString(d, "UNUSED_COUNT", x) < 0)
  3195.         goto error;
  3196.     Py_DECREF(x);
  3197. #endif
  3198. #ifdef AL_UNUSED_PORTS
  3199.     x =  PyInt_FromLong((long) AL_UNUSED_PORTS);
  3200.     if (x == NULL || PyDict_SetItemString(d, "UNUSED_PORTS", x) < 0)
  3201.         goto error;
  3202.     Py_DECREF(x);
  3203. #endif
  3204. #ifdef AL_VARIABLE_MCLK_TYPE
  3205.     x =  PyInt_FromLong((long) AL_VARIABLE_MCLK_TYPE);
  3206.     if (x == NULL || PyDict_SetItemString(d, "VARIABLE_MCLK_TYPE", x) < 0)
  3207.         goto error;
  3208.     Py_DECREF(x);
  3209. #endif
  3210. #ifdef AL_VECTOR_VAL
  3211.     x =  PyInt_FromLong((long) AL_VECTOR_VAL);
  3212.     if (x == NULL || PyDict_SetItemString(d, "VECTOR_VAL", x) < 0)
  3213.         goto error;
  3214.     Py_DECREF(x);
  3215. #endif
  3216. #ifdef AL_VIDEO_MCLK_TYPE
  3217.     x =  PyInt_FromLong((long) AL_VIDEO_MCLK_TYPE);
  3218.     if (x == NULL || PyDict_SetItemString(d, "VIDEO_MCLK_TYPE", x) < 0)
  3219.         goto error;
  3220.     Py_DECREF(x);
  3221. #endif
  3222. #ifdef AL_WORDSIZE
  3223.     x =  PyInt_FromLong((long) AL_WORDSIZE);
  3224.     if (x == NULL || PyDict_SetItemString(d, "WORDSIZE", x) < 0)
  3225.         goto error;
  3226.     Py_DECREF(x);
  3227. #endif
  3228.  
  3229. #ifdef AL_NO_ELEM        /* IRIX 6 */
  3230.     (void) alSetErrorHandler(ErrorHandler);
  3231. #endif /* AL_NO_ELEM */
  3232. #ifdef OLD_INTERFACE
  3233.     (void) ALseterrorhandler(ErrorHandler);
  3234. #endif /* OLD_INTERFACE */
  3235.     
  3236.   error:
  3237.     return;
  3238. }
  3239.