2 /* =========================== Module Snd =========================== */
9 #include "pymactoolbox.h"
13 #include <OSUtils.h> /* for Set(Current)A5 */
15 /* Create a SndCommand object (an (int, int, int) tuple) */
17 SndCmd_New(SndCommand
*pc
)
19 return Py_BuildValue("hhl", pc
->cmd
, pc
->param1
, pc
->param2
);
22 /* Convert a SndCommand argument */
24 SndCmd_Convert(PyObject
*v
, SndCommand
*pc
)
29 if (PyTuple_Check(v
)) {
30 if (PyArg_ParseTuple(v
, "h|hl", &pc
->cmd
, &pc
->param1
, &pc
->param2
))
33 return PyArg_ParseTuple(v
, "Hhs#", &pc
->cmd
, &pc
->param1
, &pc
->param2
, &len
);
35 return PyArg_Parse(v
, "H", &pc
->cmd
);
38 static pascal void SndCh_UserRoutine(SndChannelPtr chan
, SndCommand
*cmd
); /* Forward */
39 static pascal void SPB_completion(SPBPtr my_spb
); /* Forward */
40 static pascal void SPB_interrupt(SPBPtr my_spb
); /* Forward */
42 static PyObject
*Snd_Error
;
44 /* --------------------- Object type SndChannel --------------------- */
46 staticforward PyTypeObject SndChannel_Type
;
48 #define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type)
50 typedef struct SndChannelObject
{
52 SndChannelPtr ob_itself
;
53 /* Members used to implement callbacks: */
54 PyObject
*ob_callback
;
59 static PyObject
*SndCh_New(itself
)
63 it
= PyObject_NEW(SndChannelObject
, &SndChannel_Type
);
64 if (it
== NULL
) return NULL
;
65 it
->ob_itself
= itself
;
66 it
->ob_callback
= NULL
;
67 it
->ob_A5
= SetCurrentA5();
68 return (PyObject
*)it
;
70 static SndCh_Convert(v
, p_itself
)
72 SndChannelPtr
*p_itself
;
76 PyErr_SetString(PyExc_TypeError
, "SndChannel required");
79 *p_itself
= ((SndChannelObject
*)v
)->ob_itself
;
83 static void SndCh_dealloc(self
)
84 SndChannelObject
*self
;
86 SndDisposeChannel(self
->ob_itself
, 1);
87 Py_XDECREF(self
->ob_callback
);
91 static PyObject
*SndCh_SndDoCommand(_self
, _args
)
92 SndChannelObject
*_self
;
95 PyObject
*_res
= NULL
;
99 if (!PyArg_ParseTuple(_args
, "O&b",
100 SndCmd_Convert
, &cmd
,
103 _err
= SndDoCommand(_self
->ob_itself
,
106 if (_err
!= noErr
) return PyMac_Error(_err
);
112 static PyObject
*SndCh_SndDoImmediate(_self
, _args
)
113 SndChannelObject
*_self
;
116 PyObject
*_res
= NULL
;
119 if (!PyArg_ParseTuple(_args
, "O&",
120 SndCmd_Convert
, &cmd
))
122 _err
= SndDoImmediate(_self
->ob_itself
,
124 if (_err
!= noErr
) return PyMac_Error(_err
);
130 static PyObject
*SndCh_SndPlay(_self
, _args
)
131 SndChannelObject
*_self
;
134 PyObject
*_res
= NULL
;
136 SndListHandle sndHandle
;
138 if (!PyArg_ParseTuple(_args
, "O&b",
139 ResObj_Convert
, &sndHandle
,
142 _err
= SndPlay(_self
->ob_itself
,
145 if (_err
!= noErr
) return PyMac_Error(_err
);
151 #if !TARGET_API_MAC_CARBON
153 static PyObject
*SndCh_SndStartFilePlay(_self
, _args
)
154 SndChannelObject
*_self
;
157 PyObject
*_res
= NULL
;
163 if (!PyArg_ParseTuple(_args
, "hhlb",
169 _err
= SndStartFilePlay(_self
->ob_itself
,
177 if (_err
!= noErr
) return PyMac_Error(_err
);
184 #if !TARGET_API_MAC_CARBON
186 static PyObject
*SndCh_SndPauseFilePlay(_self
, _args
)
187 SndChannelObject
*_self
;
190 PyObject
*_res
= NULL
;
192 if (!PyArg_ParseTuple(_args
, ""))
194 _err
= SndPauseFilePlay(_self
->ob_itself
);
195 if (_err
!= noErr
) return PyMac_Error(_err
);
202 #if !TARGET_API_MAC_CARBON
204 static PyObject
*SndCh_SndStopFilePlay(_self
, _args
)
205 SndChannelObject
*_self
;
208 PyObject
*_res
= NULL
;
211 if (!PyArg_ParseTuple(_args
, "b",
214 _err
= SndStopFilePlay(_self
->ob_itself
,
216 if (_err
!= noErr
) return PyMac_Error(_err
);
223 static PyObject
*SndCh_SndChannelStatus(_self
, _args
)
224 SndChannelObject
*_self
;
227 PyObject
*_res
= NULL
;
230 SCStatus theStatus__out__
;
231 if (!PyArg_ParseTuple(_args
, "h",
234 _err
= SndChannelStatus(_self
->ob_itself
,
237 if (_err
!= noErr
) return PyMac_Error(_err
);
238 _res
= Py_BuildValue("s#",
239 (char *)&theStatus__out__
, (int)sizeof(SCStatus
));
240 theStatus__error__
: ;
244 static PyObject
*SndCh_SndGetInfo(_self
, _args
)
245 SndChannelObject
*_self
;
248 PyObject
*_res
= NULL
;
252 if (!PyArg_ParseTuple(_args
, "O&w",
253 PyMac_GetOSType
, &selector
,
256 _err
= SndGetInfo(_self
->ob_itself
,
259 if (_err
!= noErr
) return PyMac_Error(_err
);
265 static PyObject
*SndCh_SndSetInfo(_self
, _args
)
266 SndChannelObject
*_self
;
269 PyObject
*_res
= NULL
;
273 if (!PyArg_ParseTuple(_args
, "O&w",
274 PyMac_GetOSType
, &selector
,
277 _err
= SndSetInfo(_self
->ob_itself
,
280 if (_err
!= noErr
) return PyMac_Error(_err
);
286 static PyMethodDef SndCh_methods
[] = {
287 {"SndDoCommand", (PyCFunction
)SndCh_SndDoCommand
, 1,
288 "(SndCommand cmd, Boolean noWait) -> None"},
289 {"SndDoImmediate", (PyCFunction
)SndCh_SndDoImmediate
, 1,
290 "(SndCommand cmd) -> None"},
291 {"SndPlay", (PyCFunction
)SndCh_SndPlay
, 1,
292 "(SndListHandle sndHandle, Boolean async) -> None"},
294 #if !TARGET_API_MAC_CARBON
295 {"SndStartFilePlay", (PyCFunction
)SndCh_SndStartFilePlay
, 1,
296 "(short fRefNum, short resNum, long bufferSize, Boolean async) -> None"},
299 #if !TARGET_API_MAC_CARBON
300 {"SndPauseFilePlay", (PyCFunction
)SndCh_SndPauseFilePlay
, 1,
304 #if !TARGET_API_MAC_CARBON
305 {"SndStopFilePlay", (PyCFunction
)SndCh_SndStopFilePlay
, 1,
306 "(Boolean quietNow) -> None"},
308 {"SndChannelStatus", (PyCFunction
)SndCh_SndChannelStatus
, 1,
309 "(short theLength) -> (SCStatus theStatus)"},
310 {"SndGetInfo", (PyCFunction
)SndCh_SndGetInfo
, 1,
311 "(OSType selector, void * infoPtr) -> None"},
312 {"SndSetInfo", (PyCFunction
)SndCh_SndSetInfo
, 1,
313 "(OSType selector, void * infoPtr) -> None"},
317 static PyMethodChain SndCh_chain
= { SndCh_methods
, NULL
};
319 static PyObject
*SndCh_getattr(self
, name
)
320 SndChannelObject
*self
;
323 return Py_FindMethodInChain(&SndCh_chain
, (PyObject
*)self
, name
);
326 #define SndCh_setattr NULL
328 #define SndCh_compare NULL
330 #define SndCh_repr NULL
332 #define SndCh_hash NULL
334 staticforward PyTypeObject SndChannel_Type
= {
335 PyObject_HEAD_INIT(&PyType_Type
)
337 "SndChannel", /*tp_name*/
338 sizeof(SndChannelObject
), /*tp_basicsize*/
341 (destructor
) SndCh_dealloc
, /*tp_dealloc*/
343 (getattrfunc
) SndCh_getattr
, /*tp_getattr*/
344 (setattrfunc
) SndCh_setattr
, /*tp_setattr*/
345 (cmpfunc
) SndCh_compare
, /*tp_compare*/
346 (reprfunc
) SndCh_repr
, /*tp_repr*/
347 (PyNumberMethods
*)0, /* tp_as_number */
348 (PySequenceMethods
*)0, /* tp_as_sequence */
349 (PyMappingMethods
*)0, /* tp_as_mapping */
350 (hashfunc
) SndCh_hash
, /*tp_hash*/
353 /* ------------------- End object type SndChannel ------------------- */
356 /* ------------------------ Object type SPB ------------------------- */
358 staticforward PyTypeObject SPB_Type
;
360 #define SPBObj_Check(x) ((x)->ob_type == &SPB_Type)
362 typedef struct SPBObject
{
364 /* Members used to implement callbacks: */
365 PyObject
*ob_completion
;
366 PyObject
*ob_interrupt
;
367 PyObject
*ob_thiscallback
;
372 static PyObject
*SPBObj_New()
375 it
= PyObject_NEW(SPBObject
, &SPB_Type
);
376 if (it
== NULL
) return NULL
;
377 it
->ob_completion
= NULL
;
378 it
->ob_interrupt
= NULL
;
379 it
->ob_thiscallback
= NULL
;
380 it
->ob_A5
= SetCurrentA5();
381 memset((char *)&it
->ob_spb
, 0, sizeof(it
->ob_spb
));
382 it
->ob_spb
.userLong
= (long)it
;
383 return (PyObject
*)it
;
385 static SPBObj_Convert(v
, p_itself
)
389 if (!SPBObj_Check(v
))
391 PyErr_SetString(PyExc_TypeError
, "SPB required");
394 *p_itself
= &((SPBObject
*)v
)->ob_spb
;
398 static void SPBObj_dealloc(self
)
401 /* Cleanup of self->ob_itself goes here */
402 self
->ob_spb
.userLong
= 0;
403 self
->ob_thiscallback
= 0;
404 Py_XDECREF(self
->ob_completion
);
405 Py_XDECREF(self
->ob_interrupt
);
409 static PyMethodDef SPBObj_methods
[] = {
413 static PyMethodChain SPBObj_chain
= { SPBObj_methods
, NULL
};
415 static PyObject
*SPBObj_getattr(self
, name
)
420 if (strcmp(name
, "inRefNum") == 0)
421 return Py_BuildValue("l", self
->ob_spb
.inRefNum
);
422 else if (strcmp(name
, "count") == 0)
423 return Py_BuildValue("l", self
->ob_spb
.count
);
424 else if (strcmp(name
, "milliseconds") == 0)
425 return Py_BuildValue("l", self
->ob_spb
.milliseconds
);
426 else if (strcmp(name
, "error") == 0)
427 return Py_BuildValue("h", self
->ob_spb
.error
);
428 return Py_FindMethodInChain(&SPBObj_chain
, (PyObject
*)self
, name
);
431 static int SPBObj_setattr(self
, name
, value
)
439 if (strcmp(name
, "inRefNum") == 0)
440 rv
= PyArg_Parse(value
, "l", &self
->ob_spb
.inRefNum
);
441 else if (strcmp(name
, "count") == 0)
442 rv
= PyArg_Parse(value
, "l", &self
->ob_spb
.count
);
443 else if (strcmp(name
, "milliseconds") == 0)
444 rv
= PyArg_Parse(value
, "l", &self
->ob_spb
.milliseconds
);
445 else if (strcmp(name
, "buffer") == 0)
446 rv
= PyArg_Parse(value
, "w#", &self
->ob_spb
.bufferPtr
, &self
->ob_spb
.bufferLength
);
447 else if (strcmp(name
, "completionRoutine") == 0) {
448 self
->ob_spb
.completionRoutine
= NewSICompletionProc(SPB_completion
);
449 self
->ob_completion
= value
;
452 #if !TARGET_API_MAC_CARBON_NOTYET
453 } else if (strcmp(name
, "interruptRoutine") == 0) {
454 self
->ob_spb
.completionRoutine
= NewSIInterruptProc(SPB_interrupt
);
455 self
->ob_interrupt
= value
;
464 #define SPBObj_compare NULL
466 #define SPBObj_repr NULL
468 #define SPBObj_hash NULL
470 staticforward PyTypeObject SPB_Type
= {
471 PyObject_HEAD_INIT(&PyType_Type
)
474 sizeof(SPBObject
), /*tp_basicsize*/
477 (destructor
) SPBObj_dealloc
, /*tp_dealloc*/
479 (getattrfunc
) SPBObj_getattr
, /*tp_getattr*/
480 (setattrfunc
) SPBObj_setattr
, /*tp_setattr*/
481 (cmpfunc
) SPBObj_compare
, /*tp_compare*/
482 (reprfunc
) SPBObj_repr
, /*tp_repr*/
483 (PyNumberMethods
*)0, /* tp_as_number */
484 (PySequenceMethods
*)0, /* tp_as_sequence */
485 (PyMappingMethods
*)0, /* tp_as_mapping */
486 (hashfunc
) SPBObj_hash
, /*tp_hash*/
489 /* ---------------------- End object type SPB ----------------------- */
492 static PyObject
*Snd_SPB(_self
, _args
)
496 PyObject
*_res
= NULL
;
500 static PyObject
*Snd_SysBeep(_self
, _args
)
504 PyObject
*_res
= NULL
;
506 if (!PyArg_ParseTuple(_args
, "h",
515 static PyObject
*Snd_SndNewChannel(_self
, _args
)
519 PyObject
*_res
= NULL
;
521 SndChannelPtr chan
= 0;
524 PyObject
* userRoutine
;
525 if (!PyArg_ParseTuple(_args
, "hlO",
530 if (userRoutine
!= Py_None
&& !PyCallable_Check(userRoutine
))
532 PyErr_SetString(PyExc_TypeError
, "callback must be callable");
533 goto userRoutine__error__
;
535 _err
= SndNewChannel(&chan
,
538 NewSndCallBackProc(SndCh_UserRoutine
));
539 if (_err
!= noErr
) return PyMac_Error(_err
);
540 _res
= Py_BuildValue("O&",
542 if (_res
!= NULL
&& userRoutine
!= Py_None
)
544 SndChannelObject
*p
= (SndChannelObject
*)_res
;
545 p
->ob_itself
->userInfo
= (long)p
;
546 Py_INCREF(userRoutine
);
547 p
->ob_callback
= userRoutine
;
549 userRoutine__error__
: ;
553 #if !TARGET_API_MAC_CARBON
555 static PyObject
*Snd_SndControl(_self
, _args
)
559 PyObject
*_res
= NULL
;
563 if (!PyArg_ParseTuple(_args
, "h",
566 _err
= SndControl(id
,
568 if (_err
!= noErr
) return PyMac_Error(_err
);
569 _res
= Py_BuildValue("O&",
575 static PyObject
*Snd_SndSoundManagerVersion(_self
, _args
)
579 PyObject
*_res
= NULL
;
581 if (!PyArg_ParseTuple(_args
, ""))
583 _rv
= SndSoundManagerVersion();
584 _res
= Py_BuildValue("O&",
585 PyMac_BuildNumVersion
, _rv
);
589 static PyObject
*Snd_SndManagerStatus(_self
, _args
)
593 PyObject
*_res
= NULL
;
596 SMStatus theStatus__out__
;
597 if (!PyArg_ParseTuple(_args
, "h",
600 _err
= SndManagerStatus(theLength
,
602 if (_err
!= noErr
) return PyMac_Error(_err
);
603 _res
= Py_BuildValue("s#",
604 (char *)&theStatus__out__
, (int)sizeof(SMStatus
));
605 theStatus__error__
: ;
609 static PyObject
*Snd_SndGetSysBeepState(_self
, _args
)
613 PyObject
*_res
= NULL
;
615 if (!PyArg_ParseTuple(_args
, ""))
617 SndGetSysBeepState(&sysBeepState
);
618 _res
= Py_BuildValue("h",
623 static PyObject
*Snd_SndSetSysBeepState(_self
, _args
)
627 PyObject
*_res
= NULL
;
630 if (!PyArg_ParseTuple(_args
, "h",
633 _err
= SndSetSysBeepState(sysBeepState
);
634 if (_err
!= noErr
) return PyMac_Error(_err
);
640 #if !TARGET_API_MAC_CARBON
642 static PyObject
*Snd_MACEVersion(_self
, _args
)
646 PyObject
*_res
= NULL
;
648 if (!PyArg_ParseTuple(_args
, ""))
651 _res
= Py_BuildValue("O&",
652 PyMac_BuildNumVersion
, _rv
);
657 #if !TARGET_API_MAC_CARBON
659 static PyObject
*Snd_Comp3to1(_self
, _args
)
663 PyObject
*_res
= NULL
;
667 int buffer__in_len__
;
668 StateBlock
*state__in__
;
669 StateBlock state__out__
;
671 unsigned long numChannels
;
672 unsigned long whichChannel
;
673 if (!PyArg_ParseTuple(_args
, "s#s#ll",
674 &buffer__in__
, &buffer__in_len__
,
675 (char **)&state__in__
, &state__in_len__
,
679 if ((buffer__out__
= malloc(buffer__in_len__
)) == NULL
)
682 goto buffer__error__
;
684 buffer__len__
= buffer__in_len__
;
685 if (state__in_len__
!= sizeof(StateBlock
))
687 PyErr_SetString(PyExc_TypeError
, "buffer length should be sizeof(StateBlock)");
690 Comp3to1(buffer__in__
, buffer__out__
, (long)buffer__len__
,
691 state__in__
, &state__out__
,
694 _res
= Py_BuildValue("s#s#",
695 buffer__out__
, (int)buffer__len__
,
696 (char *)&state__out__
, (int)sizeof(StateBlock
));
704 #if !TARGET_API_MAC_CARBON
706 static PyObject
*Snd_Exp1to3(_self
, _args
)
710 PyObject
*_res
= NULL
;
714 int buffer__in_len__
;
715 StateBlock
*state__in__
;
716 StateBlock state__out__
;
718 unsigned long numChannels
;
719 unsigned long whichChannel
;
720 if (!PyArg_ParseTuple(_args
, "s#s#ll",
721 &buffer__in__
, &buffer__in_len__
,
722 (char **)&state__in__
, &state__in_len__
,
726 if ((buffer__out__
= malloc(buffer__in_len__
)) == NULL
)
729 goto buffer__error__
;
731 buffer__len__
= buffer__in_len__
;
732 if (state__in_len__
!= sizeof(StateBlock
))
734 PyErr_SetString(PyExc_TypeError
, "buffer length should be sizeof(StateBlock)");
737 Exp1to3(buffer__in__
, buffer__out__
, (long)buffer__len__
,
738 state__in__
, &state__out__
,
741 _res
= Py_BuildValue("s#s#",
742 buffer__out__
, (int)buffer__len__
,
743 (char *)&state__out__
, (int)sizeof(StateBlock
));
751 #if !TARGET_API_MAC_CARBON
753 static PyObject
*Snd_Comp6to1(_self
, _args
)
757 PyObject
*_res
= NULL
;
761 int buffer__in_len__
;
762 StateBlock
*state__in__
;
763 StateBlock state__out__
;
765 unsigned long numChannels
;
766 unsigned long whichChannel
;
767 if (!PyArg_ParseTuple(_args
, "s#s#ll",
768 &buffer__in__
, &buffer__in_len__
,
769 (char **)&state__in__
, &state__in_len__
,
773 if ((buffer__out__
= malloc(buffer__in_len__
)) == NULL
)
776 goto buffer__error__
;
778 buffer__len__
= buffer__in_len__
;
779 if (state__in_len__
!= sizeof(StateBlock
))
781 PyErr_SetString(PyExc_TypeError
, "buffer length should be sizeof(StateBlock)");
784 Comp6to1(buffer__in__
, buffer__out__
, (long)buffer__len__
,
785 state__in__
, &state__out__
,
788 _res
= Py_BuildValue("s#s#",
789 buffer__out__
, (int)buffer__len__
,
790 (char *)&state__out__
, (int)sizeof(StateBlock
));
798 #if !TARGET_API_MAC_CARBON
800 static PyObject
*Snd_Exp1to6(_self
, _args
)
804 PyObject
*_res
= NULL
;
808 int buffer__in_len__
;
809 StateBlock
*state__in__
;
810 StateBlock state__out__
;
812 unsigned long numChannels
;
813 unsigned long whichChannel
;
814 if (!PyArg_ParseTuple(_args
, "s#s#ll",
815 &buffer__in__
, &buffer__in_len__
,
816 (char **)&state__in__
, &state__in_len__
,
820 if ((buffer__out__
= malloc(buffer__in_len__
)) == NULL
)
823 goto buffer__error__
;
825 buffer__len__
= buffer__in_len__
;
826 if (state__in_len__
!= sizeof(StateBlock
))
828 PyErr_SetString(PyExc_TypeError
, "buffer length should be sizeof(StateBlock)");
831 Exp1to6(buffer__in__
, buffer__out__
, (long)buffer__len__
,
832 state__in__
, &state__out__
,
835 _res
= Py_BuildValue("s#s#",
836 buffer__out__
, (int)buffer__len__
,
837 (char *)&state__out__
, (int)sizeof(StateBlock
));
845 static PyObject
*Snd_GetSysBeepVolume(_self
, _args
)
849 PyObject
*_res
= NULL
;
852 if (!PyArg_ParseTuple(_args
, ""))
854 _err
= GetSysBeepVolume(&level
);
855 if (_err
!= noErr
) return PyMac_Error(_err
);
856 _res
= Py_BuildValue("l",
861 static PyObject
*Snd_SetSysBeepVolume(_self
, _args
)
865 PyObject
*_res
= NULL
;
868 if (!PyArg_ParseTuple(_args
, "l",
871 _err
= SetSysBeepVolume(level
);
872 if (_err
!= noErr
) return PyMac_Error(_err
);
878 static PyObject
*Snd_GetDefaultOutputVolume(_self
, _args
)
882 PyObject
*_res
= NULL
;
885 if (!PyArg_ParseTuple(_args
, ""))
887 _err
= GetDefaultOutputVolume(&level
);
888 if (_err
!= noErr
) return PyMac_Error(_err
);
889 _res
= Py_BuildValue("l",
894 static PyObject
*Snd_SetDefaultOutputVolume(_self
, _args
)
898 PyObject
*_res
= NULL
;
901 if (!PyArg_ParseTuple(_args
, "l",
904 _err
= SetDefaultOutputVolume(level
);
905 if (_err
!= noErr
) return PyMac_Error(_err
);
911 static PyObject
*Snd_GetSoundHeaderOffset(_self
, _args
)
915 PyObject
*_res
= NULL
;
917 SndListHandle sndHandle
;
919 if (!PyArg_ParseTuple(_args
, "O&",
920 ResObj_Convert
, &sndHandle
))
922 _err
= GetSoundHeaderOffset(sndHandle
,
924 if (_err
!= noErr
) return PyMac_Error(_err
);
925 _res
= Py_BuildValue("l",
930 static PyObject
*Snd_GetCompressionInfo(_self
, _args
)
934 PyObject
*_res
= NULL
;
940 CompressionInfo cp__out__
;
941 if (!PyArg_ParseTuple(_args
, "hO&hh",
943 PyMac_GetOSType
, &format
,
947 _err
= GetCompressionInfo(compressionID
,
952 if (_err
!= noErr
) return PyMac_Error(_err
);
953 _res
= Py_BuildValue("s#",
954 (char *)&cp__out__
, (int)sizeof(CompressionInfo
));
959 static PyObject
*Snd_SetSoundPreference(_self
, _args
)
963 PyObject
*_res
= NULL
;
968 if (!PyArg_ParseTuple(_args
, "O&O&",
969 PyMac_GetOSType
, &theType
,
970 ResObj_Convert
, &settings
))
972 _err
= SetSoundPreference(theType
,
975 if (_err
!= noErr
) return PyMac_Error(_err
);
976 _res
= Py_BuildValue("O&",
977 PyMac_BuildStr255
, name
);
981 static PyObject
*Snd_GetSoundPreference(_self
, _args
)
985 PyObject
*_res
= NULL
;
990 if (!PyArg_ParseTuple(_args
, "O&O&",
991 PyMac_GetOSType
, &theType
,
992 ResObj_Convert
, &settings
))
994 _err
= GetSoundPreference(theType
,
997 if (_err
!= noErr
) return PyMac_Error(_err
);
998 _res
= Py_BuildValue("O&",
999 PyMac_BuildStr255
, name
);
1003 static PyObject
*Snd_GetCompressionName(_self
, _args
)
1007 PyObject
*_res
= NULL
;
1009 OSType compressionType
;
1010 Str255 compressionName
;
1011 if (!PyArg_ParseTuple(_args
, "O&",
1012 PyMac_GetOSType
, &compressionType
))
1014 _err
= GetCompressionName(compressionType
,
1016 if (_err
!= noErr
) return PyMac_Error(_err
);
1017 _res
= Py_BuildValue("O&",
1018 PyMac_BuildStr255
, compressionName
);
1022 static PyObject
*Snd_SPBVersion(_self
, _args
)
1026 PyObject
*_res
= NULL
;
1028 if (!PyArg_ParseTuple(_args
, ""))
1031 _res
= Py_BuildValue("O&",
1032 PyMac_BuildNumVersion
, _rv
);
1036 static PyObject
*Snd_SPBSignInDevice(_self
, _args
)
1040 PyObject
*_res
= NULL
;
1044 if (!PyArg_ParseTuple(_args
, "hO&",
1046 PyMac_GetStr255
, deviceName
))
1048 _err
= SPBSignInDevice(deviceRefNum
,
1050 if (_err
!= noErr
) return PyMac_Error(_err
);
1056 static PyObject
*Snd_SPBSignOutDevice(_self
, _args
)
1060 PyObject
*_res
= NULL
;
1063 if (!PyArg_ParseTuple(_args
, "h",
1066 _err
= SPBSignOutDevice(deviceRefNum
);
1067 if (_err
!= noErr
) return PyMac_Error(_err
);
1073 static PyObject
*Snd_SPBGetIndexedDevice(_self
, _args
)
1077 PyObject
*_res
= NULL
;
1081 Handle deviceIconHandle
;
1082 if (!PyArg_ParseTuple(_args
, "h",
1085 _err
= SPBGetIndexedDevice(count
,
1088 if (_err
!= noErr
) return PyMac_Error(_err
);
1089 _res
= Py_BuildValue("O&O&",
1090 PyMac_BuildStr255
, deviceName
,
1091 ResObj_New
, deviceIconHandle
);
1095 static PyObject
*Snd_SPBOpenDevice(_self
, _args
)
1099 PyObject
*_res
= NULL
;
1104 if (!PyArg_ParseTuple(_args
, "O&h",
1105 PyMac_GetStr255
, deviceName
,
1108 _err
= SPBOpenDevice(deviceName
,
1111 if (_err
!= noErr
) return PyMac_Error(_err
);
1112 _res
= Py_BuildValue("l",
1117 static PyObject
*Snd_SPBCloseDevice(_self
, _args
)
1121 PyObject
*_res
= NULL
;
1124 if (!PyArg_ParseTuple(_args
, "l",
1127 _err
= SPBCloseDevice(inRefNum
);
1128 if (_err
!= noErr
) return PyMac_Error(_err
);
1134 static PyObject
*Snd_SPBRecord(_self
, _args
)
1138 PyObject
*_res
= NULL
;
1142 if (!PyArg_ParseTuple(_args
, "O&b",
1143 SPBObj_Convert
, &inParamPtr
,
1146 _err
= SPBRecord(inParamPtr
,
1148 if (_err
!= noErr
) return PyMac_Error(_err
);
1154 #if !TARGET_API_MAC_CARBON
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
);
1180 static PyObject
*Snd_SPBPauseRecording(_self
, _args
)
1184 PyObject
*_res
= NULL
;
1187 if (!PyArg_ParseTuple(_args
, "l",
1190 _err
= SPBPauseRecording(inRefNum
);
1191 if (_err
!= noErr
) return PyMac_Error(_err
);
1197 static PyObject
*Snd_SPBResumeRecording(_self
, _args
)
1201 PyObject
*_res
= NULL
;
1204 if (!PyArg_ParseTuple(_args
, "l",
1207 _err
= SPBResumeRecording(inRefNum
);
1208 if (_err
!= noErr
) return PyMac_Error(_err
);
1214 static PyObject
*Snd_SPBStopRecording(_self
, _args
)
1218 PyObject
*_res
= NULL
;
1221 if (!PyArg_ParseTuple(_args
, "l",
1224 _err
= SPBStopRecording(inRefNum
);
1225 if (_err
!= noErr
) return PyMac_Error(_err
);
1231 static PyObject
*Snd_SPBGetRecordingStatus(_self
, _args
)
1235 PyObject
*_res
= NULL
;
1238 short recordingStatus
;
1240 unsigned long totalSamplesToRecord
;
1241 unsigned long numberOfSamplesRecorded
;
1242 unsigned long totalMsecsToRecord
;
1243 unsigned long numberOfMsecsRecorded
;
1244 if (!PyArg_ParseTuple(_args
, "l",
1247 _err
= SPBGetRecordingStatus(inRefNum
,
1250 &totalSamplesToRecord
,
1251 &numberOfSamplesRecorded
,
1252 &totalMsecsToRecord
,
1253 &numberOfMsecsRecorded
);
1254 if (_err
!= noErr
) return PyMac_Error(_err
);
1255 _res
= Py_BuildValue("hhllll",
1258 totalSamplesToRecord
,
1259 numberOfSamplesRecorded
,
1261 numberOfMsecsRecorded
);
1265 static PyObject
*Snd_SPBGetDeviceInfo(_self
, _args
)
1269 PyObject
*_res
= NULL
;
1274 if (!PyArg_ParseTuple(_args
, "lO&w",
1276 PyMac_GetOSType
, &infoType
,
1279 _err
= SPBGetDeviceInfo(inRefNum
,
1282 if (_err
!= noErr
) return PyMac_Error(_err
);
1288 static PyObject
*Snd_SPBSetDeviceInfo(_self
, _args
)
1292 PyObject
*_res
= NULL
;
1297 if (!PyArg_ParseTuple(_args
, "lO&w",
1299 PyMac_GetOSType
, &infoType
,
1302 _err
= SPBSetDeviceInfo(inRefNum
,
1305 if (_err
!= noErr
) return PyMac_Error(_err
);
1311 static PyObject
*Snd_SPBMillisecondsToBytes(_self
, _args
)
1315 PyObject
*_res
= NULL
;
1319 if (!PyArg_ParseTuple(_args
, "l",
1322 _err
= SPBMillisecondsToBytes(inRefNum
,
1324 if (_err
!= noErr
) return PyMac_Error(_err
);
1325 _res
= Py_BuildValue("l",
1330 static PyObject
*Snd_SPBBytesToMilliseconds(_self
, _args
)
1334 PyObject
*_res
= NULL
;
1338 if (!PyArg_ParseTuple(_args
, "l",
1341 _err
= SPBBytesToMilliseconds(inRefNum
,
1343 if (_err
!= noErr
) return PyMac_Error(_err
);
1344 _res
= Py_BuildValue("l",
1349 static PyMethodDef Snd_methods
[] = {
1350 {"SPB", (PyCFunction
)Snd_SPB
, 1,
1352 {"SysBeep", (PyCFunction
)Snd_SysBeep
, 1,
1353 "(short duration) -> None"},
1354 {"SndNewChannel", (PyCFunction
)Snd_SndNewChannel
, 1,
1355 "(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)"},
1357 #if !TARGET_API_MAC_CARBON
1358 {"SndControl", (PyCFunction
)Snd_SndControl
, 1,
1359 "(short id) -> (SndCommand cmd)"},
1361 {"SndSoundManagerVersion", (PyCFunction
)Snd_SndSoundManagerVersion
, 1,
1362 "() -> (NumVersion _rv)"},
1363 {"SndManagerStatus", (PyCFunction
)Snd_SndManagerStatus
, 1,
1364 "(short theLength) -> (SMStatus theStatus)"},
1365 {"SndGetSysBeepState", (PyCFunction
)Snd_SndGetSysBeepState
, 1,
1366 "() -> (short sysBeepState)"},
1367 {"SndSetSysBeepState", (PyCFunction
)Snd_SndSetSysBeepState
, 1,
1368 "(short sysBeepState) -> None"},
1370 #if !TARGET_API_MAC_CARBON
1371 {"MACEVersion", (PyCFunction
)Snd_MACEVersion
, 1,
1372 "() -> (NumVersion _rv)"},
1375 #if !TARGET_API_MAC_CARBON
1376 {"Comp3to1", (PyCFunction
)Snd_Comp3to1
, 1,
1377 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1380 #if !TARGET_API_MAC_CARBON
1381 {"Exp1to3", (PyCFunction
)Snd_Exp1to3
, 1,
1382 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1385 #if !TARGET_API_MAC_CARBON
1386 {"Comp6to1", (PyCFunction
)Snd_Comp6to1
, 1,
1387 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1390 #if !TARGET_API_MAC_CARBON
1391 {"Exp1to6", (PyCFunction
)Snd_Exp1to6
, 1,
1392 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1394 {"GetSysBeepVolume", (PyCFunction
)Snd_GetSysBeepVolume
, 1,
1395 "() -> (long level)"},
1396 {"SetSysBeepVolume", (PyCFunction
)Snd_SetSysBeepVolume
, 1,
1397 "(long level) -> None"},
1398 {"GetDefaultOutputVolume", (PyCFunction
)Snd_GetDefaultOutputVolume
, 1,
1399 "() -> (long level)"},
1400 {"SetDefaultOutputVolume", (PyCFunction
)Snd_SetDefaultOutputVolume
, 1,
1401 "(long level) -> None"},
1402 {"GetSoundHeaderOffset", (PyCFunction
)Snd_GetSoundHeaderOffset
, 1,
1403 "(SndListHandle sndHandle) -> (long offset)"},
1404 {"GetCompressionInfo", (PyCFunction
)Snd_GetCompressionInfo
, 1,
1405 "(short compressionID, OSType format, short numChannels, short sampleSize) -> (CompressionInfo cp)"},
1406 {"SetSoundPreference", (PyCFunction
)Snd_SetSoundPreference
, 1,
1407 "(OSType theType, Handle settings) -> (Str255 name)"},
1408 {"GetSoundPreference", (PyCFunction
)Snd_GetSoundPreference
, 1,
1409 "(OSType theType, Handle settings) -> (Str255 name)"},
1410 {"GetCompressionName", (PyCFunction
)Snd_GetCompressionName
, 1,
1411 "(OSType compressionType) -> (Str255 compressionName)"},
1412 {"SPBVersion", (PyCFunction
)Snd_SPBVersion
, 1,
1413 "() -> (NumVersion _rv)"},
1414 {"SPBSignInDevice", (PyCFunction
)Snd_SPBSignInDevice
, 1,
1415 "(short deviceRefNum, Str255 deviceName) -> None"},
1416 {"SPBSignOutDevice", (PyCFunction
)Snd_SPBSignOutDevice
, 1,
1417 "(short deviceRefNum) -> None"},
1418 {"SPBGetIndexedDevice", (PyCFunction
)Snd_SPBGetIndexedDevice
, 1,
1419 "(short count) -> (Str255 deviceName, Handle deviceIconHandle)"},
1420 {"SPBOpenDevice", (PyCFunction
)Snd_SPBOpenDevice
, 1,
1421 "(Str255 deviceName, short permission) -> (long inRefNum)"},
1422 {"SPBCloseDevice", (PyCFunction
)Snd_SPBCloseDevice
, 1,
1423 "(long inRefNum) -> None"},
1424 {"SPBRecord", (PyCFunction
)Snd_SPBRecord
, 1,
1425 "(SPBPtr inParamPtr, Boolean asynchFlag) -> None"},
1427 #if !TARGET_API_MAC_CARBON
1428 {"SPBRecordToFile", (PyCFunction
)Snd_SPBRecordToFile
, 1,
1429 "(short fRefNum, SPBPtr inParamPtr, Boolean asynchFlag) -> None"},
1431 {"SPBPauseRecording", (PyCFunction
)Snd_SPBPauseRecording
, 1,
1432 "(long inRefNum) -> None"},
1433 {"SPBResumeRecording", (PyCFunction
)Snd_SPBResumeRecording
, 1,
1434 "(long inRefNum) -> None"},
1435 {"SPBStopRecording", (PyCFunction
)Snd_SPBStopRecording
, 1,
1436 "(long inRefNum) -> None"},
1437 {"SPBGetRecordingStatus", (PyCFunction
)Snd_SPBGetRecordingStatus
, 1,
1438 "(long inRefNum) -> (short recordingStatus, short meterLevel, unsigned long totalSamplesToRecord, unsigned long numberOfSamplesRecorded, unsigned long totalMsecsToRecord, unsigned long numberOfMsecsRecorded)"},
1439 {"SPBGetDeviceInfo", (PyCFunction
)Snd_SPBGetDeviceInfo
, 1,
1440 "(long inRefNum, OSType infoType, void * infoData) -> None"},
1441 {"SPBSetDeviceInfo", (PyCFunction
)Snd_SPBSetDeviceInfo
, 1,
1442 "(long inRefNum, OSType infoType, void * infoData) -> None"},
1443 {"SPBMillisecondsToBytes", (PyCFunction
)Snd_SPBMillisecondsToBytes
, 1,
1444 "(long inRefNum) -> (long milliseconds)"},
1445 {"SPBBytesToMilliseconds", (PyCFunction
)Snd_SPBBytesToMilliseconds
, 1,
1446 "(long inRefNum) -> (long byteCount)"},
1452 /* Routine passed to Py_AddPendingCall -- call the Python callback */
1454 SndCh_CallCallBack(arg
)
1457 SndChannelObject
*p
= (SndChannelObject
*)arg
;
1460 args
= Py_BuildValue("(O(hhl))",
1461 p
, p
->ob_cmd
.cmd
, p
->ob_cmd
.param1
, p
->ob_cmd
.param2
);
1462 res
= PyEval_CallObject(p
->ob_callback
, args
);
1470 /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */
1472 SndCh_UserRoutine(SndChannelPtr chan
, SndCommand
*cmd
)
1474 SndChannelObject
*p
= (SndChannelObject
*)(chan
->userInfo
);
1475 if (p
->ob_callback
!= NULL
) {
1476 long A5
= SetA5(p
->ob_A5
);
1478 Py_AddPendingCall(SndCh_CallCallBack
, (void *)p
);
1483 /* SPB callbacks - Schedule callbacks to Python */
1485 SPB_CallCallBack(arg
)
1488 SPBObject
*p
= (SPBObject
*)arg
;
1492 if ( p
->ob_thiscallback
== 0 ) return 0;
1493 args
= Py_BuildValue("(O)", p
);
1494 res
= PyEval_CallObject(p
->ob_thiscallback
, args
);
1495 p
->ob_thiscallback
= 0;
1504 SPB_completion(SPBPtr my_spb
)
1506 SPBObject
*p
= (SPBObject
*)(my_spb
->userLong
);
1508 if (p
&& p
->ob_completion
) {
1509 long A5
= SetA5(p
->ob_A5
);
1510 p
->ob_thiscallback
= p
->ob_completion
; /* Hope we cannot get two at the same time */
1511 Py_AddPendingCall(SPB_CallCallBack
, (void *)p
);
1517 SPB_interrupt(SPBPtr my_spb
)
1519 SPBObject
*p
= (SPBObject
*)(my_spb
->userLong
);
1521 if (p
&& p
->ob_interrupt
) {
1522 long A5
= SetA5(p
->ob_A5
);
1523 p
->ob_thiscallback
= p
->ob_interrupt
; /* Hope we cannot get two at the same time */
1524 Py_AddPendingCall(SPB_CallCallBack
, (void *)p
);
1539 m
= Py_InitModule("Snd", Snd_methods
);
1540 d
= PyModule_GetDict(m
);
1541 Snd_Error
= PyMac_GetOSErrException();
1542 if (Snd_Error
== NULL
||
1543 PyDict_SetItemString(d
, "Error", Snd_Error
) != 0)
1544 Py_FatalError("can't initialize Snd.Error");
1545 SndChannel_Type
.ob_type
= &PyType_Type
;
1546 Py_INCREF(&SndChannel_Type
);
1547 if (PyDict_SetItemString(d
, "SndChannelType", (PyObject
*)&SndChannel_Type
) != 0)
1548 Py_FatalError("can't initialize SndChannelType");
1549 SPB_Type
.ob_type
= &PyType_Type
;
1550 Py_INCREF(&SPB_Type
);
1551 if (PyDict_SetItemString(d
, "SPBType", (PyObject
*)&SPB_Type
) != 0)
1552 Py_FatalError("can't initialize SPBType");
1555 /* ========================= End module Snd ========================= */