Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 1 | /********************************************************** |
Guido van Rossum | 524b588 | 1995-01-04 19:10:35 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 9 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 10 | both that copyright notice and this permission notice appear in |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 11 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 12 | Centrum or CWI or Corporation for National Research Initiatives or |
| 13 | CNRI not be used in advertising or publicity pertaining to |
| 14 | distribution of the software without specific, written prior |
| 15 | permission. |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 17 | While CWI is the initial source for this software, a modified version |
| 18 | is made available by the Corporation for National Research Initiatives |
| 19 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 22 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 24 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 25 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 26 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 27 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 28 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
| 32 | /* CD module -- interface to Mark Callow's and Roger Chickering's */ |
| 33 | /* CD Audio Library (CD). */ |
| 34 | |
| 35 | #include <sys/types.h> |
| 36 | #include <cdaudio.h> |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 37 | #include "Python.h" |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 38 | |
| 39 | #define NCALLBACKS 8 |
| 40 | |
| 41 | typedef struct { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 42 | PyObject_HEAD |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 43 | CDPLAYER *ob_cdplayer; |
| 44 | } cdplayerobject; |
| 45 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 46 | static PyObject *CdError; /* exception cd.error */ |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 47 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 48 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 49 | CD_allowremoval(self, args) |
| 50 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 51 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 52 | { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 53 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 54 | return NULL; |
| 55 | |
| 56 | CDallowremoval(self->ob_cdplayer); |
| 57 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 58 | Py_INCREF(Py_None); |
| 59 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 62 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 63 | CD_preventremoval(self, args) |
| 64 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 65 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 66 | { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 67 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 68 | return NULL; |
| 69 | |
| 70 | CDpreventremoval(self->ob_cdplayer); |
| 71 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 72 | Py_INCREF(Py_None); |
| 73 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 76 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 77 | CD_bestreadsize(self, args) |
| 78 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 79 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 80 | { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 81 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 82 | return NULL; |
| 83 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 84 | return PyInt_FromLong((long) CDbestreadsize(self->ob_cdplayer)); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 87 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 88 | CD_close(self, args) |
| 89 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 90 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 91 | { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 92 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 93 | return NULL; |
| 94 | |
| 95 | if (!CDclose(self->ob_cdplayer)) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 96 | PyErr_SetFromErrno(CdError); /* XXX - ??? */ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 97 | return NULL; |
| 98 | } |
| 99 | self->ob_cdplayer = NULL; |
| 100 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 101 | Py_INCREF(Py_None); |
| 102 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 105 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 106 | CD_eject(self, args) |
| 107 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 108 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 109 | { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 110 | CDSTATUS status; |
| 111 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 112 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 113 | return NULL; |
| 114 | |
| 115 | if (!CDeject(self->ob_cdplayer)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 116 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 117 | status.state == CD_NODISC) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 118 | PyErr_SetString(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 119 | else |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 120 | PyErr_SetString(CdError, "eject failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 121 | return NULL; |
| 122 | } |
| 123 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 124 | Py_INCREF(Py_None); |
| 125 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 128 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 129 | CD_getstatus(self, args) |
| 130 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 131 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 132 | { |
| 133 | CDSTATUS status; |
| 134 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 135 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 136 | return NULL; |
| 137 | |
| 138 | if (!CDgetstatus(self->ob_cdplayer, &status)) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 139 | PyErr_SetFromErrno(CdError); /* XXX - ??? */ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 140 | return NULL; |
| 141 | } |
| 142 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 143 | return Py_BuildValue("(ii(iii)(iii)(iii)iiii)", status.state, |
Guido van Rossum | ece6efe | 1992-04-15 15:56:11 +0000 | [diff] [blame] | 144 | status.track, status.min, status.sec, status.frame, |
| 145 | status.abs_min, status.abs_sec, status.abs_frame, |
| 146 | status.total_min, status.total_sec, status.total_frame, |
| 147 | status.first, status.last, status.scsi_audio, |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 148 | status.cur_block); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 151 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 152 | CD_gettrackinfo(self, args) |
| 153 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 154 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 155 | { |
| 156 | int track; |
| 157 | CDTRACKINFO info; |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 158 | CDSTATUS status; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 159 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 160 | if (!PyArg_ParseTuple(args, "i", &track)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 161 | return NULL; |
| 162 | |
| 163 | if (!CDgettrackinfo(self->ob_cdplayer, track, &info)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 164 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 165 | status.state == CD_NODISC) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 166 | PyErr_SetString(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 167 | else |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 168 | PyErr_SetString(CdError, "gettrackinfo failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 169 | return NULL; |
| 170 | } |
| 171 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 172 | return Py_BuildValue("((iii)(iii))", |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 173 | info.start_min, info.start_sec, info.start_frame, |
| 174 | info.total_min, info.total_sec, info.total_frame); |
| 175 | } |
| 176 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 177 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 178 | CD_msftoblock(self, args) |
| 179 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 180 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 181 | { |
| 182 | int min, sec, frame; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 183 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 184 | if (!PyArg_ParseTuple(args, "iii", &min, &sec, &frame)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 185 | return NULL; |
| 186 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 187 | return PyInt_FromLong((long) CDmsftoblock(self->ob_cdplayer, |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 188 | min, sec, frame)); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 191 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 192 | CD_play(self, args) |
| 193 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 194 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 195 | { |
| 196 | int start, play; |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 197 | CDSTATUS status; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 198 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 199 | if (!PyArg_ParseTuple(args, "ii", &start, &play)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 200 | return NULL; |
| 201 | |
| 202 | if (!CDplay(self->ob_cdplayer, start, play)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 203 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 204 | status.state == CD_NODISC) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 205 | PyErr_SetString(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 206 | else |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 207 | PyErr_SetString(CdError, "play failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 208 | return NULL; |
| 209 | } |
| 210 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 211 | Py_INCREF(Py_None); |
| 212 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 215 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 216 | CD_playabs(self, args) |
| 217 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 218 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 219 | { |
| 220 | int min, sec, frame, play; |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 221 | CDSTATUS status; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 222 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 223 | if (!PyArg_ParseTuple(args, "iiii", &min, &sec, &frame, &play)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 224 | return NULL; |
| 225 | |
| 226 | if (!CDplayabs(self->ob_cdplayer, min, sec, frame, play)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 227 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 228 | status.state == CD_NODISC) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 229 | PyErr_SetString(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 230 | else |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 231 | PyErr_SetString(CdError, "playabs failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 232 | return NULL; |
| 233 | } |
| 234 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 235 | Py_INCREF(Py_None); |
| 236 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 239 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 240 | CD_playtrack(self, args) |
| 241 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 242 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 243 | { |
| 244 | int start, play; |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 245 | CDSTATUS status; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 246 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 247 | if (!PyArg_ParseTuple(args, "ii", &start, &play)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 248 | return NULL; |
| 249 | |
| 250 | if (!CDplaytrack(self->ob_cdplayer, start, play)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 251 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 252 | status.state == CD_NODISC) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 253 | PyErr_SetString(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 254 | else |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 255 | PyErr_SetString(CdError, "playtrack failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 256 | return NULL; |
| 257 | } |
| 258 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 259 | Py_INCREF(Py_None); |
| 260 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 263 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 264 | CD_playtrackabs(self, args) |
| 265 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 266 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 267 | { |
| 268 | int track, min, sec, frame, play; |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 269 | CDSTATUS status; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 270 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 271 | if (!PyArg_ParseTuple(args, "iiiii", &track, &min, &sec, |
| 272 | &frame, &play)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 273 | return NULL; |
| 274 | |
| 275 | if (!CDplaytrackabs(self->ob_cdplayer, track, min, sec, frame, play)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 276 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 277 | status.state == CD_NODISC) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 278 | PyErr_SetString(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 279 | else |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 280 | PyErr_SetString(CdError, "playtrackabs failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 281 | return NULL; |
| 282 | } |
| 283 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 284 | Py_INCREF(Py_None); |
| 285 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 288 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 289 | CD_readda(self, args) |
| 290 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 291 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 292 | { |
| 293 | int numframes, n; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 294 | PyObject *result; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 295 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 296 | if (!PyArg_ParseTuple(args, "i", &numframes)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 297 | return NULL; |
| 298 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 299 | result = PyString_FromStringAndSize(NULL, numframes * sizeof(CDFRAME)); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 300 | if (result == NULL) |
| 301 | return NULL; |
| 302 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 303 | n = CDreadda(self->ob_cdplayer, |
| 304 | (CDFRAME *) PyString_AsString(result), numframes); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 305 | if (n == -1) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 306 | Py_DECREF(result); |
| 307 | PyErr_SetFromErrno(CdError); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 308 | return NULL; |
| 309 | } |
| 310 | if (n < numframes) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 311 | if (_PyString_Resize(&result, n * sizeof(CDFRAME))) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 312 | return NULL; |
| 313 | |
| 314 | return result; |
| 315 | } |
| 316 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 317 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 318 | CD_seek(self, args) |
| 319 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 320 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 321 | { |
| 322 | int min, sec, frame; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 323 | long PyTryBlock; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 324 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 325 | if (!PyArg_ParseTuple(args, "iii", &min, &sec, &frame)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 326 | return NULL; |
| 327 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 328 | PyTryBlock = CDseek(self->ob_cdplayer, min, sec, frame); |
| 329 | if (PyTryBlock == -1) { |
| 330 | PyErr_SetFromErrno(CdError); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 331 | return NULL; |
| 332 | } |
| 333 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 334 | return PyInt_FromLong(PyTryBlock); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 337 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 338 | CD_seektrack(self, args) |
| 339 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 340 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 341 | { |
| 342 | int track; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 343 | long PyTryBlock; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 344 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 345 | if (!PyArg_ParseTuple(args, "i", &track)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 346 | return NULL; |
| 347 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 348 | PyTryBlock = CDseektrack(self->ob_cdplayer, track); |
| 349 | if (PyTryBlock == -1) { |
| 350 | PyErr_SetFromErrno(CdError); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 351 | return NULL; |
| 352 | } |
| 353 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 354 | return PyInt_FromLong(PyTryBlock); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 357 | static PyObject * |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 358 | CD_seekblock(self, args) |
| 359 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 360 | PyObject *args; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 361 | { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 362 | unsigned long PyTryBlock; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 363 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 364 | if (!PyArg_ParseTuple(args, "l", &PyTryBlock)) |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 365 | return NULL; |
| 366 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 367 | PyTryBlock = CDseekblock(self->ob_cdplayer, PyTryBlock); |
| 368 | if (PyTryBlock == (unsigned long) -1) { |
| 369 | PyErr_SetFromErrno(CdError); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 370 | return NULL; |
| 371 | } |
| 372 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 373 | return PyInt_FromLong(PyTryBlock); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 376 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 377 | CD_stop(self, args) |
| 378 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 379 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 380 | { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 381 | CDSTATUS status; |
| 382 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 383 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 384 | return NULL; |
| 385 | |
| 386 | if (!CDstop(self->ob_cdplayer)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 387 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 388 | status.state == CD_NODISC) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 389 | PyErr_SetString(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 390 | else |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 391 | PyErr_SetString(CdError, "stop failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 392 | return NULL; |
| 393 | } |
| 394 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 395 | Py_INCREF(Py_None); |
| 396 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 399 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 400 | CD_togglepause(self, args) |
| 401 | cdplayerobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 402 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 403 | { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 404 | CDSTATUS status; |
| 405 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 406 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 407 | return NULL; |
| 408 | |
| 409 | if (!CDtogglepause(self->ob_cdplayer)) { |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 410 | if (CDgetstatus(self->ob_cdplayer, &status) && |
| 411 | status.state == CD_NODISC) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 412 | PyErr_SetString(CdError, "no disc in player"); |
Guido van Rossum | c3c7ac8 | 1992-05-06 09:48:30 +0000 | [diff] [blame] | 413 | else |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 414 | PyErr_SetString(CdError, "togglepause failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 415 | return NULL; |
| 416 | } |
| 417 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 418 | Py_INCREF(Py_None); |
| 419 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 422 | static PyMethodDef cdplayer_methods[] = { |
| 423 | {"allowremoval", (PyCFunction)CD_allowremoval, 1}, |
| 424 | {"bestreadsize", (PyCFunction)CD_bestreadsize, 1}, |
| 425 | {"close", (PyCFunction)CD_close, 1}, |
| 426 | {"eject", (PyCFunction)CD_eject, 1}, |
| 427 | {"getstatus", (PyCFunction)CD_getstatus, 1}, |
| 428 | {"gettrackinfo", (PyCFunction)CD_gettrackinfo, 1}, |
| 429 | {"msftoblock", (PyCFunction)CD_msftoblock, 1}, |
| 430 | {"play", (PyCFunction)CD_play, 1}, |
| 431 | {"playabs", (PyCFunction)CD_playabs, 1}, |
| 432 | {"playtrack", (PyCFunction)CD_playtrack, 1}, |
| 433 | {"playtrackabs", (PyCFunction)CD_playtrackabs, 1}, |
| 434 | {"preventremoval", (PyCFunction)CD_preventremoval, 1}, |
| 435 | {"readda", (PyCFunction)CD_readda, 1}, |
| 436 | {"seek", (PyCFunction)CD_seek, 1}, |
| 437 | {"seekblock", (PyCFunction)CD_seekblock, 1}, |
| 438 | {"seektrack", (PyCFunction)CD_seektrack, 1}, |
| 439 | {"stop", (PyCFunction)CD_stop, 1}, |
| 440 | {"togglepause", (PyCFunction)CD_togglepause, 1}, |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 441 | {NULL, NULL} /* sentinel */ |
| 442 | }; |
| 443 | |
| 444 | static void |
| 445 | cdplayer_dealloc(self) |
| 446 | cdplayerobject *self; |
| 447 | { |
| 448 | if (self->ob_cdplayer != NULL) |
| 449 | CDclose(self->ob_cdplayer); |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 450 | PyMem_DEL(self); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 453 | static PyObject * |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 454 | cdplayer_getattr(self, name) |
| 455 | cdplayerobject *self; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 456 | char *name; |
| 457 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 458 | if (self->ob_cdplayer == NULL) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 459 | PyErr_SetString(PyExc_RuntimeError, "no player active"); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 460 | return NULL; |
| 461 | } |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 462 | return Py_FindMethod(cdplayer_methods, (PyObject *)self, name); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 465 | PyTypeObject CdPlayertype = { |
| 466 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 467 | 0, /*ob_size*/ |
| 468 | "cdplayer", /*tp_name*/ |
| 469 | sizeof(cdplayerobject), /*tp_size*/ |
| 470 | 0, /*tp_itemsize*/ |
| 471 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 472 | (destructor)cdplayer_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 473 | 0, /*tp_print*/ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 474 | (getattrfunc)cdplayer_getattr, /*tp_getattr*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 475 | 0, /*tp_setattr*/ |
| 476 | 0, /*tp_compare*/ |
| 477 | 0, /*tp_repr*/ |
| 478 | }; |
| 479 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 480 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 481 | newcdplayerobject(cdp) |
| 482 | CDPLAYER *cdp; |
| 483 | { |
| 484 | cdplayerobject *p; |
| 485 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 486 | p = PyObject_NEW(cdplayerobject, &CdPlayertype); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 487 | if (p == NULL) |
| 488 | return NULL; |
| 489 | p->ob_cdplayer = cdp; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 490 | return (PyObject *) p; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 493 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 494 | CD_open(self, args) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 495 | PyObject *self, *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 496 | { |
| 497 | char *dev, *direction; |
| 498 | CDPLAYER *cdp; |
| 499 | |
| 500 | /* |
| 501 | * Variable number of args. |
| 502 | * First defaults to "None", second defaults to "r". |
| 503 | */ |
| 504 | dev = NULL; |
| 505 | direction = "r"; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 506 | if (!PyArg_ParseTuple(args, "|zs", &dev, &direction)) |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 507 | return NULL; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 508 | |
| 509 | cdp = CDopen(dev, direction); |
| 510 | if (cdp == NULL) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 511 | PyErr_SetFromErrno(CdError); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 512 | return NULL; |
| 513 | } |
| 514 | |
| 515 | return newcdplayerobject(cdp); |
| 516 | } |
| 517 | |
| 518 | typedef struct { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 519 | PyObject_HEAD |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 520 | CDPARSER *ob_cdparser; |
| 521 | struct { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 522 | PyObject *ob_cdcallback; |
| 523 | PyObject *ob_cdcallbackarg; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 524 | } ob_cdcallbacks[NCALLBACKS]; |
| 525 | } cdparserobject; |
| 526 | |
| 527 | static void |
| 528 | CD_callback(arg, type, data) |
| 529 | void *arg; |
| 530 | CDDATATYPES type; |
| 531 | void *data; |
| 532 | { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 533 | PyObject *result, *args, *v = NULL; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 534 | char *p; |
| 535 | int i; |
| 536 | cdparserobject *self; |
| 537 | |
| 538 | self = (cdparserobject *) arg; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 539 | args = PyTuple_New(3); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 540 | if (args == NULL) |
| 541 | return; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 542 | Py_INCREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); |
| 543 | PyTuple_SetItem(args, 0, self->ob_cdcallbacks[type].ob_cdcallbackarg); |
| 544 | PyTuple_SetItem(args, 1, PyInt_FromLong((long) type)); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 545 | switch (type) { |
| 546 | case cd_audio: |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 547 | v = PyString_FromStringAndSize(data, CDDA_DATASIZE); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 548 | break; |
| 549 | case cd_pnum: |
| 550 | case cd_index: |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 551 | v = PyInt_FromLong(((CDPROGNUM *) data)->value); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 552 | break; |
| 553 | case cd_ptime: |
| 554 | case cd_atime: |
Guido van Rossum | ece6efe | 1992-04-15 15:56:11 +0000 | [diff] [blame] | 555 | #define ptr ((struct cdtimecode *) data) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 556 | v = Py_BuildValue("(iii)", |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 557 | ptr->mhi * 10 + ptr->mlo, |
Guido van Rossum | ece6efe | 1992-04-15 15:56:11 +0000 | [diff] [blame] | 558 | ptr->shi * 10 + ptr->slo, |
| 559 | ptr->fhi * 10 + ptr->flo); |
| 560 | #undef ptr |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 561 | break; |
| 562 | case cd_catalog: |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 563 | v = PyString_FromStringAndSize(NULL, 13); |
| 564 | p = PyString_AsString(v); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 565 | for (i = 0; i < 13; i++) |
| 566 | *p++ = ((char *) data)[i] + '0'; |
| 567 | break; |
| 568 | case cd_ident: |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 569 | #define ptr ((struct cdident *) data) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 570 | v = PyString_FromStringAndSize(NULL, 12); |
| 571 | p = PyString_AsString(v); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 572 | CDsbtoa(p, ptr->country, 2); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 573 | p += 2; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 574 | CDsbtoa(p, ptr->owner, 3); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 575 | p += 3; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 576 | *p++ = ptr->year[0] + '0'; |
| 577 | *p++ = ptr->year[1] + '0'; |
| 578 | *p++ = ptr->serial[0] + '0'; |
| 579 | *p++ = ptr->serial[1] + '0'; |
| 580 | *p++ = ptr->serial[2] + '0'; |
| 581 | *p++ = ptr->serial[3] + '0'; |
| 582 | *p++ = ptr->serial[4] + '0'; |
| 583 | #undef ptr |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 584 | break; |
| 585 | case cd_control: |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 586 | v = PyInt_FromLong((long) *((unchar *) data)); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 587 | break; |
| 588 | } |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 589 | PyTuple_SetItem(args, 2, v); |
| 590 | if (PyErr_Occurred()) { |
| 591 | Py_DECREF(args); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 592 | return; |
| 593 | } |
| 594 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 595 | result = PyEval_CallObject(self->ob_cdcallbacks[type].ob_cdcallback, |
| 596 | args); |
| 597 | Py_DECREF(args); |
| 598 | Py_XDECREF(result); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 601 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 602 | CD_deleteparser(self, args) |
| 603 | cdparserobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 604 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 605 | { |
| 606 | int i; |
| 607 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 608 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 609 | return NULL; |
| 610 | |
| 611 | CDdeleteparser(self->ob_cdparser); |
| 612 | self->ob_cdparser = NULL; |
| 613 | |
| 614 | /* no sense in keeping the callbacks, so remove them */ |
| 615 | for (i = 0; i < NCALLBACKS; i++) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 616 | Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 617 | self->ob_cdcallbacks[i].ob_cdcallback = NULL; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 618 | Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 619 | self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; |
| 620 | } |
| 621 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 622 | Py_INCREF(Py_None); |
| 623 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 626 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 627 | CD_parseframe(self, args) |
| 628 | cdparserobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 629 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 630 | { |
| 631 | char *cdfp; |
| 632 | int length; |
| 633 | CDFRAME *p; |
| 634 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 635 | if (!PyArg_ParseTuple(args, "s#", &cdfp, &length)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 636 | return NULL; |
| 637 | |
| 638 | if (length % sizeof(CDFRAME) != 0) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 639 | PyErr_SetString(PyExc_TypeError, "bad length"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 640 | return NULL; |
| 641 | } |
| 642 | |
| 643 | p = (CDFRAME *) cdfp; |
| 644 | while (length > 0) { |
| 645 | CDparseframe(self->ob_cdparser, p); |
| 646 | length -= sizeof(CDFRAME); |
| 647 | p++; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 648 | if (PyErr_Occurred()) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 649 | return NULL; |
| 650 | } |
| 651 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 652 | Py_INCREF(Py_None); |
| 653 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 656 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 657 | CD_removecallback(self, args) |
| 658 | cdparserobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 659 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 660 | { |
| 661 | int type; |
| 662 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 663 | if (!PyArg_ParseTuple(args, "i", &type)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 664 | return NULL; |
| 665 | |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 666 | if (type < 0 || type >= NCALLBACKS) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 667 | PyErr_SetString(PyExc_TypeError, "bad type"); |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 668 | return NULL; |
| 669 | } |
| 670 | |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 671 | CDremovecallback(self->ob_cdparser, (CDDATATYPES) type); |
| 672 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 673 | Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 674 | self->ob_cdcallbacks[type].ob_cdcallback = NULL; |
| 675 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 676 | Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 677 | self->ob_cdcallbacks[type].ob_cdcallbackarg = NULL; |
| 678 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 679 | Py_INCREF(Py_None); |
| 680 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 681 | } |
| 682 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 683 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 684 | CD_resetparser(self, args) |
| 685 | cdparserobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 686 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 687 | { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 688 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 689 | return NULL; |
| 690 | |
| 691 | CDresetparser(self->ob_cdparser); |
| 692 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 693 | Py_INCREF(Py_None); |
| 694 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 695 | } |
| 696 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 697 | static PyObject * |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 698 | CD_addcallback(self, args) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 699 | cdparserobject *self; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 700 | PyObject *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 701 | { |
| 702 | int type; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 703 | PyObject *func, *funcarg; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 704 | |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 705 | /* XXX - more work here */ |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 706 | if (!PyArg_ParseTuple(args, "iOO", &type, &func, &funcarg)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 707 | return NULL; |
| 708 | |
| 709 | if (type < 0 || type >= NCALLBACKS) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 710 | PyErr_SetString(PyExc_TypeError, "argument out of range"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 711 | return NULL; |
| 712 | } |
| 713 | |
Sjoerd Mullender | 7c4eb40 | 1992-09-25 11:15:58 +0000 | [diff] [blame] | 714 | #ifdef CDsetcallback |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 715 | CDaddcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, |
| 716 | (void *) self); |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 717 | #else |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 718 | CDsetcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, |
| 719 | (void *) self); |
Guido van Rossum | f16eda5 | 1992-08-03 19:06:59 +0000 | [diff] [blame] | 720 | #endif |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 721 | Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback); |
| 722 | Py_INCREF(func); |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 723 | self->ob_cdcallbacks[type].ob_cdcallback = func; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 724 | Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); |
| 725 | Py_INCREF(funcarg); |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 726 | self->ob_cdcallbacks[type].ob_cdcallbackarg = funcarg; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 727 | |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 728 | /* |
| 729 | if (type == cd_audio) { |
| 730 | sigfpe_[_UNDERFL].repls = _ZERO; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 731 | handle_sigfpes(_ON, _EN_UNDERFL, NULL, |
| 732 | _ABORT_ON_ERROR, NULL); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 733 | } |
| 734 | */ |
| 735 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 736 | Py_INCREF(Py_None); |
| 737 | return Py_None; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 740 | static PyMethodDef cdparser_methods[] = { |
| 741 | {"addcallback", (PyCFunction)CD_addcallback, 1}, |
| 742 | {"deleteparser", (PyCFunction)CD_deleteparser, 1}, |
| 743 | {"parseframe", (PyCFunction)CD_parseframe, 1}, |
| 744 | {"removecallback", (PyCFunction)CD_removecallback, 1}, |
| 745 | {"resetparser", (PyCFunction)CD_resetparser, 1}, |
| 746 | /* backward compatibility */ |
| 747 | {"setcallback", (PyCFunction)CD_addcallback, 1}, |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 748 | {NULL, NULL} /* sentinel */ |
| 749 | }; |
| 750 | |
| 751 | static void |
| 752 | cdparser_dealloc(self) |
| 753 | cdparserobject *self; |
| 754 | { |
| 755 | int i; |
| 756 | |
| 757 | for (i = 0; i < NCALLBACKS; i++) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 758 | Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 759 | self->ob_cdcallbacks[i].ob_cdcallback = NULL; |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 760 | Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 761 | self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; |
| 762 | } |
| 763 | CDdeleteparser(self->ob_cdparser); |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 764 | PyMem_DEL(self); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 765 | } |
| 766 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 767 | static PyObject * |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 768 | cdparser_getattr(self, name) |
| 769 | cdparserobject *self; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 770 | char *name; |
| 771 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 772 | if (self->ob_cdparser == NULL) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 773 | PyErr_SetString(PyExc_RuntimeError, "no parser active"); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 774 | return NULL; |
| 775 | } |
| 776 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 777 | return Py_FindMethod(cdparser_methods, (PyObject *)self, name); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 778 | } |
| 779 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 780 | PyTypeObject CdParsertype = { |
| 781 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 782 | 0, /*ob_size*/ |
| 783 | "cdparser", /*tp_name*/ |
| 784 | sizeof(cdparserobject), /*tp_size*/ |
| 785 | 0, /*tp_itemsize*/ |
| 786 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 787 | (destructor)cdparser_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 788 | 0, /*tp_print*/ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 789 | (getattrfunc)cdparser_getattr, /*tp_getattr*/ |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 790 | 0, /*tp_setattr*/ |
| 791 | 0, /*tp_compare*/ |
| 792 | 0, /*tp_repr*/ |
| 793 | }; |
| 794 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 795 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 796 | newcdparserobject(cdp) |
| 797 | CDPARSER *cdp; |
| 798 | { |
| 799 | cdparserobject *p; |
| 800 | int i; |
| 801 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 802 | p = PyObject_NEW(cdparserobject, &CdParsertype); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 803 | if (p == NULL) |
| 804 | return NULL; |
| 805 | p->ob_cdparser = cdp; |
| 806 | for (i = 0; i < NCALLBACKS; i++) { |
| 807 | p->ob_cdcallbacks[i].ob_cdcallback = NULL; |
| 808 | p->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; |
| 809 | } |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 810 | return (PyObject *) p; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 813 | static PyObject * |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 814 | CD_createparser(self, args) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 815 | PyObject *self, *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 816 | { |
| 817 | CDPARSER *cdp; |
| 818 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 819 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 820 | return NULL; |
| 821 | cdp = CDcreateparser(); |
| 822 | if (cdp == NULL) { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 823 | PyErr_SetString(CdError, "createparser failed"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 824 | return NULL; |
| 825 | } |
| 826 | |
| 827 | return newcdparserobject(cdp); |
| 828 | } |
| 829 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 830 | static PyObject * |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 831 | CD_msftoframe(self, args) |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 832 | PyObject *self, *args; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 833 | { |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 834 | int min, sec, frame; |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 835 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 836 | if (!PyArg_ParseTuple(args, "iii", &min, &sec, &frame)) |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 837 | return NULL; |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 838 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 839 | return PyInt_FromLong((long) CDmsftoframe(min, sec, frame)); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 840 | } |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 841 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 842 | static PyMethodDef CD_methods[] = { |
| 843 | {"open", (PyCFunction)CD_open, 1}, |
| 844 | {"createparser", (PyCFunction)CD_createparser, 1}, |
| 845 | {"msftoframe", (PyCFunction)CD_msftoframe, 1}, |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 846 | {NULL, NULL} /* Sentinel */ |
| 847 | }; |
| 848 | |
| 849 | void |
| 850 | initcd() |
| 851 | { |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 852 | PyObject *m, *d; |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 853 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 854 | m = Py_InitModule("cd", CD_methods); |
| 855 | d = PyModule_GetDict(m); |
Sjoerd Mullender | 46927ba | 1992-09-24 10:48:40 +0000 | [diff] [blame] | 856 | |
Guido van Rossum | 88d8bee | 1997-10-01 04:43:39 +0000 | [diff] [blame] | 857 | CdError = PyErr_NewException("cd.error", NULL, NULL); |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 858 | PyDict_SetItemString(d, "error", CdError); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 859 | |
| 860 | /* Identifiers for the different types of callbacks from the parser */ |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 861 | PyDict_SetItemString(d, "audio", PyInt_FromLong((long) cd_audio)); |
| 862 | PyDict_SetItemString(d, "pnum", PyInt_FromLong((long) cd_pnum)); |
| 863 | PyDict_SetItemString(d, "index", PyInt_FromLong((long) cd_index)); |
| 864 | PyDict_SetItemString(d, "ptime", PyInt_FromLong((long) cd_ptime)); |
| 865 | PyDict_SetItemString(d, "atime", PyInt_FromLong((long) cd_atime)); |
| 866 | PyDict_SetItemString(d, "catalog", PyInt_FromLong((long) cd_catalog)); |
| 867 | PyDict_SetItemString(d, "ident", PyInt_FromLong((long) cd_ident)); |
| 868 | PyDict_SetItemString(d, "control", PyInt_FromLong((long) cd_control)); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 869 | |
| 870 | /* Block size information for digital audio data */ |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 871 | PyDict_SetItemString(d, "DATASIZE", |
| 872 | PyInt_FromLong((long) CDDA_DATASIZE)); |
| 873 | PyDict_SetItemString(d, "BLOCKSIZE", |
| 874 | PyInt_FromLong((long) CDDA_BLOCKSIZE)); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 875 | |
| 876 | /* Possible states for the cd player */ |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 877 | PyDict_SetItemString(d, "ERROR", PyInt_FromLong((long) CD_ERROR)); |
| 878 | PyDict_SetItemString(d, "NODISC", PyInt_FromLong((long) CD_NODISC)); |
| 879 | PyDict_SetItemString(d, "READY", PyInt_FromLong((long) CD_READY)); |
| 880 | PyDict_SetItemString(d, "PLAYING", PyInt_FromLong((long) CD_PLAYING)); |
| 881 | PyDict_SetItemString(d, "PAUSED", PyInt_FromLong((long) CD_PAUSED)); |
| 882 | PyDict_SetItemString(d, "STILL", PyInt_FromLong((long) CD_STILL)); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 883 | #ifdef CD_CDROM /* only newer versions of the library */ |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 884 | PyDict_SetItemString(d, "CDROM", PyInt_FromLong((long) CD_CDROM)); |
Sjoerd Mullender | 542659b | 1995-03-28 12:06:23 +0000 | [diff] [blame] | 885 | #endif |
| 886 | |
Roger E. Masse | bf0c3ca | 1997-01-03 23:00:51 +0000 | [diff] [blame] | 887 | if (PyErr_Occurred()) |
| 888 | Py_FatalError("can't initialize module cd"); |
Guido van Rossum | 16b8f30 | 1992-04-13 18:22:53 +0000 | [diff] [blame] | 889 | } |