| 1 |
|
|---|
| 2 | /* ========================== Module _Snd =========================== */
|
|---|
| 3 |
|
|---|
| 4 | #include "Python.h"
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | #include "pymactoolbox.h"
|
|---|
| 9 |
|
|---|
| 10 | /* Macro to test whether a weak-loaded CFM function exists */
|
|---|
| 11 | #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
|
|---|
| 12 | PyErr_SetString(PyExc_NotImplementedError, \
|
|---|
| 13 | "Not available in this shared library/OS version"); \
|
|---|
| 14 | return NULL; \
|
|---|
| 15 | }} while(0)
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 | #include <Carbon/Carbon.h>
|
|---|
| 19 |
|
|---|
| 20 | /* Convert a SndCommand argument */
|
|---|
| 21 | static int
|
|---|
| 22 | SndCmd_Convert(PyObject *v, SndCommand *pc)
|
|---|
| 23 | {
|
|---|
| 24 | int len;
|
|---|
| 25 | pc->param1 = 0;
|
|---|
| 26 | pc->param2 = 0;
|
|---|
| 27 | if (PyTuple_Check(v)) {
|
|---|
| 28 | if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2))
|
|---|
| 29 | return 1;
|
|---|
| 30 | PyErr_Clear();
|
|---|
| 31 | return PyArg_ParseTuple(v, "Hhs#", &pc->cmd, &pc->param1, &pc->param2, &len);
|
|---|
| 32 | }
|
|---|
| 33 | return PyArg_Parse(v, "H", &pc->cmd);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */
|
|---|
| 37 | static pascal void SPB_completion(SPBPtr my_spb); /* Forward */
|
|---|
| 38 |
|
|---|
| 39 | static PyObject *Snd_Error;
|
|---|
| 40 |
|
|---|
| 41 | /* --------------------- Object type SndChannel --------------------- */
|
|---|
| 42 |
|
|---|
| 43 | static PyTypeObject SndChannel_Type;
|
|---|
| 44 |
|
|---|
| 45 | #define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type || PyObject_TypeCheck((x), &SndChannel_Type))
|
|---|
| 46 |
|
|---|
| 47 | typedef struct SndChannelObject {
|
|---|
| 48 | PyObject_HEAD
|
|---|
| 49 | SndChannelPtr ob_itself;
|
|---|
| 50 | /* Members used to implement callbacks: */
|
|---|
| 51 | PyObject *ob_callback;
|
|---|
| 52 | long ob_A5;
|
|---|
| 53 | SndCommand ob_cmd;
|
|---|
| 54 | } SndChannelObject;
|
|---|
| 55 |
|
|---|
| 56 | static PyObject *SndCh_New(SndChannelPtr itself)
|
|---|
| 57 | {
|
|---|
| 58 | SndChannelObject *it;
|
|---|
| 59 | it = PyObject_NEW(SndChannelObject, &SndChannel_Type);
|
|---|
| 60 | if (it == NULL) return NULL;
|
|---|
| 61 | it->ob_itself = itself;
|
|---|
| 62 | it->ob_callback = NULL;
|
|---|
| 63 | it->ob_A5 = SetCurrentA5();
|
|---|
| 64 | return (PyObject *)it;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | static void SndCh_dealloc(SndChannelObject *self)
|
|---|
| 68 | {
|
|---|
| 69 | SndDisposeChannel(self->ob_itself, 1);
|
|---|
| 70 | Py_XDECREF(self->ob_callback);
|
|---|
| 71 | PyObject_Free((PyObject *)self);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | static PyObject *SndCh_SndDoCommand(SndChannelObject *_self, PyObject *_args)
|
|---|
| 75 | {
|
|---|
| 76 | PyObject *_res = NULL;
|
|---|
| 77 | OSErr _err;
|
|---|
| 78 | SndCommand cmd;
|
|---|
| 79 | Boolean noWait;
|
|---|
| 80 | if (!PyArg_ParseTuple(_args, "O&b",
|
|---|
| 81 | SndCmd_Convert, &cmd,
|
|---|
| 82 | &noWait))
|
|---|
| 83 | return NULL;
|
|---|
| 84 | _err = SndDoCommand(_self->ob_itself,
|
|---|
| 85 | &cmd,
|
|---|
| 86 | noWait);
|
|---|
| 87 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 88 | Py_INCREF(Py_None);
|
|---|
| 89 | _res = Py_None;
|
|---|
| 90 | return _res;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | static PyObject *SndCh_SndDoImmediate(SndChannelObject *_self, PyObject *_args)
|
|---|
| 94 | {
|
|---|
| 95 | PyObject *_res = NULL;
|
|---|
| 96 | OSErr _err;
|
|---|
| 97 | SndCommand cmd;
|
|---|
| 98 | if (!PyArg_ParseTuple(_args, "O&",
|
|---|
| 99 | SndCmd_Convert, &cmd))
|
|---|
| 100 | return NULL;
|
|---|
| 101 | _err = SndDoImmediate(_self->ob_itself,
|
|---|
| 102 | &cmd);
|
|---|
| 103 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 104 | Py_INCREF(Py_None);
|
|---|
| 105 | _res = Py_None;
|
|---|
| 106 | return _res;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | static PyObject *SndCh_SndPlay(SndChannelObject *_self, PyObject *_args)
|
|---|
| 110 | {
|
|---|
| 111 | PyObject *_res = NULL;
|
|---|
| 112 | OSErr _err;
|
|---|
| 113 | SndListHandle sndHandle;
|
|---|
| 114 | Boolean async;
|
|---|
| 115 | if (!PyArg_ParseTuple(_args, "O&b",
|
|---|
| 116 | ResObj_Convert, &sndHandle,
|
|---|
| 117 | &async))
|
|---|
| 118 | return NULL;
|
|---|
| 119 | _err = SndPlay(_self->ob_itself,
|
|---|
| 120 | sndHandle,
|
|---|
| 121 | async);
|
|---|
| 122 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 123 | Py_INCREF(Py_None);
|
|---|
| 124 | _res = Py_None;
|
|---|
| 125 | return _res;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | static PyObject *SndCh_SndChannelStatus(SndChannelObject *_self, PyObject *_args)
|
|---|
| 129 | {
|
|---|
| 130 | PyObject *_res = NULL;
|
|---|
| 131 | OSErr _err;
|
|---|
| 132 | short theLength;
|
|---|
| 133 | SCStatus theStatus__out__;
|
|---|
| 134 | if (!PyArg_ParseTuple(_args, "h",
|
|---|
| 135 | &theLength))
|
|---|
| 136 | return NULL;
|
|---|
| 137 | _err = SndChannelStatus(_self->ob_itself,
|
|---|
| 138 | theLength,
|
|---|
| 139 | &theStatus__out__);
|
|---|
| 140 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 141 | _res = Py_BuildValue("s#",
|
|---|
| 142 | (char *)&theStatus__out__, (int)sizeof(SCStatus));
|
|---|
| 143 | return _res;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | static PyObject *SndCh_SndGetInfo(SndChannelObject *_self, PyObject *_args)
|
|---|
| 147 | {
|
|---|
| 148 | PyObject *_res = NULL;
|
|---|
| 149 | OSErr _err;
|
|---|
| 150 | OSType selector;
|
|---|
| 151 | void * infoPtr;
|
|---|
| 152 | if (!PyArg_ParseTuple(_args, "O&w",
|
|---|
| 153 | PyMac_GetOSType, &selector,
|
|---|
| 154 | &infoPtr))
|
|---|
| 155 | return NULL;
|
|---|
| 156 | _err = SndGetInfo(_self->ob_itself,
|
|---|
| 157 | selector,
|
|---|
| 158 | infoPtr);
|
|---|
| 159 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 160 | Py_INCREF(Py_None);
|
|---|
| 161 | _res = Py_None;
|
|---|
| 162 | return _res;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | static PyObject *SndCh_SndSetInfo(SndChannelObject *_self, PyObject *_args)
|
|---|
| 166 | {
|
|---|
| 167 | PyObject *_res = NULL;
|
|---|
| 168 | OSErr _err;
|
|---|
| 169 | OSType selector;
|
|---|
| 170 | void * infoPtr;
|
|---|
| 171 | if (!PyArg_ParseTuple(_args, "O&w",
|
|---|
| 172 | PyMac_GetOSType, &selector,
|
|---|
| 173 | &infoPtr))
|
|---|
| 174 | return NULL;
|
|---|
| 175 | _err = SndSetInfo(_self->ob_itself,
|
|---|
| 176 | selector,
|
|---|
| 177 | infoPtr);
|
|---|
| 178 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 179 | Py_INCREF(Py_None);
|
|---|
| 180 | _res = Py_None;
|
|---|
| 181 | return _res;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | static PyMethodDef SndCh_methods[] = {
|
|---|
| 185 | {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1,
|
|---|
| 186 | PyDoc_STR("(SndCommand cmd, Boolean noWait) -> None")},
|
|---|
| 187 | {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1,
|
|---|
| 188 | PyDoc_STR("(SndCommand cmd) -> None")},
|
|---|
| 189 | {"SndPlay", (PyCFunction)SndCh_SndPlay, 1,
|
|---|
| 190 | PyDoc_STR("(SndListHandle sndHandle, Boolean async) -> None")},
|
|---|
| 191 | {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1,
|
|---|
| 192 | PyDoc_STR("(short theLength) -> (SCStatus theStatus)")},
|
|---|
| 193 | {"SndGetInfo", (PyCFunction)SndCh_SndGetInfo, 1,
|
|---|
| 194 | PyDoc_STR("(OSType selector, void * infoPtr) -> None")},
|
|---|
| 195 | {"SndSetInfo", (PyCFunction)SndCh_SndSetInfo, 1,
|
|---|
| 196 | PyDoc_STR("(OSType selector, void * infoPtr) -> None")},
|
|---|
| 197 | {NULL, NULL, 0}
|
|---|
| 198 | };
|
|---|
| 199 |
|
|---|
| 200 | #define SndCh_getsetlist NULL
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 | #define SndCh_compare NULL
|
|---|
| 204 |
|
|---|
| 205 | #define SndCh_repr NULL
|
|---|
| 206 |
|
|---|
| 207 | #define SndCh_hash NULL
|
|---|
| 208 |
|
|---|
| 209 | static PyTypeObject SndChannel_Type = {
|
|---|
| 210 | PyObject_HEAD_INIT(NULL)
|
|---|
| 211 | 0, /*ob_size*/
|
|---|
| 212 | "_Snd.SndChannel", /*tp_name*/
|
|---|
| 213 | sizeof(SndChannelObject), /*tp_basicsize*/
|
|---|
| 214 | 0, /*tp_itemsize*/
|
|---|
| 215 | /* methods */
|
|---|
| 216 | (destructor) SndCh_dealloc, /*tp_dealloc*/
|
|---|
| 217 | 0, /*tp_print*/
|
|---|
| 218 | (getattrfunc)0, /*tp_getattr*/
|
|---|
| 219 | (setattrfunc)0, /*tp_setattr*/
|
|---|
| 220 | (cmpfunc) SndCh_compare, /*tp_compare*/
|
|---|
| 221 | (reprfunc) SndCh_repr, /*tp_repr*/
|
|---|
| 222 | (PyNumberMethods *)0, /* tp_as_number */
|
|---|
| 223 | (PySequenceMethods *)0, /* tp_as_sequence */
|
|---|
| 224 | (PyMappingMethods *)0, /* tp_as_mapping */
|
|---|
| 225 | (hashfunc) SndCh_hash, /*tp_hash*/
|
|---|
| 226 | 0, /*tp_call*/
|
|---|
| 227 | 0, /*tp_str*/
|
|---|
| 228 | PyObject_GenericGetAttr, /*tp_getattro*/
|
|---|
| 229 | PyObject_GenericSetAttr, /*tp_setattro */
|
|---|
| 230 | 0, /*tp_as_buffer*/
|
|---|
| 231 | Py_TPFLAGS_DEFAULT, /* tp_flags */
|
|---|
| 232 | 0, /*tp_doc*/
|
|---|
| 233 | 0, /*tp_traverse*/
|
|---|
| 234 | 0, /*tp_clear*/
|
|---|
| 235 | 0, /*tp_richcompare*/
|
|---|
| 236 | 0, /*tp_weaklistoffset*/
|
|---|
| 237 | 0, /*tp_iter*/
|
|---|
| 238 | 0, /*tp_iternext*/
|
|---|
| 239 | SndCh_methods, /* tp_methods */
|
|---|
| 240 | 0, /*tp_members*/
|
|---|
| 241 | SndCh_getsetlist, /*tp_getset*/
|
|---|
| 242 | 0, /*tp_base*/
|
|---|
| 243 | 0, /*tp_dict*/
|
|---|
| 244 | 0, /*tp_descr_get*/
|
|---|
| 245 | 0, /*tp_descr_set*/
|
|---|
| 246 | 0, /*tp_dictoffset*/
|
|---|
| 247 | 0, /*tp_init*/
|
|---|
| 248 | 0, /*tp_alloc*/
|
|---|
| 249 | 0, /*tp_new*/
|
|---|
| 250 | 0, /*tp_free*/
|
|---|
| 251 | };
|
|---|
| 252 |
|
|---|
| 253 | /* ------------------- End object type SndChannel ------------------- */
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 | /* ------------------------ Object type SPB ------------------------- */
|
|---|
| 257 |
|
|---|
| 258 | static PyTypeObject SPB_Type;
|
|---|
| 259 |
|
|---|
| 260 | #define SPBObj_Check(x) ((x)->ob_type == &SPB_Type || PyObject_TypeCheck((x), &SPB_Type))
|
|---|
| 261 |
|
|---|
| 262 | typedef struct SPBObject {
|
|---|
| 263 | PyObject_HEAD
|
|---|
| 264 | /* Members used to implement callbacks: */
|
|---|
| 265 | PyObject *ob_completion;
|
|---|
| 266 | PyObject *ob_interrupt;
|
|---|
| 267 | PyObject *ob_thiscallback;
|
|---|
| 268 | long ob_A5;
|
|---|
| 269 | SPB ob_spb;
|
|---|
| 270 | } SPBObject;
|
|---|
| 271 |
|
|---|
| 272 | static PyObject *SPBObj_New(void)
|
|---|
| 273 | {
|
|---|
| 274 | SPBObject *it;
|
|---|
| 275 | it = PyObject_NEW(SPBObject, &SPB_Type);
|
|---|
| 276 | if (it == NULL) return NULL;
|
|---|
| 277 | it->ob_completion = NULL;
|
|---|
| 278 | it->ob_interrupt = NULL;
|
|---|
| 279 | it->ob_thiscallback = NULL;
|
|---|
| 280 | it->ob_A5 = SetCurrentA5();
|
|---|
| 281 | memset((char *)&it->ob_spb, 0, sizeof(it->ob_spb));
|
|---|
| 282 | it->ob_spb.userLong = (long)it;
|
|---|
| 283 | return (PyObject *)it;
|
|---|
| 284 | }
|
|---|
| 285 | static int SPBObj_Convert(PyObject *v, SPBPtr *p_itself)
|
|---|
| 286 | {
|
|---|
| 287 | if (!SPBObj_Check(v))
|
|---|
| 288 | {
|
|---|
| 289 | PyErr_SetString(PyExc_TypeError, "SPB required");
|
|---|
| 290 | return 0;
|
|---|
| 291 | }
|
|---|
| 292 | *p_itself = &((SPBObject *)v)->ob_spb;
|
|---|
| 293 | return 1;
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | static void SPBObj_dealloc(SPBObject *self)
|
|---|
| 297 | {
|
|---|
| 298 | /* Cleanup of self->ob_itself goes here */
|
|---|
| 299 | self->ob_spb.userLong = 0;
|
|---|
| 300 | self->ob_thiscallback = 0;
|
|---|
| 301 | Py_XDECREF(self->ob_completion);
|
|---|
| 302 | Py_XDECREF(self->ob_interrupt);
|
|---|
| 303 | PyObject_Free((PyObject *)self);
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 | static PyMethodDef SPBObj_methods[] = {
|
|---|
| 307 | {NULL, NULL, 0}
|
|---|
| 308 | };
|
|---|
| 309 |
|
|---|
| 310 | static PyObject *SPBObj_get_inRefNum(SPBObject *self, void *closure)
|
|---|
| 311 | {
|
|---|
| 312 | return Py_BuildValue("l", self->ob_spb.inRefNum);
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | static int SPBObj_set_inRefNum(SPBObject *self, PyObject *v, void *closure)
|
|---|
| 316 | {
|
|---|
| 317 | return -1 + PyArg_Parse(v, "l", &self->ob_spb.inRefNum);
|
|---|
| 318 | return 0;
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | static PyObject *SPBObj_get_count(SPBObject *self, void *closure)
|
|---|
| 322 | {
|
|---|
| 323 | return Py_BuildValue("l", self->ob_spb.count);
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | static int SPBObj_set_count(SPBObject *self, PyObject *v, void *closure)
|
|---|
| 327 | {
|
|---|
| 328 | return -1 + PyArg_Parse(v, "l", &self->ob_spb.count);
|
|---|
| 329 | return 0;
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | static PyObject *SPBObj_get_milliseconds(SPBObject *self, void *closure)
|
|---|
| 333 | {
|
|---|
| 334 | return Py_BuildValue("l", self->ob_spb.milliseconds);
|
|---|
| 335 | }
|
|---|
| 336 |
|
|---|
| 337 | static int SPBObj_set_milliseconds(SPBObject *self, PyObject *v, void *closure)
|
|---|
| 338 | {
|
|---|
| 339 | return -1 + PyArg_Parse(v, "l", &self->ob_spb.milliseconds);
|
|---|
| 340 | return 0;
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | static PyObject *SPBObj_get_error(SPBObject *self, void *closure)
|
|---|
| 344 | {
|
|---|
| 345 | return Py_BuildValue("h", self->ob_spb.error);
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | #define SPBObj_set_error NULL
|
|---|
| 349 |
|
|---|
| 350 | #define SPBObj_get_completionRoutine NULL
|
|---|
| 351 |
|
|---|
| 352 | static int SPBObj_set_completionRoutine(SPBObject *self, PyObject *v, void *closure)
|
|---|
| 353 | {
|
|---|
| 354 | self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
|
|---|
| 355 | self->ob_completion = v;
|
|---|
| 356 | Py_INCREF(v);
|
|---|
| 357 | return 0;
|
|---|
| 358 | return 0;
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | static PyGetSetDef SPBObj_getsetlist[] = {
|
|---|
| 362 | {"inRefNum", (getter)SPBObj_get_inRefNum, (setter)SPBObj_set_inRefNum, NULL},
|
|---|
| 363 | {"count", (getter)SPBObj_get_count, (setter)SPBObj_set_count, NULL},
|
|---|
| 364 | {"milliseconds", (getter)SPBObj_get_milliseconds, (setter)SPBObj_set_milliseconds, NULL},
|
|---|
| 365 | {"error", (getter)SPBObj_get_error, (setter)SPBObj_set_error, NULL},
|
|---|
| 366 | {"completionRoutine", (getter)SPBObj_get_completionRoutine, (setter)SPBObj_set_completionRoutine, NULL},
|
|---|
| 367 | {NULL, NULL, NULL, NULL},
|
|---|
| 368 | };
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 | #define SPBObj_compare NULL
|
|---|
| 372 |
|
|---|
| 373 | #define SPBObj_repr NULL
|
|---|
| 374 |
|
|---|
| 375 | #define SPBObj_hash NULL
|
|---|
| 376 |
|
|---|
| 377 | static PyTypeObject SPB_Type = {
|
|---|
| 378 | PyObject_HEAD_INIT(NULL)
|
|---|
| 379 | 0, /*ob_size*/
|
|---|
| 380 | "_Snd.SPB", /*tp_name*/
|
|---|
| 381 | sizeof(SPBObject), /*tp_basicsize*/
|
|---|
| 382 | 0, /*tp_itemsize*/
|
|---|
| 383 | /* methods */
|
|---|
| 384 | (destructor) SPBObj_dealloc, /*tp_dealloc*/
|
|---|
| 385 | 0, /*tp_print*/
|
|---|
| 386 | (getattrfunc)0, /*tp_getattr*/
|
|---|
| 387 | (setattrfunc)0, /*tp_setattr*/
|
|---|
| 388 | (cmpfunc) SPBObj_compare, /*tp_compare*/
|
|---|
| 389 | (reprfunc) SPBObj_repr, /*tp_repr*/
|
|---|
| 390 | (PyNumberMethods *)0, /* tp_as_number */
|
|---|
| 391 | (PySequenceMethods *)0, /* tp_as_sequence */
|
|---|
| 392 | (PyMappingMethods *)0, /* tp_as_mapping */
|
|---|
| 393 | (hashfunc) SPBObj_hash, /*tp_hash*/
|
|---|
| 394 | 0, /*tp_call*/
|
|---|
| 395 | 0, /*tp_str*/
|
|---|
| 396 | PyObject_GenericGetAttr, /*tp_getattro*/
|
|---|
| 397 | PyObject_GenericSetAttr, /*tp_setattro */
|
|---|
| 398 | 0, /*tp_as_buffer*/
|
|---|
| 399 | Py_TPFLAGS_DEFAULT, /* tp_flags */
|
|---|
| 400 | 0, /*tp_doc*/
|
|---|
| 401 | 0, /*tp_traverse*/
|
|---|
| 402 | 0, /*tp_clear*/
|
|---|
| 403 | 0, /*tp_richcompare*/
|
|---|
| 404 | 0, /*tp_weaklistoffset*/
|
|---|
| 405 | 0, /*tp_iter*/
|
|---|
| 406 | 0, /*tp_iternext*/
|
|---|
| 407 | SPBObj_methods, /* tp_methods */
|
|---|
| 408 | 0, /*tp_members*/
|
|---|
| 409 | SPBObj_getsetlist, /*tp_getset*/
|
|---|
| 410 | 0, /*tp_base*/
|
|---|
| 411 | 0, /*tp_dict*/
|
|---|
| 412 | 0, /*tp_descr_get*/
|
|---|
| 413 | 0, /*tp_descr_set*/
|
|---|
| 414 | 0, /*tp_dictoffset*/
|
|---|
| 415 | 0, /*tp_init*/
|
|---|
| 416 | 0, /*tp_alloc*/
|
|---|
| 417 | 0, /*tp_new*/
|
|---|
| 418 | 0, /*tp_free*/
|
|---|
| 419 | };
|
|---|
| 420 |
|
|---|
| 421 | /* ---------------------- End object type SPB ----------------------- */
|
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 | static PyObject *Snd_SPB(PyObject *_self, PyObject *_args)
|
|---|
| 425 | {
|
|---|
| 426 | PyObject *_res = NULL;
|
|---|
| 427 | _res = SPBObj_New(); return _res;
|
|---|
| 428 | }
|
|---|
| 429 |
|
|---|
| 430 | static PyObject *Snd_SysBeep(PyObject *_self, PyObject *_args)
|
|---|
| 431 | {
|
|---|
| 432 | PyObject *_res = NULL;
|
|---|
| 433 | short duration;
|
|---|
| 434 | if (!PyArg_ParseTuple(_args, "h",
|
|---|
| 435 | &duration))
|
|---|
| 436 | return NULL;
|
|---|
| 437 | SysBeep(duration);
|
|---|
| 438 | Py_INCREF(Py_None);
|
|---|
| 439 | _res = Py_None;
|
|---|
| 440 | return _res;
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | static PyObject *Snd_SndNewChannel(PyObject *_self, PyObject *_args)
|
|---|
| 444 | {
|
|---|
| 445 | PyObject *_res = NULL;
|
|---|
| 446 | OSErr _err;
|
|---|
| 447 | SndChannelPtr chan = 0;
|
|---|
| 448 | short synth;
|
|---|
| 449 | long init;
|
|---|
| 450 | PyObject* userRoutine;
|
|---|
| 451 | if (!PyArg_ParseTuple(_args, "hlO",
|
|---|
| 452 | &synth,
|
|---|
| 453 | &init,
|
|---|
| 454 | &userRoutine))
|
|---|
| 455 | return NULL;
|
|---|
| 456 | if (userRoutine != Py_None && !PyCallable_Check(userRoutine))
|
|---|
| 457 | {
|
|---|
| 458 | PyErr_SetString(PyExc_TypeError, "callback must be callable");
|
|---|
| 459 | goto userRoutine__error__;
|
|---|
| 460 | }
|
|---|
| 461 | _err = SndNewChannel(&chan,
|
|---|
| 462 | synth,
|
|---|
| 463 | init,
|
|---|
| 464 | NewSndCallBackUPP(SndCh_UserRoutine));
|
|---|
| 465 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 466 | _res = Py_BuildValue("O&",
|
|---|
| 467 | SndCh_New, chan);
|
|---|
| 468 | if (_res != NULL && userRoutine != Py_None)
|
|---|
| 469 | {
|
|---|
| 470 | SndChannelObject *p = (SndChannelObject *)_res;
|
|---|
| 471 | p->ob_itself->userInfo = (long)p;
|
|---|
| 472 | Py_INCREF(userRoutine);
|
|---|
| 473 | p->ob_callback = userRoutine;
|
|---|
| 474 | }
|
|---|
| 475 | userRoutine__error__: ;
|
|---|
| 476 | return _res;
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | static PyObject *Snd_SndSoundManagerVersion(PyObject *_self, PyObject *_args)
|
|---|
| 480 | {
|
|---|
| 481 | PyObject *_res = NULL;
|
|---|
| 482 | NumVersion _rv;
|
|---|
| 483 | if (!PyArg_ParseTuple(_args, ""))
|
|---|
| 484 | return NULL;
|
|---|
| 485 | _rv = SndSoundManagerVersion();
|
|---|
| 486 | _res = Py_BuildValue("O&",
|
|---|
| 487 | PyMac_BuildNumVersion, _rv);
|
|---|
| 488 | return _res;
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 | static PyObject *Snd_SndManagerStatus(PyObject *_self, PyObject *_args)
|
|---|
| 492 | {
|
|---|
| 493 | PyObject *_res = NULL;
|
|---|
| 494 | OSErr _err;
|
|---|
| 495 | short theLength;
|
|---|
| 496 | SMStatus theStatus__out__;
|
|---|
| 497 | if (!PyArg_ParseTuple(_args, "h",
|
|---|
| 498 | &theLength))
|
|---|
| 499 | return NULL;
|
|---|
| 500 | _err = SndManagerStatus(theLength,
|
|---|
| 501 | &theStatus__out__);
|
|---|
| 502 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 503 | _res = Py_BuildValue("s#",
|
|---|
| 504 | (char *)&theStatus__out__, (int)sizeof(SMStatus));
|
|---|
| 505 | return _res;
|
|---|
| 506 | }
|
|---|
| 507 |
|
|---|
| 508 | static PyObject *Snd_SndGetSysBeepState(PyObject *_self, PyObject *_args)
|
|---|
| 509 | {
|
|---|
| 510 | PyObject *_res = NULL;
|
|---|
| 511 | short sysBeepState;
|
|---|
| 512 | if (!PyArg_ParseTuple(_args, ""))
|
|---|
| 513 | return NULL;
|
|---|
| 514 | SndGetSysBeepState(&sysBeepState);
|
|---|
| 515 | _res = Py_BuildValue("h",
|
|---|
| 516 | sysBeepState);
|
|---|
| 517 | return _res;
|
|---|
| 518 | }
|
|---|
| 519 |
|
|---|
| 520 | static PyObject *Snd_SndSetSysBeepState(PyObject *_self, PyObject *_args)
|
|---|
| 521 | {
|
|---|
| 522 | PyObject *_res = NULL;
|
|---|
| 523 | OSErr _err;
|
|---|
| 524 | short sysBeepState;
|
|---|
| 525 | if (!PyArg_ParseTuple(_args, "h",
|
|---|
| 526 | &sysBeepState))
|
|---|
| 527 | return NULL;
|
|---|
| 528 | _err = SndSetSysBeepState(sysBeepState);
|
|---|
| 529 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 530 | Py_INCREF(Py_None);
|
|---|
| 531 | _res = Py_None;
|
|---|
| 532 | return _res;
|
|---|
| 533 | }
|
|---|
| 534 |
|
|---|
| 535 | static PyObject *Snd_GetSysBeepVolume(PyObject *_self, PyObject *_args)
|
|---|
| 536 | {
|
|---|
| 537 | PyObject *_res = NULL;
|
|---|
| 538 | OSErr _err;
|
|---|
| 539 | long level;
|
|---|
| 540 | if (!PyArg_ParseTuple(_args, ""))
|
|---|
| 541 | return NULL;
|
|---|
| 542 | _err = GetSysBeepVolume(&level);
|
|---|
| 543 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 544 | _res = Py_BuildValue("l",
|
|---|
| 545 | level);
|
|---|
| 546 | return _res;
|
|---|
| 547 | }
|
|---|
| 548 |
|
|---|
| 549 | static PyObject *Snd_SetSysBeepVolume(PyObject *_self, PyObject *_args)
|
|---|
| 550 | {
|
|---|
| 551 | PyObject *_res = NULL;
|
|---|
| 552 | OSErr _err;
|
|---|
| 553 | long level;
|
|---|
| 554 | if (!PyArg_ParseTuple(_args, "l",
|
|---|
| 555 | &level))
|
|---|
| 556 | return NULL;
|
|---|
| 557 | _err = SetSysBeepVolume(level);
|
|---|
| 558 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 559 | Py_INCREF(Py_None);
|
|---|
| 560 | _res = Py_None;
|
|---|
| 561 | return _res;
|
|---|
| 562 | }
|
|---|
| 563 |
|
|---|
| 564 | static PyObject *Snd_GetDefaultOutputVolume(PyObject *_self, PyObject *_args)
|
|---|
| 565 | {
|
|---|
| 566 | PyObject *_res = NULL;
|
|---|
| 567 | OSErr _err;
|
|---|
| 568 | long level;
|
|---|
| 569 | if (!PyArg_ParseTuple(_args, ""))
|
|---|
| 570 | return NULL;
|
|---|
| 571 | _err = GetDefaultOutputVolume(&level);
|
|---|
| 572 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 573 | _res = Py_BuildValue("l",
|
|---|
| 574 | level);
|
|---|
| 575 | return _res;
|
|---|
| 576 | }
|
|---|
| 577 |
|
|---|
| 578 | static PyObject *Snd_SetDefaultOutputVolume(PyObject *_self, PyObject *_args)
|
|---|
| 579 | {
|
|---|
| 580 | PyObject *_res = NULL;
|
|---|
| 581 | OSErr _err;
|
|---|
| 582 | long level;
|
|---|
| 583 | if (!PyArg_ParseTuple(_args, "l",
|
|---|
| 584 | &level))
|
|---|
| 585 | return NULL;
|
|---|
| 586 | _err = SetDefaultOutputVolume(level);
|
|---|
| 587 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 588 | Py_INCREF(Py_None);
|
|---|
| 589 | _res = Py_None;
|
|---|
| 590 | return _res;
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | static PyObject *Snd_GetSoundHeaderOffset(PyObject *_self, PyObject *_args)
|
|---|
| 594 | {
|
|---|
| 595 | PyObject *_res = NULL;
|
|---|
| 596 | OSErr _err;
|
|---|
| 597 | SndListHandle sndHandle;
|
|---|
| 598 | long offset;
|
|---|
| 599 | if (!PyArg_ParseTuple(_args, "O&",
|
|---|
| 600 | ResObj_Convert, &sndHandle))
|
|---|
| 601 | return NULL;
|
|---|
| 602 | _err = GetSoundHeaderOffset(sndHandle,
|
|---|
| 603 | &offset);
|
|---|
| 604 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 605 | _res = Py_BuildValue("l",
|
|---|
| 606 | offset);
|
|---|
| 607 | return _res;
|
|---|
| 608 | }
|
|---|
| 609 |
|
|---|
| 610 | static PyObject *Snd_GetCompressionInfo(PyObject *_self, PyObject *_args)
|
|---|
| 611 | {
|
|---|
| 612 | PyObject *_res = NULL;
|
|---|
| 613 | OSErr _err;
|
|---|
| 614 | short compressionID;
|
|---|
| 615 | OSType format;
|
|---|
| 616 | short numChannels;
|
|---|
| 617 | short sampleSize;
|
|---|
| 618 | CompressionInfo cp__out__;
|
|---|
| 619 | if (!PyArg_ParseTuple(_args, "hO&hh",
|
|---|
| 620 | &compressionID,
|
|---|
| 621 | PyMac_GetOSType, &format,
|
|---|
| 622 | &numChannels,
|
|---|
| 623 | &sampleSize))
|
|---|
| 624 | return NULL;
|
|---|
| 625 | _err = GetCompressionInfo(compressionID,
|
|---|
| 626 | format,
|
|---|
| 627 | numChannels,
|
|---|
| 628 | sampleSize,
|
|---|
| 629 | &cp__out__);
|
|---|
| 630 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 631 | _res = Py_BuildValue("s#",
|
|---|
| 632 | (char *)&cp__out__, (int)sizeof(CompressionInfo));
|
|---|
| 633 | return _res;
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | static PyObject *Snd_SetSoundPreference(PyObject *_self, PyObject *_args)
|
|---|
| 637 | {
|
|---|
| 638 | PyObject *_res = NULL;
|
|---|
| 639 | OSErr _err;
|
|---|
| 640 | OSType theType;
|
|---|
| 641 | Str255 name;
|
|---|
| 642 | Handle settings;
|
|---|
| 643 | if (!PyArg_ParseTuple(_args, "O&O&",
|
|---|
| 644 | PyMac_GetOSType, &theType,
|
|---|
| 645 | ResObj_Convert, &settings))
|
|---|
| 646 | return NULL;
|
|---|
| 647 | _err = SetSoundPreference(theType,
|
|---|
| 648 | name,
|
|---|
| 649 | settings);
|
|---|
| 650 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 651 | _res = Py_BuildValue("O&",
|
|---|
| 652 | PyMac_BuildStr255, name);
|
|---|
| 653 | return _res;
|
|---|
| 654 | }
|
|---|
| 655 |
|
|---|
| 656 | static PyObject *Snd_GetSoundPreference(PyObject *_self, PyObject *_args)
|
|---|
| 657 | {
|
|---|
| 658 | PyObject *_res = NULL;
|
|---|
| 659 | OSErr _err;
|
|---|
| 660 | OSType theType;
|
|---|
| 661 | Str255 name;
|
|---|
| 662 | Handle settings;
|
|---|
| 663 | if (!PyArg_ParseTuple(_args, "O&O&",
|
|---|
| 664 | PyMac_GetOSType, &theType,
|
|---|
| 665 | ResObj_Convert, &settings))
|
|---|
| 666 | return NULL;
|
|---|
| 667 | _err = GetSoundPreference(theType,
|
|---|
| 668 | name,
|
|---|
| 669 | settings);
|
|---|
| 670 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 671 | _res = Py_BuildValue("O&",
|
|---|
| 672 | PyMac_BuildStr255, name);
|
|---|
| 673 | return _res;
|
|---|
| 674 | }
|
|---|
| 675 |
|
|---|
| 676 | static PyObject *Snd_GetCompressionName(PyObject *_self, PyObject *_args)
|
|---|
| 677 | {
|
|---|
| 678 | PyObject *_res = NULL;
|
|---|
| 679 | OSErr _err;
|
|---|
| 680 | OSType compressionType;
|
|---|
| 681 | Str255 compressionName;
|
|---|
| 682 | if (!PyArg_ParseTuple(_args, "O&",
|
|---|
| 683 | PyMac_GetOSType, &compressionType))
|
|---|
| 684 | return NULL;
|
|---|
| 685 | _err = GetCompressionName(compressionType,
|
|---|
| 686 | compressionName);
|
|---|
| 687 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 688 | _res = Py_BuildValue("O&",
|
|---|
| 689 | PyMac_BuildStr255, compressionName);
|
|---|
| 690 | return _res;
|
|---|
| 691 | }
|
|---|
| 692 |
|
|---|
| 693 | static PyObject *Snd_SPBVersion(PyObject *_self, PyObject *_args)
|
|---|
| 694 | {
|
|---|
| 695 | PyObject *_res = NULL;
|
|---|
| 696 | NumVersion _rv;
|
|---|
| 697 | if (!PyArg_ParseTuple(_args, ""))
|
|---|
| 698 | return NULL;
|
|---|
| 699 | _rv = SPBVersion();
|
|---|
| 700 | _res = Py_BuildValue("O&",
|
|---|
| 701 | PyMac_BuildNumVersion, _rv);
|
|---|
| 702 | return _res;
|
|---|
| 703 | }
|
|---|
| 704 |
|
|---|
| 705 | static PyObject *Snd_SndRecord(PyObject *_self, PyObject *_args)
|
|---|
| 706 | {
|
|---|
| 707 | PyObject *_res = NULL;
|
|---|
| 708 | OSErr _err;
|
|---|
| 709 | Point corner;
|
|---|
| 710 | OSType quality;
|
|---|
| 711 | SndListHandle sndHandle;
|
|---|
| 712 | if (!PyArg_ParseTuple(_args, "O&O&",
|
|---|
| 713 | PyMac_GetPoint, &corner,
|
|---|
| 714 | PyMac_GetOSType, &quality))
|
|---|
| 715 | return NULL;
|
|---|
| 716 | _err = SndRecord((ModalFilterUPP)0,
|
|---|
| 717 | corner,
|
|---|
| 718 | quality,
|
|---|
| 719 | &sndHandle);
|
|---|
| 720 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 721 | _res = Py_BuildValue("O&",
|
|---|
| 722 | ResObj_New, sndHandle);
|
|---|
| 723 | return _res;
|
|---|
| 724 | }
|
|---|
| 725 |
|
|---|
| 726 | static PyObject *Snd_SPBSignInDevice(PyObject *_self, PyObject *_args)
|
|---|
| 727 | {
|
|---|
| 728 | PyObject *_res = NULL;
|
|---|
| 729 | OSErr _err;
|
|---|
| 730 | short deviceRefNum;
|
|---|
| 731 | Str255 deviceName;
|
|---|
| 732 | if (!PyArg_ParseTuple(_args, "hO&",
|
|---|
| 733 | &deviceRefNum,
|
|---|
| 734 | PyMac_GetStr255, deviceName))
|
|---|
| 735 | return NULL;
|
|---|
| 736 | _err = SPBSignInDevice(deviceRefNum,
|
|---|
| 737 | deviceName);
|
|---|
| 738 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 739 | Py_INCREF(Py_None);
|
|---|
| 740 | _res = Py_None;
|
|---|
| 741 | return _res;
|
|---|
| 742 | }
|
|---|
| 743 |
|
|---|
| 744 | static PyObject *Snd_SPBSignOutDevice(PyObject *_self, PyObject *_args)
|
|---|
| 745 | {
|
|---|
| 746 | PyObject *_res = NULL;
|
|---|
| 747 | OSErr _err;
|
|---|
| 748 | short deviceRefNum;
|
|---|
| 749 | if (!PyArg_ParseTuple(_args, "h",
|
|---|
| 750 | &deviceRefNum))
|
|---|
| 751 | return NULL;
|
|---|
| 752 | _err = SPBSignOutDevice(deviceRefNum);
|
|---|
| 753 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 754 | Py_INCREF(Py_None);
|
|---|
| 755 | _res = Py_None;
|
|---|
| 756 | return _res;
|
|---|
| 757 | }
|
|---|
| 758 |
|
|---|
| 759 | static PyObject *Snd_SPBGetIndexedDevice(PyObject *_self, PyObject *_args)
|
|---|
| 760 | {
|
|---|
| 761 | PyObject *_res = NULL;
|
|---|
| 762 | OSErr _err;
|
|---|
| 763 | short count;
|
|---|
| 764 | Str255 deviceName;
|
|---|
| 765 | Handle deviceIconHandle;
|
|---|
| 766 | if (!PyArg_ParseTuple(_args, "h",
|
|---|
| 767 | &count))
|
|---|
| 768 | return NULL;
|
|---|
| 769 | _err = SPBGetIndexedDevice(count,
|
|---|
| 770 | deviceName,
|
|---|
| 771 | &deviceIconHandle);
|
|---|
| 772 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 773 | _res = Py_BuildValue("O&O&",
|
|---|
| 774 | PyMac_BuildStr255, deviceName,
|
|---|
| 775 | ResObj_New, deviceIconHandle);
|
|---|
| 776 | return _res;
|
|---|
| 777 | }
|
|---|
| 778 |
|
|---|
| 779 | static PyObject *Snd_SPBOpenDevice(PyObject *_self, PyObject *_args)
|
|---|
| 780 | {
|
|---|
| 781 | PyObject *_res = NULL;
|
|---|
| 782 | OSErr _err;
|
|---|
| 783 | Str255 deviceName;
|
|---|
| 784 | short permission;
|
|---|
| 785 | long inRefNum;
|
|---|
| 786 | if (!PyArg_ParseTuple(_args, "O&h",
|
|---|
| 787 | PyMac_GetStr255, deviceName,
|
|---|
| 788 | &permission))
|
|---|
| 789 | return NULL;
|
|---|
| 790 | _err = SPBOpenDevice(deviceName,
|
|---|
| 791 | permission,
|
|---|
| 792 | &inRefNum);
|
|---|
| 793 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 794 | _res = Py_BuildValue("l",
|
|---|
| 795 | inRefNum);
|
|---|
| 796 | return _res;
|
|---|
| 797 | }
|
|---|
| 798 |
|
|---|
| 799 | static PyObject *Snd_SPBCloseDevice(PyObject *_self, PyObject *_args)
|
|---|
| 800 | {
|
|---|
| 801 | PyObject *_res = NULL;
|
|---|
| 802 | OSErr _err;
|
|---|
| 803 | long inRefNum;
|
|---|
| 804 | if (!PyArg_ParseTuple(_args, "l",
|
|---|
| 805 | &inRefNum))
|
|---|
| 806 | return NULL;
|
|---|
| 807 | _err = SPBCloseDevice(inRefNum);
|
|---|
| 808 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 809 | Py_INCREF(Py_None);
|
|---|
| 810 | _res = Py_None;
|
|---|
| 811 | return _res;
|
|---|
| 812 | }
|
|---|
| 813 |
|
|---|
| 814 | static PyObject *Snd_SPBRecord(PyObject *_self, PyObject *_args)
|
|---|
| 815 | {
|
|---|
| 816 | PyObject *_res = NULL;
|
|---|
| 817 | OSErr _err;
|
|---|
| 818 | SPBPtr inParamPtr;
|
|---|
| 819 | Boolean asynchFlag;
|
|---|
| 820 | if (!PyArg_ParseTuple(_args, "O&b",
|
|---|
| 821 | SPBObj_Convert, &inParamPtr,
|
|---|
| 822 | &asynchFlag))
|
|---|
| 823 | return NULL;
|
|---|
| 824 | _err = SPBRecord(inParamPtr,
|
|---|
| 825 | asynchFlag);
|
|---|
| 826 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 827 | Py_INCREF(Py_None);
|
|---|
| 828 | _res = Py_None;
|
|---|
| 829 | return _res;
|
|---|
| 830 | }
|
|---|
| 831 |
|
|---|
| 832 | static PyObject *Snd_SPBPauseRecording(PyObject *_self, PyObject *_args)
|
|---|
| 833 | {
|
|---|
| 834 | PyObject *_res = NULL;
|
|---|
| 835 | OSErr _err;
|
|---|
| 836 | long inRefNum;
|
|---|
| 837 | if (!PyArg_ParseTuple(_args, "l",
|
|---|
| 838 | &inRefNum))
|
|---|
| 839 | return NULL;
|
|---|
| 840 | _err = SPBPauseRecording(inRefNum);
|
|---|
| 841 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 842 | Py_INCREF(Py_None);
|
|---|
| 843 | _res = Py_None;
|
|---|
| 844 | return _res;
|
|---|
| 845 | }
|
|---|
| 846 |
|
|---|
| 847 | static PyObject *Snd_SPBResumeRecording(PyObject *_self, PyObject *_args)
|
|---|
| 848 | {
|
|---|
| 849 | PyObject *_res = NULL;
|
|---|
| 850 | OSErr _err;
|
|---|
| 851 | long inRefNum;
|
|---|
| 852 | if (!PyArg_ParseTuple(_args, "l",
|
|---|
| 853 | &inRefNum))
|
|---|
| 854 | return NULL;
|
|---|
| 855 | _err = SPBResumeRecording(inRefNum);
|
|---|
| 856 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 857 | Py_INCREF(Py_None);
|
|---|
| 858 | _res = Py_None;
|
|---|
| 859 | return _res;
|
|---|
| 860 | }
|
|---|
| 861 |
|
|---|
| 862 | static PyObject *Snd_SPBStopRecording(PyObject *_self, PyObject *_args)
|
|---|
| 863 | {
|
|---|
| 864 | PyObject *_res = NULL;
|
|---|
| 865 | OSErr _err;
|
|---|
| 866 | long inRefNum;
|
|---|
| 867 | if (!PyArg_ParseTuple(_args, "l",
|
|---|
| 868 | &inRefNum))
|
|---|
| 869 | return NULL;
|
|---|
| 870 | _err = SPBStopRecording(inRefNum);
|
|---|
| 871 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 872 | Py_INCREF(Py_None);
|
|---|
| 873 | _res = Py_None;
|
|---|
| 874 | return _res;
|
|---|
| 875 | }
|
|---|
| 876 |
|
|---|
| 877 | static PyObject *Snd_SPBGetRecordingStatus(PyObject *_self, PyObject *_args)
|
|---|
| 878 | {
|
|---|
| 879 | PyObject *_res = NULL;
|
|---|
| 880 | OSErr _err;
|
|---|
| 881 | long inRefNum;
|
|---|
| 882 | short recordingStatus;
|
|---|
| 883 | short meterLevel;
|
|---|
| 884 | unsigned long totalSamplesToRecord;
|
|---|
| 885 | unsigned long numberOfSamplesRecorded;
|
|---|
| 886 | unsigned long totalMsecsToRecord;
|
|---|
| 887 | unsigned long numberOfMsecsRecorded;
|
|---|
| 888 | if (!PyArg_ParseTuple(_args, "l",
|
|---|
| 889 | &inRefNum))
|
|---|
| 890 | return NULL;
|
|---|
| 891 | _err = SPBGetRecordingStatus(inRefNum,
|
|---|
| 892 | &recordingStatus,
|
|---|
| 893 | &meterLevel,
|
|---|
| 894 | &totalSamplesToRecord,
|
|---|
| 895 | &numberOfSamplesRecorded,
|
|---|
| 896 | &totalMsecsToRecord,
|
|---|
| 897 | &numberOfMsecsRecorded);
|
|---|
| 898 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 899 | _res = Py_BuildValue("hhllll",
|
|---|
| 900 | recordingStatus,
|
|---|
| 901 | meterLevel,
|
|---|
| 902 | totalSamplesToRecord,
|
|---|
| 903 | numberOfSamplesRecorded,
|
|---|
| 904 | totalMsecsToRecord,
|
|---|
| 905 | numberOfMsecsRecorded);
|
|---|
| 906 | return _res;
|
|---|
| 907 | }
|
|---|
| 908 |
|
|---|
| 909 | static PyObject *Snd_SPBGetDeviceInfo(PyObject *_self, PyObject *_args)
|
|---|
| 910 | {
|
|---|
| 911 | PyObject *_res = NULL;
|
|---|
| 912 | OSErr _err;
|
|---|
| 913 | long inRefNum;
|
|---|
| 914 | OSType infoType;
|
|---|
| 915 | void * infoData;
|
|---|
| 916 | if (!PyArg_ParseTuple(_args, "lO&w",
|
|---|
| 917 | &inRefNum,
|
|---|
| 918 | PyMac_GetOSType, &infoType,
|
|---|
| 919 | &infoData))
|
|---|
| 920 | return NULL;
|
|---|
| 921 | _err = SPBGetDeviceInfo(inRefNum,
|
|---|
| 922 | infoType,
|
|---|
| 923 | infoData);
|
|---|
| 924 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 925 | Py_INCREF(Py_None);
|
|---|
| 926 | _res = Py_None;
|
|---|
| 927 | return _res;
|
|---|
| 928 | }
|
|---|
| 929 |
|
|---|
| 930 | static PyObject *Snd_SPBSetDeviceInfo(PyObject *_self, PyObject *_args)
|
|---|
| 931 | {
|
|---|
| 932 | PyObject *_res = NULL;
|
|---|
| 933 | OSErr _err;
|
|---|
| 934 | long inRefNum;
|
|---|
| 935 | OSType infoType;
|
|---|
| 936 | void * infoData;
|
|---|
| 937 | if (!PyArg_ParseTuple(_args, "lO&w",
|
|---|
| 938 | &inRefNum,
|
|---|
| 939 | PyMac_GetOSType, &infoType,
|
|---|
| 940 | &infoData))
|
|---|
| 941 | return NULL;
|
|---|
| 942 | _err = SPBSetDeviceInfo(inRefNum,
|
|---|
| 943 | infoType,
|
|---|
| 944 | infoData);
|
|---|
| 945 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 946 | Py_INCREF(Py_None);
|
|---|
| 947 | _res = Py_None;
|
|---|
| 948 | return _res;
|
|---|
| 949 | }
|
|---|
| 950 |
|
|---|
| 951 | static PyObject *Snd_SPBMillisecondsToBytes(PyObject *_self, PyObject *_args)
|
|---|
| 952 | {
|
|---|
| 953 | PyObject *_res = NULL;
|
|---|
| 954 | OSErr _err;
|
|---|
| 955 | long inRefNum;
|
|---|
| 956 | long milliseconds;
|
|---|
| 957 | if (!PyArg_ParseTuple(_args, "l",
|
|---|
| 958 | &inRefNum))
|
|---|
| 959 | return NULL;
|
|---|
| 960 | _err = SPBMillisecondsToBytes(inRefNum,
|
|---|
| 961 | &milliseconds);
|
|---|
| 962 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 963 | _res = Py_BuildValue("l",
|
|---|
| 964 | milliseconds);
|
|---|
| 965 | return _res;
|
|---|
| 966 | }
|
|---|
| 967 |
|
|---|
| 968 | static PyObject *Snd_SPBBytesToMilliseconds(PyObject *_self, PyObject *_args)
|
|---|
| 969 | {
|
|---|
| 970 | PyObject *_res = NULL;
|
|---|
| 971 | OSErr _err;
|
|---|
| 972 | long inRefNum;
|
|---|
| 973 | long byteCount;
|
|---|
| 974 | if (!PyArg_ParseTuple(_args, "l",
|
|---|
| 975 | &inRefNum))
|
|---|
| 976 | return NULL;
|
|---|
| 977 | _err = SPBBytesToMilliseconds(inRefNum,
|
|---|
| 978 | &byteCount);
|
|---|
| 979 | if (_err != noErr) return PyMac_Error(_err);
|
|---|
| 980 | _res = Py_BuildValue("l",
|
|---|
| 981 | byteCount);
|
|---|
| 982 | return _res;
|
|---|
| 983 | }
|
|---|
| 984 |
|
|---|
| 985 | static PyMethodDef Snd_methods[] = {
|
|---|
| 986 | {"SPB", (PyCFunction)Snd_SPB, 1,
|
|---|
| 987 | PyDoc_STR(NULL)},
|
|---|
| 988 | {"SysBeep", (PyCFunction)Snd_SysBeep, 1,
|
|---|
| 989 | PyDoc_STR("(short duration) -> None")},
|
|---|
| 990 | {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1,
|
|---|
| 991 | PyDoc_STR("(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)")},
|
|---|
| 992 | {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1,
|
|---|
| 993 | PyDoc_STR("() -> (NumVersion _rv)")},
|
|---|
| 994 | {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1,
|
|---|
| 995 | PyDoc_STR("(short theLength) -> (SMStatus theStatus)")},
|
|---|
| 996 | {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1,
|
|---|
| 997 | PyDoc_STR("() -> (short sysBeepState)")},
|
|---|
| 998 | {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1,
|
|---|
| 999 | PyDoc_STR("(short sysBeepState) -> None")},
|
|---|
| 1000 | {"GetSysBeepVolume", (PyCFunction)Snd_GetSysBeepVolume, 1,
|
|---|
| 1001 | PyDoc_STR("() -> (long level)")},
|
|---|
| 1002 | {"SetSysBeepVolume", (PyCFunction)Snd_SetSysBeepVolume, 1,
|
|---|
| 1003 | PyDoc_STR("(long level) -> None")},
|
|---|
| 1004 | {"GetDefaultOutputVolume", (PyCFunction)Snd_GetDefaultOutputVolume, 1,
|
|---|
| 1005 | PyDoc_STR("() -> (long level)")},
|
|---|
| 1006 | {"SetDefaultOutputVolume", (PyCFunction)Snd_SetDefaultOutputVolume, 1,
|
|---|
| 1007 | PyDoc_STR("(long level) -> None")},
|
|---|
| 1008 | {"GetSoundHeaderOffset", (PyCFunction)Snd_GetSoundHeaderOffset, 1,
|
|---|
| 1009 | PyDoc_STR("(SndListHandle sndHandle) -> (long offset)")},
|
|---|
| 1010 | {"GetCompressionInfo", (PyCFunction)Snd_GetCompressionInfo, 1,
|
|---|
| 1011 | PyDoc_STR("(short compressionID, OSType format, short numChannels, short sampleSize) -> (CompressionInfo cp)")},
|
|---|
| 1012 | {"SetSoundPreference", (PyCFunction)Snd_SetSoundPreference, 1,
|
|---|
| 1013 | PyDoc_STR("(OSType theType, Handle settings) -> (Str255 name)")},
|
|---|
| 1014 | {"GetSoundPreference", (PyCFunction)Snd_GetSoundPreference, 1,
|
|---|
| 1015 | PyDoc_STR("(OSType theType, Handle settings) -> (Str255 name)")},
|
|---|
| 1016 | {"GetCompressionName", (PyCFunction)Snd_GetCompressionName, 1,
|
|---|
| 1017 | PyDoc_STR("(OSType compressionType) -> (Str255 compressionName)")},
|
|---|
| 1018 | {"SPBVersion", (PyCFunction)Snd_SPBVersion, 1,
|
|---|
| 1019 | PyDoc_STR("() -> (NumVersion _rv)")},
|
|---|
| 1020 | {"SndRecord", (PyCFunction)Snd_SndRecord, 1,
|
|---|
| 1021 | PyDoc_STR("(Point corner, OSType quality) -> (SndListHandle sndHandle)")},
|
|---|
| 1022 | {"SPBSignInDevice", (PyCFunction)Snd_SPBSignInDevice, 1,
|
|---|
| 1023 | PyDoc_STR("(short deviceRefNum, Str255 deviceName) -> None")},
|
|---|
| 1024 | {"SPBSignOutDevice", (PyCFunction)Snd_SPBSignOutDevice, 1,
|
|---|
| 1025 | PyDoc_STR("(short deviceRefNum) -> None")},
|
|---|
| 1026 | {"SPBGetIndexedDevice", (PyCFunction)Snd_SPBGetIndexedDevice, 1,
|
|---|
| 1027 | PyDoc_STR("(short count) -> (Str255 deviceName, Handle deviceIconHandle)")},
|
|---|
| 1028 | {"SPBOpenDevice", (PyCFunction)Snd_SPBOpenDevice, 1,
|
|---|
| 1029 | PyDoc_STR("(Str255 deviceName, short permission) -> (long inRefNum)")},
|
|---|
| 1030 | {"SPBCloseDevice", (PyCFunction)Snd_SPBCloseDevice, 1,
|
|---|
| 1031 | PyDoc_STR("(long inRefNum) -> None")},
|
|---|
| 1032 | {"SPBRecord", (PyCFunction)Snd_SPBRecord, 1,
|
|---|
| 1033 | PyDoc_STR("(SPBPtr inParamPtr, Boolean asynchFlag) -> None")},
|
|---|
| 1034 | {"SPBPauseRecording", (PyCFunction)Snd_SPBPauseRecording, 1,
|
|---|
| 1035 | PyDoc_STR("(long inRefNum) -> None")},
|
|---|
| 1036 | {"SPBResumeRecording", (PyCFunction)Snd_SPBResumeRecording, 1,
|
|---|
| 1037 | PyDoc_STR("(long inRefNum) -> None")},
|
|---|
| 1038 | {"SPBStopRecording", (PyCFunction)Snd_SPBStopRecording, 1,
|
|---|
| 1039 | PyDoc_STR("(long inRefNum) -> None")},
|
|---|
| 1040 | {"SPBGetRecordingStatus", (PyCFunction)Snd_SPBGetRecordingStatus, 1,
|
|---|
| 1041 | PyDoc_STR("(long inRefNum) -> (short recordingStatus, short meterLevel, unsigned long totalSamplesToRecord, unsigned long numberOfSamplesRecorded, unsigned long totalMsecsToRecord, unsigned long numberOfMsecsRecorded)")},
|
|---|
| 1042 | {"SPBGetDeviceInfo", (PyCFunction)Snd_SPBGetDeviceInfo, 1,
|
|---|
| 1043 | PyDoc_STR("(long inRefNum, OSType infoType, void * infoData) -> None")},
|
|---|
| 1044 | {"SPBSetDeviceInfo", (PyCFunction)Snd_SPBSetDeviceInfo, 1,
|
|---|
| 1045 | PyDoc_STR("(long inRefNum, OSType infoType, void * infoData) -> None")},
|
|---|
| 1046 | {"SPBMillisecondsToBytes", (PyCFunction)Snd_SPBMillisecondsToBytes, 1,
|
|---|
| 1047 | PyDoc_STR("(long inRefNum) -> (long milliseconds)")},
|
|---|
| 1048 | {"SPBBytesToMilliseconds", (PyCFunction)Snd_SPBBytesToMilliseconds, 1,
|
|---|
| 1049 | PyDoc_STR("(long inRefNum) -> (long byteCount)")},
|
|---|
| 1050 | {NULL, NULL, 0}
|
|---|
| 1051 | };
|
|---|
| 1052 |
|
|---|
| 1053 |
|
|---|
| 1054 |
|
|---|
| 1055 | /* Routine passed to Py_AddPendingCall -- call the Python callback */
|
|---|
| 1056 | static int
|
|---|
| 1057 | SndCh_CallCallBack(void *arg)
|
|---|
| 1058 | {
|
|---|
| 1059 | SndChannelObject *p = (SndChannelObject *)arg;
|
|---|
| 1060 | PyObject *args;
|
|---|
| 1061 | PyObject *res;
|
|---|
| 1062 | args = Py_BuildValue("(O(hhl))",
|
|---|
| 1063 | p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2);
|
|---|
| 1064 | res = PyEval_CallObject(p->ob_callback, args);
|
|---|
| 1065 | Py_DECREF(args);
|
|---|
| 1066 | if (res == NULL)
|
|---|
| 1067 | return -1;
|
|---|
| 1068 | Py_DECREF(res);
|
|---|
| 1069 | return 0;
|
|---|
| 1070 | }
|
|---|
| 1071 |
|
|---|
| 1072 | /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */
|
|---|
| 1073 | static pascal void
|
|---|
| 1074 | SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd)
|
|---|
| 1075 | {
|
|---|
| 1076 | SndChannelObject *p = (SndChannelObject *)(chan->userInfo);
|
|---|
| 1077 | if (p->ob_callback != NULL) {
|
|---|
| 1078 | long A5 = SetA5(p->ob_A5);
|
|---|
| 1079 | p->ob_cmd = *cmd;
|
|---|
| 1080 | Py_AddPendingCall(SndCh_CallCallBack, (void *)p);
|
|---|
| 1081 | SetA5(A5);
|
|---|
| 1082 | }
|
|---|
| 1083 | }
|
|---|
| 1084 |
|
|---|
| 1085 | /* SPB callbacks - Schedule callbacks to Python */
|
|---|
| 1086 | static int
|
|---|
| 1087 | SPB_CallCallBack(void *arg)
|
|---|
| 1088 | {
|
|---|
| 1089 | SPBObject *p = (SPBObject *)arg;
|
|---|
| 1090 | PyObject *args;
|
|---|
| 1091 | PyObject *res;
|
|---|
| 1092 |
|
|---|
| 1093 | if ( p->ob_thiscallback == 0 ) return 0;
|
|---|
| 1094 | args = Py_BuildValue("(O)", p);
|
|---|
| 1095 | res = PyEval_CallObject(p->ob_thiscallback, args);
|
|---|
| 1096 | p->ob_thiscallback = 0;
|
|---|
| 1097 | Py_DECREF(args);
|
|---|
| 1098 | if (res == NULL)
|
|---|
| 1099 | return -1;
|
|---|
| 1100 | Py_DECREF(res);
|
|---|
| 1101 | return 0;
|
|---|
| 1102 | }
|
|---|
| 1103 |
|
|---|
| 1104 | static pascal void
|
|---|
| 1105 | SPB_completion(SPBPtr my_spb)
|
|---|
| 1106 | {
|
|---|
| 1107 | SPBObject *p = (SPBObject *)(my_spb->userLong);
|
|---|
| 1108 |
|
|---|
| 1109 | if (p && p->ob_completion) {
|
|---|
| 1110 | long A5 = SetA5(p->ob_A5);
|
|---|
| 1111 | p->ob_thiscallback = p->ob_completion; /* Hope we cannot get two at the same time */
|
|---|
| 1112 | Py_AddPendingCall(SPB_CallCallBack, (void *)p);
|
|---|
| 1113 | SetA5(A5);
|
|---|
| 1114 | }
|
|---|
| 1115 | }
|
|---|
| 1116 |
|
|---|
| 1117 |
|
|---|
| 1118 |
|
|---|
| 1119 | void init_Snd(void)
|
|---|
| 1120 | {
|
|---|
| 1121 | PyObject *m;
|
|---|
| 1122 | PyObject *d;
|
|---|
| 1123 |
|
|---|
| 1124 |
|
|---|
| 1125 |
|
|---|
| 1126 |
|
|---|
| 1127 |
|
|---|
| 1128 | m = Py_InitModule("_Snd", Snd_methods);
|
|---|
| 1129 | d = PyModule_GetDict(m);
|
|---|
| 1130 | Snd_Error = PyMac_GetOSErrException();
|
|---|
| 1131 | if (Snd_Error == NULL ||
|
|---|
| 1132 | PyDict_SetItemString(d, "Error", Snd_Error) != 0)
|
|---|
| 1133 | return;
|
|---|
| 1134 | SndChannel_Type.ob_type = &PyType_Type;
|
|---|
| 1135 | if (PyType_Ready(&SndChannel_Type) < 0) return;
|
|---|
| 1136 | Py_INCREF(&SndChannel_Type);
|
|---|
| 1137 | PyModule_AddObject(m, "SndChannel", (PyObject *)&SndChannel_Type);
|
|---|
| 1138 | /* Backward-compatible name */
|
|---|
| 1139 | Py_INCREF(&SndChannel_Type);
|
|---|
| 1140 | PyModule_AddObject(m, "SndChannelType", (PyObject *)&SndChannel_Type);
|
|---|
| 1141 | SPB_Type.ob_type = &PyType_Type;
|
|---|
| 1142 | if (PyType_Ready(&SPB_Type) < 0) return;
|
|---|
| 1143 | Py_INCREF(&SPB_Type);
|
|---|
| 1144 | PyModule_AddObject(m, "SPB", (PyObject *)&SPB_Type);
|
|---|
| 1145 | /* Backward-compatible name */
|
|---|
| 1146 | Py_INCREF(&SPB_Type);
|
|---|
| 1147 | PyModule_AddObject(m, "SPBType", (PyObject *)&SPB_Type);
|
|---|
| 1148 | }
|
|---|
| 1149 |
|
|---|
| 1150 | /* ======================== End module _Snd ========================= */
|
|---|
| 1151 |
|
|---|