This commit was manufactured by cvs2svn to create tag 'r212'.
[python/dscho.git] / Mac / Modules / snd / Sndmodule.c
bloba561a9560159287fca764242e810132916380131
2 /* =========================== Module Snd =========================== */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #ifdef WITHOUT_FRAMEWORKS
12 #include <Sound.h>
13 #include <OSUtils.h> /* for Set(Current)A5 */
14 #else
15 #include <Carbon/Carbon.h>
16 #endif
19 /* Create a SndCommand object (an (int, int, int) tuple) */
20 static PyObject *
21 SndCmd_New(SndCommand *pc)
23 return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2);
26 /* Convert a SndCommand argument */
27 static int
28 SndCmd_Convert(PyObject *v, SndCommand *pc)
30 int len;
31 pc->param1 = 0;
32 pc->param2 = 0;
33 if (PyTuple_Check(v)) {
34 if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2))
35 return 1;
36 PyErr_Clear();
37 return PyArg_ParseTuple(v, "Hhs#", &pc->cmd, &pc->param1, &pc->param2, &len);
39 return PyArg_Parse(v, "H", &pc->cmd);
42 static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */
43 static pascal void SPB_completion(SPBPtr my_spb); /* Forward */
44 #if !TARGET_API_MAC_CARBON
45 static pascal void SPB_interrupt(SPBPtr my_spb); /* Forward */
46 #endif
48 static PyObject *Snd_Error;
50 /* --------------------- Object type SndChannel --------------------- */
52 staticforward PyTypeObject SndChannel_Type;
54 #define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type)
56 typedef struct SndChannelObject {
57 PyObject_HEAD
58 SndChannelPtr ob_itself;
59 /* Members used to implement callbacks: */
60 PyObject *ob_callback;
61 long ob_A5;
62 SndCommand ob_cmd;
63 } SndChannelObject;
65 static PyObject *SndCh_New(SndChannelPtr itself)
67 SndChannelObject *it;
68 it = PyObject_NEW(SndChannelObject, &SndChannel_Type);
69 if (it == NULL) return NULL;
70 it->ob_itself = itself;
71 it->ob_callback = NULL;
72 it->ob_A5 = SetCurrentA5();
73 return (PyObject *)it;
75 static SndCh_Convert(PyObject *v, SndChannelPtr *p_itself)
77 if (!SndCh_Check(v))
79 PyErr_SetString(PyExc_TypeError, "SndChannel required");
80 return 0;
82 *p_itself = ((SndChannelObject *)v)->ob_itself;
83 return 1;
86 static void SndCh_dealloc(SndChannelObject *self)
88 SndDisposeChannel(self->ob_itself, 1);
89 Py_XDECREF(self->ob_callback);
90 PyMem_DEL(self);
93 static PyObject *SndCh_SndDoCommand(SndChannelObject *_self, PyObject *_args)
95 PyObject *_res = NULL;
96 OSErr _err;
97 SndCommand cmd;
98 Boolean noWait;
99 if (!PyArg_ParseTuple(_args, "O&b",
100 SndCmd_Convert, &cmd,
101 &noWait))
102 return NULL;
103 _err = SndDoCommand(_self->ob_itself,
104 &cmd,
105 noWait);
106 if (_err != noErr) return PyMac_Error(_err);
107 Py_INCREF(Py_None);
108 _res = Py_None;
109 return _res;
112 static PyObject *SndCh_SndDoImmediate(SndChannelObject *_self, PyObject *_args)
114 PyObject *_res = NULL;
115 OSErr _err;
116 SndCommand cmd;
117 if (!PyArg_ParseTuple(_args, "O&",
118 SndCmd_Convert, &cmd))
119 return NULL;
120 _err = SndDoImmediate(_self->ob_itself,
121 &cmd);
122 if (_err != noErr) return PyMac_Error(_err);
123 Py_INCREF(Py_None);
124 _res = Py_None;
125 return _res;
128 static PyObject *SndCh_SndPlay(SndChannelObject *_self, PyObject *_args)
130 PyObject *_res = NULL;
131 OSErr _err;
132 SndListHandle sndHandle;
133 Boolean async;
134 if (!PyArg_ParseTuple(_args, "O&b",
135 ResObj_Convert, &sndHandle,
136 &async))
137 return NULL;
138 _err = SndPlay(_self->ob_itself,
139 sndHandle,
140 async);
141 if (_err != noErr) return PyMac_Error(_err);
142 Py_INCREF(Py_None);
143 _res = Py_None;
144 return _res;
147 #if !TARGET_API_MAC_CARBON
149 static PyObject *SndCh_SndStartFilePlay(SndChannelObject *_self, PyObject *_args)
151 PyObject *_res = NULL;
152 OSErr _err;
153 short fRefNum;
154 short resNum;
155 long bufferSize;
156 Boolean async;
157 if (!PyArg_ParseTuple(_args, "hhlb",
158 &fRefNum,
159 &resNum,
160 &bufferSize,
161 &async))
162 return NULL;
163 _err = SndStartFilePlay(_self->ob_itself,
164 fRefNum,
165 resNum,
166 bufferSize,
170 async);
171 if (_err != noErr) return PyMac_Error(_err);
172 Py_INCREF(Py_None);
173 _res = Py_None;
174 return _res;
176 #endif
178 #if !TARGET_API_MAC_CARBON
180 static PyObject *SndCh_SndPauseFilePlay(SndChannelObject *_self, PyObject *_args)
182 PyObject *_res = NULL;
183 OSErr _err;
184 if (!PyArg_ParseTuple(_args, ""))
185 return NULL;
186 _err = SndPauseFilePlay(_self->ob_itself);
187 if (_err != noErr) return PyMac_Error(_err);
188 Py_INCREF(Py_None);
189 _res = Py_None;
190 return _res;
192 #endif
194 #if !TARGET_API_MAC_CARBON
196 static PyObject *SndCh_SndStopFilePlay(SndChannelObject *_self, PyObject *_args)
198 PyObject *_res = NULL;
199 OSErr _err;
200 Boolean quietNow;
201 if (!PyArg_ParseTuple(_args, "b",
202 &quietNow))
203 return NULL;
204 _err = SndStopFilePlay(_self->ob_itself,
205 quietNow);
206 if (_err != noErr) return PyMac_Error(_err);
207 Py_INCREF(Py_None);
208 _res = Py_None;
209 return _res;
211 #endif
213 static PyObject *SndCh_SndChannelStatus(SndChannelObject *_self, PyObject *_args)
215 PyObject *_res = NULL;
216 OSErr _err;
217 short theLength;
218 SCStatus theStatus__out__;
219 if (!PyArg_ParseTuple(_args, "h",
220 &theLength))
221 return NULL;
222 _err = SndChannelStatus(_self->ob_itself,
223 theLength,
224 &theStatus__out__);
225 if (_err != noErr) return PyMac_Error(_err);
226 _res = Py_BuildValue("s#",
227 (char *)&theStatus__out__, (int)sizeof(SCStatus));
228 theStatus__error__: ;
229 return _res;
232 static PyObject *SndCh_SndGetInfo(SndChannelObject *_self, PyObject *_args)
234 PyObject *_res = NULL;
235 OSErr _err;
236 OSType selector;
237 void * infoPtr;
238 if (!PyArg_ParseTuple(_args, "O&w",
239 PyMac_GetOSType, &selector,
240 &infoPtr))
241 return NULL;
242 _err = SndGetInfo(_self->ob_itself,
243 selector,
244 infoPtr);
245 if (_err != noErr) return PyMac_Error(_err);
246 Py_INCREF(Py_None);
247 _res = Py_None;
248 return _res;
251 static PyObject *SndCh_SndSetInfo(SndChannelObject *_self, PyObject *_args)
253 PyObject *_res = NULL;
254 OSErr _err;
255 OSType selector;
256 void * infoPtr;
257 if (!PyArg_ParseTuple(_args, "O&w",
258 PyMac_GetOSType, &selector,
259 &infoPtr))
260 return NULL;
261 _err = SndSetInfo(_self->ob_itself,
262 selector,
263 infoPtr);
264 if (_err != noErr) return PyMac_Error(_err);
265 Py_INCREF(Py_None);
266 _res = Py_None;
267 return _res;
270 static PyMethodDef SndCh_methods[] = {
271 {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1,
272 "(SndCommand cmd, Boolean noWait) -> None"},
273 {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1,
274 "(SndCommand cmd) -> None"},
275 {"SndPlay", (PyCFunction)SndCh_SndPlay, 1,
276 "(SndListHandle sndHandle, Boolean async) -> None"},
278 #if !TARGET_API_MAC_CARBON
279 {"SndStartFilePlay", (PyCFunction)SndCh_SndStartFilePlay, 1,
280 "(short fRefNum, short resNum, long bufferSize, Boolean async) -> None"},
281 #endif
283 #if !TARGET_API_MAC_CARBON
284 {"SndPauseFilePlay", (PyCFunction)SndCh_SndPauseFilePlay, 1,
285 "() -> None"},
286 #endif
288 #if !TARGET_API_MAC_CARBON
289 {"SndStopFilePlay", (PyCFunction)SndCh_SndStopFilePlay, 1,
290 "(Boolean quietNow) -> None"},
291 #endif
292 {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1,
293 "(short theLength) -> (SCStatus theStatus)"},
294 {"SndGetInfo", (PyCFunction)SndCh_SndGetInfo, 1,
295 "(OSType selector, void * infoPtr) -> None"},
296 {"SndSetInfo", (PyCFunction)SndCh_SndSetInfo, 1,
297 "(OSType selector, void * infoPtr) -> None"},
298 {NULL, NULL, 0}
301 static PyMethodChain SndCh_chain = { SndCh_methods, NULL };
303 static PyObject *SndCh_getattr(SndChannelObject *self, char *name)
305 return Py_FindMethodInChain(&SndCh_chain, (PyObject *)self, name);
308 #define SndCh_setattr NULL
310 #define SndCh_compare NULL
312 #define SndCh_repr NULL
314 #define SndCh_hash NULL
316 staticforward PyTypeObject SndChannel_Type = {
317 PyObject_HEAD_INIT(&PyType_Type)
318 0, /*ob_size*/
319 "SndChannel", /*tp_name*/
320 sizeof(SndChannelObject), /*tp_basicsize*/
321 0, /*tp_itemsize*/
322 /* methods */
323 (destructor) SndCh_dealloc, /*tp_dealloc*/
324 0, /*tp_print*/
325 (getattrfunc) SndCh_getattr, /*tp_getattr*/
326 (setattrfunc) SndCh_setattr, /*tp_setattr*/
327 (cmpfunc) SndCh_compare, /*tp_compare*/
328 (reprfunc) SndCh_repr, /*tp_repr*/
329 (PyNumberMethods *)0, /* tp_as_number */
330 (PySequenceMethods *)0, /* tp_as_sequence */
331 (PyMappingMethods *)0, /* tp_as_mapping */
332 (hashfunc) SndCh_hash, /*tp_hash*/
335 /* ------------------- End object type SndChannel ------------------- */
338 /* ------------------------ Object type SPB ------------------------- */
340 staticforward PyTypeObject SPB_Type;
342 #define SPBObj_Check(x) ((x)->ob_type == &SPB_Type)
344 typedef struct SPBObject {
345 PyObject_HEAD
346 /* Members used to implement callbacks: */
347 PyObject *ob_completion;
348 PyObject *ob_interrupt;
349 PyObject *ob_thiscallback;
350 long ob_A5;
351 SPB ob_spb;
352 } SPBObject;
354 static PyObject *SPBObj_New(void)
356 SPBObject *it;
357 it = PyObject_NEW(SPBObject, &SPB_Type);
358 if (it == NULL) return NULL;
359 it->ob_completion = NULL;
360 it->ob_interrupt = NULL;
361 it->ob_thiscallback = NULL;
362 it->ob_A5 = SetCurrentA5();
363 memset((char *)&it->ob_spb, 0, sizeof(it->ob_spb));
364 it->ob_spb.userLong = (long)it;
365 return (PyObject *)it;
367 static SPBObj_Convert(PyObject *v, SPBPtr *p_itself)
369 if (!SPBObj_Check(v))
371 PyErr_SetString(PyExc_TypeError, "SPB required");
372 return 0;
374 *p_itself = &((SPBObject *)v)->ob_spb;
375 return 1;
378 static void SPBObj_dealloc(SPBObject *self)
380 /* Cleanup of self->ob_itself goes here */
381 self->ob_spb.userLong = 0;
382 self->ob_thiscallback = 0;
383 Py_XDECREF(self->ob_completion);
384 Py_XDECREF(self->ob_interrupt);
385 PyMem_DEL(self);
388 static PyMethodDef SPBObj_methods[] = {
389 {NULL, NULL, 0}
392 static PyMethodChain SPBObj_chain = { SPBObj_methods, NULL };
394 static PyObject *SPBObj_getattr(SPBObject *self, char *name)
397 if (strcmp(name, "inRefNum") == 0)
398 return Py_BuildValue("l", self->ob_spb.inRefNum);
399 else if (strcmp(name, "count") == 0)
400 return Py_BuildValue("l", self->ob_spb.count);
401 else if (strcmp(name, "milliseconds") == 0)
402 return Py_BuildValue("l", self->ob_spb.milliseconds);
403 else if (strcmp(name, "error") == 0)
404 return Py_BuildValue("h", self->ob_spb.error);
405 return Py_FindMethodInChain(&SPBObj_chain, (PyObject *)self, name);
408 static int SPBObj_setattr(SPBObject *self, char *name, PyObject *value)
411 int rv = 0;
413 if (strcmp(name, "inRefNum") == 0)
414 rv = PyArg_Parse(value, "l", &self->ob_spb.inRefNum);
415 else if (strcmp(name, "count") == 0)
416 rv = PyArg_Parse(value, "l", &self->ob_spb.count);
417 else if (strcmp(name, "milliseconds") == 0)
418 rv = PyArg_Parse(value, "l", &self->ob_spb.milliseconds);
419 else if (strcmp(name, "buffer") == 0)
420 rv = PyArg_Parse(value, "w#", &self->ob_spb.bufferPtr, &self->ob_spb.bufferLength);
421 else if (strcmp(name, "completionRoutine") == 0) {
422 self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
423 self->ob_completion = value;
424 Py_INCREF(value);
425 rv = 1;
426 #if !TARGET_API_MAC_CARBON
427 } else if (strcmp(name, "interruptRoutine") == 0) {
428 self->ob_spb.completionRoutine = NewSIInterruptUPP(SPB_interrupt);
429 self->ob_interrupt = value;
430 Py_INCREF(value);
431 rv = 1;
432 #endif
434 if ( rv ) return 0;
435 else return -1;
438 #define SPBObj_compare NULL
440 #define SPBObj_repr NULL
442 #define SPBObj_hash NULL
444 staticforward PyTypeObject SPB_Type = {
445 PyObject_HEAD_INIT(&PyType_Type)
446 0, /*ob_size*/
447 "SPB", /*tp_name*/
448 sizeof(SPBObject), /*tp_basicsize*/
449 0, /*tp_itemsize*/
450 /* methods */
451 (destructor) SPBObj_dealloc, /*tp_dealloc*/
452 0, /*tp_print*/
453 (getattrfunc) SPBObj_getattr, /*tp_getattr*/
454 (setattrfunc) SPBObj_setattr, /*tp_setattr*/
455 (cmpfunc) SPBObj_compare, /*tp_compare*/
456 (reprfunc) SPBObj_repr, /*tp_repr*/
457 (PyNumberMethods *)0, /* tp_as_number */
458 (PySequenceMethods *)0, /* tp_as_sequence */
459 (PyMappingMethods *)0, /* tp_as_mapping */
460 (hashfunc) SPBObj_hash, /*tp_hash*/
463 /* ---------------------- End object type SPB ----------------------- */
466 static PyObject *Snd_SPB(PyObject *_self, PyObject *_args)
468 PyObject *_res = NULL;
469 return SPBObj_New();
472 static PyObject *Snd_SysBeep(PyObject *_self, PyObject *_args)
474 PyObject *_res = NULL;
475 short duration;
476 if (!PyArg_ParseTuple(_args, "h",
477 &duration))
478 return NULL;
479 SysBeep(duration);
480 Py_INCREF(Py_None);
481 _res = Py_None;
482 return _res;
485 static PyObject *Snd_SndNewChannel(PyObject *_self, PyObject *_args)
487 PyObject *_res = NULL;
488 OSErr _err;
489 SndChannelPtr chan = 0;
490 short synth;
491 long init;
492 PyObject* userRoutine;
493 if (!PyArg_ParseTuple(_args, "hlO",
494 &synth,
495 &init,
496 &userRoutine))
497 return NULL;
498 if (userRoutine != Py_None && !PyCallable_Check(userRoutine))
500 PyErr_SetString(PyExc_TypeError, "callback must be callable");
501 goto userRoutine__error__;
503 _err = SndNewChannel(&chan,
504 synth,
505 init,
506 NewSndCallBackUPP(SndCh_UserRoutine));
507 if (_err != noErr) return PyMac_Error(_err);
508 _res = Py_BuildValue("O&",
509 SndCh_New, chan);
510 if (_res != NULL && userRoutine != Py_None)
512 SndChannelObject *p = (SndChannelObject *)_res;
513 p->ob_itself->userInfo = (long)p;
514 Py_INCREF(userRoutine);
515 p->ob_callback = userRoutine;
517 userRoutine__error__: ;
518 return _res;
521 #if !TARGET_API_MAC_CARBON
523 static PyObject *Snd_SndControl(PyObject *_self, PyObject *_args)
525 PyObject *_res = NULL;
526 OSErr _err;
527 short id;
528 SndCommand cmd;
529 if (!PyArg_ParseTuple(_args, "h",
530 &id))
531 return NULL;
532 _err = SndControl(id,
533 &cmd);
534 if (_err != noErr) return PyMac_Error(_err);
535 _res = Py_BuildValue("O&",
536 SndCmd_New, &cmd);
537 return _res;
539 #endif
541 static PyObject *Snd_SndSoundManagerVersion(PyObject *_self, PyObject *_args)
543 PyObject *_res = NULL;
544 NumVersion _rv;
545 if (!PyArg_ParseTuple(_args, ""))
546 return NULL;
547 _rv = SndSoundManagerVersion();
548 _res = Py_BuildValue("O&",
549 PyMac_BuildNumVersion, _rv);
550 return _res;
553 static PyObject *Snd_SndManagerStatus(PyObject *_self, PyObject *_args)
555 PyObject *_res = NULL;
556 OSErr _err;
557 short theLength;
558 SMStatus theStatus__out__;
559 if (!PyArg_ParseTuple(_args, "h",
560 &theLength))
561 return NULL;
562 _err = SndManagerStatus(theLength,
563 &theStatus__out__);
564 if (_err != noErr) return PyMac_Error(_err);
565 _res = Py_BuildValue("s#",
566 (char *)&theStatus__out__, (int)sizeof(SMStatus));
567 theStatus__error__: ;
568 return _res;
571 static PyObject *Snd_SndGetSysBeepState(PyObject *_self, PyObject *_args)
573 PyObject *_res = NULL;
574 short sysBeepState;
575 if (!PyArg_ParseTuple(_args, ""))
576 return NULL;
577 SndGetSysBeepState(&sysBeepState);
578 _res = Py_BuildValue("h",
579 sysBeepState);
580 return _res;
583 static PyObject *Snd_SndSetSysBeepState(PyObject *_self, PyObject *_args)
585 PyObject *_res = NULL;
586 OSErr _err;
587 short sysBeepState;
588 if (!PyArg_ParseTuple(_args, "h",
589 &sysBeepState))
590 return NULL;
591 _err = SndSetSysBeepState(sysBeepState);
592 if (_err != noErr) return PyMac_Error(_err);
593 Py_INCREF(Py_None);
594 _res = Py_None;
595 return _res;
598 #if !TARGET_API_MAC_CARBON
600 static PyObject *Snd_MACEVersion(PyObject *_self, PyObject *_args)
602 PyObject *_res = NULL;
603 NumVersion _rv;
604 if (!PyArg_ParseTuple(_args, ""))
605 return NULL;
606 _rv = MACEVersion();
607 _res = Py_BuildValue("O&",
608 PyMac_BuildNumVersion, _rv);
609 return _res;
611 #endif
613 #if !TARGET_API_MAC_CARBON
615 static PyObject *Snd_Comp3to1(PyObject *_self, PyObject *_args)
617 PyObject *_res = NULL;
618 char *buffer__in__;
619 char *buffer__out__;
620 long buffer__len__;
621 int buffer__in_len__;
622 StateBlock *state__in__;
623 StateBlock state__out__;
624 int state__in_len__;
625 unsigned long numChannels;
626 unsigned long whichChannel;
627 if (!PyArg_ParseTuple(_args, "s#s#ll",
628 &buffer__in__, &buffer__in_len__,
629 (char **)&state__in__, &state__in_len__,
630 &numChannels,
631 &whichChannel))
632 return NULL;
633 if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
635 PyErr_NoMemory();
636 goto buffer__error__;
638 buffer__len__ = buffer__in_len__;
639 if (state__in_len__ != sizeof(StateBlock))
641 PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
642 goto state__error__;
644 Comp3to1(buffer__in__, buffer__out__, (long)buffer__len__,
645 state__in__, &state__out__,
646 numChannels,
647 whichChannel);
648 _res = Py_BuildValue("s#s#",
649 buffer__out__, (int)buffer__len__,
650 (char *)&state__out__, (int)sizeof(StateBlock));
651 state__error__: ;
652 free(buffer__out__);
653 buffer__error__: ;
654 return _res;
656 #endif
658 #if !TARGET_API_MAC_CARBON
660 static PyObject *Snd_Exp1to3(PyObject *_self, PyObject *_args)
662 PyObject *_res = NULL;
663 char *buffer__in__;
664 char *buffer__out__;
665 long buffer__len__;
666 int buffer__in_len__;
667 StateBlock *state__in__;
668 StateBlock state__out__;
669 int state__in_len__;
670 unsigned long numChannels;
671 unsigned long whichChannel;
672 if (!PyArg_ParseTuple(_args, "s#s#ll",
673 &buffer__in__, &buffer__in_len__,
674 (char **)&state__in__, &state__in_len__,
675 &numChannels,
676 &whichChannel))
677 return NULL;
678 if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
680 PyErr_NoMemory();
681 goto buffer__error__;
683 buffer__len__ = buffer__in_len__;
684 if (state__in_len__ != sizeof(StateBlock))
686 PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
687 goto state__error__;
689 Exp1to3(buffer__in__, buffer__out__, (long)buffer__len__,
690 state__in__, &state__out__,
691 numChannels,
692 whichChannel);
693 _res = Py_BuildValue("s#s#",
694 buffer__out__, (int)buffer__len__,
695 (char *)&state__out__, (int)sizeof(StateBlock));
696 state__error__: ;
697 free(buffer__out__);
698 buffer__error__: ;
699 return _res;
701 #endif
703 #if !TARGET_API_MAC_CARBON
705 static PyObject *Snd_Comp6to1(PyObject *_self, PyObject *_args)
707 PyObject *_res = NULL;
708 char *buffer__in__;
709 char *buffer__out__;
710 long buffer__len__;
711 int buffer__in_len__;
712 StateBlock *state__in__;
713 StateBlock state__out__;
714 int state__in_len__;
715 unsigned long numChannels;
716 unsigned long whichChannel;
717 if (!PyArg_ParseTuple(_args, "s#s#ll",
718 &buffer__in__, &buffer__in_len__,
719 (char **)&state__in__, &state__in_len__,
720 &numChannels,
721 &whichChannel))
722 return NULL;
723 if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
725 PyErr_NoMemory();
726 goto buffer__error__;
728 buffer__len__ = buffer__in_len__;
729 if (state__in_len__ != sizeof(StateBlock))
731 PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
732 goto state__error__;
734 Comp6to1(buffer__in__, buffer__out__, (long)buffer__len__,
735 state__in__, &state__out__,
736 numChannels,
737 whichChannel);
738 _res = Py_BuildValue("s#s#",
739 buffer__out__, (int)buffer__len__,
740 (char *)&state__out__, (int)sizeof(StateBlock));
741 state__error__: ;
742 free(buffer__out__);
743 buffer__error__: ;
744 return _res;
746 #endif
748 #if !TARGET_API_MAC_CARBON
750 static PyObject *Snd_Exp1to6(PyObject *_self, PyObject *_args)
752 PyObject *_res = NULL;
753 char *buffer__in__;
754 char *buffer__out__;
755 long buffer__len__;
756 int buffer__in_len__;
757 StateBlock *state__in__;
758 StateBlock state__out__;
759 int state__in_len__;
760 unsigned long numChannels;
761 unsigned long whichChannel;
762 if (!PyArg_ParseTuple(_args, "s#s#ll",
763 &buffer__in__, &buffer__in_len__,
764 (char **)&state__in__, &state__in_len__,
765 &numChannels,
766 &whichChannel))
767 return NULL;
768 if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
770 PyErr_NoMemory();
771 goto buffer__error__;
773 buffer__len__ = buffer__in_len__;
774 if (state__in_len__ != sizeof(StateBlock))
776 PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
777 goto state__error__;
779 Exp1to6(buffer__in__, buffer__out__, (long)buffer__len__,
780 state__in__, &state__out__,
781 numChannels,
782 whichChannel);
783 _res = Py_BuildValue("s#s#",
784 buffer__out__, (int)buffer__len__,
785 (char *)&state__out__, (int)sizeof(StateBlock));
786 state__error__: ;
787 free(buffer__out__);
788 buffer__error__: ;
789 return _res;
791 #endif
793 static PyObject *Snd_GetSysBeepVolume(PyObject *_self, PyObject *_args)
795 PyObject *_res = NULL;
796 OSErr _err;
797 long level;
798 if (!PyArg_ParseTuple(_args, ""))
799 return NULL;
800 _err = GetSysBeepVolume(&level);
801 if (_err != noErr) return PyMac_Error(_err);
802 _res = Py_BuildValue("l",
803 level);
804 return _res;
807 static PyObject *Snd_SetSysBeepVolume(PyObject *_self, PyObject *_args)
809 PyObject *_res = NULL;
810 OSErr _err;
811 long level;
812 if (!PyArg_ParseTuple(_args, "l",
813 &level))
814 return NULL;
815 _err = SetSysBeepVolume(level);
816 if (_err != noErr) return PyMac_Error(_err);
817 Py_INCREF(Py_None);
818 _res = Py_None;
819 return _res;
822 static PyObject *Snd_GetDefaultOutputVolume(PyObject *_self, PyObject *_args)
824 PyObject *_res = NULL;
825 OSErr _err;
826 long level;
827 if (!PyArg_ParseTuple(_args, ""))
828 return NULL;
829 _err = GetDefaultOutputVolume(&level);
830 if (_err != noErr) return PyMac_Error(_err);
831 _res = Py_BuildValue("l",
832 level);
833 return _res;
836 static PyObject *Snd_SetDefaultOutputVolume(PyObject *_self, PyObject *_args)
838 PyObject *_res = NULL;
839 OSErr _err;
840 long level;
841 if (!PyArg_ParseTuple(_args, "l",
842 &level))
843 return NULL;
844 _err = SetDefaultOutputVolume(level);
845 if (_err != noErr) return PyMac_Error(_err);
846 Py_INCREF(Py_None);
847 _res = Py_None;
848 return _res;
851 static PyObject *Snd_GetSoundHeaderOffset(PyObject *_self, PyObject *_args)
853 PyObject *_res = NULL;
854 OSErr _err;
855 SndListHandle sndHandle;
856 long offset;
857 if (!PyArg_ParseTuple(_args, "O&",
858 ResObj_Convert, &sndHandle))
859 return NULL;
860 _err = GetSoundHeaderOffset(sndHandle,
861 &offset);
862 if (_err != noErr) return PyMac_Error(_err);
863 _res = Py_BuildValue("l",
864 offset);
865 return _res;
868 static PyObject *Snd_GetCompressionInfo(PyObject *_self, PyObject *_args)
870 PyObject *_res = NULL;
871 OSErr _err;
872 short compressionID;
873 OSType format;
874 short numChannels;
875 short sampleSize;
876 CompressionInfo cp__out__;
877 if (!PyArg_ParseTuple(_args, "hO&hh",
878 &compressionID,
879 PyMac_GetOSType, &format,
880 &numChannels,
881 &sampleSize))
882 return NULL;
883 _err = GetCompressionInfo(compressionID,
884 format,
885 numChannels,
886 sampleSize,
887 &cp__out__);
888 if (_err != noErr) return PyMac_Error(_err);
889 _res = Py_BuildValue("s#",
890 (char *)&cp__out__, (int)sizeof(CompressionInfo));
891 cp__error__: ;
892 return _res;
895 static PyObject *Snd_SetSoundPreference(PyObject *_self, PyObject *_args)
897 PyObject *_res = NULL;
898 OSErr _err;
899 OSType theType;
900 Str255 name;
901 Handle settings;
902 if (!PyArg_ParseTuple(_args, "O&O&",
903 PyMac_GetOSType, &theType,
904 ResObj_Convert, &settings))
905 return NULL;
906 _err = SetSoundPreference(theType,
907 name,
908 settings);
909 if (_err != noErr) return PyMac_Error(_err);
910 _res = Py_BuildValue("O&",
911 PyMac_BuildStr255, name);
912 return _res;
915 static PyObject *Snd_GetSoundPreference(PyObject *_self, PyObject *_args)
917 PyObject *_res = NULL;
918 OSErr _err;
919 OSType theType;
920 Str255 name;
921 Handle settings;
922 if (!PyArg_ParseTuple(_args, "O&O&",
923 PyMac_GetOSType, &theType,
924 ResObj_Convert, &settings))
925 return NULL;
926 _err = GetSoundPreference(theType,
927 name,
928 settings);
929 if (_err != noErr) return PyMac_Error(_err);
930 _res = Py_BuildValue("O&",
931 PyMac_BuildStr255, name);
932 return _res;
935 static PyObject *Snd_GetCompressionName(PyObject *_self, PyObject *_args)
937 PyObject *_res = NULL;
938 OSErr _err;
939 OSType compressionType;
940 Str255 compressionName;
941 if (!PyArg_ParseTuple(_args, "O&",
942 PyMac_GetOSType, &compressionType))
943 return NULL;
944 _err = GetCompressionName(compressionType,
945 compressionName);
946 if (_err != noErr) return PyMac_Error(_err);
947 _res = Py_BuildValue("O&",
948 PyMac_BuildStr255, compressionName);
949 return _res;
952 static PyObject *Snd_SPBVersion(PyObject *_self, PyObject *_args)
954 PyObject *_res = NULL;
955 NumVersion _rv;
956 if (!PyArg_ParseTuple(_args, ""))
957 return NULL;
958 _rv = SPBVersion();
959 _res = Py_BuildValue("O&",
960 PyMac_BuildNumVersion, _rv);
961 return _res;
964 static PyObject *Snd_SPBSignInDevice(PyObject *_self, PyObject *_args)
966 PyObject *_res = NULL;
967 OSErr _err;
968 short deviceRefNum;
969 Str255 deviceName;
970 if (!PyArg_ParseTuple(_args, "hO&",
971 &deviceRefNum,
972 PyMac_GetStr255, deviceName))
973 return NULL;
974 _err = SPBSignInDevice(deviceRefNum,
975 deviceName);
976 if (_err != noErr) return PyMac_Error(_err);
977 Py_INCREF(Py_None);
978 _res = Py_None;
979 return _res;
982 static PyObject *Snd_SPBSignOutDevice(PyObject *_self, PyObject *_args)
984 PyObject *_res = NULL;
985 OSErr _err;
986 short deviceRefNum;
987 if (!PyArg_ParseTuple(_args, "h",
988 &deviceRefNum))
989 return NULL;
990 _err = SPBSignOutDevice(deviceRefNum);
991 if (_err != noErr) return PyMac_Error(_err);
992 Py_INCREF(Py_None);
993 _res = Py_None;
994 return _res;
997 static PyObject *Snd_SPBGetIndexedDevice(PyObject *_self, PyObject *_args)
999 PyObject *_res = NULL;
1000 OSErr _err;
1001 short count;
1002 Str255 deviceName;
1003 Handle deviceIconHandle;
1004 if (!PyArg_ParseTuple(_args, "h",
1005 &count))
1006 return NULL;
1007 _err = SPBGetIndexedDevice(count,
1008 deviceName,
1009 &deviceIconHandle);
1010 if (_err != noErr) return PyMac_Error(_err);
1011 _res = Py_BuildValue("O&O&",
1012 PyMac_BuildStr255, deviceName,
1013 ResObj_New, deviceIconHandle);
1014 return _res;
1017 static PyObject *Snd_SPBOpenDevice(PyObject *_self, PyObject *_args)
1019 PyObject *_res = NULL;
1020 OSErr _err;
1021 Str255 deviceName;
1022 short permission;
1023 long inRefNum;
1024 if (!PyArg_ParseTuple(_args, "O&h",
1025 PyMac_GetStr255, deviceName,
1026 &permission))
1027 return NULL;
1028 _err = SPBOpenDevice(deviceName,
1029 permission,
1030 &inRefNum);
1031 if (_err != noErr) return PyMac_Error(_err);
1032 _res = Py_BuildValue("l",
1033 inRefNum);
1034 return _res;
1037 static PyObject *Snd_SPBCloseDevice(PyObject *_self, PyObject *_args)
1039 PyObject *_res = NULL;
1040 OSErr _err;
1041 long inRefNum;
1042 if (!PyArg_ParseTuple(_args, "l",
1043 &inRefNum))
1044 return NULL;
1045 _err = SPBCloseDevice(inRefNum);
1046 if (_err != noErr) return PyMac_Error(_err);
1047 Py_INCREF(Py_None);
1048 _res = Py_None;
1049 return _res;
1052 static PyObject *Snd_SPBRecord(PyObject *_self, PyObject *_args)
1054 PyObject *_res = NULL;
1055 OSErr _err;
1056 SPBPtr inParamPtr;
1057 Boolean asynchFlag;
1058 if (!PyArg_ParseTuple(_args, "O&b",
1059 SPBObj_Convert, &inParamPtr,
1060 &asynchFlag))
1061 return NULL;
1062 _err = SPBRecord(inParamPtr,
1063 asynchFlag);
1064 if (_err != noErr) return PyMac_Error(_err);
1065 Py_INCREF(Py_None);
1066 _res = Py_None;
1067 return _res;
1070 #if !TARGET_API_MAC_CARBON
1072 static PyObject *Snd_SPBRecordToFile(PyObject *_self, PyObject *_args)
1074 PyObject *_res = NULL;
1075 OSErr _err;
1076 short fRefNum;
1077 SPBPtr inParamPtr;
1078 Boolean asynchFlag;
1079 if (!PyArg_ParseTuple(_args, "hO&b",
1080 &fRefNum,
1081 SPBObj_Convert, &inParamPtr,
1082 &asynchFlag))
1083 return NULL;
1084 _err = SPBRecordToFile(fRefNum,
1085 inParamPtr,
1086 asynchFlag);
1087 if (_err != noErr) return PyMac_Error(_err);
1088 Py_INCREF(Py_None);
1089 _res = Py_None;
1090 return _res;
1092 #endif
1094 static PyObject *Snd_SPBPauseRecording(PyObject *_self, PyObject *_args)
1096 PyObject *_res = NULL;
1097 OSErr _err;
1098 long inRefNum;
1099 if (!PyArg_ParseTuple(_args, "l",
1100 &inRefNum))
1101 return NULL;
1102 _err = SPBPauseRecording(inRefNum);
1103 if (_err != noErr) return PyMac_Error(_err);
1104 Py_INCREF(Py_None);
1105 _res = Py_None;
1106 return _res;
1109 static PyObject *Snd_SPBResumeRecording(PyObject *_self, PyObject *_args)
1111 PyObject *_res = NULL;
1112 OSErr _err;
1113 long inRefNum;
1114 if (!PyArg_ParseTuple(_args, "l",
1115 &inRefNum))
1116 return NULL;
1117 _err = SPBResumeRecording(inRefNum);
1118 if (_err != noErr) return PyMac_Error(_err);
1119 Py_INCREF(Py_None);
1120 _res = Py_None;
1121 return _res;
1124 static PyObject *Snd_SPBStopRecording(PyObject *_self, PyObject *_args)
1126 PyObject *_res = NULL;
1127 OSErr _err;
1128 long inRefNum;
1129 if (!PyArg_ParseTuple(_args, "l",
1130 &inRefNum))
1131 return NULL;
1132 _err = SPBStopRecording(inRefNum);
1133 if (_err != noErr) return PyMac_Error(_err);
1134 Py_INCREF(Py_None);
1135 _res = Py_None;
1136 return _res;
1139 static PyObject *Snd_SPBGetRecordingStatus(PyObject *_self, PyObject *_args)
1141 PyObject *_res = NULL;
1142 OSErr _err;
1143 long inRefNum;
1144 short recordingStatus;
1145 short meterLevel;
1146 unsigned long totalSamplesToRecord;
1147 unsigned long numberOfSamplesRecorded;
1148 unsigned long totalMsecsToRecord;
1149 unsigned long numberOfMsecsRecorded;
1150 if (!PyArg_ParseTuple(_args, "l",
1151 &inRefNum))
1152 return NULL;
1153 _err = SPBGetRecordingStatus(inRefNum,
1154 &recordingStatus,
1155 &meterLevel,
1156 &totalSamplesToRecord,
1157 &numberOfSamplesRecorded,
1158 &totalMsecsToRecord,
1159 &numberOfMsecsRecorded);
1160 if (_err != noErr) return PyMac_Error(_err);
1161 _res = Py_BuildValue("hhllll",
1162 recordingStatus,
1163 meterLevel,
1164 totalSamplesToRecord,
1165 numberOfSamplesRecorded,
1166 totalMsecsToRecord,
1167 numberOfMsecsRecorded);
1168 return _res;
1171 static PyObject *Snd_SPBGetDeviceInfo(PyObject *_self, PyObject *_args)
1173 PyObject *_res = NULL;
1174 OSErr _err;
1175 long inRefNum;
1176 OSType infoType;
1177 void * infoData;
1178 if (!PyArg_ParseTuple(_args, "lO&w",
1179 &inRefNum,
1180 PyMac_GetOSType, &infoType,
1181 &infoData))
1182 return NULL;
1183 _err = SPBGetDeviceInfo(inRefNum,
1184 infoType,
1185 infoData);
1186 if (_err != noErr) return PyMac_Error(_err);
1187 Py_INCREF(Py_None);
1188 _res = Py_None;
1189 return _res;
1192 static PyObject *Snd_SPBSetDeviceInfo(PyObject *_self, PyObject *_args)
1194 PyObject *_res = NULL;
1195 OSErr _err;
1196 long inRefNum;
1197 OSType infoType;
1198 void * infoData;
1199 if (!PyArg_ParseTuple(_args, "lO&w",
1200 &inRefNum,
1201 PyMac_GetOSType, &infoType,
1202 &infoData))
1203 return NULL;
1204 _err = SPBSetDeviceInfo(inRefNum,
1205 infoType,
1206 infoData);
1207 if (_err != noErr) return PyMac_Error(_err);
1208 Py_INCREF(Py_None);
1209 _res = Py_None;
1210 return _res;
1213 static PyObject *Snd_SPBMillisecondsToBytes(PyObject *_self, PyObject *_args)
1215 PyObject *_res = NULL;
1216 OSErr _err;
1217 long inRefNum;
1218 long milliseconds;
1219 if (!PyArg_ParseTuple(_args, "l",
1220 &inRefNum))
1221 return NULL;
1222 _err = SPBMillisecondsToBytes(inRefNum,
1223 &milliseconds);
1224 if (_err != noErr) return PyMac_Error(_err);
1225 _res = Py_BuildValue("l",
1226 milliseconds);
1227 return _res;
1230 static PyObject *Snd_SPBBytesToMilliseconds(PyObject *_self, PyObject *_args)
1232 PyObject *_res = NULL;
1233 OSErr _err;
1234 long inRefNum;
1235 long byteCount;
1236 if (!PyArg_ParseTuple(_args, "l",
1237 &inRefNum))
1238 return NULL;
1239 _err = SPBBytesToMilliseconds(inRefNum,
1240 &byteCount);
1241 if (_err != noErr) return PyMac_Error(_err);
1242 _res = Py_BuildValue("l",
1243 byteCount);
1244 return _res;
1247 static PyMethodDef Snd_methods[] = {
1248 {"SPB", (PyCFunction)Snd_SPB, 1,
1249 NULL},
1250 {"SysBeep", (PyCFunction)Snd_SysBeep, 1,
1251 "(short duration) -> None"},
1252 {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1,
1253 "(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)"},
1255 #if !TARGET_API_MAC_CARBON
1256 {"SndControl", (PyCFunction)Snd_SndControl, 1,
1257 "(short id) -> (SndCommand cmd)"},
1258 #endif
1259 {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1,
1260 "() -> (NumVersion _rv)"},
1261 {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1,
1262 "(short theLength) -> (SMStatus theStatus)"},
1263 {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1,
1264 "() -> (short sysBeepState)"},
1265 {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1,
1266 "(short sysBeepState) -> None"},
1268 #if !TARGET_API_MAC_CARBON
1269 {"MACEVersion", (PyCFunction)Snd_MACEVersion, 1,
1270 "() -> (NumVersion _rv)"},
1271 #endif
1273 #if !TARGET_API_MAC_CARBON
1274 {"Comp3to1", (PyCFunction)Snd_Comp3to1, 1,
1275 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1276 #endif
1278 #if !TARGET_API_MAC_CARBON
1279 {"Exp1to3", (PyCFunction)Snd_Exp1to3, 1,
1280 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1281 #endif
1283 #if !TARGET_API_MAC_CARBON
1284 {"Comp6to1", (PyCFunction)Snd_Comp6to1, 1,
1285 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1286 #endif
1288 #if !TARGET_API_MAC_CARBON
1289 {"Exp1to6", (PyCFunction)Snd_Exp1to6, 1,
1290 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1291 #endif
1292 {"GetSysBeepVolume", (PyCFunction)Snd_GetSysBeepVolume, 1,
1293 "() -> (long level)"},
1294 {"SetSysBeepVolume", (PyCFunction)Snd_SetSysBeepVolume, 1,
1295 "(long level) -> None"},
1296 {"GetDefaultOutputVolume", (PyCFunction)Snd_GetDefaultOutputVolume, 1,
1297 "() -> (long level)"},
1298 {"SetDefaultOutputVolume", (PyCFunction)Snd_SetDefaultOutputVolume, 1,
1299 "(long level) -> None"},
1300 {"GetSoundHeaderOffset", (PyCFunction)Snd_GetSoundHeaderOffset, 1,
1301 "(SndListHandle sndHandle) -> (long offset)"},
1302 {"GetCompressionInfo", (PyCFunction)Snd_GetCompressionInfo, 1,
1303 "(short compressionID, OSType format, short numChannels, short sampleSize) -> (CompressionInfo cp)"},
1304 {"SetSoundPreference", (PyCFunction)Snd_SetSoundPreference, 1,
1305 "(OSType theType, Handle settings) -> (Str255 name)"},
1306 {"GetSoundPreference", (PyCFunction)Snd_GetSoundPreference, 1,
1307 "(OSType theType, Handle settings) -> (Str255 name)"},
1308 {"GetCompressionName", (PyCFunction)Snd_GetCompressionName, 1,
1309 "(OSType compressionType) -> (Str255 compressionName)"},
1310 {"SPBVersion", (PyCFunction)Snd_SPBVersion, 1,
1311 "() -> (NumVersion _rv)"},
1312 {"SPBSignInDevice", (PyCFunction)Snd_SPBSignInDevice, 1,
1313 "(short deviceRefNum, Str255 deviceName) -> None"},
1314 {"SPBSignOutDevice", (PyCFunction)Snd_SPBSignOutDevice, 1,
1315 "(short deviceRefNum) -> None"},
1316 {"SPBGetIndexedDevice", (PyCFunction)Snd_SPBGetIndexedDevice, 1,
1317 "(short count) -> (Str255 deviceName, Handle deviceIconHandle)"},
1318 {"SPBOpenDevice", (PyCFunction)Snd_SPBOpenDevice, 1,
1319 "(Str255 deviceName, short permission) -> (long inRefNum)"},
1320 {"SPBCloseDevice", (PyCFunction)Snd_SPBCloseDevice, 1,
1321 "(long inRefNum) -> None"},
1322 {"SPBRecord", (PyCFunction)Snd_SPBRecord, 1,
1323 "(SPBPtr inParamPtr, Boolean asynchFlag) -> None"},
1325 #if !TARGET_API_MAC_CARBON
1326 {"SPBRecordToFile", (PyCFunction)Snd_SPBRecordToFile, 1,
1327 "(short fRefNum, SPBPtr inParamPtr, Boolean asynchFlag) -> None"},
1328 #endif
1329 {"SPBPauseRecording", (PyCFunction)Snd_SPBPauseRecording, 1,
1330 "(long inRefNum) -> None"},
1331 {"SPBResumeRecording", (PyCFunction)Snd_SPBResumeRecording, 1,
1332 "(long inRefNum) -> None"},
1333 {"SPBStopRecording", (PyCFunction)Snd_SPBStopRecording, 1,
1334 "(long inRefNum) -> None"},
1335 {"SPBGetRecordingStatus", (PyCFunction)Snd_SPBGetRecordingStatus, 1,
1336 "(long inRefNum) -> (short recordingStatus, short meterLevel, unsigned long totalSamplesToRecord, unsigned long numberOfSamplesRecorded, unsigned long totalMsecsToRecord, unsigned long numberOfMsecsRecorded)"},
1337 {"SPBGetDeviceInfo", (PyCFunction)Snd_SPBGetDeviceInfo, 1,
1338 "(long inRefNum, OSType infoType, void * infoData) -> None"},
1339 {"SPBSetDeviceInfo", (PyCFunction)Snd_SPBSetDeviceInfo, 1,
1340 "(long inRefNum, OSType infoType, void * infoData) -> None"},
1341 {"SPBMillisecondsToBytes", (PyCFunction)Snd_SPBMillisecondsToBytes, 1,
1342 "(long inRefNum) -> (long milliseconds)"},
1343 {"SPBBytesToMilliseconds", (PyCFunction)Snd_SPBBytesToMilliseconds, 1,
1344 "(long inRefNum) -> (long byteCount)"},
1345 {NULL, NULL, 0}
1350 /* Routine passed to Py_AddPendingCall -- call the Python callback */
1351 static int
1352 SndCh_CallCallBack(void *arg)
1354 SndChannelObject *p = (SndChannelObject *)arg;
1355 PyObject *args;
1356 PyObject *res;
1357 args = Py_BuildValue("(O(hhl))",
1358 p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2);
1359 res = PyEval_CallObject(p->ob_callback, args);
1360 Py_DECREF(args);
1361 if (res == NULL)
1362 return -1;
1363 Py_DECREF(res);
1364 return 0;
1367 /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */
1368 static pascal void
1369 SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd)
1371 SndChannelObject *p = (SndChannelObject *)(chan->userInfo);
1372 if (p->ob_callback != NULL) {
1373 long A5 = SetA5(p->ob_A5);
1374 p->ob_cmd = *cmd;
1375 Py_AddPendingCall(SndCh_CallCallBack, (void *)p);
1376 SetA5(A5);
1380 /* SPB callbacks - Schedule callbacks to Python */
1381 static int
1382 SPB_CallCallBack(void *arg)
1384 SPBObject *p = (SPBObject *)arg;
1385 PyObject *args;
1386 PyObject *res;
1388 if ( p->ob_thiscallback == 0 ) return 0;
1389 args = Py_BuildValue("(O)", p);
1390 res = PyEval_CallObject(p->ob_thiscallback, args);
1391 p->ob_thiscallback = 0;
1392 Py_DECREF(args);
1393 if (res == NULL)
1394 return -1;
1395 Py_DECREF(res);
1396 return 0;
1399 static pascal void
1400 SPB_completion(SPBPtr my_spb)
1402 SPBObject *p = (SPBObject *)(my_spb->userLong);
1404 if (p && p->ob_completion) {
1405 long A5 = SetA5(p->ob_A5);
1406 p->ob_thiscallback = p->ob_completion; /* Hope we cannot get two at the same time */
1407 Py_AddPendingCall(SPB_CallCallBack, (void *)p);
1408 SetA5(A5);
1412 #if !TARGET_API_MAC_CARBON
1413 static pascal void
1414 SPB_interrupt(SPBPtr my_spb)
1416 SPBObject *p = (SPBObject *)(my_spb->userLong);
1418 if (p && p->ob_interrupt) {
1419 long A5 = SetA5(p->ob_A5);
1420 p->ob_thiscallback = p->ob_interrupt; /* Hope we cannot get two at the same time */
1421 Py_AddPendingCall(SPB_CallCallBack, (void *)p);
1422 SetA5(A5);
1425 #endif
1428 void initSnd(void)
1430 PyObject *m;
1431 PyObject *d;
1437 m = Py_InitModule("Snd", Snd_methods);
1438 d = PyModule_GetDict(m);
1439 Snd_Error = PyMac_GetOSErrException();
1440 if (Snd_Error == NULL ||
1441 PyDict_SetItemString(d, "Error", Snd_Error) != 0)
1442 return;
1443 SndChannel_Type.ob_type = &PyType_Type;
1444 Py_INCREF(&SndChannel_Type);
1445 if (PyDict_SetItemString(d, "SndChannelType", (PyObject *)&SndChannel_Type) != 0)
1446 Py_FatalError("can't initialize SndChannelType");
1447 SPB_Type.ob_type = &PyType_Type;
1448 Py_INCREF(&SPB_Type);
1449 if (PyDict_SetItemString(d, "SPBType", (PyObject *)&SPB_Type) != 0)
1450 Py_FatalError("can't initialize SPBType");
1453 /* ========================= End module Snd ========================= */