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 ******************************************************************/
36 #pragma options align=mac68k
37 struct SampleRateAvailable_arg
{
42 struct SampleSizeAvailable_arg
{
47 #pragma options align=reset
49 extern PyObject
*ResObj_New(Handle
);
51 static PyObject
*ErrorObject
;
54 /* Convert Python object to unsigned Fixed */
56 PyMac_GetUFixed(PyObject
*v
, Fixed
*f
)
61 if( !PyArg_Parse(v
, "d", &d
))
63 uns
= (unsigned long)(d
* 0x10000);
68 /* Convert a Point to a Python object */
70 PyMac_BuildUFixed(Fixed f
)
75 funs
= (unsigned long)f
;
79 return Py_BuildValue("d", d
);
83 /* ----------------------------------------------------- */
85 static char sndih_getChannelAvailable__doc__
[] =
90 sndih_getChannelAvailable(self
, args
)
91 PyObject
*self
; /* Not used */
98 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
101 if( (err
=SPBGetDeviceInfo(inRefNum
, siChannelAvailable
, (Ptr
)&nchannel
)) != noErr
)
102 return PyMac_Error(err
);
103 return Py_BuildValue("h", nchannel
);
106 static char sndih_getNumberChannels__doc__
[] =
111 sndih_getNumberChannels(self
, args
)
112 PyObject
*self
; /* Not used */
119 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
122 if( (err
=SPBGetDeviceInfo(inRefNum
, siNumberChannels
, (Ptr
)&nchannel
)) != noErr
)
123 return PyMac_Error(err
);
124 return Py_BuildValue("h", nchannel
);
127 static char sndih_setNumberChannels__doc__
[] =
132 sndih_setNumberChannels(self
, args
)
133 PyObject
*self
; /* Not used */
140 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &nchannel
))
143 if( (err
=SPBSetDeviceInfo(inRefNum
, siNumberChannels
, (Ptr
)&nchannel
)) != noErr
)
144 return PyMac_Error(err
);
149 static char sndih_getContinuous__doc__
[] =
154 sndih_getContinuous(self
, args
)
155 PyObject
*self
; /* Not used */
162 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
165 if( (err
=SPBGetDeviceInfo(inRefNum
, siContinuous
, (Ptr
)&onoff
)) != noErr
)
166 return PyMac_Error(err
);
167 return Py_BuildValue("h", onoff
);
170 static char sndih_setContinuous__doc__
[] =
175 sndih_setContinuous(self
, args
)
176 PyObject
*self
; /* Not used */
183 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &onoff
))
186 if( (err
=SPBSetDeviceInfo(inRefNum
, siContinuous
, (Ptr
)&onoff
)) != noErr
)
187 return PyMac_Error(err
);
192 static char sndih_getInputSourceNames__doc__
[] =
197 sndih_getInputSourceNames(self
, args
)
198 PyObject
*self
; /* Not used */
205 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
208 if( (err
=SPBGetDeviceInfo(inRefNum
, siInputSourceNames
, (Ptr
)&names
)) != noErr
)
209 return PyMac_Error(err
);
210 return Py_BuildValue("O&", ResObj_New
, names
);
213 static char sndih_getInputSource__doc__
[] =
218 sndih_getInputSource(self
, args
)
219 PyObject
*self
; /* Not used */
226 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
229 if( (err
=SPBGetDeviceInfo(inRefNum
, siInputSource
, (Ptr
)&source
)) != noErr
)
230 return PyMac_Error(err
);
231 return Py_BuildValue("h", source
);
234 static char sndih_setInputSource__doc__
[] =
239 sndih_setInputSource(self
, args
)
240 PyObject
*self
; /* Not used */
247 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &source
))
250 if( (err
=SPBSetDeviceInfo(inRefNum
, siInputSource
, (Ptr
)&source
)) != noErr
)
251 return PyMac_Error(err
);
256 static char sndih_getPlayThruOnOff__doc__
[] =
261 sndih_getPlayThruOnOff(self
, args
)
262 PyObject
*self
; /* Not used */
269 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
272 if( (err
=SPBGetDeviceInfo(inRefNum
, siPlayThruOnOff
, (Ptr
)&onoff
)) != noErr
)
273 return PyMac_Error(err
);
274 return Py_BuildValue("h", onoff
);
277 static char sndih_setPlayThruOnOff__doc__
[] =
282 sndih_setPlayThruOnOff(self
, args
)
283 PyObject
*self
; /* Not used */
290 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &onoff
))
293 if( (err
=SPBSetDeviceInfo(inRefNum
, siPlayThruOnOff
, (Ptr
)&onoff
)) != noErr
)
294 return PyMac_Error(err
);
299 static char sndih_getSampleRate__doc__
[] =
304 sndih_getSampleRate(self
, args
)
305 PyObject
*self
; /* Not used */
312 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
315 if( (err
=SPBGetDeviceInfo(inRefNum
, siSampleRate
, (Ptr
)&sample_rate
)) != noErr
)
316 return PyMac_Error(err
);
317 return Py_BuildValue("O&", PyMac_BuildUFixed
, sample_rate
);
320 static char sndih_setSampleRate__doc__
[] =
325 sndih_setSampleRate(self
, args
)
326 PyObject
*self
; /* Not used */
333 if (!PyArg_ParseTuple(args
, "lO&", &inRefNum
, PyMac_GetUFixed
, &sample_rate
))
336 if( (err
=SPBSetDeviceInfo(inRefNum
, siSampleRate
, (Ptr
)&sample_rate
)) != noErr
)
337 return PyMac_Error(err
);
342 static char sndih_getSampleSize__doc__
[] =
347 sndih_getSampleSize(self
, args
)
348 PyObject
*self
; /* Not used */
355 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
358 if( (err
=SPBGetDeviceInfo(inRefNum
, siSampleSize
, (Ptr
)&bits
)) != noErr
)
359 return PyMac_Error(err
);
360 return Py_BuildValue("h", bits
);
363 static char sndih_setSampleSize__doc__
[] =
368 sndih_setSampleSize(self
, args
)
369 PyObject
*self
; /* Not used */
376 if (!PyArg_ParseTuple(args
, "lh", &inRefNum
, &size
))
379 if( (err
=SPBSetDeviceInfo(inRefNum
, siSampleSize
, (Ptr
)&size
)) != noErr
)
380 return PyMac_Error(err
);
385 static char sndih_getSampleSizeAvailable__doc__
[] =
390 sndih_getSampleSizeAvailable(self
, args
)
391 PyObject
*self
; /* Not used */
395 struct SampleSizeAvailable_arg arg
;
403 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
406 if( (err
=SPBGetDeviceInfo(inRefNum
, siSampleSizeAvailable
, (Ptr
)&arg
)) != noErr
) {
407 return PyMac_Error(err
);
409 fsizes
= (short *)*(arg
.sizes
);
410 /* Handle contains a list of rates */
411 if( (rsizes
= PyTuple_New(arg
.numsizes
)) == NULL
)
413 for( i
=0; i
<arg
.numsizes
; i
++ )
414 PyTuple_SetItem(rsizes
, i
, PyInt_FromLong((long)fsizes
[i
]));
418 static char sndih_getSampleRateAvailable__doc__
[] =
423 sndih_getSampleRateAvailable(self
, args
)
424 PyObject
*self
; /* Not used */
428 struct SampleRateAvailable_arg arg
;
430 PyObject
*rrates
, *obj
;
436 if (!PyArg_ParseTuple(args
, "l", &inRefNum
))
439 if( (err
=SPBGetDeviceInfo(inRefNum
, siSampleRateAvailable
, (Ptr
)&arg
)) != noErr
) {
440 return PyMac_Error(err
);
442 frates
= (Fixed
*)*(arg
.rates
);
443 if( arg
.numrates
== 0 ) {
444 /* The handle contains upper and lowerbound */
445 rrates
= Py_BuildValue("O&O&", frates
[0], frates
[1]);
446 if (rrates
== NULL
) return NULL
;
448 /* Handle contains a list of rates */
449 if( (rrates
= PyTuple_New(arg
.numrates
)) == NULL
)
451 for( i
=0; i
<arg
.numrates
; i
++ ) {
452 if( (obj
= Py_BuildValue("O&", PyMac_BuildUFixed
, frates
[i
]))==NULL
)
454 PyTuple_SetItem(rrates
, i
, obj
);
457 return Py_BuildValue("hO", arg
.numrates
, rrates
);
463 /* List of methods defined in the module */
465 static struct PyMethodDef sndih_methods
[] = {
466 {"getChannelAvailable", (PyCFunction
)sndih_getChannelAvailable
, METH_VARARGS
, sndih_getChannelAvailable__doc__
},
467 {"getNumberChannels", (PyCFunction
)sndih_getNumberChannels
, METH_VARARGS
, sndih_getNumberChannels__doc__
},
468 {"setNumberChannels", (PyCFunction
)sndih_setNumberChannels
, METH_VARARGS
, sndih_setNumberChannels__doc__
},
469 {"getContinuous", (PyCFunction
)sndih_getContinuous
, METH_VARARGS
, sndih_getContinuous__doc__
},
470 {"setContinuous", (PyCFunction
)sndih_setContinuous
, METH_VARARGS
, sndih_setContinuous__doc__
},
471 {"getInputSourceNames", (PyCFunction
)sndih_getInputSourceNames
, METH_VARARGS
, sndih_getInputSourceNames__doc__
},
472 {"getInputSource", (PyCFunction
)sndih_getInputSource
, METH_VARARGS
, sndih_getInputSource__doc__
},
473 {"setInputSource", (PyCFunction
)sndih_setInputSource
, METH_VARARGS
, sndih_setInputSource__doc__
},
474 {"getPlayThruOnOff", (PyCFunction
)sndih_getPlayThruOnOff
, METH_VARARGS
, sndih_getPlayThruOnOff__doc__
},
475 {"setPlayThruOnOff", (PyCFunction
)sndih_setPlayThruOnOff
, METH_VARARGS
, sndih_setPlayThruOnOff__doc__
},
476 {"getSampleRate", (PyCFunction
)sndih_getSampleRate
, METH_VARARGS
, sndih_getSampleRate__doc__
},
477 {"setSampleRate", (PyCFunction
)sndih_setSampleRate
, METH_VARARGS
, sndih_setSampleRate__doc__
},
478 {"getSampleSize", (PyCFunction
)sndih_getSampleSize
, METH_VARARGS
, sndih_getSampleSize__doc__
},
479 {"setSampleSize", (PyCFunction
)sndih_setSampleSize
, METH_VARARGS
, sndih_setSampleSize__doc__
},
480 {"getSampleSizeAvailable", (PyCFunction
)sndih_getSampleSizeAvailable
, METH_VARARGS
, sndih_getSampleSizeAvailable__doc__
},
481 {"getSampleRateAvailable", (PyCFunction
)sndih_getSampleRateAvailable
, METH_VARARGS
, sndih_getSampleRateAvailable__doc__
},
483 {NULL
, (PyCFunction
)NULL
, 0, NULL
} /* sentinel */
487 /* Initialization function for the module (*must* be called initSndihooks) */
489 static char Sndihooks_module_documentation
[] =
498 /* Create the module and add the functions */
499 m
= Py_InitModule4("Sndihooks", sndih_methods
,
500 Sndihooks_module_documentation
,
501 (PyObject
*)NULL
,PYTHON_API_VERSION
);
503 /* Add some symbolic constants to the module */
504 d
= PyModule_GetDict(m
);
505 ErrorObject
= PyString_FromString("Sndihooks.error");
506 PyDict_SetItemString(d
, "error", ErrorObject
);
508 /* XXXX Add constants here */
510 /* Check for errors */
511 if (PyErr_Occurred())
512 Py_FatalError("can't initialize module Sndihooks");