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