2 /* ========================== Module _Snd =========================== */
9 #include "pymactoolbox.h"
11 /* Macro to test whether a weak-loaded CFM function exists */
12 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
13 PyErr_SetString(PyExc_NotImplementedError, \
14 "Not available in this shared library/OS version"); \
19 #include <Carbon/Carbon.h>
21 /* Convert a SndCommand argument */
23 SndCmd_Convert(PyObject
*v
, SndCommand
*pc
)
28 if (PyTuple_Check(v
)) {
29 if (PyArg_ParseTuple(v
, "h|hl", &pc
->cmd
, &pc
->param1
, &pc
->param2
))
32 return PyArg_ParseTuple(v
, "Hhs#", &pc
->cmd
, &pc
->param1
, &pc
->param2
, &len
);
34 return PyArg_Parse(v
, "H", &pc
->cmd
);
37 static pascal void SndCh_UserRoutine(SndChannelPtr chan
, SndCommand
*cmd
); /* Forward */
38 static pascal void SPB_completion(SPBPtr my_spb
); /* Forward */
40 static PyObject
*Snd_Error
;
42 /* --------------------- Object type SndChannel --------------------- */
44 static PyTypeObject SndChannel_Type
;
46 #define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type || PyObject_TypeCheck((x), &SndChannel_Type))
48 typedef struct SndChannelObject
{
50 SndChannelPtr ob_itself
;
51 /* Members used to implement callbacks: */
52 PyObject
*ob_callback
;
57 static PyObject
*SndCh_New(SndChannelPtr itself
)
60 it
= PyObject_NEW(SndChannelObject
, &SndChannel_Type
);
61 if (it
== NULL
) return NULL
;
62 it
->ob_itself
= itself
;
63 it
->ob_callback
= NULL
;
64 it
->ob_A5
= SetCurrentA5();
65 return (PyObject
*)it
;
68 static void SndCh_dealloc(SndChannelObject
*self
)
70 SndDisposeChannel(self
->ob_itself
, 1);
71 Py_XDECREF(self
->ob_callback
);
72 PyObject_Free((PyObject
*)self
);
75 static PyObject
*SndCh_SndDoCommand(SndChannelObject
*_self
, PyObject
*_args
)
77 PyObject
*_res
= NULL
;
81 if (!PyArg_ParseTuple(_args
, "O&b",
85 _err
= SndDoCommand(_self
->ob_itself
,
88 if (_err
!= noErr
) return PyMac_Error(_err
);
94 static PyObject
*SndCh_SndDoImmediate(SndChannelObject
*_self
, PyObject
*_args
)
96 PyObject
*_res
= NULL
;
99 if (!PyArg_ParseTuple(_args
, "O&",
100 SndCmd_Convert
, &cmd
))
102 _err
= SndDoImmediate(_self
->ob_itself
,
104 if (_err
!= noErr
) return PyMac_Error(_err
);
110 static PyObject
*SndCh_SndPlay(SndChannelObject
*_self
, PyObject
*_args
)
112 PyObject
*_res
= NULL
;
114 SndListHandle sndHandle
;
116 if (!PyArg_ParseTuple(_args
, "O&b",
117 ResObj_Convert
, &sndHandle
,
120 _err
= SndPlay(_self
->ob_itself
,
123 if (_err
!= noErr
) return PyMac_Error(_err
);
129 static PyObject
*SndCh_SndChannelStatus(SndChannelObject
*_self
, PyObject
*_args
)
131 PyObject
*_res
= NULL
;
134 SCStatus theStatus__out__
;
135 if (!PyArg_ParseTuple(_args
, "h",
138 _err
= SndChannelStatus(_self
->ob_itself
,
141 if (_err
!= noErr
) return PyMac_Error(_err
);
142 _res
= Py_BuildValue("s#",
143 (char *)&theStatus__out__
, (int)sizeof(SCStatus
));
147 static PyObject
*SndCh_SndGetInfo(SndChannelObject
*_self
, PyObject
*_args
)
149 PyObject
*_res
= NULL
;
153 if (!PyArg_ParseTuple(_args
, "O&w",
154 PyMac_GetOSType
, &selector
,
157 _err
= SndGetInfo(_self
->ob_itself
,
160 if (_err
!= noErr
) return PyMac_Error(_err
);
166 static PyObject
*SndCh_SndSetInfo(SndChannelObject
*_self
, PyObject
*_args
)
168 PyObject
*_res
= NULL
;
172 if (!PyArg_ParseTuple(_args
, "O&w",
173 PyMac_GetOSType
, &selector
,
176 _err
= SndSetInfo(_self
->ob_itself
,
179 if (_err
!= noErr
) return PyMac_Error(_err
);
185 static PyMethodDef SndCh_methods
[] = {
186 {"SndDoCommand", (PyCFunction
)SndCh_SndDoCommand
, 1,
187 PyDoc_STR("(SndCommand cmd, Boolean noWait) -> None")},
188 {"SndDoImmediate", (PyCFunction
)SndCh_SndDoImmediate
, 1,
189 PyDoc_STR("(SndCommand cmd) -> None")},
190 {"SndPlay", (PyCFunction
)SndCh_SndPlay
, 1,
191 PyDoc_STR("(SndListHandle sndHandle, Boolean async) -> None")},
192 {"SndChannelStatus", (PyCFunction
)SndCh_SndChannelStatus
, 1,
193 PyDoc_STR("(short theLength) -> (SCStatus theStatus)")},
194 {"SndGetInfo", (PyCFunction
)SndCh_SndGetInfo
, 1,
195 PyDoc_STR("(OSType selector, void * infoPtr) -> None")},
196 {"SndSetInfo", (PyCFunction
)SndCh_SndSetInfo
, 1,
197 PyDoc_STR("(OSType selector, void * infoPtr) -> None")},
201 #define SndCh_getsetlist NULL
204 #define SndCh_compare NULL
206 #define SndCh_repr NULL
208 #define SndCh_hash NULL
210 static PyTypeObject SndChannel_Type
= {
211 PyObject_HEAD_INIT(NULL
)
213 "_Snd.SndChannel", /*tp_name*/
214 sizeof(SndChannelObject
), /*tp_basicsize*/
217 (destructor
) SndCh_dealloc
, /*tp_dealloc*/
219 (getattrfunc
)0, /*tp_getattr*/
220 (setattrfunc
)0, /*tp_setattr*/
221 (cmpfunc
) SndCh_compare
, /*tp_compare*/
222 (reprfunc
) SndCh_repr
, /*tp_repr*/
223 (PyNumberMethods
*)0, /* tp_as_number */
224 (PySequenceMethods
*)0, /* tp_as_sequence */
225 (PyMappingMethods
*)0, /* tp_as_mapping */
226 (hashfunc
) SndCh_hash
, /*tp_hash*/
229 PyObject_GenericGetAttr
, /*tp_getattro*/
230 PyObject_GenericSetAttr
, /*tp_setattro */
232 Py_TPFLAGS_DEFAULT
, /* tp_flags */
236 0, /*tp_richcompare*/
237 0, /*tp_weaklistoffset*/
240 SndCh_methods
, /* tp_methods */
242 SndCh_getsetlist
, /*tp_getset*/
254 /* ------------------- End object type SndChannel ------------------- */
257 /* ------------------------ Object type SPB ------------------------- */
259 static PyTypeObject SPB_Type
;
261 #define SPBObj_Check(x) ((x)->ob_type == &SPB_Type || PyObject_TypeCheck((x), &SPB_Type))
263 typedef struct SPBObject
{
265 /* Members used to implement callbacks: */
266 PyObject
*ob_completion
;
267 PyObject
*ob_interrupt
;
268 PyObject
*ob_thiscallback
;
273 static PyObject
*SPBObj_New(void)
276 it
= PyObject_NEW(SPBObject
, &SPB_Type
);
277 if (it
== NULL
) return NULL
;
278 it
->ob_completion
= NULL
;
279 it
->ob_interrupt
= NULL
;
280 it
->ob_thiscallback
= NULL
;
281 it
->ob_A5
= SetCurrentA5();
282 memset((char *)&it
->ob_spb
, 0, sizeof(it
->ob_spb
));
283 it
->ob_spb
.userLong
= (long)it
;
284 return (PyObject
*)it
;
286 static int SPBObj_Convert(PyObject
*v
, SPBPtr
*p_itself
)
288 if (!SPBObj_Check(v
))
290 PyErr_SetString(PyExc_TypeError
, "SPB required");
293 *p_itself
= &((SPBObject
*)v
)->ob_spb
;
297 static void SPBObj_dealloc(SPBObject
*self
)
299 /* Cleanup of self->ob_itself goes here */
300 self
->ob_spb
.userLong
= 0;
301 self
->ob_thiscallback
= 0;
302 Py_XDECREF(self
->ob_completion
);
303 Py_XDECREF(self
->ob_interrupt
);
304 PyObject_Free((PyObject
*)self
);
307 static PyMethodDef SPBObj_methods
[] = {
311 static PyObject
*SPBObj_get_inRefNum(SPBObject
*self
, void *closure
)
313 return Py_BuildValue("l", self
->ob_spb
.inRefNum
);
316 static int SPBObj_set_inRefNum(SPBObject
*self
, PyObject
*v
, void *closure
)
318 return -1 + PyArg_Parse(v
, "l", &self
->ob_spb
.inRefNum
);
322 static PyObject
*SPBObj_get_count(SPBObject
*self
, void *closure
)
324 return Py_BuildValue("l", self
->ob_spb
.count
);
327 static int SPBObj_set_count(SPBObject
*self
, PyObject
*v
, void *closure
)
329 return -1 + PyArg_Parse(v
, "l", &self
->ob_spb
.count
);
333 static PyObject
*SPBObj_get_milliseconds(SPBObject
*self
, void *closure
)
335 return Py_BuildValue("l", self
->ob_spb
.milliseconds
);
338 static int SPBObj_set_milliseconds(SPBObject
*self
, PyObject
*v
, void *closure
)
340 return -1 + PyArg_Parse(v
, "l", &self
->ob_spb
.milliseconds
);
344 static PyObject
*SPBObj_get_error(SPBObject
*self
, void *closure
)
346 return Py_BuildValue("h", self
->ob_spb
.error
);
349 #define SPBObj_set_error NULL
351 #define SPBObj_get_completionRoutine NULL
353 static int SPBObj_set_completionRoutine(SPBObject
*self
, PyObject
*v
, void *closure
)
355 self
->ob_spb
.completionRoutine
= NewSICompletionUPP(SPB_completion
);
356 self
->ob_completion
= v
;
362 static PyGetSetDef SPBObj_getsetlist
[] = {
363 {"inRefNum", (getter
)SPBObj_get_inRefNum
, (setter
)SPBObj_set_inRefNum
, NULL
},
364 {"count", (getter
)SPBObj_get_count
, (setter
)SPBObj_set_count
, NULL
},
365 {"milliseconds", (getter
)SPBObj_get_milliseconds
, (setter
)SPBObj_set_milliseconds
, NULL
},
366 {"error", (getter
)SPBObj_get_error
, (setter
)SPBObj_set_error
, NULL
},
367 {"completionRoutine", (getter
)SPBObj_get_completionRoutine
, (setter
)SPBObj_set_completionRoutine
, NULL
},
368 {NULL
, NULL
, NULL
, NULL
},
372 #define SPBObj_compare NULL
374 #define SPBObj_repr NULL
376 #define SPBObj_hash NULL
378 static PyTypeObject SPB_Type
= {
379 PyObject_HEAD_INIT(NULL
)
381 "_Snd.SPB", /*tp_name*/
382 sizeof(SPBObject
), /*tp_basicsize*/
385 (destructor
) SPBObj_dealloc
, /*tp_dealloc*/
387 (getattrfunc
)0, /*tp_getattr*/
388 (setattrfunc
)0, /*tp_setattr*/
389 (cmpfunc
) SPBObj_compare
, /*tp_compare*/
390 (reprfunc
) SPBObj_repr
, /*tp_repr*/
391 (PyNumberMethods
*)0, /* tp_as_number */
392 (PySequenceMethods
*)0, /* tp_as_sequence */
393 (PyMappingMethods
*)0, /* tp_as_mapping */
394 (hashfunc
) SPBObj_hash
, /*tp_hash*/
397 PyObject_GenericGetAttr
, /*tp_getattro*/
398 PyObject_GenericSetAttr
, /*tp_setattro */
400 Py_TPFLAGS_DEFAULT
, /* tp_flags */
404 0, /*tp_richcompare*/
405 0, /*tp_weaklistoffset*/
408 SPBObj_methods
, /* tp_methods */
410 SPBObj_getsetlist
, /*tp_getset*/
422 /* ---------------------- End object type SPB ----------------------- */
425 static PyObject
*Snd_SPB(PyObject
*_self
, PyObject
*_args
)
427 PyObject
*_res
= NULL
;
428 _res
= SPBObj_New(); return _res
;
431 static PyObject
*Snd_SysBeep(PyObject
*_self
, PyObject
*_args
)
433 PyObject
*_res
= NULL
;
435 if (!PyArg_ParseTuple(_args
, "h",
444 static PyObject
*Snd_SndNewChannel(PyObject
*_self
, PyObject
*_args
)
446 PyObject
*_res
= NULL
;
448 SndChannelPtr chan
= 0;
451 PyObject
* userRoutine
;
452 if (!PyArg_ParseTuple(_args
, "hlO",
457 if (userRoutine
!= Py_None
&& !PyCallable_Check(userRoutine
))
459 PyErr_SetString(PyExc_TypeError
, "callback must be callable");
460 goto userRoutine__error__
;
462 _err
= SndNewChannel(&chan
,
465 NewSndCallBackUPP(SndCh_UserRoutine
));
466 if (_err
!= noErr
) return PyMac_Error(_err
);
467 _res
= Py_BuildValue("O&",
469 if (_res
!= NULL
&& userRoutine
!= Py_None
)
471 SndChannelObject
*p
= (SndChannelObject
*)_res
;
472 p
->ob_itself
->userInfo
= (long)p
;
473 Py_INCREF(userRoutine
);
474 p
->ob_callback
= userRoutine
;
476 userRoutine__error__
: ;
480 static PyObject
*Snd_SndSoundManagerVersion(PyObject
*_self
, PyObject
*_args
)
482 PyObject
*_res
= NULL
;
484 if (!PyArg_ParseTuple(_args
, ""))
486 _rv
= SndSoundManagerVersion();
487 _res
= Py_BuildValue("O&",
488 PyMac_BuildNumVersion
, _rv
);
492 static PyObject
*Snd_SndManagerStatus(PyObject
*_self
, PyObject
*_args
)
494 PyObject
*_res
= NULL
;
497 SMStatus theStatus__out__
;
498 if (!PyArg_ParseTuple(_args
, "h",
501 _err
= SndManagerStatus(theLength
,
503 if (_err
!= noErr
) return PyMac_Error(_err
);
504 _res
= Py_BuildValue("s#",
505 (char *)&theStatus__out__
, (int)sizeof(SMStatus
));
509 static PyObject
*Snd_SndGetSysBeepState(PyObject
*_self
, PyObject
*_args
)
511 PyObject
*_res
= NULL
;
513 if (!PyArg_ParseTuple(_args
, ""))
515 SndGetSysBeepState(&sysBeepState
);
516 _res
= Py_BuildValue("h",
521 static PyObject
*Snd_SndSetSysBeepState(PyObject
*_self
, PyObject
*_args
)
523 PyObject
*_res
= NULL
;
526 if (!PyArg_ParseTuple(_args
, "h",
529 _err
= SndSetSysBeepState(sysBeepState
);
530 if (_err
!= noErr
) return PyMac_Error(_err
);
536 static PyObject
*Snd_GetSysBeepVolume(PyObject
*_self
, PyObject
*_args
)
538 PyObject
*_res
= NULL
;
541 if (!PyArg_ParseTuple(_args
, ""))
543 _err
= GetSysBeepVolume(&level
);
544 if (_err
!= noErr
) return PyMac_Error(_err
);
545 _res
= Py_BuildValue("l",
550 static PyObject
*Snd_SetSysBeepVolume(PyObject
*_self
, PyObject
*_args
)
552 PyObject
*_res
= NULL
;
555 if (!PyArg_ParseTuple(_args
, "l",
558 _err
= SetSysBeepVolume(level
);
559 if (_err
!= noErr
) return PyMac_Error(_err
);
565 static PyObject
*Snd_GetDefaultOutputVolume(PyObject
*_self
, PyObject
*_args
)
567 PyObject
*_res
= NULL
;
570 if (!PyArg_ParseTuple(_args
, ""))
572 _err
= GetDefaultOutputVolume(&level
);
573 if (_err
!= noErr
) return PyMac_Error(_err
);
574 _res
= Py_BuildValue("l",
579 static PyObject
*Snd_SetDefaultOutputVolume(PyObject
*_self
, PyObject
*_args
)
581 PyObject
*_res
= NULL
;
584 if (!PyArg_ParseTuple(_args
, "l",
587 _err
= SetDefaultOutputVolume(level
);
588 if (_err
!= noErr
) return PyMac_Error(_err
);
594 static PyObject
*Snd_GetSoundHeaderOffset(PyObject
*_self
, PyObject
*_args
)
596 PyObject
*_res
= NULL
;
598 SndListHandle sndHandle
;
600 if (!PyArg_ParseTuple(_args
, "O&",
601 ResObj_Convert
, &sndHandle
))
603 _err
= GetSoundHeaderOffset(sndHandle
,
605 if (_err
!= noErr
) return PyMac_Error(_err
);
606 _res
= Py_BuildValue("l",
611 static PyObject
*Snd_GetCompressionInfo(PyObject
*_self
, PyObject
*_args
)
613 PyObject
*_res
= NULL
;
619 CompressionInfo cp__out__
;
620 if (!PyArg_ParseTuple(_args
, "hO&hh",
622 PyMac_GetOSType
, &format
,
626 _err
= GetCompressionInfo(compressionID
,
631 if (_err
!= noErr
) return PyMac_Error(_err
);
632 _res
= Py_BuildValue("s#",
633 (char *)&cp__out__
, (int)sizeof(CompressionInfo
));
637 static PyObject
*Snd_SetSoundPreference(PyObject
*_self
, PyObject
*_args
)
639 PyObject
*_res
= NULL
;
644 if (!PyArg_ParseTuple(_args
, "O&O&",
645 PyMac_GetOSType
, &theType
,
646 ResObj_Convert
, &settings
))
648 _err
= SetSoundPreference(theType
,
651 if (_err
!= noErr
) return PyMac_Error(_err
);
652 _res
= Py_BuildValue("O&",
653 PyMac_BuildStr255
, name
);
657 static PyObject
*Snd_GetSoundPreference(PyObject
*_self
, PyObject
*_args
)
659 PyObject
*_res
= NULL
;
664 if (!PyArg_ParseTuple(_args
, "O&O&",
665 PyMac_GetOSType
, &theType
,
666 ResObj_Convert
, &settings
))
668 _err
= GetSoundPreference(theType
,
671 if (_err
!= noErr
) return PyMac_Error(_err
);
672 _res
= Py_BuildValue("O&",
673 PyMac_BuildStr255
, name
);
677 static PyObject
*Snd_GetCompressionName(PyObject
*_self
, PyObject
*_args
)
679 PyObject
*_res
= NULL
;
681 OSType compressionType
;
682 Str255 compressionName
;
683 if (!PyArg_ParseTuple(_args
, "O&",
684 PyMac_GetOSType
, &compressionType
))
686 _err
= GetCompressionName(compressionType
,
688 if (_err
!= noErr
) return PyMac_Error(_err
);
689 _res
= Py_BuildValue("O&",
690 PyMac_BuildStr255
, compressionName
);
694 static PyObject
*Snd_SPBVersion(PyObject
*_self
, PyObject
*_args
)
696 PyObject
*_res
= NULL
;
698 if (!PyArg_ParseTuple(_args
, ""))
701 _res
= Py_BuildValue("O&",
702 PyMac_BuildNumVersion
, _rv
);
706 static PyObject
*Snd_SndRecord(PyObject
*_self
, PyObject
*_args
)
708 PyObject
*_res
= NULL
;
712 SndListHandle sndHandle
;
713 if (!PyArg_ParseTuple(_args
, "O&O&",
714 PyMac_GetPoint
, &corner
,
715 PyMac_GetOSType
, &quality
))
717 _err
= SndRecord((ModalFilterUPP
)0,
721 if (_err
!= noErr
) return PyMac_Error(_err
);
722 _res
= Py_BuildValue("O&",
723 ResObj_New
, sndHandle
);
727 static PyObject
*Snd_SPBSignInDevice(PyObject
*_self
, PyObject
*_args
)
729 PyObject
*_res
= NULL
;
733 if (!PyArg_ParseTuple(_args
, "hO&",
735 PyMac_GetStr255
, deviceName
))
737 _err
= SPBSignInDevice(deviceRefNum
,
739 if (_err
!= noErr
) return PyMac_Error(_err
);
745 static PyObject
*Snd_SPBSignOutDevice(PyObject
*_self
, PyObject
*_args
)
747 PyObject
*_res
= NULL
;
750 if (!PyArg_ParseTuple(_args
, "h",
753 _err
= SPBSignOutDevice(deviceRefNum
);
754 if (_err
!= noErr
) return PyMac_Error(_err
);
760 static PyObject
*Snd_SPBGetIndexedDevice(PyObject
*_self
, PyObject
*_args
)
762 PyObject
*_res
= NULL
;
766 Handle deviceIconHandle
;
767 if (!PyArg_ParseTuple(_args
, "h",
770 _err
= SPBGetIndexedDevice(count
,
773 if (_err
!= noErr
) return PyMac_Error(_err
);
774 _res
= Py_BuildValue("O&O&",
775 PyMac_BuildStr255
, deviceName
,
776 ResObj_New
, deviceIconHandle
);
780 static PyObject
*Snd_SPBOpenDevice(PyObject
*_self
, PyObject
*_args
)
782 PyObject
*_res
= NULL
;
787 if (!PyArg_ParseTuple(_args
, "O&h",
788 PyMac_GetStr255
, deviceName
,
791 _err
= SPBOpenDevice(deviceName
,
794 if (_err
!= noErr
) return PyMac_Error(_err
);
795 _res
= Py_BuildValue("l",
800 static PyObject
*Snd_SPBCloseDevice(PyObject
*_self
, PyObject
*_args
)
802 PyObject
*_res
= NULL
;
805 if (!PyArg_ParseTuple(_args
, "l",
808 _err
= SPBCloseDevice(inRefNum
);
809 if (_err
!= noErr
) return PyMac_Error(_err
);
815 static PyObject
*Snd_SPBRecord(PyObject
*_self
, PyObject
*_args
)
817 PyObject
*_res
= NULL
;
821 if (!PyArg_ParseTuple(_args
, "O&b",
822 SPBObj_Convert
, &inParamPtr
,
825 _err
= SPBRecord(inParamPtr
,
827 if (_err
!= noErr
) return PyMac_Error(_err
);
833 static PyObject
*Snd_SPBPauseRecording(PyObject
*_self
, PyObject
*_args
)
835 PyObject
*_res
= NULL
;
838 if (!PyArg_ParseTuple(_args
, "l",
841 _err
= SPBPauseRecording(inRefNum
);
842 if (_err
!= noErr
) return PyMac_Error(_err
);
848 static PyObject
*Snd_SPBResumeRecording(PyObject
*_self
, PyObject
*_args
)
850 PyObject
*_res
= NULL
;
853 if (!PyArg_ParseTuple(_args
, "l",
856 _err
= SPBResumeRecording(inRefNum
);
857 if (_err
!= noErr
) return PyMac_Error(_err
);
863 static PyObject
*Snd_SPBStopRecording(PyObject
*_self
, PyObject
*_args
)
865 PyObject
*_res
= NULL
;
868 if (!PyArg_ParseTuple(_args
, "l",
871 _err
= SPBStopRecording(inRefNum
);
872 if (_err
!= noErr
) return PyMac_Error(_err
);
878 static PyObject
*Snd_SPBGetRecordingStatus(PyObject
*_self
, PyObject
*_args
)
880 PyObject
*_res
= NULL
;
883 short recordingStatus
;
885 unsigned long totalSamplesToRecord
;
886 unsigned long numberOfSamplesRecorded
;
887 unsigned long totalMsecsToRecord
;
888 unsigned long numberOfMsecsRecorded
;
889 if (!PyArg_ParseTuple(_args
, "l",
892 _err
= SPBGetRecordingStatus(inRefNum
,
895 &totalSamplesToRecord
,
896 &numberOfSamplesRecorded
,
898 &numberOfMsecsRecorded
);
899 if (_err
!= noErr
) return PyMac_Error(_err
);
900 _res
= Py_BuildValue("hhllll",
903 totalSamplesToRecord
,
904 numberOfSamplesRecorded
,
906 numberOfMsecsRecorded
);
910 static PyObject
*Snd_SPBGetDeviceInfo(PyObject
*_self
, PyObject
*_args
)
912 PyObject
*_res
= NULL
;
917 if (!PyArg_ParseTuple(_args
, "lO&w",
919 PyMac_GetOSType
, &infoType
,
922 _err
= SPBGetDeviceInfo(inRefNum
,
925 if (_err
!= noErr
) return PyMac_Error(_err
);
931 static PyObject
*Snd_SPBSetDeviceInfo(PyObject
*_self
, PyObject
*_args
)
933 PyObject
*_res
= NULL
;
938 if (!PyArg_ParseTuple(_args
, "lO&w",
940 PyMac_GetOSType
, &infoType
,
943 _err
= SPBSetDeviceInfo(inRefNum
,
946 if (_err
!= noErr
) return PyMac_Error(_err
);
952 static PyObject
*Snd_SPBMillisecondsToBytes(PyObject
*_self
, PyObject
*_args
)
954 PyObject
*_res
= NULL
;
958 if (!PyArg_ParseTuple(_args
, "l",
961 _err
= SPBMillisecondsToBytes(inRefNum
,
963 if (_err
!= noErr
) return PyMac_Error(_err
);
964 _res
= Py_BuildValue("l",
969 static PyObject
*Snd_SPBBytesToMilliseconds(PyObject
*_self
, PyObject
*_args
)
971 PyObject
*_res
= NULL
;
975 if (!PyArg_ParseTuple(_args
, "l",
978 _err
= SPBBytesToMilliseconds(inRefNum
,
980 if (_err
!= noErr
) return PyMac_Error(_err
);
981 _res
= Py_BuildValue("l",
985 #endif /* __LP64__ */
987 static PyMethodDef Snd_methods
[] = {
989 {"SPB", (PyCFunction
)Snd_SPB
, 1,
991 {"SysBeep", (PyCFunction
)Snd_SysBeep
, 1,
992 PyDoc_STR("(short duration) -> None")},
993 {"SndNewChannel", (PyCFunction
)Snd_SndNewChannel
, 1,
994 PyDoc_STR("(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)")},
995 {"SndSoundManagerVersion", (PyCFunction
)Snd_SndSoundManagerVersion
, 1,
996 PyDoc_STR("() -> (NumVersion _rv)")},
997 {"SndManagerStatus", (PyCFunction
)Snd_SndManagerStatus
, 1,
998 PyDoc_STR("(short theLength) -> (SMStatus theStatus)")},
999 {"SndGetSysBeepState", (PyCFunction
)Snd_SndGetSysBeepState
, 1,
1000 PyDoc_STR("() -> (short sysBeepState)")},
1001 {"SndSetSysBeepState", (PyCFunction
)Snd_SndSetSysBeepState
, 1,
1002 PyDoc_STR("(short sysBeepState) -> None")},
1003 {"GetSysBeepVolume", (PyCFunction
)Snd_GetSysBeepVolume
, 1,
1004 PyDoc_STR("() -> (long level)")},
1005 {"SetSysBeepVolume", (PyCFunction
)Snd_SetSysBeepVolume
, 1,
1006 PyDoc_STR("(long level) -> None")},
1007 {"GetDefaultOutputVolume", (PyCFunction
)Snd_GetDefaultOutputVolume
, 1,
1008 PyDoc_STR("() -> (long level)")},
1009 {"SetDefaultOutputVolume", (PyCFunction
)Snd_SetDefaultOutputVolume
, 1,
1010 PyDoc_STR("(long level) -> None")},
1011 {"GetSoundHeaderOffset", (PyCFunction
)Snd_GetSoundHeaderOffset
, 1,
1012 PyDoc_STR("(SndListHandle sndHandle) -> (long offset)")},
1013 {"GetCompressionInfo", (PyCFunction
)Snd_GetCompressionInfo
, 1,
1014 PyDoc_STR("(short compressionID, OSType format, short numChannels, short sampleSize) -> (CompressionInfo cp)")},
1015 {"SetSoundPreference", (PyCFunction
)Snd_SetSoundPreference
, 1,
1016 PyDoc_STR("(OSType theType, Handle settings) -> (Str255 name)")},
1017 {"GetSoundPreference", (PyCFunction
)Snd_GetSoundPreference
, 1,
1018 PyDoc_STR("(OSType theType, Handle settings) -> (Str255 name)")},
1019 {"GetCompressionName", (PyCFunction
)Snd_GetCompressionName
, 1,
1020 PyDoc_STR("(OSType compressionType) -> (Str255 compressionName)")},
1021 {"SPBVersion", (PyCFunction
)Snd_SPBVersion
, 1,
1022 PyDoc_STR("() -> (NumVersion _rv)")},
1023 {"SndRecord", (PyCFunction
)Snd_SndRecord
, 1,
1024 PyDoc_STR("(Point corner, OSType quality) -> (SndListHandle sndHandle)")},
1025 {"SPBSignInDevice", (PyCFunction
)Snd_SPBSignInDevice
, 1,
1026 PyDoc_STR("(short deviceRefNum, Str255 deviceName) -> None")},
1027 {"SPBSignOutDevice", (PyCFunction
)Snd_SPBSignOutDevice
, 1,
1028 PyDoc_STR("(short deviceRefNum) -> None")},
1029 {"SPBGetIndexedDevice", (PyCFunction
)Snd_SPBGetIndexedDevice
, 1,
1030 PyDoc_STR("(short count) -> (Str255 deviceName, Handle deviceIconHandle)")},
1031 {"SPBOpenDevice", (PyCFunction
)Snd_SPBOpenDevice
, 1,
1032 PyDoc_STR("(Str255 deviceName, short permission) -> (long inRefNum)")},
1033 {"SPBCloseDevice", (PyCFunction
)Snd_SPBCloseDevice
, 1,
1034 PyDoc_STR("(long inRefNum) -> None")},
1035 {"SPBRecord", (PyCFunction
)Snd_SPBRecord
, 1,
1036 PyDoc_STR("(SPBPtr inParamPtr, Boolean asynchFlag) -> None")},
1037 {"SPBPauseRecording", (PyCFunction
)Snd_SPBPauseRecording
, 1,
1038 PyDoc_STR("(long inRefNum) -> None")},
1039 {"SPBResumeRecording", (PyCFunction
)Snd_SPBResumeRecording
, 1,
1040 PyDoc_STR("(long inRefNum) -> None")},
1041 {"SPBStopRecording", (PyCFunction
)Snd_SPBStopRecording
, 1,
1042 PyDoc_STR("(long inRefNum) -> None")},
1043 {"SPBGetRecordingStatus", (PyCFunction
)Snd_SPBGetRecordingStatus
, 1,
1044 PyDoc_STR("(long inRefNum) -> (short recordingStatus, short meterLevel, unsigned long totalSamplesToRecord, unsigned long numberOfSamplesRecorded, unsigned long totalMsecsToRecord, unsigned long numberOfMsecsRecorded)")},
1045 {"SPBGetDeviceInfo", (PyCFunction
)Snd_SPBGetDeviceInfo
, 1,
1046 PyDoc_STR("(long inRefNum, OSType infoType, void * infoData) -> None")},
1047 {"SPBSetDeviceInfo", (PyCFunction
)Snd_SPBSetDeviceInfo
, 1,
1048 PyDoc_STR("(long inRefNum, OSType infoType, void * infoData) -> None")},
1049 {"SPBMillisecondsToBytes", (PyCFunction
)Snd_SPBMillisecondsToBytes
, 1,
1050 PyDoc_STR("(long inRefNum) -> (long milliseconds)")},
1051 {"SPBBytesToMilliseconds", (PyCFunction
)Snd_SPBBytesToMilliseconds
, 1,
1052 PyDoc_STR("(long inRefNum) -> (long byteCount)")},
1053 #endif /* __LP64__ */
1060 /* Routine passed to Py_AddPendingCall -- call the Python callback */
1062 SndCh_CallCallBack(void *arg
)
1064 SndChannelObject
*p
= (SndChannelObject
*)arg
;
1067 args
= Py_BuildValue("(O(hhl))",
1068 p
, p
->ob_cmd
.cmd
, p
->ob_cmd
.param1
, p
->ob_cmd
.param2
);
1069 res
= PyEval_CallObject(p
->ob_callback
, args
);
1077 /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */
1079 SndCh_UserRoutine(SndChannelPtr chan
, SndCommand
*cmd
)
1081 SndChannelObject
*p
= (SndChannelObject
*)(chan
->userInfo
);
1082 if (p
->ob_callback
!= NULL
) {
1083 long A5
= SetA5(p
->ob_A5
);
1085 Py_AddPendingCall(SndCh_CallCallBack
, (void *)p
);
1090 /* SPB callbacks - Schedule callbacks to Python */
1092 SPB_CallCallBack(void *arg
)
1094 SPBObject
*p
= (SPBObject
*)arg
;
1098 if ( p
->ob_thiscallback
== 0 ) return 0;
1099 args
= Py_BuildValue("(O)", p
);
1100 res
= PyEval_CallObject(p
->ob_thiscallback
, args
);
1101 p
->ob_thiscallback
= 0;
1110 SPB_completion(SPBPtr my_spb
)
1112 SPBObject
*p
= (SPBObject
*)(my_spb
->userLong
);
1114 if (p
&& p
->ob_completion
) {
1115 long A5
= SetA5(p
->ob_A5
);
1116 p
->ob_thiscallback
= p
->ob_completion
; /* Hope we cannot get two at the same time */
1117 Py_AddPendingCall(SPB_CallCallBack
, (void *)p
);
1121 #endif /* __LP64__ */
1130 #endif /* __LP64__ */
1136 m
= Py_InitModule("_Snd", Snd_methods
);
1138 d
= PyModule_GetDict(m
);
1139 Snd_Error
= PyMac_GetOSErrException();
1140 if (Snd_Error
== NULL
||
1141 PyDict_SetItemString(d
, "Error", Snd_Error
) != 0)
1143 SndChannel_Type
.ob_type
= &PyType_Type
;
1144 if (PyType_Ready(&SndChannel_Type
) < 0) return;
1145 Py_INCREF(&SndChannel_Type
);
1146 PyModule_AddObject(m
, "SndChannel", (PyObject
*)&SndChannel_Type
);
1147 /* Backward-compatible name */
1148 Py_INCREF(&SndChannel_Type
);
1149 PyModule_AddObject(m
, "SndChannelType", (PyObject
*)&SndChannel_Type
);
1150 SPB_Type
.ob_type
= &PyType_Type
;
1151 if (PyType_Ready(&SPB_Type
) < 0) return;
1152 Py_INCREF(&SPB_Type
);
1154 PyModule_AddObject(m
, "SPB", (PyObject
*)&SPB_Type
);
1156 /* Backward-compatible name */
1157 Py_INCREF(&SPB_Type
);
1158 PyModule_AddObject(m
, "SPBType", (PyObject
*)&SPB_Type
);
1159 #endif /* __LP64__ */
1162 /* ======================== End module _Snd ========================= */