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