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 ******************************************************************/
34 #include "pymactoolbox.h"
37 #pragma options align=mac68k
38 struct SampleRateAvailable_arg
{
43 struct SampleSizeAvailable_arg
{
48 #pragma options align=reset
50 static PyObject
*ErrorObject
;
53 /* Convert Python object to unsigned Fixed */
55 PyMac_GetUFixed(PyObject
*v
, Fixed
*f
)
60 if( !PyArg_Parse(v
, "d", &d
))
62 uns
= (unsigned long)(d
* 0x10000);
67 /* Convert a Point to a Python object */
69 PyMac_BuildUFixed(Fixed f
)
74 funs
= (unsigned long)f
;
78 return Py_BuildValue("d", d
);
82 /* ----------------------------------------------------- */
84 static char sndih_getChannelAvailable__doc__
[] =
89 sndih_getChannelAvailable(self
, args
)
90 PyObject
*self
; /* Not used */
97 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
100 if( (err
=SPBGetDeviceInfo(inRefNum
, siChannelAvailable
, (Ptr
)&nchannel
)) != noErr
)
101 return PyMac_Error(err
);
102 return Py_BuildValue("h", nchannel
);
105 static char sndih_getNumberChannels__doc__
[] =
110 sndih_getNumberChannels(self
, args
)
111 PyObject
*self
; /* Not used */
118 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
121 if( (err
=SPBGetDeviceInfo(inRefNum
, siNumberChannels
, (Ptr
)&nchannel
)) != noErr
)
122 return PyMac_Error(err
);
123 return Py_BuildValue("h", nchannel
);
126 static char sndih_setNumberChannels__doc__
[] =
131 sndih_setNumberChannels(self
, args
)
132 PyObject
*self
; /* Not used */
139 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &nchannel
))
142 if( (err
=SPBSetDeviceInfo(inRefNum
, siNumberChannels
, (Ptr
)&nchannel
)) != noErr
)
143 return PyMac_Error(err
);
148 static char sndih_getContinuous__doc__
[] =
153 sndih_getContinuous(self
, args
)
154 PyObject
*self
; /* Not used */
161 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
164 if( (err
=SPBGetDeviceInfo(inRefNum
, siContinuous
, (Ptr
)&onoff
)) != noErr
)
165 return PyMac_Error(err
);
166 return Py_BuildValue("h", onoff
);
169 static char sndih_setContinuous__doc__
[] =
174 sndih_setContinuous(self
, args
)
175 PyObject
*self
; /* Not used */
182 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &onoff
))
185 if( (err
=SPBSetDeviceInfo(inRefNum
, siContinuous
, (Ptr
)&onoff
)) != noErr
)
186 return PyMac_Error(err
);
191 static char sndih_getInputSourceNames__doc__
[] =
196 sndih_getInputSourceNames(self
, args
)
197 PyObject
*self
; /* Not used */
204 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
207 if( (err
=SPBGetDeviceInfo(inRefNum
, siInputSourceNames
, (Ptr
)&names
)) != noErr
)
208 return PyMac_Error(err
);
209 return Py_BuildValue("O&", ResObj_New
, names
);
212 static char sndih_getInputSource__doc__
[] =
217 sndih_getInputSource(self
, args
)
218 PyObject
*self
; /* Not used */
225 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
228 if( (err
=SPBGetDeviceInfo(inRefNum
, siInputSource
, (Ptr
)&source
)) != noErr
)
229 return PyMac_Error(err
);
230 return Py_BuildValue("h", source
);
233 static char sndih_setInputSource__doc__
[] =
238 sndih_setInputSource(self
, args
)
239 PyObject
*self
; /* Not used */
246 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &source
))
249 if( (err
=SPBSetDeviceInfo(inRefNum
, siInputSource
, (Ptr
)&source
)) != noErr
)
250 return PyMac_Error(err
);
255 static char sndih_getPlayThruOnOff__doc__
[] =
260 sndih_getPlayThruOnOff(self
, args
)
261 PyObject
*self
; /* Not used */
268 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
271 if( (err
=SPBGetDeviceInfo(inRefNum
, siPlayThruOnOff
, (Ptr
)&onoff
)) != noErr
)
272 return PyMac_Error(err
);
273 return Py_BuildValue("h", onoff
);
276 static char sndih_setPlayThruOnOff__doc__
[] =
281 sndih_setPlayThruOnOff(self
, args
)
282 PyObject
*self
; /* Not used */
289 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &onoff
))
292 if( (err
=SPBSetDeviceInfo(inRefNum
, siPlayThruOnOff
, (Ptr
)&onoff
)) != noErr
)
293 return PyMac_Error(err
);
298 static char sndih_getSampleRate__doc__
[] =
303 sndih_getSampleRate(self
, args
)
304 PyObject
*self
; /* Not used */
311 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
314 if( (err
=SPBGetDeviceInfo(inRefNum
, siSampleRate
, (Ptr
)&sample_rate
)) != noErr
)
315 return PyMac_Error(err
);
316 return Py_BuildValue("O&", PyMac_BuildUFixed
, sample_rate
);
319 static char sndih_setSampleRate__doc__
[] =
324 sndih_setSampleRate(self
, args
)
325 PyObject
*self
; /* Not used */
332 if (!PyArg_ParseTuple(args
, "lO&", &inRefNum
, PyMac_GetUFixed
, &sample_rate
))
335 if( (err
=SPBSetDeviceInfo(inRefNum
, siSampleRate
, (Ptr
)&sample_rate
)) != noErr
)
336 return PyMac_Error(err
);
341 static char sndih_getSampleSize__doc__
[] =
346 sndih_getSampleSize(self
, args
)
347 PyObject
*self
; /* Not used */
354 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
357 if( (err
=SPBGetDeviceInfo(inRefNum
, siSampleSize
, (Ptr
)&bits
)) != noErr
)
358 return PyMac_Error(err
);
359 return Py_BuildValue("h", bits
);
362 static char sndih_setSampleSize__doc__
[] =
367 sndih_setSampleSize(self
, args
)
368 PyObject
*self
; /* Not used */
375 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &size
))
378 if( (err
=SPBSetDeviceInfo(inRefNum
, siSampleSize
, (Ptr
)&size
)) != noErr
)
379 return PyMac_Error(err
);
384 static char sndih_getSampleSizeAvailable__doc__
[] =
389 sndih_getSampleSizeAvailable(self
, args
)
390 PyObject
*self
; /* Not used */
394 struct SampleSizeAvailable_arg arg
;
402 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
405 if( (err
=SPBGetDeviceInfo(inRefNum
, siSampleSizeAvailable
, (Ptr
)&arg
)) != noErr
) {
406 return PyMac_Error(err
);
408 fsizes
= (short *)*(arg
.sizes
);
409 /* Handle contains a list of rates */
410 if( (rsizes
= PyTuple_New(arg
.numsizes
)) == NULL
)
412 for( i
=0; i
<arg
.numsizes
; i
++ )
413 PyTuple_SetItem(rsizes
, i
, PyInt_FromLong((long)fsizes
[i
]));
417 static char sndih_getSampleRateAvailable__doc__
[] =
422 sndih_getSampleRateAvailable(self
, args
)
423 PyObject
*self
; /* Not used */
427 struct SampleRateAvailable_arg arg
;
429 PyObject
*rrates
, *obj
;
435 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
438 if( (err
=SPBGetDeviceInfo(inRefNum
, siSampleRateAvailable
, (Ptr
)&arg
)) != noErr
) {
439 return PyMac_Error(err
);
441 frates
= (Fixed
*)*(arg
.rates
);
442 if( arg
.numrates
== 0 ) {
443 /* The handle contains upper and lowerbound */
444 rrates
= Py_BuildValue("O&O&", frates
[0], frates
[1]);
445 if (rrates
== NULL
) return NULL
;
447 /* Handle contains a list of rates */
448 if( (rrates
= PyTuple_New(arg
.numrates
)) == NULL
)
450 for( i
=0; i
<arg
.numrates
; i
++ ) {
451 if( (obj
= Py_BuildValue("O&", PyMac_BuildUFixed
, frates
[i
]))==NULL
)
453 PyTuple_SetItem(rrates
, i
, obj
);
456 return Py_BuildValue("hO", arg
.numrates
, rrates
);
462 /* List of methods defined in the module */
464 static struct PyMethodDef sndih_methods
[] = {
465 {"getChannelAvailable", (PyCFunction
)sndih_getChannelAvailable
, METH_VARARGS
, sndih_getChannelAvailable__doc__
},
466 {"getNumberChannels", (PyCFunction
)sndih_getNumberChannels
, METH_VARARGS
, sndih_getNumberChannels__doc__
},
467 {"setNumberChannels", (PyCFunction
)sndih_setNumberChannels
, METH_VARARGS
, sndih_setNumberChannels__doc__
},
468 {"getContinuous", (PyCFunction
)sndih_getContinuous
, METH_VARARGS
, sndih_getContinuous__doc__
},
469 {"setContinuous", (PyCFunction
)sndih_setContinuous
, METH_VARARGS
, sndih_setContinuous__doc__
},
470 {"getInputSourceNames", (PyCFunction
)sndih_getInputSourceNames
, METH_VARARGS
, sndih_getInputSourceNames__doc__
},
471 {"getInputSource", (PyCFunction
)sndih_getInputSource
, METH_VARARGS
, sndih_getInputSource__doc__
},
472 {"setInputSource", (PyCFunction
)sndih_setInputSource
, METH_VARARGS
, sndih_setInputSource__doc__
},
473 {"getPlayThruOnOff", (PyCFunction
)sndih_getPlayThruOnOff
, METH_VARARGS
, sndih_getPlayThruOnOff__doc__
},
474 {"setPlayThruOnOff", (PyCFunction
)sndih_setPlayThruOnOff
, METH_VARARGS
, sndih_setPlayThruOnOff__doc__
},
475 {"getSampleRate", (PyCFunction
)sndih_getSampleRate
, METH_VARARGS
, sndih_getSampleRate__doc__
},
476 {"setSampleRate", (PyCFunction
)sndih_setSampleRate
, METH_VARARGS
, sndih_setSampleRate__doc__
},
477 {"getSampleSize", (PyCFunction
)sndih_getSampleSize
, METH_VARARGS
, sndih_getSampleSize__doc__
},
478 {"setSampleSize", (PyCFunction
)sndih_setSampleSize
, METH_VARARGS
, sndih_setSampleSize__doc__
},
479 {"getSampleSizeAvailable", (PyCFunction
)sndih_getSampleSizeAvailable
, METH_VARARGS
, sndih_getSampleSizeAvailable__doc__
},
480 {"getSampleRateAvailable", (PyCFunction
)sndih_getSampleRateAvailable
, METH_VARARGS
, sndih_getSampleRateAvailable__doc__
},
482 {NULL
, (PyCFunction
)NULL
, 0, NULL
} /* sentinel */
486 /* Initialization function for the module (*must* be called initSndihooks) */
488 static char Sndihooks_module_documentation
[] =
497 /* Create the module and add the functions */
498 m
= Py_InitModule4("_Sndihooks", sndih_methods
,
499 Sndihooks_module_documentation
,
500 (PyObject
*)NULL
,PYTHON_API_VERSION
);
502 /* Add some symbolic constants to the module */
503 d
= PyModule_GetDict(m
);
504 ErrorObject
= PyString_FromString("Sndihooks.error");
505 PyDict_SetItemString(d
, "error", ErrorObject
);
507 /* XXXX Add constants here */
509 /* Check for errors */
510 if (PyErr_Occurred())
511 Py_FatalError("can't initialize module Sndihooks");