2 /* =========================== Module Snd =========================== */
9 #include "pymactoolbox.h"
11 #ifdef WITHOUT_FRAMEWORKS
13 #include <OSUtils.h> /* for Set(Current)A5 */
15 #include <Carbon/Carbon.h>
19 /* Create a SndCommand object (an (int, int, int) tuple) */
21 SndCmd_New(SndCommand
*pc
)
23 return Py_BuildValue("hhl", pc
->cmd
, pc
->param1
, pc
->param2
);
26 /* Convert a SndCommand argument */
28 SndCmd_Convert(PyObject
*v
, SndCommand
*pc
)
33 if (PyTuple_Check(v
)) {
34 if (PyArg_ParseTuple(v
, "h|hl", &pc
->cmd
, &pc
->param1
, &pc
->param2
))
37 return PyArg_ParseTuple(v
, "Hhs#", &pc
->cmd
, &pc
->param1
, &pc
->param2
, &len
);
39 return PyArg_Parse(v
, "H", &pc
->cmd
);
42 static pascal void SndCh_UserRoutine(SndChannelPtr chan
, SndCommand
*cmd
); /* Forward */
43 static pascal void SPB_completion(SPBPtr my_spb
); /* Forward */
44 #if !TARGET_API_MAC_CARBON
45 static pascal void SPB_interrupt(SPBPtr my_spb
); /* Forward */
48 static PyObject
*Snd_Error
;
50 /* --------------------- Object type SndChannel --------------------- */
52 staticforward PyTypeObject SndChannel_Type
;
54 #define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type)
56 typedef struct SndChannelObject
{
58 SndChannelPtr ob_itself
;
59 /* Members used to implement callbacks: */
60 PyObject
*ob_callback
;
65 static PyObject
*SndCh_New(SndChannelPtr itself
)
68 it
= PyObject_NEW(SndChannelObject
, &SndChannel_Type
);
69 if (it
== NULL
) return NULL
;
70 it
->ob_itself
= itself
;
71 it
->ob_callback
= NULL
;
72 it
->ob_A5
= SetCurrentA5();
73 return (PyObject
*)it
;
75 static SndCh_Convert(PyObject
*v
, SndChannelPtr
*p_itself
)
79 PyErr_SetString(PyExc_TypeError
, "SndChannel required");
82 *p_itself
= ((SndChannelObject
*)v
)->ob_itself
;
86 static void SndCh_dealloc(SndChannelObject
*self
)
88 SndDisposeChannel(self
->ob_itself
, 1);
89 Py_XDECREF(self
->ob_callback
);
93 static PyObject
*SndCh_SndDoCommand(SndChannelObject
*_self
, PyObject
*_args
)
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(SndChannelObject
*_self
, PyObject
*_args
)
114 PyObject
*_res
= NULL
;
117 if (!PyArg_ParseTuple(_args
, "O&",
118 SndCmd_Convert
, &cmd
))
120 _err
= SndDoImmediate(_self
->ob_itself
,
122 if (_err
!= noErr
) return PyMac_Error(_err
);
128 static PyObject
*SndCh_SndPlay(SndChannelObject
*_self
, PyObject
*_args
)
130 PyObject
*_res
= NULL
;
132 SndListHandle sndHandle
;
134 if (!PyArg_ParseTuple(_args
, "O&b",
135 ResObj_Convert
, &sndHandle
,
138 _err
= SndPlay(_self
->ob_itself
,
141 if (_err
!= noErr
) return PyMac_Error(_err
);
147 #if !TARGET_API_MAC_CARBON
149 static PyObject
*SndCh_SndStartFilePlay(SndChannelObject
*_self
, PyObject
*_args
)
151 PyObject
*_res
= NULL
;
157 if (!PyArg_ParseTuple(_args
, "hhlb",
163 _err
= SndStartFilePlay(_self
->ob_itself
,
171 if (_err
!= noErr
) return PyMac_Error(_err
);
178 #if !TARGET_API_MAC_CARBON
180 static PyObject
*SndCh_SndPauseFilePlay(SndChannelObject
*_self
, PyObject
*_args
)
182 PyObject
*_res
= NULL
;
184 if (!PyArg_ParseTuple(_args
, ""))
186 _err
= SndPauseFilePlay(_self
->ob_itself
);
187 if (_err
!= noErr
) return PyMac_Error(_err
);
194 #if !TARGET_API_MAC_CARBON
196 static PyObject
*SndCh_SndStopFilePlay(SndChannelObject
*_self
, PyObject
*_args
)
198 PyObject
*_res
= NULL
;
201 if (!PyArg_ParseTuple(_args
, "b",
204 _err
= SndStopFilePlay(_self
->ob_itself
,
206 if (_err
!= noErr
) return PyMac_Error(_err
);
213 static PyObject
*SndCh_SndChannelStatus(SndChannelObject
*_self
, PyObject
*_args
)
215 PyObject
*_res
= NULL
;
218 SCStatus theStatus__out__
;
219 if (!PyArg_ParseTuple(_args
, "h",
222 _err
= SndChannelStatus(_self
->ob_itself
,
225 if (_err
!= noErr
) return PyMac_Error(_err
);
226 _res
= Py_BuildValue("s#",
227 (char *)&theStatus__out__
, (int)sizeof(SCStatus
));
228 theStatus__error__
: ;
232 static PyObject
*SndCh_SndGetInfo(SndChannelObject
*_self
, PyObject
*_args
)
234 PyObject
*_res
= NULL
;
238 if (!PyArg_ParseTuple(_args
, "O&w",
239 PyMac_GetOSType
, &selector
,
242 _err
= SndGetInfo(_self
->ob_itself
,
245 if (_err
!= noErr
) return PyMac_Error(_err
);
251 static PyObject
*SndCh_SndSetInfo(SndChannelObject
*_self
, PyObject
*_args
)
253 PyObject
*_res
= NULL
;
257 if (!PyArg_ParseTuple(_args
, "O&w",
258 PyMac_GetOSType
, &selector
,
261 _err
= SndSetInfo(_self
->ob_itself
,
264 if (_err
!= noErr
) return PyMac_Error(_err
);
270 static PyMethodDef SndCh_methods
[] = {
271 {"SndDoCommand", (PyCFunction
)SndCh_SndDoCommand
, 1,
272 "(SndCommand cmd, Boolean noWait) -> None"},
273 {"SndDoImmediate", (PyCFunction
)SndCh_SndDoImmediate
, 1,
274 "(SndCommand cmd) -> None"},
275 {"SndPlay", (PyCFunction
)SndCh_SndPlay
, 1,
276 "(SndListHandle sndHandle, Boolean async) -> None"},
278 #if !TARGET_API_MAC_CARBON
279 {"SndStartFilePlay", (PyCFunction
)SndCh_SndStartFilePlay
, 1,
280 "(short fRefNum, short resNum, long bufferSize, Boolean async) -> None"},
283 #if !TARGET_API_MAC_CARBON
284 {"SndPauseFilePlay", (PyCFunction
)SndCh_SndPauseFilePlay
, 1,
288 #if !TARGET_API_MAC_CARBON
289 {"SndStopFilePlay", (PyCFunction
)SndCh_SndStopFilePlay
, 1,
290 "(Boolean quietNow) -> None"},
292 {"SndChannelStatus", (PyCFunction
)SndCh_SndChannelStatus
, 1,
293 "(short theLength) -> (SCStatus theStatus)"},
294 {"SndGetInfo", (PyCFunction
)SndCh_SndGetInfo
, 1,
295 "(OSType selector, void * infoPtr) -> None"},
296 {"SndSetInfo", (PyCFunction
)SndCh_SndSetInfo
, 1,
297 "(OSType selector, void * infoPtr) -> None"},
301 static PyMethodChain SndCh_chain
= { SndCh_methods
, NULL
};
303 static PyObject
*SndCh_getattr(SndChannelObject
*self
, char *name
)
305 return Py_FindMethodInChain(&SndCh_chain
, (PyObject
*)self
, name
);
308 #define SndCh_setattr NULL
310 #define SndCh_compare NULL
312 #define SndCh_repr NULL
314 #define SndCh_hash NULL
316 staticforward PyTypeObject SndChannel_Type
= {
317 PyObject_HEAD_INIT(&PyType_Type
)
319 "SndChannel", /*tp_name*/
320 sizeof(SndChannelObject
), /*tp_basicsize*/
323 (destructor
) SndCh_dealloc
, /*tp_dealloc*/
325 (getattrfunc
) SndCh_getattr
, /*tp_getattr*/
326 (setattrfunc
) SndCh_setattr
, /*tp_setattr*/
327 (cmpfunc
) SndCh_compare
, /*tp_compare*/
328 (reprfunc
) SndCh_repr
, /*tp_repr*/
329 (PyNumberMethods
*)0, /* tp_as_number */
330 (PySequenceMethods
*)0, /* tp_as_sequence */
331 (PyMappingMethods
*)0, /* tp_as_mapping */
332 (hashfunc
) SndCh_hash
, /*tp_hash*/
335 /* ------------------- End object type SndChannel ------------------- */
338 /* ------------------------ Object type SPB ------------------------- */
340 staticforward PyTypeObject SPB_Type
;
342 #define SPBObj_Check(x) ((x)->ob_type == &SPB_Type)
344 typedef struct SPBObject
{
346 /* Members used to implement callbacks: */
347 PyObject
*ob_completion
;
348 PyObject
*ob_interrupt
;
349 PyObject
*ob_thiscallback
;
354 static PyObject
*SPBObj_New(void)
357 it
= PyObject_NEW(SPBObject
, &SPB_Type
);
358 if (it
== NULL
) return NULL
;
359 it
->ob_completion
= NULL
;
360 it
->ob_interrupt
= NULL
;
361 it
->ob_thiscallback
= NULL
;
362 it
->ob_A5
= SetCurrentA5();
363 memset((char *)&it
->ob_spb
, 0, sizeof(it
->ob_spb
));
364 it
->ob_spb
.userLong
= (long)it
;
365 return (PyObject
*)it
;
367 static SPBObj_Convert(PyObject
*v
, SPBPtr
*p_itself
)
369 if (!SPBObj_Check(v
))
371 PyErr_SetString(PyExc_TypeError
, "SPB required");
374 *p_itself
= &((SPBObject
*)v
)->ob_spb
;
378 static void SPBObj_dealloc(SPBObject
*self
)
380 /* Cleanup of self->ob_itself goes here */
381 self
->ob_spb
.userLong
= 0;
382 self
->ob_thiscallback
= 0;
383 Py_XDECREF(self
->ob_completion
);
384 Py_XDECREF(self
->ob_interrupt
);
388 static PyMethodDef SPBObj_methods
[] = {
392 static PyMethodChain SPBObj_chain
= { SPBObj_methods
, NULL
};
394 static PyObject
*SPBObj_getattr(SPBObject
*self
, char *name
)
397 if (strcmp(name
, "inRefNum") == 0)
398 return Py_BuildValue("l", self
->ob_spb
.inRefNum
);
399 else if (strcmp(name
, "count") == 0)
400 return Py_BuildValue("l", self
->ob_spb
.count
);
401 else if (strcmp(name
, "milliseconds") == 0)
402 return Py_BuildValue("l", self
->ob_spb
.milliseconds
);
403 else if (strcmp(name
, "error") == 0)
404 return Py_BuildValue("h", self
->ob_spb
.error
);
405 return Py_FindMethodInChain(&SPBObj_chain
, (PyObject
*)self
, name
);
408 static int SPBObj_setattr(SPBObject
*self
, char *name
, PyObject
*value
)
413 if (strcmp(name
, "inRefNum") == 0)
414 rv
= PyArg_Parse(value
, "l", &self
->ob_spb
.inRefNum
);
415 else if (strcmp(name
, "count") == 0)
416 rv
= PyArg_Parse(value
, "l", &self
->ob_spb
.count
);
417 else if (strcmp(name
, "milliseconds") == 0)
418 rv
= PyArg_Parse(value
, "l", &self
->ob_spb
.milliseconds
);
419 else if (strcmp(name
, "buffer") == 0)
420 rv
= PyArg_Parse(value
, "w#", &self
->ob_spb
.bufferPtr
, &self
->ob_spb
.bufferLength
);
421 else if (strcmp(name
, "completionRoutine") == 0) {
422 self
->ob_spb
.completionRoutine
= NewSICompletionUPP(SPB_completion
);
423 self
->ob_completion
= value
;
426 #if !TARGET_API_MAC_CARBON
427 } else if (strcmp(name
, "interruptRoutine") == 0) {
428 self
->ob_spb
.completionRoutine
= NewSIInterruptUPP(SPB_interrupt
);
429 self
->ob_interrupt
= value
;
438 #define SPBObj_compare NULL
440 #define SPBObj_repr NULL
442 #define SPBObj_hash NULL
444 staticforward PyTypeObject SPB_Type
= {
445 PyObject_HEAD_INIT(&PyType_Type
)
448 sizeof(SPBObject
), /*tp_basicsize*/
451 (destructor
) SPBObj_dealloc
, /*tp_dealloc*/
453 (getattrfunc
) SPBObj_getattr
, /*tp_getattr*/
454 (setattrfunc
) SPBObj_setattr
, /*tp_setattr*/
455 (cmpfunc
) SPBObj_compare
, /*tp_compare*/
456 (reprfunc
) SPBObj_repr
, /*tp_repr*/
457 (PyNumberMethods
*)0, /* tp_as_number */
458 (PySequenceMethods
*)0, /* tp_as_sequence */
459 (PyMappingMethods
*)0, /* tp_as_mapping */
460 (hashfunc
) SPBObj_hash
, /*tp_hash*/
463 /* ---------------------- End object type SPB ----------------------- */
466 static PyObject
*Snd_SPB(PyObject
*_self
, PyObject
*_args
)
468 PyObject
*_res
= NULL
;
472 static PyObject
*Snd_SysBeep(PyObject
*_self
, PyObject
*_args
)
474 PyObject
*_res
= NULL
;
476 if (!PyArg_ParseTuple(_args
, "h",
485 static PyObject
*Snd_SndNewChannel(PyObject
*_self
, PyObject
*_args
)
487 PyObject
*_res
= NULL
;
489 SndChannelPtr chan
= 0;
492 PyObject
* userRoutine
;
493 if (!PyArg_ParseTuple(_args
, "hlO",
498 if (userRoutine
!= Py_None
&& !PyCallable_Check(userRoutine
))
500 PyErr_SetString(PyExc_TypeError
, "callback must be callable");
501 goto userRoutine__error__
;
503 _err
= SndNewChannel(&chan
,
506 NewSndCallBackUPP(SndCh_UserRoutine
));
507 if (_err
!= noErr
) return PyMac_Error(_err
);
508 _res
= Py_BuildValue("O&",
510 if (_res
!= NULL
&& userRoutine
!= Py_None
)
512 SndChannelObject
*p
= (SndChannelObject
*)_res
;
513 p
->ob_itself
->userInfo
= (long)p
;
514 Py_INCREF(userRoutine
);
515 p
->ob_callback
= userRoutine
;
517 userRoutine__error__
: ;
521 #if !TARGET_API_MAC_CARBON
523 static PyObject
*Snd_SndControl(PyObject
*_self
, PyObject
*_args
)
525 PyObject
*_res
= NULL
;
529 if (!PyArg_ParseTuple(_args
, "h",
532 _err
= SndControl(id
,
534 if (_err
!= noErr
) return PyMac_Error(_err
);
535 _res
= Py_BuildValue("O&",
541 static PyObject
*Snd_SndSoundManagerVersion(PyObject
*_self
, PyObject
*_args
)
543 PyObject
*_res
= NULL
;
545 if (!PyArg_ParseTuple(_args
, ""))
547 _rv
= SndSoundManagerVersion();
548 _res
= Py_BuildValue("O&",
549 PyMac_BuildNumVersion
, _rv
);
553 static PyObject
*Snd_SndManagerStatus(PyObject
*_self
, PyObject
*_args
)
555 PyObject
*_res
= NULL
;
558 SMStatus theStatus__out__
;
559 if (!PyArg_ParseTuple(_args
, "h",
562 _err
= SndManagerStatus(theLength
,
564 if (_err
!= noErr
) return PyMac_Error(_err
);
565 _res
= Py_BuildValue("s#",
566 (char *)&theStatus__out__
, (int)sizeof(SMStatus
));
567 theStatus__error__
: ;
571 static PyObject
*Snd_SndGetSysBeepState(PyObject
*_self
, PyObject
*_args
)
573 PyObject
*_res
= NULL
;
575 if (!PyArg_ParseTuple(_args
, ""))
577 SndGetSysBeepState(&sysBeepState
);
578 _res
= Py_BuildValue("h",
583 static PyObject
*Snd_SndSetSysBeepState(PyObject
*_self
, PyObject
*_args
)
585 PyObject
*_res
= NULL
;
588 if (!PyArg_ParseTuple(_args
, "h",
591 _err
= SndSetSysBeepState(sysBeepState
);
592 if (_err
!= noErr
) return PyMac_Error(_err
);
598 #if !TARGET_API_MAC_CARBON
600 static PyObject
*Snd_MACEVersion(PyObject
*_self
, PyObject
*_args
)
602 PyObject
*_res
= NULL
;
604 if (!PyArg_ParseTuple(_args
, ""))
607 _res
= Py_BuildValue("O&",
608 PyMac_BuildNumVersion
, _rv
);
613 #if !TARGET_API_MAC_CARBON
615 static PyObject
*Snd_Comp3to1(PyObject
*_self
, PyObject
*_args
)
617 PyObject
*_res
= NULL
;
621 int buffer__in_len__
;
622 StateBlock
*state__in__
;
623 StateBlock state__out__
;
625 unsigned long numChannels
;
626 unsigned long whichChannel
;
627 if (!PyArg_ParseTuple(_args
, "s#s#ll",
628 &buffer__in__
, &buffer__in_len__
,
629 (char **)&state__in__
, &state__in_len__
,
633 if ((buffer__out__
= malloc(buffer__in_len__
)) == NULL
)
636 goto buffer__error__
;
638 buffer__len__
= buffer__in_len__
;
639 if (state__in_len__
!= sizeof(StateBlock
))
641 PyErr_SetString(PyExc_TypeError
, "buffer length should be sizeof(StateBlock)");
644 Comp3to1(buffer__in__
, buffer__out__
, (long)buffer__len__
,
645 state__in__
, &state__out__
,
648 _res
= Py_BuildValue("s#s#",
649 buffer__out__
, (int)buffer__len__
,
650 (char *)&state__out__
, (int)sizeof(StateBlock
));
658 #if !TARGET_API_MAC_CARBON
660 static PyObject
*Snd_Exp1to3(PyObject
*_self
, PyObject
*_args
)
662 PyObject
*_res
= NULL
;
666 int buffer__in_len__
;
667 StateBlock
*state__in__
;
668 StateBlock state__out__
;
670 unsigned long numChannels
;
671 unsigned long whichChannel
;
672 if (!PyArg_ParseTuple(_args
, "s#s#ll",
673 &buffer__in__
, &buffer__in_len__
,
674 (char **)&state__in__
, &state__in_len__
,
678 if ((buffer__out__
= malloc(buffer__in_len__
)) == NULL
)
681 goto buffer__error__
;
683 buffer__len__
= buffer__in_len__
;
684 if (state__in_len__
!= sizeof(StateBlock
))
686 PyErr_SetString(PyExc_TypeError
, "buffer length should be sizeof(StateBlock)");
689 Exp1to3(buffer__in__
, buffer__out__
, (long)buffer__len__
,
690 state__in__
, &state__out__
,
693 _res
= Py_BuildValue("s#s#",
694 buffer__out__
, (int)buffer__len__
,
695 (char *)&state__out__
, (int)sizeof(StateBlock
));
703 #if !TARGET_API_MAC_CARBON
705 static PyObject
*Snd_Comp6to1(PyObject
*_self
, PyObject
*_args
)
707 PyObject
*_res
= NULL
;
711 int buffer__in_len__
;
712 StateBlock
*state__in__
;
713 StateBlock state__out__
;
715 unsigned long numChannels
;
716 unsigned long whichChannel
;
717 if (!PyArg_ParseTuple(_args
, "s#s#ll",
718 &buffer__in__
, &buffer__in_len__
,
719 (char **)&state__in__
, &state__in_len__
,
723 if ((buffer__out__
= malloc(buffer__in_len__
)) == NULL
)
726 goto buffer__error__
;
728 buffer__len__
= buffer__in_len__
;
729 if (state__in_len__
!= sizeof(StateBlock
))
731 PyErr_SetString(PyExc_TypeError
, "buffer length should be sizeof(StateBlock)");
734 Comp6to1(buffer__in__
, buffer__out__
, (long)buffer__len__
,
735 state__in__
, &state__out__
,
738 _res
= Py_BuildValue("s#s#",
739 buffer__out__
, (int)buffer__len__
,
740 (char *)&state__out__
, (int)sizeof(StateBlock
));
748 #if !TARGET_API_MAC_CARBON
750 static PyObject
*Snd_Exp1to6(PyObject
*_self
, PyObject
*_args
)
752 PyObject
*_res
= NULL
;
756 int buffer__in_len__
;
757 StateBlock
*state__in__
;
758 StateBlock state__out__
;
760 unsigned long numChannels
;
761 unsigned long whichChannel
;
762 if (!PyArg_ParseTuple(_args
, "s#s#ll",
763 &buffer__in__
, &buffer__in_len__
,
764 (char **)&state__in__
, &state__in_len__
,
768 if ((buffer__out__
= malloc(buffer__in_len__
)) == NULL
)
771 goto buffer__error__
;
773 buffer__len__
= buffer__in_len__
;
774 if (state__in_len__
!= sizeof(StateBlock
))
776 PyErr_SetString(PyExc_TypeError
, "buffer length should be sizeof(StateBlock)");
779 Exp1to6(buffer__in__
, buffer__out__
, (long)buffer__len__
,
780 state__in__
, &state__out__
,
783 _res
= Py_BuildValue("s#s#",
784 buffer__out__
, (int)buffer__len__
,
785 (char *)&state__out__
, (int)sizeof(StateBlock
));
793 static PyObject
*Snd_GetSysBeepVolume(PyObject
*_self
, PyObject
*_args
)
795 PyObject
*_res
= NULL
;
798 if (!PyArg_ParseTuple(_args
, ""))
800 _err
= GetSysBeepVolume(&level
);
801 if (_err
!= noErr
) return PyMac_Error(_err
);
802 _res
= Py_BuildValue("l",
807 static PyObject
*Snd_SetSysBeepVolume(PyObject
*_self
, PyObject
*_args
)
809 PyObject
*_res
= NULL
;
812 if (!PyArg_ParseTuple(_args
, "l",
815 _err
= SetSysBeepVolume(level
);
816 if (_err
!= noErr
) return PyMac_Error(_err
);
822 static PyObject
*Snd_GetDefaultOutputVolume(PyObject
*_self
, PyObject
*_args
)
824 PyObject
*_res
= NULL
;
827 if (!PyArg_ParseTuple(_args
, ""))
829 _err
= GetDefaultOutputVolume(&level
);
830 if (_err
!= noErr
) return PyMac_Error(_err
);
831 _res
= Py_BuildValue("l",
836 static PyObject
*Snd_SetDefaultOutputVolume(PyObject
*_self
, PyObject
*_args
)
838 PyObject
*_res
= NULL
;
841 if (!PyArg_ParseTuple(_args
, "l",
844 _err
= SetDefaultOutputVolume(level
);
845 if (_err
!= noErr
) return PyMac_Error(_err
);
851 static PyObject
*Snd_GetSoundHeaderOffset(PyObject
*_self
, PyObject
*_args
)
853 PyObject
*_res
= NULL
;
855 SndListHandle sndHandle
;
857 if (!PyArg_ParseTuple(_args
, "O&",
858 ResObj_Convert
, &sndHandle
))
860 _err
= GetSoundHeaderOffset(sndHandle
,
862 if (_err
!= noErr
) return PyMac_Error(_err
);
863 _res
= Py_BuildValue("l",
868 static PyObject
*Snd_GetCompressionInfo(PyObject
*_self
, PyObject
*_args
)
870 PyObject
*_res
= NULL
;
876 CompressionInfo cp__out__
;
877 if (!PyArg_ParseTuple(_args
, "hO&hh",
879 PyMac_GetOSType
, &format
,
883 _err
= GetCompressionInfo(compressionID
,
888 if (_err
!= noErr
) return PyMac_Error(_err
);
889 _res
= Py_BuildValue("s#",
890 (char *)&cp__out__
, (int)sizeof(CompressionInfo
));
895 static PyObject
*Snd_SetSoundPreference(PyObject
*_self
, PyObject
*_args
)
897 PyObject
*_res
= NULL
;
902 if (!PyArg_ParseTuple(_args
, "O&O&",
903 PyMac_GetOSType
, &theType
,
904 ResObj_Convert
, &settings
))
906 _err
= SetSoundPreference(theType
,
909 if (_err
!= noErr
) return PyMac_Error(_err
);
910 _res
= Py_BuildValue("O&",
911 PyMac_BuildStr255
, name
);
915 static PyObject
*Snd_GetSoundPreference(PyObject
*_self
, PyObject
*_args
)
917 PyObject
*_res
= NULL
;
922 if (!PyArg_ParseTuple(_args
, "O&O&",
923 PyMac_GetOSType
, &theType
,
924 ResObj_Convert
, &settings
))
926 _err
= GetSoundPreference(theType
,
929 if (_err
!= noErr
) return PyMac_Error(_err
);
930 _res
= Py_BuildValue("O&",
931 PyMac_BuildStr255
, name
);
935 static PyObject
*Snd_GetCompressionName(PyObject
*_self
, PyObject
*_args
)
937 PyObject
*_res
= NULL
;
939 OSType compressionType
;
940 Str255 compressionName
;
941 if (!PyArg_ParseTuple(_args
, "O&",
942 PyMac_GetOSType
, &compressionType
))
944 _err
= GetCompressionName(compressionType
,
946 if (_err
!= noErr
) return PyMac_Error(_err
);
947 _res
= Py_BuildValue("O&",
948 PyMac_BuildStr255
, compressionName
);
952 static PyObject
*Snd_SPBVersion(PyObject
*_self
, PyObject
*_args
)
954 PyObject
*_res
= NULL
;
956 if (!PyArg_ParseTuple(_args
, ""))
959 _res
= Py_BuildValue("O&",
960 PyMac_BuildNumVersion
, _rv
);
964 static PyObject
*Snd_SPBSignInDevice(PyObject
*_self
, PyObject
*_args
)
966 PyObject
*_res
= NULL
;
970 if (!PyArg_ParseTuple(_args
, "hO&",
972 PyMac_GetStr255
, deviceName
))
974 _err
= SPBSignInDevice(deviceRefNum
,
976 if (_err
!= noErr
) return PyMac_Error(_err
);
982 static PyObject
*Snd_SPBSignOutDevice(PyObject
*_self
, PyObject
*_args
)
984 PyObject
*_res
= NULL
;
987 if (!PyArg_ParseTuple(_args
, "h",
990 _err
= SPBSignOutDevice(deviceRefNum
);
991 if (_err
!= noErr
) return PyMac_Error(_err
);
997 static PyObject
*Snd_SPBGetIndexedDevice(PyObject
*_self
, PyObject
*_args
)
999 PyObject
*_res
= NULL
;
1003 Handle deviceIconHandle
;
1004 if (!PyArg_ParseTuple(_args
, "h",
1007 _err
= SPBGetIndexedDevice(count
,
1010 if (_err
!= noErr
) return PyMac_Error(_err
);
1011 _res
= Py_BuildValue("O&O&",
1012 PyMac_BuildStr255
, deviceName
,
1013 ResObj_New
, deviceIconHandle
);
1017 static PyObject
*Snd_SPBOpenDevice(PyObject
*_self
, PyObject
*_args
)
1019 PyObject
*_res
= NULL
;
1024 if (!PyArg_ParseTuple(_args
, "O&h",
1025 PyMac_GetStr255
, deviceName
,
1028 _err
= SPBOpenDevice(deviceName
,
1031 if (_err
!= noErr
) return PyMac_Error(_err
);
1032 _res
= Py_BuildValue("l",
1037 static PyObject
*Snd_SPBCloseDevice(PyObject
*_self
, PyObject
*_args
)
1039 PyObject
*_res
= NULL
;
1042 if (!PyArg_ParseTuple(_args
, "l",
1045 _err
= SPBCloseDevice(inRefNum
);
1046 if (_err
!= noErr
) return PyMac_Error(_err
);
1052 static PyObject
*Snd_SPBRecord(PyObject
*_self
, PyObject
*_args
)
1054 PyObject
*_res
= NULL
;
1058 if (!PyArg_ParseTuple(_args
, "O&b",
1059 SPBObj_Convert
, &inParamPtr
,
1062 _err
= SPBRecord(inParamPtr
,
1064 if (_err
!= noErr
) return PyMac_Error(_err
);
1070 #if !TARGET_API_MAC_CARBON
1072 static PyObject
*Snd_SPBRecordToFile(PyObject
*_self
, PyObject
*_args
)
1074 PyObject
*_res
= NULL
;
1079 if (!PyArg_ParseTuple(_args
, "hO&b",
1081 SPBObj_Convert
, &inParamPtr
,
1084 _err
= SPBRecordToFile(fRefNum
,
1087 if (_err
!= noErr
) return PyMac_Error(_err
);
1094 static PyObject
*Snd_SPBPauseRecording(PyObject
*_self
, PyObject
*_args
)
1096 PyObject
*_res
= NULL
;
1099 if (!PyArg_ParseTuple(_args
, "l",
1102 _err
= SPBPauseRecording(inRefNum
);
1103 if (_err
!= noErr
) return PyMac_Error(_err
);
1109 static PyObject
*Snd_SPBResumeRecording(PyObject
*_self
, PyObject
*_args
)
1111 PyObject
*_res
= NULL
;
1114 if (!PyArg_ParseTuple(_args
, "l",
1117 _err
= SPBResumeRecording(inRefNum
);
1118 if (_err
!= noErr
) return PyMac_Error(_err
);
1124 static PyObject
*Snd_SPBStopRecording(PyObject
*_self
, PyObject
*_args
)
1126 PyObject
*_res
= NULL
;
1129 if (!PyArg_ParseTuple(_args
, "l",
1132 _err
= SPBStopRecording(inRefNum
);
1133 if (_err
!= noErr
) return PyMac_Error(_err
);
1139 static PyObject
*Snd_SPBGetRecordingStatus(PyObject
*_self
, PyObject
*_args
)
1141 PyObject
*_res
= NULL
;
1144 short recordingStatus
;
1146 unsigned long totalSamplesToRecord
;
1147 unsigned long numberOfSamplesRecorded
;
1148 unsigned long totalMsecsToRecord
;
1149 unsigned long numberOfMsecsRecorded
;
1150 if (!PyArg_ParseTuple(_args
, "l",
1153 _err
= SPBGetRecordingStatus(inRefNum
,
1156 &totalSamplesToRecord
,
1157 &numberOfSamplesRecorded
,
1158 &totalMsecsToRecord
,
1159 &numberOfMsecsRecorded
);
1160 if (_err
!= noErr
) return PyMac_Error(_err
);
1161 _res
= Py_BuildValue("hhllll",
1164 totalSamplesToRecord
,
1165 numberOfSamplesRecorded
,
1167 numberOfMsecsRecorded
);
1171 static PyObject
*Snd_SPBGetDeviceInfo(PyObject
*_self
, PyObject
*_args
)
1173 PyObject
*_res
= NULL
;
1178 if (!PyArg_ParseTuple(_args
, "lO&w",
1180 PyMac_GetOSType
, &infoType
,
1183 _err
= SPBGetDeviceInfo(inRefNum
,
1186 if (_err
!= noErr
) return PyMac_Error(_err
);
1192 static PyObject
*Snd_SPBSetDeviceInfo(PyObject
*_self
, PyObject
*_args
)
1194 PyObject
*_res
= NULL
;
1199 if (!PyArg_ParseTuple(_args
, "lO&w",
1201 PyMac_GetOSType
, &infoType
,
1204 _err
= SPBSetDeviceInfo(inRefNum
,
1207 if (_err
!= noErr
) return PyMac_Error(_err
);
1213 static PyObject
*Snd_SPBMillisecondsToBytes(PyObject
*_self
, PyObject
*_args
)
1215 PyObject
*_res
= NULL
;
1219 if (!PyArg_ParseTuple(_args
, "l",
1222 _err
= SPBMillisecondsToBytes(inRefNum
,
1224 if (_err
!= noErr
) return PyMac_Error(_err
);
1225 _res
= Py_BuildValue("l",
1230 static PyObject
*Snd_SPBBytesToMilliseconds(PyObject
*_self
, PyObject
*_args
)
1232 PyObject
*_res
= NULL
;
1236 if (!PyArg_ParseTuple(_args
, "l",
1239 _err
= SPBBytesToMilliseconds(inRefNum
,
1241 if (_err
!= noErr
) return PyMac_Error(_err
);
1242 _res
= Py_BuildValue("l",
1247 static PyMethodDef Snd_methods
[] = {
1248 {"SPB", (PyCFunction
)Snd_SPB
, 1,
1250 {"SysBeep", (PyCFunction
)Snd_SysBeep
, 1,
1251 "(short duration) -> None"},
1252 {"SndNewChannel", (PyCFunction
)Snd_SndNewChannel
, 1,
1253 "(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)"},
1255 #if !TARGET_API_MAC_CARBON
1256 {"SndControl", (PyCFunction
)Snd_SndControl
, 1,
1257 "(short id) -> (SndCommand cmd)"},
1259 {"SndSoundManagerVersion", (PyCFunction
)Snd_SndSoundManagerVersion
, 1,
1260 "() -> (NumVersion _rv)"},
1261 {"SndManagerStatus", (PyCFunction
)Snd_SndManagerStatus
, 1,
1262 "(short theLength) -> (SMStatus theStatus)"},
1263 {"SndGetSysBeepState", (PyCFunction
)Snd_SndGetSysBeepState
, 1,
1264 "() -> (short sysBeepState)"},
1265 {"SndSetSysBeepState", (PyCFunction
)Snd_SndSetSysBeepState
, 1,
1266 "(short sysBeepState) -> None"},
1268 #if !TARGET_API_MAC_CARBON
1269 {"MACEVersion", (PyCFunction
)Snd_MACEVersion
, 1,
1270 "() -> (NumVersion _rv)"},
1273 #if !TARGET_API_MAC_CARBON
1274 {"Comp3to1", (PyCFunction
)Snd_Comp3to1
, 1,
1275 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1278 #if !TARGET_API_MAC_CARBON
1279 {"Exp1to3", (PyCFunction
)Snd_Exp1to3
, 1,
1280 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1283 #if !TARGET_API_MAC_CARBON
1284 {"Comp6to1", (PyCFunction
)Snd_Comp6to1
, 1,
1285 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1288 #if !TARGET_API_MAC_CARBON
1289 {"Exp1to6", (PyCFunction
)Snd_Exp1to6
, 1,
1290 "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
1292 {"GetSysBeepVolume", (PyCFunction
)Snd_GetSysBeepVolume
, 1,
1293 "() -> (long level)"},
1294 {"SetSysBeepVolume", (PyCFunction
)Snd_SetSysBeepVolume
, 1,
1295 "(long level) -> None"},
1296 {"GetDefaultOutputVolume", (PyCFunction
)Snd_GetDefaultOutputVolume
, 1,
1297 "() -> (long level)"},
1298 {"SetDefaultOutputVolume", (PyCFunction
)Snd_SetDefaultOutputVolume
, 1,
1299 "(long level) -> None"},
1300 {"GetSoundHeaderOffset", (PyCFunction
)Snd_GetSoundHeaderOffset
, 1,
1301 "(SndListHandle sndHandle) -> (long offset)"},
1302 {"GetCompressionInfo", (PyCFunction
)Snd_GetCompressionInfo
, 1,
1303 "(short compressionID, OSType format, short numChannels, short sampleSize) -> (CompressionInfo cp)"},
1304 {"SetSoundPreference", (PyCFunction
)Snd_SetSoundPreference
, 1,
1305 "(OSType theType, Handle settings) -> (Str255 name)"},
1306 {"GetSoundPreference", (PyCFunction
)Snd_GetSoundPreference
, 1,
1307 "(OSType theType, Handle settings) -> (Str255 name)"},
1308 {"GetCompressionName", (PyCFunction
)Snd_GetCompressionName
, 1,
1309 "(OSType compressionType) -> (Str255 compressionName)"},
1310 {"SPBVersion", (PyCFunction
)Snd_SPBVersion
, 1,
1311 "() -> (NumVersion _rv)"},
1312 {"SPBSignInDevice", (PyCFunction
)Snd_SPBSignInDevice
, 1,
1313 "(short deviceRefNum, Str255 deviceName) -> None"},
1314 {"SPBSignOutDevice", (PyCFunction
)Snd_SPBSignOutDevice
, 1,
1315 "(short deviceRefNum) -> None"},
1316 {"SPBGetIndexedDevice", (PyCFunction
)Snd_SPBGetIndexedDevice
, 1,
1317 "(short count) -> (Str255 deviceName, Handle deviceIconHandle)"},
1318 {"SPBOpenDevice", (PyCFunction
)Snd_SPBOpenDevice
, 1,
1319 "(Str255 deviceName, short permission) -> (long inRefNum)"},
1320 {"SPBCloseDevice", (PyCFunction
)Snd_SPBCloseDevice
, 1,
1321 "(long inRefNum) -> None"},
1322 {"SPBRecord", (PyCFunction
)Snd_SPBRecord
, 1,
1323 "(SPBPtr inParamPtr, Boolean asynchFlag) -> None"},
1325 #if !TARGET_API_MAC_CARBON
1326 {"SPBRecordToFile", (PyCFunction
)Snd_SPBRecordToFile
, 1,
1327 "(short fRefNum, SPBPtr inParamPtr, Boolean asynchFlag) -> None"},
1329 {"SPBPauseRecording", (PyCFunction
)Snd_SPBPauseRecording
, 1,
1330 "(long inRefNum) -> None"},
1331 {"SPBResumeRecording", (PyCFunction
)Snd_SPBResumeRecording
, 1,
1332 "(long inRefNum) -> None"},
1333 {"SPBStopRecording", (PyCFunction
)Snd_SPBStopRecording
, 1,
1334 "(long inRefNum) -> None"},
1335 {"SPBGetRecordingStatus", (PyCFunction
)Snd_SPBGetRecordingStatus
, 1,
1336 "(long inRefNum) -> (short recordingStatus, short meterLevel, unsigned long totalSamplesToRecord, unsigned long numberOfSamplesRecorded, unsigned long totalMsecsToRecord, unsigned long numberOfMsecsRecorded)"},
1337 {"SPBGetDeviceInfo", (PyCFunction
)Snd_SPBGetDeviceInfo
, 1,
1338 "(long inRefNum, OSType infoType, void * infoData) -> None"},
1339 {"SPBSetDeviceInfo", (PyCFunction
)Snd_SPBSetDeviceInfo
, 1,
1340 "(long inRefNum, OSType infoType, void * infoData) -> None"},
1341 {"SPBMillisecondsToBytes", (PyCFunction
)Snd_SPBMillisecondsToBytes
, 1,
1342 "(long inRefNum) -> (long milliseconds)"},
1343 {"SPBBytesToMilliseconds", (PyCFunction
)Snd_SPBBytesToMilliseconds
, 1,
1344 "(long inRefNum) -> (long byteCount)"},
1350 /* Routine passed to Py_AddPendingCall -- call the Python callback */
1352 SndCh_CallCallBack(void *arg
)
1354 SndChannelObject
*p
= (SndChannelObject
*)arg
;
1357 args
= Py_BuildValue("(O(hhl))",
1358 p
, p
->ob_cmd
.cmd
, p
->ob_cmd
.param1
, p
->ob_cmd
.param2
);
1359 res
= PyEval_CallObject(p
->ob_callback
, args
);
1367 /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */
1369 SndCh_UserRoutine(SndChannelPtr chan
, SndCommand
*cmd
)
1371 SndChannelObject
*p
= (SndChannelObject
*)(chan
->userInfo
);
1372 if (p
->ob_callback
!= NULL
) {
1373 long A5
= SetA5(p
->ob_A5
);
1375 Py_AddPendingCall(SndCh_CallCallBack
, (void *)p
);
1380 /* SPB callbacks - Schedule callbacks to Python */
1382 SPB_CallCallBack(void *arg
)
1384 SPBObject
*p
= (SPBObject
*)arg
;
1388 if ( p
->ob_thiscallback
== 0 ) return 0;
1389 args
= Py_BuildValue("(O)", p
);
1390 res
= PyEval_CallObject(p
->ob_thiscallback
, args
);
1391 p
->ob_thiscallback
= 0;
1400 SPB_completion(SPBPtr my_spb
)
1402 SPBObject
*p
= (SPBObject
*)(my_spb
->userLong
);
1404 if (p
&& p
->ob_completion
) {
1405 long A5
= SetA5(p
->ob_A5
);
1406 p
->ob_thiscallback
= p
->ob_completion
; /* Hope we cannot get two at the same time */
1407 Py_AddPendingCall(SPB_CallCallBack
, (void *)p
);
1412 #if !TARGET_API_MAC_CARBON
1414 SPB_interrupt(SPBPtr my_spb
)
1416 SPBObject
*p
= (SPBObject
*)(my_spb
->userLong
);
1418 if (p
&& p
->ob_interrupt
) {
1419 long A5
= SetA5(p
->ob_A5
);
1420 p
->ob_thiscallback
= p
->ob_interrupt
; /* Hope we cannot get two at the same time */
1421 Py_AddPendingCall(SPB_CallCallBack
, (void *)p
);
1437 m
= Py_InitModule("Snd", Snd_methods
);
1438 d
= PyModule_GetDict(m
);
1439 Snd_Error
= PyMac_GetOSErrException();
1440 if (Snd_Error
== NULL
||
1441 PyDict_SetItemString(d
, "Error", Snd_Error
) != 0)
1443 SndChannel_Type
.ob_type
= &PyType_Type
;
1444 Py_INCREF(&SndChannel_Type
);
1445 if (PyDict_SetItemString(d
, "SndChannelType", (PyObject
*)&SndChannel_Type
) != 0)
1446 Py_FatalError("can't initialize SndChannelType");
1447 SPB_Type
.ob_type
= &PyType_Type
;
1448 Py_INCREF(&SPB_Type
);
1449 if (PyDict_SetItemString(d
, "SPBType", (PyObject
*)&SPB_Type
) != 0)
1450 Py_FatalError("can't initialize SPBType");
1453 /* ========================= End module Snd ========================= */