When the classes in wave.py opened files themselves, their .close() methods
[python/dscho.git] / Mac / Modules / snd / Sndmodule.c
blobdaa0090572bb06299415f3fcf0669e9c0fc7690e
2 /* =========================== Module Snd =========================== */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #include <Sound.h>
13 #include <OSUtils.h> /* for Set(Current)A5 */
15 /* Create a SndCommand object (an (int, int, int) tuple) */
16 static PyObject *
17 SndCmd_New(SndCommand *pc)
19 return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2);
22 /* Convert a SndCommand argument */
23 static int
24 SndCmd_Convert(PyObject *v, SndCommand *pc)
26 int len;
27 pc->param1 = 0;
28 pc->param2 = 0;
29 if (PyTuple_Check(v)) {
30 if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2))
31 return 1;
32 PyErr_Clear();
33 return PyArg_ParseTuple(v, "Hhs#", &pc->cmd, &pc->param1, &pc->param2, &len);
35 return PyArg_Parse(v, "H", &pc->cmd);
38 static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */
39 static pascal void SPB_completion(SPBPtr my_spb); /* Forward */
40 static pascal void SPB_interrupt(SPBPtr my_spb); /* Forward */
42 static PyObject *Snd_Error;
44 /* --------------------- Object type SndChannel --------------------- */
46 staticforward PyTypeObject SndChannel_Type;
48 #define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type)
50 typedef struct SndChannelObject {
51 PyObject_HEAD
52 SndChannelPtr ob_itself;
53 /* Members used to implement callbacks: */
54 PyObject *ob_callback;
55 long ob_A5;
56 SndCommand ob_cmd;
57 } SndChannelObject;
59 static PyObject *SndCh_New(itself)
60 SndChannelPtr itself;
62 SndChannelObject *it;
63 it = PyObject_NEW(SndChannelObject, &SndChannel_Type);
64 if (it == NULL) return NULL;
65 it->ob_itself = itself;
66 it->ob_callback = NULL;
67 it->ob_A5 = SetCurrentA5();
68 return (PyObject *)it;
70 static SndCh_Convert(v, p_itself)
71 PyObject *v;
72 SndChannelPtr *p_itself;
74 if (!SndCh_Check(v))
76 PyErr_SetString(PyExc_TypeError, "SndChannel required");
77 return 0;
79 *p_itself = ((SndChannelObject *)v)->ob_itself;
80 return 1;
83 static void SndCh_dealloc(self)
84 SndChannelObject *self;
86 SndDisposeChannel(self->ob_itself, 1);
87 Py_XDECREF(self->ob_callback);
88 PyMem_DEL(self);
91 static PyObject *SndCh_SndDoCommand(_self, _args)
92 SndChannelObject *_self;
93 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(_self, _args)
113 SndChannelObject *_self;
114 PyObject *_args;
116 PyObject *_res = NULL;
117 OSErr _err;
118 SndCommand cmd;
119 if (!PyArg_ParseTuple(_args, "O&",
120 SndCmd_Convert, &cmd))
121 return NULL;
122 _err = SndDoImmediate(_self->ob_itself,
123 &cmd);
124 if (_err != noErr) return PyMac_Error(_err);
125 Py_INCREF(Py_None);
126 _res = Py_None;
127 return _res;
130 static PyObject *SndCh_SndPlay(_self, _args)
131 SndChannelObject *_self;
132 PyObject *_args;
134 PyObject *_res = NULL;
135 OSErr _err;
136 SndListHandle sndHandle;
137 Boolean async;
138 if (!PyArg_ParseTuple(_args, "O&b",
139 ResObj_Convert, &sndHandle,
140 &async))
141 return NULL;
142 _err = SndPlay(_self->ob_itself,
143 sndHandle,
144 async);
145 if (_err != noErr) return PyMac_Error(_err);
146 Py_INCREF(Py_None);
147 _res = Py_None;
148 return _res;
151 #if !TARGET_API_MAC_CARBON
153 static PyObject *SndCh_SndStartFilePlay(_self, _args)
154 SndChannelObject *_self;
155 PyObject *_args;
157 PyObject *_res = NULL;
158 OSErr _err;
159 short fRefNum;
160 short resNum;
161 long bufferSize;
162 Boolean async;
163 if (!PyArg_ParseTuple(_args, "hhlb",
164 &fRefNum,
165 &resNum,
166 &bufferSize,
167 &async))
168 return NULL;
169 _err = SndStartFilePlay(_self->ob_itself,
170 fRefNum,
171 resNum,
172 bufferSize,
176 async);
177 if (_err != noErr) return PyMac_Error(_err);
178 Py_INCREF(Py_None);
179 _res = Py_None;
180 return _res;
182 #endif
184 #if !TARGET_API_MAC_CARBON
186 static PyObject *SndCh_SndPauseFilePlay(_self, _args)
187 SndChannelObject *_self;
188 PyObject *_args;
190 PyObject *_res = NULL;
191 OSErr _err;
192 if (!PyArg_ParseTuple(_args, ""))
193 return NULL;
194 _err = SndPauseFilePlay(_self->ob_itself);
195 if (_err != noErr) return PyMac_Error(_err);
196 Py_INCREF(Py_None);
197 _res = Py_None;
198 return _res;
200 #endif
202 #if !TARGET_API_MAC_CARBON
204 static PyObject *SndCh_SndStopFilePlay(_self, _args)
205 SndChannelObject *_self;
206 PyObject *_args;
208 PyObject *_res = NULL;
209 OSErr _err;
210 Boolean quietNow;
211 if (!PyArg_ParseTuple(_args, "b",
212 &quietNow))
213 return NULL;
214 _err = SndStopFilePlay(_self->ob_itself,
215 quietNow);
216 if (_err != noErr) return PyMac_Error(_err);
217 Py_INCREF(Py_None);
218 _res = Py_None;
219 return _res;
221 #endif
223 static PyObject *SndCh_SndChannelStatus(_self, _args)
224 SndChannelObject *_self;
225 PyObject *_args;
227 PyObject *_res = NULL;
228 OSErr _err;
229 short theLength;
230 SCStatus theStatus__out__;
231 if (!PyArg_ParseTuple(_args, "h",
232 &theLength))
233 return NULL;
234 _err = SndChannelStatus(_self->ob_itself,
235 theLength,
236 &theStatus__out__);
237 if (_err != noErr) return PyMac_Error(_err);
238 _res = Py_BuildValue("s#",
239 (char *)&theStatus__out__, (int)sizeof(SCStatus));
240 theStatus__error__: ;
241 return _res;
244 static PyObject *SndCh_SndGetInfo(_self, _args)
245 SndChannelObject *_self;
246 PyObject *_args;
248 PyObject *_res = NULL;
249 OSErr _err;
250 OSType selector;
251 void * infoPtr;
252 if (!PyArg_ParseTuple(_args, "O&w",
253 PyMac_GetOSType, &selector,
254 &infoPtr))
255 return NULL;
256 _err = SndGetInfo(_self->ob_itself,
257 selector,
258 infoPtr);
259 if (_err != noErr) return PyMac_Error(_err);
260 Py_INCREF(Py_None);
261 _res = Py_None;
262 return _res;
265 static PyObject *SndCh_SndSetInfo(_self, _args)
266 SndChannelObject *_self;
267 PyObject *_args;
269 PyObject *_res = NULL;
270 OSErr _err;
271 OSType selector;
272 void * infoPtr;
273 if (!PyArg_ParseTuple(_args, "O&w",
274 PyMac_GetOSType, &selector,
275 &infoPtr))
276 return NULL;
277 _err = SndSetInfo(_self->ob_itself,
278 selector,
279 infoPtr);
280 if (_err != noErr) return PyMac_Error(_err);
281 Py_INCREF(Py_None);
282 _res = Py_None;
283 return _res;
286 static PyMethodDef SndCh_methods[] = {
287 {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1,
288 "(SndCommand cmd, Boolean noWait) -> None"},
289 {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1,
290 "(SndCommand cmd) -> None"},
291 {"SndPlay", (PyCFunction)SndCh_SndPlay, 1,
292 "(SndListHandle sndHandle, Boolean async) -> None"},
294 #if !TARGET_API_MAC_CARBON
295 {"SndStartFilePlay", (PyCFunction)SndCh_SndStartFilePlay, 1,
296 "(short fRefNum, short resNum, long bufferSize, Boolean async) -> None"},
297 #endif
299 #if !TARGET_API_MAC_CARBON
300 {"SndPauseFilePlay", (PyCFunction)SndCh_SndPauseFilePlay, 1,
301 "() -> None"},
302 #endif
304 #if !TARGET_API_MAC_CARBON
305 {"SndStopFilePlay", (PyCFunction)SndCh_SndStopFilePlay, 1,
306 "(Boolean quietNow) -> None"},
307 #endif
308 {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1,
309 "(short theLength) -> (SCStatus theStatus)"},
310 {"SndGetInfo", (PyCFunction)SndCh_SndGetInfo, 1,
311 "(OSType selector, void * infoPtr) -> None"},
312 {"SndSetInfo", (PyCFunction)SndCh_SndSetInfo, 1,
313 "(OSType selector, void * infoPtr) -> None"},
314 {NULL, NULL, 0}
317 static PyMethodChain SndCh_chain = { SndCh_methods, NULL };
319 static PyObject *SndCh_getattr(self, name)
320 SndChannelObject *self;
321 char *name;
323 return Py_FindMethodInChain(&SndCh_chain, (PyObject *)self, name);
326 #define SndCh_setattr NULL
328 #define SndCh_compare NULL
330 #define SndCh_repr NULL
332 #define SndCh_hash NULL
334 staticforward PyTypeObject SndChannel_Type = {
335 PyObject_HEAD_INIT(&PyType_Type)
336 0, /*ob_size*/
337 "SndChannel", /*tp_name*/
338 sizeof(SndChannelObject), /*tp_basicsize*/
339 0, /*tp_itemsize*/
340 /* methods */
341 (destructor) SndCh_dealloc, /*tp_dealloc*/
342 0, /*tp_print*/
343 (getattrfunc) SndCh_getattr, /*tp_getattr*/
344 (setattrfunc) SndCh_setattr, /*tp_setattr*/
345 (cmpfunc) SndCh_compare, /*tp_compare*/
346 (reprfunc) SndCh_repr, /*tp_repr*/
347 (PyNumberMethods *)0, /* tp_as_number */
348 (PySequenceMethods *)0, /* tp_as_sequence */
349 (PyMappingMethods *)0, /* tp_as_mapping */
350 (hashfunc) SndCh_hash, /*tp_hash*/
353 /* ------------------- End object type SndChannel ------------------- */
356 /* ------------------------ Object type SPB ------------------------- */
358 staticforward PyTypeObject SPB_Type;
360 #define SPBObj_Check(x) ((x)->ob_type == &SPB_Type)
362 typedef struct SPBObject {
363 PyObject_HEAD
364 /* Members used to implement callbacks: */
365 PyObject *ob_completion;
366 PyObject *ob_interrupt;
367 PyObject *ob_thiscallback;
368 long ob_A5;
369 SPB ob_spb;
370 } SPBObject;
372 static PyObject *SPBObj_New()
374 SPBObject *it;
375 it = PyObject_NEW(SPBObject, &SPB_Type);
376 if (it == NULL) return NULL;
377 it->ob_completion = NULL;
378 it->ob_interrupt = NULL;
379 it->ob_thiscallback = NULL;
380 it->ob_A5 = SetCurrentA5();
381 memset((char *)&it->ob_spb, 0, sizeof(it->ob_spb));
382 it->ob_spb.userLong = (long)it;
383 return (PyObject *)it;
385 static SPBObj_Convert(v, p_itself)
386 PyObject *v;
387 SPBPtr *p_itself;
389 if (!SPBObj_Check(v))
391 PyErr_SetString(PyExc_TypeError, "SPB required");
392 return 0;
394 *p_itself = &((SPBObject *)v)->ob_spb;
395 return 1;
398 static void SPBObj_dealloc(self)
399 SPBObject *self;
401 /* Cleanup of self->ob_itself goes here */
402 self->ob_spb.userLong = 0;
403 self->ob_thiscallback = 0;
404 Py_XDECREF(self->ob_completion);
405 Py_XDECREF(self->ob_interrupt);
406 PyMem_DEL(self);
409 static PyMethodDef SPBObj_methods[] = {
410 {NULL, NULL, 0}
413 static PyMethodChain SPBObj_chain = { SPBObj_methods, NULL };
415 static PyObject *SPBObj_getattr(self, name)
416 SPBObject *self;
417 char *name;
420 if (strcmp(name, "inRefNum") == 0)
421 return Py_BuildValue("l", self->ob_spb.inRefNum);
422 else if (strcmp(name, "count") == 0)
423 return Py_BuildValue("l", self->ob_spb.count);
424 else if (strcmp(name, "milliseconds") == 0)
425 return Py_BuildValue("l", self->ob_spb.milliseconds);
426 else if (strcmp(name, "error") == 0)
427 return Py_BuildValue("h", self->ob_spb.error);
428 return Py_FindMethodInChain(&SPBObj_chain, (PyObject *)self, name);
431 static int SPBObj_setattr(self, name, value)
432 SPBObject *self;
433 char *name;
434 PyObject *value;
437 int rv = 0;
439 if (strcmp(name, "inRefNum") == 0)
440 rv = PyArg_Parse(value, "l", &self->ob_spb.inRefNum);
441 else if (strcmp(name, "count") == 0)
442 rv = PyArg_Parse(value, "l", &self->ob_spb.count);
443 else if (strcmp(name, "milliseconds") == 0)
444 rv = PyArg_Parse(value, "l", &self->ob_spb.milliseconds);
445 else if (strcmp(name, "buffer") == 0)
446 rv = PyArg_Parse(value, "w#", &self->ob_spb.bufferPtr, &self->ob_spb.bufferLength);
447 else if (strcmp(name, "completionRoutine") == 0) {
448 self->ob_spb.completionRoutine = NewSICompletionProc(SPB_completion);
449 self->ob_completion = value;
450 Py_INCREF(value);
451 rv = 1;
452 #if !TARGET_API_MAC_CARBON_NOTYET
453 } else if (strcmp(name, "interruptRoutine") == 0) {
454 self->ob_spb.completionRoutine = NewSIInterruptProc(SPB_interrupt);
455 self->ob_interrupt = value;
456 Py_INCREF(value);
457 rv = 1;
458 #endif
460 if ( rv ) return 0;
461 else return -1;
464 #define SPBObj_compare NULL
466 #define SPBObj_repr NULL
468 #define SPBObj_hash NULL
470 staticforward PyTypeObject SPB_Type = {
471 PyObject_HEAD_INIT(&PyType_Type)
472 0, /*ob_size*/
473 "SPB", /*tp_name*/
474 sizeof(SPBObject), /*tp_basicsize*/
475 0, /*tp_itemsize*/
476 /* methods */
477 (destructor) SPBObj_dealloc, /*tp_dealloc*/
478 0, /*tp_print*/
479 (getattrfunc) SPBObj_getattr, /*tp_getattr*/
480 (setattrfunc) SPBObj_setattr, /*tp_setattr*/
481 (cmpfunc) SPBObj_compare, /*tp_compare*/
482 (reprfunc) SPBObj_repr, /*tp_repr*/
483 (PyNumberMethods *)0, /* tp_as_number */
484 (PySequenceMethods *)0, /* tp_as_sequence */
485 (PyMappingMethods *)0, /* tp_as_mapping */
486 (hashfunc) SPBObj_hash, /*tp_hash*/
489 /* ---------------------- End object type SPB ----------------------- */
492 static PyObject *Snd_SPB(_self, _args)
493 PyObject *_self;
494 PyObject *_args;
496 PyObject *_res = NULL;
497 return SPBObj_New();
500 static PyObject *Snd_SysBeep(_self, _args)
501 PyObject *_self;
502 PyObject *_args;
504 PyObject *_res = NULL;
505 short duration;
506 if (!PyArg_ParseTuple(_args, "h",
507 &duration))
508 return NULL;
509 SysBeep(duration);
510 Py_INCREF(Py_None);
511 _res = Py_None;
512 return _res;
515 static PyObject *Snd_SndNewChannel(_self, _args)
516 PyObject *_self;
517 PyObject *_args;
519 PyObject *_res = NULL;
520 OSErr _err;
521 SndChannelPtr chan = 0;
522 short synth;
523 long init;
524 PyObject* userRoutine;
525 if (!PyArg_ParseTuple(_args, "hlO",
526 &synth,
527 &init,
528 &userRoutine))
529 return NULL;
530 if (userRoutine != Py_None && !PyCallable_Check(userRoutine))
532 PyErr_SetString(PyExc_TypeError, "callback must be callable");
533 goto userRoutine__error__;
535 _err = SndNewChannel(&chan,
536 synth,
537 init,
538 NewSndCallBackProc(SndCh_UserRoutine));
539 if (_err != noErr) return PyMac_Error(_err);
540 _res = Py_BuildValue("O&",
541 SndCh_New, chan);
542 if (_res != NULL && userRoutine != Py_None)
544 SndChannelObject *p = (SndChannelObject *)_res;
545 p->ob_itself->userInfo = (long)p;
546 Py_INCREF(userRoutine);
547 p->ob_callback = userRoutine;
549 userRoutine__error__: ;
550 return _res;
553 #if !TARGET_API_MAC_CARBON
555 static PyObject *Snd_SndControl(_self, _args)
556 PyObject *_self;
557 PyObject *_args;
559 PyObject *_res = NULL;
560 OSErr _err;
561 short id;
562 SndCommand cmd;
563 if (!PyArg_ParseTuple(_args, "h",
564 &id))
565 return NULL;
566 _err = SndControl(id,
567 &cmd);
568 if (_err != noErr) return PyMac_Error(_err);
569 _res = Py_BuildValue("O&",
570 SndCmd_New, &cmd);
571 return _res;
573 #endif
575 static PyObject *Snd_SndSoundManagerVersion(_self, _args)
576 PyObject *_self;
577 PyObject *_args;
579 PyObject *_res = NULL;
580 NumVersion _rv;
581 if (!PyArg_ParseTuple(_args, ""))
582 return NULL;
583 _rv = SndSoundManagerVersion();
584 _res = Py_BuildValue("O&",
585 PyMac_BuildNumVersion, _rv);
586 return _res;
589 static PyObject *Snd_SndManagerStatus(_self, _args)
590 PyObject *_self;
591 PyObject *_args;
593 PyObject *_res = NULL;
594 OSErr _err;
595 short theLength;
596 SMStatus theStatus__out__;
597 if (!PyArg_ParseTuple(_args, "h",
598 &theLength))
599 return NULL;
600 _err = SndManagerStatus(theLength,
601 &theStatus__out__);
602 if (_err != noErr) return PyMac_Error(_err);
603 _res = Py_BuildValue("s#",
604 (char *)&theStatus__out__, (int)sizeof(SMStatus));
605 theStatus__error__: ;
606 return _res;
609 static PyObject *Snd_SndGetSysBeepState(_self, _args)
610 PyObject *_self;
611 PyObject *_args;
613 PyObject *_res = NULL;
614 short sysBeepState;
615 if (!PyArg_ParseTuple(_args, ""))
616 return NULL;
617 SndGetSysBeepState(&sysBeepState);
618 _res = Py_BuildValue("h",
619 sysBeepState);
620 return _res;
623 static PyObject *Snd_SndSetSysBeepState(_self, _args)
624 PyObject *_self;
625 PyObject *_args;
627 PyObject *_res = NULL;
628 OSErr _err;
629 short sysBeepState;
630 if (!PyArg_ParseTuple(_args, "h",
631 &sysBeepState))
632 return NULL;
633 _err = SndSetSysBeepState(sysBeepState);
634 if (_err != noErr) return PyMac_Error(_err);
635 Py_INCREF(Py_None);
636 _res = Py_None;
637 return _res;
640 #if !TARGET_API_MAC_CARBON
642 static PyObject *Snd_MACEVersion(_self, _args)
643 PyObject *_self;
644 PyObject *_args;
646 PyObject *_res = NULL;
647 NumVersion _rv;
648 if (!PyArg_ParseTuple(_args, ""))
649 return NULL;
650 _rv = MACEVersion();
651 _res = Py_BuildValue("O&",
652 PyMac_BuildNumVersion, _rv);
653 return _res;
655 #endif
657 #if !TARGET_API_MAC_CARBON
659 static PyObject *Snd_Comp3to1(_self, _args)
660 PyObject *_self;
661 PyObject *_args;
663 PyObject *_res = NULL;
664 char *buffer__in__;
665 char *buffer__out__;
666 long buffer__len__;
667 int buffer__in_len__;
668 StateBlock *state__in__;
669 StateBlock state__out__;
670 int state__in_len__;
671 unsigned long numChannels;
672 unsigned long whichChannel;
673 if (!PyArg_ParseTuple(_args, "s#s#ll",
674 &buffer__in__, &buffer__in_len__,
675 (char **)&state__in__, &state__in_len__,
676 &numChannels,
677 &whichChannel))
678 return NULL;
679 if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
681 PyErr_NoMemory();
682 goto buffer__error__;
684 buffer__len__ = buffer__in_len__;
685 if (state__in_len__ != sizeof(StateBlock))
687 PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
688 goto state__error__;
690 Comp3to1(buffer__in__, buffer__out__, (long)buffer__len__,
691 state__in__, &state__out__,
692 numChannels,
693 whichChannel);
694 _res = Py_BuildValue("s#s#",
695 buffer__out__, (int)buffer__len__,
696 (char *)&state__out__, (int)sizeof(StateBlock));
697 state__error__: ;
698 free(buffer__out__);
699 buffer__error__: ;
700 return _res;
702 #endif
704 #if !TARGET_API_MAC_CARBON
706 static PyObject *Snd_Exp1to3(_self, _args)
707 PyObject *_self;
708 PyObject *_args;
710 PyObject *_res = NULL;
711 char *buffer__in__;
712 char *buffer__out__;
713 long buffer__len__;
714 int buffer__in_len__;
715 StateBlock *state__in__;
716 StateBlock state__out__;
717 int state__in_len__;
718 unsigned long numChannels;
719 unsigned long whichChannel;
720 if (!PyArg_ParseTuple(_args, "s#s#ll",
721 &buffer__in__, &buffer__in_len__,
722 (char **)&state__in__, &state__in_len__,
723 &numChannels,
724 &whichChannel))
725 return NULL;
726 if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
728 PyErr_NoMemory();
729 goto buffer__error__;
731 buffer__len__ = buffer__in_len__;
732 if (state__in_len__ != sizeof(StateBlock))
734 PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
735 goto state__error__;
737 Exp1to3(buffer__in__, buffer__out__, (long)buffer__len__,
738 state__in__, &state__out__,
739 numChannels,
740 whichChannel);
741 _res = Py_BuildValue("s#s#",
742 buffer__out__, (int)buffer__len__,
743 (char *)&state__out__, (int)sizeof(StateBlock));
744 state__error__: ;
745 free(buffer__out__);
746 buffer__error__: ;
747 return _res;
749 #endif
751 #if !TARGET_API_MAC_CARBON
753 static PyObject *Snd_Comp6to1(_self, _args)
754 PyObject *_self;
755 PyObject *_args;
757 PyObject *_res = NULL;
758 char *buffer__in__;
759 char *buffer__out__;
760 long buffer__len__;
761 int buffer__in_len__;
762 StateBlock *state__in__;
763 StateBlock state__out__;
764 int state__in_len__;
765 unsigned long numChannels;
766 unsigned long whichChannel;
767 if (!PyArg_ParseTuple(_args, "s#s#ll",
768 &buffer__in__, &buffer__in_len__,
769 (char **)&state__in__, &state__in_len__,
770 &numChannels,
771 &whichChannel))
772 return NULL;
773 if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
775 PyErr_NoMemory();
776 goto buffer__error__;
778 buffer__len__ = buffer__in_len__;
779 if (state__in_len__ != sizeof(StateBlock))
781 PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
782 goto state__error__;
784 Comp6to1(buffer__in__, buffer__out__, (long)buffer__len__,
785 state__in__, &state__out__,
786 numChannels,
787 whichChannel);
788 _res = Py_BuildValue("s#s#",
789 buffer__out__, (int)buffer__len__,
790 (char *)&state__out__, (int)sizeof(StateBlock));
791 state__error__: ;
792 free(buffer__out__);
793 buffer__error__: ;
794 return _res;
796 #endif
798 #if !TARGET_API_MAC_CARBON
800 static PyObject *Snd_Exp1to6(_self, _args)
801 PyObject *_self;
802 PyObject *_args;
804 PyObject *_res = NULL;
805 char *buffer__in__;
806 char *buffer__out__;
807 long buffer__len__;
808 int buffer__in_len__;
809 StateBlock *state__in__;
810 StateBlock state__out__;
811 int state__in_len__;
812 unsigned long numChannels;
813 unsigned long whichChannel;
814 if (!PyArg_ParseTuple(_args, "s#s#ll",
815 &buffer__in__, &buffer__in_len__,
816 (char **)&state__in__, &state__in_len__,
817 &numChannels,
818 &whichChannel))
819 return NULL;
820 if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
822 PyErr_NoMemory();
823 goto buffer__error__;
825 buffer__len__ = buffer__in_len__;
826 if (state__in_len__ != sizeof(StateBlock))
828 PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
829 goto state__error__;
831 Exp1to6(buffer__in__, buffer__out__, (long)buffer__len__,
832 state__in__, &state__out__,
833 numChannels,
834 whichChannel);
835 _res = Py_BuildValue("s#s#",
836 buffer__out__, (int)buffer__len__,
837 (char *)&state__out__, (int)sizeof(StateBlock));
838 state__error__: ;
839 free(buffer__out__);
840 buffer__error__: ;
841 return _res;
843 #endif
845 static PyObject *Snd_GetSysBeepVolume(_self, _args)
846 PyObject *_self;
847 PyObject *_args;
849 PyObject *_res = NULL;
850 OSErr _err;
851 long level;
852 if (!PyArg_ParseTuple(_args, ""))
853 return NULL;
854 _err = GetSysBeepVolume(&level);
855 if (_err != noErr) return PyMac_Error(_err);
856 _res = Py_BuildValue("l",
857 level);
858 return _res;
861 static PyObject *Snd_SetSysBeepVolume(_self, _args)
862 PyObject *_self;
863 PyObject *_args;
865 PyObject *_res = NULL;
866 OSErr _err;
867 long level;
868 if (!PyArg_ParseTuple(_args, "l",
869 &level))
870 return NULL;
871 _err = SetSysBeepVolume(level);
872 if (_err != noErr) return PyMac_Error(_err);
873 Py_INCREF(Py_None);
874 _res = Py_None;
875 return _res;
878 static PyObject *Snd_GetDefaultOutputVolume(_self, _args)
879 PyObject *_self;
880 PyObject *_args;
882 PyObject *_res = NULL;
883 OSErr _err;
884 long level;
885 if (!PyArg_ParseTuple(_args, ""))
886 return NULL;
887 _err = GetDefaultOutputVolume(&level);
888 if (_err != noErr) return PyMac_Error(_err);
889 _res = Py_BuildValue("l",
890 level);
891 return _res;
894 static PyObject *Snd_SetDefaultOutputVolume(_self, _args)
895 PyObject *_self;
896 PyObject *_args;
898 PyObject *_res = NULL;
899 OSErr _err;
900 long level;
901 if (!PyArg_ParseTuple(_args, "l",
902 &level))
903 return NULL;
904 _err = SetDefaultOutputVolume(level);
905 if (_err != noErr) return PyMac_Error(_err);
906 Py_INCREF(Py_None);
907 _res = Py_None;
908 return _res;
911 static PyObject *Snd_GetSoundHeaderOffset(_self, _args)
912 PyObject *_self;
913 PyObject *_args;
915 PyObject *_res = NULL;
916 OSErr _err;
917 SndListHandle sndHandle;
918 long offset;
919 if (!PyArg_ParseTuple(_args, "O&",
920 ResObj_Convert, &sndHandle))
921 return NULL;
922 _err = GetSoundHeaderOffset(sndHandle,
923 &offset);
924 if (_err != noErr) return PyMac_Error(_err);
925 _res = Py_BuildValue("l",
926 offset);
927 return _res;
930 static PyObject *Snd_GetCompressionInfo(_self, _args)
931 PyObject *_self;
932 PyObject *_args;
934 PyObject *_res = NULL;
935 OSErr _err;
936 short compressionID;
937 OSType format;
938 short numChannels;
939 short sampleSize;
940 CompressionInfo cp__out__;
941 if (!PyArg_ParseTuple(_args, "hO&hh",
942 &compressionID,
943 PyMac_GetOSType, &format,
944 &numChannels,
945 &sampleSize))
946 return NULL;
947 _err = GetCompressionInfo(compressionID,
948 format,
949 numChannels,
950 sampleSize,
951 &cp__out__);
952 if (_err != noErr) return PyMac_Error(_err);
953 _res = Py_BuildValue("s#",
954 (char *)&cp__out__, (int)sizeof(CompressionInfo));
955 cp__error__: ;
956 return _res;
959 static PyObject *Snd_SetSoundPreference(_self, _args)
960 PyObject *_self;
961 PyObject *_args;
963 PyObject *_res = NULL;
964 OSErr _err;
965 OSType theType;
966 Str255 name;
967 Handle settings;
968 if (!PyArg_ParseTuple(_args, "O&O&",
969 PyMac_GetOSType, &theType,
970 ResObj_Convert, &settings))
971 return NULL;
972 _err = SetSoundPreference(theType,
973 name,
974 settings);
975 if (_err != noErr) return PyMac_Error(_err);
976 _res = Py_BuildValue("O&",
977 PyMac_BuildStr255, name);
978 return _res;
981 static PyObject *Snd_GetSoundPreference(_self, _args)
982 PyObject *_self;
983 PyObject *_args;
985 PyObject *_res = NULL;
986 OSErr _err;
987 OSType theType;
988 Str255 name;
989 Handle settings;
990 if (!PyArg_ParseTuple(_args, "O&O&",
991 PyMac_GetOSType, &theType,
992 ResObj_Convert, &settings))
993 return NULL;
994 _err = GetSoundPreference(theType,
995 name,
996 settings);
997 if (_err != noErr) return PyMac_Error(_err);
998 _res = Py_BuildValue("O&",
999 PyMac_BuildStr255, name);
1000 return _res;
1003 static PyObject *Snd_GetCompressionName(_self, _args)
1004 PyObject *_self;
1005 PyObject *_args;
1007 PyObject *_res = NULL;
1008 OSErr _err;
1009 OSType compressionType;
1010 Str255 compressionName;
1011 if (!PyArg_ParseTuple(_args, "O&",
1012 PyMac_GetOSType, &compressionType))
1013 return NULL;
1014 _err = GetCompressionName(compressionType,
1015 compressionName);
1016 if (_err != noErr) return PyMac_Error(_err);
1017 _res = Py_BuildValue("O&",
1018 PyMac_BuildStr255, compressionName);
1019 return _res;
1022 static PyObject *Snd_SPBVersion(_self, _args)
1023 PyObject *_self;
1024 PyObject *_args;
1026 PyObject *_res = NULL;
1027 NumVersion _rv;
1028 if (!PyArg_ParseTuple(_args, ""))
1029 return NULL;
1030 _rv = SPBVersion();
1031 _res = Py_BuildValue("O&",
1032 PyMac_BuildNumVersion, _rv);
1033 return _res;
1036 static PyObject *Snd_SPBSignInDevice(_self, _args)
1037 PyObject *_self;
1038 PyObject *_args;
1040 PyObject *_res = NULL;
1041 OSErr _err;
1042 short deviceRefNum;
1043 Str255 deviceName;
1044 if (!PyArg_ParseTuple(_args, "hO&",
1045 &deviceRefNum,
1046 PyMac_GetStr255, deviceName))
1047 return NULL;
1048 _err = SPBSignInDevice(deviceRefNum,
1049 deviceName);
1050 if (_err != noErr) return PyMac_Error(_err);
1051 Py_INCREF(Py_None);
1052 _res = Py_None;
1053 return _res;
1056 static PyObject *Snd_SPBSignOutDevice(_self, _args)
1057 PyObject *_self;
1058 PyObject *_args;
1060 PyObject *_res = NULL;
1061 OSErr _err;
1062 short deviceRefNum;
1063 if (!PyArg_ParseTuple(_args, "h",
1064 &deviceRefNum))
1065 return NULL;
1066 _err = SPBSignOutDevice(deviceRefNum);
1067 if (_err != noErr) return PyMac_Error(_err);
1068 Py_INCREF(Py_None);
1069 _res = Py_None;
1070 return _res;
1073 static PyObject *Snd_SPBGetIndexedDevice(_self, _args)
1074 PyObject *_self;
1075 PyObject *_args;
1077 PyObject *_res = NULL;
1078 OSErr _err;
1079 short count;
1080 Str255 deviceName;
1081 Handle deviceIconHandle;
1082 if (!PyArg_ParseTuple(_args, "h",
1083 &count))
1084 return NULL;
1085 _err = SPBGetIndexedDevice(count,
1086 deviceName,
1087 &deviceIconHandle);
1088 if (_err != noErr) return PyMac_Error(_err);
1089 _res = Py_BuildValue("O&O&",
1090 PyMac_BuildStr255, deviceName,
1091 ResObj_New, deviceIconHandle);
1092 return _res;
1095 static PyObject *Snd_SPBOpenDevice(_self, _args)
1096 PyObject *_self;
1097 PyObject *_args;
1099 PyObject *_res = NULL;
1100 OSErr _err;
1101 Str255 deviceName;
1102 short permission;
1103 long inRefNum;
1104 if (!PyArg_ParseTuple(_args, "O&h",
1105 PyMac_GetStr255, deviceName,
1106 &permission))
1107 return NULL;
1108 _err = SPBOpenDevice(deviceName,
1109 permission,
1110 &inRefNum);
1111 if (_err != noErr) return PyMac_Error(_err);
1112 _res = Py_BuildValue("l",
1113 inRefNum);
1114 return _res;
1117 static PyObject *Snd_SPBCloseDevice(_self, _args)
1118 PyObject *_self;
1119 PyObject *_args;
1121 PyObject *_res = NULL;
1122 OSErr _err;
1123 long inRefNum;
1124 if (!PyArg_ParseTuple(_args, "l",
1125 &inRefNum))
1126 return NULL;
1127 _err = SPBCloseDevice(inRefNum);
1128 if (_err != noErr) return PyMac_Error(_err);
1129 Py_INCREF(Py_None);
1130 _res = Py_None;
1131 return _res;
1134 static PyObject *Snd_SPBRecord(_self, _args)
1135 PyObject *_self;
1136 PyObject *_args;
1138 PyObject *_res = NULL;
1139 OSErr _err;
1140 SPBPtr inParamPtr;
1141 Boolean asynchFlag;
1142 if (!PyArg_ParseTuple(_args, "O&b",
1143 SPBObj_Convert, &inParamPtr,
1144 &asynchFlag))
1145 return NULL;
1146 _err = SPBRecord(inParamPtr,
1147 asynchFlag);
1148 if (_err != noErr) return PyMac_Error(_err);
1149 Py_INCREF(Py_None);
1150 _res = Py_None;
1151 return _res;
1154 #if !TARGET_API_MAC_CARBON
1156 static PyObject *Snd_SPBRecordToFile(_self, _args)
1157 PyObject *_self;
1158 PyObject *_args;
1160 PyObject *_res = NULL;
1161 OSErr _err;
1162 short fRefNum;
1163 SPBPtr inParamPtr;
1164 Boolean asynchFlag;
1165 if (!PyArg_ParseTuple(_args, "hO&b",
1166 &fRefNum,
1167 SPBObj_Convert, &inParamPtr,
1168 &asynchFlag))
1169 return NULL;
1170 _err = SPBRecordToFile(fRefNum,
1171 inParamPtr,
1172 asynchFlag);
1173 if (_err != noErr) return PyMac_Error(_err);
1174 Py_INCREF(Py_None);
1175 _res = Py_None;
1176 return _res;
1178 #endif
1180 static PyObject *Snd_SPBPauseRecording(_self, _args)
1181 PyObject *_self;
1182 PyObject *_args;
1184 PyObject *_res = NULL;
1185 OSErr _err;
1186 long inRefNum;
1187 if (!PyArg_ParseTuple(_args, "l",
1188 &inRefNum))
1189 return NULL;
1190 _err = SPBPauseRecording(inRefNum);
1191 if (_err != noErr) return PyMac_Error(_err);
1192 Py_INCREF(Py_None);
1193 _res = Py_None;
1194 return _res;
1197 static PyObject *Snd_SPBResumeRecording(_self, _args)
1198 PyObject *_self;
1199 PyObject *_args;
1201 PyObject *_res = NULL;
1202 OSErr _err;
1203 long inRefNum;
1204 if (!PyArg_ParseTuple(_args, "l",
1205 &inRefNum))
1206 return NULL;
1207 _err = SPBResumeRecording(inRefNum);
1208 if (_err != noErr) return PyMac_Error(_err);
1209 Py_INCREF(Py_None);
1210 _res = Py_None;
1211 return _res;
1214 static PyObject *Snd_SPBStopRecording(_self, _args)
1215 PyObject *_self;
1216 PyObject *_args;
1218 PyObject *_res = NULL;
1219 OSErr _err;
1220 long inRefNum;
1221 if (!PyArg_ParseTuple(_args, "l",
1222 &inRefNum))
1223 return NULL;
1224 _err = SPBStopRecording(inRefNum);
1225 if (_err != noErr) return PyMac_Error(_err);
1226 Py_INCREF(Py_None);
1227 _res = Py_None;
1228 return _res;
1231 static PyObject *Snd_SPBGetRecordingStatus(_self, _args)
1232 PyObject *_self;
1233 PyObject *_args;
1235 PyObject *_res = NULL;
1236 OSErr _err;
1237 long inRefNum;
1238 short recordingStatus;
1239 short meterLevel;
1240 unsigned long totalSamplesToRecord;
1241 unsigned long numberOfSamplesRecorded;
1242 unsigned long totalMsecsToRecord;
1243 unsigned long numberOfMsecsRecorded;
1244 if (!PyArg_ParseTuple(_args, "l",
1245 &inRefNum))
1246 return NULL;
1247 _err = SPBGetRecordingStatus(inRefNum,
1248 &recordingStatus,
1249 &meterLevel,
1250 &totalSamplesToRecord,
1251 &numberOfSamplesRecorded,
1252 &totalMsecsToRecord,
1253 &numberOfMsecsRecorded);
1254 if (_err != noErr) return PyMac_Error(_err);
1255 _res = Py_BuildValue("hhllll",
1256 recordingStatus,
1257 meterLevel,
1258 totalSamplesToRecord,
1259 numberOfSamplesRecorded,
1260 totalMsecsToRecord,
1261 numberOfMsecsRecorded);
1262 return _res;
1265 static PyObject *Snd_SPBGetDeviceInfo(_self, _args)
1266 PyObject *_self;
1267 PyObject *_args;
1269 PyObject *_res = NULL;
1270 OSErr _err;
1271 long inRefNum;
1272 OSType infoType;
1273 void * infoData;
1274 if (!PyArg_ParseTuple(_args, "lO&w",
1275 &inRefNum,
1276 PyMac_GetOSType, &infoType,
1277 &infoData))
1278 return NULL;
1279 _err = SPBGetDeviceInfo(inRefNum,
1280 infoType,
1281 infoData);
1282 if (_err != noErr) return PyMac_Error(_err);
1283 Py_INCREF(Py_None);
1284 _res = Py_None;
1285 return _res;
1288 static PyObject *Snd_SPBSetDeviceInfo(_self, _args)
1289 PyObject *_self;
1290 PyObject *_args;
1292 PyObject *_res = NULL;
1293 OSErr _err;
1294 long inRefNum;
1295 OSType infoType;
1296 void * infoData;
1297 if (!PyArg_ParseTuple(_args, "lO&w",
1298 &inRefNum,
1299 PyMac_GetOSType, &infoType,
1300 &infoData))
1301 return NULL;
1302 _err = SPBSetDeviceInfo(inRefNum,
1303 infoType,
1304 infoData);
1305 if (_err != noErr) return PyMac_Error(_err);
1306 Py_INCREF(Py_None);
1307 _res = Py_None;
1308 return _res;
1311 static PyObject *Snd_SPBMillisecondsToBytes(_self, _args)
1312 PyObject *_self;
1313 PyObject *_args;
1315 PyObject *_res = NULL;
1316 OSErr _err;
1317 long inRefNum;
1318 long milliseconds;
1319 if (!PyArg_ParseTuple(_args, "l",
1320 &inRefNum))
1321 return NULL;
1322 _err = SPBMillisecondsToBytes(inRefNum,
1323 &milliseconds);
1324 if (_err != noErr) return PyMac_Error(_err);
1325 _res = Py_BuildValue("l",
1326 milliseconds);
1327 return _res;
1330 static PyObject *Snd_SPBBytesToMilliseconds(_self, _args)
1331 PyObject *_self;
1332 PyObject *_args;
1334 PyObject *_res = NULL;
1335 OSErr _err;
1336 long inRefNum;
1337 long byteCount;
1338 if (!PyArg_ParseTuple(_args, "l",
1339 &inRefNum))
1340 return NULL;
1341 _err = SPBBytesToMilliseconds(inRefNum,
1342 &byteCount);
1343 if (_err != noErr) return PyMac_Error(_err);
1344 _res = Py_BuildValue("l",
1345 byteCount);
1346 return _res;
1349 static PyMethodDef Snd_methods[] = {
1350 {"SPB", (PyCFunction)Snd_SPB, 1,
1351 NULL},
1352 {"SysBeep", (PyCFunction)Snd_SysBeep, 1,
1353 "(short duration) -> None"},
1354 {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1,
1355 "(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)"},
1357 #if !TARGET_API_MAC_CARBON
1358 {"SndControl", (PyCFunction)Snd_SndControl, 1,
1359 "(short id) -> (SndCommand cmd)"},
1360 #endif
1361 {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1,
1362 "() -> (NumVersion _rv)"},
1363 {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1,
1364 "(short theLength) -> (SMStatus theStatus)"},
1365 {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1,
1366 "() -> (short sysBeepState)"},
1367 {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1,
1368 "(short sysBeepState) -> None"},
1370 #if !TARGET_API_MAC_CARBON
1371 {"MACEVersion", (PyCFunction)Snd_MACEVersion, 1,
1372 "() -> (NumVersion _rv)"},
1373 #endif
1375 #if !TARGET_API_MAC_CARBON
1376 {"Comp3to1", (PyCFunction)Snd_Comp3to1, 1,
1377 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1378 #endif
1380 #if !TARGET_API_MAC_CARBON
1381 {"Exp1to3", (PyCFunction)Snd_Exp1to3, 1,
1382 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1383 #endif
1385 #if !TARGET_API_MAC_CARBON
1386 {"Comp6to1", (PyCFunction)Snd_Comp6to1, 1,
1387 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1388 #endif
1390 #if !TARGET_API_MAC_CARBON
1391 {"Exp1to6", (PyCFunction)Snd_Exp1to6, 1,
1392 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1393 #endif
1394 {"GetSysBeepVolume", (PyCFunction)Snd_GetSysBeepVolume, 1,
1395 "() -> (long level)"},
1396 {"SetSysBeepVolume", (PyCFunction)Snd_SetSysBeepVolume, 1,
1397 "(long level) -> None"},
1398 {"GetDefaultOutputVolume", (PyCFunction)Snd_GetDefaultOutputVolume, 1,
1399 "() -> (long level)"},
1400 {"SetDefaultOutputVolume", (PyCFunction)Snd_SetDefaultOutputVolume, 1,
1401 "(long level) -> None"},
1402 {"GetSoundHeaderOffset", (PyCFunction)Snd_GetSoundHeaderOffset, 1,
1403 "(SndListHandle sndHandle) -> (long offset)"},
1404 {"GetCompressionInfo", (PyCFunction)Snd_GetCompressionInfo, 1,
1405 "(short compressionID, OSType format, short numChannels, short sampleSize) -> (CompressionInfo cp)"},
1406 {"SetSoundPreference", (PyCFunction)Snd_SetSoundPreference, 1,
1407 "(OSType theType, Handle settings) -> (Str255 name)"},
1408 {"GetSoundPreference", (PyCFunction)Snd_GetSoundPreference, 1,
1409 "(OSType theType, Handle settings) -> (Str255 name)"},
1410 {"GetCompressionName", (PyCFunction)Snd_GetCompressionName, 1,
1411 "(OSType compressionType) -> (Str255 compressionName)"},
1412 {"SPBVersion", (PyCFunction)Snd_SPBVersion, 1,
1413 "() -> (NumVersion _rv)"},
1414 {"SPBSignInDevice", (PyCFunction)Snd_SPBSignInDevice, 1,
1415 "(short deviceRefNum, Str255 deviceName) -> None"},
1416 {"SPBSignOutDevice", (PyCFunction)Snd_SPBSignOutDevice, 1,
1417 "(short deviceRefNum) -> None"},
1418 {"SPBGetIndexedDevice", (PyCFunction)Snd_SPBGetIndexedDevice, 1,
1419 "(short count) -> (Str255 deviceName, Handle deviceIconHandle)"},
1420 {"SPBOpenDevice", (PyCFunction)Snd_SPBOpenDevice, 1,
1421 "(Str255 deviceName, short permission) -> (long inRefNum)"},
1422 {"SPBCloseDevice", (PyCFunction)Snd_SPBCloseDevice, 1,
1423 "(long inRefNum) -> None"},
1424 {"SPBRecord", (PyCFunction)Snd_SPBRecord, 1,
1425 "(SPBPtr inParamPtr, Boolean asynchFlag) -> None"},
1427 #if !TARGET_API_MAC_CARBON
1428 {"SPBRecordToFile", (PyCFunction)Snd_SPBRecordToFile, 1,
1429 "(short fRefNum, SPBPtr inParamPtr, Boolean asynchFlag) -> None"},
1430 #endif
1431 {"SPBPauseRecording", (PyCFunction)Snd_SPBPauseRecording, 1,
1432 "(long inRefNum) -> None"},
1433 {"SPBResumeRecording", (PyCFunction)Snd_SPBResumeRecording, 1,
1434 "(long inRefNum) -> None"},
1435 {"SPBStopRecording", (PyCFunction)Snd_SPBStopRecording, 1,
1436 "(long inRefNum) -> None"},
1437 {"SPBGetRecordingStatus", (PyCFunction)Snd_SPBGetRecordingStatus, 1,
1438 "(long inRefNum) -> (short recordingStatus, short meterLevel, unsigned long totalSamplesToRecord, unsigned long numberOfSamplesRecorded, unsigned long totalMsecsToRecord, unsigned long numberOfMsecsRecorded)"},
1439 {"SPBGetDeviceInfo", (PyCFunction)Snd_SPBGetDeviceInfo, 1,
1440 "(long inRefNum, OSType infoType, void * infoData) -> None"},
1441 {"SPBSetDeviceInfo", (PyCFunction)Snd_SPBSetDeviceInfo, 1,
1442 "(long inRefNum, OSType infoType, void * infoData) -> None"},
1443 {"SPBMillisecondsToBytes", (PyCFunction)Snd_SPBMillisecondsToBytes, 1,
1444 "(long inRefNum) -> (long milliseconds)"},
1445 {"SPBBytesToMilliseconds", (PyCFunction)Snd_SPBBytesToMilliseconds, 1,
1446 "(long inRefNum) -> (long byteCount)"},
1447 {NULL, NULL, 0}
1452 /* Routine passed to Py_AddPendingCall -- call the Python callback */
1453 static int
1454 SndCh_CallCallBack(arg)
1455 void *arg;
1457 SndChannelObject *p = (SndChannelObject *)arg;
1458 PyObject *args;
1459 PyObject *res;
1460 args = Py_BuildValue("(O(hhl))",
1461 p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2);
1462 res = PyEval_CallObject(p->ob_callback, args);
1463 Py_DECREF(args);
1464 if (res == NULL)
1465 return -1;
1466 Py_DECREF(res);
1467 return 0;
1470 /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */
1471 static pascal void
1472 SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd)
1474 SndChannelObject *p = (SndChannelObject *)(chan->userInfo);
1475 if (p->ob_callback != NULL) {
1476 long A5 = SetA5(p->ob_A5);
1477 p->ob_cmd = *cmd;
1478 Py_AddPendingCall(SndCh_CallCallBack, (void *)p);
1479 SetA5(A5);
1483 /* SPB callbacks - Schedule callbacks to Python */
1484 static int
1485 SPB_CallCallBack(arg)
1486 void *arg;
1488 SPBObject *p = (SPBObject *)arg;
1489 PyObject *args;
1490 PyObject *res;
1492 if ( p->ob_thiscallback == 0 ) return 0;
1493 args = Py_BuildValue("(O)", p);
1494 res = PyEval_CallObject(p->ob_thiscallback, args);
1495 p->ob_thiscallback = 0;
1496 Py_DECREF(args);
1497 if (res == NULL)
1498 return -1;
1499 Py_DECREF(res);
1500 return 0;
1503 static pascal void
1504 SPB_completion(SPBPtr my_spb)
1506 SPBObject *p = (SPBObject *)(my_spb->userLong);
1508 if (p && p->ob_completion) {
1509 long A5 = SetA5(p->ob_A5);
1510 p->ob_thiscallback = p->ob_completion; /* Hope we cannot get two at the same time */
1511 Py_AddPendingCall(SPB_CallCallBack, (void *)p);
1512 SetA5(A5);
1516 static pascal void
1517 SPB_interrupt(SPBPtr my_spb)
1519 SPBObject *p = (SPBObject *)(my_spb->userLong);
1521 if (p && p->ob_interrupt) {
1522 long A5 = SetA5(p->ob_A5);
1523 p->ob_thiscallback = p->ob_interrupt; /* Hope we cannot get two at the same time */
1524 Py_AddPendingCall(SPB_CallCallBack, (void *)p);
1525 SetA5(A5);
1530 void initSnd()
1532 PyObject *m;
1533 PyObject *d;
1539 m = Py_InitModule("Snd", Snd_methods);
1540 d = PyModule_GetDict(m);
1541 Snd_Error = PyMac_GetOSErrException();
1542 if (Snd_Error == NULL ||
1543 PyDict_SetItemString(d, "Error", Snd_Error) != 0)
1544 Py_FatalError("can't initialize Snd.Error");
1545 SndChannel_Type.ob_type = &PyType_Type;
1546 Py_INCREF(&SndChannel_Type);
1547 if (PyDict_SetItemString(d, "SndChannelType", (PyObject *)&SndChannel_Type) != 0)
1548 Py_FatalError("can't initialize SndChannelType");
1549 SPB_Type.ob_type = &PyType_Type;
1550 Py_INCREF(&SPB_Type);
1551 if (PyDict_SetItemString(d, "SPBType", (PyObject *)&SPB_Type) != 0)
1552 Py_FatalError("can't initialize SPBType");
1555 /* ========================= End module Snd ========================= */