Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | |
| 2 | /* =========================== Module Snd =========================== */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | |
| 7 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 8 | #include "macglue.h" |
Jack Jansen | 9d8b96c | 2000-07-14 22:16:45 +0000 | [diff] [blame] | 9 | #include "pymactoolbox.h" |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 10 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 11 | #include <Sound.h> |
| 12 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 13 | #include <OSUtils.h> /* for Set(Current)A5 */ |
| 14 | |
| 15 | /* Create a SndCommand object (an (int, int, int) tuple) */ |
| 16 | static PyObject * |
| 17 | SndCmd_New(SndCommand *pc) |
| 18 | { |
| 19 | return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2); |
| 20 | } |
| 21 | |
| 22 | /* Convert a SndCommand argument */ |
| 23 | static int |
| 24 | SndCmd_Convert(PyObject *v, SndCommand *pc) |
| 25 | { |
| 26 | int len; |
| 27 | pc->param1 = 0; |
| 28 | pc->param2 = 0; |
| 29 | if (PyTuple_Check(v)) { |
| 30 | if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2)) |
| 31 | return 1; |
| 32 | PyErr_Clear(); |
Jack Jansen | 0b13e7c | 2000-07-07 13:09:35 +0000 | [diff] [blame] | 33 | return PyArg_ParseTuple(v, "Hhs#", &pc->cmd, &pc->param1, &pc->param2, &len); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 34 | } |
Jack Jansen | 0b13e7c | 2000-07-07 13:09:35 +0000 | [diff] [blame] | 35 | return PyArg_Parse(v, "H", &pc->cmd); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 38 | static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */ |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 39 | static pascal void SPB_completion(SPBPtr my_spb); /* Forward */ |
| 40 | static pascal void SPB_interrupt(SPBPtr my_spb); /* Forward */ |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 41 | |
| 42 | static PyObject *Snd_Error; |
| 43 | |
| 44 | /* --------------------- Object type SndChannel --------------------- */ |
| 45 | |
| 46 | staticforward PyTypeObject SndChannel_Type; |
| 47 | |
| 48 | #define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type) |
| 49 | |
| 50 | typedef struct SndChannelObject { |
| 51 | PyObject_HEAD |
| 52 | SndChannelPtr ob_itself; |
| 53 | /* Members used to implement callbacks: */ |
| 54 | PyObject *ob_callback; |
| 55 | long ob_A5; |
| 56 | SndCommand ob_cmd; |
| 57 | } SndChannelObject; |
| 58 | |
| 59 | static PyObject *SndCh_New(itself) |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 60 | SndChannelPtr itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 61 | { |
| 62 | SndChannelObject *it; |
| 63 | it = PyObject_NEW(SndChannelObject, &SndChannel_Type); |
| 64 | if (it == NULL) return NULL; |
| 65 | it->ob_itself = itself; |
| 66 | it->ob_callback = NULL; |
| 67 | it->ob_A5 = SetCurrentA5(); |
| 68 | return (PyObject *)it; |
| 69 | } |
| 70 | static SndCh_Convert(v, p_itself) |
| 71 | PyObject *v; |
| 72 | SndChannelPtr *p_itself; |
| 73 | { |
| 74 | if (!SndCh_Check(v)) |
| 75 | { |
| 76 | PyErr_SetString(PyExc_TypeError, "SndChannel required"); |
| 77 | return 0; |
| 78 | } |
| 79 | *p_itself = ((SndChannelObject *)v)->ob_itself; |
| 80 | return 1; |
| 81 | } |
| 82 | |
| 83 | static void SndCh_dealloc(self) |
| 84 | SndChannelObject *self; |
| 85 | { |
| 86 | SndDisposeChannel(self->ob_itself, 1); |
| 87 | Py_XDECREF(self->ob_callback); |
| 88 | PyMem_DEL(self); |
| 89 | } |
| 90 | |
| 91 | static PyObject *SndCh_SndDoCommand(_self, _args) |
| 92 | SndChannelObject *_self; |
| 93 | PyObject *_args; |
| 94 | { |
| 95 | PyObject *_res = NULL; |
| 96 | OSErr _err; |
| 97 | SndCommand cmd; |
| 98 | Boolean noWait; |
| 99 | if (!PyArg_ParseTuple(_args, "O&b", |
| 100 | SndCmd_Convert, &cmd, |
| 101 | &noWait)) |
| 102 | return NULL; |
| 103 | _err = SndDoCommand(_self->ob_itself, |
| 104 | &cmd, |
| 105 | noWait); |
| 106 | if (_err != noErr) return PyMac_Error(_err); |
| 107 | Py_INCREF(Py_None); |
| 108 | _res = Py_None; |
| 109 | return _res; |
| 110 | } |
| 111 | |
| 112 | static PyObject *SndCh_SndDoImmediate(_self, _args) |
| 113 | SndChannelObject *_self; |
| 114 | PyObject *_args; |
| 115 | { |
| 116 | PyObject *_res = NULL; |
| 117 | OSErr _err; |
| 118 | SndCommand cmd; |
| 119 | if (!PyArg_ParseTuple(_args, "O&", |
| 120 | SndCmd_Convert, &cmd)) |
| 121 | return NULL; |
| 122 | _err = SndDoImmediate(_self->ob_itself, |
| 123 | &cmd); |
| 124 | if (_err != noErr) return PyMac_Error(_err); |
| 125 | Py_INCREF(Py_None); |
| 126 | _res = Py_None; |
| 127 | return _res; |
| 128 | } |
| 129 | |
| 130 | static PyObject *SndCh_SndPlay(_self, _args) |
| 131 | SndChannelObject *_self; |
| 132 | PyObject *_args; |
| 133 | { |
| 134 | PyObject *_res = NULL; |
| 135 | OSErr _err; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 136 | SndListHandle sndHandle; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 137 | Boolean async; |
| 138 | if (!PyArg_ParseTuple(_args, "O&b", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 139 | ResObj_Convert, &sndHandle, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 140 | &async)) |
| 141 | return NULL; |
| 142 | _err = SndPlay(_self->ob_itself, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 143 | sndHandle, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 144 | async); |
| 145 | if (_err != noErr) return PyMac_Error(_err); |
| 146 | Py_INCREF(Py_None); |
| 147 | _res = Py_None; |
| 148 | return _res; |
| 149 | } |
| 150 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 151 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 152 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 153 | static PyObject *SndCh_SndStartFilePlay(_self, _args) |
| 154 | SndChannelObject *_self; |
| 155 | PyObject *_args; |
| 156 | { |
| 157 | PyObject *_res = NULL; |
| 158 | OSErr _err; |
| 159 | short fRefNum; |
| 160 | short resNum; |
| 161 | long bufferSize; |
| 162 | Boolean async; |
| 163 | if (!PyArg_ParseTuple(_args, "hhlb", |
| 164 | &fRefNum, |
| 165 | &resNum, |
| 166 | &bufferSize, |
| 167 | &async)) |
| 168 | return NULL; |
| 169 | _err = SndStartFilePlay(_self->ob_itself, |
| 170 | fRefNum, |
| 171 | resNum, |
| 172 | bufferSize, |
| 173 | 0, |
| 174 | 0, |
| 175 | 0, |
| 176 | async); |
| 177 | if (_err != noErr) return PyMac_Error(_err); |
| 178 | Py_INCREF(Py_None); |
| 179 | _res = Py_None; |
| 180 | return _res; |
| 181 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 182 | #endif |
| 183 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 184 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 185 | |
| 186 | static PyObject *SndCh_SndPauseFilePlay(_self, _args) |
| 187 | SndChannelObject *_self; |
| 188 | PyObject *_args; |
| 189 | { |
| 190 | PyObject *_res = NULL; |
| 191 | OSErr _err; |
| 192 | if (!PyArg_ParseTuple(_args, "")) |
| 193 | return NULL; |
| 194 | _err = SndPauseFilePlay(_self->ob_itself); |
| 195 | if (_err != noErr) return PyMac_Error(_err); |
| 196 | Py_INCREF(Py_None); |
| 197 | _res = Py_None; |
| 198 | return _res; |
| 199 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 200 | #endif |
| 201 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 202 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 203 | |
| 204 | static PyObject *SndCh_SndStopFilePlay(_self, _args) |
| 205 | SndChannelObject *_self; |
| 206 | PyObject *_args; |
| 207 | { |
| 208 | PyObject *_res = NULL; |
| 209 | OSErr _err; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 210 | Boolean quietNow; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 211 | if (!PyArg_ParseTuple(_args, "b", |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 212 | &quietNow)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 213 | return NULL; |
| 214 | _err = SndStopFilePlay(_self->ob_itself, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 215 | quietNow); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 216 | if (_err != noErr) return PyMac_Error(_err); |
| 217 | Py_INCREF(Py_None); |
| 218 | _res = Py_None; |
| 219 | return _res; |
| 220 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 221 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 222 | |
| 223 | static PyObject *SndCh_SndChannelStatus(_self, _args) |
| 224 | SndChannelObject *_self; |
| 225 | PyObject *_args; |
| 226 | { |
| 227 | PyObject *_res = NULL; |
| 228 | OSErr _err; |
| 229 | short theLength; |
| 230 | SCStatus theStatus__out__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 231 | if (!PyArg_ParseTuple(_args, "h", |
| 232 | &theLength)) |
| 233 | return NULL; |
| 234 | _err = SndChannelStatus(_self->ob_itself, |
| 235 | theLength, |
| 236 | &theStatus__out__); |
| 237 | if (_err != noErr) return PyMac_Error(_err); |
| 238 | _res = Py_BuildValue("s#", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 239 | (char *)&theStatus__out__, (int)sizeof(SCStatus)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 240 | theStatus__error__: ; |
| 241 | return _res; |
| 242 | } |
| 243 | |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 244 | static PyObject *SndCh_SndGetInfo(_self, _args) |
| 245 | SndChannelObject *_self; |
| 246 | PyObject *_args; |
| 247 | { |
| 248 | PyObject *_res = NULL; |
| 249 | OSErr _err; |
| 250 | OSType selector; |
| 251 | void * infoPtr; |
| 252 | if (!PyArg_ParseTuple(_args, "O&w", |
| 253 | PyMac_GetOSType, &selector, |
| 254 | &infoPtr)) |
| 255 | return NULL; |
| 256 | _err = SndGetInfo(_self->ob_itself, |
| 257 | selector, |
| 258 | infoPtr); |
| 259 | if (_err != noErr) return PyMac_Error(_err); |
| 260 | Py_INCREF(Py_None); |
| 261 | _res = Py_None; |
| 262 | return _res; |
| 263 | } |
| 264 | |
| 265 | static PyObject *SndCh_SndSetInfo(_self, _args) |
| 266 | SndChannelObject *_self; |
| 267 | PyObject *_args; |
| 268 | { |
| 269 | PyObject *_res = NULL; |
| 270 | OSErr _err; |
| 271 | OSType selector; |
| 272 | void * infoPtr; |
| 273 | if (!PyArg_ParseTuple(_args, "O&w", |
| 274 | PyMac_GetOSType, &selector, |
| 275 | &infoPtr)) |
| 276 | return NULL; |
| 277 | _err = SndSetInfo(_self->ob_itself, |
| 278 | selector, |
| 279 | infoPtr); |
| 280 | if (_err != noErr) return PyMac_Error(_err); |
| 281 | Py_INCREF(Py_None); |
| 282 | _res = Py_None; |
| 283 | return _res; |
| 284 | } |
| 285 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 286 | static PyMethodDef SndCh_methods[] = { |
| 287 | {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1, |
| 288 | "(SndCommand cmd, Boolean noWait) -> None"}, |
| 289 | {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1, |
| 290 | "(SndCommand cmd) -> None"}, |
| 291 | {"SndPlay", (PyCFunction)SndCh_SndPlay, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 292 | "(SndListHandle sndHandle, Boolean async) -> None"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 293 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 294 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 295 | {"SndStartFilePlay", (PyCFunction)SndCh_SndStartFilePlay, 1, |
| 296 | "(short fRefNum, short resNum, long bufferSize, Boolean async) -> None"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 297 | #endif |
| 298 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 299 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 300 | {"SndPauseFilePlay", (PyCFunction)SndCh_SndPauseFilePlay, 1, |
| 301 | "() -> None"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 302 | #endif |
| 303 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 304 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 305 | {"SndStopFilePlay", (PyCFunction)SndCh_SndStopFilePlay, 1, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 306 | "(Boolean quietNow) -> None"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 307 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 308 | {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1, |
| 309 | "(short theLength) -> (SCStatus theStatus)"}, |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 310 | {"SndGetInfo", (PyCFunction)SndCh_SndGetInfo, 1, |
| 311 | "(OSType selector, void * infoPtr) -> None"}, |
| 312 | {"SndSetInfo", (PyCFunction)SndCh_SndSetInfo, 1, |
| 313 | "(OSType selector, void * infoPtr) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 314 | {NULL, NULL, 0} |
| 315 | }; |
| 316 | |
| 317 | static PyMethodChain SndCh_chain = { SndCh_methods, NULL }; |
| 318 | |
| 319 | static PyObject *SndCh_getattr(self, name) |
| 320 | SndChannelObject *self; |
| 321 | char *name; |
| 322 | { |
| 323 | return Py_FindMethodInChain(&SndCh_chain, (PyObject *)self, name); |
| 324 | } |
| 325 | |
| 326 | #define SndCh_setattr NULL |
| 327 | |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 328 | #define SndCh_compare NULL |
| 329 | |
| 330 | #define SndCh_repr NULL |
| 331 | |
| 332 | #define SndCh_hash NULL |
| 333 | |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 334 | staticforward PyTypeObject SndChannel_Type = { |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 335 | PyObject_HEAD_INIT(&PyType_Type) |
| 336 | 0, /*ob_size*/ |
| 337 | "SndChannel", /*tp_name*/ |
| 338 | sizeof(SndChannelObject), /*tp_basicsize*/ |
| 339 | 0, /*tp_itemsize*/ |
| 340 | /* methods */ |
| 341 | (destructor) SndCh_dealloc, /*tp_dealloc*/ |
| 342 | 0, /*tp_print*/ |
| 343 | (getattrfunc) SndCh_getattr, /*tp_getattr*/ |
| 344 | (setattrfunc) SndCh_setattr, /*tp_setattr*/ |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 345 | (cmpfunc) SndCh_compare, /*tp_compare*/ |
| 346 | (reprfunc) SndCh_repr, /*tp_repr*/ |
| 347 | (PyNumberMethods *)0, /* tp_as_number */ |
| 348 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 349 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 350 | (hashfunc) SndCh_hash, /*tp_hash*/ |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 351 | }; |
| 352 | |
| 353 | /* ------------------- End object type SndChannel ------------------- */ |
| 354 | |
| 355 | |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 356 | /* ------------------------ Object type SPB ------------------------- */ |
| 357 | |
| 358 | staticforward PyTypeObject SPB_Type; |
| 359 | |
| 360 | #define SPBObj_Check(x) ((x)->ob_type == &SPB_Type) |
| 361 | |
| 362 | typedef struct SPBObject { |
| 363 | PyObject_HEAD |
| 364 | /* Members used to implement callbacks: */ |
| 365 | PyObject *ob_completion; |
| 366 | PyObject *ob_interrupt; |
| 367 | PyObject *ob_thiscallback; |
| 368 | long ob_A5; |
| 369 | SPB ob_spb; |
| 370 | } SPBObject; |
| 371 | |
| 372 | static PyObject *SPBObj_New() |
| 373 | { |
| 374 | SPBObject *it; |
| 375 | it = PyObject_NEW(SPBObject, &SPB_Type); |
| 376 | if (it == NULL) return NULL; |
| 377 | it->ob_completion = NULL; |
| 378 | it->ob_interrupt = NULL; |
| 379 | it->ob_thiscallback = NULL; |
| 380 | it->ob_A5 = SetCurrentA5(); |
| 381 | memset((char *)&it->ob_spb, 0, sizeof(it->ob_spb)); |
| 382 | it->ob_spb.userLong = (long)it; |
| 383 | return (PyObject *)it; |
| 384 | } |
| 385 | static SPBObj_Convert(v, p_itself) |
| 386 | PyObject *v; |
| 387 | SPBPtr *p_itself; |
| 388 | { |
| 389 | if (!SPBObj_Check(v)) |
| 390 | { |
| 391 | PyErr_SetString(PyExc_TypeError, "SPB required"); |
| 392 | return 0; |
| 393 | } |
| 394 | *p_itself = &((SPBObject *)v)->ob_spb; |
| 395 | return 1; |
| 396 | } |
| 397 | |
| 398 | static void SPBObj_dealloc(self) |
| 399 | SPBObject *self; |
| 400 | { |
| 401 | /* Cleanup of self->ob_itself goes here */ |
| 402 | self->ob_spb.userLong = 0; |
| 403 | self->ob_thiscallback = 0; |
| 404 | Py_XDECREF(self->ob_completion); |
| 405 | Py_XDECREF(self->ob_interrupt); |
| 406 | PyMem_DEL(self); |
| 407 | } |
| 408 | |
| 409 | static PyMethodDef SPBObj_methods[] = { |
| 410 | {NULL, NULL, 0} |
| 411 | }; |
| 412 | |
| 413 | static PyMethodChain SPBObj_chain = { SPBObj_methods, NULL }; |
| 414 | |
| 415 | static PyObject *SPBObj_getattr(self, name) |
| 416 | SPBObject *self; |
| 417 | char *name; |
| 418 | { |
| 419 | |
| 420 | if (strcmp(name, "inRefNum") == 0) |
| 421 | return Py_BuildValue("l", self->ob_spb.inRefNum); |
| 422 | else if (strcmp(name, "count") == 0) |
| 423 | return Py_BuildValue("l", self->ob_spb.count); |
| 424 | else if (strcmp(name, "milliseconds") == 0) |
| 425 | return Py_BuildValue("l", self->ob_spb.milliseconds); |
| 426 | else if (strcmp(name, "error") == 0) |
| 427 | return Py_BuildValue("h", self->ob_spb.error); |
| 428 | return Py_FindMethodInChain(&SPBObj_chain, (PyObject *)self, name); |
| 429 | } |
| 430 | |
| 431 | static int SPBObj_setattr(self, name, value) |
| 432 | SPBObject *self; |
| 433 | char *name; |
| 434 | PyObject *value; |
| 435 | { |
| 436 | |
Jack Jansen | a239a92 | 1998-04-15 14:08:28 +0000 | [diff] [blame] | 437 | int rv = 0; |
| 438 | |
| 439 | if (strcmp(name, "inRefNum") == 0) |
| 440 | rv = PyArg_Parse(value, "l", &self->ob_spb.inRefNum); |
| 441 | else if (strcmp(name, "count") == 0) |
| 442 | rv = PyArg_Parse(value, "l", &self->ob_spb.count); |
| 443 | else if (strcmp(name, "milliseconds") == 0) |
| 444 | rv = PyArg_Parse(value, "l", &self->ob_spb.milliseconds); |
| 445 | else if (strcmp(name, "buffer") == 0) |
| 446 | rv = PyArg_Parse(value, "w#", &self->ob_spb.bufferPtr, &self->ob_spb.bufferLength); |
| 447 | else if (strcmp(name, "completionRoutine") == 0) { |
| 448 | self->ob_spb.completionRoutine = NewSICompletionProc(SPB_completion); |
| 449 | self->ob_completion = value; |
| 450 | Py_INCREF(value); |
| 451 | rv = 1; |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 452 | #if !TARGET_API_MAC_CARBON_NOTYET |
Jack Jansen | a239a92 | 1998-04-15 14:08:28 +0000 | [diff] [blame] | 453 | } else if (strcmp(name, "interruptRoutine") == 0) { |
| 454 | self->ob_spb.completionRoutine = NewSIInterruptProc(SPB_interrupt); |
| 455 | self->ob_interrupt = value; |
| 456 | Py_INCREF(value); |
| 457 | rv = 1; |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 458 | #endif |
Jack Jansen | a239a92 | 1998-04-15 14:08:28 +0000 | [diff] [blame] | 459 | } |
| 460 | if ( rv ) return 0; |
| 461 | else return -1; |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 464 | #define SPBObj_compare NULL |
| 465 | |
| 466 | #define SPBObj_repr NULL |
| 467 | |
| 468 | #define SPBObj_hash NULL |
| 469 | |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 470 | staticforward PyTypeObject SPB_Type = { |
| 471 | PyObject_HEAD_INIT(&PyType_Type) |
| 472 | 0, /*ob_size*/ |
| 473 | "SPB", /*tp_name*/ |
| 474 | sizeof(SPBObject), /*tp_basicsize*/ |
| 475 | 0, /*tp_itemsize*/ |
| 476 | /* methods */ |
| 477 | (destructor) SPBObj_dealloc, /*tp_dealloc*/ |
| 478 | 0, /*tp_print*/ |
| 479 | (getattrfunc) SPBObj_getattr, /*tp_getattr*/ |
| 480 | (setattrfunc) SPBObj_setattr, /*tp_setattr*/ |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 481 | (cmpfunc) SPBObj_compare, /*tp_compare*/ |
| 482 | (reprfunc) SPBObj_repr, /*tp_repr*/ |
| 483 | (PyNumberMethods *)0, /* tp_as_number */ |
| 484 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 485 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 486 | (hashfunc) SPBObj_hash, /*tp_hash*/ |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 487 | }; |
| 488 | |
| 489 | /* ---------------------- End object type SPB ----------------------- */ |
| 490 | |
| 491 | |
| 492 | static PyObject *Snd_SPB(_self, _args) |
| 493 | PyObject *_self; |
| 494 | PyObject *_args; |
| 495 | { |
| 496 | PyObject *_res = NULL; |
| 497 | return SPBObj_New(); |
| 498 | } |
| 499 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 500 | static PyObject *Snd_SysBeep(_self, _args) |
| 501 | PyObject *_self; |
| 502 | PyObject *_args; |
| 503 | { |
| 504 | PyObject *_res = NULL; |
| 505 | short duration; |
| 506 | if (!PyArg_ParseTuple(_args, "h", |
| 507 | &duration)) |
| 508 | return NULL; |
| 509 | SysBeep(duration); |
| 510 | Py_INCREF(Py_None); |
| 511 | _res = Py_None; |
| 512 | return _res; |
| 513 | } |
| 514 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 515 | static PyObject *Snd_SndNewChannel(_self, _args) |
| 516 | PyObject *_self; |
| 517 | PyObject *_args; |
| 518 | { |
| 519 | PyObject *_res = NULL; |
| 520 | OSErr _err; |
| 521 | SndChannelPtr chan = 0; |
| 522 | short synth; |
| 523 | long init; |
| 524 | PyObject* userRoutine; |
| 525 | if (!PyArg_ParseTuple(_args, "hlO", |
| 526 | &synth, |
| 527 | &init, |
| 528 | &userRoutine)) |
| 529 | return NULL; |
Guido van Rossum | 0818a4c | 1995-02-05 16:53:45 +0000 | [diff] [blame] | 530 | if (userRoutine != Py_None && !PyCallable_Check(userRoutine)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 531 | { |
| 532 | PyErr_SetString(PyExc_TypeError, "callback must be callable"); |
| 533 | goto userRoutine__error__; |
| 534 | } |
| 535 | _err = SndNewChannel(&chan, |
| 536 | synth, |
| 537 | init, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 538 | NewSndCallBackProc(SndCh_UserRoutine)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 539 | if (_err != noErr) return PyMac_Error(_err); |
| 540 | _res = Py_BuildValue("O&", |
| 541 | SndCh_New, chan); |
| 542 | if (_res != NULL && userRoutine != Py_None) |
| 543 | { |
| 544 | SndChannelObject *p = (SndChannelObject *)_res; |
| 545 | p->ob_itself->userInfo = (long)p; |
| 546 | Py_INCREF(userRoutine); |
| 547 | p->ob_callback = userRoutine; |
| 548 | } |
| 549 | userRoutine__error__: ; |
| 550 | return _res; |
| 551 | } |
| 552 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 553 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 554 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 555 | static PyObject *Snd_SndControl(_self, _args) |
| 556 | PyObject *_self; |
| 557 | PyObject *_args; |
| 558 | { |
| 559 | PyObject *_res = NULL; |
| 560 | OSErr _err; |
| 561 | short id; |
| 562 | SndCommand cmd; |
| 563 | if (!PyArg_ParseTuple(_args, "h", |
| 564 | &id)) |
| 565 | return NULL; |
| 566 | _err = SndControl(id, |
| 567 | &cmd); |
| 568 | if (_err != noErr) return PyMac_Error(_err); |
| 569 | _res = Py_BuildValue("O&", |
| 570 | SndCmd_New, &cmd); |
| 571 | return _res; |
| 572 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 573 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 574 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 575 | static PyObject *Snd_SndSoundManagerVersion(_self, _args) |
| 576 | PyObject *_self; |
| 577 | PyObject *_args; |
| 578 | { |
| 579 | PyObject *_res = NULL; |
Jack Jansen | 5674e4e | 1996-08-01 15:26:05 +0000 | [diff] [blame] | 580 | NumVersion _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 581 | if (!PyArg_ParseTuple(_args, "")) |
| 582 | return NULL; |
| 583 | _rv = SndSoundManagerVersion(); |
Jack Jansen | 5674e4e | 1996-08-01 15:26:05 +0000 | [diff] [blame] | 584 | _res = Py_BuildValue("O&", |
| 585 | PyMac_BuildNumVersion, _rv); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 586 | return _res; |
| 587 | } |
| 588 | |
| 589 | static PyObject *Snd_SndManagerStatus(_self, _args) |
| 590 | PyObject *_self; |
| 591 | PyObject *_args; |
| 592 | { |
| 593 | PyObject *_res = NULL; |
| 594 | OSErr _err; |
| 595 | short theLength; |
| 596 | SMStatus theStatus__out__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 597 | if (!PyArg_ParseTuple(_args, "h", |
| 598 | &theLength)) |
| 599 | return NULL; |
| 600 | _err = SndManagerStatus(theLength, |
| 601 | &theStatus__out__); |
| 602 | if (_err != noErr) return PyMac_Error(_err); |
| 603 | _res = Py_BuildValue("s#", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 604 | (char *)&theStatus__out__, (int)sizeof(SMStatus)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 605 | theStatus__error__: ; |
| 606 | return _res; |
| 607 | } |
| 608 | |
| 609 | static PyObject *Snd_SndGetSysBeepState(_self, _args) |
| 610 | PyObject *_self; |
| 611 | PyObject *_args; |
| 612 | { |
| 613 | PyObject *_res = NULL; |
| 614 | short sysBeepState; |
| 615 | if (!PyArg_ParseTuple(_args, "")) |
| 616 | return NULL; |
| 617 | SndGetSysBeepState(&sysBeepState); |
| 618 | _res = Py_BuildValue("h", |
| 619 | sysBeepState); |
| 620 | return _res; |
| 621 | } |
| 622 | |
| 623 | static PyObject *Snd_SndSetSysBeepState(_self, _args) |
| 624 | PyObject *_self; |
| 625 | PyObject *_args; |
| 626 | { |
| 627 | PyObject *_res = NULL; |
| 628 | OSErr _err; |
| 629 | short sysBeepState; |
| 630 | if (!PyArg_ParseTuple(_args, "h", |
| 631 | &sysBeepState)) |
| 632 | return NULL; |
| 633 | _err = SndSetSysBeepState(sysBeepState); |
| 634 | if (_err != noErr) return PyMac_Error(_err); |
| 635 | Py_INCREF(Py_None); |
| 636 | _res = Py_None; |
| 637 | return _res; |
| 638 | } |
| 639 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 640 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 641 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 642 | static PyObject *Snd_MACEVersion(_self, _args) |
| 643 | PyObject *_self; |
| 644 | PyObject *_args; |
| 645 | { |
| 646 | PyObject *_res = NULL; |
Jack Jansen | 5674e4e | 1996-08-01 15:26:05 +0000 | [diff] [blame] | 647 | NumVersion _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 648 | if (!PyArg_ParseTuple(_args, "")) |
| 649 | return NULL; |
| 650 | _rv = MACEVersion(); |
Jack Jansen | 5674e4e | 1996-08-01 15:26:05 +0000 | [diff] [blame] | 651 | _res = Py_BuildValue("O&", |
| 652 | PyMac_BuildNumVersion, _rv); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 653 | return _res; |
| 654 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 655 | #endif |
| 656 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 657 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 658 | |
| 659 | static PyObject *Snd_Comp3to1(_self, _args) |
| 660 | PyObject *_self; |
| 661 | PyObject *_args; |
| 662 | { |
| 663 | PyObject *_res = NULL; |
| 664 | char *buffer__in__; |
| 665 | char *buffer__out__; |
| 666 | long buffer__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 667 | int buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 668 | StateBlock *state__in__; |
| 669 | StateBlock state__out__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 670 | int state__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 671 | unsigned long numChannels; |
| 672 | unsigned long whichChannel; |
| 673 | if (!PyArg_ParseTuple(_args, "s#s#ll", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 674 | &buffer__in__, &buffer__in_len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 675 | (char **)&state__in__, &state__in_len__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 676 | &numChannels, |
| 677 | &whichChannel)) |
| 678 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 679 | if ((buffer__out__ = malloc(buffer__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 680 | { |
| 681 | PyErr_NoMemory(); |
| 682 | goto buffer__error__; |
| 683 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 684 | buffer__len__ = buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 685 | if (state__in_len__ != sizeof(StateBlock)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 686 | { |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 687 | PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 688 | goto state__error__; |
| 689 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 690 | Comp3to1(buffer__in__, buffer__out__, (long)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 691 | state__in__, &state__out__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 692 | numChannels, |
| 693 | whichChannel); |
| 694 | _res = Py_BuildValue("s#s#", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 695 | buffer__out__, (int)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 696 | (char *)&state__out__, (int)sizeof(StateBlock)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 697 | state__error__: ; |
| 698 | free(buffer__out__); |
| 699 | buffer__error__: ; |
| 700 | return _res; |
| 701 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 702 | #endif |
| 703 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 704 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 705 | |
| 706 | static PyObject *Snd_Exp1to3(_self, _args) |
| 707 | PyObject *_self; |
| 708 | PyObject *_args; |
| 709 | { |
| 710 | PyObject *_res = NULL; |
| 711 | char *buffer__in__; |
| 712 | char *buffer__out__; |
| 713 | long buffer__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 714 | int buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 715 | StateBlock *state__in__; |
| 716 | StateBlock state__out__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 717 | int state__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 718 | unsigned long numChannels; |
| 719 | unsigned long whichChannel; |
| 720 | if (!PyArg_ParseTuple(_args, "s#s#ll", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 721 | &buffer__in__, &buffer__in_len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 722 | (char **)&state__in__, &state__in_len__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 723 | &numChannels, |
| 724 | &whichChannel)) |
| 725 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 726 | if ((buffer__out__ = malloc(buffer__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 727 | { |
| 728 | PyErr_NoMemory(); |
| 729 | goto buffer__error__; |
| 730 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 731 | buffer__len__ = buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 732 | if (state__in_len__ != sizeof(StateBlock)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 733 | { |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 734 | PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 735 | goto state__error__; |
| 736 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 737 | Exp1to3(buffer__in__, buffer__out__, (long)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 738 | state__in__, &state__out__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 739 | numChannels, |
| 740 | whichChannel); |
| 741 | _res = Py_BuildValue("s#s#", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 742 | buffer__out__, (int)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 743 | (char *)&state__out__, (int)sizeof(StateBlock)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 744 | state__error__: ; |
| 745 | free(buffer__out__); |
| 746 | buffer__error__: ; |
| 747 | return _res; |
| 748 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 749 | #endif |
| 750 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 751 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 752 | |
| 753 | static PyObject *Snd_Comp6to1(_self, _args) |
| 754 | PyObject *_self; |
| 755 | PyObject *_args; |
| 756 | { |
| 757 | PyObject *_res = NULL; |
| 758 | char *buffer__in__; |
| 759 | char *buffer__out__; |
| 760 | long buffer__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 761 | int buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 762 | StateBlock *state__in__; |
| 763 | StateBlock state__out__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 764 | int state__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 765 | unsigned long numChannels; |
| 766 | unsigned long whichChannel; |
| 767 | if (!PyArg_ParseTuple(_args, "s#s#ll", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 768 | &buffer__in__, &buffer__in_len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 769 | (char **)&state__in__, &state__in_len__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 770 | &numChannels, |
| 771 | &whichChannel)) |
| 772 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 773 | if ((buffer__out__ = malloc(buffer__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 774 | { |
| 775 | PyErr_NoMemory(); |
| 776 | goto buffer__error__; |
| 777 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 778 | buffer__len__ = buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 779 | if (state__in_len__ != sizeof(StateBlock)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 780 | { |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 781 | PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 782 | goto state__error__; |
| 783 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 784 | Comp6to1(buffer__in__, buffer__out__, (long)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 785 | state__in__, &state__out__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 786 | numChannels, |
| 787 | whichChannel); |
| 788 | _res = Py_BuildValue("s#s#", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 789 | buffer__out__, (int)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 790 | (char *)&state__out__, (int)sizeof(StateBlock)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 791 | state__error__: ; |
| 792 | free(buffer__out__); |
| 793 | buffer__error__: ; |
| 794 | return _res; |
| 795 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 796 | #endif |
| 797 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 798 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 799 | |
| 800 | static PyObject *Snd_Exp1to6(_self, _args) |
| 801 | PyObject *_self; |
| 802 | PyObject *_args; |
| 803 | { |
| 804 | PyObject *_res = NULL; |
| 805 | char *buffer__in__; |
| 806 | char *buffer__out__; |
| 807 | long buffer__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 808 | int buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 809 | StateBlock *state__in__; |
| 810 | StateBlock state__out__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 811 | int state__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 812 | unsigned long numChannels; |
| 813 | unsigned long whichChannel; |
| 814 | if (!PyArg_ParseTuple(_args, "s#s#ll", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 815 | &buffer__in__, &buffer__in_len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 816 | (char **)&state__in__, &state__in_len__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 817 | &numChannels, |
| 818 | &whichChannel)) |
| 819 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 820 | if ((buffer__out__ = malloc(buffer__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 821 | { |
| 822 | PyErr_NoMemory(); |
| 823 | goto buffer__error__; |
| 824 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 825 | buffer__len__ = buffer__in_len__; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 826 | if (state__in_len__ != sizeof(StateBlock)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 827 | { |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 828 | PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 829 | goto state__error__; |
| 830 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 831 | Exp1to6(buffer__in__, buffer__out__, (long)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 832 | state__in__, &state__out__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 833 | numChannels, |
| 834 | whichChannel); |
| 835 | _res = Py_BuildValue("s#s#", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 836 | buffer__out__, (int)buffer__len__, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 837 | (char *)&state__out__, (int)sizeof(StateBlock)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 838 | state__error__: ; |
| 839 | free(buffer__out__); |
| 840 | buffer__error__: ; |
| 841 | return _res; |
| 842 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 843 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 844 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 845 | static PyObject *Snd_GetSysBeepVolume(_self, _args) |
| 846 | PyObject *_self; |
| 847 | PyObject *_args; |
| 848 | { |
| 849 | PyObject *_res = NULL; |
| 850 | OSErr _err; |
| 851 | long level; |
| 852 | if (!PyArg_ParseTuple(_args, "")) |
| 853 | return NULL; |
| 854 | _err = GetSysBeepVolume(&level); |
| 855 | if (_err != noErr) return PyMac_Error(_err); |
| 856 | _res = Py_BuildValue("l", |
| 857 | level); |
| 858 | return _res; |
| 859 | } |
| 860 | |
| 861 | static PyObject *Snd_SetSysBeepVolume(_self, _args) |
| 862 | PyObject *_self; |
| 863 | PyObject *_args; |
| 864 | { |
| 865 | PyObject *_res = NULL; |
| 866 | OSErr _err; |
| 867 | long level; |
| 868 | if (!PyArg_ParseTuple(_args, "l", |
| 869 | &level)) |
| 870 | return NULL; |
| 871 | _err = SetSysBeepVolume(level); |
| 872 | if (_err != noErr) return PyMac_Error(_err); |
| 873 | Py_INCREF(Py_None); |
| 874 | _res = Py_None; |
| 875 | return _res; |
| 876 | } |
| 877 | |
| 878 | static PyObject *Snd_GetDefaultOutputVolume(_self, _args) |
| 879 | PyObject *_self; |
| 880 | PyObject *_args; |
| 881 | { |
| 882 | PyObject *_res = NULL; |
| 883 | OSErr _err; |
| 884 | long level; |
| 885 | if (!PyArg_ParseTuple(_args, "")) |
| 886 | return NULL; |
| 887 | _err = GetDefaultOutputVolume(&level); |
| 888 | if (_err != noErr) return PyMac_Error(_err); |
| 889 | _res = Py_BuildValue("l", |
| 890 | level); |
| 891 | return _res; |
| 892 | } |
| 893 | |
| 894 | static PyObject *Snd_SetDefaultOutputVolume(_self, _args) |
| 895 | PyObject *_self; |
| 896 | PyObject *_args; |
| 897 | { |
| 898 | PyObject *_res = NULL; |
| 899 | OSErr _err; |
| 900 | long level; |
| 901 | if (!PyArg_ParseTuple(_args, "l", |
| 902 | &level)) |
| 903 | return NULL; |
| 904 | _err = SetDefaultOutputVolume(level); |
| 905 | if (_err != noErr) return PyMac_Error(_err); |
| 906 | Py_INCREF(Py_None); |
| 907 | _res = Py_None; |
| 908 | return _res; |
| 909 | } |
| 910 | |
| 911 | static PyObject *Snd_GetSoundHeaderOffset(_self, _args) |
| 912 | PyObject *_self; |
| 913 | PyObject *_args; |
| 914 | { |
| 915 | PyObject *_res = NULL; |
| 916 | OSErr _err; |
| 917 | SndListHandle sndHandle; |
| 918 | long offset; |
| 919 | if (!PyArg_ParseTuple(_args, "O&", |
| 920 | ResObj_Convert, &sndHandle)) |
| 921 | return NULL; |
| 922 | _err = GetSoundHeaderOffset(sndHandle, |
| 923 | &offset); |
| 924 | if (_err != noErr) return PyMac_Error(_err); |
| 925 | _res = Py_BuildValue("l", |
| 926 | offset); |
| 927 | return _res; |
| 928 | } |
| 929 | |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 930 | static PyObject *Snd_GetCompressionInfo(_self, _args) |
| 931 | PyObject *_self; |
| 932 | PyObject *_args; |
| 933 | { |
| 934 | PyObject *_res = NULL; |
| 935 | OSErr _err; |
| 936 | short compressionID; |
| 937 | OSType format; |
| 938 | short numChannels; |
| 939 | short sampleSize; |
| 940 | CompressionInfo cp__out__; |
| 941 | if (!PyArg_ParseTuple(_args, "hO&hh", |
| 942 | &compressionID, |
| 943 | PyMac_GetOSType, &format, |
| 944 | &numChannels, |
| 945 | &sampleSize)) |
| 946 | return NULL; |
| 947 | _err = GetCompressionInfo(compressionID, |
| 948 | format, |
| 949 | numChannels, |
| 950 | sampleSize, |
| 951 | &cp__out__); |
| 952 | if (_err != noErr) return PyMac_Error(_err); |
| 953 | _res = Py_BuildValue("s#", |
| 954 | (char *)&cp__out__, (int)sizeof(CompressionInfo)); |
| 955 | cp__error__: ; |
| 956 | return _res; |
| 957 | } |
| 958 | |
| 959 | static PyObject *Snd_SetSoundPreference(_self, _args) |
| 960 | PyObject *_self; |
| 961 | PyObject *_args; |
| 962 | { |
| 963 | PyObject *_res = NULL; |
| 964 | OSErr _err; |
| 965 | OSType theType; |
| 966 | Str255 name; |
| 967 | Handle settings; |
| 968 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 969 | PyMac_GetOSType, &theType, |
| 970 | ResObj_Convert, &settings)) |
| 971 | return NULL; |
| 972 | _err = SetSoundPreference(theType, |
| 973 | name, |
| 974 | settings); |
| 975 | if (_err != noErr) return PyMac_Error(_err); |
| 976 | _res = Py_BuildValue("O&", |
| 977 | PyMac_BuildStr255, name); |
| 978 | return _res; |
| 979 | } |
| 980 | |
| 981 | static PyObject *Snd_GetSoundPreference(_self, _args) |
| 982 | PyObject *_self; |
| 983 | PyObject *_args; |
| 984 | { |
| 985 | PyObject *_res = NULL; |
| 986 | OSErr _err; |
| 987 | OSType theType; |
| 988 | Str255 name; |
| 989 | Handle settings; |
| 990 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 991 | PyMac_GetOSType, &theType, |
| 992 | ResObj_Convert, &settings)) |
| 993 | return NULL; |
| 994 | _err = GetSoundPreference(theType, |
| 995 | name, |
| 996 | settings); |
| 997 | if (_err != noErr) return PyMac_Error(_err); |
| 998 | _res = Py_BuildValue("O&", |
| 999 | PyMac_BuildStr255, name); |
| 1000 | return _res; |
| 1001 | } |
| 1002 | |
| 1003 | static PyObject *Snd_GetCompressionName(_self, _args) |
| 1004 | PyObject *_self; |
| 1005 | PyObject *_args; |
| 1006 | { |
| 1007 | PyObject *_res = NULL; |
| 1008 | OSErr _err; |
| 1009 | OSType compressionType; |
| 1010 | Str255 compressionName; |
| 1011 | if (!PyArg_ParseTuple(_args, "O&", |
| 1012 | PyMac_GetOSType, &compressionType)) |
| 1013 | return NULL; |
| 1014 | _err = GetCompressionName(compressionType, |
| 1015 | compressionName); |
| 1016 | if (_err != noErr) return PyMac_Error(_err); |
| 1017 | _res = Py_BuildValue("O&", |
| 1018 | PyMac_BuildStr255, compressionName); |
| 1019 | return _res; |
| 1020 | } |
| 1021 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1022 | static PyObject *Snd_SPBVersion(_self, _args) |
| 1023 | PyObject *_self; |
| 1024 | PyObject *_args; |
| 1025 | { |
| 1026 | PyObject *_res = NULL; |
| 1027 | NumVersion _rv; |
| 1028 | if (!PyArg_ParseTuple(_args, "")) |
| 1029 | return NULL; |
| 1030 | _rv = SPBVersion(); |
| 1031 | _res = Py_BuildValue("O&", |
| 1032 | PyMac_BuildNumVersion, _rv); |
| 1033 | return _res; |
| 1034 | } |
| 1035 | |
| 1036 | static PyObject *Snd_SPBSignInDevice(_self, _args) |
| 1037 | PyObject *_self; |
| 1038 | PyObject *_args; |
| 1039 | { |
| 1040 | PyObject *_res = NULL; |
| 1041 | OSErr _err; |
| 1042 | short deviceRefNum; |
| 1043 | Str255 deviceName; |
| 1044 | if (!PyArg_ParseTuple(_args, "hO&", |
| 1045 | &deviceRefNum, |
| 1046 | PyMac_GetStr255, deviceName)) |
| 1047 | return NULL; |
| 1048 | _err = SPBSignInDevice(deviceRefNum, |
| 1049 | deviceName); |
| 1050 | if (_err != noErr) return PyMac_Error(_err); |
| 1051 | Py_INCREF(Py_None); |
| 1052 | _res = Py_None; |
| 1053 | return _res; |
| 1054 | } |
| 1055 | |
| 1056 | static PyObject *Snd_SPBSignOutDevice(_self, _args) |
| 1057 | PyObject *_self; |
| 1058 | PyObject *_args; |
| 1059 | { |
| 1060 | PyObject *_res = NULL; |
| 1061 | OSErr _err; |
| 1062 | short deviceRefNum; |
| 1063 | if (!PyArg_ParseTuple(_args, "h", |
| 1064 | &deviceRefNum)) |
| 1065 | return NULL; |
| 1066 | _err = SPBSignOutDevice(deviceRefNum); |
| 1067 | if (_err != noErr) return PyMac_Error(_err); |
| 1068 | Py_INCREF(Py_None); |
| 1069 | _res = Py_None; |
| 1070 | return _res; |
| 1071 | } |
| 1072 | |
| 1073 | static PyObject *Snd_SPBGetIndexedDevice(_self, _args) |
| 1074 | PyObject *_self; |
| 1075 | PyObject *_args; |
| 1076 | { |
| 1077 | PyObject *_res = NULL; |
| 1078 | OSErr _err; |
| 1079 | short count; |
| 1080 | Str255 deviceName; |
| 1081 | Handle deviceIconHandle; |
| 1082 | if (!PyArg_ParseTuple(_args, "h", |
| 1083 | &count)) |
| 1084 | return NULL; |
| 1085 | _err = SPBGetIndexedDevice(count, |
| 1086 | deviceName, |
| 1087 | &deviceIconHandle); |
| 1088 | if (_err != noErr) return PyMac_Error(_err); |
| 1089 | _res = Py_BuildValue("O&O&", |
| 1090 | PyMac_BuildStr255, deviceName, |
| 1091 | ResObj_New, deviceIconHandle); |
| 1092 | return _res; |
| 1093 | } |
| 1094 | |
| 1095 | static PyObject *Snd_SPBOpenDevice(_self, _args) |
| 1096 | PyObject *_self; |
| 1097 | PyObject *_args; |
| 1098 | { |
| 1099 | PyObject *_res = NULL; |
| 1100 | OSErr _err; |
| 1101 | Str255 deviceName; |
| 1102 | short permission; |
| 1103 | long inRefNum; |
| 1104 | if (!PyArg_ParseTuple(_args, "O&h", |
| 1105 | PyMac_GetStr255, deviceName, |
| 1106 | &permission)) |
| 1107 | return NULL; |
| 1108 | _err = SPBOpenDevice(deviceName, |
| 1109 | permission, |
| 1110 | &inRefNum); |
| 1111 | if (_err != noErr) return PyMac_Error(_err); |
| 1112 | _res = Py_BuildValue("l", |
| 1113 | inRefNum); |
| 1114 | return _res; |
| 1115 | } |
| 1116 | |
| 1117 | static PyObject *Snd_SPBCloseDevice(_self, _args) |
| 1118 | PyObject *_self; |
| 1119 | PyObject *_args; |
| 1120 | { |
| 1121 | PyObject *_res = NULL; |
| 1122 | OSErr _err; |
| 1123 | long inRefNum; |
| 1124 | if (!PyArg_ParseTuple(_args, "l", |
| 1125 | &inRefNum)) |
| 1126 | return NULL; |
| 1127 | _err = SPBCloseDevice(inRefNum); |
| 1128 | if (_err != noErr) return PyMac_Error(_err); |
| 1129 | Py_INCREF(Py_None); |
| 1130 | _res = Py_None; |
| 1131 | return _res; |
| 1132 | } |
| 1133 | |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 1134 | static PyObject *Snd_SPBRecord(_self, _args) |
| 1135 | PyObject *_self; |
| 1136 | PyObject *_args; |
| 1137 | { |
| 1138 | PyObject *_res = NULL; |
| 1139 | OSErr _err; |
| 1140 | SPBPtr inParamPtr; |
| 1141 | Boolean asynchFlag; |
| 1142 | if (!PyArg_ParseTuple(_args, "O&b", |
| 1143 | SPBObj_Convert, &inParamPtr, |
| 1144 | &asynchFlag)) |
| 1145 | return NULL; |
| 1146 | _err = SPBRecord(inParamPtr, |
| 1147 | asynchFlag); |
| 1148 | if (_err != noErr) return PyMac_Error(_err); |
| 1149 | Py_INCREF(Py_None); |
| 1150 | _res = Py_None; |
| 1151 | return _res; |
| 1152 | } |
| 1153 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1154 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 1155 | |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 1156 | static PyObject *Snd_SPBRecordToFile(_self, _args) |
| 1157 | PyObject *_self; |
| 1158 | PyObject *_args; |
| 1159 | { |
| 1160 | PyObject *_res = NULL; |
| 1161 | OSErr _err; |
| 1162 | short fRefNum; |
| 1163 | SPBPtr inParamPtr; |
| 1164 | Boolean asynchFlag; |
| 1165 | if (!PyArg_ParseTuple(_args, "hO&b", |
| 1166 | &fRefNum, |
| 1167 | SPBObj_Convert, &inParamPtr, |
| 1168 | &asynchFlag)) |
| 1169 | return NULL; |
| 1170 | _err = SPBRecordToFile(fRefNum, |
| 1171 | inParamPtr, |
| 1172 | asynchFlag); |
| 1173 | if (_err != noErr) return PyMac_Error(_err); |
| 1174 | Py_INCREF(Py_None); |
| 1175 | _res = Py_None; |
| 1176 | return _res; |
| 1177 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 1178 | #endif |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 1179 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1180 | static PyObject *Snd_SPBPauseRecording(_self, _args) |
| 1181 | PyObject *_self; |
| 1182 | PyObject *_args; |
| 1183 | { |
| 1184 | PyObject *_res = NULL; |
| 1185 | OSErr _err; |
| 1186 | long inRefNum; |
| 1187 | if (!PyArg_ParseTuple(_args, "l", |
| 1188 | &inRefNum)) |
| 1189 | return NULL; |
| 1190 | _err = SPBPauseRecording(inRefNum); |
| 1191 | if (_err != noErr) return PyMac_Error(_err); |
| 1192 | Py_INCREF(Py_None); |
| 1193 | _res = Py_None; |
| 1194 | return _res; |
| 1195 | } |
| 1196 | |
| 1197 | static PyObject *Snd_SPBResumeRecording(_self, _args) |
| 1198 | PyObject *_self; |
| 1199 | PyObject *_args; |
| 1200 | { |
| 1201 | PyObject *_res = NULL; |
| 1202 | OSErr _err; |
| 1203 | long inRefNum; |
| 1204 | if (!PyArg_ParseTuple(_args, "l", |
| 1205 | &inRefNum)) |
| 1206 | return NULL; |
| 1207 | _err = SPBResumeRecording(inRefNum); |
| 1208 | if (_err != noErr) return PyMac_Error(_err); |
| 1209 | Py_INCREF(Py_None); |
| 1210 | _res = Py_None; |
| 1211 | return _res; |
| 1212 | } |
| 1213 | |
| 1214 | static PyObject *Snd_SPBStopRecording(_self, _args) |
| 1215 | PyObject *_self; |
| 1216 | PyObject *_args; |
| 1217 | { |
| 1218 | PyObject *_res = NULL; |
| 1219 | OSErr _err; |
| 1220 | long inRefNum; |
| 1221 | if (!PyArg_ParseTuple(_args, "l", |
| 1222 | &inRefNum)) |
| 1223 | return NULL; |
| 1224 | _err = SPBStopRecording(inRefNum); |
| 1225 | if (_err != noErr) return PyMac_Error(_err); |
| 1226 | Py_INCREF(Py_None); |
| 1227 | _res = Py_None; |
| 1228 | return _res; |
| 1229 | } |
| 1230 | |
| 1231 | static PyObject *Snd_SPBGetRecordingStatus(_self, _args) |
| 1232 | PyObject *_self; |
| 1233 | PyObject *_args; |
| 1234 | { |
| 1235 | PyObject *_res = NULL; |
| 1236 | OSErr _err; |
| 1237 | long inRefNum; |
| 1238 | short recordingStatus; |
| 1239 | short meterLevel; |
| 1240 | unsigned long totalSamplesToRecord; |
| 1241 | unsigned long numberOfSamplesRecorded; |
| 1242 | unsigned long totalMsecsToRecord; |
| 1243 | unsigned long numberOfMsecsRecorded; |
| 1244 | if (!PyArg_ParseTuple(_args, "l", |
| 1245 | &inRefNum)) |
| 1246 | return NULL; |
| 1247 | _err = SPBGetRecordingStatus(inRefNum, |
| 1248 | &recordingStatus, |
| 1249 | &meterLevel, |
| 1250 | &totalSamplesToRecord, |
| 1251 | &numberOfSamplesRecorded, |
| 1252 | &totalMsecsToRecord, |
| 1253 | &numberOfMsecsRecorded); |
| 1254 | if (_err != noErr) return PyMac_Error(_err); |
| 1255 | _res = Py_BuildValue("hhllll", |
| 1256 | recordingStatus, |
| 1257 | meterLevel, |
| 1258 | totalSamplesToRecord, |
| 1259 | numberOfSamplesRecorded, |
| 1260 | totalMsecsToRecord, |
| 1261 | numberOfMsecsRecorded); |
| 1262 | return _res; |
| 1263 | } |
| 1264 | |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 1265 | static PyObject *Snd_SPBGetDeviceInfo(_self, _args) |
| 1266 | PyObject *_self; |
| 1267 | PyObject *_args; |
| 1268 | { |
| 1269 | PyObject *_res = NULL; |
| 1270 | OSErr _err; |
| 1271 | long inRefNum; |
| 1272 | OSType infoType; |
| 1273 | void * infoData; |
| 1274 | if (!PyArg_ParseTuple(_args, "lO&w", |
| 1275 | &inRefNum, |
| 1276 | PyMac_GetOSType, &infoType, |
| 1277 | &infoData)) |
| 1278 | return NULL; |
| 1279 | _err = SPBGetDeviceInfo(inRefNum, |
| 1280 | infoType, |
| 1281 | infoData); |
| 1282 | if (_err != noErr) return PyMac_Error(_err); |
| 1283 | Py_INCREF(Py_None); |
| 1284 | _res = Py_None; |
| 1285 | return _res; |
| 1286 | } |
| 1287 | |
| 1288 | static PyObject *Snd_SPBSetDeviceInfo(_self, _args) |
| 1289 | PyObject *_self; |
| 1290 | PyObject *_args; |
| 1291 | { |
| 1292 | PyObject *_res = NULL; |
| 1293 | OSErr _err; |
| 1294 | long inRefNum; |
| 1295 | OSType infoType; |
| 1296 | void * infoData; |
| 1297 | if (!PyArg_ParseTuple(_args, "lO&w", |
| 1298 | &inRefNum, |
| 1299 | PyMac_GetOSType, &infoType, |
| 1300 | &infoData)) |
| 1301 | return NULL; |
| 1302 | _err = SPBSetDeviceInfo(inRefNum, |
| 1303 | infoType, |
| 1304 | infoData); |
| 1305 | if (_err != noErr) return PyMac_Error(_err); |
| 1306 | Py_INCREF(Py_None); |
| 1307 | _res = Py_None; |
| 1308 | return _res; |
| 1309 | } |
| 1310 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1311 | static PyObject *Snd_SPBMillisecondsToBytes(_self, _args) |
| 1312 | PyObject *_self; |
| 1313 | PyObject *_args; |
| 1314 | { |
| 1315 | PyObject *_res = NULL; |
| 1316 | OSErr _err; |
| 1317 | long inRefNum; |
| 1318 | long milliseconds; |
| 1319 | if (!PyArg_ParseTuple(_args, "l", |
| 1320 | &inRefNum)) |
| 1321 | return NULL; |
| 1322 | _err = SPBMillisecondsToBytes(inRefNum, |
| 1323 | &milliseconds); |
| 1324 | if (_err != noErr) return PyMac_Error(_err); |
| 1325 | _res = Py_BuildValue("l", |
| 1326 | milliseconds); |
| 1327 | return _res; |
| 1328 | } |
| 1329 | |
| 1330 | static PyObject *Snd_SPBBytesToMilliseconds(_self, _args) |
| 1331 | PyObject *_self; |
| 1332 | PyObject *_args; |
| 1333 | { |
| 1334 | PyObject *_res = NULL; |
| 1335 | OSErr _err; |
| 1336 | long inRefNum; |
| 1337 | long byteCount; |
| 1338 | if (!PyArg_ParseTuple(_args, "l", |
| 1339 | &inRefNum)) |
| 1340 | return NULL; |
| 1341 | _err = SPBBytesToMilliseconds(inRefNum, |
| 1342 | &byteCount); |
| 1343 | if (_err != noErr) return PyMac_Error(_err); |
| 1344 | _res = Py_BuildValue("l", |
| 1345 | byteCount); |
| 1346 | return _res; |
| 1347 | } |
| 1348 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1349 | static PyMethodDef Snd_methods[] = { |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 1350 | {"SPB", (PyCFunction)Snd_SPB, 1, |
| 1351 | NULL}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1352 | {"SysBeep", (PyCFunction)Snd_SysBeep, 1, |
| 1353 | "(short duration) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1354 | {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1, |
| 1355 | "(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 1356 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1357 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1358 | {"SndControl", (PyCFunction)Snd_SndControl, 1, |
| 1359 | "(short id) -> (SndCommand cmd)"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 1360 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1361 | {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1, |
Jack Jansen | 5674e4e | 1996-08-01 15:26:05 +0000 | [diff] [blame] | 1362 | "() -> (NumVersion _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1363 | {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1, |
| 1364 | "(short theLength) -> (SMStatus theStatus)"}, |
| 1365 | {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1, |
| 1366 | "() -> (short sysBeepState)"}, |
| 1367 | {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1, |
| 1368 | "(short sysBeepState) -> None"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 1369 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1370 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1371 | {"MACEVersion", (PyCFunction)Snd_MACEVersion, 1, |
Jack Jansen | 5674e4e | 1996-08-01 15:26:05 +0000 | [diff] [blame] | 1372 | "() -> (NumVersion _rv)"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 1373 | #endif |
| 1374 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1375 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1376 | {"Comp3to1", (PyCFunction)Snd_Comp3to1, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1377 | "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 1378 | #endif |
| 1379 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1380 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1381 | {"Exp1to3", (PyCFunction)Snd_Exp1to3, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1382 | "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 1383 | #endif |
| 1384 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1385 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1386 | {"Comp6to1", (PyCFunction)Snd_Comp6to1, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1387 | "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 1388 | #endif |
| 1389 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1390 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1391 | {"Exp1to6", (PyCFunction)Snd_Exp1to6, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1392 | "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 1393 | #endif |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1394 | {"GetSysBeepVolume", (PyCFunction)Snd_GetSysBeepVolume, 1, |
| 1395 | "() -> (long level)"}, |
| 1396 | {"SetSysBeepVolume", (PyCFunction)Snd_SetSysBeepVolume, 1, |
| 1397 | "(long level) -> None"}, |
| 1398 | {"GetDefaultOutputVolume", (PyCFunction)Snd_GetDefaultOutputVolume, 1, |
| 1399 | "() -> (long level)"}, |
| 1400 | {"SetDefaultOutputVolume", (PyCFunction)Snd_SetDefaultOutputVolume, 1, |
| 1401 | "(long level) -> None"}, |
| 1402 | {"GetSoundHeaderOffset", (PyCFunction)Snd_GetSoundHeaderOffset, 1, |
| 1403 | "(SndListHandle sndHandle) -> (long offset)"}, |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 1404 | {"GetCompressionInfo", (PyCFunction)Snd_GetCompressionInfo, 1, |
| 1405 | "(short compressionID, OSType format, short numChannels, short sampleSize) -> (CompressionInfo cp)"}, |
| 1406 | {"SetSoundPreference", (PyCFunction)Snd_SetSoundPreference, 1, |
| 1407 | "(OSType theType, Handle settings) -> (Str255 name)"}, |
| 1408 | {"GetSoundPreference", (PyCFunction)Snd_GetSoundPreference, 1, |
| 1409 | "(OSType theType, Handle settings) -> (Str255 name)"}, |
| 1410 | {"GetCompressionName", (PyCFunction)Snd_GetCompressionName, 1, |
| 1411 | "(OSType compressionType) -> (Str255 compressionName)"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1412 | {"SPBVersion", (PyCFunction)Snd_SPBVersion, 1, |
| 1413 | "() -> (NumVersion _rv)"}, |
| 1414 | {"SPBSignInDevice", (PyCFunction)Snd_SPBSignInDevice, 1, |
| 1415 | "(short deviceRefNum, Str255 deviceName) -> None"}, |
| 1416 | {"SPBSignOutDevice", (PyCFunction)Snd_SPBSignOutDevice, 1, |
| 1417 | "(short deviceRefNum) -> None"}, |
| 1418 | {"SPBGetIndexedDevice", (PyCFunction)Snd_SPBGetIndexedDevice, 1, |
| 1419 | "(short count) -> (Str255 deviceName, Handle deviceIconHandle)"}, |
| 1420 | {"SPBOpenDevice", (PyCFunction)Snd_SPBOpenDevice, 1, |
| 1421 | "(Str255 deviceName, short permission) -> (long inRefNum)"}, |
| 1422 | {"SPBCloseDevice", (PyCFunction)Snd_SPBCloseDevice, 1, |
| 1423 | "(long inRefNum) -> None"}, |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 1424 | {"SPBRecord", (PyCFunction)Snd_SPBRecord, 1, |
| 1425 | "(SPBPtr inParamPtr, Boolean asynchFlag) -> None"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 1426 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1427 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 1428 | {"SPBRecordToFile", (PyCFunction)Snd_SPBRecordToFile, 1, |
| 1429 | "(short fRefNum, SPBPtr inParamPtr, Boolean asynchFlag) -> None"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 1430 | #endif |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1431 | {"SPBPauseRecording", (PyCFunction)Snd_SPBPauseRecording, 1, |
| 1432 | "(long inRefNum) -> None"}, |
| 1433 | {"SPBResumeRecording", (PyCFunction)Snd_SPBResumeRecording, 1, |
| 1434 | "(long inRefNum) -> None"}, |
| 1435 | {"SPBStopRecording", (PyCFunction)Snd_SPBStopRecording, 1, |
| 1436 | "(long inRefNum) -> None"}, |
| 1437 | {"SPBGetRecordingStatus", (PyCFunction)Snd_SPBGetRecordingStatus, 1, |
| 1438 | "(long inRefNum) -> (short recordingStatus, short meterLevel, unsigned long totalSamplesToRecord, unsigned long numberOfSamplesRecorded, unsigned long totalMsecsToRecord, unsigned long numberOfMsecsRecorded)"}, |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 1439 | {"SPBGetDeviceInfo", (PyCFunction)Snd_SPBGetDeviceInfo, 1, |
| 1440 | "(long inRefNum, OSType infoType, void * infoData) -> None"}, |
| 1441 | {"SPBSetDeviceInfo", (PyCFunction)Snd_SPBSetDeviceInfo, 1, |
| 1442 | "(long inRefNum, OSType infoType, void * infoData) -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1443 | {"SPBMillisecondsToBytes", (PyCFunction)Snd_SPBMillisecondsToBytes, 1, |
| 1444 | "(long inRefNum) -> (long milliseconds)"}, |
| 1445 | {"SPBBytesToMilliseconds", (PyCFunction)Snd_SPBBytesToMilliseconds, 1, |
| 1446 | "(long inRefNum) -> (long byteCount)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1447 | {NULL, NULL, 0} |
| 1448 | }; |
| 1449 | |
| 1450 | |
| 1451 | |
| 1452 | /* Routine passed to Py_AddPendingCall -- call the Python callback */ |
| 1453 | static int |
| 1454 | SndCh_CallCallBack(arg) |
| 1455 | void *arg; |
| 1456 | { |
| 1457 | SndChannelObject *p = (SndChannelObject *)arg; |
| 1458 | PyObject *args; |
| 1459 | PyObject *res; |
| 1460 | args = Py_BuildValue("(O(hhl))", |
| 1461 | p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2); |
| 1462 | res = PyEval_CallObject(p->ob_callback, args); |
| 1463 | Py_DECREF(args); |
| 1464 | if (res == NULL) |
| 1465 | return -1; |
| 1466 | Py_DECREF(res); |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
| 1470 | /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */ |
| 1471 | static pascal void |
| 1472 | SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd) |
| 1473 | { |
| 1474 | SndChannelObject *p = (SndChannelObject *)(chan->userInfo); |
| 1475 | if (p->ob_callback != NULL) { |
| 1476 | long A5 = SetA5(p->ob_A5); |
| 1477 | p->ob_cmd = *cmd; |
| 1478 | Py_AddPendingCall(SndCh_CallCallBack, (void *)p); |
| 1479 | SetA5(A5); |
| 1480 | } |
| 1481 | } |
| 1482 | |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 1483 | /* SPB callbacks - Schedule callbacks to Python */ |
| 1484 | static int |
| 1485 | SPB_CallCallBack(arg) |
| 1486 | void *arg; |
| 1487 | { |
| 1488 | SPBObject *p = (SPBObject *)arg; |
| 1489 | PyObject *args; |
| 1490 | PyObject *res; |
| 1491 | |
| 1492 | if ( p->ob_thiscallback == 0 ) return 0; |
| 1493 | args = Py_BuildValue("(O)", p); |
| 1494 | res = PyEval_CallObject(p->ob_thiscallback, args); |
| 1495 | p->ob_thiscallback = 0; |
| 1496 | Py_DECREF(args); |
| 1497 | if (res == NULL) |
| 1498 | return -1; |
| 1499 | Py_DECREF(res); |
| 1500 | return 0; |
| 1501 | } |
| 1502 | |
| 1503 | static pascal void |
| 1504 | SPB_completion(SPBPtr my_spb) |
| 1505 | { |
| 1506 | SPBObject *p = (SPBObject *)(my_spb->userLong); |
| 1507 | |
| 1508 | if (p && p->ob_completion) { |
| 1509 | long A5 = SetA5(p->ob_A5); |
| 1510 | p->ob_thiscallback = p->ob_completion; /* Hope we cannot get two at the same time */ |
| 1511 | Py_AddPendingCall(SPB_CallCallBack, (void *)p); |
| 1512 | SetA5(A5); |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | static pascal void |
| 1517 | SPB_interrupt(SPBPtr my_spb) |
| 1518 | { |
| 1519 | SPBObject *p = (SPBObject *)(my_spb->userLong); |
| 1520 | |
| 1521 | if (p && p->ob_interrupt) { |
| 1522 | long A5 = SetA5(p->ob_A5); |
| 1523 | p->ob_thiscallback = p->ob_interrupt; /* Hope we cannot get two at the same time */ |
| 1524 | Py_AddPendingCall(SPB_CallCallBack, (void *)p); |
| 1525 | SetA5(A5); |
| 1526 | } |
| 1527 | } |
| 1528 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1529 | |
| 1530 | void initSnd() |
| 1531 | { |
| 1532 | PyObject *m; |
| 1533 | PyObject *d; |
| 1534 | |
| 1535 | |
| 1536 | |
| 1537 | |
| 1538 | |
| 1539 | m = Py_InitModule("Snd", Snd_methods); |
| 1540 | d = PyModule_GetDict(m); |
| 1541 | Snd_Error = PyMac_GetOSErrException(); |
| 1542 | if (Snd_Error == NULL || |
| 1543 | PyDict_SetItemString(d, "Error", Snd_Error) != 0) |
| 1544 | Py_FatalError("can't initialize Snd.Error"); |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 1545 | SndChannel_Type.ob_type = &PyType_Type; |
| 1546 | Py_INCREF(&SndChannel_Type); |
| 1547 | if (PyDict_SetItemString(d, "SndChannelType", (PyObject *)&SndChannel_Type) != 0) |
| 1548 | Py_FatalError("can't initialize SndChannelType"); |
Jack Jansen | 52b38b7 | 1998-02-25 15:47:51 +0000 | [diff] [blame] | 1549 | SPB_Type.ob_type = &PyType_Type; |
| 1550 | Py_INCREF(&SPB_Type); |
| 1551 | if (PyDict_SetItemString(d, "SPBType", (PyObject *)&SPB_Type) != 0) |
| 1552 | Py_FatalError("can't initialize SPBType"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | /* ========================= End module Snd ========================= */ |
| 1556 | |