1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
33 #include "pymactoolbox.h"
36 #pragma options align=mac68k
37 struct SampleRateAvailable_arg
{
42 struct SampleSizeAvailable_arg
{
47 #pragma options align=reset
49 static PyObject
*ErrorObject
;
52 /* Convert Python object to unsigned Fixed */
54 PyMac_GetUFixed(PyObject
*v
, Fixed
*f
)
59 if( !PyArg_Parse(v
, "d", &d
))
61 uns
= (unsigned long)(d
* 0x10000);
66 /* Convert a Point to a Python object */
68 PyMac_BuildUFixed(Fixed f
)
73 funs
= (unsigned long)f
;
77 return Py_BuildValue("d", d
);
81 /* ----------------------------------------------------- */
83 static char sndih_getChannelAvailable__doc__
[] =
88 sndih_getChannelAvailable(self
, args
)
89 PyObject
*self
; /* Not used */
96 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
99 if( (err
=SPBGetDeviceInfo(inRefNum
, siChannelAvailable
, (Ptr
)&nchannel
)) != noErr
)
100 return PyMac_Error(err
);
101 return Py_BuildValue("h", nchannel
);
104 static char sndih_getNumberChannels__doc__
[] =
109 sndih_getNumberChannels(self
, args
)
110 PyObject
*self
; /* Not used */
117 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
120 if( (err
=SPBGetDeviceInfo(inRefNum
, siNumberChannels
, (Ptr
)&nchannel
)) != noErr
)
121 return PyMac_Error(err
);
122 return Py_BuildValue("h", nchannel
);
125 static char sndih_setNumberChannels__doc__
[] =
130 sndih_setNumberChannels(self
, args
)
131 PyObject
*self
; /* Not used */
138 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &nchannel
))
141 if( (err
=SPBSetDeviceInfo(inRefNum
, siNumberChannels
, (Ptr
)&nchannel
)) != noErr
)
142 return PyMac_Error(err
);
147 static char sndih_getContinuous__doc__
[] =
152 sndih_getContinuous(self
, args
)
153 PyObject
*self
; /* Not used */
160 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
163 if( (err
=SPBGetDeviceInfo(inRefNum
, siContinuous
, (Ptr
)&onoff
)) != noErr
)
164 return PyMac_Error(err
);
165 return Py_BuildValue("h", onoff
);
168 static char sndih_setContinuous__doc__
[] =
173 sndih_setContinuous(self
, args
)
174 PyObject
*self
; /* Not used */
181 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &onoff
))
184 if( (err
=SPBSetDeviceInfo(inRefNum
, siContinuous
, (Ptr
)&onoff
)) != noErr
)
185 return PyMac_Error(err
);
190 static char sndih_getInputSourceNames__doc__
[] =
195 sndih_getInputSourceNames(self
, args
)
196 PyObject
*self
; /* Not used */
203 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
206 if( (err
=SPBGetDeviceInfo(inRefNum
, siInputSourceNames
, (Ptr
)&names
)) != noErr
)
207 return PyMac_Error(err
);
208 return Py_BuildValue("O&", ResObj_New
, names
);
211 static char sndih_getInputSource__doc__
[] =
216 sndih_getInputSource(self
, args
)
217 PyObject
*self
; /* Not used */
224 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
227 if( (err
=SPBGetDeviceInfo(inRefNum
, siInputSource
, (Ptr
)&source
)) != noErr
)
228 return PyMac_Error(err
);
229 return Py_BuildValue("h", source
);
232 static char sndih_setInputSource__doc__
[] =
237 sndih_setInputSource(self
, args
)
238 PyObject
*self
; /* Not used */
245 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &source
))
248 if( (err
=SPBSetDeviceInfo(inRefNum
, siInputSource
, (Ptr
)&source
)) != noErr
)
249 return PyMac_Error(err
);
254 static char sndih_getPlayThruOnOff__doc__
[] =
259 sndih_getPlayThruOnOff(self
, args
)
260 PyObject
*self
; /* Not used */
267 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
270 if( (err
=SPBGetDeviceInfo(inRefNum
, siPlayThruOnOff
, (Ptr
)&onoff
)) != noErr
)
271 return PyMac_Error(err
);
272 return Py_BuildValue("h", onoff
);
275 static char sndih_setPlayThruOnOff__doc__
[] =
280 sndih_setPlayThruOnOff(self
, args
)
281 PyObject
*self
; /* Not used */
288 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &onoff
))
291 if( (err
=SPBSetDeviceInfo(inRefNum
, siPlayThruOnOff
, (Ptr
)&onoff
)) != noErr
)
292 return PyMac_Error(err
);
297 static char sndih_getSampleRate__doc__
[] =
302 sndih_getSampleRate(self
, args
)
303 PyObject
*self
; /* Not used */
310 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
313 if( (err
=SPBGetDeviceInfo(inRefNum
, siSampleRate
, (Ptr
)&sample_rate
)) != noErr
)
314 return PyMac_Error(err
);
315 return Py_BuildValue("O&", PyMac_BuildUFixed
, sample_rate
);
318 static char sndih_setSampleRate__doc__
[] =
323 sndih_setSampleRate(self
, args
)
324 PyObject
*self
; /* Not used */
331 if (!PyArg_ParseTuple(args
, "lO&", &inRefNum
, PyMac_GetUFixed
, &sample_rate
))
334 if( (err
=SPBSetDeviceInfo(inRefNum
, siSampleRate
, (Ptr
)&sample_rate
)) != noErr
)
335 return PyMac_Error(err
);
340 static char sndih_getSampleSize__doc__
[] =
345 sndih_getSampleSize(self
, args
)
346 PyObject
*self
; /* Not used */
353 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
356 if( (err
=SPBGetDeviceInfo(inRefNum
, siSampleSize
, (Ptr
)&bits
)) != noErr
)
357 return PyMac_Error(err
);
358 return Py_BuildValue("h", bits
);
361 static char sndih_setSampleSize__doc__
[] =
366 sndih_setSampleSize(self
, args
)
367 PyObject
*self
; /* Not used */
374 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &size
))
377 if( (err
=SPBSetDeviceInfo(inRefNum
, siSampleSize
, (Ptr
)&size
)) != noErr
)
378 return PyMac_Error(err
);
383 static char sndih_getSampleSizeAvailable__doc__
[] =
388 sndih_getSampleSizeAvailable(self
, args
)
389 PyObject
*self
; /* Not used */
393 struct SampleSizeAvailable_arg arg
;
401 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
404 if( (err
=SPBGetDeviceInfo(inRefNum
, siSampleSizeAvailable
, (Ptr
)&arg
)) != noErr
) {
405 return PyMac_Error(err
);
407 fsizes
= (short *)*(arg
.sizes
);
408 /* Handle contains a list of rates */
409 if( (rsizes
= PyTuple_New(arg
.numsizes
)) == NULL
)
411 for( i
=0; i
<arg
.numsizes
; i
++ )
412 PyTuple_SetItem(rsizes
, i
, PyInt_FromLong((long)fsizes
[i
]));
416 static char sndih_getSampleRateAvailable__doc__
[] =
421 sndih_getSampleRateAvailable(self
, args
)
422 PyObject
*self
; /* Not used */
426 struct SampleRateAvailable_arg arg
;
428 PyObject
*rrates
, *obj
;
434 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
437 if( (err
=SPBGetDeviceInfo(inRefNum
, siSampleRateAvailable
, (Ptr
)&arg
)) != noErr
) {
438 return PyMac_Error(err
);
440 frates
= (Fixed
*)*(arg
.rates
);
441 if( arg
.numrates
== 0 ) {
442 /* The handle contains upper and lowerbound */
443 rrates
= Py_BuildValue("O&O&", frates
[0], frates
[1]);
444 if (rrates
== NULL
) return NULL
;
446 /* Handle contains a list of rates */
447 if( (rrates
= PyTuple_New(arg
.numrates
)) == NULL
)
449 for( i
=0; i
<arg
.numrates
; i
++ ) {
450 if( (obj
= Py_BuildValue("O&", PyMac_BuildUFixed
, frates
[i
]))==NULL
)
452 PyTuple_SetItem(rrates
, i
, obj
);
455 return Py_BuildValue("hO", arg
.numrates
, rrates
);
461 /* List of methods defined in the module */
463 static struct PyMethodDef sndih_methods
[] = {
464 {"getChannelAvailable", (PyCFunction
)sndih_getChannelAvailable
, METH_VARARGS
, sndih_getChannelAvailable__doc__
},
465 {"getNumberChannels", (PyCFunction
)sndih_getNumberChannels
, METH_VARARGS
, sndih_getNumberChannels__doc__
},
466 {"setNumberChannels", (PyCFunction
)sndih_setNumberChannels
, METH_VARARGS
, sndih_setNumberChannels__doc__
},
467 {"getContinuous", (PyCFunction
)sndih_getContinuous
, METH_VARARGS
, sndih_getContinuous__doc__
},
468 {"setContinuous", (PyCFunction
)sndih_setContinuous
, METH_VARARGS
, sndih_setContinuous__doc__
},
469 {"getInputSourceNames", (PyCFunction
)sndih_getInputSourceNames
, METH_VARARGS
, sndih_getInputSourceNames__doc__
},
470 {"getInputSource", (PyCFunction
)sndih_getInputSource
, METH_VARARGS
, sndih_getInputSource__doc__
},
471 {"setInputSource", (PyCFunction
)sndih_setInputSource
, METH_VARARGS
, sndih_setInputSource__doc__
},
472 {"getPlayThruOnOff", (PyCFunction
)sndih_getPlayThruOnOff
, METH_VARARGS
, sndih_getPlayThruOnOff__doc__
},
473 {"setPlayThruOnOff", (PyCFunction
)sndih_setPlayThruOnOff
, METH_VARARGS
, sndih_setPlayThruOnOff__doc__
},
474 {"getSampleRate", (PyCFunction
)sndih_getSampleRate
, METH_VARARGS
, sndih_getSampleRate__doc__
},
475 {"setSampleRate", (PyCFunction
)sndih_setSampleRate
, METH_VARARGS
, sndih_setSampleRate__doc__
},
476 {"getSampleSize", (PyCFunction
)sndih_getSampleSize
, METH_VARARGS
, sndih_getSampleSize__doc__
},
477 {"setSampleSize", (PyCFunction
)sndih_setSampleSize
, METH_VARARGS
, sndih_setSampleSize__doc__
},
478 {"getSampleSizeAvailable", (PyCFunction
)sndih_getSampleSizeAvailable
, METH_VARARGS
, sndih_getSampleSizeAvailable__doc__
},
479 {"getSampleRateAvailable", (PyCFunction
)sndih_getSampleRateAvailable
, METH_VARARGS
, sndih_getSampleRateAvailable__doc__
},
481 {NULL
, (PyCFunction
)NULL
, 0, NULL
} /* sentinel */
485 /* Initialization function for the module (*must* be called initSndihooks) */
487 static char Sndihooks_module_documentation
[] =
496 /* Create the module and add the functions */
497 m
= Py_InitModule4("_Sndihooks", sndih_methods
,
498 Sndihooks_module_documentation
,
499 (PyObject
*)NULL
,PYTHON_API_VERSION
);
501 /* Add some symbolic constants to the module */
502 d
= PyModule_GetDict(m
);
503 ErrorObject
= PyString_FromString("Sndihooks.error");
504 PyDict_SetItemString(d
, "error", ErrorObject
);
506 /* XXXX Add constants here */
508 /* Check for errors */
509 if (PyErr_Occurred())
510 Py_FatalError("can't initialize module Sndihooks");