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 | |
| 33 | #include <Sound.h> |
| 34 | |
| 35 | #ifndef __MWERKS__ |
| 36 | #define SndCallBackUPP ProcPtr |
| 37 | #define NewSndCallBackProc(x) (x) |
| 38 | #define SndListHandle Handle |
| 39 | #endif |
| 40 | |
| 41 | #include <OSUtils.h> /* for Set(Current)A5 */ |
| 42 | |
| 43 | /* Create a SndCommand object (an (int, int, int) tuple) */ |
| 44 | static PyObject * |
| 45 | SndCmd_New(SndCommand *pc) |
| 46 | { |
| 47 | return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2); |
| 48 | } |
| 49 | |
| 50 | /* Convert a SndCommand argument */ |
| 51 | static int |
| 52 | SndCmd_Convert(PyObject *v, SndCommand *pc) |
| 53 | { |
| 54 | int len; |
| 55 | pc->param1 = 0; |
| 56 | pc->param2 = 0; |
| 57 | if (PyTuple_Check(v)) { |
| 58 | if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2)) |
| 59 | return 1; |
| 60 | PyErr_Clear(); |
| 61 | return PyArg_ParseTuple(v, "hhs#", &pc->cmd, &pc->param1, &pc->param2, &len); |
| 62 | } |
| 63 | return PyArg_Parse(v, "h", &pc->cmd); |
| 64 | } |
| 65 | |
| 66 | /* Create a NumVersion object (a quintuple of integers) */ |
| 67 | static PyObject * |
| 68 | NumVer_New(NumVersion nv) |
| 69 | { |
| 70 | return Py_BuildValue("iiiii", |
| 71 | nv.majorRev, |
Guido van Rossum | 0818a4c | 1995-02-05 16:53:45 +0000 | [diff] [blame] | 72 | #ifdef THINK_C |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 73 | nv.minorRev, |
| 74 | nv.bugFixRev, |
Guido van Rossum | 0818a4c | 1995-02-05 16:53:45 +0000 | [diff] [blame] | 75 | #else |
| 76 | (nv.minorAndBugRev>>4) & 0xf, |
| 77 | nv.minorAndBugRev & 0xf, |
| 78 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 79 | nv.stage, |
| 80 | nv.nonRelRev); |
| 81 | } |
| 82 | |
| 83 | static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */ |
| 84 | |
| 85 | static PyObject *Snd_Error; |
| 86 | |
| 87 | /* --------------------- Object type SndChannel --------------------- */ |
| 88 | |
| 89 | staticforward PyTypeObject SndChannel_Type; |
| 90 | |
| 91 | #define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type) |
| 92 | |
| 93 | typedef struct SndChannelObject { |
| 94 | PyObject_HEAD |
| 95 | SndChannelPtr ob_itself; |
| 96 | /* Members used to implement callbacks: */ |
| 97 | PyObject *ob_callback; |
| 98 | long ob_A5; |
| 99 | SndCommand ob_cmd; |
| 100 | } SndChannelObject; |
| 101 | |
| 102 | static PyObject *SndCh_New(itself) |
| 103 | const SndChannelPtr itself; |
| 104 | { |
| 105 | SndChannelObject *it; |
| 106 | it = PyObject_NEW(SndChannelObject, &SndChannel_Type); |
| 107 | if (it == NULL) return NULL; |
| 108 | it->ob_itself = itself; |
| 109 | it->ob_callback = NULL; |
| 110 | it->ob_A5 = SetCurrentA5(); |
| 111 | return (PyObject *)it; |
| 112 | } |
| 113 | static SndCh_Convert(v, p_itself) |
| 114 | PyObject *v; |
| 115 | SndChannelPtr *p_itself; |
| 116 | { |
| 117 | if (!SndCh_Check(v)) |
| 118 | { |
| 119 | PyErr_SetString(PyExc_TypeError, "SndChannel required"); |
| 120 | return 0; |
| 121 | } |
| 122 | *p_itself = ((SndChannelObject *)v)->ob_itself; |
| 123 | return 1; |
| 124 | } |
| 125 | |
| 126 | static void SndCh_dealloc(self) |
| 127 | SndChannelObject *self; |
| 128 | { |
| 129 | SndDisposeChannel(self->ob_itself, 1); |
| 130 | Py_XDECREF(self->ob_callback); |
| 131 | PyMem_DEL(self); |
| 132 | } |
| 133 | |
| 134 | static PyObject *SndCh_SndDoCommand(_self, _args) |
| 135 | SndChannelObject *_self; |
| 136 | PyObject *_args; |
| 137 | { |
| 138 | PyObject *_res = NULL; |
| 139 | OSErr _err; |
| 140 | SndCommand cmd; |
| 141 | Boolean noWait; |
| 142 | if (!PyArg_ParseTuple(_args, "O&b", |
| 143 | SndCmd_Convert, &cmd, |
| 144 | &noWait)) |
| 145 | return NULL; |
| 146 | _err = SndDoCommand(_self->ob_itself, |
| 147 | &cmd, |
| 148 | noWait); |
| 149 | if (_err != noErr) return PyMac_Error(_err); |
| 150 | Py_INCREF(Py_None); |
| 151 | _res = Py_None; |
| 152 | return _res; |
| 153 | } |
| 154 | |
| 155 | static PyObject *SndCh_SndDoImmediate(_self, _args) |
| 156 | SndChannelObject *_self; |
| 157 | PyObject *_args; |
| 158 | { |
| 159 | PyObject *_res = NULL; |
| 160 | OSErr _err; |
| 161 | SndCommand cmd; |
| 162 | if (!PyArg_ParseTuple(_args, "O&", |
| 163 | SndCmd_Convert, &cmd)) |
| 164 | return NULL; |
| 165 | _err = SndDoImmediate(_self->ob_itself, |
| 166 | &cmd); |
| 167 | if (_err != noErr) return PyMac_Error(_err); |
| 168 | Py_INCREF(Py_None); |
| 169 | _res = Py_None; |
| 170 | return _res; |
| 171 | } |
| 172 | |
| 173 | static PyObject *SndCh_SndPlay(_self, _args) |
| 174 | SndChannelObject *_self; |
| 175 | PyObject *_args; |
| 176 | { |
| 177 | PyObject *_res = NULL; |
| 178 | OSErr _err; |
Guido van Rossum | 0818a4c | 1995-02-05 16:53:45 +0000 | [diff] [blame] | 179 | SndListHandle sndHdl; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 180 | Boolean async; |
| 181 | if (!PyArg_ParseTuple(_args, "O&b", |
| 182 | ResObj_Convert, &sndHdl, |
| 183 | &async)) |
| 184 | return NULL; |
| 185 | _err = SndPlay(_self->ob_itself, |
| 186 | sndHdl, |
| 187 | async); |
| 188 | if (_err != noErr) return PyMac_Error(_err); |
| 189 | Py_INCREF(Py_None); |
| 190 | _res = Py_None; |
| 191 | return _res; |
| 192 | } |
| 193 | |
| 194 | static PyObject *SndCh_SndStartFilePlay(_self, _args) |
| 195 | SndChannelObject *_self; |
| 196 | PyObject *_args; |
| 197 | { |
| 198 | PyObject *_res = NULL; |
| 199 | OSErr _err; |
| 200 | short fRefNum; |
| 201 | short resNum; |
| 202 | long bufferSize; |
| 203 | Boolean async; |
| 204 | if (!PyArg_ParseTuple(_args, "hhlb", |
| 205 | &fRefNum, |
| 206 | &resNum, |
| 207 | &bufferSize, |
| 208 | &async)) |
| 209 | return NULL; |
| 210 | _err = SndStartFilePlay(_self->ob_itself, |
| 211 | fRefNum, |
| 212 | resNum, |
| 213 | bufferSize, |
| 214 | 0, |
| 215 | 0, |
| 216 | 0, |
| 217 | async); |
| 218 | if (_err != noErr) return PyMac_Error(_err); |
| 219 | Py_INCREF(Py_None); |
| 220 | _res = Py_None; |
| 221 | return _res; |
| 222 | } |
| 223 | |
| 224 | static PyObject *SndCh_SndPauseFilePlay(_self, _args) |
| 225 | SndChannelObject *_self; |
| 226 | PyObject *_args; |
| 227 | { |
| 228 | PyObject *_res = NULL; |
| 229 | OSErr _err; |
| 230 | if (!PyArg_ParseTuple(_args, "")) |
| 231 | return NULL; |
| 232 | _err = SndPauseFilePlay(_self->ob_itself); |
| 233 | if (_err != noErr) return PyMac_Error(_err); |
| 234 | Py_INCREF(Py_None); |
| 235 | _res = Py_None; |
| 236 | return _res; |
| 237 | } |
| 238 | |
| 239 | static PyObject *SndCh_SndStopFilePlay(_self, _args) |
| 240 | SndChannelObject *_self; |
| 241 | PyObject *_args; |
| 242 | { |
| 243 | PyObject *_res = NULL; |
| 244 | OSErr _err; |
| 245 | Boolean async; |
| 246 | if (!PyArg_ParseTuple(_args, "b", |
| 247 | &async)) |
| 248 | return NULL; |
| 249 | _err = SndStopFilePlay(_self->ob_itself, |
| 250 | async); |
| 251 | if (_err != noErr) return PyMac_Error(_err); |
| 252 | Py_INCREF(Py_None); |
| 253 | _res = Py_None; |
| 254 | return _res; |
| 255 | } |
| 256 | |
| 257 | static PyObject *SndCh_SndChannelStatus(_self, _args) |
| 258 | SndChannelObject *_self; |
| 259 | PyObject *_args; |
| 260 | { |
| 261 | PyObject *_res = NULL; |
| 262 | OSErr _err; |
| 263 | short theLength; |
| 264 | SCStatus theStatus__out__; |
| 265 | int theStatus__len__; |
| 266 | if (!PyArg_ParseTuple(_args, "h", |
| 267 | &theLength)) |
| 268 | return NULL; |
| 269 | _err = SndChannelStatus(_self->ob_itself, |
| 270 | theLength, |
| 271 | &theStatus__out__); |
| 272 | if (_err != noErr) return PyMac_Error(_err); |
| 273 | _res = Py_BuildValue("s#", |
| 274 | (char *)&theStatus__out__, sizeof(SCStatus)); |
| 275 | theStatus__error__: ; |
| 276 | return _res; |
| 277 | } |
| 278 | |
| 279 | static PyMethodDef SndCh_methods[] = { |
| 280 | {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1, |
| 281 | "(SndCommand cmd, Boolean noWait) -> None"}, |
| 282 | {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1, |
| 283 | "(SndCommand cmd) -> None"}, |
| 284 | {"SndPlay", (PyCFunction)SndCh_SndPlay, 1, |
Guido van Rossum | 0818a4c | 1995-02-05 16:53:45 +0000 | [diff] [blame] | 285 | "(SndListHandle sndHdl, Boolean async) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 286 | {"SndStartFilePlay", (PyCFunction)SndCh_SndStartFilePlay, 1, |
| 287 | "(short fRefNum, short resNum, long bufferSize, Boolean async) -> None"}, |
| 288 | {"SndPauseFilePlay", (PyCFunction)SndCh_SndPauseFilePlay, 1, |
| 289 | "() -> None"}, |
| 290 | {"SndStopFilePlay", (PyCFunction)SndCh_SndStopFilePlay, 1, |
| 291 | "(Boolean async) -> None"}, |
| 292 | {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1, |
| 293 | "(short theLength) -> (SCStatus theStatus)"}, |
| 294 | {NULL, NULL, 0} |
| 295 | }; |
| 296 | |
| 297 | static PyMethodChain SndCh_chain = { SndCh_methods, NULL }; |
| 298 | |
| 299 | static PyObject *SndCh_getattr(self, name) |
| 300 | SndChannelObject *self; |
| 301 | char *name; |
| 302 | { |
| 303 | return Py_FindMethodInChain(&SndCh_chain, (PyObject *)self, name); |
| 304 | } |
| 305 | |
| 306 | #define SndCh_setattr NULL |
| 307 | |
| 308 | static PyTypeObject SndChannel_Type = { |
| 309 | PyObject_HEAD_INIT(&PyType_Type) |
| 310 | 0, /*ob_size*/ |
| 311 | "SndChannel", /*tp_name*/ |
| 312 | sizeof(SndChannelObject), /*tp_basicsize*/ |
| 313 | 0, /*tp_itemsize*/ |
| 314 | /* methods */ |
| 315 | (destructor) SndCh_dealloc, /*tp_dealloc*/ |
| 316 | 0, /*tp_print*/ |
| 317 | (getattrfunc) SndCh_getattr, /*tp_getattr*/ |
| 318 | (setattrfunc) SndCh_setattr, /*tp_setattr*/ |
| 319 | }; |
| 320 | |
| 321 | /* ------------------- End object type SndChannel ------------------- */ |
| 322 | |
| 323 | |
| 324 | static PyObject *Snd_SndNewChannel(_self, _args) |
| 325 | PyObject *_self; |
| 326 | PyObject *_args; |
| 327 | { |
| 328 | PyObject *_res = NULL; |
| 329 | OSErr _err; |
| 330 | SndChannelPtr chan = 0; |
| 331 | short synth; |
| 332 | long init; |
| 333 | PyObject* userRoutine; |
| 334 | if (!PyArg_ParseTuple(_args, "hlO", |
| 335 | &synth, |
| 336 | &init, |
| 337 | &userRoutine)) |
| 338 | return NULL; |
Guido van Rossum | 0818a4c | 1995-02-05 16:53:45 +0000 | [diff] [blame] | 339 | if (userRoutine != Py_None && !PyCallable_Check(userRoutine)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 340 | { |
| 341 | PyErr_SetString(PyExc_TypeError, "callback must be callable"); |
| 342 | goto userRoutine__error__; |
| 343 | } |
| 344 | _err = SndNewChannel(&chan, |
| 345 | synth, |
| 346 | init, |
| 347 | (SndCallBackProcPtr)&SndCh_UserRoutine); |
| 348 | if (_err != noErr) return PyMac_Error(_err); |
| 349 | _res = Py_BuildValue("O&", |
| 350 | SndCh_New, chan); |
| 351 | if (_res != NULL && userRoutine != Py_None) |
| 352 | { |
| 353 | SndChannelObject *p = (SndChannelObject *)_res; |
| 354 | p->ob_itself->userInfo = (long)p; |
| 355 | Py_INCREF(userRoutine); |
| 356 | p->ob_callback = userRoutine; |
| 357 | } |
| 358 | userRoutine__error__: ; |
| 359 | return _res; |
| 360 | } |
| 361 | |
| 362 | static PyObject *Snd_SndControl(_self, _args) |
| 363 | PyObject *_self; |
| 364 | PyObject *_args; |
| 365 | { |
| 366 | PyObject *_res = NULL; |
| 367 | OSErr _err; |
| 368 | short id; |
| 369 | SndCommand cmd; |
| 370 | if (!PyArg_ParseTuple(_args, "h", |
| 371 | &id)) |
| 372 | return NULL; |
| 373 | _err = SndControl(id, |
| 374 | &cmd); |
| 375 | if (_err != noErr) return PyMac_Error(_err); |
| 376 | _res = Py_BuildValue("O&", |
| 377 | SndCmd_New, &cmd); |
| 378 | return _res; |
| 379 | } |
| 380 | |
| 381 | static PyObject *Snd_SetSoundVol(_self, _args) |
| 382 | PyObject *_self; |
| 383 | PyObject *_args; |
| 384 | { |
| 385 | PyObject *_res = NULL; |
| 386 | short level; |
| 387 | if (!PyArg_ParseTuple(_args, "h", |
| 388 | &level)) |
| 389 | return NULL; |
| 390 | SetSoundVol(level); |
| 391 | Py_INCREF(Py_None); |
| 392 | _res = Py_None; |
| 393 | return _res; |
| 394 | } |
| 395 | |
| 396 | static PyObject *Snd_GetSoundVol(_self, _args) |
| 397 | PyObject *_self; |
| 398 | PyObject *_args; |
| 399 | { |
| 400 | PyObject *_res = NULL; |
| 401 | short level; |
| 402 | if (!PyArg_ParseTuple(_args, "")) |
| 403 | return NULL; |
| 404 | GetSoundVol(&level); |
| 405 | _res = Py_BuildValue("h", |
| 406 | level); |
| 407 | return _res; |
| 408 | } |
| 409 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 410 | static PyObject *Snd_SndSoundManagerVersion(_self, _args) |
| 411 | PyObject *_self; |
| 412 | PyObject *_args; |
| 413 | { |
| 414 | PyObject *_res = NULL; |
| 415 | NumVersion _rv; |
| 416 | if (!PyArg_ParseTuple(_args, "")) |
| 417 | return NULL; |
| 418 | _rv = SndSoundManagerVersion(); |
| 419 | _res = Py_BuildValue("O&", |
| 420 | NumVer_New, _rv); |
| 421 | return _res; |
| 422 | } |
| 423 | |
| 424 | static PyObject *Snd_SndManagerStatus(_self, _args) |
| 425 | PyObject *_self; |
| 426 | PyObject *_args; |
| 427 | { |
| 428 | PyObject *_res = NULL; |
| 429 | OSErr _err; |
| 430 | short theLength; |
| 431 | SMStatus theStatus__out__; |
| 432 | int theStatus__len__; |
| 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#", |
| 440 | (char *)&theStatus__out__, sizeof(SMStatus)); |
| 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__; |
| 498 | char *state__in__; |
| 499 | char state__out__[128]; |
| 500 | int state__len__; |
| 501 | unsigned long numChannels; |
| 502 | unsigned long whichChannel; |
| 503 | if (!PyArg_ParseTuple(_args, "s#s#ll", |
| 504 | &buffer__in__, &buffer__len__, |
| 505 | &state__in__, &state__len__, |
| 506 | &numChannels, |
| 507 | &whichChannel)) |
| 508 | return NULL; |
| 509 | if ((buffer__out__ = malloc(buffer__len__)) == NULL) |
| 510 | { |
| 511 | PyErr_NoMemory(); |
| 512 | goto buffer__error__; |
| 513 | } |
| 514 | if (state__len__ != 128) |
| 515 | { |
| 516 | PyErr_SetString(PyExc_TypeError, "buffer length should be 128"); |
| 517 | goto state__error__; |
| 518 | } |
| 519 | Comp3to1(buffer__in__, buffer__out__, buffer__len__, |
| 520 | state__in__, state__out__, |
| 521 | numChannels, |
| 522 | whichChannel); |
| 523 | _res = Py_BuildValue("s#s#", |
| 524 | buffer__out__, buffer__len__, |
| 525 | state__out__, 128); |
| 526 | state__error__: ; |
| 527 | free(buffer__out__); |
| 528 | buffer__error__: ; |
| 529 | return _res; |
| 530 | } |
| 531 | |
| 532 | static PyObject *Snd_Exp1to3(_self, _args) |
| 533 | PyObject *_self; |
| 534 | PyObject *_args; |
| 535 | { |
| 536 | PyObject *_res = NULL; |
| 537 | char *buffer__in__; |
| 538 | char *buffer__out__; |
| 539 | long buffer__len__; |
| 540 | char *state__in__; |
| 541 | char state__out__[128]; |
| 542 | int state__len__; |
| 543 | unsigned long numChannels; |
| 544 | unsigned long whichChannel; |
| 545 | if (!PyArg_ParseTuple(_args, "s#s#ll", |
| 546 | &buffer__in__, &buffer__len__, |
| 547 | &state__in__, &state__len__, |
| 548 | &numChannels, |
| 549 | &whichChannel)) |
| 550 | return NULL; |
| 551 | if ((buffer__out__ = malloc(buffer__len__)) == NULL) |
| 552 | { |
| 553 | PyErr_NoMemory(); |
| 554 | goto buffer__error__; |
| 555 | } |
| 556 | if (state__len__ != 128) |
| 557 | { |
| 558 | PyErr_SetString(PyExc_TypeError, "buffer length should be 128"); |
| 559 | goto state__error__; |
| 560 | } |
| 561 | Exp1to3(buffer__in__, buffer__out__, buffer__len__, |
| 562 | state__in__, state__out__, |
| 563 | numChannels, |
| 564 | whichChannel); |
| 565 | _res = Py_BuildValue("s#s#", |
| 566 | buffer__out__, buffer__len__, |
| 567 | state__out__, 128); |
| 568 | state__error__: ; |
| 569 | free(buffer__out__); |
| 570 | buffer__error__: ; |
| 571 | return _res; |
| 572 | } |
| 573 | |
| 574 | static PyObject *Snd_Comp6to1(_self, _args) |
| 575 | PyObject *_self; |
| 576 | PyObject *_args; |
| 577 | { |
| 578 | PyObject *_res = NULL; |
| 579 | char *buffer__in__; |
| 580 | char *buffer__out__; |
| 581 | long buffer__len__; |
| 582 | char *state__in__; |
| 583 | char state__out__[128]; |
| 584 | int state__len__; |
| 585 | unsigned long numChannels; |
| 586 | unsigned long whichChannel; |
| 587 | if (!PyArg_ParseTuple(_args, "s#s#ll", |
| 588 | &buffer__in__, &buffer__len__, |
| 589 | &state__in__, &state__len__, |
| 590 | &numChannels, |
| 591 | &whichChannel)) |
| 592 | return NULL; |
| 593 | if ((buffer__out__ = malloc(buffer__len__)) == NULL) |
| 594 | { |
| 595 | PyErr_NoMemory(); |
| 596 | goto buffer__error__; |
| 597 | } |
| 598 | if (state__len__ != 128) |
| 599 | { |
| 600 | PyErr_SetString(PyExc_TypeError, "buffer length should be 128"); |
| 601 | goto state__error__; |
| 602 | } |
| 603 | Comp6to1(buffer__in__, buffer__out__, buffer__len__, |
| 604 | state__in__, state__out__, |
| 605 | numChannels, |
| 606 | whichChannel); |
| 607 | _res = Py_BuildValue("s#s#", |
| 608 | buffer__out__, buffer__len__, |
| 609 | state__out__, 128); |
| 610 | state__error__: ; |
| 611 | free(buffer__out__); |
| 612 | buffer__error__: ; |
| 613 | return _res; |
| 614 | } |
| 615 | |
| 616 | static PyObject *Snd_Exp1to6(_self, _args) |
| 617 | PyObject *_self; |
| 618 | PyObject *_args; |
| 619 | { |
| 620 | PyObject *_res = NULL; |
| 621 | char *buffer__in__; |
| 622 | char *buffer__out__; |
| 623 | long buffer__len__; |
| 624 | char *state__in__; |
| 625 | char state__out__[128]; |
| 626 | int state__len__; |
| 627 | unsigned long numChannels; |
| 628 | unsigned long whichChannel; |
| 629 | if (!PyArg_ParseTuple(_args, "s#s#ll", |
| 630 | &buffer__in__, &buffer__len__, |
| 631 | &state__in__, &state__len__, |
| 632 | &numChannels, |
| 633 | &whichChannel)) |
| 634 | return NULL; |
| 635 | if ((buffer__out__ = malloc(buffer__len__)) == NULL) |
| 636 | { |
| 637 | PyErr_NoMemory(); |
| 638 | goto buffer__error__; |
| 639 | } |
| 640 | if (state__len__ != 128) |
| 641 | { |
| 642 | PyErr_SetString(PyExc_TypeError, "buffer length should be 128"); |
| 643 | goto state__error__; |
| 644 | } |
| 645 | Exp1to6(buffer__in__, buffer__out__, buffer__len__, |
| 646 | state__in__, state__out__, |
| 647 | numChannels, |
| 648 | whichChannel); |
| 649 | _res = Py_BuildValue("s#s#", |
| 650 | buffer__out__, buffer__len__, |
| 651 | state__out__, 128); |
| 652 | state__error__: ; |
| 653 | free(buffer__out__); |
| 654 | buffer__error__: ; |
| 655 | return _res; |
| 656 | } |
| 657 | |
| 658 | static PyMethodDef Snd_methods[] = { |
| 659 | {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1, |
| 660 | "(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)"}, |
| 661 | {"SndControl", (PyCFunction)Snd_SndControl, 1, |
| 662 | "(short id) -> (SndCommand cmd)"}, |
| 663 | {"SetSoundVol", (PyCFunction)Snd_SetSoundVol, 1, |
| 664 | "(short level) -> None"}, |
| 665 | {"GetSoundVol", (PyCFunction)Snd_GetSoundVol, 1, |
| 666 | "() -> (short level)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 667 | {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1, |
| 668 | "() -> (NumVersion _rv)"}, |
| 669 | {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1, |
| 670 | "(short theLength) -> (SMStatus theStatus)"}, |
| 671 | {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1, |
| 672 | "() -> (short sysBeepState)"}, |
| 673 | {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1, |
| 674 | "(short sysBeepState) -> None"}, |
| 675 | {"MACEVersion", (PyCFunction)Snd_MACEVersion, 1, |
| 676 | "() -> (NumVersion _rv)"}, |
| 677 | {"Comp3to1", (PyCFunction)Snd_Comp3to1, 1, |
| 678 | "(Buffer buffer, Buffer state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, Buffer state)"}, |
| 679 | {"Exp1to3", (PyCFunction)Snd_Exp1to3, 1, |
| 680 | "(Buffer buffer, Buffer state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, Buffer state)"}, |
| 681 | {"Comp6to1", (PyCFunction)Snd_Comp6to1, 1, |
| 682 | "(Buffer buffer, Buffer state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, Buffer state)"}, |
| 683 | {"Exp1to6", (PyCFunction)Snd_Exp1to6, 1, |
| 684 | "(Buffer buffer, Buffer state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, Buffer state)"}, |
| 685 | {NULL, NULL, 0} |
| 686 | }; |
| 687 | |
| 688 | |
| 689 | |
| 690 | /* Routine passed to Py_AddPendingCall -- call the Python callback */ |
| 691 | static int |
| 692 | SndCh_CallCallBack(arg) |
| 693 | void *arg; |
| 694 | { |
| 695 | SndChannelObject *p = (SndChannelObject *)arg; |
| 696 | PyObject *args; |
| 697 | PyObject *res; |
| 698 | args = Py_BuildValue("(O(hhl))", |
| 699 | p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2); |
| 700 | res = PyEval_CallObject(p->ob_callback, args); |
| 701 | Py_DECREF(args); |
| 702 | if (res == NULL) |
| 703 | return -1; |
| 704 | Py_DECREF(res); |
| 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */ |
| 709 | static pascal void |
| 710 | SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd) |
| 711 | { |
| 712 | SndChannelObject *p = (SndChannelObject *)(chan->userInfo); |
| 713 | if (p->ob_callback != NULL) { |
| 714 | long A5 = SetA5(p->ob_A5); |
| 715 | p->ob_cmd = *cmd; |
| 716 | Py_AddPendingCall(SndCh_CallCallBack, (void *)p); |
| 717 | SetA5(A5); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | |
| 722 | void initSnd() |
| 723 | { |
| 724 | PyObject *m; |
| 725 | PyObject *d; |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | |
| 731 | m = Py_InitModule("Snd", Snd_methods); |
| 732 | d = PyModule_GetDict(m); |
| 733 | Snd_Error = PyMac_GetOSErrException(); |
| 734 | if (Snd_Error == NULL || |
| 735 | PyDict_SetItemString(d, "Error", Snd_Error) != 0) |
| 736 | Py_FatalError("can't initialize Snd.Error"); |
| 737 | } |
| 738 | |
| 739 | /* ========================= End module Snd ========================= */ |
| 740 | |