diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-05-12 22:25:16 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-05-12 22:25:16 (GMT) |
commit | 69a07fbd9b2c1e2d203532d4babbc6d874d389ee (patch) | |
tree | 822d06c6602339d309b30584ca0bfd05f5b56edc /Mac/Modules/snd | |
parent | a005b34f14fd4548c84886244b68d2c34e75edbd (diff) | |
download | cpython-69a07fbd9b2c1e2d203532d4babbc6d874d389ee.zip cpython-69a07fbd9b2c1e2d203532d4babbc6d874d389ee.tar.gz cpython-69a07fbd9b2c1e2d203532d4babbc6d874d389ee.tar.bz2 |
Remove the Mac modules
Diffstat (limited to 'Mac/Modules/snd')
-rw-r--r-- | Mac/Modules/snd/_Sndihooks.c | 512 | ||||
-rw-r--r-- | Mac/Modules/snd/_Sndmodule.c | 1149 | ||||
-rw-r--r-- | Mac/Modules/snd/sndscan.py | 127 | ||||
-rw-r--r-- | Mac/Modules/snd/sndsupport.py | 319 |
4 files changed, 0 insertions, 2107 deletions
diff --git a/Mac/Modules/snd/_Sndihooks.c b/Mac/Modules/snd/_Sndihooks.c deleted file mode 100644 index 383663a..0000000 --- a/Mac/Modules/snd/_Sndihooks.c +++ /dev/null @@ -1,512 +0,0 @@ -/*********************************************************** -Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI or Corporation for National Research Initiatives or -CNRI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -While CWI is the initial source for this software, a modified version -is made available by the Corporation for National Research Initiatives -(CNRI) at the Internet address ftp://ftp.python.org. - -STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH -CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR -PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - -#include "Python.h" -#include "pymactoolbox.h" -#include <Sound.h> - -#pragma options align=mac68k -struct SampleRateAvailable_arg { - short numrates; - Handle rates; -}; - -struct SampleSizeAvailable_arg { - short numsizes; - Handle sizes; -}; - -#pragma options align=reset - -static PyObject *ErrorObject; - - -/* Convert Python object to unsigned Fixed */ -static int -PyMac_GetUFixed(PyObject *v, Fixed *f) -{ - double d; - unsigned long uns; - - if( !PyArg_Parse(v, "d", &d)) - return 0; - uns = (unsigned long)(d * 0x10000); - *f = (Fixed)uns; - return 1; -} - -/* Convert a Point to a Python object */ -static PyObject * -PyMac_BuildUFixed(Fixed f) -{ - double d; - unsigned long funs; - - funs = (unsigned long)f; - - d = funs; - d = d / 0x10000; - return Py_BuildValue("d", d); -} - - -/* ----------------------------------------------------- */ - -static char sndih_getChannelAvailable__doc__[] = -"" -; - -static PyObject * -sndih_getChannelAvailable(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - short nchannel; - OSErr err; - - if (!PyArg_ParseTuple(args, "l", &inRefNum)) - return NULL; - - if( (err=SPBGetDeviceInfo(inRefNum, siChannelAvailable, (Ptr)&nchannel)) != noErr ) - return PyMac_Error(err); - return Py_BuildValue("h", nchannel); -} - -static char sndih_getNumberChannels__doc__[] = -"" -; - -static PyObject * -sndih_getNumberChannels(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - short nchannel; - OSErr err; - - if (!PyArg_ParseTuple(args, "l", &inRefNum)) - return NULL; - - if( (err=SPBGetDeviceInfo(inRefNum, siNumberChannels, (Ptr)&nchannel)) != noErr ) - return PyMac_Error(err); - return Py_BuildValue("h", nchannel); -} - -static char sndih_setNumberChannels__doc__[] = -"" -; - -static PyObject * -sndih_setNumberChannels(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - short nchannel; - OSErr err; - - if (!PyArg_ParseTuple(args, "lh", &inRefNum, &nchannel)) - return NULL; - - if( (err=SPBSetDeviceInfo(inRefNum, siNumberChannels, (Ptr)&nchannel)) != noErr ) - return PyMac_Error(err); - Py_INCREF(Py_None); - return Py_None; -} - -static char sndih_getContinuous__doc__[] = -"" -; - -static PyObject * -sndih_getContinuous(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - short onoff; - OSErr err; - - if (!PyArg_ParseTuple(args, "l", &inRefNum)) - return NULL; - - if( (err=SPBGetDeviceInfo(inRefNum, siContinuous, (Ptr)&onoff)) != noErr ) - return PyMac_Error(err); - return Py_BuildValue("h", onoff); -} - -static char sndih_setContinuous__doc__[] = -"" -; - -static PyObject * -sndih_setContinuous(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - short onoff; - OSErr err; - - if (!PyArg_ParseTuple(args, "lh", &inRefNum, &onoff)) - return NULL; - - if( (err=SPBSetDeviceInfo(inRefNum, siContinuous, (Ptr)&onoff)) != noErr ) - return PyMac_Error(err); - Py_INCREF(Py_None); - return Py_None; -} - -static char sndih_getInputSourceNames__doc__[] = -"" -; - -static PyObject * -sndih_getInputSourceNames(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - Handle names; - OSErr err; - - if (!PyArg_ParseTuple(args, "l", &inRefNum)) - return NULL; - - if( (err=SPBGetDeviceInfo(inRefNum, siInputSourceNames, (Ptr)&names)) != noErr ) - return PyMac_Error(err); - return Py_BuildValue("O&", ResObj_New, names); -} - -static char sndih_getInputSource__doc__[] = -"" -; - -static PyObject * -sndih_getInputSource(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - short source; - OSErr err; - - if (!PyArg_ParseTuple(args, "l", &inRefNum)) - return NULL; - - if( (err=SPBGetDeviceInfo(inRefNum, siInputSource, (Ptr)&source)) != noErr ) - return PyMac_Error(err); - return Py_BuildValue("h", source); -} - -static char sndih_setInputSource__doc__[] = -"" -; - -static PyObject * -sndih_setInputSource(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - short source; - OSErr err; - - if (!PyArg_ParseTuple(args, "lh", &inRefNum, &source)) - return NULL; - - if( (err=SPBSetDeviceInfo(inRefNum, siInputSource, (Ptr)&source)) != noErr ) - return PyMac_Error(err); - Py_INCREF(Py_None); - return Py_None; -} - -static char sndih_getPlayThruOnOff__doc__[] = -"" -; - -static PyObject * -sndih_getPlayThruOnOff(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - short onoff; - OSErr err; - - if (!PyArg_ParseTuple(args, "l", &inRefNum)) - return NULL; - - if( (err=SPBGetDeviceInfo(inRefNum, siPlayThruOnOff, (Ptr)&onoff)) != noErr ) - return PyMac_Error(err); - return Py_BuildValue("h", onoff); -} - -static char sndih_setPlayThruOnOff__doc__[] = -"" -; - -static PyObject * -sndih_setPlayThruOnOff(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - short onoff; - OSErr err; - - if (!PyArg_ParseTuple(args, "lh", &inRefNum, &onoff)) - return NULL; - - if( (err=SPBSetDeviceInfo(inRefNum, siPlayThruOnOff, (Ptr)&onoff)) != noErr ) - return PyMac_Error(err); - Py_INCREF(Py_None); - return Py_None; -} - -static char sndih_getSampleRate__doc__[] = -"" -; - -static PyObject * -sndih_getSampleRate(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - Fixed sample_rate; - OSErr err; - - if (!PyArg_ParseTuple(args, "l", &inRefNum)) - return NULL; - - if( (err=SPBGetDeviceInfo(inRefNum, siSampleRate, (Ptr)&sample_rate)) != noErr ) - return PyMac_Error(err); - return Py_BuildValue("O&", PyMac_BuildUFixed, sample_rate); -} - -static char sndih_setSampleRate__doc__[] = -"" -; - -static PyObject * -sndih_setSampleRate(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - Fixed sample_rate; - OSErr err; - - if (!PyArg_ParseTuple(args, "lO&", &inRefNum, PyMac_GetUFixed, &sample_rate)) - return NULL; - - if( (err=SPBSetDeviceInfo(inRefNum, siSampleRate, (Ptr)&sample_rate)) != noErr ) - return PyMac_Error(err); - Py_INCREF(Py_None); - return Py_None; -} - -static char sndih_getSampleSize__doc__[] = -"" -; - -static PyObject * -sndih_getSampleSize(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - short bits; - OSErr err; - - if (!PyArg_ParseTuple(args, "l", &inRefNum)) - return NULL; - - if( (err=SPBGetDeviceInfo(inRefNum, siSampleSize, (Ptr)&bits)) != noErr ) - return PyMac_Error(err); - return Py_BuildValue("h", bits); -} - -static char sndih_setSampleSize__doc__[] = -"" -; - -static PyObject * -sndih_setSampleSize(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - short size; - OSErr err; - - if (!PyArg_ParseTuple(args, "lh", &inRefNum, &size)) - return NULL; - - if( (err=SPBSetDeviceInfo(inRefNum, siSampleSize, (Ptr)&size)) != noErr ) - return PyMac_Error(err); - Py_INCREF(Py_None); - return Py_None; -} - -static char sndih_getSampleSizeAvailable__doc__[] = -"" -; - -static PyObject * -sndih_getSampleSizeAvailable(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - struct SampleSizeAvailable_arg arg; - OSErr err; - PyObject *rsizes; - short *fsizes; - int i; - - arg.sizes = NULL; - rsizes = NULL; - if (!PyArg_ParseTuple(args, "l", &inRefNum)) - return NULL; - - if( (err=SPBGetDeviceInfo(inRefNum, siSampleSizeAvailable, (Ptr)&arg)) != noErr ) { - return PyMac_Error(err); - } - fsizes = (short *)*(arg.sizes); - /* Handle contains a list of rates */ - if( (rsizes = PyTuple_New(arg.numsizes)) == NULL) - return NULL; - for( i=0; i<arg.numsizes; i++ ) - PyTuple_SetItem(rsizes, i, PyLong_FromLong((long)fsizes[i])); - return rsizes; -} - -static char sndih_getSampleRateAvailable__doc__[] = -"" -; - -static PyObject * -sndih_getSampleRateAvailable(self, args) - PyObject *self; /* Not used */ - PyObject *args; -{ - long inRefNum; - struct SampleRateAvailable_arg arg; - OSErr err; - PyObject *rrates, *obj; - Fixed *frates; - int i; - - arg.rates = NULL; - rrates = NULL; - if (!PyArg_ParseTuple(args, "l", &inRefNum)) - return NULL; - - if( (err=SPBGetDeviceInfo(inRefNum, siSampleRateAvailable, (Ptr)&arg)) != noErr ) { - return PyMac_Error(err); - } - frates = (Fixed *)*(arg.rates); - if( arg.numrates == 0 ) { - /* The handle contains upper and lowerbound */ - rrates = Py_BuildValue("O&O&", frates[0], frates[1]); - if (rrates == NULL) return NULL; - } else { - /* Handle contains a list of rates */ - if( (rrates = PyTuple_New(arg.numrates)) == NULL) - return NULL; - for( i=0; i<arg.numrates; i++ ) { - if( (obj = Py_BuildValue("O&", PyMac_BuildUFixed, frates[i]))==NULL) - goto out; - PyTuple_SetItem(rrates, i, obj); - } - } - return Py_BuildValue("hO", arg.numrates, rrates); -out: - Py_XDECREF(rrates); - return NULL; -} - -/* List of methods defined in the module */ - -static struct PyMethodDef sndih_methods[] = { - {"getChannelAvailable", (PyCFunction)sndih_getChannelAvailable, METH_VARARGS, sndih_getChannelAvailable__doc__}, - {"getNumberChannels", (PyCFunction)sndih_getNumberChannels, METH_VARARGS, sndih_getNumberChannels__doc__}, - {"setNumberChannels", (PyCFunction)sndih_setNumberChannels, METH_VARARGS, sndih_setNumberChannels__doc__}, - {"getContinuous", (PyCFunction)sndih_getContinuous, METH_VARARGS, sndih_getContinuous__doc__}, - {"setContinuous", (PyCFunction)sndih_setContinuous, METH_VARARGS, sndih_setContinuous__doc__}, - {"getInputSourceNames", (PyCFunction)sndih_getInputSourceNames, METH_VARARGS, sndih_getInputSourceNames__doc__}, - {"getInputSource", (PyCFunction)sndih_getInputSource, METH_VARARGS, sndih_getInputSource__doc__}, - {"setInputSource", (PyCFunction)sndih_setInputSource, METH_VARARGS, sndih_setInputSource__doc__}, - {"getPlayThruOnOff", (PyCFunction)sndih_getPlayThruOnOff, METH_VARARGS, sndih_getPlayThruOnOff__doc__}, - {"setPlayThruOnOff", (PyCFunction)sndih_setPlayThruOnOff, METH_VARARGS, sndih_setPlayThruOnOff__doc__}, - {"getSampleRate", (PyCFunction)sndih_getSampleRate, METH_VARARGS, sndih_getSampleRate__doc__}, - {"setSampleRate", (PyCFunction)sndih_setSampleRate, METH_VARARGS, sndih_setSampleRate__doc__}, - {"getSampleSize", (PyCFunction)sndih_getSampleSize, METH_VARARGS, sndih_getSampleSize__doc__}, - {"setSampleSize", (PyCFunction)sndih_setSampleSize, METH_VARARGS, sndih_setSampleSize__doc__}, - {"getSampleSizeAvailable", (PyCFunction)sndih_getSampleSizeAvailable, METH_VARARGS, sndih_getSampleSizeAvailable__doc__}, - {"getSampleRateAvailable", (PyCFunction)sndih_getSampleRateAvailable, METH_VARARGS, sndih_getSampleRateAvailable__doc__}, - - {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ -}; - - -/* Initialization function for the module (*must* be called initSndihooks) */ - -static char Sndihooks_module_documentation[] = -"" -; - -void -init_Sndihooks() -{ - PyObject *m, *d; - - /* Create the module and add the functions */ - m = Py_InitModule4("_Sndihooks", sndih_methods, - Sndihooks_module_documentation, - (PyObject*)NULL,PYTHON_API_VERSION); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyString_FromString("Sndihooks.error"); - PyDict_SetItemString(d, "error", ErrorObject); - - /* XXXX Add constants here */ - - /* Check for errors */ - if (PyErr_Occurred()) - Py_FatalError("can't initialize module Sndihooks"); -} - diff --git a/Mac/Modules/snd/_Sndmodule.c b/Mac/Modules/snd/_Sndmodule.c deleted file mode 100644 index 0e2e572..0000000 --- a/Mac/Modules/snd/_Sndmodule.c +++ /dev/null @@ -1,1149 +0,0 @@ - -/* ========================== Module _Snd =========================== */ - -#include "Python.h" - - - -#include "pymactoolbox.h" - -/* Macro to test whether a weak-loaded CFM function exists */ -#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ - PyErr_SetString(PyExc_NotImplementedError, \ - "Not available in this shared library/OS version"); \ - return NULL; \ - }} while(0) - - -#include <Carbon/Carbon.h> - -/* Convert a SndCommand argument */ -static int -SndCmd_Convert(PyObject *v, SndCommand *pc) -{ - int len; - pc->param1 = 0; - pc->param2 = 0; - if (PyTuple_Check(v)) { - if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2)) - return 1; - PyErr_Clear(); - return PyArg_ParseTuple(v, "Hhs#", &pc->cmd, &pc->param1, &pc->param2, &len); - } - return PyArg_Parse(v, "H", &pc->cmd); -} - -static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */ -static pascal void SPB_completion(SPBPtr my_spb); /* Forward */ - -static PyObject *Snd_Error; - -/* --------------------- Object type SndChannel --------------------- */ - -static PyTypeObject SndChannel_Type; - -#define SndCh_Check(x) (Py_TYPE(x) == &SndChannel_Type || PyObject_TypeCheck((x), &SndChannel_Type)) - -typedef struct SndChannelObject { - PyObject_HEAD - SndChannelPtr ob_itself; - /* Members used to implement callbacks: */ - PyObject *ob_callback; - long ob_A5; - SndCommand ob_cmd; -} SndChannelObject; - -static PyObject *SndCh_New(SndChannelPtr itself) -{ - SndChannelObject *it; - it = PyObject_NEW(SndChannelObject, &SndChannel_Type); - if (it == NULL) return NULL; - it->ob_itself = itself; - it->ob_callback = NULL; - it->ob_A5 = SetCurrentA5(); - return (PyObject *)it; -} - -static void SndCh_dealloc(SndChannelObject *self) -{ - SndDisposeChannel(self->ob_itself, 1); - Py_XDECREF(self->ob_callback); - PyObject_Free((PyObject *)self); -} - -static PyObject *SndCh_SndDoCommand(SndChannelObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SndCommand cmd; - Boolean noWait; - if (!PyArg_ParseTuple(_args, "O&b", - SndCmd_Convert, &cmd, - &noWait)) - return NULL; - _err = SndDoCommand(_self->ob_itself, - &cmd, - noWait); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *SndCh_SndDoImmediate(SndChannelObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SndCommand cmd; - if (!PyArg_ParseTuple(_args, "O&", - SndCmd_Convert, &cmd)) - return NULL; - _err = SndDoImmediate(_self->ob_itself, - &cmd); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *SndCh_SndPlay(SndChannelObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SndListHandle sndHandle; - Boolean async; - if (!PyArg_ParseTuple(_args, "O&b", - ResObj_Convert, &sndHandle, - &async)) - return NULL; - _err = SndPlay(_self->ob_itself, - sndHandle, - async); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *SndCh_SndChannelStatus(SndChannelObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - short theLength; - SCStatus theStatus__out__; - if (!PyArg_ParseTuple(_args, "h", - &theLength)) - return NULL; - _err = SndChannelStatus(_self->ob_itself, - theLength, - &theStatus__out__); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("s#", - (char *)&theStatus__out__, (int)sizeof(SCStatus)); - return _res; -} - -static PyObject *SndCh_SndGetInfo(SndChannelObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - OSType selector; - void * infoPtr; - if (!PyArg_ParseTuple(_args, "O&w", - PyMac_GetOSType, &selector, - &infoPtr)) - return NULL; - _err = SndGetInfo(_self->ob_itself, - selector, - infoPtr); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *SndCh_SndSetInfo(SndChannelObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - OSType selector; - void * infoPtr; - if (!PyArg_ParseTuple(_args, "O&w", - PyMac_GetOSType, &selector, - &infoPtr)) - return NULL; - _err = SndSetInfo(_self->ob_itself, - selector, - infoPtr); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyMethodDef SndCh_methods[] = { - {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1, - PyDoc_STR("(SndCommand cmd, Boolean noWait) -> None")}, - {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1, - PyDoc_STR("(SndCommand cmd) -> None")}, - {"SndPlay", (PyCFunction)SndCh_SndPlay, 1, - PyDoc_STR("(SndListHandle sndHandle, Boolean async) -> None")}, - {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1, - PyDoc_STR("(short theLength) -> (SCStatus theStatus)")}, - {"SndGetInfo", (PyCFunction)SndCh_SndGetInfo, 1, - PyDoc_STR("(OSType selector, void * infoPtr) -> None")}, - {"SndSetInfo", (PyCFunction)SndCh_SndSetInfo, 1, - PyDoc_STR("(OSType selector, void * infoPtr) -> None")}, - {NULL, NULL, 0} -}; - -#define SndCh_getsetlist NULL - - -#define SndCh_compare NULL - -#define SndCh_repr NULL - -#define SndCh_hash NULL - -static PyTypeObject SndChannel_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_Snd.SndChannel", /*tp_name*/ - sizeof(SndChannelObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor) SndCh_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)0, /*tp_getattr*/ - (setattrfunc)0, /*tp_setattr*/ - (cmpfunc) SndCh_compare, /*tp_compare*/ - (reprfunc) SndCh_repr, /*tp_repr*/ - (PyNumberMethods *)0, /* tp_as_number */ - (PySequenceMethods *)0, /* tp_as_sequence */ - (PyMappingMethods *)0, /* tp_as_mapping */ - (hashfunc) SndCh_hash, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - PyObject_GenericGetAttr, /*tp_getattro*/ - PyObject_GenericSetAttr, /*tp_setattro */ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - SndCh_methods, /* tp_methods */ - 0, /*tp_members*/ - SndCh_getsetlist, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - 0, /*tp_new*/ - 0, /*tp_free*/ -}; - -/* ------------------- End object type SndChannel ------------------- */ - - -/* ------------------------ Object type SPB ------------------------- */ - -static PyTypeObject SPB_Type; - -#define SPBObj_Check(x) (Py_TYPE(x) == &SPB_Type || PyObject_TypeCheck((x), &SPB_Type)) - -typedef struct SPBObject { - PyObject_HEAD - /* Members used to implement callbacks: */ - PyObject *ob_completion; - PyObject *ob_interrupt; - PyObject *ob_thiscallback; - long ob_A5; - SPB ob_spb; -} SPBObject; - -static PyObject *SPBObj_New(void) -{ - SPBObject *it; - it = PyObject_NEW(SPBObject, &SPB_Type); - if (it == NULL) return NULL; - it->ob_completion = NULL; - it->ob_interrupt = NULL; - it->ob_thiscallback = NULL; - it->ob_A5 = SetCurrentA5(); - memset((char *)&it->ob_spb, 0, sizeof(it->ob_spb)); - it->ob_spb.userLong = (long)it; - return (PyObject *)it; -} -static int SPBObj_Convert(PyObject *v, SPBPtr *p_itself) -{ - if (!SPBObj_Check(v)) - { - PyErr_SetString(PyExc_TypeError, "SPB required"); - return 0; - } - *p_itself = &((SPBObject *)v)->ob_spb; - return 1; -} - -static void SPBObj_dealloc(SPBObject *self) -{ - /* Cleanup of self->ob_itself goes here */ - self->ob_spb.userLong = 0; - self->ob_thiscallback = 0; - Py_XDECREF(self->ob_completion); - Py_XDECREF(self->ob_interrupt); - PyObject_Free((PyObject *)self); -} - -static PyMethodDef SPBObj_methods[] = { - {NULL, NULL, 0} -}; - -static PyObject *SPBObj_get_inRefNum(SPBObject *self, void *closure) -{ - return Py_BuildValue("l", self->ob_spb.inRefNum); -} - -static int SPBObj_set_inRefNum(SPBObject *self, PyObject *v, void *closure) -{ - return -1 + PyArg_Parse(v, "l", &self->ob_spb.inRefNum); - return 0; -} - -static PyObject *SPBObj_get_count(SPBObject *self, void *closure) -{ - return Py_BuildValue("l", self->ob_spb.count); -} - -static int SPBObj_set_count(SPBObject *self, PyObject *v, void *closure) -{ - return -1 + PyArg_Parse(v, "l", &self->ob_spb.count); - return 0; -} - -static PyObject *SPBObj_get_milliseconds(SPBObject *self, void *closure) -{ - return Py_BuildValue("l", self->ob_spb.milliseconds); -} - -static int SPBObj_set_milliseconds(SPBObject *self, PyObject *v, void *closure) -{ - return -1 + PyArg_Parse(v, "l", &self->ob_spb.milliseconds); - return 0; -} - -static PyObject *SPBObj_get_error(SPBObject *self, void *closure) -{ - return Py_BuildValue("h", self->ob_spb.error); -} - -#define SPBObj_set_error NULL - -#define SPBObj_get_completionRoutine NULL - -static int SPBObj_set_completionRoutine(SPBObject *self, PyObject *v, void *closure) -{ - self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion); - self->ob_completion = v; - Py_INCREF(v); - return 0; - return 0; -} - -static PyGetSetDef SPBObj_getsetlist[] = { - {"inRefNum", (getter)SPBObj_get_inRefNum, (setter)SPBObj_set_inRefNum, NULL}, - {"count", (getter)SPBObj_get_count, (setter)SPBObj_set_count, NULL}, - {"milliseconds", (getter)SPBObj_get_milliseconds, (setter)SPBObj_set_milliseconds, NULL}, - {"error", (getter)SPBObj_get_error, (setter)SPBObj_set_error, NULL}, - {"completionRoutine", (getter)SPBObj_get_completionRoutine, (setter)SPBObj_set_completionRoutine, NULL}, - {NULL, NULL, NULL, NULL}, -}; - - -#define SPBObj_compare NULL - -#define SPBObj_repr NULL - -#define SPBObj_hash NULL - -static PyTypeObject SPB_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_Snd.SPB", /*tp_name*/ - sizeof(SPBObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor) SPBObj_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)0, /*tp_getattr*/ - (setattrfunc)0, /*tp_setattr*/ - (cmpfunc) SPBObj_compare, /*tp_compare*/ - (reprfunc) SPBObj_repr, /*tp_repr*/ - (PyNumberMethods *)0, /* tp_as_number */ - (PySequenceMethods *)0, /* tp_as_sequence */ - (PyMappingMethods *)0, /* tp_as_mapping */ - (hashfunc) SPBObj_hash, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - PyObject_GenericGetAttr, /*tp_getattro*/ - PyObject_GenericSetAttr, /*tp_setattro */ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - SPBObj_methods, /* tp_methods */ - 0, /*tp_members*/ - SPBObj_getsetlist, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - 0, /*tp_new*/ - 0, /*tp_free*/ -}; - -/* ---------------------- End object type SPB ----------------------- */ - - -static PyObject *Snd_SPB(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - _res = SPBObj_New(); return _res; -} - -static PyObject *Snd_SysBeep(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - short duration; - if (!PyArg_ParseTuple(_args, "h", - &duration)) - return NULL; - SysBeep(duration); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_SndNewChannel(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SndChannelPtr chan = 0; - short synth; - long init; - PyObject* userRoutine; - if (!PyArg_ParseTuple(_args, "hlO", - &synth, - &init, - &userRoutine)) - return NULL; - if (userRoutine != Py_None && !PyCallable_Check(userRoutine)) - { - PyErr_SetString(PyExc_TypeError, "callback must be callable"); - goto userRoutine__error__; - } - _err = SndNewChannel(&chan, - synth, - init, - NewSndCallBackUPP(SndCh_UserRoutine)); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("O&", - SndCh_New, chan); - if (_res != NULL && userRoutine != Py_None) - { - SndChannelObject *p = (SndChannelObject *)_res; - p->ob_itself->userInfo = (long)p; - Py_INCREF(userRoutine); - p->ob_callback = userRoutine; - } - userRoutine__error__: ; - return _res; -} - -static PyObject *Snd_SndSoundManagerVersion(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - NumVersion _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = SndSoundManagerVersion(); - _res = Py_BuildValue("O&", - PyMac_BuildNumVersion, _rv); - return _res; -} - -static PyObject *Snd_SndManagerStatus(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - short theLength; - SMStatus theStatus__out__; - if (!PyArg_ParseTuple(_args, "h", - &theLength)) - return NULL; - _err = SndManagerStatus(theLength, - &theStatus__out__); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("s#", - (char *)&theStatus__out__, (int)sizeof(SMStatus)); - return _res; -} - -static PyObject *Snd_SndGetSysBeepState(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - short sysBeepState; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - SndGetSysBeepState(&sysBeepState); - _res = Py_BuildValue("h", - sysBeepState); - return _res; -} - -static PyObject *Snd_SndSetSysBeepState(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - short sysBeepState; - if (!PyArg_ParseTuple(_args, "h", - &sysBeepState)) - return NULL; - _err = SndSetSysBeepState(sysBeepState); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_GetSysBeepVolume(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long level; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = GetSysBeepVolume(&level); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("l", - level); - return _res; -} - -static PyObject *Snd_SetSysBeepVolume(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long level; - if (!PyArg_ParseTuple(_args, "l", - &level)) - return NULL; - _err = SetSysBeepVolume(level); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_GetDefaultOutputVolume(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long level; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = GetDefaultOutputVolume(&level); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("l", - level); - return _res; -} - -static PyObject *Snd_SetDefaultOutputVolume(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long level; - if (!PyArg_ParseTuple(_args, "l", - &level)) - return NULL; - _err = SetDefaultOutputVolume(level); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_GetSoundHeaderOffset(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SndListHandle sndHandle; - long offset; - if (!PyArg_ParseTuple(_args, "O&", - ResObj_Convert, &sndHandle)) - return NULL; - _err = GetSoundHeaderOffset(sndHandle, - &offset); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("l", - offset); - return _res; -} - -static PyObject *Snd_GetCompressionInfo(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - short compressionID; - OSType format; - short numChannels; - short sampleSize; - CompressionInfo cp__out__; - if (!PyArg_ParseTuple(_args, "hO&hh", - &compressionID, - PyMac_GetOSType, &format, - &numChannels, - &sampleSize)) - return NULL; - _err = GetCompressionInfo(compressionID, - format, - numChannels, - sampleSize, - &cp__out__); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("s#", - (char *)&cp__out__, (int)sizeof(CompressionInfo)); - return _res; -} - -static PyObject *Snd_SetSoundPreference(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - OSType theType; - Str255 name; - Handle settings; - if (!PyArg_ParseTuple(_args, "O&O&", - PyMac_GetOSType, &theType, - ResObj_Convert, &settings)) - return NULL; - _err = SetSoundPreference(theType, - name, - settings); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("O&", - PyMac_BuildStr255, name); - return _res; -} - -static PyObject *Snd_GetSoundPreference(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - OSType theType; - Str255 name; - Handle settings; - if (!PyArg_ParseTuple(_args, "O&O&", - PyMac_GetOSType, &theType, - ResObj_Convert, &settings)) - return NULL; - _err = GetSoundPreference(theType, - name, - settings); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("O&", - PyMac_BuildStr255, name); - return _res; -} - -static PyObject *Snd_GetCompressionName(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - OSType compressionType; - Str255 compressionName; - if (!PyArg_ParseTuple(_args, "O&", - PyMac_GetOSType, &compressionType)) - return NULL; - _err = GetCompressionName(compressionType, - compressionName); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("O&", - PyMac_BuildStr255, compressionName); - return _res; -} - -static PyObject *Snd_SPBVersion(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - NumVersion _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = SPBVersion(); - _res = Py_BuildValue("O&", - PyMac_BuildNumVersion, _rv); - return _res; -} - -static PyObject *Snd_SndRecord(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - Point corner; - OSType quality; - SndListHandle sndHandle; - if (!PyArg_ParseTuple(_args, "O&O&", - PyMac_GetPoint, &corner, - PyMac_GetOSType, &quality)) - return NULL; - _err = SndRecord((ModalFilterUPP)0, - corner, - quality, - &sndHandle); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("O&", - ResObj_New, sndHandle); - return _res; -} - -static PyObject *Snd_SPBSignInDevice(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - short deviceRefNum; - Str255 deviceName; - if (!PyArg_ParseTuple(_args, "hO&", - &deviceRefNum, - PyMac_GetStr255, deviceName)) - return NULL; - _err = SPBSignInDevice(deviceRefNum, - deviceName); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_SPBSignOutDevice(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - short deviceRefNum; - if (!PyArg_ParseTuple(_args, "h", - &deviceRefNum)) - return NULL; - _err = SPBSignOutDevice(deviceRefNum); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_SPBGetIndexedDevice(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - short count; - Str255 deviceName; - Handle deviceIconHandle; - if (!PyArg_ParseTuple(_args, "h", - &count)) - return NULL; - _err = SPBGetIndexedDevice(count, - deviceName, - &deviceIconHandle); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("O&O&", - PyMac_BuildStr255, deviceName, - ResObj_New, deviceIconHandle); - return _res; -} - -static PyObject *Snd_SPBOpenDevice(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - Str255 deviceName; - short permission; - long inRefNum; - if (!PyArg_ParseTuple(_args, "O&h", - PyMac_GetStr255, deviceName, - &permission)) - return NULL; - _err = SPBOpenDevice(deviceName, - permission, - &inRefNum); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("l", - inRefNum); - return _res; -} - -static PyObject *Snd_SPBCloseDevice(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long inRefNum; - if (!PyArg_ParseTuple(_args, "l", - &inRefNum)) - return NULL; - _err = SPBCloseDevice(inRefNum); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_SPBRecord(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SPBPtr inParamPtr; - Boolean asynchFlag; - if (!PyArg_ParseTuple(_args, "O&b", - SPBObj_Convert, &inParamPtr, - &asynchFlag)) - return NULL; - _err = SPBRecord(inParamPtr, - asynchFlag); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_SPBPauseRecording(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long inRefNum; - if (!PyArg_ParseTuple(_args, "l", - &inRefNum)) - return NULL; - _err = SPBPauseRecording(inRefNum); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_SPBResumeRecording(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long inRefNum; - if (!PyArg_ParseTuple(_args, "l", - &inRefNum)) - return NULL; - _err = SPBResumeRecording(inRefNum); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_SPBStopRecording(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long inRefNum; - if (!PyArg_ParseTuple(_args, "l", - &inRefNum)) - return NULL; - _err = SPBStopRecording(inRefNum); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_SPBGetRecordingStatus(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long inRefNum; - short recordingStatus; - short meterLevel; - unsigned long totalSamplesToRecord; - unsigned long numberOfSamplesRecorded; - unsigned long totalMsecsToRecord; - unsigned long numberOfMsecsRecorded; - if (!PyArg_ParseTuple(_args, "l", - &inRefNum)) - return NULL; - _err = SPBGetRecordingStatus(inRefNum, - &recordingStatus, - &meterLevel, - &totalSamplesToRecord, - &numberOfSamplesRecorded, - &totalMsecsToRecord, - &numberOfMsecsRecorded); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("hhllll", - recordingStatus, - meterLevel, - totalSamplesToRecord, - numberOfSamplesRecorded, - totalMsecsToRecord, - numberOfMsecsRecorded); - return _res; -} - -static PyObject *Snd_SPBGetDeviceInfo(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long inRefNum; - OSType infoType; - void * infoData; - if (!PyArg_ParseTuple(_args, "lO&w", - &inRefNum, - PyMac_GetOSType, &infoType, - &infoData)) - return NULL; - _err = SPBGetDeviceInfo(inRefNum, - infoType, - infoData); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_SPBSetDeviceInfo(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long inRefNum; - OSType infoType; - void * infoData; - if (!PyArg_ParseTuple(_args, "lO&w", - &inRefNum, - PyMac_GetOSType, &infoType, - &infoData)) - return NULL; - _err = SPBSetDeviceInfo(inRefNum, - infoType, - infoData); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *Snd_SPBMillisecondsToBytes(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long inRefNum; - long milliseconds; - if (!PyArg_ParseTuple(_args, "l", - &inRefNum)) - return NULL; - _err = SPBMillisecondsToBytes(inRefNum, - &milliseconds); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("l", - milliseconds); - return _res; -} - -static PyObject *Snd_SPBBytesToMilliseconds(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - long inRefNum; - long byteCount; - if (!PyArg_ParseTuple(_args, "l", - &inRefNum)) - return NULL; - _err = SPBBytesToMilliseconds(inRefNum, - &byteCount); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("l", - byteCount); - return _res; -} - -static PyMethodDef Snd_methods[] = { - {"SPB", (PyCFunction)Snd_SPB, 1, - PyDoc_STR(NULL)}, - {"SysBeep", (PyCFunction)Snd_SysBeep, 1, - PyDoc_STR("(short duration) -> None")}, - {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1, - PyDoc_STR("(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)")}, - {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1, - PyDoc_STR("() -> (NumVersion _rv)")}, - {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1, - PyDoc_STR("(short theLength) -> (SMStatus theStatus)")}, - {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1, - PyDoc_STR("() -> (short sysBeepState)")}, - {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1, - PyDoc_STR("(short sysBeepState) -> None")}, - {"GetSysBeepVolume", (PyCFunction)Snd_GetSysBeepVolume, 1, - PyDoc_STR("() -> (long level)")}, - {"SetSysBeepVolume", (PyCFunction)Snd_SetSysBeepVolume, 1, - PyDoc_STR("(long level) -> None")}, - {"GetDefaultOutputVolume", (PyCFunction)Snd_GetDefaultOutputVolume, 1, - PyDoc_STR("() -> (long level)")}, - {"SetDefaultOutputVolume", (PyCFunction)Snd_SetDefaultOutputVolume, 1, - PyDoc_STR("(long level) -> None")}, - {"GetSoundHeaderOffset", (PyCFunction)Snd_GetSoundHeaderOffset, 1, - PyDoc_STR("(SndListHandle sndHandle) -> (long offset)")}, - {"GetCompressionInfo", (PyCFunction)Snd_GetCompressionInfo, 1, - PyDoc_STR("(short compressionID, OSType format, short numChannels, short sampleSize) -> (CompressionInfo cp)")}, - {"SetSoundPreference", (PyCFunction)Snd_SetSoundPreference, 1, - PyDoc_STR("(OSType theType, Handle settings) -> (Str255 name)")}, - {"GetSoundPreference", (PyCFunction)Snd_GetSoundPreference, 1, - PyDoc_STR("(OSType theType, Handle settings) -> (Str255 name)")}, - {"GetCompressionName", (PyCFunction)Snd_GetCompressionName, 1, - PyDoc_STR("(OSType compressionType) -> (Str255 compressionName)")}, - {"SPBVersion", (PyCFunction)Snd_SPBVersion, 1, - PyDoc_STR("() -> (NumVersion _rv)")}, - {"SndRecord", (PyCFunction)Snd_SndRecord, 1, - PyDoc_STR("(Point corner, OSType quality) -> (SndListHandle sndHandle)")}, - {"SPBSignInDevice", (PyCFunction)Snd_SPBSignInDevice, 1, - PyDoc_STR("(short deviceRefNum, Str255 deviceName) -> None")}, - {"SPBSignOutDevice", (PyCFunction)Snd_SPBSignOutDevice, 1, - PyDoc_STR("(short deviceRefNum) -> None")}, - {"SPBGetIndexedDevice", (PyCFunction)Snd_SPBGetIndexedDevice, 1, - PyDoc_STR("(short count) -> (Str255 deviceName, Handle deviceIconHandle)")}, - {"SPBOpenDevice", (PyCFunction)Snd_SPBOpenDevice, 1, - PyDoc_STR("(Str255 deviceName, short permission) -> (long inRefNum)")}, - {"SPBCloseDevice", (PyCFunction)Snd_SPBCloseDevice, 1, - PyDoc_STR("(long inRefNum) -> None")}, - {"SPBRecord", (PyCFunction)Snd_SPBRecord, 1, - PyDoc_STR("(SPBPtr inParamPtr, Boolean asynchFlag) -> None")}, - {"SPBPauseRecording", (PyCFunction)Snd_SPBPauseRecording, 1, - PyDoc_STR("(long inRefNum) -> None")}, - {"SPBResumeRecording", (PyCFunction)Snd_SPBResumeRecording, 1, - PyDoc_STR("(long inRefNum) -> None")}, - {"SPBStopRecording", (PyCFunction)Snd_SPBStopRecording, 1, - PyDoc_STR("(long inRefNum) -> None")}, - {"SPBGetRecordingStatus", (PyCFunction)Snd_SPBGetRecordingStatus, 1, - PyDoc_STR("(long inRefNum) -> (short recordingStatus, short meterLevel, unsigned long totalSamplesToRecord, unsigned long numberOfSamplesRecorded, unsigned long totalMsecsToRecord, unsigned long numberOfMsecsRecorded)")}, - {"SPBGetDeviceInfo", (PyCFunction)Snd_SPBGetDeviceInfo, 1, - PyDoc_STR("(long inRefNum, OSType infoType, void * infoData) -> None")}, - {"SPBSetDeviceInfo", (PyCFunction)Snd_SPBSetDeviceInfo, 1, - PyDoc_STR("(long inRefNum, OSType infoType, void * infoData) -> None")}, - {"SPBMillisecondsToBytes", (PyCFunction)Snd_SPBMillisecondsToBytes, 1, - PyDoc_STR("(long inRefNum) -> (long milliseconds)")}, - {"SPBBytesToMilliseconds", (PyCFunction)Snd_SPBBytesToMilliseconds, 1, - PyDoc_STR("(long inRefNum) -> (long byteCount)")}, - {NULL, NULL, 0} -}; - - - -/* Routine passed to Py_AddPendingCall -- call the Python callback */ -static int -SndCh_CallCallBack(void *arg) -{ - SndChannelObject *p = (SndChannelObject *)arg; - PyObject *args; - PyObject *res; - args = Py_BuildValue("(O(hhl))", - p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2); - res = PyEval_CallObject(p->ob_callback, args); - Py_DECREF(args); - if (res == NULL) - return -1; - Py_DECREF(res); - return 0; -} - -/* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */ -static pascal void -SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd) -{ - SndChannelObject *p = (SndChannelObject *)(chan->userInfo); - if (p->ob_callback != NULL) { - long A5 = SetA5(p->ob_A5); - p->ob_cmd = *cmd; - Py_AddPendingCall(SndCh_CallCallBack, (void *)p); - SetA5(A5); - } -} - -/* SPB callbacks - Schedule callbacks to Python */ -static int -SPB_CallCallBack(void *arg) -{ - SPBObject *p = (SPBObject *)arg; - PyObject *args; - PyObject *res; - - if ( p->ob_thiscallback == 0 ) return 0; - args = Py_BuildValue("(O)", p); - res = PyEval_CallObject(p->ob_thiscallback, args); - p->ob_thiscallback = 0; - Py_DECREF(args); - if (res == NULL) - return -1; - Py_DECREF(res); - return 0; -} - -static pascal void -SPB_completion(SPBPtr my_spb) -{ - SPBObject *p = (SPBObject *)(my_spb->userLong); - - if (p && p->ob_completion) { - long A5 = SetA5(p->ob_A5); - p->ob_thiscallback = p->ob_completion; /* Hope we cannot get two at the same time */ - Py_AddPendingCall(SPB_CallCallBack, (void *)p); - SetA5(A5); - } -} - - - -void init_Snd(void) -{ - PyObject *m; - PyObject *d; - - - - - - m = Py_InitModule("_Snd", Snd_methods); - d = PyModule_GetDict(m); - Snd_Error = PyMac_GetOSErrException(); - if (Snd_Error == NULL || - PyDict_SetItemString(d, "Error", Snd_Error) != 0) - return; - Py_TYPE(&SndChannel_Type) = &PyType_Type; - if (PyType_Ready(&SndChannel_Type) < 0) return; - Py_INCREF(&SndChannel_Type); - PyModule_AddObject(m, "SndChannel", (PyObject *)&SndChannel_Type); - /* Backward-compatible name */ - Py_INCREF(&SndChannel_Type); - PyModule_AddObject(m, "SndChannelType", (PyObject *)&SndChannel_Type); - Py_TYPE(&SPB_Type) = &PyType_Type; - if (PyType_Ready(&SPB_Type) < 0) return; - Py_INCREF(&SPB_Type); - PyModule_AddObject(m, "SPB", (PyObject *)&SPB_Type); - /* Backward-compatible name */ - Py_INCREF(&SPB_Type); - PyModule_AddObject(m, "SPBType", (PyObject *)&SPB_Type); -} - -/* ======================== End module _Snd ========================= */ - diff --git a/Mac/Modules/snd/sndscan.py b/Mac/Modules/snd/sndscan.py deleted file mode 100644 index 03092ee..0000000 --- a/Mac/Modules/snd/sndscan.py +++ /dev/null @@ -1,127 +0,0 @@ -# Scan Sound.h header file, generate sndgen.py and Sound.py files. -# Then import sndsupport (which execs sndgen.py) to generate Sndmodule.c. -# (Should learn how to tell the compiler to compile it as well.) - -import sys -from bgenlocations import TOOLBOXDIR, BGENDIR -sys.path.append(BGENDIR) - -from scantools import Scanner - -def main(): - input = "Sound.h" - output = "sndgen.py" - defsoutput = TOOLBOXDIR + "Sound.py" - scanner = SoundScanner(input, output, defsoutput) - scanner.scan() - scanner.close() - print("=== Testing definitions output code ===") - exec(open(defsoutput).read(), {}, {}) - print("=== Done scanning and generating, now doing 'import sndsupport' ===") - import sndsupport - print("=== Done. It's up to you to compile Sndmodule.c ===") - -class SoundScanner(Scanner): - - def destination(self, type, name, arglist): - classname = "SndFunction" - listname = "functions" - if arglist: - t, n, m = arglist[0] - if t == "SndChannelPtr" and m == "InMode": - classname = "SndMethod" - listname = "sndmethods" - return classname, listname - - def writeinitialdefs(self): - self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") - - def makeblacklistnames(self): - return [ - 'SndDisposeChannel', # automatic on deallocation - 'SndAddModifier', # for internal use only - 'SndPlayDoubleBuffer', # very low level routine - # Missing from libraries (UH332) - 'SoundManagerSetInfo', - 'SoundManagerGetInfo', - # Constants with funny definitions - 'rate48khz', - 'rate44khz', - 'kInvalidSource', - # OS8 only: - 'MACEVersion', - 'SPBRecordToFile', - 'Exp1to6', - 'Comp6to1', - 'Exp1to3', - 'Comp3to1', - 'SndControl', - 'SndStopFilePlay', - 'SndStartFilePlay', - 'SndPauseFilePlay', - 'SndRecordToFile', - - ] - - def makeblacklisttypes(self): - return [ - "GetSoundVol", - "SetSoundVol", - "UnsignedFixed", - # Don't have the time to dig into this... - "Component", - "ComponentInstance", - "SoundComponentDataPtr", - "SoundComponentData", - "SoundComponentData_ptr", - "SoundConverter", - ] - - def makerepairinstructions(self): - return [ - ([("Str255", "*", "InMode")], - [("*", "*", "OutMode")]), - - ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], - [("InBuffer", "*", "*")]), - - ([("void", "*", "OutMode"), ("long", "*", "InMode"), - ("long", "*", "OutMode")], - [("VarVarOutBuffer", "*", "InOutMode")]), - - ([("SCStatusPtr", "*", "InMode")], - [("SCStatus", "*", "OutMode")]), - - ([("SMStatusPtr", "*", "InMode")], - [("SMStatus", "*", "OutMode")]), - - ([("CompressionInfoPtr", "*", "InMode")], - [("CompressionInfo", "*", "OutMode")]), - - # For SndPlay's SndListHandle argument - ([("Handle", "sndHdl", "InMode")], - [("SndListHandle", "*", "*")]), - - # For SndStartFilePlay - ([("long", "bufferSize", "InMode"), ("void", "theBuffer", "OutMode")], - [("*", "*", "*"), ("FakeType('0')", "*", "InMode")]), - - # For Comp3to1 etc. - ([("void_ptr", "inBuffer", "InMode"), - ("void", "outBuffer", "OutMode"), - ("unsigned_long", "cnt", "InMode")], - [("InOutBuffer", "buffer", "InOutMode")]), - - # Ditto -## ([("void_ptr", "inState", "InMode"), ("void", "outState", "OutMode")], -## [("InOutBuf128", "state", "InOutMode")]), - ([("StateBlockPtr", "inState", "InMode"), ("StateBlockPtr", "outState", "InMode")], - [("StateBlock", "state", "InOutMode")]), - - # Catch-all for the last couple of void pointers - ([("void", "*", "OutMode")], - [("void_ptr", "*", "InMode")]), - ] - -if __name__ == "__main__": - main() diff --git a/Mac/Modules/snd/sndsupport.py b/Mac/Modules/snd/sndsupport.py deleted file mode 100644 index 5c5da54..0000000 --- a/Mac/Modules/snd/sndsupport.py +++ /dev/null @@ -1,319 +0,0 @@ -# This script generates the Sound interface for Python. -# It uses the "bgen" package to generate C code. -# It execs the file sndgen.py which contain the function definitions -# (sndgen.py was generated by sndscan.py, scanning the <Sound.h> header file). - -from macsupport import * - - -# define our own function and module generators - -class SndMixIn: pass - -class SndFunction(SndMixIn, OSErrFunctionGenerator): pass -class SndMethod(SndMixIn, OSErrMethodGenerator): pass - - -# includestuff etc. are imported from macsupport - -includestuff = includestuff + """ -#include <Carbon/Carbon.h> -""" - -initstuff = initstuff + """ -""" - - -# define types used for arguments (in addition to standard and macsupport types) - -class SndChannelPtrType(OpaqueByValueType): - def declare(self, name): - # Initializing all SndChannelPtr objects to 0 saves - # special-casing NewSndChannel(), where it is formally an - # input-output parameter but we treat it as output-only - # (since Python users are not supposed to allocate memory) - Output("SndChannelPtr %s = 0;", name) - -SndChannelPtr = SndChannelPtrType('SndChannelPtr', 'SndCh') - -SndCommand = OpaqueType('SndCommand', 'SndCmd') -SndCommand_ptr = OpaqueType('SndCommand', 'SndCmd') -SndListHandle = OpaqueByValueType("SndListHandle", "ResObj") -SPBPtr = OpaqueByValueType("SPBPtr", "SPBObj") -ModalFilterUPP = FakeType("(ModalFilterUPP)0") - -# -# NOTE: the following is pretty dangerous. For void pointers we pass buffer addresses -# but we have no way to check that the buffer is big enough. This is the same problem -# as in C, though (but Pythoneers may not be suspecting this...) -void_ptr = Type("void *", "w") - -class SndCallBackType(InputOnlyType): - def __init__(self): - Type.__init__(self, 'PyObject*', 'O') - def getargsCheck(self, name): - Output("if (%s != Py_None && !PyCallable_Check(%s))", name, name) - OutLbrace() - Output('PyErr_SetString(PyExc_TypeError, "callback must be callable");') - Output("goto %s__error__;", name) - OutRbrace() - def passInput(self, name): - return "NewSndCallBackUPP(SndCh_UserRoutine)" - def cleanup(self, name): - # XXX This knows it is executing inside the SndNewChannel wrapper - Output("if (_res != NULL && %s != Py_None)", name) - OutLbrace() - Output("SndChannelObject *p = (SndChannelObject *)_res;") - Output("p->ob_itself->userInfo = (long)p;") - Output("Py_INCREF(%s);", name) - Output("p->ob_callback = %s;", name) - OutRbrace() - DedentLevel() - Output(" %s__error__: ;", name) - IndentLevel() - -SndCallBackProcPtr = SndCallBackType() -SndCallBackUPP = SndCallBackProcPtr - -SndCompletionProcPtr = FakeType('(SndCompletionProcPtr)0') # XXX -SndCompletionUPP = SndCompletionProcPtr - -##InOutBuf128 = FixedInputOutputBufferType(128) -StateBlock = StructInputOutputBufferType('StateBlock') - -AudioSelectionPtr = FakeType('0') # XXX - -ProcPtr = FakeType('0') # XXX -FilePlayCompletionUPP = FakeType('0') # XXX - -SCStatus = StructOutputBufferType('SCStatus') -SMStatus = StructOutputBufferType('SMStatus') -CompressionInfo = StructOutputBufferType('CompressionInfo') - -includestuff = includestuff + """ -/* Convert a SndCommand argument */ -static int -SndCmd_Convert(PyObject *v, SndCommand *pc) -{ - int len; - pc->param1 = 0; - pc->param2 = 0; - if (PyTuple_Check(v)) { - if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2)) - return 1; - PyErr_Clear(); - return PyArg_ParseTuple(v, "Hhs#", &pc->cmd, &pc->param1, &pc->param2, &len); - } - return PyArg_Parse(v, "H", &pc->cmd); -} - -static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */ -static pascal void SPB_completion(SPBPtr my_spb); /* Forward */ -""" - - -finalstuff = finalstuff + """ -/* Routine passed to Py_AddPendingCall -- call the Python callback */ -static int -SndCh_CallCallBack(void *arg) -{ - SndChannelObject *p = (SndChannelObject *)arg; - PyObject *args; - PyObject *res; - args = Py_BuildValue("(O(hhl))", - p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2); - res = PyEval_CallObject(p->ob_callback, args); - Py_DECREF(args); - if (res == NULL) - return -1; - Py_DECREF(res); - return 0; -} - -/* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */ -static pascal void -SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd) -{ - SndChannelObject *p = (SndChannelObject *)(chan->userInfo); - if (p->ob_callback != NULL) { - long A5 = SetA5(p->ob_A5); - p->ob_cmd = *cmd; - Py_AddPendingCall(SndCh_CallCallBack, (void *)p); - SetA5(A5); - } -} - -/* SPB callbacks - Schedule callbacks to Python */ -static int -SPB_CallCallBack(void *arg) -{ - SPBObject *p = (SPBObject *)arg; - PyObject *args; - PyObject *res; - - if ( p->ob_thiscallback == 0 ) return 0; - args = Py_BuildValue("(O)", p); - res = PyEval_CallObject(p->ob_thiscallback, args); - p->ob_thiscallback = 0; - Py_DECREF(args); - if (res == NULL) - return -1; - Py_DECREF(res); - return 0; -} - -static pascal void -SPB_completion(SPBPtr my_spb) -{ - SPBObject *p = (SPBObject *)(my_spb->userLong); - - if (p && p->ob_completion) { - long A5 = SetA5(p->ob_A5); - p->ob_thiscallback = p->ob_completion; /* Hope we cannot get two at the same time */ - Py_AddPendingCall(SPB_CallCallBack, (void *)p); - SetA5(A5); - } -} - -""" - - -# create the module and object definition and link them - -class SndObjectDefinition(PEP252Mixin, ObjectDefinition): - - def outputStructMembers(self): - ObjectDefinition.outputStructMembers(self) - Output("/* Members used to implement callbacks: */") - Output("PyObject *ob_callback;") - Output("long ob_A5;"); - Output("SndCommand ob_cmd;") - - def outputInitStructMembers(self): - ObjectDefinition.outputInitStructMembers(self) - Output("it->ob_callback = NULL;") - Output("it->ob_A5 = SetCurrentA5();"); - - def outputCleanupStructMembers(self): - ObjectDefinition.outputCleanupStructMembers(self) - Output("Py_XDECREF(self->ob_callback);") - - def outputFreeIt(self, itselfname): - Output("SndDisposeChannel(%s, 1);", itselfname) - - def outputConvert(self): - pass # Not needed - -# - -class SpbObjectDefinition(PEP252Mixin, ObjectDefinition): - getsetlist = [ - ( - 'inRefNum', - 'return Py_BuildValue("l", self->ob_spb.inRefNum);', - 'return -1 + PyArg_Parse(v, "l", &self->ob_spb.inRefNum);', - None, - ), ( - 'count', - 'return Py_BuildValue("l", self->ob_spb.count);', - 'return -1 + PyArg_Parse(v, "l", &self->ob_spb.count);', - None - ), ( - 'milliseconds', - 'return Py_BuildValue("l", self->ob_spb.milliseconds);', - 'return -1 + PyArg_Parse(v, "l", &self->ob_spb.milliseconds);', - None, - ), ( - 'error', - 'return Py_BuildValue("h", self->ob_spb.error);', - None, - None - ), ( - 'completionRoutine', - None, - """self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion); - self->ob_completion = v; - Py_INCREF(v); - return 0;""", - None, - )] - - def outputStructMembers(self): - Output("/* Members used to implement callbacks: */") - Output("PyObject *ob_completion;") - Output("PyObject *ob_interrupt;") - Output("PyObject *ob_thiscallback;"); - Output("long ob_A5;") - Output("SPB ob_spb;") - - def outputNew(self): - Output() - Output("%sPyObject *%s_New(void)", self.static, self.prefix) - OutLbrace() - Output("%s *it;", self.objecttype) - self.outputCheckNewArg() - Output("it = PyObject_NEW(%s, &%s);", self.objecttype, self.typename) - Output("if (it == NULL) return NULL;") - self.outputInitStructMembers() - Output("return (PyObject *)it;") - OutRbrace() - - def outputInitStructMembers(self): - Output("it->ob_completion = NULL;") - Output("it->ob_interrupt = NULL;") - Output("it->ob_thiscallback = NULL;") - Output("it->ob_A5 = SetCurrentA5();") - Output("memset((char *)&it->ob_spb, 0, sizeof(it->ob_spb));") - Output("it->ob_spb.userLong = (long)it;") - - def outputCleanupStructMembers(self): - ObjectDefinition.outputCleanupStructMembers(self) - Output("self->ob_spb.userLong = 0;") - Output("self->ob_thiscallback = 0;") - Output("Py_XDECREF(self->ob_completion);") - Output("Py_XDECREF(self->ob_interrupt);") - - def outputConvert(self): - Output("%sint %s_Convert(PyObject *v, %s *p_itself)", self.static, self.prefix, self.itselftype) - OutLbrace() - self.outputCheckConvertArg() - Output("if (!%s_Check(v))", self.prefix) - OutLbrace() - Output('PyErr_SetString(PyExc_TypeError, "%s required");', self.name) - Output("return 0;") - OutRbrace() - Output("*p_itself = &((%s *)v)->ob_spb;", self.objecttype) - Output("return 1;") - OutRbrace() - - -sndobject = SndObjectDefinition('SndChannel', 'SndCh', 'SndChannelPtr') -spbobject = SpbObjectDefinition('SPB', 'SPBObj', 'SPBPtr') -spbgenerator = ManualGenerator("SPB", "_res = SPBObj_New(); return _res;") -module = MacModule('_Snd', 'Snd', includestuff, finalstuff, initstuff) -module.addobject(sndobject) -module.addobject(spbobject) -module.add(spbgenerator) - - -# create lists of functions and object methods - -functions = [] -sndmethods = [] - - -# populate the lists - -exec(open('sndgen.py').read()) - - -# add the functions and methods to the module and object, respectively - -for f in functions: module.add(f) -for f in sndmethods: sndobject.add(f) - - -# generate output - -SetOutputFileName('_Sndmodule.c') -module.generate() |