2 /* =========================== Module Snd =========================== */
8 #define SystemSevenOrLater 1
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
);
47 #ifndef HAVE_UNIVERSAL_HEADERS
48 #define SndCallBackUPP ProcPtr
49 #define NewSndCallBackProc(x) ((SndCallBackProcPtr)(x))
50 #define SndListHandle Handle
53 #include <OSUtils.h> /* for Set(Current)A5 */
55 /* Create a SndCommand object (an (int, int, int) tuple) */
57 SndCmd_New(SndCommand
*pc
)
59 return Py_BuildValue("hhl", pc
->cmd
, pc
->param1
, pc
->param2
);
62 /* Convert a SndCommand argument */
64 SndCmd_Convert(PyObject
*v
, SndCommand
*pc
)
69 if (PyTuple_Check(v
)) {
70 if (PyArg_ParseTuple(v
, "h|hl", &pc
->cmd
, &pc
->param1
, &pc
->param2
))
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
{
92 SndChannelPtr ob_itself
;
93 /* Members used to implement callbacks: */
94 PyObject
*ob_callback
;
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
)
112 SndChannelPtr
*p_itself
;
116 PyErr_SetString(PyExc_TypeError
, "SndChannel required");
119 *p_itself
= ((SndChannelObject
*)v
)->ob_itself
;
123 static void SndCh_dealloc(self
)
124 SndChannelObject
*self
;
126 SndDisposeChannel(self
->ob_itself
, 1);
127 Py_XDECREF(self
->ob_callback
);
131 static PyObject
*SndCh_SndDoCommand(_self
, _args
)
132 SndChannelObject
*_self
;
135 PyObject
*_res
= NULL
;
139 if (!PyArg_ParseTuple(_args
, "O&b",
140 SndCmd_Convert
, &cmd
,
143 _err
= SndDoCommand(_self
->ob_itself
,
146 if (_err
!= noErr
) return PyMac_Error(_err
);
152 static PyObject
*SndCh_SndDoImmediate(_self
, _args
)
153 SndChannelObject
*_self
;
156 PyObject
*_res
= NULL
;
159 if (!PyArg_ParseTuple(_args
, "O&",
160 SndCmd_Convert
, &cmd
))
162 _err
= SndDoImmediate(_self
->ob_itself
,
164 if (_err
!= noErr
) return PyMac_Error(_err
);
170 static PyObject
*SndCh_SndPlay(_self
, _args
)
171 SndChannelObject
*_self
;
174 PyObject
*_res
= NULL
;
176 SndListHandle sndHandle
;
178 if (!PyArg_ParseTuple(_args
, "O&b",
179 ResObj_Convert
, &sndHandle
,
182 _err
= SndPlay(_self
->ob_itself
,
185 if (_err
!= noErr
) return PyMac_Error(_err
);
191 static PyObject
*SndCh_SndStartFilePlay(_self
, _args
)
192 SndChannelObject
*_self
;
195 PyObject
*_res
= NULL
;
201 if (!PyArg_ParseTuple(_args
, "hhlb",
207 _err
= SndStartFilePlay(_self
->ob_itself
,
215 if (_err
!= noErr
) return PyMac_Error(_err
);
221 static PyObject
*SndCh_SndPauseFilePlay(_self
, _args
)
222 SndChannelObject
*_self
;
225 PyObject
*_res
= NULL
;
227 if (!PyArg_ParseTuple(_args
, ""))
229 _err
= SndPauseFilePlay(_self
->ob_itself
);
230 if (_err
!= noErr
) return PyMac_Error(_err
);
236 static PyObject
*SndCh_SndStopFilePlay(_self
, _args
)
237 SndChannelObject
*_self
;
240 PyObject
*_res
= NULL
;
243 if (!PyArg_ParseTuple(_args
, "b",
246 _err
= SndStopFilePlay(_self
->ob_itself
,
248 if (_err
!= noErr
) return PyMac_Error(_err
);
254 static PyObject
*SndCh_SndChannelStatus(_self
, _args
)
255 SndChannelObject
*_self
;
258 PyObject
*_res
= NULL
;
261 SCStatus theStatus__out__
;
262 if (!PyArg_ParseTuple(_args
, "h",
265 _err
= SndChannelStatus(_self
->ob_itself
,
268 if (_err
!= noErr
) return PyMac_Error(_err
);
269 _res
= Py_BuildValue("s#",
270 (char *)&theStatus__out__
, (int)sizeof(SCStatus
));
271 theStatus__error__
: ;
275 static PyObject
*SndCh_SndGetInfo(_self
, _args
)
276 SndChannelObject
*_self
;
279 PyObject
*_res
= NULL
;
283 if (!PyArg_ParseTuple(_args
, "O&w",
284 PyMac_GetOSType
, &selector
,
287 _err
= SndGetInfo(_self
->ob_itself
,
290 if (_err
!= noErr
) return PyMac_Error(_err
);
296 static PyObject
*SndCh_SndSetInfo(_self
, _args
)
297 SndChannelObject
*_self
;
300 PyObject
*_res
= NULL
;
304 if (!PyArg_ParseTuple(_args
, "O&w",
305 PyMac_GetOSType
, &selector
,
308 _err
= SndSetInfo(_self
->ob_itself
,
311 if (_err
!= noErr
) return PyMac_Error(_err
);
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,
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"},
339 static PyMethodChain SndCh_chain
= { SndCh_methods
, NULL
};
341 static PyObject
*SndCh_getattr(self
, name
)
342 SndChannelObject
*self
;
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
)
359 "SndChannel", /*tp_name*/
360 sizeof(SndChannelObject
), /*tp_basicsize*/
363 (destructor
) SndCh_dealloc
, /*tp_dealloc*/
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
{
386 /* Members used to implement callbacks: */
387 PyObject
*ob_completion
;
388 PyObject
*ob_interrupt
;
389 PyObject
*ob_thiscallback
;
394 static PyObject
*SPBObj_New()
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
)
411 if (!SPBObj_Check(v
))
413 PyErr_SetString(PyExc_TypeError
, "SPB required");
416 *p_itself
= &((SPBObject
*)v
)->ob_spb
;
420 static void SPBObj_dealloc(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
);
431 static PyMethodDef SPBObj_methods
[] = {
435 static PyMethodChain SPBObj_chain
= { SPBObj_methods
, NULL
};
437 static PyObject
*SPBObj_getattr(self
, 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
)
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
;
474 } else if (strcmp(name
, "interruptRoutine") == 0) {
475 self
->ob_spb
.completionRoutine
= NewSIInterruptProc(SPB_interrupt
);
476 self
->ob_interrupt
= value
;
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
)
494 sizeof(SPBObject
), /*tp_basicsize*/
497 (destructor
) SPBObj_dealloc
, /*tp_dealloc*/
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
)
516 PyObject
*_res
= NULL
;
520 static PyObject
*Snd_SysBeep(_self
, _args
)
524 PyObject
*_res
= NULL
;
526 if (!PyArg_ParseTuple(_args
, "h",
535 static PyObject
*Snd_SndNewChannel(_self
, _args
)
539 PyObject
*_res
= NULL
;
541 SndChannelPtr chan
= 0;
544 PyObject
* userRoutine
;
545 if (!PyArg_ParseTuple(_args
, "hlO",
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
,
558 NewSndCallBackProc(SndCh_UserRoutine
));
559 if (_err
!= noErr
) return PyMac_Error(_err
);
560 _res
= Py_BuildValue("O&",
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__
: ;
573 static PyObject
*Snd_SndControl(_self
, _args
)
577 PyObject
*_res
= NULL
;
581 if (!PyArg_ParseTuple(_args
, "h",
584 _err
= SndControl(id
,
586 if (_err
!= noErr
) return PyMac_Error(_err
);
587 _res
= Py_BuildValue("O&",
592 static PyObject
*Snd_SndSoundManagerVersion(_self
, _args
)
596 PyObject
*_res
= NULL
;
598 if (!PyArg_ParseTuple(_args
, ""))
600 _rv
= SndSoundManagerVersion();
601 _res
= Py_BuildValue("O&",
602 PyMac_BuildNumVersion
, _rv
);
606 static PyObject
*Snd_SndManagerStatus(_self
, _args
)
610 PyObject
*_res
= NULL
;
613 SMStatus theStatus__out__
;
614 if (!PyArg_ParseTuple(_args
, "h",
617 _err
= SndManagerStatus(theLength
,
619 if (_err
!= noErr
) return PyMac_Error(_err
);
620 _res
= Py_BuildValue("s#",
621 (char *)&theStatus__out__
, (int)sizeof(SMStatus
));
622 theStatus__error__
: ;
626 static PyObject
*Snd_SndGetSysBeepState(_self
, _args
)
630 PyObject
*_res
= NULL
;
632 if (!PyArg_ParseTuple(_args
, ""))
634 SndGetSysBeepState(&sysBeepState
);
635 _res
= Py_BuildValue("h",
640 static PyObject
*Snd_SndSetSysBeepState(_self
, _args
)
644 PyObject
*_res
= NULL
;
647 if (!PyArg_ParseTuple(_args
, "h",
650 _err
= SndSetSysBeepState(sysBeepState
);
651 if (_err
!= noErr
) return PyMac_Error(_err
);
657 static PyObject
*Snd_MACEVersion(_self
, _args
)
661 PyObject
*_res
= NULL
;
663 if (!PyArg_ParseTuple(_args
, ""))
666 _res
= Py_BuildValue("O&",
667 PyMac_BuildNumVersion
, _rv
);
671 static PyObject
*Snd_Comp3to1(_self
, _args
)
675 PyObject
*_res
= NULL
;
679 int buffer__in_len__
;
680 StateBlock
*state__in__
;
681 StateBlock state__out__
;
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__
,
691 if ((buffer__out__
= malloc(buffer__in_len__
)) == NULL
)
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)");
702 Comp3to1(buffer__in__
, buffer__out__
, (long)buffer__len__
,
703 state__in__
, &state__out__
,
706 _res
= Py_BuildValue("s#s#",
707 buffer__out__
, (int)buffer__len__
,
708 (char *)&state__out__
, (int)sizeof(StateBlock
));
715 static PyObject
*Snd_Exp1to3(_self
, _args
)
719 PyObject
*_res
= NULL
;
723 int buffer__in_len__
;
724 StateBlock
*state__in__
;
725 StateBlock state__out__
;
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__
,
735 if ((buffer__out__
= malloc(buffer__in_len__
)) == NULL
)
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)");
746 Exp1to3(buffer__in__
, buffer__out__
, (long)buffer__len__
,
747 state__in__
, &state__out__
,
750 _res
= Py_BuildValue("s#s#",
751 buffer__out__
, (int)buffer__len__
,
752 (char *)&state__out__
, (int)sizeof(StateBlock
));
759 static PyObject
*Snd_Comp6to1(_self
, _args
)
763 PyObject
*_res
= NULL
;
767 int buffer__in_len__
;
768 StateBlock
*state__in__
;
769 StateBlock state__out__
;
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__
,
779 if ((buffer__out__
= malloc(buffer__in_len__
)) == NULL
)
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)");
790 Comp6to1(buffer__in__
, buffer__out__
, (long)buffer__len__
,
791 state__in__
, &state__out__
,
794 _res
= Py_BuildValue("s#s#",
795 buffer__out__
, (int)buffer__len__
,
796 (char *)&state__out__
, (int)sizeof(StateBlock
));
803 static PyObject
*Snd_Exp1to6(_self
, _args
)
807 PyObject
*_res
= NULL
;
811 int buffer__in_len__
;
812 StateBlock
*state__in__
;
813 StateBlock state__out__
;
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__
,
823 if ((buffer__out__
= malloc(buffer__in_len__
)) == NULL
)
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)");
834 Exp1to6(buffer__in__
, buffer__out__
, (long)buffer__len__
,
835 state__in__
, &state__out__
,
838 _res
= Py_BuildValue("s#s#",
839 buffer__out__
, (int)buffer__len__
,
840 (char *)&state__out__
, (int)sizeof(StateBlock
));
847 static PyObject
*Snd_GetSysBeepVolume(_self
, _args
)
851 PyObject
*_res
= NULL
;
854 if (!PyArg_ParseTuple(_args
, ""))
856 _err
= GetSysBeepVolume(&level
);
857 if (_err
!= noErr
) return PyMac_Error(_err
);
858 _res
= Py_BuildValue("l",
863 static PyObject
*Snd_SetSysBeepVolume(_self
, _args
)
867 PyObject
*_res
= NULL
;
870 if (!PyArg_ParseTuple(_args
, "l",
873 _err
= SetSysBeepVolume(level
);
874 if (_err
!= noErr
) return PyMac_Error(_err
);
880 static PyObject
*Snd_GetDefaultOutputVolume(_self
, _args
)
884 PyObject
*_res
= NULL
;
887 if (!PyArg_ParseTuple(_args
, ""))
889 _err
= GetDefaultOutputVolume(&level
);
890 if (_err
!= noErr
) return PyMac_Error(_err
);
891 _res
= Py_BuildValue("l",
896 static PyObject
*Snd_SetDefaultOutputVolume(_self
, _args
)
900 PyObject
*_res
= NULL
;
903 if (!PyArg_ParseTuple(_args
, "l",
906 _err
= SetDefaultOutputVolume(level
);
907 if (_err
!= noErr
) return PyMac_Error(_err
);
913 static PyObject
*Snd_GetSoundHeaderOffset(_self
, _args
)
917 PyObject
*_res
= NULL
;
919 SndListHandle sndHandle
;
921 if (!PyArg_ParseTuple(_args
, "O&",
922 ResObj_Convert
, &sndHandle
))
924 _err
= GetSoundHeaderOffset(sndHandle
,
926 if (_err
!= noErr
) return PyMac_Error(_err
);
927 _res
= Py_BuildValue("l",
932 static PyObject
*Snd_GetCompressionInfo(_self
, _args
)
936 PyObject
*_res
= NULL
;
942 CompressionInfo cp__out__
;
943 if (!PyArg_ParseTuple(_args
, "hO&hh",
945 PyMac_GetOSType
, &format
,
949 _err
= GetCompressionInfo(compressionID
,
954 if (_err
!= noErr
) return PyMac_Error(_err
);
955 _res
= Py_BuildValue("s#",
956 (char *)&cp__out__
, (int)sizeof(CompressionInfo
));
961 static PyObject
*Snd_SetSoundPreference(_self
, _args
)
965 PyObject
*_res
= NULL
;
970 if (!PyArg_ParseTuple(_args
, "O&O&",
971 PyMac_GetOSType
, &theType
,
972 ResObj_Convert
, &settings
))
974 _err
= SetSoundPreference(theType
,
977 if (_err
!= noErr
) return PyMac_Error(_err
);
978 _res
= Py_BuildValue("O&",
979 PyMac_BuildStr255
, name
);
983 static PyObject
*Snd_GetSoundPreference(_self
, _args
)
987 PyObject
*_res
= NULL
;
992 if (!PyArg_ParseTuple(_args
, "O&O&",
993 PyMac_GetOSType
, &theType
,
994 ResObj_Convert
, &settings
))
996 _err
= GetSoundPreference(theType
,
999 if (_err
!= noErr
) return PyMac_Error(_err
);
1000 _res
= Py_BuildValue("O&",
1001 PyMac_BuildStr255
, name
);
1005 static PyObject
*Snd_GetCompressionName(_self
, _args
)
1009 PyObject
*_res
= NULL
;
1011 OSType compressionType
;
1012 Str255 compressionName
;
1013 if (!PyArg_ParseTuple(_args
, "O&",
1014 PyMac_GetOSType
, &compressionType
))
1016 _err
= GetCompressionName(compressionType
,
1018 if (_err
!= noErr
) return PyMac_Error(_err
);
1019 _res
= Py_BuildValue("O&",
1020 PyMac_BuildStr255
, compressionName
);
1024 static PyObject
*Snd_SPBVersion(_self
, _args
)
1028 PyObject
*_res
= NULL
;
1030 if (!PyArg_ParseTuple(_args
, ""))
1033 _res
= Py_BuildValue("O&",
1034 PyMac_BuildNumVersion
, _rv
);
1038 static PyObject
*Snd_SPBSignInDevice(_self
, _args
)
1042 PyObject
*_res
= NULL
;
1046 if (!PyArg_ParseTuple(_args
, "hO&",
1048 PyMac_GetStr255
, deviceName
))
1050 _err
= SPBSignInDevice(deviceRefNum
,
1052 if (_err
!= noErr
) return PyMac_Error(_err
);
1058 static PyObject
*Snd_SPBSignOutDevice(_self
, _args
)
1062 PyObject
*_res
= NULL
;
1065 if (!PyArg_ParseTuple(_args
, "h",
1068 _err
= SPBSignOutDevice(deviceRefNum
);
1069 if (_err
!= noErr
) return PyMac_Error(_err
);
1075 static PyObject
*Snd_SPBGetIndexedDevice(_self
, _args
)
1079 PyObject
*_res
= NULL
;
1083 Handle deviceIconHandle
;
1084 if (!PyArg_ParseTuple(_args
, "h",
1087 _err
= SPBGetIndexedDevice(count
,
1090 if (_err
!= noErr
) return PyMac_Error(_err
);
1091 _res
= Py_BuildValue("O&O&",
1092 PyMac_BuildStr255
, deviceName
,
1093 ResObj_New
, deviceIconHandle
);
1097 static PyObject
*Snd_SPBOpenDevice(_self
, _args
)
1101 PyObject
*_res
= NULL
;
1106 if (!PyArg_ParseTuple(_args
, "O&h",
1107 PyMac_GetStr255
, deviceName
,
1110 _err
= SPBOpenDevice(deviceName
,
1113 if (_err
!= noErr
) return PyMac_Error(_err
);
1114 _res
= Py_BuildValue("l",
1119 static PyObject
*Snd_SPBCloseDevice(_self
, _args
)
1123 PyObject
*_res
= NULL
;
1126 if (!PyArg_ParseTuple(_args
, "l",
1129 _err
= SPBCloseDevice(inRefNum
);
1130 if (_err
!= noErr
) return PyMac_Error(_err
);
1136 static PyObject
*Snd_SPBRecord(_self
, _args
)
1140 PyObject
*_res
= NULL
;
1144 if (!PyArg_ParseTuple(_args
, "O&b",
1145 SPBObj_Convert
, &inParamPtr
,
1148 _err
= SPBRecord(inParamPtr
,
1150 if (_err
!= noErr
) return PyMac_Error(_err
);
1156 static PyObject
*Snd_SPBRecordToFile(_self
, _args
)
1160 PyObject
*_res
= NULL
;
1165 if (!PyArg_ParseTuple(_args
, "hO&b",
1167 SPBObj_Convert
, &inParamPtr
,
1170 _err
= SPBRecordToFile(fRefNum
,
1173 if (_err
!= noErr
) return PyMac_Error(_err
);
1179 static PyObject
*Snd_SPBPauseRecording(_self
, _args
)
1183 PyObject
*_res
= NULL
;
1186 if (!PyArg_ParseTuple(_args
, "l",
1189 _err
= SPBPauseRecording(inRefNum
);
1190 if (_err
!= noErr
) return PyMac_Error(_err
);
1196 static PyObject
*Snd_SPBResumeRecording(_self
, _args
)
1200 PyObject
*_res
= NULL
;
1203 if (!PyArg_ParseTuple(_args
, "l",
1206 _err
= SPBResumeRecording(inRefNum
);
1207 if (_err
!= noErr
) return PyMac_Error(_err
);
1213 static PyObject
*Snd_SPBStopRecording(_self
, _args
)
1217 PyObject
*_res
= NULL
;
1220 if (!PyArg_ParseTuple(_args
, "l",
1223 _err
= SPBStopRecording(inRefNum
);
1224 if (_err
!= noErr
) return PyMac_Error(_err
);
1230 static PyObject
*Snd_SPBGetRecordingStatus(_self
, _args
)
1234 PyObject
*_res
= NULL
;
1237 short recordingStatus
;
1239 unsigned long totalSamplesToRecord
;
1240 unsigned long numberOfSamplesRecorded
;
1241 unsigned long totalMsecsToRecord
;
1242 unsigned long numberOfMsecsRecorded
;
1243 if (!PyArg_ParseTuple(_args
, "l",
1246 _err
= SPBGetRecordingStatus(inRefNum
,
1249 &totalSamplesToRecord
,
1250 &numberOfSamplesRecorded
,
1251 &totalMsecsToRecord
,
1252 &numberOfMsecsRecorded
);
1253 if (_err
!= noErr
) return PyMac_Error(_err
);
1254 _res
= Py_BuildValue("hhllll",
1257 totalSamplesToRecord
,
1258 numberOfSamplesRecorded
,
1260 numberOfMsecsRecorded
);
1264 static PyObject
*Snd_SPBGetDeviceInfo(_self
, _args
)
1268 PyObject
*_res
= NULL
;
1273 if (!PyArg_ParseTuple(_args
, "lO&w",
1275 PyMac_GetOSType
, &infoType
,
1278 _err
= SPBGetDeviceInfo(inRefNum
,
1281 if (_err
!= noErr
) return PyMac_Error(_err
);
1287 static PyObject
*Snd_SPBSetDeviceInfo(_self
, _args
)
1291 PyObject
*_res
= NULL
;
1296 if (!PyArg_ParseTuple(_args
, "lO&w",
1298 PyMac_GetOSType
, &infoType
,
1301 _err
= SPBSetDeviceInfo(inRefNum
,
1304 if (_err
!= noErr
) return PyMac_Error(_err
);
1310 static PyObject
*Snd_SPBMillisecondsToBytes(_self
, _args
)
1314 PyObject
*_res
= NULL
;
1318 if (!PyArg_ParseTuple(_args
, "l",
1321 _err
= SPBMillisecondsToBytes(inRefNum
,
1323 if (_err
!= noErr
) return PyMac_Error(_err
);
1324 _res
= Py_BuildValue("l",
1329 static PyObject
*Snd_SPBBytesToMilliseconds(_self
, _args
)
1333 PyObject
*_res
= NULL
;
1337 if (!PyArg_ParseTuple(_args
, "l",
1340 _err
= SPBBytesToMilliseconds(inRefNum
,
1342 if (_err
!= noErr
) return PyMac_Error(_err
);
1343 _res
= Py_BuildValue("l",
1348 static PyMethodDef Snd_methods
[] = {
1349 {"SPB", (PyCFunction
)Snd_SPB
, 1,
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)"},
1430 /* Routine passed to Py_AddPendingCall -- call the Python callback */
1432 SndCh_CallCallBack(arg
)
1435 SndChannelObject
*p
= (SndChannelObject
*)arg
;
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
);
1448 /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */
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
);
1456 Py_AddPendingCall(SndCh_CallCallBack
, (void *)p
);
1461 /* SPB callbacks - Schedule callbacks to Python */
1463 SPB_CallCallBack(arg
)
1466 SPBObject
*p
= (SPBObject
*)arg
;
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;
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
);
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
);
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 ========================= */