The 0.5 release happened on 2/15, not on 2/14. :-)
[python/dscho.git] / Mac / Modules / snd / Sndmodule.c
blob019fa256d1510bc1eb53ad4d114c2b576439744a
2 /* =========================== Module Snd =========================== */
4 #include "Python.h"
8 #define SystemSevenOrLater 1
10 #include "macglue.h"
11 #include <Memory.h>
12 #include <Dialogs.h>
13 #include <Menus.h>
14 #include <Controls.h>
16 extern PyObject *ResObj_New(Handle);
17 extern int ResObj_Convert(PyObject *, Handle *);
18 extern PyObject *OptResObj_New(Handle);
19 extern int OptResObj_Convert(PyObject *, Handle *);
21 extern PyObject *WinObj_New(WindowPtr);
22 extern int WinObj_Convert(PyObject *, WindowPtr *);
23 extern PyTypeObject Window_Type;
24 #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
26 extern PyObject *DlgObj_New(DialogPtr);
27 extern int DlgObj_Convert(PyObject *, DialogPtr *);
28 extern PyTypeObject Dialog_Type;
29 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
31 extern PyObject *MenuObj_New(MenuHandle);
32 extern int MenuObj_Convert(PyObject *, MenuHandle *);
34 extern PyObject *CtlObj_New(ControlHandle);
35 extern int CtlObj_Convert(PyObject *, ControlHandle *);
37 extern PyObject *GrafObj_New(GrafPtr);
38 extern int GrafObj_Convert(PyObject *, GrafPtr *);
40 extern PyObject *BMObj_New(BitMapPtr);
41 extern int BMObj_Convert(PyObject *, BitMapPtr *);
43 extern PyObject *WinObj_WhichWindow(WindowPtr);
45 #include <Sound.h>
47 #ifndef HAVE_UNIVERSAL_HEADERS
48 #define SndCallBackUPP ProcPtr
49 #define NewSndCallBackProc(x) ((SndCallBackProcPtr)(x))
50 #define SndListHandle Handle
51 #endif
53 #include <OSUtils.h> /* for Set(Current)A5 */
55 /* Create a SndCommand object (an (int, int, int) tuple) */
56 static PyObject *
57 SndCmd_New(SndCommand *pc)
59 return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2);
62 /* Convert a SndCommand argument */
63 static int
64 SndCmd_Convert(PyObject *v, SndCommand *pc)
66 int len;
67 pc->param1 = 0;
68 pc->param2 = 0;
69 if (PyTuple_Check(v)) {
70 if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2))
71 return 1;
72 PyErr_Clear();
73 return PyArg_ParseTuple(v, "hhs#", &pc->cmd, &pc->param1, &pc->param2, &len);
75 return PyArg_Parse(v, "h", &pc->cmd);
78 static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */
79 static pascal void SPB_completion(SPBPtr my_spb); /* Forward */
80 static pascal void SPB_interrupt(SPBPtr my_spb); /* Forward */
82 static PyObject *Snd_Error;
84 /* --------------------- Object type SndChannel --------------------- */
86 staticforward PyTypeObject SndChannel_Type;
88 #define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type)
90 typedef struct SndChannelObject {
91 PyObject_HEAD
92 SndChannelPtr ob_itself;
93 /* Members used to implement callbacks: */
94 PyObject *ob_callback;
95 long ob_A5;
96 SndCommand ob_cmd;
97 } SndChannelObject;
99 static PyObject *SndCh_New(itself)
100 SndChannelPtr itself;
102 SndChannelObject *it;
103 it = PyObject_NEW(SndChannelObject, &SndChannel_Type);
104 if (it == NULL) return NULL;
105 it->ob_itself = itself;
106 it->ob_callback = NULL;
107 it->ob_A5 = SetCurrentA5();
108 return (PyObject *)it;
110 static SndCh_Convert(v, p_itself)
111 PyObject *v;
112 SndChannelPtr *p_itself;
114 if (!SndCh_Check(v))
116 PyErr_SetString(PyExc_TypeError, "SndChannel required");
117 return 0;
119 *p_itself = ((SndChannelObject *)v)->ob_itself;
120 return 1;
123 static void SndCh_dealloc(self)
124 SndChannelObject *self;
126 SndDisposeChannel(self->ob_itself, 1);
127 Py_XDECREF(self->ob_callback);
128 PyMem_DEL(self);
131 static PyObject *SndCh_SndDoCommand(_self, _args)
132 SndChannelObject *_self;
133 PyObject *_args;
135 PyObject *_res = NULL;
136 OSErr _err;
137 SndCommand cmd;
138 Boolean noWait;
139 if (!PyArg_ParseTuple(_args, "O&b",
140 SndCmd_Convert, &cmd,
141 &noWait))
142 return NULL;
143 _err = SndDoCommand(_self->ob_itself,
144 &cmd,
145 noWait);
146 if (_err != noErr) return PyMac_Error(_err);
147 Py_INCREF(Py_None);
148 _res = Py_None;
149 return _res;
152 static PyObject *SndCh_SndDoImmediate(_self, _args)
153 SndChannelObject *_self;
154 PyObject *_args;
156 PyObject *_res = NULL;
157 OSErr _err;
158 SndCommand cmd;
159 if (!PyArg_ParseTuple(_args, "O&",
160 SndCmd_Convert, &cmd))
161 return NULL;
162 _err = SndDoImmediate(_self->ob_itself,
163 &cmd);
164 if (_err != noErr) return PyMac_Error(_err);
165 Py_INCREF(Py_None);
166 _res = Py_None;
167 return _res;
170 static PyObject *SndCh_SndPlay(_self, _args)
171 SndChannelObject *_self;
172 PyObject *_args;
174 PyObject *_res = NULL;
175 OSErr _err;
176 SndListHandle sndHandle;
177 Boolean async;
178 if (!PyArg_ParseTuple(_args, "O&b",
179 ResObj_Convert, &sndHandle,
180 &async))
181 return NULL;
182 _err = SndPlay(_self->ob_itself,
183 sndHandle,
184 async);
185 if (_err != noErr) return PyMac_Error(_err);
186 Py_INCREF(Py_None);
187 _res = Py_None;
188 return _res;
191 static PyObject *SndCh_SndStartFilePlay(_self, _args)
192 SndChannelObject *_self;
193 PyObject *_args;
195 PyObject *_res = NULL;
196 OSErr _err;
197 short fRefNum;
198 short resNum;
199 long bufferSize;
200 Boolean async;
201 if (!PyArg_ParseTuple(_args, "hhlb",
202 &fRefNum,
203 &resNum,
204 &bufferSize,
205 &async))
206 return NULL;
207 _err = SndStartFilePlay(_self->ob_itself,
208 fRefNum,
209 resNum,
210 bufferSize,
214 async);
215 if (_err != noErr) return PyMac_Error(_err);
216 Py_INCREF(Py_None);
217 _res = Py_None;
218 return _res;
221 static PyObject *SndCh_SndPauseFilePlay(_self, _args)
222 SndChannelObject *_self;
223 PyObject *_args;
225 PyObject *_res = NULL;
226 OSErr _err;
227 if (!PyArg_ParseTuple(_args, ""))
228 return NULL;
229 _err = SndPauseFilePlay(_self->ob_itself);
230 if (_err != noErr) return PyMac_Error(_err);
231 Py_INCREF(Py_None);
232 _res = Py_None;
233 return _res;
236 static PyObject *SndCh_SndStopFilePlay(_self, _args)
237 SndChannelObject *_self;
238 PyObject *_args;
240 PyObject *_res = NULL;
241 OSErr _err;
242 Boolean quietNow;
243 if (!PyArg_ParseTuple(_args, "b",
244 &quietNow))
245 return NULL;
246 _err = SndStopFilePlay(_self->ob_itself,
247 quietNow);
248 if (_err != noErr) return PyMac_Error(_err);
249 Py_INCREF(Py_None);
250 _res = Py_None;
251 return _res;
254 static PyObject *SndCh_SndChannelStatus(_self, _args)
255 SndChannelObject *_self;
256 PyObject *_args;
258 PyObject *_res = NULL;
259 OSErr _err;
260 short theLength;
261 SCStatus theStatus__out__;
262 if (!PyArg_ParseTuple(_args, "h",
263 &theLength))
264 return NULL;
265 _err = SndChannelStatus(_self->ob_itself,
266 theLength,
267 &theStatus__out__);
268 if (_err != noErr) return PyMac_Error(_err);
269 _res = Py_BuildValue("s#",
270 (char *)&theStatus__out__, (int)sizeof(SCStatus));
271 theStatus__error__: ;
272 return _res;
275 static PyObject *SndCh_SndGetInfo(_self, _args)
276 SndChannelObject *_self;
277 PyObject *_args;
279 PyObject *_res = NULL;
280 OSErr _err;
281 OSType selector;
282 void * infoPtr;
283 if (!PyArg_ParseTuple(_args, "O&w",
284 PyMac_GetOSType, &selector,
285 &infoPtr))
286 return NULL;
287 _err = SndGetInfo(_self->ob_itself,
288 selector,
289 infoPtr);
290 if (_err != noErr) return PyMac_Error(_err);
291 Py_INCREF(Py_None);
292 _res = Py_None;
293 return _res;
296 static PyObject *SndCh_SndSetInfo(_self, _args)
297 SndChannelObject *_self;
298 PyObject *_args;
300 PyObject *_res = NULL;
301 OSErr _err;
302 OSType selector;
303 void * infoPtr;
304 if (!PyArg_ParseTuple(_args, "O&w",
305 PyMac_GetOSType, &selector,
306 &infoPtr))
307 return NULL;
308 _err = SndSetInfo(_self->ob_itself,
309 selector,
310 infoPtr);
311 if (_err != noErr) return PyMac_Error(_err);
312 Py_INCREF(Py_None);
313 _res = Py_None;
314 return _res;
317 static PyMethodDef SndCh_methods[] = {
318 {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1,
319 "(SndCommand cmd, Boolean noWait) -> None"},
320 {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1,
321 "(SndCommand cmd) -> None"},
322 {"SndPlay", (PyCFunction)SndCh_SndPlay, 1,
323 "(SndListHandle sndHandle, Boolean async) -> None"},
324 {"SndStartFilePlay", (PyCFunction)SndCh_SndStartFilePlay, 1,
325 "(short fRefNum, short resNum, long bufferSize, Boolean async) -> None"},
326 {"SndPauseFilePlay", (PyCFunction)SndCh_SndPauseFilePlay, 1,
327 "() -> None"},
328 {"SndStopFilePlay", (PyCFunction)SndCh_SndStopFilePlay, 1,
329 "(Boolean quietNow) -> None"},
330 {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1,
331 "(short theLength) -> (SCStatus theStatus)"},
332 {"SndGetInfo", (PyCFunction)SndCh_SndGetInfo, 1,
333 "(OSType selector, void * infoPtr) -> None"},
334 {"SndSetInfo", (PyCFunction)SndCh_SndSetInfo, 1,
335 "(OSType selector, void * infoPtr) -> None"},
336 {NULL, NULL, 0}
339 static PyMethodChain SndCh_chain = { SndCh_methods, NULL };
341 static PyObject *SndCh_getattr(self, name)
342 SndChannelObject *self;
343 char *name;
345 return Py_FindMethodInChain(&SndCh_chain, (PyObject *)self, name);
348 #define SndCh_setattr NULL
350 #define SndCh_compare NULL
352 #define SndCh_repr NULL
354 #define SndCh_hash NULL
356 staticforward PyTypeObject SndChannel_Type = {
357 PyObject_HEAD_INIT(&PyType_Type)
358 0, /*ob_size*/
359 "SndChannel", /*tp_name*/
360 sizeof(SndChannelObject), /*tp_basicsize*/
361 0, /*tp_itemsize*/
362 /* methods */
363 (destructor) SndCh_dealloc, /*tp_dealloc*/
364 0, /*tp_print*/
365 (getattrfunc) SndCh_getattr, /*tp_getattr*/
366 (setattrfunc) SndCh_setattr, /*tp_setattr*/
367 (cmpfunc) SndCh_compare, /*tp_compare*/
368 (reprfunc) SndCh_repr, /*tp_repr*/
369 (PyNumberMethods *)0, /* tp_as_number */
370 (PySequenceMethods *)0, /* tp_as_sequence */
371 (PyMappingMethods *)0, /* tp_as_mapping */
372 (hashfunc) SndCh_hash, /*tp_hash*/
375 /* ------------------- End object type SndChannel ------------------- */
378 /* ------------------------ Object type SPB ------------------------- */
380 staticforward PyTypeObject SPB_Type;
382 #define SPBObj_Check(x) ((x)->ob_type == &SPB_Type)
384 typedef struct SPBObject {
385 PyObject_HEAD
386 /* Members used to implement callbacks: */
387 PyObject *ob_completion;
388 PyObject *ob_interrupt;
389 PyObject *ob_thiscallback;
390 long ob_A5;
391 SPB ob_spb;
392 } SPBObject;
394 static PyObject *SPBObj_New()
396 SPBObject *it;
397 it = PyObject_NEW(SPBObject, &SPB_Type);
398 if (it == NULL) return NULL;
399 it->ob_completion = NULL;
400 it->ob_interrupt = NULL;
401 it->ob_thiscallback = NULL;
402 it->ob_A5 = SetCurrentA5();
403 memset((char *)&it->ob_spb, 0, sizeof(it->ob_spb));
404 it->ob_spb.userLong = (long)it;
405 return (PyObject *)it;
407 static SPBObj_Convert(v, p_itself)
408 PyObject *v;
409 SPBPtr *p_itself;
411 if (!SPBObj_Check(v))
413 PyErr_SetString(PyExc_TypeError, "SPB required");
414 return 0;
416 *p_itself = &((SPBObject *)v)->ob_spb;
417 return 1;
420 static void SPBObj_dealloc(self)
421 SPBObject *self;
423 /* Cleanup of self->ob_itself goes here */
424 self->ob_spb.userLong = 0;
425 self->ob_thiscallback = 0;
426 Py_XDECREF(self->ob_completion);
427 Py_XDECREF(self->ob_interrupt);
428 PyMem_DEL(self);
431 static PyMethodDef SPBObj_methods[] = {
432 {NULL, NULL, 0}
435 static PyMethodChain SPBObj_chain = { SPBObj_methods, NULL };
437 static PyObject *SPBObj_getattr(self, name)
438 SPBObject *self;
439 char *name;
442 if (strcmp(name, "inRefNum") == 0)
443 return Py_BuildValue("l", self->ob_spb.inRefNum);
444 else if (strcmp(name, "count") == 0)
445 return Py_BuildValue("l", self->ob_spb.count);
446 else if (strcmp(name, "milliseconds") == 0)
447 return Py_BuildValue("l", self->ob_spb.milliseconds);
448 else if (strcmp(name, "error") == 0)
449 return Py_BuildValue("h", self->ob_spb.error);
450 return Py_FindMethodInChain(&SPBObj_chain, (PyObject *)self, name);
453 static int SPBObj_setattr(self, name, value)
454 SPBObject *self;
455 char *name;
456 PyObject *value;
459 int rv = 0;
461 if (strcmp(name, "inRefNum") == 0)
462 rv = PyArg_Parse(value, "l", &self->ob_spb.inRefNum);
463 else if (strcmp(name, "count") == 0)
464 rv = PyArg_Parse(value, "l", &self->ob_spb.count);
465 else if (strcmp(name, "milliseconds") == 0)
466 rv = PyArg_Parse(value, "l", &self->ob_spb.milliseconds);
467 else if (strcmp(name, "buffer") == 0)
468 rv = PyArg_Parse(value, "w#", &self->ob_spb.bufferPtr, &self->ob_spb.bufferLength);
469 else if (strcmp(name, "completionRoutine") == 0) {
470 self->ob_spb.completionRoutine = NewSICompletionProc(SPB_completion);
471 self->ob_completion = value;
472 Py_INCREF(value);
473 rv = 1;
474 } else if (strcmp(name, "interruptRoutine") == 0) {
475 self->ob_spb.completionRoutine = NewSIInterruptProc(SPB_interrupt);
476 self->ob_interrupt = value;
477 Py_INCREF(value);
478 rv = 1;
480 if ( rv ) return 0;
481 else return -1;
484 #define SPBObj_compare NULL
486 #define SPBObj_repr NULL
488 #define SPBObj_hash NULL
490 staticforward PyTypeObject SPB_Type = {
491 PyObject_HEAD_INIT(&PyType_Type)
492 0, /*ob_size*/
493 "SPB", /*tp_name*/
494 sizeof(SPBObject), /*tp_basicsize*/
495 0, /*tp_itemsize*/
496 /* methods */
497 (destructor) SPBObj_dealloc, /*tp_dealloc*/
498 0, /*tp_print*/
499 (getattrfunc) SPBObj_getattr, /*tp_getattr*/
500 (setattrfunc) SPBObj_setattr, /*tp_setattr*/
501 (cmpfunc) SPBObj_compare, /*tp_compare*/
502 (reprfunc) SPBObj_repr, /*tp_repr*/
503 (PyNumberMethods *)0, /* tp_as_number */
504 (PySequenceMethods *)0, /* tp_as_sequence */
505 (PyMappingMethods *)0, /* tp_as_mapping */
506 (hashfunc) SPBObj_hash, /*tp_hash*/
509 /* ---------------------- End object type SPB ----------------------- */
512 static PyObject *Snd_SPB(_self, _args)
513 PyObject *_self;
514 PyObject *_args;
516 PyObject *_res = NULL;
517 return SPBObj_New();
520 static PyObject *Snd_SysBeep(_self, _args)
521 PyObject *_self;
522 PyObject *_args;
524 PyObject *_res = NULL;
525 short duration;
526 if (!PyArg_ParseTuple(_args, "h",
527 &duration))
528 return NULL;
529 SysBeep(duration);
530 Py_INCREF(Py_None);
531 _res = Py_None;
532 return _res;
535 static PyObject *Snd_SndNewChannel(_self, _args)
536 PyObject *_self;
537 PyObject *_args;
539 PyObject *_res = NULL;
540 OSErr _err;
541 SndChannelPtr chan = 0;
542 short synth;
543 long init;
544 PyObject* userRoutine;
545 if (!PyArg_ParseTuple(_args, "hlO",
546 &synth,
547 &init,
548 &userRoutine))
549 return NULL;
550 if (userRoutine != Py_None && !PyCallable_Check(userRoutine))
552 PyErr_SetString(PyExc_TypeError, "callback must be callable");
553 goto userRoutine__error__;
555 _err = SndNewChannel(&chan,
556 synth,
557 init,
558 NewSndCallBackProc(SndCh_UserRoutine));
559 if (_err != noErr) return PyMac_Error(_err);
560 _res = Py_BuildValue("O&",
561 SndCh_New, chan);
562 if (_res != NULL && userRoutine != Py_None)
564 SndChannelObject *p = (SndChannelObject *)_res;
565 p->ob_itself->userInfo = (long)p;
566 Py_INCREF(userRoutine);
567 p->ob_callback = userRoutine;
569 userRoutine__error__: ;
570 return _res;
573 static PyObject *Snd_SndControl(_self, _args)
574 PyObject *_self;
575 PyObject *_args;
577 PyObject *_res = NULL;
578 OSErr _err;
579 short id;
580 SndCommand cmd;
581 if (!PyArg_ParseTuple(_args, "h",
582 &id))
583 return NULL;
584 _err = SndControl(id,
585 &cmd);
586 if (_err != noErr) return PyMac_Error(_err);
587 _res = Py_BuildValue("O&",
588 SndCmd_New, &cmd);
589 return _res;
592 static PyObject *Snd_SndSoundManagerVersion(_self, _args)
593 PyObject *_self;
594 PyObject *_args;
596 PyObject *_res = NULL;
597 NumVersion _rv;
598 if (!PyArg_ParseTuple(_args, ""))
599 return NULL;
600 _rv = SndSoundManagerVersion();
601 _res = Py_BuildValue("O&",
602 PyMac_BuildNumVersion, _rv);
603 return _res;
606 static PyObject *Snd_SndManagerStatus(_self, _args)
607 PyObject *_self;
608 PyObject *_args;
610 PyObject *_res = NULL;
611 OSErr _err;
612 short theLength;
613 SMStatus theStatus__out__;
614 if (!PyArg_ParseTuple(_args, "h",
615 &theLength))
616 return NULL;
617 _err = SndManagerStatus(theLength,
618 &theStatus__out__);
619 if (_err != noErr) return PyMac_Error(_err);
620 _res = Py_BuildValue("s#",
621 (char *)&theStatus__out__, (int)sizeof(SMStatus));
622 theStatus__error__: ;
623 return _res;
626 static PyObject *Snd_SndGetSysBeepState(_self, _args)
627 PyObject *_self;
628 PyObject *_args;
630 PyObject *_res = NULL;
631 short sysBeepState;
632 if (!PyArg_ParseTuple(_args, ""))
633 return NULL;
634 SndGetSysBeepState(&sysBeepState);
635 _res = Py_BuildValue("h",
636 sysBeepState);
637 return _res;
640 static PyObject *Snd_SndSetSysBeepState(_self, _args)
641 PyObject *_self;
642 PyObject *_args;
644 PyObject *_res = NULL;
645 OSErr _err;
646 short sysBeepState;
647 if (!PyArg_ParseTuple(_args, "h",
648 &sysBeepState))
649 return NULL;
650 _err = SndSetSysBeepState(sysBeepState);
651 if (_err != noErr) return PyMac_Error(_err);
652 Py_INCREF(Py_None);
653 _res = Py_None;
654 return _res;
657 static PyObject *Snd_MACEVersion(_self, _args)
658 PyObject *_self;
659 PyObject *_args;
661 PyObject *_res = NULL;
662 NumVersion _rv;
663 if (!PyArg_ParseTuple(_args, ""))
664 return NULL;
665 _rv = MACEVersion();
666 _res = Py_BuildValue("O&",
667 PyMac_BuildNumVersion, _rv);
668 return _res;
671 static PyObject *Snd_Comp3to1(_self, _args)
672 PyObject *_self;
673 PyObject *_args;
675 PyObject *_res = NULL;
676 char *buffer__in__;
677 char *buffer__out__;
678 long buffer__len__;
679 int buffer__in_len__;
680 StateBlock *state__in__;
681 StateBlock state__out__;
682 int state__in_len__;
683 unsigned long numChannels;
684 unsigned long whichChannel;
685 if (!PyArg_ParseTuple(_args, "s#s#ll",
686 &buffer__in__, &buffer__in_len__,
687 (char **)&state__in__, &state__in_len__,
688 &numChannels,
689 &whichChannel))
690 return NULL;
691 if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
693 PyErr_NoMemory();
694 goto buffer__error__;
696 buffer__len__ = buffer__in_len__;
697 if (state__in_len__ != sizeof(StateBlock))
699 PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
700 goto state__error__;
702 Comp3to1(buffer__in__, buffer__out__, (long)buffer__len__,
703 state__in__, &state__out__,
704 numChannels,
705 whichChannel);
706 _res = Py_BuildValue("s#s#",
707 buffer__out__, (int)buffer__len__,
708 (char *)&state__out__, (int)sizeof(StateBlock));
709 state__error__: ;
710 free(buffer__out__);
711 buffer__error__: ;
712 return _res;
715 static PyObject *Snd_Exp1to3(_self, _args)
716 PyObject *_self;
717 PyObject *_args;
719 PyObject *_res = NULL;
720 char *buffer__in__;
721 char *buffer__out__;
722 long buffer__len__;
723 int buffer__in_len__;
724 StateBlock *state__in__;
725 StateBlock state__out__;
726 int state__in_len__;
727 unsigned long numChannels;
728 unsigned long whichChannel;
729 if (!PyArg_ParseTuple(_args, "s#s#ll",
730 &buffer__in__, &buffer__in_len__,
731 (char **)&state__in__, &state__in_len__,
732 &numChannels,
733 &whichChannel))
734 return NULL;
735 if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
737 PyErr_NoMemory();
738 goto buffer__error__;
740 buffer__len__ = buffer__in_len__;
741 if (state__in_len__ != sizeof(StateBlock))
743 PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
744 goto state__error__;
746 Exp1to3(buffer__in__, buffer__out__, (long)buffer__len__,
747 state__in__, &state__out__,
748 numChannels,
749 whichChannel);
750 _res = Py_BuildValue("s#s#",
751 buffer__out__, (int)buffer__len__,
752 (char *)&state__out__, (int)sizeof(StateBlock));
753 state__error__: ;
754 free(buffer__out__);
755 buffer__error__: ;
756 return _res;
759 static PyObject *Snd_Comp6to1(_self, _args)
760 PyObject *_self;
761 PyObject *_args;
763 PyObject *_res = NULL;
764 char *buffer__in__;
765 char *buffer__out__;
766 long buffer__len__;
767 int buffer__in_len__;
768 StateBlock *state__in__;
769 StateBlock state__out__;
770 int state__in_len__;
771 unsigned long numChannels;
772 unsigned long whichChannel;
773 if (!PyArg_ParseTuple(_args, "s#s#ll",
774 &buffer__in__, &buffer__in_len__,
775 (char **)&state__in__, &state__in_len__,
776 &numChannels,
777 &whichChannel))
778 return NULL;
779 if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
781 PyErr_NoMemory();
782 goto buffer__error__;
784 buffer__len__ = buffer__in_len__;
785 if (state__in_len__ != sizeof(StateBlock))
787 PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
788 goto state__error__;
790 Comp6to1(buffer__in__, buffer__out__, (long)buffer__len__,
791 state__in__, &state__out__,
792 numChannels,
793 whichChannel);
794 _res = Py_BuildValue("s#s#",
795 buffer__out__, (int)buffer__len__,
796 (char *)&state__out__, (int)sizeof(StateBlock));
797 state__error__: ;
798 free(buffer__out__);
799 buffer__error__: ;
800 return _res;
803 static PyObject *Snd_Exp1to6(_self, _args)
804 PyObject *_self;
805 PyObject *_args;
807 PyObject *_res = NULL;
808 char *buffer__in__;
809 char *buffer__out__;
810 long buffer__len__;
811 int buffer__in_len__;
812 StateBlock *state__in__;
813 StateBlock state__out__;
814 int state__in_len__;
815 unsigned long numChannels;
816 unsigned long whichChannel;
817 if (!PyArg_ParseTuple(_args, "s#s#ll",
818 &buffer__in__, &buffer__in_len__,
819 (char **)&state__in__, &state__in_len__,
820 &numChannels,
821 &whichChannel))
822 return NULL;
823 if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
825 PyErr_NoMemory();
826 goto buffer__error__;
828 buffer__len__ = buffer__in_len__;
829 if (state__in_len__ != sizeof(StateBlock))
831 PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
832 goto state__error__;
834 Exp1to6(buffer__in__, buffer__out__, (long)buffer__len__,
835 state__in__, &state__out__,
836 numChannels,
837 whichChannel);
838 _res = Py_BuildValue("s#s#",
839 buffer__out__, (int)buffer__len__,
840 (char *)&state__out__, (int)sizeof(StateBlock));
841 state__error__: ;
842 free(buffer__out__);
843 buffer__error__: ;
844 return _res;
847 static PyObject *Snd_GetSysBeepVolume(_self, _args)
848 PyObject *_self;
849 PyObject *_args;
851 PyObject *_res = NULL;
852 OSErr _err;
853 long level;
854 if (!PyArg_ParseTuple(_args, ""))
855 return NULL;
856 _err = GetSysBeepVolume(&level);
857 if (_err != noErr) return PyMac_Error(_err);
858 _res = Py_BuildValue("l",
859 level);
860 return _res;
863 static PyObject *Snd_SetSysBeepVolume(_self, _args)
864 PyObject *_self;
865 PyObject *_args;
867 PyObject *_res = NULL;
868 OSErr _err;
869 long level;
870 if (!PyArg_ParseTuple(_args, "l",
871 &level))
872 return NULL;
873 _err = SetSysBeepVolume(level);
874 if (_err != noErr) return PyMac_Error(_err);
875 Py_INCREF(Py_None);
876 _res = Py_None;
877 return _res;
880 static PyObject *Snd_GetDefaultOutputVolume(_self, _args)
881 PyObject *_self;
882 PyObject *_args;
884 PyObject *_res = NULL;
885 OSErr _err;
886 long level;
887 if (!PyArg_ParseTuple(_args, ""))
888 return NULL;
889 _err = GetDefaultOutputVolume(&level);
890 if (_err != noErr) return PyMac_Error(_err);
891 _res = Py_BuildValue("l",
892 level);
893 return _res;
896 static PyObject *Snd_SetDefaultOutputVolume(_self, _args)
897 PyObject *_self;
898 PyObject *_args;
900 PyObject *_res = NULL;
901 OSErr _err;
902 long level;
903 if (!PyArg_ParseTuple(_args, "l",
904 &level))
905 return NULL;
906 _err = SetDefaultOutputVolume(level);
907 if (_err != noErr) return PyMac_Error(_err);
908 Py_INCREF(Py_None);
909 _res = Py_None;
910 return _res;
913 static PyObject *Snd_GetSoundHeaderOffset(_self, _args)
914 PyObject *_self;
915 PyObject *_args;
917 PyObject *_res = NULL;
918 OSErr _err;
919 SndListHandle sndHandle;
920 long offset;
921 if (!PyArg_ParseTuple(_args, "O&",
922 ResObj_Convert, &sndHandle))
923 return NULL;
924 _err = GetSoundHeaderOffset(sndHandle,
925 &offset);
926 if (_err != noErr) return PyMac_Error(_err);
927 _res = Py_BuildValue("l",
928 offset);
929 return _res;
932 static PyObject *Snd_GetCompressionInfo(_self, _args)
933 PyObject *_self;
934 PyObject *_args;
936 PyObject *_res = NULL;
937 OSErr _err;
938 short compressionID;
939 OSType format;
940 short numChannels;
941 short sampleSize;
942 CompressionInfo cp__out__;
943 if (!PyArg_ParseTuple(_args, "hO&hh",
944 &compressionID,
945 PyMac_GetOSType, &format,
946 &numChannels,
947 &sampleSize))
948 return NULL;
949 _err = GetCompressionInfo(compressionID,
950 format,
951 numChannels,
952 sampleSize,
953 &cp__out__);
954 if (_err != noErr) return PyMac_Error(_err);
955 _res = Py_BuildValue("s#",
956 (char *)&cp__out__, (int)sizeof(CompressionInfo));
957 cp__error__: ;
958 return _res;
961 static PyObject *Snd_SetSoundPreference(_self, _args)
962 PyObject *_self;
963 PyObject *_args;
965 PyObject *_res = NULL;
966 OSErr _err;
967 OSType theType;
968 Str255 name;
969 Handle settings;
970 if (!PyArg_ParseTuple(_args, "O&O&",
971 PyMac_GetOSType, &theType,
972 ResObj_Convert, &settings))
973 return NULL;
974 _err = SetSoundPreference(theType,
975 name,
976 settings);
977 if (_err != noErr) return PyMac_Error(_err);
978 _res = Py_BuildValue("O&",
979 PyMac_BuildStr255, name);
980 return _res;
983 static PyObject *Snd_GetSoundPreference(_self, _args)
984 PyObject *_self;
985 PyObject *_args;
987 PyObject *_res = NULL;
988 OSErr _err;
989 OSType theType;
990 Str255 name;
991 Handle settings;
992 if (!PyArg_ParseTuple(_args, "O&O&",
993 PyMac_GetOSType, &theType,
994 ResObj_Convert, &settings))
995 return NULL;
996 _err = GetSoundPreference(theType,
997 name,
998 settings);
999 if (_err != noErr) return PyMac_Error(_err);
1000 _res = Py_BuildValue("O&",
1001 PyMac_BuildStr255, name);
1002 return _res;
1005 static PyObject *Snd_GetCompressionName(_self, _args)
1006 PyObject *_self;
1007 PyObject *_args;
1009 PyObject *_res = NULL;
1010 OSErr _err;
1011 OSType compressionType;
1012 Str255 compressionName;
1013 if (!PyArg_ParseTuple(_args, "O&",
1014 PyMac_GetOSType, &compressionType))
1015 return NULL;
1016 _err = GetCompressionName(compressionType,
1017 compressionName);
1018 if (_err != noErr) return PyMac_Error(_err);
1019 _res = Py_BuildValue("O&",
1020 PyMac_BuildStr255, compressionName);
1021 return _res;
1024 static PyObject *Snd_SPBVersion(_self, _args)
1025 PyObject *_self;
1026 PyObject *_args;
1028 PyObject *_res = NULL;
1029 NumVersion _rv;
1030 if (!PyArg_ParseTuple(_args, ""))
1031 return NULL;
1032 _rv = SPBVersion();
1033 _res = Py_BuildValue("O&",
1034 PyMac_BuildNumVersion, _rv);
1035 return _res;
1038 static PyObject *Snd_SPBSignInDevice(_self, _args)
1039 PyObject *_self;
1040 PyObject *_args;
1042 PyObject *_res = NULL;
1043 OSErr _err;
1044 short deviceRefNum;
1045 Str255 deviceName;
1046 if (!PyArg_ParseTuple(_args, "hO&",
1047 &deviceRefNum,
1048 PyMac_GetStr255, deviceName))
1049 return NULL;
1050 _err = SPBSignInDevice(deviceRefNum,
1051 deviceName);
1052 if (_err != noErr) return PyMac_Error(_err);
1053 Py_INCREF(Py_None);
1054 _res = Py_None;
1055 return _res;
1058 static PyObject *Snd_SPBSignOutDevice(_self, _args)
1059 PyObject *_self;
1060 PyObject *_args;
1062 PyObject *_res = NULL;
1063 OSErr _err;
1064 short deviceRefNum;
1065 if (!PyArg_ParseTuple(_args, "h",
1066 &deviceRefNum))
1067 return NULL;
1068 _err = SPBSignOutDevice(deviceRefNum);
1069 if (_err != noErr) return PyMac_Error(_err);
1070 Py_INCREF(Py_None);
1071 _res = Py_None;
1072 return _res;
1075 static PyObject *Snd_SPBGetIndexedDevice(_self, _args)
1076 PyObject *_self;
1077 PyObject *_args;
1079 PyObject *_res = NULL;
1080 OSErr _err;
1081 short count;
1082 Str255 deviceName;
1083 Handle deviceIconHandle;
1084 if (!PyArg_ParseTuple(_args, "h",
1085 &count))
1086 return NULL;
1087 _err = SPBGetIndexedDevice(count,
1088 deviceName,
1089 &deviceIconHandle);
1090 if (_err != noErr) return PyMac_Error(_err);
1091 _res = Py_BuildValue("O&O&",
1092 PyMac_BuildStr255, deviceName,
1093 ResObj_New, deviceIconHandle);
1094 return _res;
1097 static PyObject *Snd_SPBOpenDevice(_self, _args)
1098 PyObject *_self;
1099 PyObject *_args;
1101 PyObject *_res = NULL;
1102 OSErr _err;
1103 Str255 deviceName;
1104 short permission;
1105 long inRefNum;
1106 if (!PyArg_ParseTuple(_args, "O&h",
1107 PyMac_GetStr255, deviceName,
1108 &permission))
1109 return NULL;
1110 _err = SPBOpenDevice(deviceName,
1111 permission,
1112 &inRefNum);
1113 if (_err != noErr) return PyMac_Error(_err);
1114 _res = Py_BuildValue("l",
1115 inRefNum);
1116 return _res;
1119 static PyObject *Snd_SPBCloseDevice(_self, _args)
1120 PyObject *_self;
1121 PyObject *_args;
1123 PyObject *_res = NULL;
1124 OSErr _err;
1125 long inRefNum;
1126 if (!PyArg_ParseTuple(_args, "l",
1127 &inRefNum))
1128 return NULL;
1129 _err = SPBCloseDevice(inRefNum);
1130 if (_err != noErr) return PyMac_Error(_err);
1131 Py_INCREF(Py_None);
1132 _res = Py_None;
1133 return _res;
1136 static PyObject *Snd_SPBRecord(_self, _args)
1137 PyObject *_self;
1138 PyObject *_args;
1140 PyObject *_res = NULL;
1141 OSErr _err;
1142 SPBPtr inParamPtr;
1143 Boolean asynchFlag;
1144 if (!PyArg_ParseTuple(_args, "O&b",
1145 SPBObj_Convert, &inParamPtr,
1146 &asynchFlag))
1147 return NULL;
1148 _err = SPBRecord(inParamPtr,
1149 asynchFlag);
1150 if (_err != noErr) return PyMac_Error(_err);
1151 Py_INCREF(Py_None);
1152 _res = Py_None;
1153 return _res;
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;
1179 static PyObject *Snd_SPBPauseRecording(_self, _args)
1180 PyObject *_self;
1181 PyObject *_args;
1183 PyObject *_res = NULL;
1184 OSErr _err;
1185 long inRefNum;
1186 if (!PyArg_ParseTuple(_args, "l",
1187 &inRefNum))
1188 return NULL;
1189 _err = SPBPauseRecording(inRefNum);
1190 if (_err != noErr) return PyMac_Error(_err);
1191 Py_INCREF(Py_None);
1192 _res = Py_None;
1193 return _res;
1196 static PyObject *Snd_SPBResumeRecording(_self, _args)
1197 PyObject *_self;
1198 PyObject *_args;
1200 PyObject *_res = NULL;
1201 OSErr _err;
1202 long inRefNum;
1203 if (!PyArg_ParseTuple(_args, "l",
1204 &inRefNum))
1205 return NULL;
1206 _err = SPBResumeRecording(inRefNum);
1207 if (_err != noErr) return PyMac_Error(_err);
1208 Py_INCREF(Py_None);
1209 _res = Py_None;
1210 return _res;
1213 static PyObject *Snd_SPBStopRecording(_self, _args)
1214 PyObject *_self;
1215 PyObject *_args;
1217 PyObject *_res = NULL;
1218 OSErr _err;
1219 long inRefNum;
1220 if (!PyArg_ParseTuple(_args, "l",
1221 &inRefNum))
1222 return NULL;
1223 _err = SPBStopRecording(inRefNum);
1224 if (_err != noErr) return PyMac_Error(_err);
1225 Py_INCREF(Py_None);
1226 _res = Py_None;
1227 return _res;
1230 static PyObject *Snd_SPBGetRecordingStatus(_self, _args)
1231 PyObject *_self;
1232 PyObject *_args;
1234 PyObject *_res = NULL;
1235 OSErr _err;
1236 long inRefNum;
1237 short recordingStatus;
1238 short meterLevel;
1239 unsigned long totalSamplesToRecord;
1240 unsigned long numberOfSamplesRecorded;
1241 unsigned long totalMsecsToRecord;
1242 unsigned long numberOfMsecsRecorded;
1243 if (!PyArg_ParseTuple(_args, "l",
1244 &inRefNum))
1245 return NULL;
1246 _err = SPBGetRecordingStatus(inRefNum,
1247 &recordingStatus,
1248 &meterLevel,
1249 &totalSamplesToRecord,
1250 &numberOfSamplesRecorded,
1251 &totalMsecsToRecord,
1252 &numberOfMsecsRecorded);
1253 if (_err != noErr) return PyMac_Error(_err);
1254 _res = Py_BuildValue("hhllll",
1255 recordingStatus,
1256 meterLevel,
1257 totalSamplesToRecord,
1258 numberOfSamplesRecorded,
1259 totalMsecsToRecord,
1260 numberOfMsecsRecorded);
1261 return _res;
1264 static PyObject *Snd_SPBGetDeviceInfo(_self, _args)
1265 PyObject *_self;
1266 PyObject *_args;
1268 PyObject *_res = NULL;
1269 OSErr _err;
1270 long inRefNum;
1271 OSType infoType;
1272 void * infoData;
1273 if (!PyArg_ParseTuple(_args, "lO&w",
1274 &inRefNum,
1275 PyMac_GetOSType, &infoType,
1276 &infoData))
1277 return NULL;
1278 _err = SPBGetDeviceInfo(inRefNum,
1279 infoType,
1280 infoData);
1281 if (_err != noErr) return PyMac_Error(_err);
1282 Py_INCREF(Py_None);
1283 _res = Py_None;
1284 return _res;
1287 static PyObject *Snd_SPBSetDeviceInfo(_self, _args)
1288 PyObject *_self;
1289 PyObject *_args;
1291 PyObject *_res = NULL;
1292 OSErr _err;
1293 long inRefNum;
1294 OSType infoType;
1295 void * infoData;
1296 if (!PyArg_ParseTuple(_args, "lO&w",
1297 &inRefNum,
1298 PyMac_GetOSType, &infoType,
1299 &infoData))
1300 return NULL;
1301 _err = SPBSetDeviceInfo(inRefNum,
1302 infoType,
1303 infoData);
1304 if (_err != noErr) return PyMac_Error(_err);
1305 Py_INCREF(Py_None);
1306 _res = Py_None;
1307 return _res;
1310 static PyObject *Snd_SPBMillisecondsToBytes(_self, _args)
1311 PyObject *_self;
1312 PyObject *_args;
1314 PyObject *_res = NULL;
1315 OSErr _err;
1316 long inRefNum;
1317 long milliseconds;
1318 if (!PyArg_ParseTuple(_args, "l",
1319 &inRefNum))
1320 return NULL;
1321 _err = SPBMillisecondsToBytes(inRefNum,
1322 &milliseconds);
1323 if (_err != noErr) return PyMac_Error(_err);
1324 _res = Py_BuildValue("l",
1325 milliseconds);
1326 return _res;
1329 static PyObject *Snd_SPBBytesToMilliseconds(_self, _args)
1330 PyObject *_self;
1331 PyObject *_args;
1333 PyObject *_res = NULL;
1334 OSErr _err;
1335 long inRefNum;
1336 long byteCount;
1337 if (!PyArg_ParseTuple(_args, "l",
1338 &inRefNum))
1339 return NULL;
1340 _err = SPBBytesToMilliseconds(inRefNum,
1341 &byteCount);
1342 if (_err != noErr) return PyMac_Error(_err);
1343 _res = Py_BuildValue("l",
1344 byteCount);
1345 return _res;
1348 static PyMethodDef Snd_methods[] = {
1349 {"SPB", (PyCFunction)Snd_SPB, 1,
1350 NULL},
1351 {"SysBeep", (PyCFunction)Snd_SysBeep, 1,
1352 "(short duration) -> None"},
1353 {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1,
1354 "(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)"},
1355 {"SndControl", (PyCFunction)Snd_SndControl, 1,
1356 "(short id) -> (SndCommand cmd)"},
1357 {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1,
1358 "() -> (NumVersion _rv)"},
1359 {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1,
1360 "(short theLength) -> (SMStatus theStatus)"},
1361 {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1,
1362 "() -> (short sysBeepState)"},
1363 {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1,
1364 "(short sysBeepState) -> None"},
1365 {"MACEVersion", (PyCFunction)Snd_MACEVersion, 1,
1366 "() -> (NumVersion _rv)"},
1367 {"Comp3to1", (PyCFunction)Snd_Comp3to1, 1,
1368 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1369 {"Exp1to3", (PyCFunction)Snd_Exp1to3, 1,
1370 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1371 {"Comp6to1", (PyCFunction)Snd_Comp6to1, 1,
1372 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1373 {"Exp1to6", (PyCFunction)Snd_Exp1to6, 1,
1374 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1375 {"GetSysBeepVolume", (PyCFunction)Snd_GetSysBeepVolume, 1,
1376 "() -> (long level)"},
1377 {"SetSysBeepVolume", (PyCFunction)Snd_SetSysBeepVolume, 1,
1378 "(long level) -> None"},
1379 {"GetDefaultOutputVolume", (PyCFunction)Snd_GetDefaultOutputVolume, 1,
1380 "() -> (long level)"},
1381 {"SetDefaultOutputVolume", (PyCFunction)Snd_SetDefaultOutputVolume, 1,
1382 "(long level) -> None"},
1383 {"GetSoundHeaderOffset", (PyCFunction)Snd_GetSoundHeaderOffset, 1,
1384 "(SndListHandle sndHandle) -> (long offset)"},
1385 {"GetCompressionInfo", (PyCFunction)Snd_GetCompressionInfo, 1,
1386 "(short compressionID, OSType format, short numChannels, short sampleSize) -> (CompressionInfo cp)"},
1387 {"SetSoundPreference", (PyCFunction)Snd_SetSoundPreference, 1,
1388 "(OSType theType, Handle settings) -> (Str255 name)"},
1389 {"GetSoundPreference", (PyCFunction)Snd_GetSoundPreference, 1,
1390 "(OSType theType, Handle settings) -> (Str255 name)"},
1391 {"GetCompressionName", (PyCFunction)Snd_GetCompressionName, 1,
1392 "(OSType compressionType) -> (Str255 compressionName)"},
1393 {"SPBVersion", (PyCFunction)Snd_SPBVersion, 1,
1394 "() -> (NumVersion _rv)"},
1395 {"SPBSignInDevice", (PyCFunction)Snd_SPBSignInDevice, 1,
1396 "(short deviceRefNum, Str255 deviceName) -> None"},
1397 {"SPBSignOutDevice", (PyCFunction)Snd_SPBSignOutDevice, 1,
1398 "(short deviceRefNum) -> None"},
1399 {"SPBGetIndexedDevice", (PyCFunction)Snd_SPBGetIndexedDevice, 1,
1400 "(short count) -> (Str255 deviceName, Handle deviceIconHandle)"},
1401 {"SPBOpenDevice", (PyCFunction)Snd_SPBOpenDevice, 1,
1402 "(Str255 deviceName, short permission) -> (long inRefNum)"},
1403 {"SPBCloseDevice", (PyCFunction)Snd_SPBCloseDevice, 1,
1404 "(long inRefNum) -> None"},
1405 {"SPBRecord", (PyCFunction)Snd_SPBRecord, 1,
1406 "(SPBPtr inParamPtr, Boolean asynchFlag) -> None"},
1407 {"SPBRecordToFile", (PyCFunction)Snd_SPBRecordToFile, 1,
1408 "(short fRefNum, SPBPtr inParamPtr, Boolean asynchFlag) -> None"},
1409 {"SPBPauseRecording", (PyCFunction)Snd_SPBPauseRecording, 1,
1410 "(long inRefNum) -> None"},
1411 {"SPBResumeRecording", (PyCFunction)Snd_SPBResumeRecording, 1,
1412 "(long inRefNum) -> None"},
1413 {"SPBStopRecording", (PyCFunction)Snd_SPBStopRecording, 1,
1414 "(long inRefNum) -> None"},
1415 {"SPBGetRecordingStatus", (PyCFunction)Snd_SPBGetRecordingStatus, 1,
1416 "(long inRefNum) -> (short recordingStatus, short meterLevel, unsigned long totalSamplesToRecord, unsigned long numberOfSamplesRecorded, unsigned long totalMsecsToRecord, unsigned long numberOfMsecsRecorded)"},
1417 {"SPBGetDeviceInfo", (PyCFunction)Snd_SPBGetDeviceInfo, 1,
1418 "(long inRefNum, OSType infoType, void * infoData) -> None"},
1419 {"SPBSetDeviceInfo", (PyCFunction)Snd_SPBSetDeviceInfo, 1,
1420 "(long inRefNum, OSType infoType, void * infoData) -> None"},
1421 {"SPBMillisecondsToBytes", (PyCFunction)Snd_SPBMillisecondsToBytes, 1,
1422 "(long inRefNum) -> (long milliseconds)"},
1423 {"SPBBytesToMilliseconds", (PyCFunction)Snd_SPBBytesToMilliseconds, 1,
1424 "(long inRefNum) -> (long byteCount)"},
1425 {NULL, NULL, 0}
1430 /* Routine passed to Py_AddPendingCall -- call the Python callback */
1431 static int
1432 SndCh_CallCallBack(arg)
1433 void *arg;
1435 SndChannelObject *p = (SndChannelObject *)arg;
1436 PyObject *args;
1437 PyObject *res;
1438 args = Py_BuildValue("(O(hhl))",
1439 p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2);
1440 res = PyEval_CallObject(p->ob_callback, args);
1441 Py_DECREF(args);
1442 if (res == NULL)
1443 return -1;
1444 Py_DECREF(res);
1445 return 0;
1448 /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */
1449 static pascal void
1450 SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd)
1452 SndChannelObject *p = (SndChannelObject *)(chan->userInfo);
1453 if (p->ob_callback != NULL) {
1454 long A5 = SetA5(p->ob_A5);
1455 p->ob_cmd = *cmd;
1456 Py_AddPendingCall(SndCh_CallCallBack, (void *)p);
1457 SetA5(A5);
1461 /* SPB callbacks - Schedule callbacks to Python */
1462 static int
1463 SPB_CallCallBack(arg)
1464 void *arg;
1466 SPBObject *p = (SPBObject *)arg;
1467 PyObject *args;
1468 PyObject *res;
1470 if ( p->ob_thiscallback == 0 ) return 0;
1471 args = Py_BuildValue("(O)", p);
1472 res = PyEval_CallObject(p->ob_thiscallback, args);
1473 p->ob_thiscallback = 0;
1474 Py_DECREF(args);
1475 if (res == NULL)
1476 return -1;
1477 Py_DECREF(res);
1478 return 0;
1481 static pascal void
1482 SPB_completion(SPBPtr my_spb)
1484 SPBObject *p = (SPBObject *)(my_spb->userLong);
1486 if (p && p->ob_completion) {
1487 long A5 = SetA5(p->ob_A5);
1488 p->ob_thiscallback = p->ob_completion; /* Hope we cannot get two at the same time */
1489 Py_AddPendingCall(SPB_CallCallBack, (void *)p);
1490 SetA5(A5);
1494 static pascal void
1495 SPB_interrupt(SPBPtr my_spb)
1497 SPBObject *p = (SPBObject *)(my_spb->userLong);
1499 if (p && p->ob_interrupt) {
1500 long A5 = SetA5(p->ob_A5);
1501 p->ob_thiscallback = p->ob_interrupt; /* Hope we cannot get two at the same time */
1502 Py_AddPendingCall(SPB_CallCallBack, (void *)p);
1503 SetA5(A5);
1508 void initSnd()
1510 PyObject *m;
1511 PyObject *d;
1517 m = Py_InitModule("Snd", Snd_methods);
1518 d = PyModule_GetDict(m);
1519 Snd_Error = PyMac_GetOSErrException();
1520 if (Snd_Error == NULL ||
1521 PyDict_SetItemString(d, "Error", Snd_Error) != 0)
1522 Py_FatalError("can't initialize Snd.Error");
1523 SndChannel_Type.ob_type = &PyType_Type;
1524 Py_INCREF(&SndChannel_Type);
1525 if (PyDict_SetItemString(d, "SndChannelType", (PyObject *)&SndChannel_Type) != 0)
1526 Py_FatalError("can't initialize SndChannelType");
1527 SPB_Type.ob_type = &PyType_Type;
1528 Py_INCREF(&SPB_Type);
1529 if (PyDict_SetItemString(d, "SPBType", (PyObject *)&SPB_Type) != 0)
1530 Py_FatalError("can't initialize SPBType");
1533 /* ========================= End module Snd ========================= */