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