| 1 | n/a | |
|---|
| 2 | n/a | /* ========================== Module _Snd =========================== */ |
|---|
| 3 | n/a | |
|---|
| 4 | n/a | #include "Python.h" |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | #ifndef __LP64__ |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | |
|---|
| 9 | n/a | #include "pymactoolbox.h" |
|---|
| 10 | n/a | |
|---|
| 11 | n/a | /* Macro to test whether a weak-loaded CFM function exists */ |
|---|
| 12 | n/a | #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ |
|---|
| 13 | n/a | PyErr_SetString(PyExc_NotImplementedError, \ |
|---|
| 14 | n/a | "Not available in this shared library/OS version"); \ |
|---|
| 15 | n/a | return NULL; \ |
|---|
| 16 | n/a | }} while(0) |
|---|
| 17 | n/a | |
|---|
| 18 | n/a | |
|---|
| 19 | n/a | #include <Carbon/Carbon.h> |
|---|
| 20 | n/a | |
|---|
| 21 | n/a | /* Convert a SndCommand argument */ |
|---|
| 22 | n/a | static int |
|---|
| 23 | n/a | SndCmd_Convert(PyObject *v, SndCommand *pc) |
|---|
| 24 | n/a | { |
|---|
| 25 | n/a | int len; |
|---|
| 26 | n/a | pc->param1 = 0; |
|---|
| 27 | n/a | pc->param2 = 0; |
|---|
| 28 | n/a | if (PyTuple_Check(v)) { |
|---|
| 29 | n/a | if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2)) |
|---|
| 30 | n/a | return 1; |
|---|
| 31 | n/a | PyErr_Clear(); |
|---|
| 32 | n/a | return PyArg_ParseTuple(v, "Hhs#", &pc->cmd, &pc->param1, &pc->param2, &len); |
|---|
| 33 | n/a | } |
|---|
| 34 | n/a | return PyArg_Parse(v, "H", &pc->cmd); |
|---|
| 35 | n/a | } |
|---|
| 36 | n/a | |
|---|
| 37 | n/a | static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */ |
|---|
| 38 | n/a | static pascal void SPB_completion(SPBPtr my_spb); /* Forward */ |
|---|
| 39 | n/a | |
|---|
| 40 | n/a | static PyObject *Snd_Error; |
|---|
| 41 | n/a | |
|---|
| 42 | n/a | /* --------------------- Object type SndChannel --------------------- */ |
|---|
| 43 | n/a | |
|---|
| 44 | n/a | static PyTypeObject SndChannel_Type; |
|---|
| 45 | n/a | |
|---|
| 46 | n/a | #define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type || PyObject_TypeCheck((x), &SndChannel_Type)) |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | typedef struct SndChannelObject { |
|---|
| 49 | n/a | PyObject_HEAD |
|---|
| 50 | n/a | SndChannelPtr ob_itself; |
|---|
| 51 | n/a | /* Members used to implement callbacks: */ |
|---|
| 52 | n/a | PyObject *ob_callback; |
|---|
| 53 | n/a | long ob_A5; |
|---|
| 54 | n/a | SndCommand ob_cmd; |
|---|
| 55 | n/a | } SndChannelObject; |
|---|
| 56 | n/a | |
|---|
| 57 | n/a | static PyObject *SndCh_New(SndChannelPtr itself) |
|---|
| 58 | n/a | { |
|---|
| 59 | n/a | SndChannelObject *it; |
|---|
| 60 | n/a | it = PyObject_NEW(SndChannelObject, &SndChannel_Type); |
|---|
| 61 | n/a | if (it == NULL) return NULL; |
|---|
| 62 | n/a | it->ob_itself = itself; |
|---|
| 63 | n/a | it->ob_callback = NULL; |
|---|
| 64 | n/a | it->ob_A5 = SetCurrentA5(); |
|---|
| 65 | n/a | return (PyObject *)it; |
|---|
| 66 | n/a | } |
|---|
| 67 | n/a | |
|---|
| 68 | n/a | static void SndCh_dealloc(SndChannelObject *self) |
|---|
| 69 | n/a | { |
|---|
| 70 | n/a | SndDisposeChannel(self->ob_itself, 1); |
|---|
| 71 | n/a | Py_XDECREF(self->ob_callback); |
|---|
| 72 | n/a | PyObject_Free((PyObject *)self); |
|---|
| 73 | n/a | } |
|---|
| 74 | n/a | |
|---|
| 75 | n/a | static PyObject *SndCh_SndDoCommand(SndChannelObject *_self, PyObject *_args) |
|---|
| 76 | n/a | { |
|---|
| 77 | n/a | PyObject *_res = NULL; |
|---|
| 78 | n/a | OSErr _err; |
|---|
| 79 | n/a | SndCommand cmd; |
|---|
| 80 | n/a | Boolean noWait; |
|---|
| 81 | n/a | if (!PyArg_ParseTuple(_args, "O&b", |
|---|
| 82 | n/a | SndCmd_Convert, &cmd, |
|---|
| 83 | n/a | &noWait)) |
|---|
| 84 | n/a | return NULL; |
|---|
| 85 | n/a | _err = SndDoCommand(_self->ob_itself, |
|---|
| 86 | n/a | &cmd, |
|---|
| 87 | n/a | noWait); |
|---|
| 88 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 89 | n/a | Py_INCREF(Py_None); |
|---|
| 90 | n/a | _res = Py_None; |
|---|
| 91 | n/a | return _res; |
|---|
| 92 | n/a | } |
|---|
| 93 | n/a | |
|---|
| 94 | n/a | static PyObject *SndCh_SndDoImmediate(SndChannelObject *_self, PyObject *_args) |
|---|
| 95 | n/a | { |
|---|
| 96 | n/a | PyObject *_res = NULL; |
|---|
| 97 | n/a | OSErr _err; |
|---|
| 98 | n/a | SndCommand cmd; |
|---|
| 99 | n/a | if (!PyArg_ParseTuple(_args, "O&", |
|---|
| 100 | n/a | SndCmd_Convert, &cmd)) |
|---|
| 101 | n/a | return NULL; |
|---|
| 102 | n/a | _err = SndDoImmediate(_self->ob_itself, |
|---|
| 103 | n/a | &cmd); |
|---|
| 104 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 105 | n/a | Py_INCREF(Py_None); |
|---|
| 106 | n/a | _res = Py_None; |
|---|
| 107 | n/a | return _res; |
|---|
| 108 | n/a | } |
|---|
| 109 | n/a | |
|---|
| 110 | n/a | static PyObject *SndCh_SndPlay(SndChannelObject *_self, PyObject *_args) |
|---|
| 111 | n/a | { |
|---|
| 112 | n/a | PyObject *_res = NULL; |
|---|
| 113 | n/a | OSErr _err; |
|---|
| 114 | n/a | SndListHandle sndHandle; |
|---|
| 115 | n/a | Boolean async; |
|---|
| 116 | n/a | if (!PyArg_ParseTuple(_args, "O&b", |
|---|
| 117 | n/a | ResObj_Convert, &sndHandle, |
|---|
| 118 | n/a | &async)) |
|---|
| 119 | n/a | return NULL; |
|---|
| 120 | n/a | _err = SndPlay(_self->ob_itself, |
|---|
| 121 | n/a | sndHandle, |
|---|
| 122 | n/a | async); |
|---|
| 123 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 124 | n/a | Py_INCREF(Py_None); |
|---|
| 125 | n/a | _res = Py_None; |
|---|
| 126 | n/a | return _res; |
|---|
| 127 | n/a | } |
|---|
| 128 | n/a | |
|---|
| 129 | n/a | static PyObject *SndCh_SndChannelStatus(SndChannelObject *_self, PyObject *_args) |
|---|
| 130 | n/a | { |
|---|
| 131 | n/a | PyObject *_res = NULL; |
|---|
| 132 | n/a | OSErr _err; |
|---|
| 133 | n/a | short theLength; |
|---|
| 134 | n/a | SCStatus theStatus__out__; |
|---|
| 135 | n/a | if (!PyArg_ParseTuple(_args, "h", |
|---|
| 136 | n/a | &theLength)) |
|---|
| 137 | n/a | return NULL; |
|---|
| 138 | n/a | _err = SndChannelStatus(_self->ob_itself, |
|---|
| 139 | n/a | theLength, |
|---|
| 140 | n/a | &theStatus__out__); |
|---|
| 141 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 142 | n/a | _res = Py_BuildValue("s#", |
|---|
| 143 | n/a | (char *)&theStatus__out__, (int)sizeof(SCStatus)); |
|---|
| 144 | n/a | return _res; |
|---|
| 145 | n/a | } |
|---|
| 146 | n/a | |
|---|
| 147 | n/a | static PyObject *SndCh_SndGetInfo(SndChannelObject *_self, PyObject *_args) |
|---|
| 148 | n/a | { |
|---|
| 149 | n/a | PyObject *_res = NULL; |
|---|
| 150 | n/a | OSErr _err; |
|---|
| 151 | n/a | OSType selector; |
|---|
| 152 | n/a | void * infoPtr; |
|---|
| 153 | n/a | if (!PyArg_ParseTuple(_args, "O&w", |
|---|
| 154 | n/a | PyMac_GetOSType, &selector, |
|---|
| 155 | n/a | &infoPtr)) |
|---|
| 156 | n/a | return NULL; |
|---|
| 157 | n/a | _err = SndGetInfo(_self->ob_itself, |
|---|
| 158 | n/a | selector, |
|---|
| 159 | n/a | infoPtr); |
|---|
| 160 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 161 | n/a | Py_INCREF(Py_None); |
|---|
| 162 | n/a | _res = Py_None; |
|---|
| 163 | n/a | return _res; |
|---|
| 164 | n/a | } |
|---|
| 165 | n/a | |
|---|
| 166 | n/a | static PyObject *SndCh_SndSetInfo(SndChannelObject *_self, PyObject *_args) |
|---|
| 167 | n/a | { |
|---|
| 168 | n/a | PyObject *_res = NULL; |
|---|
| 169 | n/a | OSErr _err; |
|---|
| 170 | n/a | OSType selector; |
|---|
| 171 | n/a | void * infoPtr; |
|---|
| 172 | n/a | if (!PyArg_ParseTuple(_args, "O&w", |
|---|
| 173 | n/a | PyMac_GetOSType, &selector, |
|---|
| 174 | n/a | &infoPtr)) |
|---|
| 175 | n/a | return NULL; |
|---|
| 176 | n/a | _err = SndSetInfo(_self->ob_itself, |
|---|
| 177 | n/a | selector, |
|---|
| 178 | n/a | infoPtr); |
|---|
| 179 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 180 | n/a | Py_INCREF(Py_None); |
|---|
| 181 | n/a | _res = Py_None; |
|---|
| 182 | n/a | return _res; |
|---|
| 183 | n/a | } |
|---|
| 184 | n/a | |
|---|
| 185 | n/a | static PyMethodDef SndCh_methods[] = { |
|---|
| 186 | n/a | {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1, |
|---|
| 187 | n/a | PyDoc_STR("(SndCommand cmd, Boolean noWait) -> None")}, |
|---|
| 188 | n/a | {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1, |
|---|
| 189 | n/a | PyDoc_STR("(SndCommand cmd) -> None")}, |
|---|
| 190 | n/a | {"SndPlay", (PyCFunction)SndCh_SndPlay, 1, |
|---|
| 191 | n/a | PyDoc_STR("(SndListHandle sndHandle, Boolean async) -> None")}, |
|---|
| 192 | n/a | {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1, |
|---|
| 193 | n/a | PyDoc_STR("(short theLength) -> (SCStatus theStatus)")}, |
|---|
| 194 | n/a | {"SndGetInfo", (PyCFunction)SndCh_SndGetInfo, 1, |
|---|
| 195 | n/a | PyDoc_STR("(OSType selector, void * infoPtr) -> None")}, |
|---|
| 196 | n/a | {"SndSetInfo", (PyCFunction)SndCh_SndSetInfo, 1, |
|---|
| 197 | n/a | PyDoc_STR("(OSType selector, void * infoPtr) -> None")}, |
|---|
| 198 | n/a | {NULL, NULL, 0} |
|---|
| 199 | n/a | }; |
|---|
| 200 | n/a | |
|---|
| 201 | n/a | #define SndCh_getsetlist NULL |
|---|
| 202 | n/a | |
|---|
| 203 | n/a | |
|---|
| 204 | n/a | #define SndCh_compare NULL |
|---|
| 205 | n/a | |
|---|
| 206 | n/a | #define SndCh_repr NULL |
|---|
| 207 | n/a | |
|---|
| 208 | n/a | #define SndCh_hash NULL |
|---|
| 209 | n/a | |
|---|
| 210 | n/a | static PyTypeObject SndChannel_Type = { |
|---|
| 211 | n/a | PyObject_HEAD_INIT(NULL) |
|---|
| 212 | n/a | 0, /*ob_size*/ |
|---|
| 213 | n/a | "_Snd.SndChannel", /*tp_name*/ |
|---|
| 214 | n/a | sizeof(SndChannelObject), /*tp_basicsize*/ |
|---|
| 215 | n/a | 0, /*tp_itemsize*/ |
|---|
| 216 | n/a | /* methods */ |
|---|
| 217 | n/a | (destructor) SndCh_dealloc, /*tp_dealloc*/ |
|---|
| 218 | n/a | 0, /*tp_print*/ |
|---|
| 219 | n/a | (getattrfunc)0, /*tp_getattr*/ |
|---|
| 220 | n/a | (setattrfunc)0, /*tp_setattr*/ |
|---|
| 221 | n/a | (cmpfunc) SndCh_compare, /*tp_compare*/ |
|---|
| 222 | n/a | (reprfunc) SndCh_repr, /*tp_repr*/ |
|---|
| 223 | n/a | (PyNumberMethods *)0, /* tp_as_number */ |
|---|
| 224 | n/a | (PySequenceMethods *)0, /* tp_as_sequence */ |
|---|
| 225 | n/a | (PyMappingMethods *)0, /* tp_as_mapping */ |
|---|
| 226 | n/a | (hashfunc) SndCh_hash, /*tp_hash*/ |
|---|
| 227 | n/a | 0, /*tp_call*/ |
|---|
| 228 | n/a | 0, /*tp_str*/ |
|---|
| 229 | n/a | PyObject_GenericGetAttr, /*tp_getattro*/ |
|---|
| 230 | n/a | PyObject_GenericSetAttr, /*tp_setattro */ |
|---|
| 231 | n/a | 0, /*tp_as_buffer*/ |
|---|
| 232 | n/a | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|---|
| 233 | n/a | 0, /*tp_doc*/ |
|---|
| 234 | n/a | 0, /*tp_traverse*/ |
|---|
| 235 | n/a | 0, /*tp_clear*/ |
|---|
| 236 | n/a | 0, /*tp_richcompare*/ |
|---|
| 237 | n/a | 0, /*tp_weaklistoffset*/ |
|---|
| 238 | n/a | 0, /*tp_iter*/ |
|---|
| 239 | n/a | 0, /*tp_iternext*/ |
|---|
| 240 | n/a | SndCh_methods, /* tp_methods */ |
|---|
| 241 | n/a | 0, /*tp_members*/ |
|---|
| 242 | n/a | SndCh_getsetlist, /*tp_getset*/ |
|---|
| 243 | n/a | 0, /*tp_base*/ |
|---|
| 244 | n/a | 0, /*tp_dict*/ |
|---|
| 245 | n/a | 0, /*tp_descr_get*/ |
|---|
| 246 | n/a | 0, /*tp_descr_set*/ |
|---|
| 247 | n/a | 0, /*tp_dictoffset*/ |
|---|
| 248 | n/a | 0, /*tp_init*/ |
|---|
| 249 | n/a | 0, /*tp_alloc*/ |
|---|
| 250 | n/a | 0, /*tp_new*/ |
|---|
| 251 | n/a | 0, /*tp_free*/ |
|---|
| 252 | n/a | }; |
|---|
| 253 | n/a | |
|---|
| 254 | n/a | /* ------------------- End object type SndChannel ------------------- */ |
|---|
| 255 | n/a | |
|---|
| 256 | n/a | |
|---|
| 257 | n/a | /* ------------------------ Object type SPB ------------------------- */ |
|---|
| 258 | n/a | |
|---|
| 259 | n/a | static PyTypeObject SPB_Type; |
|---|
| 260 | n/a | |
|---|
| 261 | n/a | #define SPBObj_Check(x) ((x)->ob_type == &SPB_Type || PyObject_TypeCheck((x), &SPB_Type)) |
|---|
| 262 | n/a | |
|---|
| 263 | n/a | typedef struct SPBObject { |
|---|
| 264 | n/a | PyObject_HEAD |
|---|
| 265 | n/a | /* Members used to implement callbacks: */ |
|---|
| 266 | n/a | PyObject *ob_completion; |
|---|
| 267 | n/a | PyObject *ob_interrupt; |
|---|
| 268 | n/a | PyObject *ob_thiscallback; |
|---|
| 269 | n/a | long ob_A5; |
|---|
| 270 | n/a | SPB ob_spb; |
|---|
| 271 | n/a | } SPBObject; |
|---|
| 272 | n/a | |
|---|
| 273 | n/a | static PyObject *SPBObj_New(void) |
|---|
| 274 | n/a | { |
|---|
| 275 | n/a | SPBObject *it; |
|---|
| 276 | n/a | it = PyObject_NEW(SPBObject, &SPB_Type); |
|---|
| 277 | n/a | if (it == NULL) return NULL; |
|---|
| 278 | n/a | it->ob_completion = NULL; |
|---|
| 279 | n/a | it->ob_interrupt = NULL; |
|---|
| 280 | n/a | it->ob_thiscallback = NULL; |
|---|
| 281 | n/a | it->ob_A5 = SetCurrentA5(); |
|---|
| 282 | n/a | memset((char *)&it->ob_spb, 0, sizeof(it->ob_spb)); |
|---|
| 283 | n/a | it->ob_spb.userLong = (long)it; |
|---|
| 284 | n/a | return (PyObject *)it; |
|---|
| 285 | n/a | } |
|---|
| 286 | n/a | static int SPBObj_Convert(PyObject *v, SPBPtr *p_itself) |
|---|
| 287 | n/a | { |
|---|
| 288 | n/a | if (!SPBObj_Check(v)) |
|---|
| 289 | n/a | { |
|---|
| 290 | n/a | PyErr_SetString(PyExc_TypeError, "SPB required"); |
|---|
| 291 | n/a | return 0; |
|---|
| 292 | n/a | } |
|---|
| 293 | n/a | *p_itself = &((SPBObject *)v)->ob_spb; |
|---|
| 294 | n/a | return 1; |
|---|
| 295 | n/a | } |
|---|
| 296 | n/a | |
|---|
| 297 | n/a | static void SPBObj_dealloc(SPBObject *self) |
|---|
| 298 | n/a | { |
|---|
| 299 | n/a | /* Cleanup of self->ob_itself goes here */ |
|---|
| 300 | n/a | self->ob_spb.userLong = 0; |
|---|
| 301 | n/a | self->ob_thiscallback = 0; |
|---|
| 302 | n/a | Py_XDECREF(self->ob_completion); |
|---|
| 303 | n/a | Py_XDECREF(self->ob_interrupt); |
|---|
| 304 | n/a | PyObject_Free((PyObject *)self); |
|---|
| 305 | n/a | } |
|---|
| 306 | n/a | |
|---|
| 307 | n/a | static PyMethodDef SPBObj_methods[] = { |
|---|
| 308 | n/a | {NULL, NULL, 0} |
|---|
| 309 | n/a | }; |
|---|
| 310 | n/a | |
|---|
| 311 | n/a | static PyObject *SPBObj_get_inRefNum(SPBObject *self, void *closure) |
|---|
| 312 | n/a | { |
|---|
| 313 | n/a | return Py_BuildValue("l", self->ob_spb.inRefNum); |
|---|
| 314 | n/a | } |
|---|
| 315 | n/a | |
|---|
| 316 | n/a | static int SPBObj_set_inRefNum(SPBObject *self, PyObject *v, void *closure) |
|---|
| 317 | n/a | { |
|---|
| 318 | n/a | return -1 + PyArg_Parse(v, "l", &self->ob_spb.inRefNum); |
|---|
| 319 | n/a | return 0; |
|---|
| 320 | n/a | } |
|---|
| 321 | n/a | |
|---|
| 322 | n/a | static PyObject *SPBObj_get_count(SPBObject *self, void *closure) |
|---|
| 323 | n/a | { |
|---|
| 324 | n/a | return Py_BuildValue("l", self->ob_spb.count); |
|---|
| 325 | n/a | } |
|---|
| 326 | n/a | |
|---|
| 327 | n/a | static int SPBObj_set_count(SPBObject *self, PyObject *v, void *closure) |
|---|
| 328 | n/a | { |
|---|
| 329 | n/a | return -1 + PyArg_Parse(v, "l", &self->ob_spb.count); |
|---|
| 330 | n/a | return 0; |
|---|
| 331 | n/a | } |
|---|
| 332 | n/a | |
|---|
| 333 | n/a | static PyObject *SPBObj_get_milliseconds(SPBObject *self, void *closure) |
|---|
| 334 | n/a | { |
|---|
| 335 | n/a | return Py_BuildValue("l", self->ob_spb.milliseconds); |
|---|
| 336 | n/a | } |
|---|
| 337 | n/a | |
|---|
| 338 | n/a | static int SPBObj_set_milliseconds(SPBObject *self, PyObject *v, void *closure) |
|---|
| 339 | n/a | { |
|---|
| 340 | n/a | return -1 + PyArg_Parse(v, "l", &self->ob_spb.milliseconds); |
|---|
| 341 | n/a | return 0; |
|---|
| 342 | n/a | } |
|---|
| 343 | n/a | |
|---|
| 344 | n/a | static PyObject *SPBObj_get_error(SPBObject *self, void *closure) |
|---|
| 345 | n/a | { |
|---|
| 346 | n/a | return Py_BuildValue("h", self->ob_spb.error); |
|---|
| 347 | n/a | } |
|---|
| 348 | n/a | |
|---|
| 349 | n/a | #define SPBObj_set_error NULL |
|---|
| 350 | n/a | |
|---|
| 351 | n/a | #define SPBObj_get_completionRoutine NULL |
|---|
| 352 | n/a | |
|---|
| 353 | n/a | static int SPBObj_set_completionRoutine(SPBObject *self, PyObject *v, void *closure) |
|---|
| 354 | n/a | { |
|---|
| 355 | n/a | self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion); |
|---|
| 356 | n/a | self->ob_completion = v; |
|---|
| 357 | n/a | Py_INCREF(v); |
|---|
| 358 | n/a | return 0; |
|---|
| 359 | n/a | return 0; |
|---|
| 360 | n/a | } |
|---|
| 361 | n/a | |
|---|
| 362 | n/a | static PyGetSetDef SPBObj_getsetlist[] = { |
|---|
| 363 | n/a | {"inRefNum", (getter)SPBObj_get_inRefNum, (setter)SPBObj_set_inRefNum, NULL}, |
|---|
| 364 | n/a | {"count", (getter)SPBObj_get_count, (setter)SPBObj_set_count, NULL}, |
|---|
| 365 | n/a | {"milliseconds", (getter)SPBObj_get_milliseconds, (setter)SPBObj_set_milliseconds, NULL}, |
|---|
| 366 | n/a | {"error", (getter)SPBObj_get_error, (setter)SPBObj_set_error, NULL}, |
|---|
| 367 | n/a | {"completionRoutine", (getter)SPBObj_get_completionRoutine, (setter)SPBObj_set_completionRoutine, NULL}, |
|---|
| 368 | n/a | {NULL, NULL, NULL, NULL}, |
|---|
| 369 | n/a | }; |
|---|
| 370 | n/a | |
|---|
| 371 | n/a | |
|---|
| 372 | n/a | #define SPBObj_compare NULL |
|---|
| 373 | n/a | |
|---|
| 374 | n/a | #define SPBObj_repr NULL |
|---|
| 375 | n/a | |
|---|
| 376 | n/a | #define SPBObj_hash NULL |
|---|
| 377 | n/a | |
|---|
| 378 | n/a | static PyTypeObject SPB_Type = { |
|---|
| 379 | n/a | PyObject_HEAD_INIT(NULL) |
|---|
| 380 | n/a | 0, /*ob_size*/ |
|---|
| 381 | n/a | "_Snd.SPB", /*tp_name*/ |
|---|
| 382 | n/a | sizeof(SPBObject), /*tp_basicsize*/ |
|---|
| 383 | n/a | 0, /*tp_itemsize*/ |
|---|
| 384 | n/a | /* methods */ |
|---|
| 385 | n/a | (destructor) SPBObj_dealloc, /*tp_dealloc*/ |
|---|
| 386 | n/a | 0, /*tp_print*/ |
|---|
| 387 | n/a | (getattrfunc)0, /*tp_getattr*/ |
|---|
| 388 | n/a | (setattrfunc)0, /*tp_setattr*/ |
|---|
| 389 | n/a | (cmpfunc) SPBObj_compare, /*tp_compare*/ |
|---|
| 390 | n/a | (reprfunc) SPBObj_repr, /*tp_repr*/ |
|---|
| 391 | n/a | (PyNumberMethods *)0, /* tp_as_number */ |
|---|
| 392 | n/a | (PySequenceMethods *)0, /* tp_as_sequence */ |
|---|
| 393 | n/a | (PyMappingMethods *)0, /* tp_as_mapping */ |
|---|
| 394 | n/a | (hashfunc) SPBObj_hash, /*tp_hash*/ |
|---|
| 395 | n/a | 0, /*tp_call*/ |
|---|
| 396 | n/a | 0, /*tp_str*/ |
|---|
| 397 | n/a | PyObject_GenericGetAttr, /*tp_getattro*/ |
|---|
| 398 | n/a | PyObject_GenericSetAttr, /*tp_setattro */ |
|---|
| 399 | n/a | 0, /*tp_as_buffer*/ |
|---|
| 400 | n/a | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|---|
| 401 | n/a | 0, /*tp_doc*/ |
|---|
| 402 | n/a | 0, /*tp_traverse*/ |
|---|
| 403 | n/a | 0, /*tp_clear*/ |
|---|
| 404 | n/a | 0, /*tp_richcompare*/ |
|---|
| 405 | n/a | 0, /*tp_weaklistoffset*/ |
|---|
| 406 | n/a | 0, /*tp_iter*/ |
|---|
| 407 | n/a | 0, /*tp_iternext*/ |
|---|
| 408 | n/a | SPBObj_methods, /* tp_methods */ |
|---|
| 409 | n/a | 0, /*tp_members*/ |
|---|
| 410 | n/a | SPBObj_getsetlist, /*tp_getset*/ |
|---|
| 411 | n/a | 0, /*tp_base*/ |
|---|
| 412 | n/a | 0, /*tp_dict*/ |
|---|
| 413 | n/a | 0, /*tp_descr_get*/ |
|---|
| 414 | n/a | 0, /*tp_descr_set*/ |
|---|
| 415 | n/a | 0, /*tp_dictoffset*/ |
|---|
| 416 | n/a | 0, /*tp_init*/ |
|---|
| 417 | n/a | 0, /*tp_alloc*/ |
|---|
| 418 | n/a | 0, /*tp_new*/ |
|---|
| 419 | n/a | 0, /*tp_free*/ |
|---|
| 420 | n/a | }; |
|---|
| 421 | n/a | |
|---|
| 422 | n/a | /* ---------------------- End object type SPB ----------------------- */ |
|---|
| 423 | n/a | |
|---|
| 424 | n/a | |
|---|
| 425 | n/a | static PyObject *Snd_SPB(PyObject *_self, PyObject *_args) |
|---|
| 426 | n/a | { |
|---|
| 427 | n/a | PyObject *_res = NULL; |
|---|
| 428 | n/a | _res = SPBObj_New(); return _res; |
|---|
| 429 | n/a | } |
|---|
| 430 | n/a | |
|---|
| 431 | n/a | static PyObject *Snd_SysBeep(PyObject *_self, PyObject *_args) |
|---|
| 432 | n/a | { |
|---|
| 433 | n/a | PyObject *_res = NULL; |
|---|
| 434 | n/a | short duration; |
|---|
| 435 | n/a | if (!PyArg_ParseTuple(_args, "h", |
|---|
| 436 | n/a | &duration)) |
|---|
| 437 | n/a | return NULL; |
|---|
| 438 | n/a | SysBeep(duration); |
|---|
| 439 | n/a | Py_INCREF(Py_None); |
|---|
| 440 | n/a | _res = Py_None; |
|---|
| 441 | n/a | return _res; |
|---|
| 442 | n/a | } |
|---|
| 443 | n/a | |
|---|
| 444 | n/a | static PyObject *Snd_SndNewChannel(PyObject *_self, PyObject *_args) |
|---|
| 445 | n/a | { |
|---|
| 446 | n/a | PyObject *_res = NULL; |
|---|
| 447 | n/a | OSErr _err; |
|---|
| 448 | n/a | SndChannelPtr chan = 0; |
|---|
| 449 | n/a | short synth; |
|---|
| 450 | n/a | long init; |
|---|
| 451 | n/a | PyObject* userRoutine; |
|---|
| 452 | n/a | if (!PyArg_ParseTuple(_args, "hlO", |
|---|
| 453 | n/a | &synth, |
|---|
| 454 | n/a | &init, |
|---|
| 455 | n/a | &userRoutine)) |
|---|
| 456 | n/a | return NULL; |
|---|
| 457 | n/a | if (userRoutine != Py_None && !PyCallable_Check(userRoutine)) |
|---|
| 458 | n/a | { |
|---|
| 459 | n/a | PyErr_SetString(PyExc_TypeError, "callback must be callable"); |
|---|
| 460 | n/a | goto userRoutine__error__; |
|---|
| 461 | n/a | } |
|---|
| 462 | n/a | _err = SndNewChannel(&chan, |
|---|
| 463 | n/a | synth, |
|---|
| 464 | n/a | init, |
|---|
| 465 | n/a | NewSndCallBackUPP(SndCh_UserRoutine)); |
|---|
| 466 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 467 | n/a | _res = Py_BuildValue("O&", |
|---|
| 468 | n/a | SndCh_New, chan); |
|---|
| 469 | n/a | if (_res != NULL && userRoutine != Py_None) |
|---|
| 470 | n/a | { |
|---|
| 471 | n/a | SndChannelObject *p = (SndChannelObject *)_res; |
|---|
| 472 | n/a | p->ob_itself->userInfo = (long)p; |
|---|
| 473 | n/a | Py_INCREF(userRoutine); |
|---|
| 474 | n/a | p->ob_callback = userRoutine; |
|---|
| 475 | n/a | } |
|---|
| 476 | n/a | userRoutine__error__: ; |
|---|
| 477 | n/a | return _res; |
|---|
| 478 | n/a | } |
|---|
| 479 | n/a | |
|---|
| 480 | n/a | static PyObject *Snd_SndSoundManagerVersion(PyObject *_self, PyObject *_args) |
|---|
| 481 | n/a | { |
|---|
| 482 | n/a | PyObject *_res = NULL; |
|---|
| 483 | n/a | NumVersion _rv; |
|---|
| 484 | n/a | if (!PyArg_ParseTuple(_args, "")) |
|---|
| 485 | n/a | return NULL; |
|---|
| 486 | n/a | _rv = SndSoundManagerVersion(); |
|---|
| 487 | n/a | _res = Py_BuildValue("O&", |
|---|
| 488 | n/a | PyMac_BuildNumVersion, _rv); |
|---|
| 489 | n/a | return _res; |
|---|
| 490 | n/a | } |
|---|
| 491 | n/a | |
|---|
| 492 | n/a | static PyObject *Snd_SndManagerStatus(PyObject *_self, PyObject *_args) |
|---|
| 493 | n/a | { |
|---|
| 494 | n/a | PyObject *_res = NULL; |
|---|
| 495 | n/a | OSErr _err; |
|---|
| 496 | n/a | short theLength; |
|---|
| 497 | n/a | SMStatus theStatus__out__; |
|---|
| 498 | n/a | if (!PyArg_ParseTuple(_args, "h", |
|---|
| 499 | n/a | &theLength)) |
|---|
| 500 | n/a | return NULL; |
|---|
| 501 | n/a | _err = SndManagerStatus(theLength, |
|---|
| 502 | n/a | &theStatus__out__); |
|---|
| 503 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 504 | n/a | _res = Py_BuildValue("s#", |
|---|
| 505 | n/a | (char *)&theStatus__out__, (int)sizeof(SMStatus)); |
|---|
| 506 | n/a | return _res; |
|---|
| 507 | n/a | } |
|---|
| 508 | n/a | |
|---|
| 509 | n/a | static PyObject *Snd_SndGetSysBeepState(PyObject *_self, PyObject *_args) |
|---|
| 510 | n/a | { |
|---|
| 511 | n/a | PyObject *_res = NULL; |
|---|
| 512 | n/a | short sysBeepState; |
|---|
| 513 | n/a | if (!PyArg_ParseTuple(_args, "")) |
|---|
| 514 | n/a | return NULL; |
|---|
| 515 | n/a | SndGetSysBeepState(&sysBeepState); |
|---|
| 516 | n/a | _res = Py_BuildValue("h", |
|---|
| 517 | n/a | sysBeepState); |
|---|
| 518 | n/a | return _res; |
|---|
| 519 | n/a | } |
|---|
| 520 | n/a | |
|---|
| 521 | n/a | static PyObject *Snd_SndSetSysBeepState(PyObject *_self, PyObject *_args) |
|---|
| 522 | n/a | { |
|---|
| 523 | n/a | PyObject *_res = NULL; |
|---|
| 524 | n/a | OSErr _err; |
|---|
| 525 | n/a | short sysBeepState; |
|---|
| 526 | n/a | if (!PyArg_ParseTuple(_args, "h", |
|---|
| 527 | n/a | &sysBeepState)) |
|---|
| 528 | n/a | return NULL; |
|---|
| 529 | n/a | _err = SndSetSysBeepState(sysBeepState); |
|---|
| 530 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 531 | n/a | Py_INCREF(Py_None); |
|---|
| 532 | n/a | _res = Py_None; |
|---|
| 533 | n/a | return _res; |
|---|
| 534 | n/a | } |
|---|
| 535 | n/a | |
|---|
| 536 | n/a | static PyObject *Snd_GetSysBeepVolume(PyObject *_self, PyObject *_args) |
|---|
| 537 | n/a | { |
|---|
| 538 | n/a | PyObject *_res = NULL; |
|---|
| 539 | n/a | OSErr _err; |
|---|
| 540 | n/a | long level; |
|---|
| 541 | n/a | if (!PyArg_ParseTuple(_args, "")) |
|---|
| 542 | n/a | return NULL; |
|---|
| 543 | n/a | _err = GetSysBeepVolume(&level); |
|---|
| 544 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 545 | n/a | _res = Py_BuildValue("l", |
|---|
| 546 | n/a | level); |
|---|
| 547 | n/a | return _res; |
|---|
| 548 | n/a | } |
|---|
| 549 | n/a | |
|---|
| 550 | n/a | static PyObject *Snd_SetSysBeepVolume(PyObject *_self, PyObject *_args) |
|---|
| 551 | n/a | { |
|---|
| 552 | n/a | PyObject *_res = NULL; |
|---|
| 553 | n/a | OSErr _err; |
|---|
| 554 | n/a | long level; |
|---|
| 555 | n/a | if (!PyArg_ParseTuple(_args, "l", |
|---|
| 556 | n/a | &level)) |
|---|
| 557 | n/a | return NULL; |
|---|
| 558 | n/a | _err = SetSysBeepVolume(level); |
|---|
| 559 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 560 | n/a | Py_INCREF(Py_None); |
|---|
| 561 | n/a | _res = Py_None; |
|---|
| 562 | n/a | return _res; |
|---|
| 563 | n/a | } |
|---|
| 564 | n/a | |
|---|
| 565 | n/a | static PyObject *Snd_GetDefaultOutputVolume(PyObject *_self, PyObject *_args) |
|---|
| 566 | n/a | { |
|---|
| 567 | n/a | PyObject *_res = NULL; |
|---|
| 568 | n/a | OSErr _err; |
|---|
| 569 | n/a | long level; |
|---|
| 570 | n/a | if (!PyArg_ParseTuple(_args, "")) |
|---|
| 571 | n/a | return NULL; |
|---|
| 572 | n/a | _err = GetDefaultOutputVolume(&level); |
|---|
| 573 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 574 | n/a | _res = Py_BuildValue("l", |
|---|
| 575 | n/a | level); |
|---|
| 576 | n/a | return _res; |
|---|
| 577 | n/a | } |
|---|
| 578 | n/a | |
|---|
| 579 | n/a | static PyObject *Snd_SetDefaultOutputVolume(PyObject *_self, PyObject *_args) |
|---|
| 580 | n/a | { |
|---|
| 581 | n/a | PyObject *_res = NULL; |
|---|
| 582 | n/a | OSErr _err; |
|---|
| 583 | n/a | long level; |
|---|
| 584 | n/a | if (!PyArg_ParseTuple(_args, "l", |
|---|
| 585 | n/a | &level)) |
|---|
| 586 | n/a | return NULL; |
|---|
| 587 | n/a | _err = SetDefaultOutputVolume(level); |
|---|
| 588 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 589 | n/a | Py_INCREF(Py_None); |
|---|
| 590 | n/a | _res = Py_None; |
|---|
| 591 | n/a | return _res; |
|---|
| 592 | n/a | } |
|---|
| 593 | n/a | |
|---|
| 594 | n/a | static PyObject *Snd_GetSoundHeaderOffset(PyObject *_self, PyObject *_args) |
|---|
| 595 | n/a | { |
|---|
| 596 | n/a | PyObject *_res = NULL; |
|---|
| 597 | n/a | OSErr _err; |
|---|
| 598 | n/a | SndListHandle sndHandle; |
|---|
| 599 | n/a | long offset; |
|---|
| 600 | n/a | if (!PyArg_ParseTuple(_args, "O&", |
|---|
| 601 | n/a | ResObj_Convert, &sndHandle)) |
|---|
| 602 | n/a | return NULL; |
|---|
| 603 | n/a | _err = GetSoundHeaderOffset(sndHandle, |
|---|
| 604 | n/a | &offset); |
|---|
| 605 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 606 | n/a | _res = Py_BuildValue("l", |
|---|
| 607 | n/a | offset); |
|---|
| 608 | n/a | return _res; |
|---|
| 609 | n/a | } |
|---|
| 610 | n/a | |
|---|
| 611 | n/a | static PyObject *Snd_GetCompressionInfo(PyObject *_self, PyObject *_args) |
|---|
| 612 | n/a | { |
|---|
| 613 | n/a | PyObject *_res = NULL; |
|---|
| 614 | n/a | OSErr _err; |
|---|
| 615 | n/a | short compressionID; |
|---|
| 616 | n/a | OSType format; |
|---|
| 617 | n/a | short numChannels; |
|---|
| 618 | n/a | short sampleSize; |
|---|
| 619 | n/a | CompressionInfo cp__out__; |
|---|
| 620 | n/a | if (!PyArg_ParseTuple(_args, "hO&hh", |
|---|
| 621 | n/a | &compressionID, |
|---|
| 622 | n/a | PyMac_GetOSType, &format, |
|---|
| 623 | n/a | &numChannels, |
|---|
| 624 | n/a | &sampleSize)) |
|---|
| 625 | n/a | return NULL; |
|---|
| 626 | n/a | _err = GetCompressionInfo(compressionID, |
|---|
| 627 | n/a | format, |
|---|
| 628 | n/a | numChannels, |
|---|
| 629 | n/a | sampleSize, |
|---|
| 630 | n/a | &cp__out__); |
|---|
| 631 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 632 | n/a | _res = Py_BuildValue("s#", |
|---|
| 633 | n/a | (char *)&cp__out__, (int)sizeof(CompressionInfo)); |
|---|
| 634 | n/a | return _res; |
|---|
| 635 | n/a | } |
|---|
| 636 | n/a | |
|---|
| 637 | n/a | static PyObject *Snd_SetSoundPreference(PyObject *_self, PyObject *_args) |
|---|
| 638 | n/a | { |
|---|
| 639 | n/a | PyObject *_res = NULL; |
|---|
| 640 | n/a | OSErr _err; |
|---|
| 641 | n/a | OSType theType; |
|---|
| 642 | n/a | Str255 name; |
|---|
| 643 | n/a | Handle settings; |
|---|
| 644 | n/a | if (!PyArg_ParseTuple(_args, "O&O&", |
|---|
| 645 | n/a | PyMac_GetOSType, &theType, |
|---|
| 646 | n/a | ResObj_Convert, &settings)) |
|---|
| 647 | n/a | return NULL; |
|---|
| 648 | n/a | _err = SetSoundPreference(theType, |
|---|
| 649 | n/a | name, |
|---|
| 650 | n/a | settings); |
|---|
| 651 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 652 | n/a | _res = Py_BuildValue("O&", |
|---|
| 653 | n/a | PyMac_BuildStr255, name); |
|---|
| 654 | n/a | return _res; |
|---|
| 655 | n/a | } |
|---|
| 656 | n/a | |
|---|
| 657 | n/a | static PyObject *Snd_GetSoundPreference(PyObject *_self, PyObject *_args) |
|---|
| 658 | n/a | { |
|---|
| 659 | n/a | PyObject *_res = NULL; |
|---|
| 660 | n/a | OSErr _err; |
|---|
| 661 | n/a | OSType theType; |
|---|
| 662 | n/a | Str255 name; |
|---|
| 663 | n/a | Handle settings; |
|---|
| 664 | n/a | if (!PyArg_ParseTuple(_args, "O&O&", |
|---|
| 665 | n/a | PyMac_GetOSType, &theType, |
|---|
| 666 | n/a | ResObj_Convert, &settings)) |
|---|
| 667 | n/a | return NULL; |
|---|
| 668 | n/a | _err = GetSoundPreference(theType, |
|---|
| 669 | n/a | name, |
|---|
| 670 | n/a | settings); |
|---|
| 671 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 672 | n/a | _res = Py_BuildValue("O&", |
|---|
| 673 | n/a | PyMac_BuildStr255, name); |
|---|
| 674 | n/a | return _res; |
|---|
| 675 | n/a | } |
|---|
| 676 | n/a | |
|---|
| 677 | n/a | static PyObject *Snd_GetCompressionName(PyObject *_self, PyObject *_args) |
|---|
| 678 | n/a | { |
|---|
| 679 | n/a | PyObject *_res = NULL; |
|---|
| 680 | n/a | OSErr _err; |
|---|
| 681 | n/a | OSType compressionType; |
|---|
| 682 | n/a | Str255 compressionName; |
|---|
| 683 | n/a | if (!PyArg_ParseTuple(_args, "O&", |
|---|
| 684 | n/a | PyMac_GetOSType, &compressionType)) |
|---|
| 685 | n/a | return NULL; |
|---|
| 686 | n/a | _err = GetCompressionName(compressionType, |
|---|
| 687 | n/a | compressionName); |
|---|
| 688 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 689 | n/a | _res = Py_BuildValue("O&", |
|---|
| 690 | n/a | PyMac_BuildStr255, compressionName); |
|---|
| 691 | n/a | return _res; |
|---|
| 692 | n/a | } |
|---|
| 693 | n/a | |
|---|
| 694 | n/a | static PyObject *Snd_SPBVersion(PyObject *_self, PyObject *_args) |
|---|
| 695 | n/a | { |
|---|
| 696 | n/a | PyObject *_res = NULL; |
|---|
| 697 | n/a | NumVersion _rv; |
|---|
| 698 | n/a | if (!PyArg_ParseTuple(_args, "")) |
|---|
| 699 | n/a | return NULL; |
|---|
| 700 | n/a | _rv = SPBVersion(); |
|---|
| 701 | n/a | _res = Py_BuildValue("O&", |
|---|
| 702 | n/a | PyMac_BuildNumVersion, _rv); |
|---|
| 703 | n/a | return _res; |
|---|
| 704 | n/a | } |
|---|
| 705 | n/a | |
|---|
| 706 | n/a | static PyObject *Snd_SndRecord(PyObject *_self, PyObject *_args) |
|---|
| 707 | n/a | { |
|---|
| 708 | n/a | PyObject *_res = NULL; |
|---|
| 709 | n/a | OSErr _err; |
|---|
| 710 | n/a | Point corner; |
|---|
| 711 | n/a | OSType quality; |
|---|
| 712 | n/a | SndListHandle sndHandle; |
|---|
| 713 | n/a | if (!PyArg_ParseTuple(_args, "O&O&", |
|---|
| 714 | n/a | PyMac_GetPoint, &corner, |
|---|
| 715 | n/a | PyMac_GetOSType, &quality)) |
|---|
| 716 | n/a | return NULL; |
|---|
| 717 | n/a | _err = SndRecord((ModalFilterUPP)0, |
|---|
| 718 | n/a | corner, |
|---|
| 719 | n/a | quality, |
|---|
| 720 | n/a | &sndHandle); |
|---|
| 721 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 722 | n/a | _res = Py_BuildValue("O&", |
|---|
| 723 | n/a | ResObj_New, sndHandle); |
|---|
| 724 | n/a | return _res; |
|---|
| 725 | n/a | } |
|---|
| 726 | n/a | |
|---|
| 727 | n/a | static PyObject *Snd_SPBSignInDevice(PyObject *_self, PyObject *_args) |
|---|
| 728 | n/a | { |
|---|
| 729 | n/a | PyObject *_res = NULL; |
|---|
| 730 | n/a | OSErr _err; |
|---|
| 731 | n/a | short deviceRefNum; |
|---|
| 732 | n/a | Str255 deviceName; |
|---|
| 733 | n/a | if (!PyArg_ParseTuple(_args, "hO&", |
|---|
| 734 | n/a | &deviceRefNum, |
|---|
| 735 | n/a | PyMac_GetStr255, deviceName)) |
|---|
| 736 | n/a | return NULL; |
|---|
| 737 | n/a | _err = SPBSignInDevice(deviceRefNum, |
|---|
| 738 | n/a | deviceName); |
|---|
| 739 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 740 | n/a | Py_INCREF(Py_None); |
|---|
| 741 | n/a | _res = Py_None; |
|---|
| 742 | n/a | return _res; |
|---|
| 743 | n/a | } |
|---|
| 744 | n/a | |
|---|
| 745 | n/a | static PyObject *Snd_SPBSignOutDevice(PyObject *_self, PyObject *_args) |
|---|
| 746 | n/a | { |
|---|
| 747 | n/a | PyObject *_res = NULL; |
|---|
| 748 | n/a | OSErr _err; |
|---|
| 749 | n/a | short deviceRefNum; |
|---|
| 750 | n/a | if (!PyArg_ParseTuple(_args, "h", |
|---|
| 751 | n/a | &deviceRefNum)) |
|---|
| 752 | n/a | return NULL; |
|---|
| 753 | n/a | _err = SPBSignOutDevice(deviceRefNum); |
|---|
| 754 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 755 | n/a | Py_INCREF(Py_None); |
|---|
| 756 | n/a | _res = Py_None; |
|---|
| 757 | n/a | return _res; |
|---|
| 758 | n/a | } |
|---|
| 759 | n/a | |
|---|
| 760 | n/a | static PyObject *Snd_SPBGetIndexedDevice(PyObject *_self, PyObject *_args) |
|---|
| 761 | n/a | { |
|---|
| 762 | n/a | PyObject *_res = NULL; |
|---|
| 763 | n/a | OSErr _err; |
|---|
| 764 | n/a | short count; |
|---|
| 765 | n/a | Str255 deviceName; |
|---|
| 766 | n/a | Handle deviceIconHandle; |
|---|
| 767 | n/a | if (!PyArg_ParseTuple(_args, "h", |
|---|
| 768 | n/a | &count)) |
|---|
| 769 | n/a | return NULL; |
|---|
| 770 | n/a | _err = SPBGetIndexedDevice(count, |
|---|
| 771 | n/a | deviceName, |
|---|
| 772 | n/a | &deviceIconHandle); |
|---|
| 773 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 774 | n/a | _res = Py_BuildValue("O&O&", |
|---|
| 775 | n/a | PyMac_BuildStr255, deviceName, |
|---|
| 776 | n/a | ResObj_New, deviceIconHandle); |
|---|
| 777 | n/a | return _res; |
|---|
| 778 | n/a | } |
|---|
| 779 | n/a | |
|---|
| 780 | n/a | static PyObject *Snd_SPBOpenDevice(PyObject *_self, PyObject *_args) |
|---|
| 781 | n/a | { |
|---|
| 782 | n/a | PyObject *_res = NULL; |
|---|
| 783 | n/a | OSErr _err; |
|---|
| 784 | n/a | Str255 deviceName; |
|---|
| 785 | n/a | short permission; |
|---|
| 786 | n/a | long inRefNum; |
|---|
| 787 | n/a | if (!PyArg_ParseTuple(_args, "O&h", |
|---|
| 788 | n/a | PyMac_GetStr255, deviceName, |
|---|
| 789 | n/a | &permission)) |
|---|
| 790 | n/a | return NULL; |
|---|
| 791 | n/a | _err = SPBOpenDevice(deviceName, |
|---|
| 792 | n/a | permission, |
|---|
| 793 | n/a | &inRefNum); |
|---|
| 794 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 795 | n/a | _res = Py_BuildValue("l", |
|---|
| 796 | n/a | inRefNum); |
|---|
| 797 | n/a | return _res; |
|---|
| 798 | n/a | } |
|---|
| 799 | n/a | |
|---|
| 800 | n/a | static PyObject *Snd_SPBCloseDevice(PyObject *_self, PyObject *_args) |
|---|
| 801 | n/a | { |
|---|
| 802 | n/a | PyObject *_res = NULL; |
|---|
| 803 | n/a | OSErr _err; |
|---|
| 804 | n/a | long inRefNum; |
|---|
| 805 | n/a | if (!PyArg_ParseTuple(_args, "l", |
|---|
| 806 | n/a | &inRefNum)) |
|---|
| 807 | n/a | return NULL; |
|---|
| 808 | n/a | _err = SPBCloseDevice(inRefNum); |
|---|
| 809 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 810 | n/a | Py_INCREF(Py_None); |
|---|
| 811 | n/a | _res = Py_None; |
|---|
| 812 | n/a | return _res; |
|---|
| 813 | n/a | } |
|---|
| 814 | n/a | |
|---|
| 815 | n/a | static PyObject *Snd_SPBRecord(PyObject *_self, PyObject *_args) |
|---|
| 816 | n/a | { |
|---|
| 817 | n/a | PyObject *_res = NULL; |
|---|
| 818 | n/a | OSErr _err; |
|---|
| 819 | n/a | SPBPtr inParamPtr; |
|---|
| 820 | n/a | Boolean asynchFlag; |
|---|
| 821 | n/a | if (!PyArg_ParseTuple(_args, "O&b", |
|---|
| 822 | n/a | SPBObj_Convert, &inParamPtr, |
|---|
| 823 | n/a | &asynchFlag)) |
|---|
| 824 | n/a | return NULL; |
|---|
| 825 | n/a | _err = SPBRecord(inParamPtr, |
|---|
| 826 | n/a | asynchFlag); |
|---|
| 827 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 828 | n/a | Py_INCREF(Py_None); |
|---|
| 829 | n/a | _res = Py_None; |
|---|
| 830 | n/a | return _res; |
|---|
| 831 | n/a | } |
|---|
| 832 | n/a | |
|---|
| 833 | n/a | static PyObject *Snd_SPBPauseRecording(PyObject *_self, PyObject *_args) |
|---|
| 834 | n/a | { |
|---|
| 835 | n/a | PyObject *_res = NULL; |
|---|
| 836 | n/a | OSErr _err; |
|---|
| 837 | n/a | long inRefNum; |
|---|
| 838 | n/a | if (!PyArg_ParseTuple(_args, "l", |
|---|
| 839 | n/a | &inRefNum)) |
|---|
| 840 | n/a | return NULL; |
|---|
| 841 | n/a | _err = SPBPauseRecording(inRefNum); |
|---|
| 842 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 843 | n/a | Py_INCREF(Py_None); |
|---|
| 844 | n/a | _res = Py_None; |
|---|
| 845 | n/a | return _res; |
|---|
| 846 | n/a | } |
|---|
| 847 | n/a | |
|---|
| 848 | n/a | static PyObject *Snd_SPBResumeRecording(PyObject *_self, PyObject *_args) |
|---|
| 849 | n/a | { |
|---|
| 850 | n/a | PyObject *_res = NULL; |
|---|
| 851 | n/a | OSErr _err; |
|---|
| 852 | n/a | long inRefNum; |
|---|
| 853 | n/a | if (!PyArg_ParseTuple(_args, "l", |
|---|
| 854 | n/a | &inRefNum)) |
|---|
| 855 | n/a | return NULL; |
|---|
| 856 | n/a | _err = SPBResumeRecording(inRefNum); |
|---|
| 857 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 858 | n/a | Py_INCREF(Py_None); |
|---|
| 859 | n/a | _res = Py_None; |
|---|
| 860 | n/a | return _res; |
|---|
| 861 | n/a | } |
|---|
| 862 | n/a | |
|---|
| 863 | n/a | static PyObject *Snd_SPBStopRecording(PyObject *_self, PyObject *_args) |
|---|
| 864 | n/a | { |
|---|
| 865 | n/a | PyObject *_res = NULL; |
|---|
| 866 | n/a | OSErr _err; |
|---|
| 867 | n/a | long inRefNum; |
|---|
| 868 | n/a | if (!PyArg_ParseTuple(_args, "l", |
|---|
| 869 | n/a | &inRefNum)) |
|---|
| 870 | n/a | return NULL; |
|---|
| 871 | n/a | _err = SPBStopRecording(inRefNum); |
|---|
| 872 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 873 | n/a | Py_INCREF(Py_None); |
|---|
| 874 | n/a | _res = Py_None; |
|---|
| 875 | n/a | return _res; |
|---|
| 876 | n/a | } |
|---|
| 877 | n/a | |
|---|
| 878 | n/a | static PyObject *Snd_SPBGetRecordingStatus(PyObject *_self, PyObject *_args) |
|---|
| 879 | n/a | { |
|---|
| 880 | n/a | PyObject *_res = NULL; |
|---|
| 881 | n/a | OSErr _err; |
|---|
| 882 | n/a | long inRefNum; |
|---|
| 883 | n/a | short recordingStatus; |
|---|
| 884 | n/a | short meterLevel; |
|---|
| 885 | n/a | unsigned long totalSamplesToRecord; |
|---|
| 886 | n/a | unsigned long numberOfSamplesRecorded; |
|---|
| 887 | n/a | unsigned long totalMsecsToRecord; |
|---|
| 888 | n/a | unsigned long numberOfMsecsRecorded; |
|---|
| 889 | n/a | if (!PyArg_ParseTuple(_args, "l", |
|---|
| 890 | n/a | &inRefNum)) |
|---|
| 891 | n/a | return NULL; |
|---|
| 892 | n/a | _err = SPBGetRecordingStatus(inRefNum, |
|---|
| 893 | n/a | &recordingStatus, |
|---|
| 894 | n/a | &meterLevel, |
|---|
| 895 | n/a | &totalSamplesToRecord, |
|---|
| 896 | n/a | &numberOfSamplesRecorded, |
|---|
| 897 | n/a | &totalMsecsToRecord, |
|---|
| 898 | n/a | &numberOfMsecsRecorded); |
|---|
| 899 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 900 | n/a | _res = Py_BuildValue("hhllll", |
|---|
| 901 | n/a | recordingStatus, |
|---|
| 902 | n/a | meterLevel, |
|---|
| 903 | n/a | totalSamplesToRecord, |
|---|
| 904 | n/a | numberOfSamplesRecorded, |
|---|
| 905 | n/a | totalMsecsToRecord, |
|---|
| 906 | n/a | numberOfMsecsRecorded); |
|---|
| 907 | n/a | return _res; |
|---|
| 908 | n/a | } |
|---|
| 909 | n/a | |
|---|
| 910 | n/a | static PyObject *Snd_SPBGetDeviceInfo(PyObject *_self, PyObject *_args) |
|---|
| 911 | n/a | { |
|---|
| 912 | n/a | PyObject *_res = NULL; |
|---|
| 913 | n/a | OSErr _err; |
|---|
| 914 | n/a | long inRefNum; |
|---|
| 915 | n/a | OSType infoType; |
|---|
| 916 | n/a | void * infoData; |
|---|
| 917 | n/a | if (!PyArg_ParseTuple(_args, "lO&w", |
|---|
| 918 | n/a | &inRefNum, |
|---|
| 919 | n/a | PyMac_GetOSType, &infoType, |
|---|
| 920 | n/a | &infoData)) |
|---|
| 921 | n/a | return NULL; |
|---|
| 922 | n/a | _err = SPBGetDeviceInfo(inRefNum, |
|---|
| 923 | n/a | infoType, |
|---|
| 924 | n/a | infoData); |
|---|
| 925 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 926 | n/a | Py_INCREF(Py_None); |
|---|
| 927 | n/a | _res = Py_None; |
|---|
| 928 | n/a | return _res; |
|---|
| 929 | n/a | } |
|---|
| 930 | n/a | |
|---|
| 931 | n/a | static PyObject *Snd_SPBSetDeviceInfo(PyObject *_self, PyObject *_args) |
|---|
| 932 | n/a | { |
|---|
| 933 | n/a | PyObject *_res = NULL; |
|---|
| 934 | n/a | OSErr _err; |
|---|
| 935 | n/a | long inRefNum; |
|---|
| 936 | n/a | OSType infoType; |
|---|
| 937 | n/a | void * infoData; |
|---|
| 938 | n/a | if (!PyArg_ParseTuple(_args, "lO&w", |
|---|
| 939 | n/a | &inRefNum, |
|---|
| 940 | n/a | PyMac_GetOSType, &infoType, |
|---|
| 941 | n/a | &infoData)) |
|---|
| 942 | n/a | return NULL; |
|---|
| 943 | n/a | _err = SPBSetDeviceInfo(inRefNum, |
|---|
| 944 | n/a | infoType, |
|---|
| 945 | n/a | infoData); |
|---|
| 946 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 947 | n/a | Py_INCREF(Py_None); |
|---|
| 948 | n/a | _res = Py_None; |
|---|
| 949 | n/a | return _res; |
|---|
| 950 | n/a | } |
|---|
| 951 | n/a | |
|---|
| 952 | n/a | static PyObject *Snd_SPBMillisecondsToBytes(PyObject *_self, PyObject *_args) |
|---|
| 953 | n/a | { |
|---|
| 954 | n/a | PyObject *_res = NULL; |
|---|
| 955 | n/a | OSErr _err; |
|---|
| 956 | n/a | long inRefNum; |
|---|
| 957 | n/a | long milliseconds; |
|---|
| 958 | n/a | if (!PyArg_ParseTuple(_args, "l", |
|---|
| 959 | n/a | &inRefNum)) |
|---|
| 960 | n/a | return NULL; |
|---|
| 961 | n/a | _err = SPBMillisecondsToBytes(inRefNum, |
|---|
| 962 | n/a | &milliseconds); |
|---|
| 963 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 964 | n/a | _res = Py_BuildValue("l", |
|---|
| 965 | n/a | milliseconds); |
|---|
| 966 | n/a | return _res; |
|---|
| 967 | n/a | } |
|---|
| 968 | n/a | |
|---|
| 969 | n/a | static PyObject *Snd_SPBBytesToMilliseconds(PyObject *_self, PyObject *_args) |
|---|
| 970 | n/a | { |
|---|
| 971 | n/a | PyObject *_res = NULL; |
|---|
| 972 | n/a | OSErr _err; |
|---|
| 973 | n/a | long inRefNum; |
|---|
| 974 | n/a | long byteCount; |
|---|
| 975 | n/a | if (!PyArg_ParseTuple(_args, "l", |
|---|
| 976 | n/a | &inRefNum)) |
|---|
| 977 | n/a | return NULL; |
|---|
| 978 | n/a | _err = SPBBytesToMilliseconds(inRefNum, |
|---|
| 979 | n/a | &byteCount); |
|---|
| 980 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 981 | n/a | _res = Py_BuildValue("l", |
|---|
| 982 | n/a | byteCount); |
|---|
| 983 | n/a | return _res; |
|---|
| 984 | n/a | } |
|---|
| 985 | n/a | #endif /* __LP64__ */ |
|---|
| 986 | n/a | |
|---|
| 987 | n/a | static PyMethodDef Snd_methods[] = { |
|---|
| 988 | n/a | #ifndef __LP64__ |
|---|
| 989 | n/a | {"SPB", (PyCFunction)Snd_SPB, 1, |
|---|
| 990 | n/a | PyDoc_STR(NULL)}, |
|---|
| 991 | n/a | {"SysBeep", (PyCFunction)Snd_SysBeep, 1, |
|---|
| 992 | n/a | PyDoc_STR("(short duration) -> None")}, |
|---|
| 993 | n/a | {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1, |
|---|
| 994 | n/a | PyDoc_STR("(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)")}, |
|---|
| 995 | n/a | {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1, |
|---|
| 996 | n/a | PyDoc_STR("() -> (NumVersion _rv)")}, |
|---|
| 997 | n/a | {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1, |
|---|
| 998 | n/a | PyDoc_STR("(short theLength) -> (SMStatus theStatus)")}, |
|---|
| 999 | n/a | {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1, |
|---|
| 1000 | n/a | PyDoc_STR("() -> (short sysBeepState)")}, |
|---|
| 1001 | n/a | {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1, |
|---|
| 1002 | n/a | PyDoc_STR("(short sysBeepState) -> None")}, |
|---|
| 1003 | n/a | {"GetSysBeepVolume", (PyCFunction)Snd_GetSysBeepVolume, 1, |
|---|
| 1004 | n/a | PyDoc_STR("() -> (long level)")}, |
|---|
| 1005 | n/a | {"SetSysBeepVolume", (PyCFunction)Snd_SetSysBeepVolume, 1, |
|---|
| 1006 | n/a | PyDoc_STR("(long level) -> None")}, |
|---|
| 1007 | n/a | {"GetDefaultOutputVolume", (PyCFunction)Snd_GetDefaultOutputVolume, 1, |
|---|
| 1008 | n/a | PyDoc_STR("() -> (long level)")}, |
|---|
| 1009 | n/a | {"SetDefaultOutputVolume", (PyCFunction)Snd_SetDefaultOutputVolume, 1, |
|---|
| 1010 | n/a | PyDoc_STR("(long level) -> None")}, |
|---|
| 1011 | n/a | {"GetSoundHeaderOffset", (PyCFunction)Snd_GetSoundHeaderOffset, 1, |
|---|
| 1012 | n/a | PyDoc_STR("(SndListHandle sndHandle) -> (long offset)")}, |
|---|
| 1013 | n/a | {"GetCompressionInfo", (PyCFunction)Snd_GetCompressionInfo, 1, |
|---|
| 1014 | n/a | PyDoc_STR("(short compressionID, OSType format, short numChannels, short sampleSize) -> (CompressionInfo cp)")}, |
|---|
| 1015 | n/a | {"SetSoundPreference", (PyCFunction)Snd_SetSoundPreference, 1, |
|---|
| 1016 | n/a | PyDoc_STR("(OSType theType, Handle settings) -> (Str255 name)")}, |
|---|
| 1017 | n/a | {"GetSoundPreference", (PyCFunction)Snd_GetSoundPreference, 1, |
|---|
| 1018 | n/a | PyDoc_STR("(OSType theType, Handle settings) -> (Str255 name)")}, |
|---|
| 1019 | n/a | {"GetCompressionName", (PyCFunction)Snd_GetCompressionName, 1, |
|---|
| 1020 | n/a | PyDoc_STR("(OSType compressionType) -> (Str255 compressionName)")}, |
|---|
| 1021 | n/a | {"SPBVersion", (PyCFunction)Snd_SPBVersion, 1, |
|---|
| 1022 | n/a | PyDoc_STR("() -> (NumVersion _rv)")}, |
|---|
| 1023 | n/a | {"SndRecord", (PyCFunction)Snd_SndRecord, 1, |
|---|
| 1024 | n/a | PyDoc_STR("(Point corner, OSType quality) -> (SndListHandle sndHandle)")}, |
|---|
| 1025 | n/a | {"SPBSignInDevice", (PyCFunction)Snd_SPBSignInDevice, 1, |
|---|
| 1026 | n/a | PyDoc_STR("(short deviceRefNum, Str255 deviceName) -> None")}, |
|---|
| 1027 | n/a | {"SPBSignOutDevice", (PyCFunction)Snd_SPBSignOutDevice, 1, |
|---|
| 1028 | n/a | PyDoc_STR("(short deviceRefNum) -> None")}, |
|---|
| 1029 | n/a | {"SPBGetIndexedDevice", (PyCFunction)Snd_SPBGetIndexedDevice, 1, |
|---|
| 1030 | n/a | PyDoc_STR("(short count) -> (Str255 deviceName, Handle deviceIconHandle)")}, |
|---|
| 1031 | n/a | {"SPBOpenDevice", (PyCFunction)Snd_SPBOpenDevice, 1, |
|---|
| 1032 | n/a | PyDoc_STR("(Str255 deviceName, short permission) -> (long inRefNum)")}, |
|---|
| 1033 | n/a | {"SPBCloseDevice", (PyCFunction)Snd_SPBCloseDevice, 1, |
|---|
| 1034 | n/a | PyDoc_STR("(long inRefNum) -> None")}, |
|---|
| 1035 | n/a | {"SPBRecord", (PyCFunction)Snd_SPBRecord, 1, |
|---|
| 1036 | n/a | PyDoc_STR("(SPBPtr inParamPtr, Boolean asynchFlag) -> None")}, |
|---|
| 1037 | n/a | {"SPBPauseRecording", (PyCFunction)Snd_SPBPauseRecording, 1, |
|---|
| 1038 | n/a | PyDoc_STR("(long inRefNum) -> None")}, |
|---|
| 1039 | n/a | {"SPBResumeRecording", (PyCFunction)Snd_SPBResumeRecording, 1, |
|---|
| 1040 | n/a | PyDoc_STR("(long inRefNum) -> None")}, |
|---|
| 1041 | n/a | {"SPBStopRecording", (PyCFunction)Snd_SPBStopRecording, 1, |
|---|
| 1042 | n/a | PyDoc_STR("(long inRefNum) -> None")}, |
|---|
| 1043 | n/a | {"SPBGetRecordingStatus", (PyCFunction)Snd_SPBGetRecordingStatus, 1, |
|---|
| 1044 | n/a | PyDoc_STR("(long inRefNum) -> (short recordingStatus, short meterLevel, unsigned long totalSamplesToRecord, unsigned long numberOfSamplesRecorded, unsigned long totalMsecsToRecord, unsigned long numberOfMsecsRecorded)")}, |
|---|
| 1045 | n/a | {"SPBGetDeviceInfo", (PyCFunction)Snd_SPBGetDeviceInfo, 1, |
|---|
| 1046 | n/a | PyDoc_STR("(long inRefNum, OSType infoType, void * infoData) -> None")}, |
|---|
| 1047 | n/a | {"SPBSetDeviceInfo", (PyCFunction)Snd_SPBSetDeviceInfo, 1, |
|---|
| 1048 | n/a | PyDoc_STR("(long inRefNum, OSType infoType, void * infoData) -> None")}, |
|---|
| 1049 | n/a | {"SPBMillisecondsToBytes", (PyCFunction)Snd_SPBMillisecondsToBytes, 1, |
|---|
| 1050 | n/a | PyDoc_STR("(long inRefNum) -> (long milliseconds)")}, |
|---|
| 1051 | n/a | {"SPBBytesToMilliseconds", (PyCFunction)Snd_SPBBytesToMilliseconds, 1, |
|---|
| 1052 | n/a | PyDoc_STR("(long inRefNum) -> (long byteCount)")}, |
|---|
| 1053 | n/a | #endif /* __LP64__ */ |
|---|
| 1054 | n/a | {NULL, NULL, 0} |
|---|
| 1055 | n/a | }; |
|---|
| 1056 | n/a | |
|---|
| 1057 | n/a | |
|---|
| 1058 | n/a | #ifndef __LP64__ |
|---|
| 1059 | n/a | |
|---|
| 1060 | n/a | /* Routine passed to Py_AddPendingCall -- call the Python callback */ |
|---|
| 1061 | n/a | static int |
|---|
| 1062 | n/a | SndCh_CallCallBack(void *arg) |
|---|
| 1063 | n/a | { |
|---|
| 1064 | n/a | SndChannelObject *p = (SndChannelObject *)arg; |
|---|
| 1065 | n/a | PyObject *args; |
|---|
| 1066 | n/a | PyObject *res; |
|---|
| 1067 | n/a | args = Py_BuildValue("(O(hhl))", |
|---|
| 1068 | n/a | p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2); |
|---|
| 1069 | n/a | res = PyEval_CallObject(p->ob_callback, args); |
|---|
| 1070 | n/a | Py_DECREF(args); |
|---|
| 1071 | n/a | if (res == NULL) |
|---|
| 1072 | n/a | return -1; |
|---|
| 1073 | n/a | Py_DECREF(res); |
|---|
| 1074 | n/a | return 0; |
|---|
| 1075 | n/a | } |
|---|
| 1076 | n/a | |
|---|
| 1077 | n/a | /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */ |
|---|
| 1078 | n/a | static pascal void |
|---|
| 1079 | n/a | SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd) |
|---|
| 1080 | n/a | { |
|---|
| 1081 | n/a | SndChannelObject *p = (SndChannelObject *)(chan->userInfo); |
|---|
| 1082 | n/a | if (p->ob_callback != NULL) { |
|---|
| 1083 | n/a | long A5 = SetA5(p->ob_A5); |
|---|
| 1084 | n/a | p->ob_cmd = *cmd; |
|---|
| 1085 | n/a | Py_AddPendingCall(SndCh_CallCallBack, (void *)p); |
|---|
| 1086 | n/a | SetA5(A5); |
|---|
| 1087 | n/a | } |
|---|
| 1088 | n/a | } |
|---|
| 1089 | n/a | |
|---|
| 1090 | n/a | /* SPB callbacks - Schedule callbacks to Python */ |
|---|
| 1091 | n/a | static int |
|---|
| 1092 | n/a | SPB_CallCallBack(void *arg) |
|---|
| 1093 | n/a | { |
|---|
| 1094 | n/a | SPBObject *p = (SPBObject *)arg; |
|---|
| 1095 | n/a | PyObject *args; |
|---|
| 1096 | n/a | PyObject *res; |
|---|
| 1097 | n/a | |
|---|
| 1098 | n/a | if ( p->ob_thiscallback == 0 ) return 0; |
|---|
| 1099 | n/a | args = Py_BuildValue("(O)", p); |
|---|
| 1100 | n/a | res = PyEval_CallObject(p->ob_thiscallback, args); |
|---|
| 1101 | n/a | p->ob_thiscallback = 0; |
|---|
| 1102 | n/a | Py_DECREF(args); |
|---|
| 1103 | n/a | if (res == NULL) |
|---|
| 1104 | n/a | return -1; |
|---|
| 1105 | n/a | Py_DECREF(res); |
|---|
| 1106 | n/a | return 0; |
|---|
| 1107 | n/a | } |
|---|
| 1108 | n/a | |
|---|
| 1109 | n/a | static pascal void |
|---|
| 1110 | n/a | SPB_completion(SPBPtr my_spb) |
|---|
| 1111 | n/a | { |
|---|
| 1112 | n/a | SPBObject *p = (SPBObject *)(my_spb->userLong); |
|---|
| 1113 | n/a | |
|---|
| 1114 | n/a | if (p && p->ob_completion) { |
|---|
| 1115 | n/a | long A5 = SetA5(p->ob_A5); |
|---|
| 1116 | n/a | p->ob_thiscallback = p->ob_completion; /* Hope we cannot get two at the same time */ |
|---|
| 1117 | n/a | Py_AddPendingCall(SPB_CallCallBack, (void *)p); |
|---|
| 1118 | n/a | SetA5(A5); |
|---|
| 1119 | n/a | } |
|---|
| 1120 | n/a | } |
|---|
| 1121 | n/a | #endif /* __LP64__ */ |
|---|
| 1122 | n/a | |
|---|
| 1123 | n/a | |
|---|
| 1124 | n/a | |
|---|
| 1125 | n/a | void init_Snd(void) |
|---|
| 1126 | n/a | { |
|---|
| 1127 | n/a | PyObject *m; |
|---|
| 1128 | n/a | #ifndef __LP64__ |
|---|
| 1129 | n/a | PyObject *d; |
|---|
| 1130 | n/a | #endif /* __LP64__ */ |
|---|
| 1131 | n/a | |
|---|
| 1132 | n/a | |
|---|
| 1133 | n/a | |
|---|
| 1134 | n/a | |
|---|
| 1135 | n/a | |
|---|
| 1136 | n/a | m = Py_InitModule("_Snd", Snd_methods); |
|---|
| 1137 | n/a | #ifndef __LP64__ |
|---|
| 1138 | n/a | d = PyModule_GetDict(m); |
|---|
| 1139 | n/a | Snd_Error = PyMac_GetOSErrException(); |
|---|
| 1140 | n/a | if (Snd_Error == NULL || |
|---|
| 1141 | n/a | PyDict_SetItemString(d, "Error", Snd_Error) != 0) |
|---|
| 1142 | n/a | return; |
|---|
| 1143 | n/a | SndChannel_Type.ob_type = &PyType_Type; |
|---|
| 1144 | n/a | if (PyType_Ready(&SndChannel_Type) < 0) return; |
|---|
| 1145 | n/a | Py_INCREF(&SndChannel_Type); |
|---|
| 1146 | n/a | PyModule_AddObject(m, "SndChannel", (PyObject *)&SndChannel_Type); |
|---|
| 1147 | n/a | /* Backward-compatible name */ |
|---|
| 1148 | n/a | Py_INCREF(&SndChannel_Type); |
|---|
| 1149 | n/a | PyModule_AddObject(m, "SndChannelType", (PyObject *)&SndChannel_Type); |
|---|
| 1150 | n/a | SPB_Type.ob_type = &PyType_Type; |
|---|
| 1151 | n/a | if (PyType_Ready(&SPB_Type) < 0) return; |
|---|
| 1152 | n/a | Py_INCREF(&SPB_Type); |
|---|
| 1153 | n/a | #if 0 |
|---|
| 1154 | n/a | PyModule_AddObject(m, "SPB", (PyObject *)&SPB_Type); |
|---|
| 1155 | n/a | #endif |
|---|
| 1156 | n/a | /* Backward-compatible name */ |
|---|
| 1157 | n/a | Py_INCREF(&SPB_Type); |
|---|
| 1158 | n/a | PyModule_AddObject(m, "SPBType", (PyObject *)&SPB_Type); |
|---|
| 1159 | n/a | #endif /* __LP64__ */ |
|---|
| 1160 | n/a | } |
|---|
| 1161 | n/a | |
|---|
| 1162 | n/a | /* ======================== End module _Snd ========================= */ |
|---|
| 1163 | n/a | |
|---|