Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | |
| 2 | /* =========================== Module Snd =========================== */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | |
| 7 | |
| 8 | #define SystemSevenOrLater 1 |
| 9 | |
| 10 | #include "macglue.h" |
| 11 | #include <Memory.h> |
| 12 | #include <Dialogs.h> |
| 13 | #include <Menus.h> |
| 14 | #include <Controls.h> |
| 15 | |
| 16 | extern PyObject *ResObj_New(Handle); |
| 17 | extern int ResObj_Convert(PyObject *, Handle *); |
| 18 | |
| 19 | extern PyObject *WinObj_New(WindowPtr); |
| 20 | extern int WinObj_Convert(PyObject *, WindowPtr *); |
| 21 | |
| 22 | extern PyObject *DlgObj_New(DialogPtr); |
| 23 | extern int DlgObj_Convert(PyObject *, DialogPtr *); |
| 24 | extern PyTypeObject Dialog_Type; |
| 25 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 26 | |
| 27 | extern PyObject *MenuObj_New(MenuHandle); |
| 28 | extern int MenuObj_Convert(PyObject *, MenuHandle *); |
| 29 | |
| 30 | extern PyObject *CtlObj_New(ControlHandle); |
| 31 | extern int CtlObj_Convert(PyObject *, ControlHandle *); |
| 32 | |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 33 | extern PyObject *WinObj_WhichWindow(WindowPtr); |
| 34 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 35 | #include <Sound.h> |
| 36 | |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 37 | #ifndef HAVE_UNIVERSAL_HEADERS |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 38 | #define SndCallBackUPP ProcPtr |
Guido van Rossum | 6fc5aec | 1995-02-19 23:32:59 +0000 | [diff] [blame] | 39 | #define NewSndCallBackProc(x) ((SndCallBackProcPtr)(x)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 40 | #define SndListHandle Handle |
| 41 | #endif |
| 42 | |
| 43 | #include <OSUtils.h> /* for Set(Current)A5 */ |
| 44 | |
| 45 | /* Create a SndCommand object (an (int, int, int) tuple) */ |
| 46 | static PyObject * |
| 47 | SndCmd_New(SndCommand *pc) |
| 48 | { |
| 49 | return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2); |
| 50 | } |
| 51 | |
| 52 | /* Convert a SndCommand argument */ |
| 53 | static int |
| 54 | SndCmd_Convert(PyObject *v, SndCommand *pc) |
| 55 | { |
| 56 | int len; |
| 57 | pc->param1 = 0; |
| 58 | pc->param2 = 0; |
| 59 | if (PyTuple_Check(v)) { |
| 60 | if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2)) |
| 61 | return 1; |
| 62 | PyErr_Clear(); |
| 63 | return PyArg_ParseTuple(v, "hhs#", &pc->cmd, &pc->param1, &pc->param2, &len); |
| 64 | } |
| 65 | return PyArg_Parse(v, "h", &pc->cmd); |
| 66 | } |
| 67 | |
| 68 | /* Create a NumVersion object (a quintuple of integers) */ |
| 69 | static PyObject * |
| 70 | NumVer_New(NumVersion nv) |
| 71 | { |
| 72 | return Py_BuildValue("iiiii", |
| 73 | nv.majorRev, |
Guido van Rossum | 0818a4c | 1995-02-05 16:53:45 +0000 | [diff] [blame] | 74 | #ifdef THINK_C |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 75 | nv.minorRev, |
| 76 | nv.bugFixRev, |
Guido van Rossum | 0818a4c | 1995-02-05 16:53:45 +0000 | [diff] [blame] | 77 | #else |
| 78 | (nv.minorAndBugRev>>4) & 0xf, |
| 79 | nv.minorAndBugRev & 0xf, |
| 80 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 81 | nv.stage, |
| 82 | nv.nonRelRev); |
| 83 | } |
| 84 | |
| 85 | static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */ |
| 86 | |
| 87 | static PyObject *Snd_Error; |
| 88 | |
| 89 | /* --------------------- Object type SndChannel --------------------- */ |
| 90 | |
| 91 | staticforward PyTypeObject SndChannel_Type; |
| 92 | |
| 93 | #define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type) |
| 94 | |
| 95 | typedef struct SndChannelObject { |
| 96 | PyObject_HEAD |
| 97 | SndChannelPtr ob_itself; |
| 98 | /* Members used to implement callbacks: */ |
| 99 | PyObject *ob_callback; |
| 100 | long ob_A5; |
| 101 | SndCommand ob_cmd; |
| 102 | } SndChannelObject; |
| 103 | |
| 104 | static PyObject *SndCh_New(itself) |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 105 | SndChannelPtr itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 106 | { |
| 107 | SndChannelObject *it; |
| 108 | it = PyObject_NEW(SndChannelObject, &SndChannel_Type); |
| 109 | if (it == NULL) return NULL; |
| 110 | it->ob_itself = itself; |
| 111 | it->ob_callback = NULL; |
| 112 | it->ob_A5 = SetCurrentA5(); |
| 113 | return (PyObject *)it; |
| 114 | } |
| 115 | static SndCh_Convert(v, p_itself) |
| 116 | PyObject *v; |
| 117 | SndChannelPtr *p_itself; |
| 118 | { |
| 119 | if (!SndCh_Check(v)) |
| 120 | { |
| 121 | PyErr_SetString(PyExc_TypeError, "SndChannel required"); |
| 122 | return 0; |
| 123 | } |
| 124 | *p_itself = ((SndChannelObject *)v)->ob_itself; |
| 125 | return 1; |
| 126 | } |
| 127 | |
| 128 | static void SndCh_dealloc(self) |
| 129 | SndChannelObject *self; |
| 130 | { |
| 131 | SndDisposeChannel(self->ob_itself, 1); |
| 132 | Py_XDECREF(self->ob_callback); |
| 133 | PyMem_DEL(self); |
| 134 | } |
| 135 | |
| 136 | static PyObject *SndCh_SndDoCommand(_self, _args) |
| 137 | SndChannelObject *_self; |
| 138 | PyObject *_args; |
| 139 | { |
| 140 | PyObject *_res = NULL; |
| 141 | OSErr _err; |
| 142 | SndCommand cmd; |
| 143 | Boolean noWait; |
| 144 | if (!PyArg_ParseTuple(_args, "O&b", |
| 145 | SndCmd_Convert, &cmd, |
| 146 | &noWait)) |
| 147 | return NULL; |
| 148 | _err = SndDoCommand(_self->ob_itself, |
| 149 | &cmd, |
| 150 | noWait); |
| 151 | if (_err != noErr) return PyMac_Error(_err); |
| 152 | Py_INCREF(Py_None); |
| 153 | _res = Py_None; |
| 154 | return _res; |
| 155 | } |
| 156 | |
| 157 | static PyObject *SndCh_SndDoImmediate(_self, _args) |
| 158 | SndChannelObject *_self; |
| 159 | PyObject *_args; |
| 160 | { |
| 161 | PyObject *_res = NULL; |
| 162 | OSErr _err; |
| 163 | SndCommand cmd; |
| 164 | if (!PyArg_ParseTuple(_args, "O&", |
| 165 | SndCmd_Convert, &cmd)) |
| 166 | return NULL; |
| 167 | _err = SndDoImmediate(_self->ob_itself, |
| 168 | &cmd); |
| 169 | if (_err != noErr) return PyMac_Error(_err); |
| 170 | Py_INCREF(Py_None); |
| 171 | _res = Py_None; |
| 172 | return _res; |
| 173 | } |
| 174 | |
| 175 | static PyObject *SndCh_SndPlay(_self, _args) |
| 176 | SndChannelObject *_self; |
| 177 | PyObject *_args; |
| 178 | { |
| 179 | PyObject *_res = NULL; |
| 180 | OSErr _err; |
Guido van Rossum | 0818a4c | 1995-02-05 16:53:45 +0000 | [diff] [blame] | 181 | SndListHandle sndHdl; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 182 | Boolean async; |
| 183 | if (!PyArg_ParseTuple(_args, "O&b", |
| 184 | ResObj_Convert, &sndHdl, |
| 185 | &async)) |
| 186 | return NULL; |
| 187 | _err = SndPlay(_self->ob_itself, |
| 188 | sndHdl, |
| 189 | async); |
| 190 | if (_err != noErr) return PyMac_Error(_err); |
| 191 | Py_INCREF(Py_None); |
| 192 | _res = Py_None; |
| 193 | return _res; |
| 194 | } |
| 195 | |
| 196 | static PyObject *SndCh_SndStartFilePlay(_self, _args) |
| 197 | SndChannelObject *_self; |
| 198 | PyObject *_args; |
| 199 | { |
| 200 | PyObject *_res = NULL; |
| 201 | OSErr _err; |
| 202 | short fRefNum; |
| 203 | short resNum; |
| 204 | long bufferSize; |
| 205 | Boolean async; |
| 206 | if (!PyArg_ParseTuple(_args, "hhlb", |
| 207 | &fRefNum, |
| 208 | &resNum, |
| 209 | &bufferSize, |
| 210 | &async)) |
| 211 | return NULL; |
| 212 | _err = SndStartFilePlay(_self->ob_itself, |
| 213 | fRefNum, |
| 214 | resNum, |
| 215 | bufferSize, |
| 216 | 0, |
| 217 | 0, |
| 218 | 0, |
| 219 | async); |
| 220 | if (_err != noErr) return PyMac_Error(_err); |
| 221 | Py_INCREF(Py_None); |
| 222 | _res = Py_None; |
| 223 | return _res; |
| 224 | } |
| 225 | |
| 226 | static PyObject *SndCh_SndPauseFilePlay(_self, _args) |
| 227 | SndChannelObject *_self; |
| 228 | PyObject *_args; |
| 229 | { |
| 230 | PyObject *_res = NULL; |
| 231 | OSErr _err; |
| 232 | if (!PyArg_ParseTuple(_args, "")) |
| 233 | return NULL; |
| 234 | _err = SndPauseFilePlay(_self->ob_itself); |
| 235 | if (_err != noErr) return PyMac_Error(_err); |
| 236 | Py_INCREF(Py_None); |
| 237 | _res = Py_None; |
| 238 | return _res; |
| 239 | } |
| 240 | |
| 241 | static PyObject *SndCh_SndStopFilePlay(_self, _args) |
| 242 | SndChannelObject *_self; |
| 243 | PyObject *_args; |
| 244 | { |
| 245 | PyObject *_res = NULL; |
| 246 | OSErr _err; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 247 | Boolean quietNow; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 248 | if (!PyArg_ParseTuple(_args, "b", |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 249 | &quietNow)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 250 | return NULL; |
| 251 | _err = SndStopFilePlay(_self->ob_itself, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 252 | quietNow); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 253 | if (_err != noErr) return PyMac_Error(_err); |
| 254 | Py_INCREF(Py_None); |
| 255 | _res = Py_None; |
| 256 | return _res; |
| 257 | } |
| 258 | |
| 259 | static PyObject *SndCh_SndChannelStatus(_self, _args) |
| 260 | SndChannelObject *_self; |
| 261 | PyObject *_args; |
| 262 | { |
| 263 | PyObject *_res = NULL; |
| 264 | OSErr _err; |
| 265 | short theLength; |
| 266 | SCStatus theStatus__out__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 267 | if (!PyArg_ParseTuple(_args, "h", |
| 268 | &theLength)) |
| 269 | return NULL; |
| 270 | _err = SndChannelStatus(_self->ob_itself, |
| 271 | theLength, |
| 272 | &theStatus__out__); |
| 273 | if (_err != noErr) return PyMac_Error(_err); |
| 274 | _res = Py_BuildValue("s#", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 275 | (char *)&theStatus__out__, (int)sizeof(SCStatus)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 276 | theStatus__error__: ; |
| 277 | return _res; |
| 278 | } |
| 279 | |
| 280 | static PyMethodDef SndCh_methods[] = { |
| 281 | {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1, |
| 282 | "(SndCommand cmd, Boolean noWait) -> None"}, |
| 283 | {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1, |
| 284 | "(SndCommand cmd) -> None"}, |
| 285 | {"SndPlay", (PyCFunction)SndCh_SndPlay, 1, |
Guido van Rossum | 0818a4c | 1995-02-05 16:53:45 +0000 | [diff] [blame] | 286 | "(SndListHandle sndHdl, Boolean async) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 287 | {"SndStartFilePlay", (PyCFunction)SndCh_SndStartFilePlay, 1, |
| 288 | "(short fRefNum, short resNum, long bufferSize, Boolean async) -> None"}, |
| 289 | {"SndPauseFilePlay", (PyCFunction)SndCh_SndPauseFilePlay, 1, |
| 290 | "() -> None"}, |
| 291 | {"SndStopFilePlay", (PyCFunction)SndCh_SndStopFilePlay, 1, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 292 | "(Boolean quietNow) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 293 | {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1, |
| 294 | "(short theLength) -> (SCStatus theStatus)"}, |
| 295 | {NULL, NULL, 0} |
| 296 | }; |
| 297 | |
| 298 | static PyMethodChain SndCh_chain = { SndCh_methods, NULL }; |
| 299 | |
| 300 | static PyObject *SndCh_getattr(self, name) |
| 301 | SndChannelObject *self; |
| 302 | char *name; |
| 303 | { |
| 304 | return Py_FindMethodInChain(&SndCh_chain, (PyObject *)self, name); |
| 305 | } |
| 306 | |
| 307 | #define SndCh_setattr NULL |
| 308 | |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 309 | staticforward PyTypeObject SndChannel_Type = { |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 310 | PyObject_HEAD_INIT(&PyType_Type) |
| 311 | 0, /*ob_size*/ |
| 312 | "SndChannel", /*tp_name*/ |
| 313 | sizeof(SndChannelObject), /*tp_basicsize*/ |
| 314 | 0, /*tp_itemsize*/ |
| 315 | /* methods */ |
| 316 | (destructor) SndCh_dealloc, /*tp_dealloc*/ |
| 317 | 0, /*tp_print*/ |
| 318 | (getattrfunc) SndCh_getattr, /*tp_getattr*/ |
| 319 | (setattrfunc) SndCh_setattr, /*tp_setattr*/ |
| 320 | }; |
| 321 | |
| 322 | /* ------------------- End object type SndChannel ------------------- */ |
| 323 | |
| 324 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 325 | static PyObject *Snd_SetSoundVol(_self, _args) |
| 326 | PyObject *_self; |
| 327 | PyObject *_args; |
| 328 | { |
| 329 | PyObject *_res = NULL; |
| 330 | short level; |
| 331 | if (!PyArg_ParseTuple(_args, "h", |
| 332 | &level)) |
| 333 | return NULL; |
| 334 | SetSoundVol(level); |
| 335 | Py_INCREF(Py_None); |
| 336 | _res = Py_None; |
| 337 | return _res; |
| 338 | } |
| 339 | |
| 340 | static PyObject *Snd_GetSoundVol(_self, _args) |
| 341 | PyObject *_self; |
| 342 | PyObject *_args; |
| 343 | { |
| 344 | PyObject *_res = NULL; |
| 345 | short level; |
| 346 | if (!PyArg_ParseTuple(_args, "")) |
| 347 | return NULL; |
| 348 | GetSoundVol(&level); |
| 349 | _res = Py_BuildValue("h", |
| 350 | level); |
| 351 | return _res; |
| 352 | } |
| 353 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 354 | static PyObject *Snd_SndNewChannel(_self, _args) |
| 355 | PyObject *_self; |
| 356 | PyObject *_args; |
| 357 | { |
| 358 | PyObject *_res = NULL; |
| 359 | OSErr _err; |
| 360 | SndChannelPtr chan = 0; |
| 361 | short synth; |
| 362 | long init; |
| 363 | PyObject* userRoutine; |
| 364 | if (!PyArg_ParseTuple(_args, "hlO", |
| 365 | &synth, |
| 366 | &init, |
| 367 | &userRoutine)) |
| 368 | return NULL; |
Guido van Rossum | 0818a4c | 1995-02-05 16:53:45 +0000 | [diff] [blame] | 369 | if (userRoutine != Py_None && !PyCallable_Check(userRoutine)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 370 | { |
| 371 | PyErr_SetString(PyExc_TypeError, "callback must be callable"); |
| 372 | goto userRoutine__error__; |
| 373 | } |
| 374 | _err = SndNewChannel(&chan, |
| 375 | synth, |
| 376 | init, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 377 | NewSndCallBackProc(SndCh_UserRoutine)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 378 | if (_err != noErr) return PyMac_Error(_err); |
| 379 | _res = Py_BuildValue("O&", |
| 380 | SndCh_New, chan); |
| 381 | if (_res != NULL && userRoutine != Py_None) |
| 382 | { |
| 383 | SndChannelObject *p = (SndChannelObject *)_res; |
| 384 | p->ob_itself->userInfo = (long)p; |
| 385 | Py_INCREF(userRoutine); |
| 386 | p->ob_callback = userRoutine; |
| 387 | } |
| 388 | userRoutine__error__: ; |
| 389 | return _res; |
| 390 | } |
| 391 | |
| 392 | static PyObject *Snd_SndControl(_self, _args) |
| 393 | PyObject *_self; |
| 394 | PyObject *_args; |
| 395 | { |
| 396 | PyObject *_res = NULL; |
| 397 | OSErr _err; |
| 398 | short id; |
| 399 | SndCommand cmd; |
| 400 | if (!PyArg_ParseTuple(_args, "h", |
| 401 | &id)) |
| 402 | return NULL; |
| 403 | _err = SndControl(id, |
| 404 | &cmd); |
| 405 | if (_err != noErr) return PyMac_Error(_err); |
| 406 | _res = Py_BuildValue("O&", |
| 407 | SndCmd_New, &cmd); |
| 408 | return _res; |
| 409 | } |
| 410 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 411 | static PyObject *Snd_SndSoundManagerVersion(_self, _args) |
| 412 | PyObject *_self; |
| 413 | PyObject *_args; |
| 414 | { |
| 415 | PyObject *_res = NULL; |
| 416 | NumVersion _rv; |
| 417 | if (!PyArg_ParseTuple(_args, "")) |
| 418 | return NULL; |
| 419 | _rv = SndSoundManagerVersion(); |
| 420 | _res = Py_BuildValue("O&", |
| 421 | NumVer_New, _rv); |
| 422 | return _res; |
| 423 | } |
| 424 | |
| 425 | static PyObject *Snd_SndManagerStatus(_self, _args) |
| 426 | PyObject *_self; |
| 427 | PyObject *_args; |
| 428 | { |
| 429 | PyObject *_res = NULL; |
| 430 | OSErr _err; |
| 431 | short theLength; |
| 432 | SMStatus theStatus__out__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 433 | if (!PyArg_ParseTuple(_args, "h", |
| 434 | &theLength)) |
| 435 | return NULL; |
| 436 | _err = SndManagerStatus(theLength, |
| 437 | &theStatus__out__); |
| 438 | if (_err != noErr) return PyMac_Error(_err); |
| 439 | _res = Py_BuildValue("s#", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 440 | (char *)&theStatus__out__, (int)sizeof(SMStatus)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 441 | theStatus__error__: ; |
| 442 | return _res; |
| 443 | } |
| 444 | |
| 445 | static PyObject *Snd_SndGetSysBeepState(_self, _args) |
| 446 | PyObject *_self; |
| 447 | PyObject *_args; |
| 448 | { |
| 449 | PyObject *_res = NULL; |
| 450 | short sysBeepState; |
| 451 | if (!PyArg_ParseTuple(_args, "")) |
| 452 | return NULL; |
| 453 | SndGetSysBeepState(&sysBeepState); |
| 454 | _res = Py_BuildValue("h", |
| 455 | sysBeepState); |
| 456 | return _res; |
| 457 | } |
| 458 | |
| 459 | static PyObject *Snd_SndSetSysBeepState(_self, _args) |
| 460 | PyObject *_self; |
| 461 | PyObject *_args; |
| 462 | { |
| 463 | PyObject *_res = NULL; |
| 464 | OSErr _err; |
| 465 | short sysBeepState; |
| 466 | if (!PyArg_ParseTuple(_args, "h", |
| 467 | &sysBeepState)) |
| 468 | return NULL; |
| 469 | _err = SndSetSysBeepState(sysBeepState); |
| 470 | if (_err != noErr) return PyMac_Error(_err); |
| 471 | Py_INCREF(Py_None); |
| 472 | _res = Py_None; |
| 473 | return _res; |
| 474 | } |
| 475 | |
| 476 | static PyObject *Snd_MACEVersion(_self, _args) |
| 477 | PyObject *_self; |
| 478 | PyObject *_args; |
| 479 | { |
| 480 | PyObject *_res = NULL; |
| 481 | NumVersion _rv; |
| 482 | if (!PyArg_ParseTuple(_args, "")) |
| 483 | return NULL; |
| 484 | _rv = MACEVersion(); |
| 485 | _res = Py_BuildValue("O&", |
| 486 | NumVer_New, _rv); |
| 487 | return _res; |
| 488 | } |
| 489 | |
| 490 | static PyObject *Snd_Comp3to1(_self, _args) |
| 491 | PyObject *_self; |
| 492 | PyObject *_args; |
| 493 | { |
| 494 | PyObject *_res = NULL; |
| 495 | char *buffer__in__; |
| 496 | char *buffer__out__; |
| 497 | long buffer__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 498 | int buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 499 | StateBlock *state__in__; |
| 500 | StateBlock state__out__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 501 | int state__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 502 | unsigned long numChannels; |
| 503 | unsigned long whichChannel; |
| 504 | if (!PyArg_ParseTuple(_args, "s#s#ll", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 505 | &buffer__in__, &buffer__in_len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 506 | (char **)&state__in__, &state__in_len__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 507 | &numChannels, |
| 508 | &whichChannel)) |
| 509 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 510 | if ((buffer__out__ = malloc(buffer__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 511 | { |
| 512 | PyErr_NoMemory(); |
| 513 | goto buffer__error__; |
| 514 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 515 | buffer__len__ = buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 516 | if (state__in_len__ != sizeof(StateBlock)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 517 | { |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 518 | PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 519 | goto state__error__; |
| 520 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 521 | Comp3to1(buffer__in__, buffer__out__, (long)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 522 | state__in__, &state__out__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 523 | numChannels, |
| 524 | whichChannel); |
| 525 | _res = Py_BuildValue("s#s#", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 526 | buffer__out__, (int)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 527 | (char *)&state__out__, (int)sizeof(StateBlock)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 528 | state__error__: ; |
| 529 | free(buffer__out__); |
| 530 | buffer__error__: ; |
| 531 | return _res; |
| 532 | } |
| 533 | |
| 534 | static PyObject *Snd_Exp1to3(_self, _args) |
| 535 | PyObject *_self; |
| 536 | PyObject *_args; |
| 537 | { |
| 538 | PyObject *_res = NULL; |
| 539 | char *buffer__in__; |
| 540 | char *buffer__out__; |
| 541 | long buffer__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 542 | int buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 543 | StateBlock *state__in__; |
| 544 | StateBlock state__out__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 545 | int state__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 546 | unsigned long numChannels; |
| 547 | unsigned long whichChannel; |
| 548 | if (!PyArg_ParseTuple(_args, "s#s#ll", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 549 | &buffer__in__, &buffer__in_len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 550 | (char **)&state__in__, &state__in_len__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 551 | &numChannels, |
| 552 | &whichChannel)) |
| 553 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 554 | if ((buffer__out__ = malloc(buffer__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 555 | { |
| 556 | PyErr_NoMemory(); |
| 557 | goto buffer__error__; |
| 558 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 559 | buffer__len__ = buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 560 | if (state__in_len__ != sizeof(StateBlock)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 561 | { |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 562 | PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 563 | goto state__error__; |
| 564 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 565 | Exp1to3(buffer__in__, buffer__out__, (long)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 566 | state__in__, &state__out__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 567 | numChannels, |
| 568 | whichChannel); |
| 569 | _res = Py_BuildValue("s#s#", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 570 | buffer__out__, (int)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 571 | (char *)&state__out__, (int)sizeof(StateBlock)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 572 | state__error__: ; |
| 573 | free(buffer__out__); |
| 574 | buffer__error__: ; |
| 575 | return _res; |
| 576 | } |
| 577 | |
| 578 | static PyObject *Snd_Comp6to1(_self, _args) |
| 579 | PyObject *_self; |
| 580 | PyObject *_args; |
| 581 | { |
| 582 | PyObject *_res = NULL; |
| 583 | char *buffer__in__; |
| 584 | char *buffer__out__; |
| 585 | long buffer__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 586 | int buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 587 | StateBlock *state__in__; |
| 588 | StateBlock state__out__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 589 | int state__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 590 | unsigned long numChannels; |
| 591 | unsigned long whichChannel; |
| 592 | if (!PyArg_ParseTuple(_args, "s#s#ll", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 593 | &buffer__in__, &buffer__in_len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 594 | (char **)&state__in__, &state__in_len__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 595 | &numChannels, |
| 596 | &whichChannel)) |
| 597 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 598 | if ((buffer__out__ = malloc(buffer__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 599 | { |
| 600 | PyErr_NoMemory(); |
| 601 | goto buffer__error__; |
| 602 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 603 | buffer__len__ = buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 604 | if (state__in_len__ != sizeof(StateBlock)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 605 | { |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 606 | PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 607 | goto state__error__; |
| 608 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 609 | Comp6to1(buffer__in__, buffer__out__, (long)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 610 | state__in__, &state__out__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 611 | numChannels, |
| 612 | whichChannel); |
| 613 | _res = Py_BuildValue("s#s#", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 614 | buffer__out__, (int)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 615 | (char *)&state__out__, (int)sizeof(StateBlock)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 616 | state__error__: ; |
| 617 | free(buffer__out__); |
| 618 | buffer__error__: ; |
| 619 | return _res; |
| 620 | } |
| 621 | |
| 622 | static PyObject *Snd_Exp1to6(_self, _args) |
| 623 | PyObject *_self; |
| 624 | PyObject *_args; |
| 625 | { |
| 626 | PyObject *_res = NULL; |
| 627 | char *buffer__in__; |
| 628 | char *buffer__out__; |
| 629 | long buffer__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 630 | int buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 631 | StateBlock *state__in__; |
| 632 | StateBlock state__out__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 633 | int state__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 634 | unsigned long numChannels; |
| 635 | unsigned long whichChannel; |
| 636 | if (!PyArg_ParseTuple(_args, "s#s#ll", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 637 | &buffer__in__, &buffer__in_len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 638 | (char **)&state__in__, &state__in_len__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 639 | &numChannels, |
| 640 | &whichChannel)) |
| 641 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 642 | if ((buffer__out__ = malloc(buffer__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 643 | { |
| 644 | PyErr_NoMemory(); |
| 645 | goto buffer__error__; |
| 646 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 647 | buffer__len__ = buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 648 | if (state__in_len__ != sizeof(StateBlock)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 649 | { |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 650 | PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 651 | goto state__error__; |
| 652 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 653 | Exp1to6(buffer__in__, buffer__out__, (long)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 654 | state__in__, &state__out__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 655 | numChannels, |
| 656 | whichChannel); |
| 657 | _res = Py_BuildValue("s#s#", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 658 | buffer__out__, (int)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 659 | (char *)&state__out__, (int)sizeof(StateBlock)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 660 | state__error__: ; |
| 661 | free(buffer__out__); |
| 662 | buffer__error__: ; |
| 663 | return _res; |
| 664 | } |
| 665 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 666 | static PyObject *Snd_GetSysBeepVolume(_self, _args) |
| 667 | PyObject *_self; |
| 668 | PyObject *_args; |
| 669 | { |
| 670 | PyObject *_res = NULL; |
| 671 | OSErr _err; |
| 672 | long level; |
| 673 | if (!PyArg_ParseTuple(_args, "")) |
| 674 | return NULL; |
| 675 | _err = GetSysBeepVolume(&level); |
| 676 | if (_err != noErr) return PyMac_Error(_err); |
| 677 | _res = Py_BuildValue("l", |
| 678 | level); |
| 679 | return _res; |
| 680 | } |
| 681 | |
| 682 | static PyObject *Snd_SetSysBeepVolume(_self, _args) |
| 683 | PyObject *_self; |
| 684 | PyObject *_args; |
| 685 | { |
| 686 | PyObject *_res = NULL; |
| 687 | OSErr _err; |
| 688 | long level; |
| 689 | if (!PyArg_ParseTuple(_args, "l", |
| 690 | &level)) |
| 691 | return NULL; |
| 692 | _err = SetSysBeepVolume(level); |
| 693 | if (_err != noErr) return PyMac_Error(_err); |
| 694 | Py_INCREF(Py_None); |
| 695 | _res = Py_None; |
| 696 | return _res; |
| 697 | } |
| 698 | |
| 699 | static PyObject *Snd_GetDefaultOutputVolume(_self, _args) |
| 700 | PyObject *_self; |
| 701 | PyObject *_args; |
| 702 | { |
| 703 | PyObject *_res = NULL; |
| 704 | OSErr _err; |
| 705 | long level; |
| 706 | if (!PyArg_ParseTuple(_args, "")) |
| 707 | return NULL; |
| 708 | _err = GetDefaultOutputVolume(&level); |
| 709 | if (_err != noErr) return PyMac_Error(_err); |
| 710 | _res = Py_BuildValue("l", |
| 711 | level); |
| 712 | return _res; |
| 713 | } |
| 714 | |
| 715 | static PyObject *Snd_SetDefaultOutputVolume(_self, _args) |
| 716 | PyObject *_self; |
| 717 | PyObject *_args; |
| 718 | { |
| 719 | PyObject *_res = NULL; |
| 720 | OSErr _err; |
| 721 | long level; |
| 722 | if (!PyArg_ParseTuple(_args, "l", |
| 723 | &level)) |
| 724 | return NULL; |
| 725 | _err = SetDefaultOutputVolume(level); |
| 726 | if (_err != noErr) return PyMac_Error(_err); |
| 727 | Py_INCREF(Py_None); |
| 728 | _res = Py_None; |
| 729 | return _res; |
| 730 | } |
| 731 | |
| 732 | static PyObject *Snd_GetSoundHeaderOffset(_self, _args) |
| 733 | PyObject *_self; |
| 734 | PyObject *_args; |
| 735 | { |
| 736 | PyObject *_res = NULL; |
| 737 | OSErr _err; |
| 738 | SndListHandle sndHandle; |
| 739 | long offset; |
| 740 | if (!PyArg_ParseTuple(_args, "O&", |
| 741 | ResObj_Convert, &sndHandle)) |
| 742 | return NULL; |
| 743 | _err = GetSoundHeaderOffset(sndHandle, |
| 744 | &offset); |
| 745 | if (_err != noErr) return PyMac_Error(_err); |
| 746 | _res = Py_BuildValue("l", |
| 747 | offset); |
| 748 | return _res; |
| 749 | } |
| 750 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 751 | static PyMethodDef Snd_methods[] = { |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 752 | {"SetSoundVol", (PyCFunction)Snd_SetSoundVol, 1, |
| 753 | "(short level) -> None"}, |
| 754 | {"GetSoundVol", (PyCFunction)Snd_GetSoundVol, 1, |
| 755 | "() -> (short level)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 756 | {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1, |
| 757 | "(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)"}, |
| 758 | {"SndControl", (PyCFunction)Snd_SndControl, 1, |
| 759 | "(short id) -> (SndCommand cmd)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 760 | {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1, |
| 761 | "() -> (NumVersion _rv)"}, |
| 762 | {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1, |
| 763 | "(short theLength) -> (SMStatus theStatus)"}, |
| 764 | {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1, |
| 765 | "() -> (short sysBeepState)"}, |
| 766 | {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1, |
| 767 | "(short sysBeepState) -> None"}, |
| 768 | {"MACEVersion", (PyCFunction)Snd_MACEVersion, 1, |
| 769 | "() -> (NumVersion _rv)"}, |
| 770 | {"Comp3to1", (PyCFunction)Snd_Comp3to1, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 771 | "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 772 | {"Exp1to3", (PyCFunction)Snd_Exp1to3, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 773 | "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 774 | {"Comp6to1", (PyCFunction)Snd_Comp6to1, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 775 | "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 776 | {"Exp1to6", (PyCFunction)Snd_Exp1to6, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 777 | "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 778 | {"GetSysBeepVolume", (PyCFunction)Snd_GetSysBeepVolume, 1, |
| 779 | "() -> (long level)"}, |
| 780 | {"SetSysBeepVolume", (PyCFunction)Snd_SetSysBeepVolume, 1, |
| 781 | "(long level) -> None"}, |
| 782 | {"GetDefaultOutputVolume", (PyCFunction)Snd_GetDefaultOutputVolume, 1, |
| 783 | "() -> (long level)"}, |
| 784 | {"SetDefaultOutputVolume", (PyCFunction)Snd_SetDefaultOutputVolume, 1, |
| 785 | "(long level) -> None"}, |
| 786 | {"GetSoundHeaderOffset", (PyCFunction)Snd_GetSoundHeaderOffset, 1, |
| 787 | "(SndListHandle sndHandle) -> (long offset)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 788 | {NULL, NULL, 0} |
| 789 | }; |
| 790 | |
| 791 | |
| 792 | |
| 793 | /* Routine passed to Py_AddPendingCall -- call the Python callback */ |
| 794 | static int |
| 795 | SndCh_CallCallBack(arg) |
| 796 | void *arg; |
| 797 | { |
| 798 | SndChannelObject *p = (SndChannelObject *)arg; |
| 799 | PyObject *args; |
| 800 | PyObject *res; |
| 801 | args = Py_BuildValue("(O(hhl))", |
| 802 | p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2); |
| 803 | res = PyEval_CallObject(p->ob_callback, args); |
| 804 | Py_DECREF(args); |
| 805 | if (res == NULL) |
| 806 | return -1; |
| 807 | Py_DECREF(res); |
| 808 | return 0; |
| 809 | } |
| 810 | |
| 811 | /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */ |
| 812 | static pascal void |
| 813 | SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd) |
| 814 | { |
| 815 | SndChannelObject *p = (SndChannelObject *)(chan->userInfo); |
| 816 | if (p->ob_callback != NULL) { |
| 817 | long A5 = SetA5(p->ob_A5); |
| 818 | p->ob_cmd = *cmd; |
| 819 | Py_AddPendingCall(SndCh_CallCallBack, (void *)p); |
| 820 | SetA5(A5); |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | |
| 825 | void initSnd() |
| 826 | { |
| 827 | PyObject *m; |
| 828 | PyObject *d; |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | m = Py_InitModule("Snd", Snd_methods); |
| 835 | d = PyModule_GetDict(m); |
| 836 | Snd_Error = PyMac_GetOSErrException(); |
| 837 | if (Snd_Error == NULL || |
| 838 | PyDict_SetItemString(d, "Error", Snd_Error) != 0) |
| 839 | Py_FatalError("can't initialize Snd.Error"); |
| 840 | } |
| 841 | |
| 842 | /* ========================= End module Snd ========================= */ |
| 843 | |